[mutter/gnome-41] cursor-sprite: Register all cursor sprites with the cursor tracker
- From: Jonas Ådahl <jadahl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter/gnome-41] cursor-sprite: Register all cursor sprites with the cursor tracker
- Date: Wed, 22 Dec 2021 20:28:47 +0000 (UTC)
commit 7e7067421a20bab6bae105cd34e96fa8c797c932
Author: Jonas Ådahl <jadahl gmail com>
Date: Mon Nov 15 14:24:53 2021 +0100
cursor-sprite: Register all cursor sprites with the cursor tracker
This will later be used to invalidate GPU state when closing device
nodes.
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2147>
(cherry picked from commit 25ed64b61decc3e20bca6cd06f14287f19a8e626)
src/backends/meta-cursor-sprite-xcursor.c | 7 ++-
src/backends/meta-cursor-sprite-xcursor.h | 4 +-
src/backends/meta-cursor-tracker-private.h | 8 +++
src/backends/meta-cursor-tracker.c | 31 ++++++++++++
src/backends/meta-cursor.c | 65 +++++++++++++++++++++++++
src/backends/x11/cm/meta-cursor-sprite-xfixes.c | 6 ++-
src/backends/x11/cm/meta-cursor-sprite-xfixes.h | 5 +-
src/backends/x11/meta-cursor-tracker-x11.c | 6 ++-
src/core/display.c | 2 +-
src/wayland/meta-cursor-sprite-wayland.c | 7 ++-
src/wayland/meta-cursor-sprite-wayland.h | 3 +-
src/wayland/meta-wayland-cursor-surface.c | 6 ++-
src/wayland/meta-wayland-tablet-tool.c | 5 +-
13 files changed, 141 insertions(+), 14 deletions(-)
---
diff --git a/src/backends/meta-cursor-sprite-xcursor.c b/src/backends/meta-cursor-sprite-xcursor.c
index 5284f28eaa..947440b9de 100644
--- a/src/backends/meta-cursor-sprite-xcursor.c
+++ b/src/backends/meta-cursor-sprite-xcursor.c
@@ -326,11 +326,14 @@ meta_cursor_sprite_xcursor_realize_texture (MetaCursorSprite *sprite)
}
MetaCursorSpriteXcursor *
-meta_cursor_sprite_xcursor_new (MetaCursor cursor)
+meta_cursor_sprite_xcursor_new (MetaCursor cursor,
+ MetaCursorTracker *cursor_tracker)
{
MetaCursorSpriteXcursor *sprite_xcursor;
- sprite_xcursor = g_object_new (META_TYPE_CURSOR_SPRITE_XCURSOR, NULL);
+ sprite_xcursor = g_object_new (META_TYPE_CURSOR_SPRITE_XCURSOR,
+ "cursor-tracker", cursor_tracker,
+ NULL);
sprite_xcursor->cursor = cursor;
return sprite_xcursor;
diff --git a/src/backends/meta-cursor-sprite-xcursor.h b/src/backends/meta-cursor-sprite-xcursor.h
index dbc927484d..dcb74817c0 100644
--- a/src/backends/meta-cursor-sprite-xcursor.h
+++ b/src/backends/meta-cursor-sprite-xcursor.h
@@ -23,12 +23,14 @@
#include <X11/Xcursor/Xcursor.h>
#include "backends/meta-cursor.h"
+#include "meta/types.h"
#define META_TYPE_CURSOR_SPRITE_XCURSOR meta_cursor_sprite_xcursor_get_type ()
G_DECLARE_FINAL_TYPE (MetaCursorSpriteXcursor, meta_cursor_sprite_xcursor,
META, CURSOR_SPRITE_XCURSOR, MetaCursorSprite)
-MetaCursorSpriteXcursor * meta_cursor_sprite_xcursor_new (MetaCursor cursor);
+MetaCursorSpriteXcursor * meta_cursor_sprite_xcursor_new (MetaCursor cursor,
+ MetaCursorTracker *cursor_tracker);
void meta_cursor_sprite_xcursor_set_theme_scale (MetaCursorSpriteXcursor *sprite_xcursor,
int scale);
diff --git a/src/backends/meta-cursor-tracker-private.h b/src/backends/meta-cursor-tracker-private.h
index 2d8d380428..ab4b065718 100644
--- a/src/backends/meta-cursor-tracker-private.h
+++ b/src/backends/meta-cursor-tracker-private.h
@@ -53,4 +53,12 @@ void meta_cursor_tracker_notify_cursor_changed (MetaCursorTracker *tracker);
void meta_cursor_tracker_destroy (MetaCursorTracker *tracker);
+void meta_cursor_tracker_register_cursor_sprite (MetaCursorTracker *tracker,
+ MetaCursorSprite *sprite);
+
+void meta_cursor_tracker_unregister_cursor_sprite (MetaCursorTracker *tracker,
+ MetaCursorSprite *sprite);
+
+GList * meta_cursor_tracker_peek_cursor_sprites (MetaCursorTracker *tracker);
+
#endif
diff --git a/src/backends/meta-cursor-tracker.c b/src/backends/meta-cursor-tracker.c
index 0df4d73cd4..0078fd6d48 100644
--- a/src/backends/meta-cursor-tracker.c
+++ b/src/backends/meta-cursor-tracker.c
@@ -74,6 +74,8 @@ typedef struct _MetaCursorTrackerPrivate
MetaCursorSprite *window_cursor;
MetaCursorSprite *root_cursor;
+
+ GList *cursor_sprites;
} MetaCursorTrackerPrivate;
G_DEFINE_TYPE_WITH_PRIVATE (MetaCursorTracker, meta_cursor_tracker,
@@ -531,3 +533,32 @@ meta_cursor_tracker_get_backend (MetaCursorTracker *tracker)
return priv->backend;
}
+
+void
+meta_cursor_tracker_register_cursor_sprite (MetaCursorTracker *tracker,
+ MetaCursorSprite *sprite)
+{
+ MetaCursorTrackerPrivate *priv =
+ meta_cursor_tracker_get_instance_private (tracker);
+
+ priv->cursor_sprites = g_list_prepend (priv->cursor_sprites, sprite);
+}
+
+void
+meta_cursor_tracker_unregister_cursor_sprite (MetaCursorTracker *tracker,
+ MetaCursorSprite *sprite)
+{
+ MetaCursorTrackerPrivate *priv =
+ meta_cursor_tracker_get_instance_private (tracker);
+
+ priv->cursor_sprites = g_list_remove (priv->cursor_sprites, sprite);
+}
+
+GList *
+meta_cursor_tracker_peek_cursor_sprites (MetaCursorTracker *tracker)
+{
+ MetaCursorTrackerPrivate *priv =
+ meta_cursor_tracker_get_instance_private (tracker);
+
+ return priv->cursor_sprites;
+}
diff --git a/src/backends/meta-cursor.c b/src/backends/meta-cursor.c
index d0fb2ba686..f8b64a42f3 100644
--- a/src/backends/meta-cursor.c
+++ b/src/backends/meta-cursor.c
@@ -24,6 +24,7 @@
#include "backends/meta-cursor.h"
#include "backends/meta-backend-private.h"
+#include "backends/meta-cursor-tracker-private.h"
#include "cogl/cogl.h"
#include "meta/common.h"
@@ -37,6 +38,17 @@ enum
static guint signals[LAST_SIGNAL];
+enum
+{
+ PROP_0,
+
+ PROP_CURSOR_TRACKER,
+
+ N_PROPS
+};
+
+static GParamSpec *obj_props[N_PROPS];
+
typedef struct _MetaCursorSpritePrivate
{
GObject parent;
@@ -45,6 +57,8 @@ typedef struct _MetaCursorSpritePrivate
float texture_scale;
MetaMonitorTransform texture_transform;
int hot_x, hot_y;
+
+ MetaCursorTracker *cursor_tracker;
} MetaCursorSpritePrivate;
G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (MetaCursorSprite,
@@ -203,6 +217,22 @@ meta_cursor_sprite_init (MetaCursorSprite *sprite)
priv->texture_transform = META_MONITOR_TRANSFORM_NORMAL;
}
+static void
+meta_cursor_sprite_constructed (GObject *object)
+{
+ MetaCursorSprite *sprite = META_CURSOR_SPRITE (object);
+ MetaCursorSpritePrivate *priv =
+ meta_cursor_sprite_get_instance_private (sprite);
+
+ g_assert (priv->cursor_tracker);
+
+ meta_cursor_tracker_register_cursor_sprite (priv->cursor_tracker, sprite);
+
+ g_clear_pointer (&priv->texture, cogl_object_unref);
+
+ G_OBJECT_CLASS (meta_cursor_sprite_parent_class)->constructed (object);
+}
+
static void
meta_cursor_sprite_finalize (GObject *object)
{
@@ -212,15 +242,50 @@ meta_cursor_sprite_finalize (GObject *object)
g_clear_pointer (&priv->texture, cogl_object_unref);
+ meta_cursor_tracker_unregister_cursor_sprite (priv->cursor_tracker, sprite);
+
G_OBJECT_CLASS (meta_cursor_sprite_parent_class)->finalize (object);
}
+static void
+meta_cursor_tracker_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ MetaCursorSprite *sprite = META_CURSOR_SPRITE (object);
+ MetaCursorSpritePrivate *priv =
+ meta_cursor_sprite_get_instance_private (sprite);
+
+ switch (prop_id)
+ {
+ case PROP_CURSOR_TRACKER:
+ priv->cursor_tracker = g_value_get_object (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
static void
meta_cursor_sprite_class_init (MetaCursorSpriteClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ object_class->constructed = meta_cursor_sprite_constructed;
object_class->finalize = meta_cursor_sprite_finalize;
+ object_class->set_property = meta_cursor_tracker_set_property;
+
+ obj_props[PROP_CURSOR_TRACKER] =
+ g_param_spec_object ("cursor-tracker",
+ "cursor tracker",
+ "MetaCursorTracker",
+ META_TYPE_CURSOR_TRACKER,
+ G_PARAM_WRITABLE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS);
+ g_object_class_install_properties (object_class, N_PROPS, obj_props);
signals[PREPARE_AT] = g_signal_new ("prepare-at",
G_TYPE_FROM_CLASS (object_class),
diff --git a/src/backends/x11/cm/meta-cursor-sprite-xfixes.c b/src/backends/x11/cm/meta-cursor-sprite-xfixes.c
index 0c524668e0..0e5ad13876 100644
--- a/src/backends/x11/cm/meta-cursor-sprite-xfixes.c
+++ b/src/backends/x11/cm/meta-cursor-sprite-xfixes.c
@@ -102,12 +102,14 @@ meta_cursor_sprite_xfixes_set_property (GObject *object,
}
MetaCursorSpriteXfixes *
-meta_cursor_sprite_xfixes_new (MetaDisplay *display,
- GError **error)
+meta_cursor_sprite_xfixes_new (MetaDisplay *display,
+ MetaCursorTracker *cursor_tracker,
+ GError **error)
{
return g_initable_new (META_TYPE_CURSOR_SPRITE_XFIXES,
NULL, error,
"display", display,
+ "cursor-tracker", cursor_tracker,
NULL);
}
diff --git a/src/backends/x11/cm/meta-cursor-sprite-xfixes.h b/src/backends/x11/cm/meta-cursor-sprite-xfixes.h
index c7073fc2c0..469d958a26 100644
--- a/src/backends/x11/cm/meta-cursor-sprite-xfixes.h
+++ b/src/backends/x11/cm/meta-cursor-sprite-xfixes.h
@@ -30,7 +30,8 @@ G_DECLARE_FINAL_TYPE (MetaCursorSpriteXfixes,
META, CURSOR_SPRITE_XFIXES,
MetaCursorSprite)
-MetaCursorSpriteXfixes * meta_cursor_sprite_xfixes_new (MetaDisplay *display,
- GError **error);
+MetaCursorSpriteXfixes * meta_cursor_sprite_xfixes_new (MetaDisplay *display,
+ MetaCursorTracker *cursor_tracker,
+ GError **error);
#endif /* META_CURSOR_SPRITE_XFIXES_H */
diff --git a/src/backends/x11/meta-cursor-tracker-x11.c b/src/backends/x11/meta-cursor-tracker-x11.c
index 7355f828ea..e01046d800 100644
--- a/src/backends/x11/meta-cursor-tracker-x11.c
+++ b/src/backends/x11/meta-cursor-tracker-x11.c
@@ -77,12 +77,16 @@ static gboolean
ensure_xfixes_cursor (MetaCursorTrackerX11 *tracker_x11)
{
MetaDisplay *display = meta_get_display ();
+ MetaCursorTracker *cursor_tracker;
g_autoptr (GError) error = NULL;
if (tracker_x11->xfixes_cursor)
return FALSE;
- tracker_x11->xfixes_cursor = meta_cursor_sprite_xfixes_new (display, &error);
+ cursor_tracker = META_CURSOR_TRACKER (tracker_x11);
+ tracker_x11->xfixes_cursor = meta_cursor_sprite_xfixes_new (display,
+ cursor_tracker,
+ &error);
if (!tracker_x11->xfixes_cursor)
g_warning ("Failed to create XFIXES cursor: %s", error->message);
diff --git a/src/core/display.c b/src/core/display.c
index 6fe69f4cec..d7852f34ff 100644
--- a/src/core/display.c
+++ b/src/core/display.c
@@ -1740,7 +1740,7 @@ meta_display_reload_cursor (MetaDisplay *display)
MetaBackend *backend = meta_get_backend ();
MetaCursorTracker *cursor_tracker = meta_backend_get_cursor_tracker (backend);
- sprite_xcursor = meta_cursor_sprite_xcursor_new (cursor);
+ sprite_xcursor = meta_cursor_sprite_xcursor_new (cursor, cursor_tracker);
if (meta_is_wayland_compositor ())
manage_root_cursor_sprite_scale (display, sprite_xcursor);
diff --git a/src/wayland/meta-cursor-sprite-wayland.c b/src/wayland/meta-cursor-sprite-wayland.c
index 7c14960ffb..f1a599151c 100644
--- a/src/wayland/meta-cursor-sprite-wayland.c
+++ b/src/wayland/meta-cursor-sprite-wayland.c
@@ -43,11 +43,14 @@ meta_cursor_sprite_wayland_is_animated (MetaCursorSprite *sprite)
}
MetaCursorSpriteWayland *
-meta_cursor_sprite_wayland_new (MetaWaylandSurface *surface)
+meta_cursor_sprite_wayland_new (MetaWaylandSurface *surface,
+ MetaCursorTracker *cursor_tracker)
{
MetaCursorSpriteWayland *sprite_wayland;
- sprite_wayland = g_object_new (META_TYPE_CURSOR_SPRITE_WAYLAND, NULL);
+ sprite_wayland = g_object_new (META_TYPE_CURSOR_SPRITE_WAYLAND,
+ "cursor-tracker", cursor_tracker,
+ NULL);
sprite_wayland->surface = surface;
return sprite_wayland;
diff --git a/src/wayland/meta-cursor-sprite-wayland.h b/src/wayland/meta-cursor-sprite-wayland.h
index 107698f3f9..6beb0b69a3 100644
--- a/src/wayland/meta-cursor-sprite-wayland.h
+++ b/src/wayland/meta-cursor-sprite-wayland.h
@@ -28,7 +28,8 @@
G_DECLARE_FINAL_TYPE (MetaCursorSpriteWayland, meta_cursor_sprite_wayland,
META, CURSOR_SPRITE_WAYLAND, MetaCursorSprite)
-MetaCursorSpriteWayland * meta_cursor_sprite_wayland_new (MetaWaylandSurface *surface);
+MetaCursorSpriteWayland * meta_cursor_sprite_wayland_new (MetaWaylandSurface *surface,
+ MetaCursorTracker *cursor_tracker);
MetaWaylandBuffer * meta_cursor_sprite_wayland_get_buffer (MetaCursorSpriteWayland *sprite_wayland);
diff --git a/src/wayland/meta-wayland-cursor-surface.c b/src/wayland/meta-wayland-cursor-surface.c
index d1f521818a..f7763884f1 100644
--- a/src/wayland/meta-wayland-cursor-surface.c
+++ b/src/wayland/meta-wayland-cursor-surface.c
@@ -245,6 +245,9 @@ meta_wayland_cursor_surface_constructed (GObject *object)
META_WAYLAND_SURFACE_ROLE (cursor_surface);
MetaWaylandSurface *surface =
meta_wayland_surface_role_get_surface (surface_role);
+ MetaWaylandCompositor *compositor = surface->compositor;
+ MetaBackend *backend = meta_context_get_backend (compositor->context);
+ MetaCursorTracker *cursor_tracker = meta_backend_get_cursor_tracker (backend);
MetaWaylandBuffer *buffer;
buffer = meta_wayland_surface_get_buffer (surface);
@@ -257,7 +260,8 @@ meta_wayland_cursor_surface_constructed (GObject *object)
meta_wayland_surface_ref_buffer_use_count (surface);
}
- priv->cursor_sprite = meta_cursor_sprite_wayland_new (surface);
+ priv->cursor_sprite = meta_cursor_sprite_wayland_new (surface,
+ cursor_tracker);
g_signal_connect_object (priv->cursor_sprite,
"prepare-at",
G_CALLBACK (cursor_sprite_prepare_at),
diff --git a/src/wayland/meta-wayland-tablet-tool.c b/src/wayland/meta-wayland-tablet-tool.c
index 51e4e7d5d4..2b2b1d6598 100644
--- a/src/wayland/meta-wayland-tablet-tool.c
+++ b/src/wayland/meta-wayland-tablet-tool.c
@@ -385,6 +385,8 @@ meta_wayland_tablet_tool_new (MetaWaylandTabletSeat *seat,
ClutterInputDevice *device,
ClutterInputDeviceTool *device_tool)
{
+ MetaBackend *backend = meta_get_backend ();
+ MetaCursorTracker *cursor_tracker = meta_backend_get_cursor_tracker (backend);
MetaWaylandTabletTool *tool;
tool = g_new0 (MetaWaylandTabletTool, 1);
@@ -397,7 +399,8 @@ meta_wayland_tablet_tool_new (MetaWaylandTabletSeat *seat,
tool->focus_surface_destroy_listener.notify = tablet_tool_handle_focus_surface_destroy;
tool->cursor_surface_destroy_listener.notify = tablet_tool_handle_cursor_surface_destroy;
- tool->default_sprite = meta_cursor_sprite_xcursor_new (META_CURSOR_CROSSHAIR);
+ tool->default_sprite = meta_cursor_sprite_xcursor_new (META_CURSOR_CROSSHAIR,
+ cursor_tracker);
tool->prepare_at_signal_id =
g_signal_connect (tool->default_sprite, "prepare-at",
G_CALLBACK (tool_cursor_prepare_at), tool);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]