[mutter/wip/texture-purge-on-nvidia: 2/66] hw-cursor-on-demand-gnome-3-28.patch



commit 631277d3d042ae8851b0a0ca7cdf40f09fc8698a
Author: Ray Strode <rstrode redhat com>
Date:   Tue Jan 8 09:40:54 2019 -0500

    hw-cursor-on-demand-gnome-3-28.patch

 src/Makefile.am                                    |  14 +-
 src/backends/meta-cursor-renderer.c                |  35 +-
 src/backends/meta-cursor-renderer.h                |  22 --
 src/backends/meta-cursor-tracker-private.h         |   3 +-
 src/backends/meta-cursor-tracker.c                 |  75 +---
 src/backends/meta-cursor.c                         | 323 ++++-------------
 src/backends/meta-cursor.h                         |  59 ++--
 src/backends/native/meta-backend-native.c          |   6 -
 src/backends/native/meta-cursor-renderer-native.c  | 275 ++++++++++-----
 src/backends/native/meta-cursor-renderer-native.h  |   2 -
 src/backends/x11/meta-cursor-renderer-x11.c        |  12 +-
 .../x11/nested/meta-cursor-renderer-x11-nested.c   |   2 +
 src/core/display.c                                 |   2 +-
 src/core/screen.c                                  |  33 +-
 src/wayland/meta-wayland-buffer.c                  |   6 +
 src/wayland/meta-wayland-buffer.h                  |   1 +
 src/wayland/meta-wayland-pointer.c                 |  22 +-
 src/wayland/meta-wayland-surface-role-cursor.c     | 391 ---------------------
 src/wayland/meta-wayland-surface-role-cursor.h     |  52 ---
 .../meta-wayland-surface-role-tablet-cursor.c      |  42 ---
 .../meta-wayland-surface-role-tablet-cursor.h      |  33 --
 src/wayland/meta-wayland-tablet-tool.c             |  37 +-
 src/wayland/meta-wayland-tablet-tool.h             |   3 +-
 23 files changed, 379 insertions(+), 1071 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index bcb3505c7..5bbac70e8 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -114,6 +114,8 @@ libmutter_@LIBMUTTER_API_VERSION@_la_SOURCES =      \
        backends/meta-cursor-tracker-private.h  \
        backends/meta-cursor-renderer.c         \
        backends/meta-cursor-renderer.h         \
+       backends/meta-cursor-sprite-xcursor.c   \
+       backends/meta-cursor-sprite-xcursor.h   \
        backends/meta-dnd-private.h             \
        backends/meta-egl.c                     \
        backends/meta-egl.h                     \
@@ -176,6 +178,8 @@ libmutter_@LIBMUTTER_API_VERSION@_la_SOURCES =      \
        backends/x11/meta-gpu-xrandr.h                  \
        backends/x11/cm/meta-backend-x11-cm.c           \
        backends/x11/cm/meta-backend-x11-cm.h           \
+       backends/x11/cm/meta-cursor-sprite-xfixes.c     \
+       backends/x11/cm/meta-cursor-sprite-xfixes.h     \
        backends/x11/cm/meta-renderer-x11-cm.c          \
        backends/x11/cm/meta-renderer-x11-cm.h          \
        backends/x11/nested/meta-backend-x11-nested.c   \
@@ -370,6 +374,8 @@ if HAVE_WAYLAND
 libmutter_@LIBMUTTER_API_VERSION@_la_SOURCES +=        \
        compositor/meta-surface-actor-wayland.c \
        compositor/meta-surface-actor-wayland.h \
+       wayland/meta-cursor-sprite-wayland.c    \
+       wayland/meta-cursor-sprite-wayland.h    \
        wayland/meta-wayland.c                  \
        wayland/meta-wayland.h                  \
        wayland/meta-wayland-private.h          \
@@ -431,10 +437,10 @@ libmutter_@LIBMUTTER_API_VERSION@_la_SOURCES +=   \
        wayland/meta-wayland-touch.h            \
        wayland/meta-wayland-surface.c          \
        wayland/meta-wayland-surface.h          \
-       wayland/meta-wayland-surface-role-cursor.c      \
-       wayland/meta-wayland-surface-role-cursor.h      \
-       wayland/meta-wayland-surface-role-tablet-cursor.c       \
-       wayland/meta-wayland-surface-role-tablet-cursor.h       \
+       wayland/meta-wayland-cursor-surface.c   \
+       wayland/meta-wayland-cursor-surface.h   \
+       wayland/meta-wayland-tablet-cursor-surface.c    \
+       wayland/meta-wayland-tablet-cursor-surface.h    \
        wayland/meta-wayland-actor-surface.c    \
        wayland/meta-wayland-actor-surface.h    \
        wayland/meta-wayland-subsurface.c       \
diff --git a/src/backends/meta-cursor-renderer.c b/src/backends/meta-cursor-renderer.c
index f6470e66a..eb79737f1 100644
--- a/src/backends/meta-cursor-renderer.c
+++ b/src/backends/meta-cursor-renderer.c
@@ -193,8 +193,8 @@ meta_cursor_renderer_calculate_rect (MetaCursorRenderer *renderer,
 }
 
 static void
-update_cursor (MetaCursorRenderer *renderer,
-               MetaCursorSprite   *cursor_sprite)
+meta_cursor_renderer_update_cursor (MetaCursorRenderer *renderer,
+                                    MetaCursorSprite   *cursor_sprite)
 {
   MetaCursorRendererPrivate *priv = meta_cursor_renderer_get_instance_private (renderer);
   gboolean handled_by_backend;
@@ -237,7 +237,7 @@ meta_cursor_renderer_set_cursor (MetaCursorRenderer *renderer,
     return;
   priv->displayed_cursor = cursor_sprite;
 
-  update_cursor (renderer, cursor_sprite);
+  meta_cursor_renderer_update_cursor (renderer, cursor_sprite);
 }
 
 void
@@ -246,7 +246,7 @@ meta_cursor_renderer_force_update (MetaCursorRenderer *renderer)
   MetaCursorRendererPrivate *priv =
     meta_cursor_renderer_get_instance_private (renderer);
 
-  update_cursor (renderer, priv->displayed_cursor);
+  meta_cursor_renderer_update_cursor (renderer, priv->displayed_cursor);
 }
 
 void
@@ -261,7 +261,7 @@ meta_cursor_renderer_set_position (MetaCursorRenderer *renderer,
   priv->current_x = x;
   priv->current_y = y;
 
-  update_cursor (renderer, priv->displayed_cursor);
+  meta_cursor_renderer_update_cursor (renderer, priv->displayed_cursor);
 }
 
 ClutterPoint
@@ -283,28 +283,3 @@ meta_cursor_renderer_get_cursor (MetaCursorRenderer *renderer)
 
   return priv->displayed_cursor;
 }
-
-#ifdef HAVE_WAYLAND
-void
-meta_cursor_renderer_realize_cursor_from_wl_buffer (MetaCursorRenderer *renderer,
-                                                    MetaCursorSprite   *cursor_sprite,
-                                                    struct wl_resource *buffer)
-{
-
-  MetaCursorRendererClass *renderer_class = META_CURSOR_RENDERER_GET_CLASS (renderer);
-
-  if (renderer_class->realize_cursor_from_wl_buffer)
-    renderer_class->realize_cursor_from_wl_buffer (renderer, cursor_sprite, buffer);
-}
-#endif
-
-void
-meta_cursor_renderer_realize_cursor_from_xcursor (MetaCursorRenderer *renderer,
-                                                  MetaCursorSprite   *cursor_sprite,
-                                                  XcursorImage       *xc_image)
-{
-  MetaCursorRendererClass *renderer_class = META_CURSOR_RENDERER_GET_CLASS (renderer);
-
-  if (renderer_class->realize_cursor_from_xcursor)
-    renderer_class->realize_cursor_from_xcursor (renderer, cursor_sprite, xc_image);
-}
diff --git a/src/backends/meta-cursor-renderer.h b/src/backends/meta-cursor-renderer.h
index 1691f4471..830d16ef6 100644
--- a/src/backends/meta-cursor-renderer.h
+++ b/src/backends/meta-cursor-renderer.h
@@ -26,10 +26,6 @@
 #define META_CURSOR_RENDERER_H
 
 #include <glib-object.h>
-#include <X11/Xcursor/Xcursor.h>
-#ifdef HAVE_WAYLAND
-#include <wayland-server.h>
-#endif
 
 #include <meta/screen.h>
 #include "meta-cursor.h"
@@ -44,14 +40,6 @@ struct _MetaCursorRendererClass
 
   gboolean (* update_cursor) (MetaCursorRenderer *renderer,
                               MetaCursorSprite   *cursor_sprite);
-#ifdef HAVE_WAYLAND
-  void (* realize_cursor_from_wl_buffer) (MetaCursorRenderer *renderer,
-                                          MetaCursorSprite *cursor_sprite,
-                                          struct wl_resource *buffer);
-#endif
-  void (* realize_cursor_from_xcursor) (MetaCursorRenderer *renderer,
-                                        MetaCursorSprite *cursor_sprite,
-                                        XcursorImage *xc_image);
 };
 
 MetaCursorRenderer * meta_cursor_renderer_new (void);
