kathenas / rpms / mutter

Forked from rpms/mutter 5 years ago
Clone

Blame SOURCES/0002-clutter-avoid-g_signal_emit_by_name-from-ClutterActo.patch

99364f
From 6881aa5ca235ee0737c2a409ffab966a10e5971e Mon Sep 17 00:00:00 2001
99364f
From: Christian Hergert <christian@hergert.me>
99364f
Date: Mon, 24 Feb 2020 22:36:27 +0000
99364f
Subject: [PATCH 2/3] clutter: avoid g_signal_emit_by_name() from ClutterActor
99364f
99364f
g_signal_emit_by_name() is used to emit signals on ClutterContainer when
99364f
actors are removed or added. It happens to do various interface lookups
99364f
which are a bit unneccessary and can allocate memory.
99364f
99364f
Simply using emission wrappers makes all of that go away.
99364f
99364f
https://gitlab.gnome.org/GNOME/mutter/merge_requests/1083
99364f
---
99364f
 clutter/clutter/cally/cally-actor.c         |  5 +--
99364f
 clutter/clutter/clutter-actor.c             | 17 ++++++++--
99364f
 clutter/clutter/clutter-actor.h             |  5 ++-
99364f
 clutter/clutter/clutter-container-private.h | 36 +++++++++++++++++++++
99364f
 clutter/clutter/clutter-container.c         | 21 ++++++++++++
99364f
 5 files changed, 78 insertions(+), 6 deletions(-)
99364f
 create mode 100644 clutter/clutter/clutter-container-private.h
