From 047da80c3b59abb233e50a788a50519bcfc20314 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Fri, 3 Jul 2020 16:57:01 +0200 Subject: [PATCH] screen-cast/src: Make record functions return an error when failing Now that we don't use the record function to early out depending on implicit state (don't record pixels if only cursor moved for example), let it simply report an error when it fails, as we should no longer ever return without pixels if nothing failed. https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1361 --- .../meta-screen-cast-area-stream-src.c | 18 +++++------ .../meta-screen-cast-monitor-stream-src.c | 19 +++++------ src/backends/meta-screen-cast-stream-src.c | 32 ++++++++++++------- src/backends/meta-screen-cast-stream-src.h | 10 +++--- .../meta-screen-cast-window-stream-src.c | 16 +++++++--- 5 files changed, 53 insertions(+), 42 deletions(-) diff --git a/src/backends/meta-screen-cast-area-stream-src.c b/src/backends/meta-screen-cast-area-stream-src.c index e28d52b46..f010d968d 100644 --- a/src/backends/meta-screen-cast-area-stream-src.c +++ b/src/backends/meta-screen-cast-area-stream-src.c @@ -392,8 +392,9 @@ meta_screen_cast_area_stream_src_disable (MetaScreenCastStreamSrc *src) } static gboolean -meta_screen_cast_area_stream_src_record_to_buffer (MetaScreenCastStreamSrc *src, - uint8_t *data) +meta_screen_cast_area_stream_src_record_to_buffer (MetaScreenCastStreamSrc *src, + uint8_t *data, + GError **error) { MetaScreenCastAreaStreamSrc *area_src = META_SCREEN_CAST_AREA_STREAM_SRC (src); @@ -404,7 +405,6 @@ meta_screen_cast_area_stream_src_record_to_buffer (MetaScreenCastStreamSrc *src, float scale; int stride; ClutterPaintFlag paint_flags = CLUTTER_PAINT_FLAG_NONE; - g_autoptr (GError) error = NULL; stage = get_stage (area_src); area = meta_screen_cast_area_stream_get_area (area_stream); @@ -426,18 +426,16 @@ meta_screen_cast_area_stream_src_record_to_buffer (MetaScreenCastStreamSrc *src, stride, CLUTTER_CAIRO_FORMAT_ARGB32, paint_flags, - &error)) - { - g_warning ("Failed to record area: %s", error->message); - return FALSE; - } + error)) + return FALSE; return TRUE; } static gboolean -meta_screen_cast_area_stream_src_record_to_framebuffer (MetaScreenCastStreamSrc *src, - CoglFramebuffer *framebuffer) +meta_screen_cast_area_stream_src_record_to_framebuffer (MetaScreenCastStreamSrc *src, + CoglFramebuffer *framebuffer, + GError **error) { MetaScreenCastAreaStreamSrc *area_src = META_SCREEN_CAST_AREA_STREAM_SRC (src); diff --git a/src/backends/meta-screen-cast-monitor-stream-src.c b/src/backends/meta-screen-cast-monitor-stream-src.c index 1aec6aaef..760cb00e3 100644 --- a/src/backends/meta-screen-cast-monitor-stream-src.c +++ b/src/backends/meta-screen-cast-monitor-stream-src.c @@ -387,8 +387,9 @@ meta_screen_cast_monitor_stream_src_disable (MetaScreenCastStreamSrc *src) } static gboolean -meta_screen_cast_monitor_stream_src_record_to_buffer (MetaScreenCastStreamSrc *src, - uint8_t *data) +meta_screen_cast_monitor_stream_src_record_to_buffer (MetaScreenCastStreamSrc *src, + uint8_t *data, + GError **error) { MetaScreenCastMonitorStreamSrc *monitor_src = META_SCREEN_CAST_MONITOR_STREAM_SRC (src); @@ -405,8 +406,9 @@ meta_screen_cast_monitor_stream_src_record_to_buffer (MetaScreenCastStreamSrc *s } static gboolean -meta_screen_cast_monitor_stream_src_record_to_framebuffer (MetaScreenCastStreamSrc *src, - CoglFramebuffer *framebuffer) +meta_screen_cast_monitor_stream_src_record_to_framebuffer (MetaScreenCastStreamSrc *src, + CoglFramebuffer *framebuffer, + GError **error) { MetaScreenCastMonitorStreamSrc *monitor_src = META_SCREEN_CAST_MONITOR_STREAM_SRC (src); @@ -430,7 +432,6 @@ meta_screen_cast_monitor_stream_src_record_to_framebuffer (MetaScreenCastStreamS for (l = meta_renderer_get_views (renderer); l; l = l->next) { ClutterStageView *view = CLUTTER_STAGE_VIEW (l->data); - g_autoptr (GError) error = NULL; CoglFramebuffer *view_framebuffer; MetaRectangle view_layout; int x, y; @@ -451,12 +452,8 @@ meta_screen_cast_monitor_stream_src_record_to_framebuffer (MetaScreenCastStreamS x, y, cogl_framebuffer_get_width (view_framebuffer), cogl_framebuffer_get_height (view_framebuffer), - &error)) - { - g_warning ("Error blitting view into DMABuf framebuffer: %s", - error->message); - return FALSE; - } + error)) + return FALSE; } cogl_framebuffer_finish (framebuffer); diff --git a/src/backends/meta-screen-cast-stream-src.c b/src/backends/meta-screen-cast-stream-src.c index 6addd16c4..7fe603b74 100644 --- a/src/backends/meta-screen-cast-stream-src.c +++ b/src/backends/meta-screen-cast-stream-src.c @@ -135,23 +135,25 @@ meta_screen_cast_stream_src_get_videocrop (MetaScreenCastStreamSrc *src, } static gboolean -meta_screen_cast_stream_src_record_to_buffer (MetaScreenCastStreamSrc *src, - uint8_t *data) +meta_screen_cast_stream_src_record_to_buffer (MetaScreenCastStreamSrc *src, + uint8_t *data, + GError **error) { MetaScreenCastStreamSrcClass *klass = META_SCREEN_CAST_STREAM_SRC_GET_CLASS (src); - return klass->record_to_buffer (src, data); + return klass->record_to_buffer (src, data, error); } static gboolean -meta_screen_cast_stream_src_record_to_framebuffer (MetaScreenCastStreamSrc *src, - CoglFramebuffer *framebuffer) +meta_screen_cast_stream_src_record_to_framebuffer (MetaScreenCastStreamSrc *src, + CoglFramebuffer *framebuffer, + GError **error) { MetaScreenCastStreamSrcClass *klass = META_SCREEN_CAST_STREAM_SRC_GET_CLASS (src); - return klass->record_to_framebuffer (src, framebuffer); + return klass->record_to_framebuffer (src, framebuffer, error); } static void @@ -409,9 +411,10 @@ maybe_record_cursor (MetaScreenCastStreamSrc *src, } static gboolean -do_record_frame (MetaScreenCastStreamSrc *src, - struct spa_buffer *spa_buffer, - uint8_t *data) +do_record_frame (MetaScreenCastStreamSrc *src, + struct spa_buffer *spa_buffer, + uint8_t *data, + GError **error) { MetaScreenCastStreamSrcPrivate *priv = meta_screen_cast_stream_src_get_instance_private (src); @@ -419,7 +422,7 @@ do_record_frame (MetaScreenCastStreamSrc *src, if (spa_buffer->datas[0].data || spa_buffer->datas[0].type == SPA_DATA_MemFd) { - return meta_screen_cast_stream_src_record_to_buffer (src, data); + return meta_screen_cast_stream_src_record_to_buffer (src, data, error); } else if (spa_buffer->datas[0].type == SPA_DATA_DmaBuf) { @@ -430,9 +433,12 @@ do_record_frame (MetaScreenCastStreamSrc *src, cogl_dma_buf_handle_get_framebuffer (dmabuf_handle); return meta_screen_cast_stream_src_record_to_framebuffer (src, - dmabuf_fbo); + dmabuf_fbo, + error); } + g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, + "Unknown SPA buffer type %u", spa_buffer->datas[0].type); return FALSE; } @@ -447,6 +453,7 @@ meta_screen_cast_stream_src_maybe_record_frame (MetaScreenCastStreamSrc *src, struct spa_buffer *spa_buffer; uint8_t *data = NULL; uint64_t now_us; + g_autoptr (GError) error = NULL; now_us = g_get_monotonic_time (); if (priv->video_format.max_framerate.num > 0 && @@ -474,7 +481,7 @@ meta_screen_cast_stream_src_maybe_record_frame (MetaScreenCastStreamSrc *src, if (!(flags & META_SCREEN_CAST_RECORD_FLAG_CURSOR_ONLY)) { - if (do_record_frame (src, spa_buffer, data)) + if (do_record_frame (src, spa_buffer, data, &error)) { struct spa_meta_region *spa_meta_video_crop; @@ -505,6 +512,7 @@ meta_screen_cast_stream_src_maybe_record_frame (MetaScreenCastStreamSrc *src, } else { + g_warning ("Failed to record screen cast frame: %s", error->message); spa_buffer->datas[0].chunk->size = 0; } } diff --git a/src/backends/meta-screen-cast-stream-src.h b/src/backends/meta-screen-cast-stream-src.h index e43e701c1..fe9660564 100644 --- a/src/backends/meta-screen-cast-stream-src.h +++ b/src/backends/meta-screen-cast-stream-src.h @@ -59,10 +59,12 @@ struct _MetaScreenCastStreamSrcClass float *frame_rate); void (* enable) (MetaScreenCastStreamSrc *src); void (* disable) (MetaScreenCastStreamSrc *src); - gboolean (* record_to_buffer) (MetaScreenCastStreamSrc *src, - uint8_t *data); - gboolean (* record_to_framebuffer) (MetaScreenCastStreamSrc *src, - CoglFramebuffer *framebuffer); + gboolean (* record_to_buffer) (MetaScreenCastStreamSrc *src, + uint8_t *data, + GError **error); + gboolean (* record_to_framebuffer) (MetaScreenCastStreamSrc *src, + CoglFramebuffer *framebuffer, + GError **error); gboolean (* get_videocrop) (MetaScreenCastStreamSrc *src, MetaRectangle *crop_rect); void (* set_cursor_metadata) (MetaScreenCastStreamSrc *src, diff --git a/src/backends/meta-screen-cast-window-stream-src.c b/src/backends/meta-screen-cast-window-stream-src.c index dfc5baa1a..a504bd194 100644 --- a/src/backends/meta-screen-cast-window-stream-src.c +++ b/src/backends/meta-screen-cast-window-stream-src.c @@ -457,8 +457,9 @@ meta_screen_cast_window_stream_src_disable (MetaScreenCastStreamSrc *src) } static gboolean -meta_screen_cast_window_stream_src_record_to_buffer (MetaScreenCastStreamSrc *src, - uint8_t *data) +meta_screen_cast_window_stream_src_record_to_buffer (MetaScreenCastStreamSrc *src, + uint8_t *data, + GError **error) { MetaScreenCastWindowStreamSrc *window_src = META_SCREEN_CAST_WINDOW_STREAM_SRC (src); @@ -469,8 +470,9 @@ meta_screen_cast_window_stream_src_record_to_buffer (MetaScreenCastStreamSrc *sr } static gboolean -meta_screen_cast_window_stream_src_record_to_framebuffer (MetaScreenCastStreamSrc *src, - CoglFramebuffer *framebuffer) +meta_screen_cast_window_stream_src_record_to_framebuffer (MetaScreenCastStreamSrc *src, + CoglFramebuffer *framebuffer, + GError **error) { MetaScreenCastWindowStreamSrc *window_src = META_SCREEN_CAST_WINDOW_STREAM_SRC (src); @@ -485,7 +487,11 @@ meta_screen_cast_window_stream_src_record_to_framebuffer (MetaScreenCastStreamSr if (!meta_screen_cast_window_blit_to_framebuffer (window_src->screen_cast_window, &stream_rect, framebuffer)) - return FALSE; + { + g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, + "Failed to blit window content to framebuffer"); + return FALSE; + } stream = meta_screen_cast_stream_src_get_stream (src); switch (meta_screen_cast_stream_get_cursor_mode (stream))