From ae8acc9980fff5711590ea79c7a38336f0debaf5 Mon Sep 17 00:00:00 2001 From: Robert Mader Date: Sun, 28 Jun 2020 23:56:21 +0200 Subject: [PATCH] surface-actor: Add culling offset for geometry scale - take 2 41130b08eb added a fix for culling subsurfaces with geometry scale. Unfortunately it only did so for the opaque regions, not for clip and unobscured regions, as the effect was hidden by bug that was only fixed by 3187fe8ebc7. Apply the same fix to clip and unobscured regions and use the chance to move most of the slightly hackish geometry scale related code into a single place. We need to scale slightly differently in the two cases, indicated by the new `ScalePerspectiveType` enum, as the scale is dependent on the perspective - once from outside, once from inside of the scaled actor. Closes https://gitlab.gnome.org/GNOME/mutter/-/issues/1312 (cherry picked from commit 86646679f14458ce567f547595ca2f93fb795c4a) --- src/compositor/meta-surface-actor.c | 62 +++++++++++++++++++---------- 1 file changed, 42 insertions(+), 20 deletions(-) diff --git a/src/compositor/meta-surface-actor.c b/src/compositor/meta-surface-actor.c index 105258954..5b328dcd3 100644 --- a/src/compositor/meta-surface-actor.c +++ b/src/compositor/meta-surface-actor.c @@ -57,6 +57,12 @@ enum static guint signals[LAST_SIGNAL]; +typedef enum +{ + IN_STAGE_PERSPECTIVE, + IN_ACTOR_PERSPECTIVE +} ScalePerspectiveType; + static cairo_region_t * effective_unobscured_region (MetaSurfaceActor *surface_actor) { @@ -78,18 +84,39 @@ effective_unobscured_region (MetaSurfaceActor *surface_actor) } static cairo_region_t* -get_scaled_region (MetaSurfaceActor *surface_actor, - cairo_region_t *region) +get_scaled_region (MetaSurfaceActor *surface_actor, + cairo_region_t *region, + ScalePerspectiveType scale_perspective) { MetaWindowActor *window_actor; + cairo_region_t *scaled_region; int geometry_scale; + float x, y; window_actor = meta_window_actor_from_actor (CLUTTER_ACTOR (surface_actor)); geometry_scale = meta_window_actor_get_geometry_scale (window_actor); - return meta_region_scale_double (region, - 1.0 / geometry_scale, - META_ROUNDING_STRATEGY_GROW); + clutter_actor_get_position (CLUTTER_ACTOR (surface_actor), &x, &y); + cairo_region_translate (region, x, y); + + switch (scale_perspective) + { + case IN_STAGE_PERSPECTIVE: + scaled_region = meta_region_scale_double (region, + geometry_scale, + META_ROUNDING_STRATEGY_GROW); + break; + case IN_ACTOR_PERSPECTIVE: + scaled_region = meta_region_scale_double (region, + 1.0 / geometry_scale, + META_ROUNDING_STRATEGY_GROW); + break; + } + + cairo_region_translate (region, -x, -y); + cairo_region_translate (scaled_region, -x, -y); + + return scaled_region; } static void @@ -119,8 +146,9 @@ set_unobscured_region (MetaSurfaceActor *surface_actor, .height = height, }; - priv->unobscured_region = - get_scaled_region (surface_actor, unobscured_region); + priv->unobscured_region = get_scaled_region (surface_actor, + unobscured_region, + IN_ACTOR_PERSPECTIVE); cairo_region_intersect_rectangle (priv->unobscured_region, &bounds); } @@ -139,7 +167,9 @@ set_clip_region (MetaSurfaceActor *surface_actor, { cairo_region_t *region; - region = get_scaled_region (surface_actor, clip_region); + region = get_scaled_region (surface_actor, + clip_region, + IN_ACTOR_PERSPECTIVE); meta_shaped_texture_set_clip_region (stex, region); cairo_region_destroy (region); @@ -267,11 +297,8 @@ meta_surface_actor_cull_out (MetaCullable *cullable, if (opacity == 0xff) { - MetaWindowActor *window_actor; - cairo_region_t *scaled_opaque_region; cairo_region_t *opaque_region; - int geometry_scale; - float x, y; + cairo_region_t *scaled_opaque_region; opaque_region = meta_shaped_texture_get_opaque_region (priv->texture); if (opaque_region) @@ -294,14 +321,9 @@ meta_surface_actor_cull_out (MetaCullable *cullable, return; } - window_actor = meta_window_actor_from_actor (CLUTTER_ACTOR (surface_actor)); - geometry_scale = meta_window_actor_get_geometry_scale (window_actor); - clutter_actor_get_position (CLUTTER_ACTOR (surface_actor), &x, &y); - - cairo_region_translate (opaque_region, x, y); - scaled_opaque_region = meta_region_scale (opaque_region, geometry_scale); - cairo_region_translate (scaled_opaque_region, -x, -y); - cairo_region_translate (opaque_region, -x, -y); + scaled_opaque_region = get_scaled_region (surface_actor, + opaque_region, + IN_STAGE_PERSPECTIVE); if (unobscured_region) cairo_region_subtract (unobscured_region, scaled_opaque_region);