From 742d026479230a41f74956f040781547a6009021 Mon Sep 17 00:00:00 2001 From: msizanoen Date: Mon, 5 Jun 2023 21:55:24 +0700 Subject: [PATCH] shaped-texture: Introduce get_unscaled_{width,height} This allows other code to obtain the size of the surface after all transformations except for scaling. Part-of: --- src/compositor/meta-shaped-texture-private.h | 3 + src/compositor/meta-shaped-texture.c | 62 ++++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/src/compositor/meta-shaped-texture-private.h b/src/compositor/meta-shaped-texture-private.h index ff5f2fa96..f9f22f510 100644 --- a/src/compositor/meta-shaped-texture-private.h +++ b/src/compositor/meta-shaped-texture-private.h @@ -66,6 +66,9 @@ gboolean meta_shaped_texture_update_area (MetaShapedTexture *stex, int meta_shaped_texture_get_width (MetaShapedTexture *stex); int meta_shaped_texture_get_height (MetaShapedTexture *stex); +float meta_shaped_texture_get_unscaled_width (MetaShapedTexture *stex); +float meta_shaped_texture_get_unscaled_height (MetaShapedTexture *stex); + void meta_shaped_texture_set_clip_region (MetaShapedTexture *stex, cairo_region_t *clip_region); void meta_shaped_texture_set_opaque_region (MetaShapedTexture *stex, diff --git a/src/compositor/meta-shaped-texture.c b/src/compositor/meta-shaped-texture.c index 7f594a5d8..8eaf3238b 100644 --- a/src/compositor/meta-shaped-texture.c +++ b/src/compositor/meta-shaped-texture.c @@ -1491,3 +1491,65 @@ meta_shaped_texture_get_height (MetaShapedTexture *stex) return stex->dst_height; } + +static graphene_size_t +get_unscaled_size (MetaShapedTexture *stex) +{ + graphene_size_t buffer_size; + + if (stex->has_viewport_src_rect) + { + graphene_size_scale (&stex->viewport_src_rect.size, + stex->buffer_scale, + &buffer_size); + } + else + { + buffer_size = (graphene_size_t) { + .width = stex->tex_width, + .height = stex->tex_height, + }; + } + + if (meta_monitor_transform_is_rotated (stex->transform)) + { + return (graphene_size_t) { + .width = buffer_size.height, + .height = buffer_size.width, + }; + } + else + { + return buffer_size; + } +} + +/** + * meta_shaped_texture_get_unscaled_width: + * @stex: A #MetaShapedTexture + * + * Returns: The unscaled width of @stex after its shaping operations are applied. + */ +float +meta_shaped_texture_get_unscaled_width (MetaShapedTexture *stex) +{ + g_return_val_if_fail (META_IS_SHAPED_TEXTURE (stex), 0); + graphene_size_t unscaled_size = get_unscaled_size (stex); + + return unscaled_size.width; +} + +/** + * meta_shaped_texture_get_unscaled_height: + * @stex: A #MetaShapedTexture + * + * Returns: The unscaled height of @stex after its shaping operations are applied. + */ +float +meta_shaped_texture_get_unscaled_height (MetaShapedTexture *stex) +{ + g_return_val_if_fail (META_IS_SHAPED_TEXTURE (stex), 0); + graphene_size_t unscaled_size = get_unscaled_size (stex); + + return unscaled_size.height; +}