From 5772c27e04c3b1ad5dd8bcbacc75f3025a776d09 Mon Sep 17 00:00:00 2001 From: Robert Mader Date: Tue, 23 Mar 2021 10:12:09 +0100 Subject: [PATCH] shaped-texture: Expose ensure_size_valid() API When the texture size is invalidated using `invalidate_size()`, the new size will only get calculated the next time `update_size()` is called. This happens e.g. in `meta_shaped_texture_get_preferred_size()` via `ensure_size_valid()`. `update_size()` can chain up to `clutter_content_invalidate_size()` as well as emitting a `size-changed` signal. If this happens during layout, the result is a 'change the layout conditions during layout' issue, causing heavy breakage in e.g. the Shell overview. To fix this, expose `ensure_size_valid()` as API so callers can make sure the texture has a valid size without creating redundant size invalidations calls. Note that if a buffer with a new size is attached we already trigger `update_size()` explicitely, avoiding such situations. Part-of: --- src/compositor/meta-shaped-texture-private.h | 2 ++ src/compositor/meta-shaped-texture.c | 18 +++++++++--------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/compositor/meta-shaped-texture-private.h b/src/compositor/meta-shaped-texture-private.h index 672f24eb7..2fe1b8ea4 100644 --- a/src/compositor/meta-shaped-texture-private.h +++ b/src/compositor/meta-shaped-texture-private.h @@ -71,4 +71,6 @@ void meta_shaped_texture_set_clip_region (MetaShapedTexture *stex, void meta_shaped_texture_set_opaque_region (MetaShapedTexture *stex, cairo_region_t *opaque_region); +void meta_shaped_texture_ensure_size_valid (MetaShapedTexture *stex); + #endif diff --git a/src/compositor/meta-shaped-texture.c b/src/compositor/meta-shaped-texture.c index 6f1f918f8..8614f1fd4 100644 --- a/src/compositor/meta-shaped-texture.c +++ b/src/compositor/meta-shaped-texture.c @@ -220,8 +220,8 @@ update_size (MetaShapedTexture *stex) } } -static void -ensure_size_valid (MetaShapedTexture *stex) +void +meta_shaped_texture_ensure_size_valid (MetaShapedTexture *stex) { if (stex->size_invalid) update_size (stex); @@ -600,7 +600,7 @@ do_paint_content (MetaShapedTexture *stex, int sample_width, sample_height; gboolean debug_paint_opaque_region; - ensure_size_valid (stex); + meta_shaped_texture_ensure_size_valid (stex); dst_width = stex->dst_width; dst_height = stex->dst_height; @@ -914,7 +914,7 @@ meta_shaped_texture_get_preferred_size (ClutterContent *content, { MetaShapedTexture *stex = META_SHAPED_TEXTURE (content); - ensure_size_valid (stex); + meta_shaped_texture_ensure_size_valid (stex); if (width) *width = stex->dst_width; @@ -1006,7 +1006,7 @@ meta_shaped_texture_update_area (MetaShapedTexture *stex, clip); inverted_transform = meta_monitor_transform_invert (stex->transform); - ensure_size_valid (stex); + meta_shaped_texture_ensure_size_valid (stex); meta_rectangle_transform (clip, inverted_transform, stex->dst_width, @@ -1219,7 +1219,7 @@ meta_shaped_texture_is_opaque (MetaShapedTexture *stex) cairo_region_get_extents (stex->opaque_region, &opaque_rect); - ensure_size_valid (stex); + meta_shaped_texture_ensure_size_valid (stex); return meta_rectangle_equal (&opaque_rect, &(MetaRectangle) { @@ -1485,7 +1485,7 @@ meta_shaped_texture_get_image (MetaShapedTexture *stex, if (texture == NULL) return NULL; - ensure_size_valid (stex); + meta_shaped_texture_ensure_size_valid (stex); if (stex->dst_width == 0 || stex->dst_height == 0) return NULL; @@ -1643,7 +1643,7 @@ meta_shaped_texture_get_width (MetaShapedTexture *stex) { g_return_val_if_fail (META_IS_SHAPED_TEXTURE (stex), 0); - ensure_size_valid (stex); + meta_shaped_texture_ensure_size_valid (stex); return stex->dst_width; } @@ -1659,7 +1659,7 @@ meta_shaped_texture_get_height (MetaShapedTexture *stex) { g_return_val_if_fail (META_IS_SHAPED_TEXTURE (stex), 0); - ensure_size_valid (stex); + meta_shaped_texture_ensure_size_valid (stex); return stex->dst_height; }