@@ -70,16 +58,6 @@ MetaCursorSprite * meta_cursor_renderer_get_cursor (MetaCursorRenderer *renderer
 ClutterRect meta_cursor_renderer_calculate_rect (MetaCursorRenderer *renderer,
                                                  MetaCursorSprite   *cursor_sprite);
 
-#ifdef HAVE_WAYLAND
-void meta_cursor_renderer_realize_cursor_from_wl_buffer (MetaCursorRenderer *renderer,
-                                                         MetaCursorSprite   *cursor_sprite,
-                                                         struct wl_resource *buffer);
-#endif
-
-void meta_cursor_renderer_realize_cursor_from_xcursor (MetaCursorRenderer *renderer,
-                                                       MetaCursorSprite   *cursor_sprite,
-                                                       XcursorImage       *xc_image);
-
 void meta_cursor_renderer_emit_painted (MetaCursorRenderer *renderer,
                                         MetaCursorSprite   *cursor_sprite);
 
diff --git a/src/backends/meta-cursor-tracker-private.h b/src/backends/meta-cursor-tracker-private.h
index 2ec946847..6f4f84b83 100644
--- a/src/backends/meta-cursor-tracker-private.h
+++ b/src/backends/meta-cursor-tracker-private.h
@@ -26,6 +26,7 @@
 
 #include "meta-cursor.h"
 #include "meta-cursor-renderer.h"
+#include "backends/x11/cm/meta-cursor-sprite-xfixes.h"
 
 struct _MetaCursorTracker {
   GObject parent_instance;
@@ -46,7 +47,7 @@ struct _MetaCursorTracker {
   MetaCursorSprite *root_cursor;
 
   /* The cursor from the X11 server. */
-  MetaCursorSprite *xfixes_cursor;
+  MetaCursorSpriteXfixes *xfixes_cursor;
 };
 
 struct _MetaCursorTrackerClass {
diff --git a/src/backends/meta-cursor-tracker.c b/src/backends/meta-cursor-tracker.c
index 74fa4351d..6244f11ee 100644
--- a/src/backends/meta-cursor-tracker.c
+++ b/src/backends/meta-cursor-tracker.c
@@ -40,9 +40,9 @@
 
 #include <gdk/gdk.h>
 #include <gdk/gdkx.h>
-#include <X11/extensions/Xfixes.h>
 
 #include "meta-backend-private.h"
+#include "backends/x11/cm/meta-cursor-sprite-xfixes.h"
 
 G_DEFINE_TYPE (MetaCursorTracker, meta_cursor_tracker, G_TYPE_OBJECT);
 
@@ -218,75 +218,14 @@ static void
 ensure_xfixes_cursor (MetaCursorTracker *tracker)
 {
   MetaDisplay *display = meta_get_display ();
-  XFixesCursorImage *cursor_image;
-  CoglTexture2D *sprite;
-  guint8 *cursor_data;
-  gboolean free_cursor_data;
-  CoglContext *ctx;
-  CoglError *error = NULL;
+  g_autoptr (GError) error = NULL;
 
   if (tracker->xfixes_cursor)
     return;
 
-  cursor_image = XFixesGetCursorImage (display->xdisplay);
-  if (!cursor_image)
-    return;
-
-  /* Like all X APIs, XFixesGetCursorImage() returns arrays of 32-bit
-   * quantities as arrays of long; we need to convert on 64 bit */
-  if (sizeof(long) == 4)
-    {
-      cursor_data = (guint8 *)cursor_image->pixels;
-      free_cursor_data = FALSE;
-    }
-  else
-    {
-      int i, j;
-      guint32 *cursor_words;
-      gulong *p;
-      guint32 *q;
-
-      cursor_words = g_new (guint32, cursor_image->width * cursor_image->height);
-      cursor_data = (guint8 *)cursor_words;
-
-      p = cursor_image->pixels;
-      q = cursor_words;
-      for (j = 0; j < cursor_image->height; j++)
-        for (i = 0; i < cursor_image->width; i++)
-          *(q++) = *(p++);
-
-      free_cursor_data = TRUE;
-    }
-
-  ctx = clutter_backend_get_cogl_context (clutter_get_default_backend ());
-  sprite = cogl_texture_2d_new_from_data (ctx,
-                                          cursor_image->width,
-                                          cursor_image->height,
-                                          CLUTTER_CAIRO_FORMAT_ARGB32,
-                                          cursor_image->width * 4, /* stride */
-                                          cursor_data,
-                                          &error);
-
-  if (free_cursor_data)
-    g_free (cursor_data);
-
-  if (error != NULL)
-    {
-      meta_warning ("Failed to allocate cursor sprite texture: %s\n", error->message);
-      cogl_error_free (error);
-    }
-
-  if (sprite != NULL)
-    {
-      MetaCursorSprite *cursor_sprite = meta_cursor_sprite_new ();
-      meta_cursor_sprite_set_texture (cursor_sprite,
-                                      COGL_TEXTURE (sprite),
-                                      cursor_image->xhot,
-                                      cursor_image->yhot);
-      cogl_object_unref (sprite);
-      tracker->xfixes_cursor = cursor_sprite;
-    }
-  XFree (cursor_image);
+  tracker->xfixes_cursor = meta_cursor_sprite_xfixes_new (display, &error);
+  if (!tracker->xfixes_cursor)
+    g_warning ("Failed to create XFIXES cursor: %s", error->message);
 }
 
 /**
@@ -308,7 +247,7 @@ meta_cursor_tracker_get_sprite (MetaCursorTracker *tracker)
   else
     {
       ensure_xfixes_cursor (tracker);
-      cursor_sprite = tracker->xfixes_cursor;
+      cursor_sprite = META_CURSOR_SPRITE (tracker->xfixes_cursor);
     }
 
   if (cursor_sprite)
@@ -345,7 +284,7 @@ meta_cursor_tracker_get_hot (MetaCursorTracker *tracker,
   else
     {
       ensure_xfixes_cursor (tracker);
-      cursor_sprite = tracker->xfixes_cursor;
+      cursor_sprite = META_CURSOR_SPRITE (tracker->xfixes_cursor);
     }
 
   if (cursor_sprite)
diff --git a/src/backends/meta-cursor.c b/src/backends/meta-cursor.c
index beeee765b..9750dc00b 100644
--- a/src/backends/meta-cursor.c
+++ b/src/backends/meta-cursor.c
@@ -23,19 +23,12 @@
 
 #include "meta-cursor.h"
 
-#include <meta/errors.h>
+#include "backends/meta-backend-private.h"
+#include "cogl/cogl.h"
+#include "meta/common.h"
 
-#include "display-private.h"
-#include "screen-private.h"
-#include "meta-backend-private.h"
-
-#include <string.h>
-
-#include <X11/cursorfont.h>
-#include <X11/extensions/Xfixes.h>
-#include <X11/Xcursor/Xcursor.h>
-
-enum {
+enum
+{
   PREPARE_AT,
   TEXTURE_CHANGED,
 
@@ -44,316 +37,148 @@ enum {
 
 static guint signals[LAST_SIGNAL];
 
-struct _MetaCursorSprite
+typedef struct _MetaCursorSpritePrivate
 {
   GObject parent;
 
-  MetaCursor cursor;
-
   CoglTexture2D *texture;
   float texture_scale;
   int hot_x, hot_y;
+} MetaCursorSpritePrivate;
 
-  int current_frame;
-  XcursorImages *xcursor_images;
-
-  int theme_scale;
-  gboolean theme_dirty;
-};
-
-G_DEFINE_TYPE (MetaCursorSprite, meta_cursor_sprite, G_TYPE_OBJECT)
+G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (MetaCursorSprite,
+                                     meta_cursor_sprite,
+                                     G_TYPE_OBJECT)
 
-static const char *
-translate_meta_cursor (MetaCursor cursor)
-{
-  switch (cursor)
-    {
-    case META_CURSOR_DEFAULT:
-      return "left_ptr";
-    case META_CURSOR_NORTH_RESIZE:
-      return "top_side";
-    case META_CURSOR_SOUTH_RESIZE:
-      return "bottom_side";
-    case META_CURSOR_WEST_RESIZE:
-      return "left_side";
-    case META_CURSOR_EAST_RESIZE:
-      return "right_side";
-    case META_CURSOR_SE_RESIZE:
-      return "bottom_right_corner";
-    case META_CURSOR_SW_RESIZE:
-      return "bottom_left_corner";
-    case META_CURSOR_NE_RESIZE:
-      return "top_right_corner";
-    case META_CURSOR_NW_RESIZE:
-      return "top_left_corner";
-    case META_CURSOR_MOVE_OR_RESIZE_WINDOW:
-      return "fleur";
-    case META_CURSOR_BUSY:
-      return "watch";
-    case META_CURSOR_DND_IN_DRAG:
-      return "dnd-none";
-    case META_CURSOR_DND_MOVE:
-      return "dnd-move";
-    case META_CURSOR_DND_COPY:
-      return "dnd-copy";
-    case META_CURSOR_DND_UNSUPPORTED_TARGET:
-      return "dnd-none";
-    case META_CURSOR_POINTING_HAND:
-      return "hand2";
-    case META_CURSOR_CROSSHAIR:
-      return "crosshair";
-    case META_CURSOR_IBEAM:
-      return "xterm";
-    default:
-      break;
-    }
-
-  g_assert_not_reached ();
-}
-
-Cursor
-meta_cursor_create_x_cursor (Display    *xdisplay,
-                             MetaCursor  cursor)
-{
-  return XcursorLibraryLoadCursor (xdisplay, translate_meta_cursor (cursor));
-}
-
-static XcursorImages *
-load_cursor_on_client (MetaCursor cursor, int scale)
-{
-  return XcursorLibraryLoadImages (translate_meta_cursor (cursor),
-                                   meta_prefs_get_cursor_theme (),
-                                   meta_prefs_get_cursor_size () * scale);
-}
-
-static void
-meta_cursor_sprite_load_from_xcursor_image (MetaCursorSprite *self,
-                                            XcursorImage     *xc_image)
+gboolean
+meta_cursor_sprite_is_animated (MetaCursorSprite *sprite)
 {
-  MetaBackend *meta_backend = meta_get_backend ();
-  MetaCursorRenderer *renderer = meta_backend_get_cursor_renderer (meta_backend);
-  uint width, height, rowstride;
-  CoglPixelFormat cogl_format;
-  ClutterBackend *clutter_backend;
-  CoglContext *cogl_context;
-  CoglTexture2D *texture;
-  CoglError *error = NULL;
-
-  g_assert (self->texture == NULL);
-
-  width           = xc_image->width;
-  height          = xc_image->height;
-  rowstride       = width * 4;
-
-#if G_BYTE_ORDER == G_LITTLE_ENDIAN
-  cogl_format = COGL_PIXEL_FORMAT_BGRA_8888;
-#else
-  cogl_format = COGL_PIXEL_FORMAT_ARGB_8888;
-#endif
-
-  clutter_backend = clutter_get_default_backend ();
-  cogl_context = clutter_backend_get_cogl_context (clutter_backend);
-  texture = cogl_texture_2d_new_from_data (cogl_context,
-                                           width, height,
-                                           cogl_format,
-                                           rowstride,
-                                           (uint8_t *) xc_image->pixels,
-                                           &error);
-
-  if (error)
-    {
-      meta_warning ("Failed to allocate cursor texture: %s\n", error->message);
-      cogl_error_free (error);
-    }
-
-  meta_cursor_sprite_set_texture (self, COGL_TEXTURE (texture),
-                                  xc_image->xhot, xc_image->yhot);
+  MetaCursorSpriteClass *klass = META_CURSOR_SPRITE_GET_CLASS (sprite);
 
-  if (texture)
-    cogl_object_unref (texture);
-
-  meta_cursor_renderer_realize_cursor_from_xcursor (renderer, self, xc_image);
-}
-
-static XcursorImage *
-meta_cursor_sprite_get_current_frame_image (MetaCursorSprite *self)
-{
-  return self->xcursor_images->images[self->current_frame];
+  if (klass->is_animated)
+    return klass->is_animated (sprite);
+  else
+    return FALSE;
 }
 
 void
-meta_cursor_sprite_tick_frame (MetaCursorSprite *self)
-{
-  XcursorImage *image;
-
-  if (!meta_cursor_sprite_is_animated (self))
-    return;
-
-  self->current_frame++;
-
-  if (self->current_frame >= self->xcursor_images->nimage)
-    self->current_frame = 0;
-
-  image = meta_cursor_sprite_get_current_frame_image (self);
-
-  g_clear_pointer (&self->texture, cogl_object_unref);
-  meta_cursor_sprite_load_from_xcursor_image (self, image);
-}
-
-guint
-meta_cursor_sprite_get_current_frame_time (MetaCursorSprite *self)
-{
-  if (!meta_cursor_sprite_is_animated (self))
-    return 0;
-
-  return self->xcursor_images->images[self->current_frame]->delay;
-}
-
-gboolean
-meta_cursor_sprite_is_animated (MetaCursorSprite *self)
+meta_cursor_sprite_tick_frame (MetaCursorSprite *sprite)
 {
-  return (self->xcursor_images &&
-          self->xcursor_images->nimage > 1);
+  return META_CURSOR_SPRITE_GET_CLASS (sprite)->tick_frame (sprite);
 }
 
-MetaCursorSprite *
-meta_cursor_sprite_new (void)
+unsigned int
+meta_cursor_sprite_get_current_frame_time (MetaCursorSprite *sprite)
 {
-  return g_object_new (META_TYPE_CURSOR_SPRITE, NULL);
+  return META_CURSOR_SPRITE_GET_CLASS (sprite)->get_current_frame_time (sprite);
 }
 
-static void
-meta_cursor_sprite_load_from_theme (MetaCursorSprite *self)
-{
-  XcursorImage *image;
-
-  g_assert (self->cursor != META_CURSOR_NONE);
-
-  self->theme_dirty = FALSE;
-
-  /* We might be reloading with a different scale. If so clear the old data. */
-  if (self->xcursor_images)
-    {
-      g_clear_pointer (&self->texture, cogl_object_unref);
-      XcursorImagesDestroy (self->xcursor_images);
-    }
-
-  self->current_frame = 0;
-  self->xcursor_images = load_cursor_on_client (self->cursor,
-                                                self->theme_scale);
-  if (!self->xcursor_images)
-    meta_fatal ("Could not find cursor. Perhaps set XCURSOR_PATH?");
-
-  image = meta_cursor_sprite_get_current_frame_image (self);
-  meta_cursor_sprite_load_from_xcursor_image (self, image);
-}
-
-MetaCursorSprite *
-meta_cursor_sprite_from_theme (MetaCursor cursor)
+void
+meta_cursor_sprite_clear_texture (MetaCursorSprite *sprite)
 {
-  MetaCursorSprite *self;
-
-  self = meta_cursor_sprite_new ();
-
-  self->cursor = cursor;
-  self->theme_dirty = TRUE;
+  MetaCursorSpritePrivate *priv =
+    meta_cursor_sprite_get_instance_private (sprite);
 
-  return self;
+  g_clear_pointer (&priv->texture, cogl_object_unref);
 }
 
 void
-meta_cursor_sprite_set_texture (MetaCursorSprite *self,
+meta_cursor_sprite_set_texture (MetaCursorSprite *sprite,
                                 CoglTexture      *texture,
                                 int               hot_x,
                                 int               hot_y)
 {
-  if (self->texture == COGL_TEXTURE_2D (texture) &&
-      self->hot_x == hot_x &&
-      self->hot_y == hot_y)
+  MetaCursorSpritePrivate *priv =
+    meta_cursor_sprite_get_instance_private (sprite);
+
+  if (priv->texture == COGL_TEXTURE_2D (texture) &&
+      priv->hot_x == hot_x &&
+      priv->hot_y == hot_y)
     return;
 
-  g_clear_pointer (&self->texture, cogl_object_unref);
+  g_clear_pointer (&priv->texture, cogl_object_unref);
   if (texture)
-    self->texture = cogl_object_ref (texture);
-  self->hot_x = hot_x;
-  self->hot_y = hot_y;
+    priv->texture = cogl_object_ref (texture);
+  priv->hot_x = hot_x;
+  priv->hot_y = hot_y;
 
-  g_signal_emit (self, signals[TEXTURE_CHANGED], 0);
+  g_signal_emit (sprite, signals[TEXTURE_CHANGED], 0);
 }
 
 void
-meta_cursor_sprite_set_texture_scale (MetaCursorSprite *self,
+meta_cursor_sprite_set_texture_scale (MetaCursorSprite *sprite,
                                       float             scale)
 {
-  self->texture_scale = scale;
-}
+  MetaCursorSpritePrivate *priv =
+    meta_cursor_sprite_get_instance_private (sprite);
 
-void
-meta_cursor_sprite_set_theme_scale (MetaCursorSprite *self,
-                                    int               theme_scale)
-{
-  if (self->theme_scale != theme_scale)
-    self->theme_dirty = TRUE;
-  self->theme_scale = theme_scale;
+  priv->texture_scale = scale;
 }
 
 CoglTexture *
-meta_cursor_sprite_get_cogl_texture (MetaCursorSprite *self)
+meta_cursor_sprite_get_cogl_texture (MetaCursorSprite *sprite)
 {
-  return COGL_TEXTURE (self->texture);
-}
+  MetaCursorSpritePrivate *priv =
+    meta_cursor_sprite_get_instance_private (sprite);
 
-MetaCursor
-meta_cursor_sprite_get_meta_cursor (MetaCursorSprite *self)
-{
-  return self->cursor;
+  return COGL_TEXTURE (priv->texture);
 }
 
 void
-meta_cursor_sprite_get_hotspot (MetaCursorSprite *self,
+meta_cursor_sprite_get_hotspot (MetaCursorSprite *sprite,
                                 int              *hot_x,
                                 int              *hot_y)
 {
-  *hot_x = self->hot_x;
-  *hot_y = self->hot_y;
+  MetaCursorSpritePrivate *priv =
+    meta_cursor_sprite_get_instance_private (sprite);
+
+  *hot_x = priv->hot_x;
+  *hot_y = priv->hot_y;
 }
 
 float
-meta_cursor_sprite_get_texture_scale (MetaCursorSprite *self)
+meta_cursor_sprite_get_texture_scale (MetaCursorSprite *sprite)
 {
-  return self->texture_scale;
+  MetaCursorSpritePrivate *priv =
+    meta_cursor_sprite_get_instance_private (sprite);
+
+  return priv->texture_scale;
 }
 
 void
-meta_cursor_sprite_prepare_at (MetaCursorSprite *self,
+meta_cursor_sprite_prepare_at (MetaCursorSprite *sprite,
                                int               x,
                                int               y)
 {
-  g_signal_emit (self, signals[PREPARE_AT], 0, x, y);
+  g_signal_emit (sprite, signals[PREPARE_AT], 0, x, y);
 }
 
 void
-meta_cursor_sprite_realize_texture (MetaCursorSprite *self)
+meta_cursor_sprite_realize_texture (MetaCursorSprite *sprite)
 {
-  if (self->theme_dirty)
-    meta_cursor_sprite_load_from_theme (self);
+  MetaCursorSpriteClass *klass = META_CURSOR_SPRITE_GET_CLASS (sprite);
+
+  if (klass->realize_texture)
+    klass->realize_texture (sprite);
 }
 
 static void
-meta_cursor_sprite_init (MetaCursorSprite *self)
+meta_cursor_sprite_init (MetaCursorSprite *sprite)
 {
-  self->texture_scale = 1.0f;
+  MetaCursorSpritePrivate *priv =
+    meta_cursor_sprite_get_instance_private (sprite);
+
+  priv->texture_scale = 1.0f;
 }
 
 static void
 meta_cursor_sprite_finalize (GObject *object)
 {
-  MetaCursorSprite *self = META_CURSOR_SPRITE (object);
-
-  if (self->xcursor_images)
-    XcursorImagesDestroy (self->xcursor_images);
+  MetaCursorSprite *sprite = META_CURSOR_SPRITE (object);
+  MetaCursorSpritePrivate *priv =
+    meta_cursor_sprite_get_instance_private (sprite);
 
-  g_clear_pointer (&self->texture, cogl_object_unref);
+  g_clear_pointer (&priv->texture, cogl_object_unref);
 
   G_OBJECT_CLASS (meta_cursor_sprite_parent_class)->finalize (object);
 }
diff --git a/src/backends/meta-cursor.h b/src/backends/meta-cursor.h
index 6087df69c..3051fdee6 100644
--- a/src/backends/meta-cursor.h
+++ b/src/backends/meta-cursor.h
@@ -25,51 +25,50 @@
 #include <meta/common.h>
 #include <meta/boxes.h>
 
-typedef struct _MetaCursorSprite MetaCursorSprite;
-
 #define META_TYPE_CURSOR_SPRITE (meta_cursor_sprite_get_type ())
-G_DECLARE_FINAL_TYPE (MetaCursorSprite,
-                      meta_cursor_sprite,
-                      META, CURSOR_SPRITE,
-                      GObject);
-
-MetaCursorSprite * meta_cursor_sprite_new (void);
-
-MetaCursorSprite * meta_cursor_sprite_from_theme  (MetaCursor cursor);
-
-
-void meta_cursor_sprite_set_theme_scale (MetaCursorSprite *self,
-                                         int               scale);
-
-MetaCursor meta_cursor_sprite_get_meta_cursor (MetaCursorSprite *self);
-
-Cursor meta_cursor_create_x_cursor (Display    *xdisplay,
-                                    MetaCursor  cursor);
-
-void meta_cursor_sprite_prepare_at (MetaCursorSprite *self,
+G_DECLARE_DERIVABLE_TYPE (MetaCursorSprite,
+                          meta_cursor_sprite,
+                          META, CURSOR_SPRITE,
+                          GObject)
+
+struct _MetaCursorSpriteClass
+{
+  GObjectClass parent_class;
+
+  void (* realize_texture) (MetaCursorSprite *sprite);
+  gboolean (* is_animated) (MetaCursorSprite *sprite);
+  void (* tick_frame) (MetaCursorSprite *sprite);
+  unsigned int (* get_current_frame_time) (MetaCursorSprite *sprite);
+};
+
+void meta_cursor_sprite_prepare_at (MetaCursorSprite *sprite,
                                     int               x,
                                     int               y);
 
-void meta_cursor_sprite_realize_texture (MetaCursorSprite *self);
+void meta_cursor_sprite_realize_texture (MetaCursorSprite *sprite);
+
+void meta_cursor_sprite_clear_texture (MetaCursorSprite *sprite);
 
-void meta_cursor_sprite_set_texture (MetaCursorSprite *self,
+void meta_cursor_sprite_set_texture (MetaCursorSprite *sprite,
                                      CoglTexture      *texture,
                                      int               hot_x,
                                      int               hot_y);
 
-void meta_cursor_sprite_set_texture_scale (MetaCursorSprite *self,
+void meta_cursor_sprite_set_texture_scale (MetaCursorSprite *sprite,
                                            float             scale);
 
-CoglTexture *meta_cursor_sprite_get_cogl_texture (MetaCursorSprite *self);
+CoglTexture *meta_cursor_sprite_get_cogl_texture (MetaCursorSprite *sprite);
 
-void meta_cursor_sprite_get_hotspot (MetaCursorSprite *self,
+void meta_cursor_sprite_get_hotspot (MetaCursorSprite *sprite,
                                      int              *hot_x,
                                      int              *hot_y);
 
-float meta_cursor_sprite_get_texture_scale (MetaCursorSprite *self);
+float meta_cursor_sprite_get_texture_scale (MetaCursorSprite *sprite);
+
+gboolean meta_cursor_sprite_is_animated (MetaCursorSprite *sprite);
+
+void meta_cursor_sprite_tick_frame (MetaCursorSprite *sprite);
 
-gboolean meta_cursor_sprite_is_animated            (MetaCursorSprite *self);
-void     meta_cursor_sprite_tick_frame             (MetaCursorSprite *self);
-guint    meta_cursor_sprite_get_current_frame_time (MetaCursorSprite *self);
+unsigned int meta_cursor_sprite_get_current_frame_time (MetaCursorSprite *sprite);
 
 #endif /* META_CURSOR_H */
diff --git a/src/backends/native/meta-backend-native.c b/src/backends/native/meta-backend-native.c
index a29f593ea..042d96ec6 100644
--- a/src/backends/native/meta-backend-native.c
+++ b/src/backends/native/meta-backend-native.c
@@ -645,8 +645,6 @@ void meta_backend_native_resume (MetaBackendNative *native)
     meta_backend_get_monitor_manager (backend);
   MetaMonitorManagerKms *monitor_manager_kms =
     META_MONITOR_MANAGER_KMS (monitor_manager);
-  MetaCursorRenderer *cursor_renderer;
-  MetaCursorRendererNative *cursor_renderer_native;
   ClutterActor *stage;
   MetaIdleMonitor *idle_monitor;
 
@@ -658,10 +656,6 @@ void meta_backend_native_resume (MetaBackendNative *native)
   stage = meta_backend_get_stage (backend);
   clutter_actor_queue_redraw (stage);
 
-  cursor_renderer = meta_backend_get_cursor_renderer (backend);
-  cursor_renderer_native = META_CURSOR_RENDERER_NATIVE (cursor_renderer);
-  meta_cursor_renderer_native_force_update (cursor_renderer_native);
-
   idle_monitor = meta_backend_get_idle_monitor (backend, 0);
   meta_idle_monitor_reset_idletime (idle_monitor);
 }
diff --git a/src/backends/native/meta-cursor-renderer-native.c 
b/src/backends/native/meta-cursor-renderer-native.c
index c7326af42..29800953b 100644
--- a/src/backends/native/meta-cursor-renderer-native.c
+++ b/src/backends/native/meta-cursor-renderer-native.c
@@ -35,6 +35,7 @@
 #include <meta/meta-backend.h>
 
 #include "backends/meta-backend-private.h"
+#include "backends/meta-cursor-sprite-xcursor.h"
 #include "backends/meta-logical-monitor.h"
 #include "backends/meta-monitor.h"
 #include "backends/meta-monitor-manager-private.h"
@@ -43,6 +44,11 @@
 #include "core/boxes-private.h"
 #include "meta/boxes.h"
 
+#ifdef HAVE_WAYLAND
+#include "wayland/meta-cursor-sprite-wayland.h"
+#include "wayland/meta-wayland-buffer.h"
+#endif
+
 #ifndef DRM_CAP_CURSOR_WIDTH
 #define DRM_CAP_CURSOR_WIDTH 0x8
 #endif
@@ -113,6 +119,11 @@ static GQuark quark_cursor_renderer_native_gpu_data = 0;
 
 G_DEFINE_TYPE_WITH_PRIVATE (MetaCursorRendererNative, meta_cursor_renderer_native, 
META_TYPE_CURSOR_RENDERER);
 
+static void
+realize_cursor_sprite (MetaCursorRenderer *renderer,
+                       MetaCursorSprite   *cursor_sprite,
+                       GList              *gpus);
+
 static MetaCursorNativeGpuState *
 get_cursor_gpu_state (MetaCursorNativePrivate *cursor_priv,
                       MetaGpuKms              *gpu_kms);
@@ -152,7 +163,8 @@ static void
 meta_cursor_renderer_native_finalize (GObject *object)
 {
   MetaCursorRendererNative *renderer = META_CURSOR_RENDERER_NATIVE (object);
-  MetaCursorRendererNativePrivate *priv = meta_cursor_renderer_native_get_instance_private (renderer);
+  MetaCursorRendererNativePrivate *priv =
+    meta_cursor_renderer_native_get_instance_private (renderer);
 
   if (priv->animation_timeout_id)
     g_source_remove (priv->animation_timeout_id);
@@ -203,7 +215,8 @@ set_crtc_cursor (MetaCursorRendererNative *native,
                  MetaCrtc                 *crtc,
                  MetaCursorSprite         *cursor_sprite)
 {
-  MetaCursorRendererNativePrivate *priv = meta_cursor_renderer_native_get_instance_private (native);
+  MetaCursorRendererNativePrivate *priv =
+    meta_cursor_renderer_native_get_instance_private (native);
   MetaCursorRendererNativeGpuData *cursor_renderer_gpu_data;
   MetaGpuKms *gpu_kms;
   int kms_fd;
@@ -371,7 +384,8 @@ static void
 update_hw_cursor (MetaCursorRendererNative *native,
                   MetaCursorSprite         *cursor_sprite)
 {
-  MetaCursorRendererNativePrivate *priv = meta_cursor_renderer_native_get_instance_private (native);
+  MetaCursorRendererNativePrivate *priv =
+    meta_cursor_renderer_native_get_instance_private (native);
   MetaCursorRenderer *renderer = META_CURSOR_RENDERER (native);
   MetaMonitorManager *monitor_manager = priv->monitor_manager;
   GList *logical_monitors;
@@ -564,18 +578,15 @@ can_draw_cursor_unscaled (MetaCursorRenderer *renderer,
 
 static gboolean
 should_have_hw_cursor (MetaCursorRenderer *renderer,
-                       MetaCursorSprite   *cursor_sprite)
+                       MetaCursorSprite   *cursor_sprite,
+                       GList              *gpus)
 {
-  MetaCursorRendererNative *native = META_CURSOR_RENDERER_NATIVE (renderer);
-  MetaCursorRendererNativePrivate *priv = meta_cursor_renderer_native_get_instance_private (native);
-  GList *gpus;
   GList *l;
   CoglTexture *texture;
 
   if (!cursor_sprite)
     return FALSE;
 
-  gpus = meta_monitor_manager_get_gpus (priv->monitor_manager);
   for (l = gpus; l; l = l->next)
     {
       MetaGpuKms *gpu_kms = l->data;
@@ -609,7 +620,8 @@ should_have_hw_cursor (MetaCursorRenderer *renderer,
 static gboolean
 meta_cursor_renderer_native_update_animation (MetaCursorRendererNative *native)
 {
-  MetaCursorRendererNativePrivate *priv = meta_cursor_renderer_native_get_instance_private (native);
+  MetaCursorRendererNativePrivate *priv =
+    meta_cursor_renderer_native_get_instance_private (native);
   MetaCursorRenderer *renderer = META_CURSOR_RENDERER (native);
   MetaCursorSprite *cursor_sprite = meta_cursor_renderer_get_cursor (renderer);
 
@@ -621,10 +633,11 @@ meta_cursor_renderer_native_update_animation (MetaCursorRendererNative *native)
 }
 
 static void
-meta_cursor_renderer_native_trigger_frame (MetaCursorRendererNative *native,
-                                           MetaCursorSprite         *cursor_sprite)
+maybe_schedule_cursor_sprite_animation_frame (MetaCursorRendererNative *native,
+                                              MetaCursorSprite         *cursor_sprite)
 {
-  MetaCursorRendererNativePrivate *priv = meta_cursor_renderer_native_get_instance_private (native);
+  MetaCursorRendererNativePrivate *priv =
+    meta_cursor_renderer_native_get_instance_private (native);
   gboolean cursor_change;
   guint delay;
 
@@ -656,21 +669,78 @@ meta_cursor_renderer_native_trigger_frame (MetaCursorRendererNative *native,
     }
 }
 
+static GList *
+calculate_cursor_sprite_gpus (MetaCursorRenderer *renderer,
+                              MetaCursorSprite   *cursor_sprite)
+{
+  MetaCursorRendererNative *native = META_CURSOR_RENDERER_NATIVE (renderer);
+  MetaCursorRendererNativePrivate *priv =
+    meta_cursor_renderer_native_get_instance_private (native);
+  MetaMonitorManager *monitor_manager = priv->monitor_manager;
+  GList *gpus = NULL;
+  GList *logical_monitors;
+  GList *l;
+  ClutterRect cursor_rect;
+
+  cursor_rect = meta_cursor_renderer_calculate_rect (renderer, cursor_sprite);
+
+  logical_monitors =
+    meta_monitor_manager_get_logical_monitors (monitor_manager);
+  for (l = logical_monitors; l; l = l->next)
+    {
+      MetaLogicalMonitor *logical_monitor = l->data;
+      MetaRectangle logical_monitor_layout;
+      ClutterRect logical_monitor_rect;
+      GList *monitors, *l_mon;
+
+      logical_monitor_layout =
+        meta_logical_monitor_get_layout (logical_monitor);
+      logical_monitor_rect =
+        meta_rectangle_to_clutter_rect (&logical_monitor_layout);
+
+      if (!clutter_rect_intersection (&cursor_rect, &logical_monitor_rect,
+                                      NULL))
+        continue;
+
+      monitors = meta_logical_monitor_get_monitors (logical_monitor);
+      for (l_mon = monitors; l_mon; l_mon = l_mon->next)
+        {
+          MetaMonitor *monitor = l_mon->data;
+          MetaGpu *gpu;
+
+          gpu = meta_monitor_get_gpu (monitor);
+          if (!g_list_find (gpus, gpu))
+            gpus = g_list_prepend (gpus, gpu);
+        }
+    }
+
+  return gpus;
+}
+
 static gboolean
 meta_cursor_renderer_native_update_cursor (MetaCursorRenderer *renderer,
                                            MetaCursorSprite   *cursor_sprite)
 {
   MetaCursorRendererNative *native = META_CURSOR_RENDERER_NATIVE (renderer);
-  MetaCursorRendererNativePrivate *priv = meta_cursor_renderer_native_get_instance_private (native);
+  MetaCursorRendererNativePrivate *priv =
+    meta_cursor_renderer_native_get_instance_private (native);
+  g_autoptr (GList) gpus = NULL;
 
   if (cursor_sprite)
-    meta_cursor_sprite_realize_texture (cursor_sprite);
+    {
+      meta_cursor_sprite_realize_texture (cursor_sprite);
+      gpus = calculate_cursor_sprite_gpus (renderer, cursor_sprite);
+      realize_cursor_sprite (renderer, cursor_sprite, gpus);
+    }
 
-  meta_cursor_renderer_native_trigger_frame (native, cursor_sprite);
+  maybe_schedule_cursor_sprite_animation_frame (native, cursor_sprite);
 
-  priv->has_hw_cursor = should_have_hw_cursor (renderer, cursor_sprite);
+  priv->has_hw_cursor = should_have_hw_cursor (renderer, cursor_sprite, gpus);
   update_hw_cursor (native, cursor_sprite);
-  return priv->has_hw_cursor;
+
+  return (priv->has_hw_cursor ||
+          !cursor_sprite ||
+          !meta_cursor_sprite_get_cogl_texture (cursor_sprite));
 }
 
 static void
@@ -706,6 +776,24 @@ ensure_cursor_gpu_state (MetaCursorNativePrivate *cursor_priv,
   return cursor_gpu_state;
 }
 
+static void
+on_cursor_sprite_texture_changed (MetaCursorSprite *cursor_sprite)
+{
+  MetaCursorNativePrivate *cursor_priv = get_cursor_priv (cursor_sprite);
+  GHashTableIter iter;
+  MetaCursorNativeGpuState *cursor_gpu_state;
+
+  g_hash_table_iter_init (&iter, cursor_priv->gpu_states);
+  while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &cursor_gpu_state))
+    {
+      guint pending_bo;
+      pending_bo = get_pending_cursor_sprite_gbm_bo_index (cursor_gpu_state);
+      g_clear_pointer (&cursor_gpu_state->bos[pending_bo],
+                       (GDestroyNotify) gbm_bo_destroy);
+      cursor_gpu_state->pending_bo_state = META_CURSOR_GBM_BO_STATE_INVALIDATED;
+    }
+}
+
 static void
 cursor_priv_free (MetaCursorNativePrivate *cursor_priv)
 {
@@ -738,6 +826,9 @@ ensure_cursor_priv (MetaCursorSprite *cursor_sprite)
                            cursor_priv,
                            (GDestroyNotify) cursor_priv_free);
 
+  g_signal_connect (cursor_sprite, "texture-changed",
+                    G_CALLBACK (on_cursor_sprite_texture_changed), NULL);
+
   return cursor_priv;
 }
 
@@ -805,57 +896,71 @@ load_cursor_sprite_gbm_buffer_for_gpu (MetaCursorRendererNative *native,
     }
 }
 
-static void
-invalidate_pending_cursor_sprite_gbm_bo (MetaCursorSprite *cursor_sprite,
-                                         MetaGpuKms       *gpu_kms)
+static gboolean
+is_cursor_hw_state_valid (MetaCursorSprite *cursor_sprite,
+                          MetaGpuKms       *gpu_kms)
 {
   MetaCursorNativePrivate *cursor_priv;
   MetaCursorNativeGpuState *cursor_gpu_state;
-  guint pending_bo;
 
   cursor_priv = get_cursor_priv (cursor_sprite);
   if (!cursor_priv)
-    return;
+    return FALSE;
 
   cursor_gpu_state = get_cursor_gpu_state (cursor_priv, gpu_kms);
   if (!cursor_gpu_state)
-    return;
+    return FALSE;
 
-  pending_bo = get_pending_cursor_sprite_gbm_bo_index (cursor_gpu_state);
-  g_clear_pointer (&cursor_gpu_state->bos[pending_bo],
-                   (GDestroyNotify) gbm_bo_destroy);
-  cursor_gpu_state->pending_bo_state = META_CURSOR_GBM_BO_STATE_INVALIDATED;
+  switch (cursor_gpu_state->pending_bo_state)
+    {
+    case META_CURSOR_GBM_BO_STATE_SET:
+    case META_CURSOR_GBM_BO_STATE_NONE:
+      return TRUE;
+    case META_CURSOR_GBM_BO_STATE_INVALIDATED:
+      return FALSE;
+    }
+
+  g_assert_not_reached ();
 }
 
 #ifdef HAVE_WAYLAND
 static void
-meta_cursor_renderer_native_realize_cursor_from_wl_buffer_for_gpu (MetaCursorRenderer *renderer,
-                                                                   MetaGpuKms         *gpu_kms,
-                                                                   MetaCursorSprite   *cursor_sprite,
-                                                                   struct wl_resource *buffer)
+realize_cursor_sprite_from_wl_buffer_for_gpu (MetaCursorRenderer      *renderer,
+                                              MetaGpuKms              *gpu_kms,
+                                              MetaCursorSpriteWayland *sprite_wayland)
 {
   MetaCursorRendererNative *native = META_CURSOR_RENDERER_NATIVE (renderer);
+  MetaCursorSprite *cursor_sprite = META_CURSOR_SPRITE (sprite_wayland);
   MetaCursorRendererNativeGpuData *cursor_renderer_gpu_data;
   uint32_t gbm_format;
   uint64_t cursor_width, cursor_height;
   CoglTexture *texture;
   uint width, height;
+  MetaWaylandBuffer *buffer;
+  struct wl_resource *buffer_resource;
+  struct wl_shm_buffer *shm_buffer;
 
   cursor_renderer_gpu_data =
     meta_cursor_renderer_native_gpu_data_from_gpu (gpu_kms);
   if (!cursor_renderer_gpu_data || cursor_renderer_gpu_data->hw_cursor_broken)
     return;
 
-  /* Destroy any previous pending cursor buffer; we'll always either fail (which
-   * should unset, or succeed, which will set new buffer.
-   */
-  invalidate_pending_cursor_sprite_gbm_bo (cursor_sprite, gpu_kms);
+  if (is_cursor_hw_state_valid (cursor_sprite, gpu_kms))
+    return;
 
   texture = meta_cursor_sprite_get_cogl_texture (cursor_sprite);
   width = cogl_texture_get_width (texture);
   height = cogl_texture_get_height (texture);
 
-  struct wl_shm_buffer *shm_buffer = wl_shm_buffer_get (buffer);
+  buffer = meta_cursor_sprite_wayland_get_buffer (sprite_wayland);
+  if (!buffer)
+    return;
+
+  buffer_resource = meta_wayland_buffer_get_resource (buffer);
+  if (!buffer_resource)
+    return;
+
+  shm_buffer = wl_shm_buffer_get (buffer_resource);
   if (shm_buffer)
     {
       int rowstride = wl_shm_buffer_get_stride (shm_buffer);
@@ -929,47 +1034,27 @@ meta_cursor_renderer_native_realize_cursor_from_wl_buffer_for_gpu (MetaCursorRen
       set_pending_cursor_sprite_gbm_bo (cursor_sprite, gpu_kms, bo);
     }
 }
-
-static void
-meta_cursor_renderer_native_realize_cursor_from_wl_buffer (MetaCursorRenderer *renderer,
-                                                           MetaCursorSprite *cursor_sprite,
-                                                           struct wl_resource *buffer)
-{
-  MetaCursorRendererNative *native = META_CURSOR_RENDERER_NATIVE (renderer);
-  MetaCursorRendererNativePrivate *priv =
-         meta_cursor_renderer_native_get_instance_private (native);
-  GList *gpus;
-  GList *l;
-
-  gpus = meta_monitor_manager_get_gpus (priv->monitor_manager);
-  for (l = gpus; l; l = l->next)
-    {
-      MetaGpuKms *gpu_kms = l->data;
-
-      meta_cursor_renderer_native_realize_cursor_from_wl_buffer_for_gpu (
-        renderer,
-        gpu_kms,
-        cursor_sprite,
-        buffer);
-    }
-}
 #endif
 
 static void
-meta_cursor_renderer_native_realize_cursor_from_xcursor_for_gpu (MetaCursorRenderer *renderer,
-                                                                 MetaGpuKms         *gpu_kms,
-                                                                 MetaCursorSprite   *cursor_sprite,
-                                                                 XcursorImage       *xc_image)
+realize_cursor_sprite_from_xcursor_for_gpu (MetaCursorRenderer      *renderer,
+                                            MetaGpuKms              *gpu_kms,
+                                            MetaCursorSpriteXcursor *sprite_xcursor)
 {
   MetaCursorRendererNative *native = META_CURSOR_RENDERER_NATIVE (renderer);
   MetaCursorRendererNativeGpuData *cursor_renderer_gpu_data;
+  MetaCursorSprite *cursor_sprite = META_CURSOR_SPRITE (sprite_xcursor);
+  XcursorImage *xc_image;
 
   cursor_renderer_gpu_data =
     meta_cursor_renderer_native_gpu_data_from_gpu (gpu_kms);
   if (!cursor_renderer_gpu_data || cursor_renderer_gpu_data->hw_cursor_broken)
     return;
 
-  invalidate_pending_cursor_sprite_gbm_bo (cursor_sprite, gpu_kms);
+  if (is_cursor_hw_state_valid (cursor_sprite, gpu_kms))
+    return;
+
+  xc_image = meta_cursor_sprite_xcursor_get_current_image (sprite_xcursor);
 
   load_cursor_sprite_gbm_buffer_for_gpu (native,
                                          gpu_kms,
@@ -982,26 +1067,45 @@ meta_cursor_renderer_native_realize_cursor_from_xcursor_for_gpu (MetaCursorRende
 }
 
 static void
-meta_cursor_renderer_native_realize_cursor_from_xcursor (MetaCursorRenderer *renderer,
-                                                         MetaCursorSprite   *cursor_sprite,
-                                                         XcursorImage       *xc_image)
+realize_cursor_sprite_for_gpu (MetaCursorRenderer *renderer,
+                               MetaGpuKms         *gpu_kms,
+                               MetaCursorSprite   *cursor_sprite)
+{
+#ifdef HAVE_WAYLAND
+  if (META_IS_CURSOR_SPRITE_WAYLAND (cursor_sprite))
+    {
+      MetaCursorSpriteWayland *sprite_wayland =
+        META_CURSOR_SPRITE_WAYLAND (cursor_sprite);
+
+      realize_cursor_sprite_from_wl_buffer_for_gpu (renderer,
+                                                    gpu_kms,
+                                                    sprite_wayland);
+    }
+  else
+#endif
+  if (META_IS_CURSOR_SPRITE_XCURSOR (cursor_sprite))
+    {
+      MetaCursorSpriteXcursor *sprite_xcursor =
+        META_CURSOR_SPRITE_XCURSOR (cursor_sprite);
+
+      realize_cursor_sprite_from_xcursor_for_gpu (renderer,
+                                                  gpu_kms,
+                                                  sprite_xcursor);
+    }
+}
+
+static void
+realize_cursor_sprite (MetaCursorRenderer *renderer,
+                       MetaCursorSprite   *cursor_sprite,
+                       GList              *gpus)
 {
-  MetaCursorRendererNative *native = META_CURSOR_RENDERER_NATIVE (renderer);
-  MetaCursorRendererNativePrivate *priv =
-         meta_cursor_renderer_native_get_instance_private (native);
-  GList *gpus;
   GList *l;
 
-  gpus = meta_monitor_manager_get_gpus (priv->monitor_manager);
   for (l = gpus; l; l = l->next)
     {
       MetaGpuKms *gpu_kms = l->data;
 
-      meta_cursor_renderer_native_realize_cursor_from_xcursor_for_gpu (
-        renderer,
-        gpu_kms,
-        cursor_sprite,
-        xc_image);
+      realize_cursor_sprite_for_gpu (renderer, gpu_kms, cursor_sprite);
     }
 }
 
@@ -1013,12 +1117,6 @@ meta_cursor_renderer_native_class_init (MetaCursorRendererNativeClass *klass)
 
   object_class->finalize = meta_cursor_renderer_native_finalize;
   renderer_class->update_cursor = meta_cursor_renderer_native_update_cursor;
-#ifdef HAVE_WAYLAND
-  renderer_class->realize_cursor_from_wl_buffer =
-    meta_cursor_renderer_native_realize_cursor_from_wl_buffer;
-#endif
-  renderer_class->realize_cursor_from_xcursor =
-    meta_cursor_renderer_native_realize_cursor_from_xcursor;
 
   quark_cursor_sprite = g_quark_from_static_string ("-meta-cursor-native");
   quark_cursor_renderer_native_gpu_data =
@@ -1033,14 +1131,13 @@ force_update_hw_cursor (MetaCursorRendererNative *native)
     meta_cursor_renderer_native_get_instance_private (native);
 
   priv->hw_state_invalidated = TRUE;
-  update_hw_cursor (native, meta_cursor_renderer_get_cursor (renderer));
+  meta_cursor_renderer_force_update (renderer);
 }
 
 static void
 on_monitors_changed (MetaMonitorManager       *monitors,
                      MetaCursorRendererNative *native)
 {
-  /* Our tracking is all messed up, so force an update. */
   force_update_hw_cursor (native);
 }
 
@@ -1112,9 +1209,3 @@ static void
 meta_cursor_renderer_native_init (MetaCursorRendererNative *native)
 {
 }
-
-void
-meta_cursor_renderer_native_force_update (MetaCursorRendererNative *native)
-{
-  force_update_hw_cursor (native);
-}
diff --git a/src/backends/native/meta-cursor-renderer-native.h 
b/src/backends/native/meta-cursor-renderer-native.h
index 09203a5f7..fb4c8edc7 100644
--- a/src/backends/native/meta-cursor-renderer-native.h
+++ b/src/backends/native/meta-cursor-renderer-native.h
@@ -32,8 +32,6 @@ G_DECLARE_FINAL_TYPE (MetaCursorRendererNative, meta_cursor_renderer_native,
                       META, CURSOR_RENDERER_NATIVE,
                       MetaCursorRenderer)
 
-void meta_cursor_renderer_native_force_update (MetaCursorRendererNative *renderer);
-
 MetaCursorRendererNative * meta_cursor_renderer_native_new (MetaBackend *backend);
 
 #endif /* META_CURSOR_RENDERER_NATIVE_H */
diff --git a/src/backends/x11/meta-cursor-renderer-x11.c b/src/backends/x11/meta-cursor-renderer-x11.c
index 82109f1f3..bb3100a91 100644
--- a/src/backends/x11/meta-cursor-renderer-x11.c
+++ b/src/backends/x11/meta-cursor-renderer-x11.c
@@ -30,6 +30,7 @@
 
 #include "meta-backend-x11.h"
 #include "meta-stage-private.h"
+#include "backends/meta-cursor-sprite-xcursor.h"
 
 struct _MetaCursorRendererX11Private
 {
@@ -59,13 +60,18 @@ meta_cursor_renderer_x11_update_cursor (MetaCursorRenderer *renderer,
 
   gboolean has_server_cursor = FALSE;
 
-  if (cursor_sprite)
+  if (cursor_sprite && META_IS_CURSOR_SPRITE_XCURSOR (cursor_sprite))
     {
-      MetaCursor cursor = meta_cursor_sprite_get_meta_cursor (cursor_sprite);
+      MetaCursorSpriteXcursor *sprite_xcursor =
+        META_CURSOR_SPRITE_XCURSOR (cursor_sprite);
+      MetaCursor cursor;
 
+      cursor = meta_cursor_sprite_xcursor_get_cursor (sprite_xcursor);
       if (cursor != META_CURSOR_NONE)
         {
-          Cursor xcursor = meta_cursor_create_x_cursor (xdisplay, cursor);
+          Cursor xcursor;
+
+          xcursor = meta_create_x_cursor (xdisplay, cursor);
           XDefineCursor (xdisplay, xwindow, xcursor);
           XFlush (xdisplay);
           XFreeCursor (xdisplay, xcursor);
diff --git a/src/backends/x11/nested/meta-cursor-renderer-x11-nested.c 
b/src/backends/x11/nested/meta-cursor-renderer-x11-nested.c
index da1a56038..0daae683c 100644
--- a/src/backends/x11/nested/meta-cursor-renderer-x11-nested.c
+++ b/src/backends/x11/nested/meta-cursor-renderer-x11-nested.c
@@ -26,6 +26,8 @@
 
 #include "backends/x11/nested/meta-cursor-renderer-x11-nested.h"
 
+#include <X11/Xcursor/Xcursor.h>
+
 #include "backends/x11/meta-backend-x11.h"
 
 struct _MetaCursorRendererX11Nested
diff --git a/src/core/display.c b/src/core/display.c
index d6da84b30..e7dd4534b 100644
--- a/src/core/display.c
+++ b/src/core/display.c
@@ -3018,7 +3018,7 @@ Cursor
 meta_display_create_x_cursor (MetaDisplay *display,
                               MetaCursor   cursor)
 {
-  return meta_cursor_create_x_cursor (display->xdisplay, cursor);
+  return meta_create_x_cursor (display->xdisplay, cursor);
 }
 
 MetaGestureTracker *
diff --git a/src/core/screen.c b/src/core/screen.c
index c14bba0cf..048104150 100644
--- a/src/core/screen.c
+++ b/src/core/screen.c
@@ -60,6 +60,7 @@
 #include "x11/xprops.h"
 
 #include "backends/x11/meta-backend-x11.h"
+#include "backends/meta-cursor-sprite-xcursor.h"
 
 static char* get_screen_name (MetaDisplay *display,
                               int          number);
@@ -1323,12 +1324,13 @@ find_highest_logical_monitor_scale (MetaBackend      *backend,
 }
 
 static void
-root_cursor_prepare_at (MetaCursorSprite *cursor_sprite,
-                        int               x,
-                        int               y,
-                        MetaScreen       *screen)
+root_cursor_prepare_at (MetaCursorSpriteXcursor *sprite_xcursor,
+                        int                      x,
+                        int                      y,
+                        MetaScreen              *screen)
 {
   MetaBackend *backend = meta_get_backend ();
+  MetaCursorSprite *cursor_sprite = META_CURSOR_SPRITE (sprite_xcursor);
 
   if (meta_is_stage_views_scaled ())
     {
@@ -1337,7 +1339,7 @@ root_cursor_prepare_at (MetaCursorSprite *cursor_sprite,
       scale = find_highest_logical_monitor_scale (backend, cursor_sprite);
       if (scale != 0.0)
         {
-          meta_cursor_sprite_set_theme_scale (cursor_sprite, scale);
+          meta_cursor_sprite_xcursor_set_theme_scale (sprite_xcursor, scale);
           meta_cursor_sprite_set_texture_scale (cursor_sprite, 1.0 / scale);
         }
     }
@@ -1353,18 +1355,18 @@ root_cursor_prepare_at (MetaCursorSprite *cursor_sprite,
       /* Reload the cursor texture if the scale has changed. */
       if (logical_monitor)
         {
-          meta_cursor_sprite_set_theme_scale (cursor_sprite,
-                                              logical_monitor->scale);
+          meta_cursor_sprite_xcursor_set_theme_scale (sprite_xcursor,
+                                                      logical_monitor->scale);
           meta_cursor_sprite_set_texture_scale (cursor_sprite, 1.0);
         }
     }
 }
 
 static void
-manage_root_cursor_sprite_scale (MetaScreen       *screen,
-                                 MetaCursorSprite *cursor_sprite)
+manage_root_cursor_sprite_scale (MetaScreen              *screen,
+                                 MetaCursorSpriteXcursor *sprite_xcursor)
 {
-  g_signal_connect_object (cursor_sprite,
+  g_signal_connect_object (sprite_xcursor,
                            "prepare-at",
                            G_CALLBACK (root_cursor_prepare_at),
                            screen,
@@ -1377,17 +1379,18 @@ meta_screen_update_cursor (MetaScreen *screen)
   MetaDisplay *display = screen->display;
   MetaCursor cursor = screen->current_cursor;
   Cursor xcursor;
-  MetaCursorSprite *cursor_sprite;
+  MetaCursorSpriteXcursor *sprite_xcursor;
   MetaBackend *backend = meta_get_backend ();
   MetaCursorTracker *cursor_tracker = meta_backend_get_cursor_tracker (backend);
 
-  cursor_sprite = meta_cursor_sprite_from_theme (cursor);
+  sprite_xcursor = meta_cursor_sprite_xcursor_new (cursor);
 
   if (meta_is_wayland_compositor ())
-    manage_root_cursor_sprite_scale (screen, cursor_sprite);
+    manage_root_cursor_sprite_scale (screen, sprite_xcursor);
 
-  meta_cursor_tracker_set_root_cursor (cursor_tracker, cursor_sprite);
-  g_object_unref (cursor_sprite);
+  meta_cursor_tracker_set_root_cursor (cursor_tracker,
+                                       META_CURSOR_SPRITE (sprite_xcursor));
+  g_object_unref (sprite_xcursor);
 
   /* Set a cursor for X11 applications that don't specify their own */
   xcursor = meta_display_create_x_cursor (display, cursor);
diff --git a/src/wayland/meta-wayland-buffer.c b/src/wayland/meta-wayland-buffer.c
index 55564492a..c759eefc1 100644
--- a/src/wayland/meta-wayland-buffer.c
+++ b/src/wayland/meta-wayland-buffer.c
@@ -88,6 +88,12 @@ meta_wayland_buffer_from_resource (struct wl_resource *resource)
   return buffer;
 }
 
+struct wl_resource *
+meta_wayland_buffer_get_resource (MetaWaylandBuffer *buffer)
+{
+  return buffer->resource;
+}
+
 static gboolean
 meta_wayland_buffer_is_realized (MetaWaylandBuffer *buffer)
 {
diff --git a/src/wayland/meta-wayland-buffer.h b/src/wayland/meta-wayland-buffer.h
index 5345033c2..e00a41e09 100644
--- a/src/wayland/meta-wayland-buffer.h
+++ b/src/wayland/meta-wayland-buffer.h
@@ -68,6 +68,7 @@ G_DECLARE_FINAL_TYPE (MetaWaylandBuffer, meta_wayland_buffer,
                       META, WAYLAND_BUFFER, GObject);
 
 MetaWaylandBuffer *     meta_wayland_buffer_from_resource       (struct wl_resource    *resource);
+struct wl_resource *    meta_wayland_buffer_get_resource        (MetaWaylandBuffer     *buffer);
 gboolean                meta_wayland_buffer_attach              (MetaWaylandBuffer     *buffer,
                                                                  GError               **error);
 CoglTexture *           meta_wayland_buffer_get_texture         (MetaWaylandBuffer     *buffer);
diff --git a/src/wayland/meta-wayland-pointer.c b/src/wayland/meta-wayland-pointer.c
index d5c90c169..e8138576e 100644
--- a/src/wayland/meta-wayland-pointer.c
+++ b/src/wayland/meta-wayland-pointer.c
@@ -55,7 +55,7 @@
 #include "meta-wayland-seat.h"
 #include "meta-wayland-surface.h"
 #include "meta-wayland-buffer.h"
-#include "meta-wayland-surface-role-cursor.h"
+#include "meta-wayland-cursor-surface.h"
 #include "meta-xwayland.h"
 #include "meta-cursor.h"
 #include "meta-cursor-tracker-private.h"
@@ -1025,10 +1025,10 @@ meta_wayland_pointer_update_cursor_surface (MetaWaylandPointer *pointer)
 
       if (pointer->cursor_surface)
         {
-          MetaWaylandSurfaceRoleCursor *cursor_role =
-            META_WAYLAND_SURFACE_ROLE_CURSOR (pointer->cursor_surface->role);
+          MetaWaylandCursorSurface *cursor_surface =
+            META_WAYLAND_CURSOR_SURFACE (pointer->cursor_surface->role);
 
-          cursor_sprite = meta_wayland_surface_role_cursor_get_sprite (cursor_role);
+          cursor_sprite = meta_wayland_cursor_surface_get_sprite (cursor_surface);
         }
 
       meta_cursor_tracker_set_window_cursor (cursor_tracker, cursor_sprite);
@@ -1102,7 +1102,7 @@ pointer_set_cursor (struct wl_client *client,
 
   if (surface &&
       !meta_wayland_surface_assign_role (surface,
-                                         META_TYPE_WAYLAND_SURFACE_ROLE_CURSOR,
+                                         META_TYPE_WAYLAND_CURSOR_SURFACE,
                                          NULL))
     {
       wl_resource_post_error (resource, WL_POINTER_ERROR_ROLE,
@@ -1115,13 +1115,13 @@ pointer_set_cursor (struct wl_client *client,
     {
       MetaCursorRenderer *cursor_renderer =
         meta_backend_get_cursor_renderer (meta_get_backend ());
-      MetaWaylandSurfaceRoleCursor *cursor_role;
+      MetaWaylandCursorSurface *cursor_surface;
 
-      cursor_role = META_WAYLAND_SURFACE_ROLE_CURSOR (surface->role);
-      meta_wayland_surface_role_cursor_set_renderer (cursor_role,
-                                                     cursor_renderer);
-      meta_wayland_surface_role_cursor_set_hotspot (cursor_role,
-                                                    hot_x, hot_y);
+      cursor_surface = META_WAYLAND_CURSOR_SURFACE (surface->role);
+      meta_wayland_cursor_surface_set_renderer (cursor_surface,
+                                                cursor_renderer);
+      meta_wayland_cursor_surface_set_hotspot (cursor_surface,
+                                               hot_x, hot_y);
     }
 
   meta_wayland_pointer_set_cursor_surface (pointer, surface);
diff --git a/src/wayland/meta-wayland-tablet-tool.c b/src/wayland/meta-wayland-tablet-tool.c
index 4b57d4156..d373f8d25 100644
--- a/src/wayland/meta-wayland-tablet-tool.c
+++ b/src/wayland/meta-wayland-tablet-tool.c
@@ -31,7 +31,7 @@
 #include <wayland-server.h>
 #include "tablet-unstable-v2-server-protocol.h"
 #include "meta-wayland-private.h"
-#include "meta-wayland-surface-role-tablet-cursor.h"
+#include "meta-wayland-tablet-cursor-surface.h"
 #include "meta-surface-actor-wayland.h"
 #include "meta-wayland-tablet.h"
 #include "meta-wayland-tablet-seat.h"
@@ -90,16 +90,16 @@ meta_wayland_tablet_tool_update_cursor_surface (MetaWaylandTabletTool *tool)
       if (tool->cursor_surface &&
           meta_wayland_surface_get_buffer (tool->cursor_surface))
         {
-          MetaWaylandSurfaceRoleCursor *cursor_role =
-            META_WAYLAND_SURFACE_ROLE_CURSOR (tool->cursor_surface->role);
+          MetaWaylandCursorSurface *cursor_surface =
+            META_WAYLAND_CURSOR_SURFACE (tool->cursor_surface->role);
 
-          cursor = meta_wayland_surface_role_cursor_get_sprite (cursor_role);
+          cursor = meta_wayland_cursor_surface_get_sprite (cursor_surface);
         }
       else
         cursor = NULL;
     }
   else if (tool->current_tablet)
-    cursor = tool->default_sprite;
+    cursor = META_CURSOR_SPRITE (tool->default_sprite);
   else
     cursor = NULL;
 
@@ -382,10 +382,10 @@ tablet_tool_handle_cursor_surface_destroy (struct wl_listener *listener,
 }
 
 static void
-tool_cursor_prepare_at (MetaCursorSprite      *cursor_sprite,
-                        int                    x,
-                        int                    y,
-                        MetaWaylandTabletTool *tool)
+tool_cursor_prepare_at (MetaCursorSpriteXcursor *sprite_xcursor,
+                        int                      x,
+                        int                      y,
+                        MetaWaylandTabletTool   *tool)
 {
   MetaBackend *backend = meta_get_backend ();
   MetaMonitorManager *monitor_manager =
@@ -397,7 +397,8 @@ tool_cursor_prepare_at (MetaCursorSprite      *cursor_sprite,
 
   /* Reload the cursor texture if the scale has changed. */
   if (logical_monitor)
-    meta_cursor_sprite_set_theme_scale (cursor_sprite, logical_monitor->scale);
+    meta_cursor_sprite_xcursor_set_theme_scale (sprite_xcursor,
+                                                logical_monitor->scale);
 }
 
 MetaWaylandTabletTool *
@@ -417,7 +418,7 @@ 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_from_theme (META_CURSOR_CROSSHAIR);
+  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);
@@ -471,7 +472,7 @@ tool_set_cursor (struct wl_client   *client,
 
   if (surface &&
       !meta_wayland_surface_assign_role (surface,
-                                         META_TYPE_WAYLAND_SURFACE_ROLE_TABLET_CURSOR,
+                                         META_TYPE_WAYLAND_TABLET_CURSOR_SURFACE,
                                          NULL))
     {
       wl_resource_post_error (resource, WL_POINTER_ERROR_ROLE,
@@ -482,13 +483,13 @@ tool_set_cursor (struct wl_client   *client,
 
   if (surface)
     {
-      MetaWaylandSurfaceRoleCursor *cursor_role;
+      MetaWaylandCursorSurface *cursor_surface;
 
-      cursor_role = META_WAYLAND_SURFACE_ROLE_CURSOR (surface->role);
-      meta_wayland_surface_role_cursor_set_renderer (cursor_role,
-                                                     tool->cursor_renderer);
-      meta_wayland_surface_role_cursor_set_hotspot (cursor_role,
-                                                    hotspot_x, hotspot_y);
+      cursor_surface = META_WAYLAND_CURSOR_SURFACE (surface->role);
+      meta_wayland_cursor_surface_set_renderer (cursor_surface,
+                                                tool->cursor_renderer);
+      meta_wayland_cursor_surface_set_hotspot (cursor_surface,
+                                               hotspot_x, hotspot_y);
     }
 
   meta_wayland_tablet_tool_set_cursor_surface (tool, surface);
diff --git a/src/wayland/meta-wayland-tablet-tool.h b/src/wayland/meta-wayland-tablet-tool.h
index 8cd930086..011972fc2 100644
--- a/src/wayland/meta-wayland-tablet-tool.h
+++ b/src/wayland/meta-wayland-tablet-tool.h
@@ -28,6 +28,7 @@
 
 #include "meta-wayland-types.h"
 #include "meta-cursor-renderer.h"
+#include "backends/meta-cursor-sprite-xcursor.h"
 
 struct _MetaWaylandTabletTool
 {
@@ -43,7 +44,7 @@ struct _MetaWaylandTabletTool
   MetaWaylandSurface *cursor_surface;
   struct wl_listener cursor_surface_destroy_listener;
   MetaCursorRenderer *cursor_renderer;
-  MetaCursorSprite *default_sprite;
+  MetaCursorSpriteXcursor *default_sprite;
   guint prepare_at_signal_id;
 
   MetaWaylandSurface *current;


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