[mutter/wip/carlosg/unthrottled-wayland: 1/9] backends: Replace MetaCursorSprite::prepare-at with in-place function




commit a6676df595b1e737ef2f4e09406691b47d4216e6
Author: Carlos Garnacho <carlosg gnome org>
Date:   Mon Jul 5 16:19:05 2021 +0200

    backends: Replace MetaCursorSprite::prepare-at with in-place function
    
    Since this signal is in a hot path during input handling, it makes sense
    not to have this be a signal at all, currently most of the time spent in
    it is in GLib signal machinery itself.
    
    Replace it with a function/user data pair that are set on the sprite
    itself. Only the places that create an sprite are interested in hooking
    one ::prepare-at behavior per sprite, so we can do with a single pair.
    
    This makes meta_cursor_sprite_prepare_at() inexpensive enough.

 src/backends/meta-cursor.c                | 31 ++++++++++++++++++++-----------
 src/backends/meta-cursor.h                | 10 ++++++++++
 src/core/display.c                        |  8 +++-----
 src/wayland/meta-wayland-cursor-surface.c | 16 ++++++++++------
 src/wayland/meta-wayland-tablet-tool.c    |  9 +++++----
 src/wayland/meta-wayland-tablet-tool.h    |  1 -
 6 files changed, 48 insertions(+), 27 deletions(-)
---
diff --git a/src/backends/meta-cursor.c b/src/backends/meta-cursor.c
index a0abd9cd67..ae35539dff 100644
--- a/src/backends/meta-cursor.c
+++ b/src/backends/meta-cursor.c
@@ -29,7 +29,6 @@
 
 enum
 {
-  PREPARE_AT,
   TEXTURE_CHANGED,
 
   LAST_SIGNAL
@@ -45,6 +44,9 @@ typedef struct _MetaCursorSpritePrivate
   float texture_scale;
   MetaMonitorTransform texture_transform;
   int hot_x, hot_y;
+
+  MetaCursorPrepareFunc prepare_func;
+  gpointer prepare_func_data;
 } MetaCursorSpritePrivate;
 
 G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (MetaCursorSprite,
@@ -187,13 +189,29 @@ meta_cursor_sprite_get_texture_transform (MetaCursorSprite *sprite)
   return priv->texture_transform;
 }
 
+void
+meta_cursor_sprite_set_prepare_func (MetaCursorSprite      *sprite,
+                                     MetaCursorPrepareFunc  func,
+                                     gpointer               user_data)
+{
+  MetaCursorSpritePrivate *priv =
+    meta_cursor_sprite_get_instance_private (sprite);
+
+  priv->prepare_func = func;
+  priv->prepare_func_data = user_data;
+}
+
 void
 meta_cursor_sprite_prepare_at (MetaCursorSprite   *sprite,
                                float               best_scale,
                                int                 x,
                                int                 y)
 {
-  g_signal_emit (sprite, signals[PREPARE_AT], 0, best_scale, x, y);
+  MetaCursorSpritePrivate *priv =
+    meta_cursor_sprite_get_instance_private (sprite);
+
+  if (priv->prepare_func)
+    priv->prepare_func (sprite, best_scale, x, y, priv->prepare_func_data);
 }
 
 gboolean
@@ -240,15 +258,6 @@ meta_cursor_sprite_class_init (MetaCursorSpriteClass *klass)
 
   object_class->finalize = meta_cursor_sprite_finalize;
 
-  signals[PREPARE_AT] = g_signal_new ("prepare-at",
-                                      G_TYPE_FROM_CLASS (object_class),
-                                      G_SIGNAL_RUN_LAST,
-                                      0,
-                                      NULL, NULL, NULL,
-                                      G_TYPE_NONE, 3,
-                                      G_TYPE_FLOAT,
-                                      G_TYPE_INT,
-                                      G_TYPE_INT);
   signals[TEXTURE_CHANGED] = g_signal_new ("texture-changed",
                                            G_TYPE_FROM_CLASS (object_class),
                                            G_SIGNAL_RUN_LAST,
diff --git a/src/backends/meta-cursor.h b/src/backends/meta-cursor.h
index 214394dd44..1bf63f1078 100644
--- a/src/backends/meta-cursor.h
+++ b/src/backends/meta-cursor.h
@@ -43,6 +43,16 @@ struct _MetaCursorSpriteClass
   unsigned int (* get_current_frame_time) (MetaCursorSprite *sprite);
 };
 
