summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorges Basile Stavracas Neto <georges.stavracas@gmail.com>2022-12-03 09:25:52 -0300
committerRobert Mader <robert.mader@collabora.com>2023-01-06 13:53:08 +0100
commit87bea894f9be299b1dedb8c45633fddb676cfe30 (patch)
treeb91d215ab46c1534b04556e8011f745938d1cbf1
parent421222c7051b104ae8e4844cc44cbae84cc72ba8 (diff)
downloadmutter-87bea894f9be299b1dedb8c45633fddb676cfe30.tar.gz
screen-cast/src: Ceil cursor buffer size
meta_screen_cast_stream_src_set_cursor_sprite_metadata() receives the cursor sprite, position, and scale, and with that it downloads the cursor sprite by drawing it into a separate framebuffer, then calls cogl_framebuffer_read_pixels() in it - this is the offscren path that is very common when using screen capturing applications such as OBS Studio. There's a sneaky issue in this code path though: the 'scale' value is a float. The cursor size is then determined by multiplying the sprite width and height - two integer variables - by scale, and this relies on standard float-to-int conversions. This is problematic as sometimes the rounded values disagree with what is expected by cogl_framebuffer_read_pixels(). If the packing of either the cursor width or height is off by one, glReadPixels() will try to write into off bounds, which crashes. This can be reproduced by enabling fractional scaling, setting a 150% zoom level, on a 4K screen, and opening any commit with an image diff in gitlab.gnome.org, all while screencasting. When hovering the new image, the cursor sprite will be such that it triggers this code path, and reproduces this issue. Fix this by always ceiling the cursor sprite sizes. Closes https://gitlab.gnome.org/GNOME/mutter/-/issues/2542 Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2736> (cherry picked from commit 4d4e8e586233344bf4d7d04d49b8cfb47bd98fc2)
-rw-r--r--src/backends/meta-screen-cast-stream-src.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/backends/meta-screen-cast-stream-src.c b/src/backends/meta-screen-cast-stream-src.c
index 806fa806c..f0a89c925 100644
--- a/src/backends/meta-screen-cast-stream-src.c
+++ b/src/backends/meta-screen-cast-stream-src.c
@@ -433,8 +433,8 @@ meta_screen_cast_stream_src_set_cursor_sprite_metadata (MetaScreenCastStreamSrc
texture_width = cogl_texture_get_width (cursor_texture);
texture_height = cogl_texture_get_height (cursor_texture);
- bitmap_width = texture_width * scale;
- bitmap_height = texture_height * scale;
+ bitmap_width = ceilf (texture_width * scale);
+ bitmap_height = ceilf (texture_height * scale);
spa_meta_bitmap->size.width = bitmap_width;
spa_meta_bitmap->size.height = bitmap_height;