From f7e256e9a1363330d406d0d6f73ee75c498c1bdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Wed, 13 Mar 2019 14:42:40 +0100 Subject: [PATCH] wayland/surface: Make cached subsurface state generic This moves the cached subsurface surface state into the generic MetaWaylandSurface namespace. Eventually it'll be used by other surface roles which as well aim to implement synhcronization. https://gitlab.gnome.org/GNOME/mutter/merge_requests/907 --- src/wayland/meta-wayland-subsurface.c | 6 ++--- src/wayland/meta-wayland-surface.c | 32 ++++++++++++++++++++++++--- src/wayland/meta-wayland-surface.h | 9 +++++--- 3 files changed, 37 insertions(+), 10 deletions(-) diff --git a/src/wayland/meta-wayland-subsurface.c b/src/wayland/meta-wayland-subsurface.c index a33c8ef89..dfd455496 100644 --- a/src/wayland/meta-wayland-subsurface.c +++ b/src/wayland/meta-wayland-subsurface.c @@ -189,7 +189,7 @@ meta_wayland_subsurface_parent_state_applied (MetaWaylandSubsurface *subsurface) } if (is_surface_effectively_synchronized (surface)) - meta_wayland_surface_apply_state (surface, surface->sub.pending); + meta_wayland_surface_apply_cached_state (surface); meta_wayland_actor_surface_sync_actor_state (actor_surface); } @@ -356,7 +356,6 @@ wl_subsurface_destructor (struct wl_resource *resource) surface->sub.parent = NULL; } - g_clear_object (&surface->sub.pending); surface->wl_subsurface = NULL; } @@ -485,7 +484,7 @@ wl_subsurface_set_desync (struct wl_client *client, if (was_effectively_synchronized && !is_surface_effectively_synchronized (surface)) - meta_wayland_surface_apply_state (surface, surface->sub.pending); + meta_wayland_surface_apply_cached_state (surface); } static const struct wl_subsurface_interface meta_wayland_wl_subsurface_interface = { @@ -561,7 +560,6 @@ wl_subcompositor_get_subsurface (struct wl_client *client, surface, wl_subsurface_destructor); - surface->sub.pending = g_object_new (META_TYPE_WAYLAND_SURFACE_STATE, NULL); surface->sub.synchronous = TRUE; surface->sub.parent = parent; surface->sub.parent_destroy_listener.notify = diff --git a/src/wayland/meta-wayland-surface.c b/src/wayland/meta-wayland-surface.c index 09d83a31d..1f4727ece 100644 --- a/src/wayland/meta-wayland-surface.c +++ b/src/wayland/meta-wayland-surface.c @@ -616,7 +616,7 @@ meta_wayland_surface_cache_pending_frame_callbacks (MetaWaylandSurface *sur wl_list_init (&pending->frame_callback_list); } -void +static void meta_wayland_surface_apply_state (MetaWaylandSurface *surface, MetaWaylandSurfaceState *state) { @@ -817,12 +817,30 @@ cleanup: } } +void +meta_wayland_surface_apply_cached_state (MetaWaylandSurface *surface) +{ + if (!surface->cached_state) + return; + + meta_wayland_surface_apply_state (surface, surface->cached_state); +} + MetaWaylandSurfaceState * meta_wayland_surface_get_pending_state (MetaWaylandSurface *surface) { return surface->pending_state; } +MetaWaylandSurfaceState * +meta_wayland_surface_ensure_cached_state (MetaWaylandSurface *surface) +{ + if (!surface->cached_state) + surface->cached_state = g_object_new (META_TYPE_WAYLAND_SURFACE_STATE, + NULL); + return surface->cached_state; +} + static void meta_wayland_surface_commit (MetaWaylandSurface *surface) { @@ -844,9 +862,16 @@ meta_wayland_surface_commit (MetaWaylandSurface *surface) * surface is in effective desynchronized mode. */ if (meta_wayland_surface_should_cache_state (surface)) - meta_wayland_surface_state_merge_into (pending, surface->sub.pending); + { + MetaWaylandSurfaceState *cached_state; + + cached_state = meta_wayland_surface_ensure_cached_state (surface); + meta_wayland_surface_state_merge_into (pending, cached_state); + } else - meta_wayland_surface_apply_state (surface, surface->pending_state); + { + meta_wayland_surface_apply_state (surface, surface->pending_state); + } } static void @@ -1344,6 +1369,7 @@ wl_surface_destructor (struct wl_resource *resource) g_clear_pointer (&surface->texture, cogl_object_unref); g_clear_object (&surface->buffer_ref.buffer); + g_clear_object (&surface->cached_state); g_clear_object (&surface->pending_state); if (surface->opaque_region) diff --git a/src/wayland/meta-wayland-surface.h b/src/wayland/meta-wayland-surface.h index 9a8c8f793..41fe47ca4 100644 --- a/src/wayland/meta-wayland-surface.h +++ b/src/wayland/meta-wayland-surface.h @@ -176,6 +176,8 @@ struct _MetaWaylandSurface /* All the pending state that wl_surface.commit will apply. */ MetaWaylandSurfaceState *pending_state; + /* State cached due to inter-surface synchronization such. */ + MetaWaylandSurfaceState *cached_state; /* Extension resources. */ struct wl_resource *wl_subsurface; @@ -197,7 +199,6 @@ struct _MetaWaylandSurface * state here. */ gboolean synchronous; - MetaWaylandSurfaceState *pending; int32_t pending_x; int32_t pending_y; @@ -232,8 +233,10 @@ MetaWaylandSurface *meta_wayland_surface_create (MetaWaylandCompositor *composit MetaWaylandSurfaceState * meta_wayland_surface_get_pending_state (MetaWaylandSurface *surface); -void meta_wayland_surface_apply_state (MetaWaylandSurface *surface, - MetaWaylandSurfaceState *state); +MetaWaylandSurfaceState * + meta_wayland_surface_ensure_cached_state (MetaWaylandSurface *surface); + +void meta_wayland_surface_apply_cached_state (MetaWaylandSurface *surface); gboolean meta_wayland_surface_is_effectively_synchronized (MetaWaylandSurface *surface);