From f96d6b0afe5f98f667530ca80f5d45b6def82a1c Mon Sep 17 00:00:00 2001 From: Georges Basile Stavracas Neto Date: Fri, 17 Nov 2023 12:25:06 -0300 Subject: [PATCH] screen-cast/monitor-src: Bring back blitting Now that the monitor screencast records to DMA-BUF buffers immediately (since bc2f1145d86), and we know which phase of the paint rountines we are (since last commit), we have the opportunity to bring back the blitting technique. Bring back blitting. This time, instead of simply failing if the blit fails, add a fallback path that does a stage paint if something goes wrong. Unlike the previous implementation of blitting, this one only blits the current view - it does not blit all views that intersect with the screencasted monitor. Embedded cursors should still be fine because hardware cursor is inhibited while embedded cursor screencasts are running. Part-of: --- .../meta-screen-cast-monitor-stream-src.c | 100 +++++++++++++++--- 1 file changed, 88 insertions(+), 12 deletions(-) diff --git a/src/backends/meta-screen-cast-monitor-stream-src.c b/src/backends/meta-screen-cast-monitor-stream-src.c index 28d112a2f..b13b25dd0 100644 --- a/src/backends/meta-screen-cast-monitor-stream-src.c +++ b/src/backends/meta-screen-cast-monitor-stream-src.c @@ -601,12 +601,20 @@ meta_screen_cast_monitor_stream_src_record_to_framebuffer (MetaScreenCastStreamS META_SCREEN_CAST_MONITOR_STREAM_SRC (src); MetaScreenCastStream *stream = meta_screen_cast_stream_src_get_stream (src); MetaBackend *backend = get_backend (monitor_src); + MetaRenderer *renderer = meta_backend_get_renderer (backend); ClutterStage *stage = get_stage (monitor_src); + g_autoptr (GError) local_error = NULL; MetaMonitor *monitor; MetaLogicalMonitor *logical_monitor; + MetaRendererView *renderer_view; + ClutterStageView *view; MtkRectangle logical_monitor_layout; + MtkRectangle view_layout; + MetaCrtc *crtc; + gboolean do_stage_paint = TRUE; float view_scale; - ClutterPaintFlag paint_flags = CLUTTER_PAINT_FLAG_CLEAR; + GList *outputs; + int x, y; monitor = get_monitor (monitor_src); logical_monitor = meta_monitor_get_logical_monitor (monitor); @@ -617,22 +625,90 @@ meta_screen_cast_monitor_stream_src_record_to_framebuffer (MetaScreenCastStreamS else view_scale = 1.0; - switch (meta_screen_cast_stream_get_cursor_mode (stream)) + if (paint_phase == META_SCREEN_CAST_PAINT_PHASE_DETACHED) + goto stage_paint; + + outputs = meta_monitor_get_outputs (monitor); + if (outputs->next) + goto stage_paint; + + crtc = meta_output_get_assigned_crtc (outputs->data); + renderer_view = meta_renderer_get_view_for_crtc (renderer, crtc); + + g_assert (renderer_view != NULL); + + view = CLUTTER_STAGE_VIEW (renderer_view); + clutter_stage_view_get_layout (view, &view_layout); + + x = (int) roundf ((view_layout.x - logical_monitor_layout.x) * view_scale); + y = (int) roundf ((view_layout.y - logical_monitor_layout.y) * view_scale); + + switch (paint_phase) { - case META_SCREEN_CAST_CURSOR_MODE_METADATA: - case META_SCREEN_CAST_CURSOR_MODE_HIDDEN: - paint_flags |= CLUTTER_PAINT_FLAG_NO_CURSORS; + case META_SCREEN_CAST_PAINT_PHASE_PRE_PAINT: + { + CoglScanout *scanout = clutter_stage_view_peek_scanout (view); + + if (scanout) + { + cogl_scanout_blit_to_framebuffer (scanout, + framebuffer, + x, y, + &local_error); + } + } break; - case META_SCREEN_CAST_CURSOR_MODE_EMBEDDED: - paint_flags |= CLUTTER_PAINT_FLAG_FORCE_CURSORS; + + case META_SCREEN_CAST_PAINT_PHASE_PRE_SWAP_BUFFER: + { + CoglFramebuffer *view_framebuffer = + clutter_stage_view_get_framebuffer (view); + + cogl_blit_framebuffer (view_framebuffer, + framebuffer, + 0, 0, + x, y, + cogl_framebuffer_get_width (view_framebuffer), + cogl_framebuffer_get_height (view_framebuffer), + &local_error); + } break; + + case META_SCREEN_CAST_PAINT_PHASE_DETACHED: + g_assert_not_reached (); } - clutter_stage_paint_to_framebuffer (stage, - framebuffer, - &logical_monitor_layout, - view_scale, - paint_flags); + if (local_error) + { + g_warning ("Error blitting to screencast framebuffer: %s", + local_error->message); + } + + do_stage_paint = local_error != NULL; + +stage_paint: + if (do_stage_paint) + { + ClutterPaintFlag paint_flags = CLUTTER_PAINT_FLAG_CLEAR; + + switch (meta_screen_cast_stream_get_cursor_mode (stream)) + { + case META_SCREEN_CAST_CURSOR_MODE_METADATA: + case META_SCREEN_CAST_CURSOR_MODE_HIDDEN: + paint_flags |= CLUTTER_PAINT_FLAG_NO_CURSORS; + break; + + case META_SCREEN_CAST_CURSOR_MODE_EMBEDDED: + paint_flags |= CLUTTER_PAINT_FLAG_FORCE_CURSORS; + break; + } + + clutter_stage_paint_to_framebuffer (stage, + framebuffer, + &logical_monitor_layout, + view_scale, + paint_flags); + } cogl_framebuffer_flush (framebuffer);