From cf88d648822eb6b7d412c08d4038c657d415bfff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Fri, 3 Jul 2020 16:52:43 +0200 Subject: [PATCH] screen-cast: Let the reason for recording determine what to record E.g. we'll have pointer movement that, if no painting is already scheduled, should only send new cursor metadata without any new pixel buffer. When this happens, tell next step to not record the pixels if this was the case, instead of having it rediscover this itself. Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/1323 https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1351 --- .../meta-screen-cast-monitor-stream-src.c | 5 +- src/backends/meta-screen-cast-stream-src.c | 53 +++++++++++-------- src/backends/meta-screen-cast-stream-src.h | 1 + .../meta-screen-cast-window-stream-src.c | 4 +- 4 files changed, 34 insertions(+), 29 deletions(-) diff --git a/src/backends/meta-screen-cast-monitor-stream-src.c b/src/backends/meta-screen-cast-monitor-stream-src.c index 70edb229c..17aa7aeb4 100644 --- a/src/backends/meta-screen-cast-monitor-stream-src.c +++ b/src/backends/meta-screen-cast-monitor-stream-src.c @@ -191,7 +191,7 @@ sync_cursor_state (MetaScreenCastMonitorStreamSrc *monitor_src) if (clutter_stage_is_redraw_queued (stage)) return; - flags = META_SCREEN_CAST_RECORD_FLAG_NONE; + flags = META_SCREEN_CAST_RECORD_FLAG_CURSOR_ONLY; meta_screen_cast_stream_src_maybe_record_frame (src, flags); } @@ -376,9 +376,6 @@ meta_screen_cast_monitor_stream_src_record_to_buffer (MetaScreenCastStreamSrc *s MetaLogicalMonitor *logical_monitor; stage = get_stage (monitor_src); - if (!clutter_stage_is_redraw_queued (stage)) - return FALSE; - monitor = get_monitor (monitor_src); logical_monitor = meta_monitor_get_logical_monitor (monitor); clutter_stage_capture_into (stage, FALSE, &logical_monitor->rect, data); diff --git a/src/backends/meta-screen-cast-stream-src.c b/src/backends/meta-screen-cast-stream-src.c index 7f124bfff..463d316eb 100644 --- a/src/backends/meta-screen-cast-stream-src.c +++ b/src/backends/meta-screen-cast-stream-src.c @@ -472,34 +472,41 @@ meta_screen_cast_stream_src_maybe_record_frame (MetaScreenCastStreamSrc *src, return; } - if (do_record_frame (src, spa_buffer, data)) + if (!(flags & META_SCREEN_CAST_RECORD_FLAG_CURSOR_ONLY)) { - struct spa_meta_region *spa_meta_video_crop; - - spa_buffer->datas[0].chunk->size = spa_buffer->datas[0].maxsize; - spa_buffer->datas[0].chunk->stride = priv->video_stride; - - /* Update VideoCrop if needed */ - spa_meta_video_crop = - spa_buffer_find_meta_data (spa_buffer, SPA_META_VideoCrop, - sizeof (*spa_meta_video_crop)); - if (spa_meta_video_crop) + if (do_record_frame (src, spa_buffer, data)) { - if (meta_screen_cast_stream_src_get_videocrop (src, &crop_rect)) + struct spa_meta_region *spa_meta_video_crop; + + spa_buffer->datas[0].chunk->size = spa_buffer->datas[0].maxsize; + spa_buffer->datas[0].chunk->stride = priv->video_stride; + + /* Update VideoCrop if needed */ + spa_meta_video_crop = + spa_buffer_find_meta_data (spa_buffer, SPA_META_VideoCrop, + sizeof (*spa_meta_video_crop)); + if (spa_meta_video_crop) { - spa_meta_video_crop->region.position.x = crop_rect.x; - spa_meta_video_crop->region.position.y = crop_rect.y; - spa_meta_video_crop->region.size.width = crop_rect.width; - spa_meta_video_crop->region.size.height = crop_rect.height; - } - else - { - spa_meta_video_crop->region.position.x = 0; - spa_meta_video_crop->region.position.y = 0; - spa_meta_video_crop->region.size.width = priv->stream_width; - spa_meta_video_crop->region.size.height = priv->stream_height; + if (meta_screen_cast_stream_src_get_videocrop (src, &crop_rect)) + { + spa_meta_video_crop->region.position.x = crop_rect.x; + spa_meta_video_crop->region.position.y = crop_rect.y; + spa_meta_video_crop->region.size.width = crop_rect.width; + spa_meta_video_crop->region.size.height = crop_rect.height; + } + else + { + spa_meta_video_crop->region.position.x = 0; + spa_meta_video_crop->region.position.y = 0; + spa_meta_video_crop->region.size.width = priv->stream_width; + spa_meta_video_crop->region.size.height = priv->stream_height; + } } } + else + { + spa_buffer->datas[0].chunk->size = 0; + } } else { diff --git a/src/backends/meta-screen-cast-stream-src.h b/src/backends/meta-screen-cast-stream-src.h index 6c73d05c1..87054eedf 100644 --- a/src/backends/meta-screen-cast-stream-src.h +++ b/src/backends/meta-screen-cast-stream-src.h @@ -40,6 +40,7 @@ typedef struct _MetaScreenCastStream MetaScreenCastStream; typedef enum _MetaScreenCastRecordFlag { META_SCREEN_CAST_RECORD_FLAG_NONE = 0, + META_SCREEN_CAST_RECORD_FLAG_CURSOR_ONLY = 1 << 0, } MetaScreenCastRecordFlag; #define META_TYPE_SCREEN_CAST_STREAM_SRC (meta_screen_cast_stream_src_get_type ()) diff --git a/src/backends/meta-screen-cast-window-stream-src.c b/src/backends/meta-screen-cast-window-stream-src.c index b3217330f..dfc5baa1a 100644 --- a/src/backends/meta-screen-cast-window-stream-src.c +++ b/src/backends/meta-screen-cast-window-stream-src.c @@ -329,7 +329,7 @@ screen_cast_window_damaged (MetaWindowActor *actor, MetaScreenCastStreamSrc *src = META_SCREEN_CAST_STREAM_SRC (window_src); MetaScreenCastRecordFlag flags; - flags = META_SCREEN_CAST_RECORD_FLAG_NONE; + flags = META_SCREEN_CAST_RECORD_FLAG_CURSOR_ONLY; meta_screen_cast_stream_src_maybe_record_frame (src, flags); } @@ -375,7 +375,7 @@ sync_cursor_state (MetaScreenCastWindowStreamSrc *window_src) if (meta_screen_cast_window_has_damage (window_src->screen_cast_window)) return; - flags = META_SCREEN_CAST_RECORD_FLAG_NONE; + flags = META_SCREEN_CAST_RECORD_FLAG_CURSOR_ONLY; meta_screen_cast_stream_src_maybe_record_frame (src, flags); }