+typedef void (* MetaCursorPrepareFunc) (MetaCursorSprite *sprite,
+                                        float             scale,
+                                        int               x,
+                                        int               y,
+                                        gpointer          user_data);
+
+void meta_cursor_sprite_set_prepare_func (MetaCursorSprite      *sprite,
+                                          MetaCursorPrepareFunc  func,
+                                          gpointer               user_data);
+
 void meta_cursor_sprite_prepare_at (MetaCursorSprite *sprite,
                                     float             best_scale,
                                     int               x,
diff --git a/src/core/display.c b/src/core/display.c
index 532d024f80..7f54802ffb 100644
--- a/src/core/display.c
+++ b/src/core/display.c
@@ -1729,11 +1729,9 @@ static void
 manage_root_cursor_sprite_scale (MetaDisplay             *display,
                                  MetaCursorSpriteXcursor *sprite_xcursor)
 {
-  g_signal_connect_object (sprite_xcursor,
-                           "prepare-at",
-                           G_CALLBACK (root_cursor_prepare_at),
-                           display,
-                           0);
+  meta_cursor_sprite_set_prepare_func (META_CURSOR_SPRITE (sprite_xcursor),
+                                       (MetaCursorPrepareFunc) root_cursor_prepare_at,
+                                       display);
 }
 
 void
diff --git a/src/wayland/meta-wayland-cursor-surface.c b/src/wayland/meta-wayland-cursor-surface.c
index d1f521818a..f4b2888125 100644
--- a/src/wayland/meta-wayland-cursor-surface.c
+++ b/src/wayland/meta-wayland-cursor-surface.c
@@ -223,7 +223,13 @@ meta_wayland_cursor_surface_dispose (GObject *object)
                                         cursor_sprite_prepare_at, cursor_surface);
 
   g_clear_object (&priv->cursor_renderer);
-  g_clear_object (&priv->cursor_sprite);
+
+  if (priv->cursor_sprite)
+    {
+      meta_cursor_sprite_set_prepare_func (META_CURSOR_SPRITE (priv->cursor_sprite),
+                                           NULL, NULL);
+      g_clear_object (&priv->cursor_sprite);
+    }
 
   if (priv->buffer)
     {
@@ -258,11 +264,9 @@ meta_wayland_cursor_surface_constructed (GObject *object)
     }
 
   priv->cursor_sprite = meta_cursor_sprite_wayland_new (surface);
-  g_signal_connect_object (priv->cursor_sprite,
-                           "prepare-at",
-                           G_CALLBACK (cursor_sprite_prepare_at),
-                           cursor_surface,
-                           0);
+  meta_cursor_sprite_set_prepare_func (META_CURSOR_SPRITE (priv->cursor_sprite),
+                                       (MetaCursorPrepareFunc) cursor_sprite_prepare_at,
+                                       cursor_surface);
 }
 
 static void
diff --git a/src/wayland/meta-wayland-tablet-tool.c b/src/wayland/meta-wayland-tablet-tool.c
index 51e4e7d5d4..4e24f8cbee 100644
--- a/src/wayland/meta-wayland-tablet-tool.c
+++ b/src/wayland/meta-wayland-tablet-tool.c
@@ -398,9 +398,9 @@ meta_wayland_tablet_tool_new (MetaWaylandTabletSeat  *seat,
   tool->cursor_surface_destroy_listener.notify = tablet_tool_handle_cursor_surface_destroy;
 
   tool->default_sprite = meta_cursor_sprite_xcursor_new (META_CURSOR_CROSSHAIR);
-  tool->prepare_at_signal_id =
-    g_signal_connect (tool->default_sprite, "prepare-at",
-                      G_CALLBACK (tool_cursor_prepare_at), tool);
+  meta_cursor_sprite_set_prepare_func (META_CURSOR_SPRITE (tool->default_sprite),
+                                       (MetaCursorPrepareFunc) tool_cursor_prepare_at,
+                                       tool);
 
   return tool;
 }
@@ -421,7 +421,8 @@ meta_wayland_tablet_tool_free (MetaWaylandTabletTool *tool)
       wl_list_init (wl_resource_get_link (resource));
     }
 
-  g_clear_signal_handler (&tool->prepare_at_signal_id, tool->default_sprite);
+  meta_cursor_sprite_set_prepare_func (META_CURSOR_SPRITE (tool->default_sprite),
+                                       NULL, NULL);
   g_object_unref (tool->default_sprite);
 
   g_free (tool);
diff --git a/src/wayland/meta-wayland-tablet-tool.h b/src/wayland/meta-wayland-tablet-tool.h
index e9ad7db40c..9fc7048519 100644
--- a/src/wayland/meta-wayland-tablet-tool.h
+++ b/src/wayland/meta-wayland-tablet-tool.h
@@ -44,7 +44,6 @@ struct _MetaWaylandTabletTool
   struct wl_listener cursor_surface_destroy_listener;
   MetaCursorRenderer *cursor_renderer;
   MetaCursorSpriteXcursor *default_sprite;
-  gulong prepare_at_signal_id;
 
   MetaWaylandSurface *current;
   guint32 pressed_buttons;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]