wayland: Replace manual GNode subsurface iteration with macro

Similar to wl_list_foreach(), add
META_WAYLAND_SURFACE_FOREACH_SUBSURFACE() that iterates over all the
subsurfaces of a surface, without the caller needing to care about
implementation details, such as leaf nodes vs non-leaf nodes.

https://gitlab.gnome.org/GNOME/mutter/merge_requests/961
This commit is contained in:
Jonas Ådahl 2019-12-06 18:22:47 +01:00 committed by Georges Basile Stavracas Neto
parent 76ee026caa
commit fcfe90aa9f
7 changed files with 58 additions and 75 deletions

View File

@ -147,9 +147,9 @@ meta_wayland_actor_surface_real_sync_actor_state (MetaWaylandActorSurface *actor
meta_wayland_surface_role_get_surface (surface_role);
MetaSurfaceActor *surface_actor;
MetaShapedTexture *stex;
GNode *n;
cairo_rectangle_int_t surface_rect;
int geometry_scale;
MetaWaylandSurface *subsurface_surface;
surface_actor = priv->actor;
stex = meta_surface_actor_get_texture (surface_actor);
@ -213,19 +213,12 @@ meta_wayland_actor_surface_real_sync_actor_state (MetaWaylandActorSurface *actor
meta_surface_actor_reset_viewport_dst_size (surface_actor);
}
for (n = g_node_first_child (surface->subsurface_branch_node);
n;
n = g_node_next_sibling (n))
META_WAYLAND_SURFACE_FOREACH_SUBSURFACE (surface, subsurface_surface)
{
MetaWaylandSurface *subsurface_surface = n->data;
MetaWaylandActorSurface *subsurface_actor_surface;
MetaWaylandActorSurface *actor_surface;
if (G_NODE_IS_LEAF (n))
continue;
subsurface_actor_surface =
META_WAYLAND_ACTOR_SURFACE (subsurface_surface->role);
meta_wayland_actor_surface_sync_actor_state (subsurface_actor_surface);
actor_surface = META_WAYLAND_ACTOR_SURFACE (subsurface_surface->role);
meta_wayland_actor_surface_sync_actor_state (actor_surface);
}
}

View File

