wayland/surface: Move subsurface synchronization logic to role

It's an implementation detail of subsurfaces when to cache state
and when not to, so move that logic to the subsurface role
implementation.

https://gitlab.gnome.org/GNOME/mutter/merge_requests/907
This commit is contained in:
Jonas Ådahl 2019-03-13 12:26:22 +01:00
parent 0cf98c5641
commit 8dc730e5ca
3 changed files with 52 additions and 34 deletions

View File

@ -112,6 +112,12 @@ is_sibling (MetaWaylandSurface *surface,
return FALSE;
}
static gboolean
is_surface_effectively_synchronized (MetaWaylandSurface *surface)
{
return meta_wayland_surface_should_cache_state (surface);
}
void
meta_wayland_subsurface_parent_state_applied (MetaWaylandSubsurface *subsurface)
{
@ -182,7 +188,7 @@ meta_wayland_subsurface_parent_state_applied (MetaWaylandSubsurface *subsurface)
meta_window_actor_wayland_rebuild_surface_tree (window_actor);
}
if (meta_wayland_surface_is_effectively_synchronized (surface))
if (is_surface_effectively_synchronized (surface))
meta_wayland_surface_apply_pending_state (surface, surface->sub.pending);
meta_wayland_actor_surface_sync_actor_state (actor_surface);
@ -240,6 +246,23 @@ meta_wayland_subsurface_get_toplevel (MetaWaylandSurfaceRole *surface_role)
return NULL;
}
static gboolean
meta_wayland_subsurface_should_cache_state (MetaWaylandSurfaceRole *surface_role)
{
MetaWaylandSurface *surface =
meta_wayland_surface_role_get_surface (surface_role);
MetaWaylandSurface *parent;
if (surface->sub.synchronous)
return TRUE;
parent = surface->sub.parent;
if (parent)
return meta_wayland_surface_should_cache_state (parent);
return TRUE;
}
static double
meta_wayland_subsurface_get_geometry_scale (MetaWaylandActorSurface *actor_surface)
{
@ -294,6 +317,7 @@ meta_wayland_subsurface_class_init (MetaWaylandSubsurfaceClass *klass)
META_WAYLAND_ACTOR_SURFACE_CLASS (klass);
surface_role_class->get_toplevel = meta_wayland_subsurface_get_toplevel;
surface_role_class->should_cache_state = meta_wayland_subsurface_should_cache_state;
actor_surface_class->get_geometry_scale =
meta_wayland_subsurface_get_geometry_scale;
@ -456,12 +480,11 @@ wl_subsurface_set_desync (struct wl_client *client,
MetaWaylandSurface *surface = wl_resource_get_user_data (resource);
gboolean was_effectively_synchronized;
was_effectively_synchronized =
meta_wayland_surface_is_effectively_synchronized (surface);
was_effectively_synchronized = is_surface_effectively_synchronized (surface);
surface->sub.synchronous = FALSE;
if (was_effectively_synchronized &&
!meta_wayland_surface_is_effectively_synchronized (surface))
!is_surface_effectively_synchronized (surface))
meta_wayland_surface_apply_pending_state (surface, surface->sub.pending);
}

View File

@ -593,35 +593,6 @@ meta_wayland_pending_state_class_init (MetaWaylandPendingStateClass *klass)
G_TYPE_NONE, 0);
}
/* A non-subsurface is always desynchronized.
*
* A subsurface is effectively synchronized if either its parent is
* synchronized or itself is in synchronized mode. */
gboolean
meta_wayland_surface_is_effectively_synchronized (MetaWaylandSurface *surface)
{
if (surface->wl_subsurface == NULL)
{
return FALSE;
}
else
{
if (surface->sub.synchronous)
{
return TRUE;
}
else
{
MetaWaylandSurface *parent = surface->sub.parent;
if (parent)
return meta_wayland_surface_is_effectively_synchronized (parent);
return TRUE;
}
}
}
static void
parent_surface_state_applied (GNode *subsurface_node,
gpointer user_data)
@ -864,7 +835,7 @@ meta_wayland_surface_commit (MetaWaylandSurface *surface)
* 2) Its mode changes from synchronized to desynchronized and its parent
* surface is in effective desynchronized mode.
*/
if (meta_wayland_surface_is_effectively_synchronized (surface))
if (meta_wayland_surface_should_cache_state (surface))
merge_pending_state (surface->pending, surface->sub.pending);
else
meta_wayland_surface_apply_pending_state (surface, surface->pending);
@ -1846,6 +1817,27 @@ meta_wayland_surface_role_get_toplevel (MetaWaylandSurfaceRole *surface_role)
return NULL;
}
static gboolean
meta_wayland_surface_role_should_cache_state (MetaWaylandSurfaceRole *surface_role)
{
MetaWaylandSurfaceRoleClass *klass;
klass = META_WAYLAND_SURFACE_ROLE_GET_CLASS (surface_role);
if (klass->should_cache_state)
return klass->should_cache_state (surface_role);
else
return FALSE;
}
gboolean
meta_wayland_surface_should_cache_state (MetaWaylandSurface *surface)
{
if (!surface->role)
return FALSE;
return meta_wayland_surface_role_should_cache_state (surface->role);
}
MetaWaylandSurface *
meta_wayland_surface_role_get_surface (MetaWaylandSurfaceRole *role)
{

View File

@ -63,6 +63,7 @@ struct _MetaWaylandSurfaceRoleClass
gboolean (*is_on_logical_monitor) (MetaWaylandSurfaceRole *surface_role,
MetaLogicalMonitor *logical_monitor);
MetaWaylandSurface * (*get_toplevel) (MetaWaylandSurfaceRole *surface_role);
gboolean (*should_cache_state) (MetaWaylandSurfaceRole *surface_role);
};
struct _MetaWaylandSerial {
@ -273,6 +274,8 @@ void meta_wayland_surface_update_outputs (MetaWaylandSurface *sur
MetaWaylandSurface *meta_wayland_surface_get_toplevel (MetaWaylandSurface *surface);
gboolean meta_wayland_surface_should_cache_state (MetaWaylandSurface *surface);
MetaWindow * meta_wayland_surface_get_toplevel_window (MetaWaylandSurface *surface);
void meta_wayland_surface_cache_pending_frame_callbacks (MetaWaylandSurface *surface,