Blob Blame History Raw
From 6d849de8ff486be21ff931bfa63313240b212852 Mon Sep 17 00:00:00 2001
From: Christian Hergert <christian@hergert.me>
Date: Fri, 21 Feb 2020 22:36:31 +0000
Subject: [PATCH 3/3] clutter: fix hole in ClutterPaintNode

Fixing the missalignment takes the structure from 80 bytes down to 72.

https://gitlab.gnome.org/GNOME/mutter/merge_requests/1081
---
 clutter/clutter/clutter-actor.c              |  8 +++----
 clutter/clutter/clutter-canvas.c             |  2 +-
 clutter/clutter/clutter-image.c              |  2 +-
 clutter/clutter/clutter-paint-node-private.h |  6 ++---
 clutter/clutter/clutter-paint-node.c         | 23 +++++++++++++++-----
 clutter/clutter/clutter-paint-node.h         |  3 +++
 6 files changed, 30 insertions(+), 14 deletions(-)

diff --git a/clutter/clutter/clutter-actor.c b/clutter/clutter/clutter-actor.c
index 8da53d3f1..995de8c35 100644
--- a/clutter/clutter/clutter-actor.c
+++ b/clutter/clutter/clutter-actor.c
@@ -3692,7 +3692,7 @@ clutter_actor_paint_node (ClutterActor     *actor,
         clear_flags |= COGL_BUFFER_BIT_COLOR;
 
       node = _clutter_root_node_new (fb, &bg_color, clear_flags);
-      clutter_paint_node_set_name (node, "stageClear");
+      clutter_paint_node_set_static_name (node, "stageClear");
       clutter_paint_node_add_rectangle (node, &box);
       clutter_paint_node_add_child (root, node);
       clutter_paint_node_unref (node);
@@ -3707,7 +3707,7 @@ clutter_actor_paint_node (ClutterActor     *actor,
                      / 255;
 
       node = clutter_color_node_new (&bg_color);
-      clutter_paint_node_set_name (node, "backgroundColor");
+      clutter_paint_node_set_static_name (node, "backgroundColor");
       clutter_paint_node_add_rectangle (node, &box);
       clutter_paint_node_add_child (root, node);
       clutter_paint_node_unref (node);
@@ -4014,7 +4014,7 @@ clutter_actor_continue_paint (ClutterActor *self)
            * virtual function can then be called directly.
            */
           dummy = _clutter_dummy_node_new (self);
-          clutter_paint_node_set_name (dummy, "Root");
+          clutter_paint_node_set_static_name (dummy, "Root");
 
           /* XXX - for 1.12, we use the return value of paint_node() to
            * decide whether we should emit the ::paint signal.
@@ -21129,7 +21129,7 @@ clutter_actor_create_texture_paint_node (ClutterActor *self,
   color.alpha = clutter_actor_get_paint_opacity_internal (self);
 
   node = clutter_texture_node_new (texture, &color, priv->min_filter, priv->mag_filter);
-  clutter_paint_node_set_name (node, "Texture");
+  clutter_paint_node_set_static_name (node, "Texture");
 
   if (priv->content_repeat == CLUTTER_REPEAT_NONE)
     clutter_paint_node_add_rectangle (node, &box);
diff --git a/clutter/clutter/clutter-canvas.c b/clutter/clutter/clutter-canvas.c
index 42e54ce9d..512e434ed 100644
--- a/clutter/clutter/clutter-canvas.c
+++ b/clutter/clutter/clutter-canvas.c
@@ -319,7 +319,7 @@ clutter_canvas_paint_content (ClutterContent   *content,
     return;
 
   node = clutter_actor_create_texture_paint_node (actor, priv->texture);
-  clutter_paint_node_set_name (node, "Canvas Content");
+  clutter_paint_node_set_static_name (node, "Canvas Content");
   clutter_paint_node_add_child (root, node);
   clutter_paint_node_unref (node);
 
diff --git a/clutter/clutter/clutter-image.c b/clutter/clutter/clutter-image.c
index 722b0375d..51e610073 100644
--- a/clutter/clutter/clutter-image.c
+++ b/clutter/clutter/clutter-image.c
@@ -108,7 +108,7 @@ clutter_image_paint_content (ClutterContent   *content,
     return;
 
   node = clutter_actor_create_texture_paint_node (actor, priv->texture);
-  clutter_paint_node_set_name (node, "Image Content");
+  clutter_paint_node_set_static_name (node, "Image Content");
   clutter_paint_node_add_child (root, node);
   clutter_paint_node_unref (node);
 }
diff --git a/clutter/clutter/clutter-paint-node-private.h b/clutter/clutter/clutter-paint-node-private.h
index 2945b78a4..ea1665ada 100644
--- a/clutter/clutter/clutter-paint-node-private.h
+++ b/clutter/clutter/clutter-paint-node-private.h
@@ -48,11 +48,11 @@ struct _ClutterPaintNode
   ClutterPaintNode *next_sibling;
   ClutterPaintNode *last_child;
 
-  guint n_children;
-
   GArray *operations;
 
-  gchar *name;
+  const gchar *name;
+
+  guint n_children;
 
   volatile int ref_count;
 };
diff --git a/clutter/clutter/clutter-paint-node.c b/clutter/clutter/clutter-paint-node.c
index db68b7766..5129e00cf 100644
--- a/clutter/clutter/clutter-paint-node.c
+++ b/clutter/clutter/clutter-paint-node.c
@@ -173,8 +173,6 @@ clutter_paint_node_real_finalize (ClutterPaintNode *node)
 {
   ClutterPaintNode *iter;
 
-  g_free (node->name);
-
   if (node->operations != NULL)
     {
       guint i;
@@ -296,7 +294,8 @@ clutter_paint_node_get_type (void)
  *
  * The @name will be used for debugging purposes.
  *
- * The @node will copy the passed string.
+ * The @node will intern @name using g_intern_string(). If you have access to a
+ * static string, use clutter_paint_node_set_static_name() instead.
  *
  * Since: 1.10
  */
@@ -306,8 +305,22 @@ clutter_paint_node_set_name (ClutterPaintNode *node,
 {
   g_return_if_fail (CLUTTER_IS_PAINT_NODE (node));
 
-  g_free (node->name);
-  node->name = g_strdup (name);
+  node->name = g_intern_string (name);
+}
+
+/**
+ * clutter_paint_node_set_static_name: (skip)
+ *
+ * Like clutter_paint_node_set_name() but uses a static or interned string
+ * containing the name.
+ */
+void
+clutter_paint_node_set_static_name (ClutterPaintNode *node,
+                                    const char       *name)
+{
+  g_return_if_fail (CLUTTER_IS_PAINT_NODE (node));
+
+  node->name = name;
 }
 
 /**
diff --git a/clutter/clutter/clutter-paint-node.h b/clutter/clutter/clutter-paint-node.h
index 5f3e962e4..d3e4e7922 100644
--- a/clutter/clutter/clutter-paint-node.h
+++ b/clutter/clutter/clutter-paint-node.h
@@ -52,6 +52,9 @@ void                    clutter_paint_node_unref                        (Clutter
 CLUTTER_AVAILABLE_IN_1_10
 void                    clutter_paint_node_set_name                     (ClutterPaintNode      *node,
                                                                          const char            *name);
+CLUTTER_AVAILABLE_IN_ALL
+void                    clutter_paint_node_set_static_name              (ClutterPaintNode      *node,
+                                                                         const char            *name);
 
 CLUTTER_AVAILABLE_IN_1_10
 void                    clutter_paint_node_add_child                    (ClutterPaintNode      *node,
-- 
2.26.0