From 817c8e568c2674bc5bcaa7cbec9e4d0d24a64401 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Mon, 30 Apr 2018 12:03:31 +0200 Subject: [PATCH] wayland: Add wl_surface backed cursor sprite implementation This removes the last use of the non-abstract form of MetaCursorSprite usage. https://gitlab.gnome.org/GNOME/mutter/issues/77 --- src/Makefile.am | 2 + src/backends/meta-cursor.c | 10 ++-- src/backends/meta-cursor.h | 2 - src/wayland/meta-cursor-sprite-wayland.c | 62 +++++++++++++++++++++++ src/wayland/meta-cursor-sprite-wayland.h | 32 ++++++++++++ src/wayland/meta-wayland-cursor-surface.c | 11 ++-- 6 files changed, 105 insertions(+), 14 deletions(-) create mode 100644 src/wayland/meta-cursor-sprite-wayland.c create mode 100644 src/wayland/meta-cursor-sprite-wayland.h diff --git a/src/Makefile.am b/src/Makefile.am index 8094abc98..5bbac70e8 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -374,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 \ diff --git a/src/backends/meta-cursor.c b/src/backends/meta-cursor.c index 57f65236b..9750dc00b 100644 --- a/src/backends/meta-cursor.c +++ b/src/backends/meta-cursor.c @@ -46,7 +46,9 @@ typedef struct _MetaCursorSpritePrivate int hot_x, hot_y; } MetaCursorSpritePrivate; -G_DEFINE_TYPE_WITH_PRIVATE (MetaCursorSprite, meta_cursor_sprite, G_TYPE_OBJECT) +G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (MetaCursorSprite, + meta_cursor_sprite, + G_TYPE_OBJECT) gboolean meta_cursor_sprite_is_animated (MetaCursorSprite *sprite) @@ -71,12 +73,6 @@ meta_cursor_sprite_get_current_frame_time (MetaCursorSprite *sprite) return META_CURSOR_SPRITE_GET_CLASS (sprite)->get_current_frame_time (sprite); } -MetaCursorSprite * -meta_cursor_sprite_new (void) -{ - return g_object_new (META_TYPE_CURSOR_SPRITE, NULL); -} - void meta_cursor_sprite_clear_texture (MetaCursorSprite *sprite) { diff --git a/src/backends/meta-cursor.h b/src/backends/meta-cursor.h index e9ba5c46a..3051fdee6 100644 --- a/src/backends/meta-cursor.h +++ b/src/backends/meta-cursor.h @@ -41,8 +41,6 @@ struct _MetaCursorSpriteClass unsigned int (* get_current_frame_time) (MetaCursorSprite *sprite); }; -MetaCursorSprite * meta_cursor_sprite_new (void); - void meta_cursor_sprite_prepare_at (MetaCursorSprite *sprite, int x, int y); diff --git a/src/wayland/meta-cursor-sprite-wayland.c b/src/wayland/meta-cursor-sprite-wayland.c new file mode 100644 index 000000000..20532f13c --- /dev/null +++ b/src/wayland/meta-cursor-sprite-wayland.c @@ -0,0 +1,62 @@ +/* + * Copyright 2015, 2018 Red Hat, Inc. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + * + */ + +#include "config.h" + +#include "wayland/meta-cursor-sprite-wayland.h" + +struct _MetaCursorSpriteWayland +{ + MetaCursorSprite parent; +}; + +G_DEFINE_TYPE (MetaCursorSpriteWayland, + meta_cursor_sprite_wayland, + META_TYPE_CURSOR_SPRITE) + +static void +meta_cursor_sprite_wayland_realize_texture (MetaCursorSprite *sprite) +{ +} + +static gboolean +meta_cursor_sprite_wayland_is_animated (MetaCursorSprite *sprite) +{ + return FALSE; +} + +MetaCursorSpriteWayland * +meta_cursor_sprite_wayland_new (void) +{ + return g_object_new (META_TYPE_CURSOR_SPRITE_WAYLAND, NULL); +} + +static void +meta_cursor_sprite_wayland_init (MetaCursorSpriteWayland *sprite_wayland) +{ +} + +static void +meta_cursor_sprite_wayland_class_init (MetaCursorSpriteWaylandClass *klass) +{ + MetaCursorSpriteClass *cursor_sprite_class = META_CURSOR_SPRITE_CLASS (klass); + + cursor_sprite_class->realize_texture = + meta_cursor_sprite_wayland_realize_texture; + cursor_sprite_class->is_animated = meta_cursor_sprite_wayland_is_animated; +} diff --git a/src/wayland/meta-cursor-sprite-wayland.h b/src/wayland/meta-cursor-sprite-wayland.h new file mode 100644 index 000000000..f0b9a0769 --- /dev/null +++ b/src/wayland/meta-cursor-sprite-wayland.h @@ -0,0 +1,32 @@ +/* + * Copyright 2013, 2018 Red Hat, Inc. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + * + */ + +#ifndef META_CURSOR_SPRITE_WAYLAND_H +#define META_CURSOR_SPRITE_WAYLAND_H + +#include + +#include "backends/meta-cursor.h" + +#define META_TYPE_CURSOR_SPRITE_WAYLAND meta_cursor_sprite_wayland_get_type () +G_DECLARE_FINAL_TYPE (MetaCursorSpriteWayland, meta_cursor_sprite_wayland, + META, CURSOR_SPRITE_WAYLAND, MetaCursorSprite) + +MetaCursorSpriteWayland * meta_cursor_sprite_wayland_new (void); + +#endif /* META_CURSOR_SPRITE_WAYLAND_H */ diff --git a/src/wayland/meta-wayland-cursor-surface.c b/src/wayland/meta-wayland-cursor-surface.c index 91a9fb95d..77931ab65 100644 --- a/src/wayland/meta-wayland-cursor-surface.c +++ b/src/wayland/meta-wayland-cursor-surface.c @@ -31,6 +31,7 @@ #include "backends/meta-backend-private.h" #include "backends/meta-logical-monitor.h" #include "core/boxes-private.h" +#include "wayland/meta-cursor-sprite-wayland.h" typedef struct _MetaWaylandCursorSurfacePrivate MetaWaylandCursorSurfacePrivate; @@ -38,7 +39,7 @@ struct _MetaWaylandCursorSurfacePrivate { int hot_x; int hot_y; - MetaCursorSprite *cursor_sprite; + MetaCursorSpriteWayland *cursor_sprite; MetaCursorRenderer *cursor_renderer; MetaWaylandBuffer *buffer; struct wl_list frame_callbacks; @@ -57,7 +58,7 @@ update_cursor_sprite_texture (MetaWaylandCursorSurface *cursor_surface) MetaWaylandSurface *surface = meta_wayland_surface_role_get_surface (META_WAYLAND_SURFACE_ROLE (cursor_surface)); MetaWaylandBuffer *buffer = meta_wayland_surface_get_buffer (surface); - MetaCursorSprite *cursor_sprite = priv->cursor_sprite; + MetaCursorSprite *cursor_sprite = META_CURSOR_SPRITE (priv->cursor_sprite); g_return_if_fail (!buffer || buffer->texture); @@ -267,7 +268,7 @@ meta_wayland_cursor_surface_init (MetaWaylandCursorSurface *role) MetaWaylandCursorSurfacePrivate *priv = meta_wayland_cursor_surface_get_instance_private (role); - priv->cursor_sprite = meta_cursor_sprite_new (); + priv->cursor_sprite = meta_cursor_sprite_wayland_new (); g_signal_connect_object (priv->cursor_sprite, "prepare-at", G_CALLBACK (cursor_sprite_prepare_at), @@ -299,7 +300,7 @@ meta_wayland_cursor_surface_get_sprite (MetaWaylandCursorSurface *cursor_surface MetaWaylandCursorSurfacePrivate *priv = meta_wayland_cursor_surface_get_instance_private (cursor_surface); - return priv->cursor_sprite; + return META_CURSOR_SPRITE (priv->cursor_sprite); } void @@ -342,7 +343,7 @@ on_cursor_painted (MetaCursorRenderer *renderer, meta_wayland_cursor_surface_get_instance_private (cursor_surface); guint32 time = (guint32) (g_get_monotonic_time () / 1000); - if (displayed_sprite != priv->cursor_sprite) + if (displayed_sprite != META_CURSOR_SPRITE (priv->cursor_sprite)) return; while (!wl_list_empty (&priv->frame_callbacks))