99364f
99364f
diff --git a/clutter/clutter/cally/cally-actor.c b/clutter/clutter/cally/cally-actor.c
99364f
index 548615f48..517969625 100644
99364f
--- a/clutter/clutter/cally/cally-actor.c
99364f
+++ b/clutter/clutter/cally/cally-actor.c
99364f
@@ -604,10 +604,11 @@ cally_actor_real_remove_actor (ClutterActor *container,
99364f
   g_return_val_if_fail (CLUTTER_IS_ACTOR (actor), 0);
99364f
 
99364f
   atk_parent = ATK_OBJECT (data);
99364f
-  atk_child = clutter_actor_get_accessible (actor);
99364f
 
99364f
-  if (atk_child)
99364f
+  if (clutter_actor_has_accessible (actor))
99364f
     {
99364f
+      atk_child = clutter_actor_get_accessible (actor);
99364f
+
99364f
       g_value_init (&values.old_value, G_TYPE_POINTER);
99364f
       g_value_set_pointer (&values.old_value, atk_parent);
99364f
 
99364f
diff --git a/clutter/clutter/clutter-actor.c b/clutter/clutter/clutter-actor.c
99364f
index 803f76aae..93d0a93ef 100644
99364f
--- a/clutter/clutter/clutter-actor.c
99364f
+++ b/clutter/clutter/clutter-actor.c
99364f
@@ -624,7 +624,7 @@
99364f
 #include "clutter-color-static.h"
99364f
 #include "clutter-color.h"
99364f
 #include "clutter-constraint-private.h"
99364f
-#include "clutter-container.h"
99364f
+#include "clutter-container-private.h"
99364f
 #include "clutter-content-private.h"
99364f
 #include "clutter-debug.h"
99364f
 #include "clutter-easing.h"
99364f
@@ -4372,7 +4372,7 @@ clutter_actor_remove_child_internal (ClutterActor                 *self,
99364f
 
99364f
   /* we need to emit the signal before dropping the reference */
99364f
   if (emit_actor_removed)
99364f
-    g_signal_emit_by_name (self, "actor-removed", child);
99364f
+    _clutter_container_emit_actor_removed (CLUTTER_CONTAINER (self), child);
99364f
 
99364f
   if (notify_first_last)
99364f
     {
99364f
@@ -13060,7 +13060,7 @@ clutter_actor_add_child_internal (ClutterActor              *self,
99364f
     }
99364f
 
99364f
   if (emit_actor_added)
99364f
-    g_signal_emit_by_name (self, "actor-added", child);
99364f
+    _clutter_container_emit_actor_added (CLUTTER_CONTAINER (self), child);
99364f
 
99364f
   if (notify_first_last)
99364f
     {
99364f
@@ -21448,3 +21448,14 @@ clutter_actor_create_texture_paint_node (ClutterActor *self,
99364f
 
99364f
   return node;
99364f
 }
99364f
+
99364f
+gboolean
99364f
+clutter_actor_has_accessible (ClutterActor *actor)
99364f
+{
99364f
+  g_return_val_if_fail (CLUTTER_IS_ACTOR (actor), FALSE);
99364f
+
99364f
+  if (CLUTTER_ACTOR_GET_CLASS (actor)->has_accessible)
99364f
+    return CLUTTER_ACTOR_GET_CLASS (actor)->has_accessible (actor);
99364f
+
99364f
+  return TRUE;
99364f
+}
99364f
diff --git a/clutter/clutter/clutter-actor.h b/clutter/clutter/clutter-actor.h
99364f
index 7d2168af1..d286f2843 100644
99364f
--- a/clutter/clutter/clutter-actor.h
99364f
+++ b/clutter/clutter/clutter-actor.h
99364f
@@ -296,10 +296,11 @@ struct _ClutterActorClass
99364f
 
99364f
   gboolean (* touch_event)          (ClutterActor         *self,
99364f
                                      ClutterTouchEvent    *event);
99364f
+  gboolean (* has_accessible)       (ClutterActor         *self);
99364f
 
99364f
   /*< private >*/
99364f
   /* padding for future expansion */
99364f
-  gpointer _padding_dummy[26];
99364f
+  gpointer _padding_dummy[25];
99364f
 };
99364f
 
99364f
 /**
99364f
@@ -369,6 +370,8 @@ CLUTTER_EXPORT
99364f
 const gchar *                   clutter_actor_get_name                          (ClutterActor                *self);
99364f
 CLUTTER_EXPORT
99364f
 AtkObject *                     clutter_actor_get_accessible                    (ClutterActor                *self);
99364f
+CLUTTER_EXPORT
99364f
+gboolean                        clutter_actor_has_accessible                    (ClutterActor                *self);
99364f
 
99364f
 CLUTTER_EXPORT
99364f
 gboolean                        clutter_actor_is_visible                        (ClutterActor                *self);
99364f
diff --git a/clutter/clutter/clutter-container-private.h b/clutter/clutter/clutter-container-private.h
99364f
new file mode 100644
99364f
index 000000000..d619a6531
99364f
--- /dev/null
99364f
+++ b/clutter/clutter/clutter-container-private.h
99364f
@@ -0,0 +1,36 @@
99364f
+/*
99364f
+ * Clutter.
99364f
+ *
99364f
+ * An OpenGL based 'interactive canvas' library.
99364f
+ *
99364f
+ * Copyright 2020 Red Hat, Inc.
99364f
+ *
99364f
+ * This library is free software; you can redistribute it and/or
99364f
+ * modify it under the terms of the GNU Lesser General Public
99364f
+ * License as published by the Free Software Foundation; either
99364f
+ * version 2 of the License, or (at your option) any later version.
99364f
+ *
99364f
+ * This library is distributed in the hope that it will be useful,
99364f
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
99364f
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
99364f
+ * Lesser General Public License for more details.
99364f
+ *
99364f
+ * You should have received a copy of the GNU Lesser General Public
99364f
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
99364f
+ */
99364f
+
99364f
+#ifndef __CLUTTER_CONTAINER_PRIVATE_H__
99364f
+#define __CLUTTER_CONTAINER_PRIVATE_H__
99364f
+
99364f
+#include <clutter/clutter-container.h>
99364f
+
99364f
+G_BEGIN_DECLS
99364f
+
99364f
+void _clutter_container_emit_actor_added   (ClutterContainer *container,
99364f
+                                            ClutterActor     *actor);
99364f
+void _clutter_container_emit_actor_removed (ClutterContainer *container,
99364f
+                                            ClutterActor     *actor);
99364f
+
99364f
+G_END_DECLS
99364f
+
99364f
+#endif /* __CLUTTER_CONTAINER_PRIVATE_H__ */
99364f
diff --git a/clutter/clutter/clutter-container.c b/clutter/clutter/clutter-container.c
99364f
index 0f611ae55..79abb5b4f 100644
99364f
--- a/clutter/clutter/clutter-container.c
99364f
+++ b/clutter/clutter/clutter-container.c
99364f
@@ -37,6 +37,7 @@
99364f
 
99364f
 #include "clutter-actor-private.h"
99364f
 #include "clutter-child-meta.h"
99364f
+#include "clutter-container-private.h"
99364f
 #include "clutter-debug.h"
99364f
 #include "clutter-main.h"
99364f
 #include "clutter-marshal.h"
99364f
@@ -1446,3 +1447,23 @@ clutter_container_child_notify (ClutterContainer *container,
99364f
                                                          child,
99364f
                                                          pspec);
99364f
 }
99364f
+
99364f
+void
99364f
+_clutter_container_emit_actor_added (ClutterContainer *container,
99364f
+                                     ClutterActor     *actor)
99364f
+{
99364f
+  g_return_if_fail (CLUTTER_IS_CONTAINER (container));
99364f
+  g_return_if_fail (CLUTTER_IS_ACTOR (actor));
99364f
+
99364f
+  g_signal_emit (container, container_signals[ACTOR_ADDED], 0, actor);
99364f
+}
99364f
+
99364f
+void
99364f
+_clutter_container_emit_actor_removed (ClutterContainer *container,
99364f
+                                       ClutterActor     *actor)
99364f
+{
99364f
+  g_return_if_fail (CLUTTER_IS_CONTAINER (container));
99364f
+  g_return_if_fail (CLUTTER_IS_ACTOR (actor));
99364f
+
99364f
+  g_signal_emit (container, container_signals[ACTOR_REMOVED], 0, actor);
99364f
+}
99364f
-- 
99364f
2.26.0
99364f