From df228e8945cb77e517f89af69bc1fba4eef89279 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Wed, 30 Sep 2020 17:40:10 +0200 Subject: [PATCH] screen-cast/area-src: Clear framebuffer before painting stage We'll be painting to a framebuffer that may not be completely covered by the painted areas, meaning the not painted areas would end up undefined, thus potentially contain garbage or old content. Avoid this by clearing the framebuffer before painting the stage. Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/1442 https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1459 --- clutter/clutter/clutter-paint-context.h | 1 + clutter/clutter/clutter-stage.c | 8 ++++++++ src/backends/meta-screen-cast-area-stream-src.c | 4 ++-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/clutter/clutter/clutter-paint-context.h b/clutter/clutter/clutter-paint-context.h index 8461b947a..2a36fe967 100644 --- a/clutter/clutter/clutter-paint-context.h +++ b/clutter/clutter/clutter-paint-context.h @@ -34,6 +34,7 @@ typedef enum _ClutterPaintFlag CLUTTER_PAINT_FLAG_NONE = 0, CLUTTER_PAINT_FLAG_NO_CURSORS = 1 << 0, CLUTTER_PAINT_FLAG_FORCE_CURSORS = 1 << 1, + CLUTTER_PAINT_FLAG_CLEAR = 1 << 2, } ClutterPaintFlag; #define CLUTTER_TYPE_PAINT_CONTEXT (clutter_paint_context_get_type ()) diff --git a/clutter/clutter/clutter-stage.c b/clutter/clutter/clutter-stage.c index 14e04e1a5..f5d7f141b 100644 --- a/clutter/clutter/clutter-stage.c +++ b/clutter/clutter/clutter-stage.c @@ -3614,6 +3614,14 @@ clutter_stage_paint_to_framebuffer (ClutterStage *stage, ClutterPaintContext *paint_context; cairo_region_t *redraw_clip; + if (paint_flags & CLUTTER_PAINT_FLAG_CLEAR) + { + CoglColor clear_color; + + cogl_color_init_from_4ub (&clear_color, 0, 0, 0, 0); + cogl_framebuffer_clear (framebuffer, COGL_BUFFER_BIT_COLOR, &clear_color); + } + redraw_clip = cairo_region_create_rectangle (rect); paint_context = clutter_paint_context_new_for_framebuffer (framebuffer, diff --git a/src/backends/meta-screen-cast-area-stream-src.c b/src/backends/meta-screen-cast-area-stream-src.c index e22b7dcab..e7d42d432 100644 --- a/src/backends/meta-screen-cast-area-stream-src.c +++ b/src/backends/meta-screen-cast-area-stream-src.c @@ -414,7 +414,7 @@ meta_screen_cast_area_stream_src_record_to_buffer (MetaScreenCastStreamSrc *src MetaRectangle *area; float scale; int stride; - ClutterPaintFlag paint_flags = CLUTTER_PAINT_FLAG_NONE; + ClutterPaintFlag paint_flags = CLUTTER_PAINT_FLAG_CLEAR; stage = get_stage (area_src); area = meta_screen_cast_area_stream_get_area (area_stream); @@ -456,7 +456,7 @@ meta_screen_cast_area_stream_src_record_to_framebuffer (MetaScreenCastStreamSrc ClutterStage *stage; MetaRectangle *area; float scale; - ClutterPaintFlag paint_flags = CLUTTER_PAINT_FLAG_NONE; + ClutterPaintFlag paint_flags = CLUTTER_PAINT_FLAG_CLEAR; stage = CLUTTER_STAGE (meta_backend_get_stage (backend)); area = meta_screen_cast_area_stream_get_area (area_stream);