diff options
author | Robert Mader <robert.mader@collabora.com> | 2022-10-18 15:40:19 +0200 |
---|---|---|
committer | Robert Mader <robert.mader@collabora.com> | 2023-01-06 13:53:08 +0100 |
commit | 5cb1cb03065b3a089b02faa7bbf016e026a937a9 (patch) | |
tree | cdb1a5891fd175f96e3969051f9494df421a0299 /src | |
parent | 9328bf523f246fd455f2f8864d5dbae99f5ad641 (diff) | |
download | mutter-5cb1cb03065b3a089b02faa7bbf016e026a937a9.tar.gz |
surface-actor-wayland: Clean up and optimize check for primary view
Avoid some allocations, save some CPU cycles and make the code easier
to read.
Behaviourwise the only expected change is that now, if there are mapped
clones, we unconditionally choose the view with the highest refresh
rate the actor (or one of its clones) is on and don't check the
obscurred region any more.
Thus in some cases a client may receive a higher rate of frame callbacks
when obscured on a faster view while a clone is present on a slower
one. The assumption is that cases like this are relatively rare and
that the reduction of code complexity, the reduction of allocations in
`meta_surface_actor_is_obscured_on_stage_view()` whenever the actor is
not fully obscured and has clones on other views, as well as generally
fewer lookups and less code in most common cases, compensate for that.
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2671>
(cherry picked from commit 292a8500ed45598d05fea954678e74cec9078e01)
Diffstat (limited to 'src')
-rw-r--r-- | src/compositor/meta-surface-actor-wayland.c | 77 | ||||
-rw-r--r-- | src/compositor/meta-surface-actor-wayland.h | 4 | ||||
-rw-r--r-- | src/wayland/meta-wayland-presentation-time.c | 6 | ||||
-rw-r--r-- | src/wayland/meta-wayland.c | 6 |
4 files changed, 54 insertions, 39 deletions
diff --git a/src/compositor/meta-surface-actor-wayland.c b/src/compositor/meta-surface-actor-wayland.c index ef2c9c242..ae60fb904 100644 --- a/src/compositor/meta-surface-actor-wayland.c +++ b/src/compositor/meta-surface-actor-wayland.c @@ -90,60 +90,79 @@ meta_surface_actor_wayland_try_acquire_scanout (MetaSurfaceActorWayland *self, #define UNOBSCURED_TRESHOLD 0.1 -ClutterStageView * -meta_surface_actor_wayland_get_current_primary_view (MetaSurfaceActor *actor, - ClutterStage *stage) +gboolean +meta_surface_actor_wayland_is_view_primary (MetaSurfaceActor *actor, + ClutterStageView *stage_view) { ClutterStageView *current_primary_view = NULL; float highest_refresh_rate = 0.f; float biggest_unobscurred_fraction = 0.f; GList *l; - for (l = clutter_stage_peek_stage_views (stage); l; l = l->next) + if (!clutter_actor_is_effectively_on_stage_view (CLUTTER_ACTOR (actor), + stage_view)) + return FALSE; + + if (clutter_actor_has_mapped_clones (CLUTTER_ACTOR (actor))) { - ClutterStageView *stage_view = l->data; - float refresh_rate; - float unobscurred_fraction = 1.f; + ClutterStage *stage; - if (clutter_actor_has_mapped_clones (CLUTTER_ACTOR (actor))) + stage = CLUTTER_STAGE (clutter_actor_get_stage (CLUTTER_ACTOR (actor))); + for (l = clutter_stage_peek_stage_views (stage); l; l = l->next) { + ClutterStageView *view = l->data; + float refresh_rate; + if (!clutter_actor_is_effectively_on_stage_view (CLUTTER_ACTOR (actor), - stage_view)) + view)) continue; - } - else - { - if (l->next || biggest_unobscurred_fraction > 0.f) - { - if (meta_surface_actor_is_obscured_on_stage_view (actor, - stage_view, - &unobscurred_fraction)) - continue; - } - else + + refresh_rate = clutter_stage_view_get_refresh_rate (view); + if (refresh_rate > highest_refresh_rate) { - if (meta_surface_actor_is_obscured (actor) || - !clutter_actor_is_effectively_on_stage_view (CLUTTER_ACTOR (actor), - stage_view)) - continue; + current_primary_view = view; + highest_refresh_rate = refresh_rate; } } - refresh_rate = clutter_stage_view_get_refresh_rate (stage_view); + return current_primary_view == stage_view; + } + + l = clutter_actor_peek_stage_views (CLUTTER_ACTOR (actor)); + g_return_val_if_fail (l, FALSE); + + if (!l->next) + { + g_return_val_if_fail (l->data == stage_view, FALSE); + return !meta_surface_actor_is_obscured (actor); + } + + for (; l; l = l->next) + { + ClutterStageView *view = l->data; + float refresh_rate; + float unobscurred_fraction; + + if (meta_surface_actor_is_obscured_on_stage_view (actor, + view, + &unobscurred_fraction)) + continue; + + refresh_rate = clutter_stage_view_get_refresh_rate (view); if ((refresh_rate > highest_refresh_rate && - (unobscurred_fraction > UNOBSCURED_TRESHOLD || - biggest_unobscurred_fraction < UNOBSCURED_TRESHOLD)) || + (biggest_unobscurred_fraction < UNOBSCURED_TRESHOLD || + unobscurred_fraction > UNOBSCURED_TRESHOLD)) || (biggest_unobscurred_fraction < UNOBSCURED_TRESHOLD && unobscurred_fraction > UNOBSCURED_TRESHOLD)) { - current_primary_view = stage_view; + current_primary_view = view; highest_refresh_rate = refresh_rate; biggest_unobscurred_fraction = unobscurred_fraction; } } - return current_primary_view; + return current_primary_view == stage_view; } static void diff --git a/src/compositor/meta-surface-actor-wayland.h b/src/compositor/meta-surface-actor-wayland.h index c8606931e..9203b2c72 100644 --- a/src/compositor/meta-surface-actor-wayland.h +++ b/src/compositor/meta-surface-actor-wayland.h @@ -53,8 +53,8 @@ void meta_surface_actor_wayland_add_frame_callbacks (MetaSurfaceActorWayland *se CoglScanout * meta_surface_actor_wayland_try_acquire_scanout (MetaSurfaceActorWayland *self, CoglOnscreen *onscreen); -ClutterStageView * meta_surface_actor_wayland_get_current_primary_view (MetaSurfaceActor *actor, - ClutterStage *stage); +gboolean meta_surface_actor_wayland_is_view_primary (MetaSurfaceActor *actor, + ClutterStageView *stage_view); G_END_DECLS diff --git a/src/wayland/meta-wayland-presentation-time.c b/src/wayland/meta-wayland-presentation-time.c index 70c90e0df..5f2f6ab66 100644 --- a/src/wayland/meta-wayland-presentation-time.c +++ b/src/wayland/meta-wayland-presentation-time.c @@ -156,7 +156,6 @@ on_after_paint (ClutterStage *stage, GList *l_cur = l; MetaWaylandSurface *surface = l->data; MetaSurfaceActor *actor; - ClutterStageView *surface_primary_view; l = l->next; @@ -164,9 +163,8 @@ on_after_paint (ClutterStage *stage, if (!actor) continue; - surface_primary_view = - meta_surface_actor_wayland_get_current_primary_view (actor, stage); - if (stage_view != surface_primary_view) + if (!meta_surface_actor_wayland_is_view_primary (actor, + stage_view)) continue; if (!wl_list_empty (&surface->presentation_time.feedback_list)) diff --git a/src/wayland/meta-wayland.c b/src/wayland/meta-wayland.c index ee6bcdec7..1ff771f6a 100644 --- a/src/wayland/meta-wayland.c +++ b/src/wayland/meta-wayland.c @@ -224,7 +224,6 @@ on_after_update (ClutterStage *stage, MetaWaylandSurface *surface = l->data; MetaSurfaceActor *actor; MetaWaylandActorSurface *actor_surface; - ClutterStageView *surface_primary_view; l = l->next; @@ -232,9 +231,8 @@ on_after_update (ClutterStage *stage, if (!actor) continue; - surface_primary_view = - meta_surface_actor_wayland_get_current_primary_view (actor, stage); - if (stage_view != surface_primary_view) + if (!meta_surface_actor_wayland_is_view_primary (actor, + stage_view)) continue; actor_surface = META_WAYLAND_ACTOR_SURFACE (surface->role); |