[mutter] wayland: Replace manual GNode subsurface iteration with macro
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter] wayland: Replace manual GNode subsurface iteration with macro
- Date: Fri, 10 Jan 2020 16:09:29 +0000 (UTC)
commit fcfe90aa9fe0db130c94ae3fe5cee38daba20a50
Author: Jonas Ã…dahl <jadahl gmail com>
Date: Fri Dec 6 18:22:47 2019 +0100
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
src/wayland/meta-wayland-actor-surface.c | 17 ++++----------
src/wayland/meta-wayland-pointer.c | 11 ++-------
src/wayland/meta-wayland-shell-surface.c | 10 ++------
src/wayland/meta-wayland-subsurface.c | 10 ++------
src/wayland/meta-wayland-surface.c | 40 +++++++++-----------------------
src/wayland/meta-wayland-surface.h | 34 +++++++++++++++++++++++++++
src/wayland/meta-wayland-tablet-tool.c | 11 ++-------
7 files changed, 58 insertions(+), 75 deletions(-)
---
diff --git a/src/wayland/meta-wayland-actor-surface.c b/src/wayland/meta-wayland-actor-surface.c
index 41802473b..fe80e8c8b 100644
--- a/src/wayland/meta-wayland-actor-surface.c
+++ b/src/wayland/meta-wayland-actor-surface.c
@@ -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);
}
}
diff --git a/src/wayland/meta-wayland-pointer.c b/src/wayland/meta-wayland-pointer.c
index bb4dbceb7..325467f27 100644
--- a/src/wayland/meta-wayland-pointer.c
+++ b/src/wayland/meta-wayland-pointer.c
@@ -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;
}
diff --git a/src/wayland/meta-wayland-shell-surface.c b/src/wayland/meta-wayland-shell-surface.c
index b391186f8..c2022a736 100644
--- a/src/wayland/meta-wayland-shell-surface.c
+++ b/src/wayland/meta-wayland-shell-surface.c
@@ -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,
diff --git a/src/wayland/meta-wayland-subsurface.c b/src/wayland/meta-wayland-subsurface.c
index dfd455496..38ae6d979 100644
--- a/src/wayland/meta-wayland-subsurface.c
+++ b/src/wayland/meta-wayland-subsurface.c
@@ -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,
diff --git a/src/wayland/meta-wayland-surface.c b/src/wayland/meta-wayland-surface.c
index f16a679a9..e5d8c1ab1 100644
--- a/src/wayland/meta-wayland-surface.c
+++ b/src/wayland/meta-wayland-surface.c
@@ -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)
diff --git a/src/wayland/meta-wayland-surface.h b/src/wayland/meta-wayland-surface.h
index fee58734b..b75b0708d 100644
--- a/src/wayland/meta-wayland-surface.h
+++ b/src/wayland/meta-wayland-surface.h
@@ -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
diff --git a/src/wayland/meta-wayland-tablet-tool.c b/src/wayland/meta-wayland-tablet-tool.c
index 01a370b9e..e960cc63b 100644
--- a/src/wayland/meta-wayland-tablet-tool.c
+++ b/src/wayland/meta-wayland-tablet-tool.c
@@ -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;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]