@ -1205,20 +1205,13 @@ static gboolean
pointer_can_grab_surface (MetaWaylandPointer *pointer,
MetaWaylandSurface *surface)
{
GNode *n;
MetaWaylandSurface *subsurface;
if (pointer->focus_surface == surface)
return TRUE;
for (n = g_node_first_child (surface->subsurface_branch_node);
n;
n = g_node_next_sibling (n))
META_WAYLAND_SURFACE_FOREACH_SUBSURFACE (surface, subsurface)
{
MetaWaylandSurface *subsurface = n->data;
if (G_NODE_IS_LEAF (n))
continue;
if (pointer_can_grab_surface (pointer, subsurface))
return TRUE;
}

View File

@ -43,23 +43,17 @@ meta_wayland_shell_surface_calculate_geometry (MetaWaylandShellSurface *shell_su
MetaWaylandSurface *surface =
meta_wayland_surface_role_get_surface (surface_role);
MetaRectangle geometry;
GNode *n;
MetaWaylandSurface *subsurface_surface;
geometry = (MetaRectangle) {
.width = meta_wayland_surface_get_width (surface),
.height = meta_wayland_surface_get_height (surface),
};
for (n = g_node_first_child (surface->subsurface_branch_node);
n;
n = g_node_next_sibling (n))
META_WAYLAND_SURFACE_FOREACH_SUBSURFACE (surface, subsurface_surface)
{
MetaWaylandSurface *subsurface_surface = n->data;
MetaWaylandSubsurface *subsurface;
if (G_NODE_IS_LEAF (n))
continue;
subsurface = META_WAYLAND_SUBSURFACE (subsurface_surface->role);
meta_wayland_subsurface_union_geometry (subsurface,
0, 0,

View File

@ -204,7 +204,7 @@ meta_wayland_subsurface_union_geometry (MetaWaylandSubsurface *subsurface,
MetaWaylandSurface *surface =
meta_wayland_surface_role_get_surface (surface_role);
MetaRectangle geometry;
GNode *n;
MetaWaylandSurface *subsurface_surface;
geometry = (MetaRectangle) {
.x = surface->offset_x + surface->sub.x,
@ -215,16 +215,10 @@ meta_wayland_subsurface_union_geometry (MetaWaylandSubsurface *subsurface,
meta_rectangle_union (out_geometry, &geometry, out_geometry);
for (n = g_node_first_child (surface->subsurface_branch_node);
n;
n = g_node_next_sibling (n))
META_WAYLAND_SURFACE_FOREACH_SUBSURFACE (surface, subsurface_surface)
{
MetaWaylandSurface *subsurface_surface = n->data;
MetaWaylandSubsurface *subsurface;
if (G_NODE_IS_LEAF (n))
continue;
subsurface = META_WAYLAND_SUBSURFACE (subsurface_surface->role);
meta_wayland_subsurface_union_geometry (subsurface,
parent_x + geometry.x,

View File

@ -600,20 +600,6 @@ meta_wayland_surface_state_class_init (MetaWaylandSurfaceStateClass *klass)
G_TYPE_NONE, 0);
}
static void
parent_surface_state_applied (GNode *subsurface_node,
gpointer user_data)
{
MetaWaylandSurface *surface = subsurface_node->data;
MetaWaylandSubsurface *subsurface;
if (G_NODE_IS_LEAF (subsurface_node))
return;
subsurface = META_WAYLAND_SUBSURFACE (surface->role);
meta_wayland_subsurface_parent_state_applied (subsurface);
}
void
meta_wayland_surface_cache_pending_frame_callbacks (MetaWaylandSurface *surface,
MetaWaylandSurfaceState *pending)
@ -627,6 +613,7 @@ static void
meta_wayland_surface_apply_state (MetaWaylandSurface *surface,
MetaWaylandSurfaceState *state)
{
MetaWaylandSurface *subsurface_surface;
gboolean had_damage = FALSE;
g_signal_emit (surface, surface_signals[SURFACE_PRE_STATE_APPLIED], 0);
@ -802,10 +789,13 @@ cleanup:
meta_wayland_surface_state_reset (state);
g_node_children_foreach (surface->subsurface_branch_node,
G_TRAVERSE_ALL,
parent_surface_state_applied,
NULL);
META_WAYLAND_SURFACE_FOREACH_SUBSURFACE (surface, subsurface_surface)
{
MetaWaylandSubsurface *subsurface;
subsurface = META_WAYLAND_SUBSURFACE (subsurface_surface->role);
meta_wayland_subsurface_parent_state_applied (subsurface);
}
if (had_damage)
{
@ -1287,22 +1277,14 @@ meta_wayland_surface_update_outputs (MetaWaylandSurface *surface)
static void
meta_wayland_surface_update_outputs_recursively (MetaWaylandSurface *surface)
{
GNode *n;
MetaWaylandSurface *subsurface_surface;
meta_wayland_surface_update_outputs (surface);
for (n = g_node_first_child (surface->subsurface_branch_node);
n;
n = g_node_next_sibling (n))
{
if (G_NODE_IS_LEAF (n))
continue;
meta_wayland_surface_update_outputs_recursively (n->data);
}
META_WAYLAND_SURFACE_FOREACH_SUBSURFACE (surface, subsurface_surface)
meta_wayland_surface_update_outputs_recursively (subsurface_surface);
}
void
meta_wayland_surface_set_window (MetaWaylandSurface *surface,
MetaWindow *window)

View File

@ -328,4 +328,38 @@ void meta_wayland_surface_notify_geometry_changed (MetaWaylandSur
int meta_wayland_surface_get_width (MetaWaylandSurface *surface);
int meta_wayland_surface_get_height (MetaWaylandSurface *surface);
static inline GNode *
meta_get_next_subsurface_sibling (GNode *n)
{
GNode *next;
if (!n)
return NULL;
next = g_node_next_sibling (n);
if (!next)
return NULL;
if (!G_NODE_IS_LEAF (next))
return next;
else
return meta_get_next_subsurface_sibling (next);
}
static inline GNode *
meta_get_first_subsurface_node (MetaWaylandSurface *surface)
{
GNode *n;
n = g_node_first_child (surface->subsurface_branch_node);
if (!G_NODE_IS_LEAF (n))
return n;
else
return meta_get_next_subsurface_sibling (n);
}
#define META_WAYLAND_SURFACE_FOREACH_SUBSURFACE(surface, subsurface) \
for (GNode *G_PASTE(__n, __LINE__) = meta_get_first_subsurface_node ((surface)); \
(subsurface = (G_PASTE (__n, __LINE__) ? G_PASTE (__n, __LINE__)->data : NULL)); \
G_PASTE (__n, __LINE__) = meta_get_next_subsurface_sibling (G_PASTE (__n, __LINE__)))
#endif

View File

@ -989,20 +989,13 @@ static gboolean
tablet_tool_can_grab_surface (MetaWaylandTabletTool *tool,
MetaWaylandSurface *surface)
{
GNode *n;
MetaWaylandSurface *subsurface;
if (tool->focus_surface == surface)
return TRUE;
for (n = g_node_first_child (surface->subsurface_branch_node);
n;
n = g_node_next_sibling (n))
META_WAYLAND_SURFACE_FOREACH_SUBSURFACE (surface, subsurface)
{
MetaWaylandSurface *subsurface = n->data;
if (G_NODE_IS_LEAF (n))
continue;
if (tablet_tool_can_grab_surface (tool, subsurface))
return TRUE;
}