cursor-renderer: Centralize hw cursor realization paths

Use a common entry point into the cursor renderer implementations HW
cursor realization paths for all cursor sprite types. This is in
preparation for realizing at more strategic times.

https://gitlab.gnome.org/GNOME/mutter/issues/77
This commit is contained in:
Jonas Ådahl 2018-05-02 14:34:02 +02:00
parent 0f519ffb05
commit 9dcf9782b6
5 changed files with 43 additions and 50 deletions

View File

@ -284,25 +284,12 @@ 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,
MetaCursorSpriteWayland *sprite_wayland)
{
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, sprite_wayland);
}
#endif
void
meta_cursor_renderer_realize_cursor_from_xcursor (MetaCursorRenderer *renderer,
MetaCursorSpriteXcursor *sprite_xcursor)
meta_cursor_renderer_realize_cursor_sprite (MetaCursorRenderer *renderer,
MetaCursorSprite *cursor_sprite)
{
MetaCursorRendererClass *renderer_class = META_CURSOR_RENDERER_GET_CLASS (renderer);
if (renderer_class->realize_cursor_from_xcursor)
renderer_class->realize_cursor_from_xcursor (renderer, sprite_xcursor);
if (renderer_class->realize_cursor_sprite)
renderer_class->realize_cursor_sprite (renderer, cursor_sprite);
}

View File

@ -29,11 +29,6 @@
#include <meta/screen.h>
#include "meta-cursor.h"
#include "backends/meta-cursor-sprite-xcursor.h"
#ifdef HAVE_WAYLAND
#include "wayland/meta-cursor-sprite-wayland.h"
#endif
#define META_TYPE_CURSOR_RENDERER (meta_cursor_renderer_get_type ())
G_DECLARE_DERIVABLE_TYPE (MetaCursorRenderer, meta_cursor_renderer,
@ -45,12 +40,8 @@ struct _MetaCursorRendererClass
gboolean (* update_cursor) (MetaCursorRenderer *renderer,
MetaCursorSprite *cursor_sprite);
#ifdef HAVE_WAYLAND
void (* realize_cursor_from_wl_buffer) (MetaCursorRenderer *renderer,
MetaCursorSpriteWayland *sprite_wayland);
#endif
void (* realize_cursor_from_xcursor) (MetaCursorRenderer *renderer,
MetaCursorSpriteXcursor *sprite_xcursor);
void (* realize_cursor_sprite) (MetaCursorRenderer *renderer,
MetaCursorSprite *cursor_sprite);
};
MetaCursorRenderer * meta_cursor_renderer_new (void);
@ -69,13 +60,8 @@ 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,
MetaCursorSpriteWayland *sprite_wayland);
#endif
void meta_cursor_renderer_realize_cursor_from_xcursor (MetaCursorRenderer *renderer,
MetaCursorSpriteXcursor *sprite_xcursor);
void meta_cursor_renderer_realize_cursor_sprite (MetaCursorRenderer *renderer,
MetaCursorSprite *cursor_sprite);
void meta_cursor_renderer_emit_painted (MetaCursorRenderer *renderer,
MetaCursorSprite *cursor_sprite);

View File

@ -117,6 +117,7 @@ load_cursor_on_client (MetaCursor cursor, int scale)
static void
load_from_current_xcursor_image (MetaCursorSpriteXcursor *sprite_xcursor)
{
MetaCursorSprite *sprite = META_CURSOR_SPRITE (sprite_xcursor);
MetaBackend *backend = meta_get_backend ();
MetaCursorRenderer *renderer = meta_backend_get_cursor_renderer (backend);
XcursorImage *xc_image;
@ -127,7 +128,7 @@ load_from_current_xcursor_image (MetaCursorSpriteXcursor *sprite_xcursor)
CoglTexture2D *texture;
CoglError *error = NULL;
g_assert (!meta_cursor_sprite_get_cogl_texture (META_CURSOR_SPRITE (sprite_xcursor)));
g_assert (!meta_cursor_sprite_get_cogl_texture (sprite));
xc_image = meta_cursor_sprite_xcursor_get_current_image (sprite_xcursor);
width = (int) xc_image->width;
@ -155,13 +156,13 @@ load_from_current_xcursor_image (MetaCursorSpriteXcursor *sprite_xcursor)
cogl_error_free (error);
}
meta_cursor_sprite_set_texture (META_CURSOR_SPRITE (sprite_xcursor),
meta_cursor_sprite_set_texture (sprite,
COGL_TEXTURE (texture),
xc_image->xhot, xc_image->yhot);
g_clear_pointer (&texture, cogl_object_unref);
meta_cursor_renderer_realize_cursor_from_xcursor (renderer, sprite_xcursor);
meta_cursor_renderer_realize_cursor_sprite (renderer, sprite);
}
void

View File

@ -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"
@ -942,8 +943,8 @@ realize_cursor_sprite_from_wl_buffer_for_gpu (MetaCursorRenderer *renderer,
}
static void
meta_cursor_renderer_native_realize_cursor_from_wl_buffer (MetaCursorRenderer *renderer,
MetaCursorSpriteWayland *sprite_wayland)
realize_cursor_sprite_from_wl_buffer (MetaCursorRenderer *renderer,
MetaCursorSpriteWayland *sprite_wayland)
{
MetaCursorRendererNative *native = META_CURSOR_RENDERER_NATIVE (renderer);
MetaCursorRendererNativePrivate *priv =
@ -1002,8 +1003,8 @@ realize_cursor_sprite_from_xcursor_for_gpu (MetaCursorRenderer *renderer,
}
static void
meta_cursor_renderer_native_realize_cursor_from_xcursor (MetaCursorRenderer *renderer,
MetaCursorSpriteXcursor *sprite_xcursor)
realize_cursor_sprite_from_xcursor (MetaCursorRenderer *renderer,
MetaCursorSpriteXcursor *sprite_xcursor)
{
MetaCursorRendererNative *native = META_CURSOR_RENDERER_NATIVE (renderer);
MetaCursorRendererNativePrivate *priv =
@ -1025,6 +1026,28 @@ meta_cursor_renderer_native_realize_cursor_from_xcursor (MetaCursorRenderer
}
}
static void
meta_cursor_renderer_native_realize_cursor_sprite (MetaCursorRenderer *renderer,
MetaCursorSprite *cursor_sprite)
{
if (META_IS_CURSOR_SPRITE_XCURSOR (cursor_sprite))
{
MetaCursorSpriteXcursor *sprite_xcursor =
META_CURSOR_SPRITE_XCURSOR (cursor_sprite);
realize_cursor_sprite_from_xcursor (renderer, sprite_xcursor);
}
#ifdef HAVE_WAYLAND
else if (META_IS_CURSOR_SPRITE_WAYLAND (cursor_sprite))
{
MetaCursorSpriteWayland *sprite_wayland =
META_CURSOR_SPRITE_WAYLAND (cursor_sprite);
realize_cursor_sprite_from_wl_buffer (renderer, sprite_wayland);
}
#endif
}
static void
meta_cursor_renderer_native_class_init (MetaCursorRendererNativeClass *klass)
{
@ -1033,12 +1056,8 @@ 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;
renderer_class->realize_cursor_sprite =
meta_cursor_renderer_native_realize_cursor_sprite;
quark_cursor_sprite = g_quark_from_static_string ("-meta-cursor-native");
quark_cursor_renderer_native_gpu_data =

View File

@ -75,8 +75,8 @@ update_cursor_sprite_texture (MetaWaylandCursorSurface *cursor_surface)
if (priv->buffer)
{
g_assert (priv->buffer == buffer);
meta_cursor_renderer_realize_cursor_from_wl_buffer (priv->cursor_renderer,
priv->cursor_sprite);
meta_cursor_renderer_realize_cursor_sprite (priv->cursor_renderer,
cursor_sprite);
meta_wayland_surface_unref_buffer_use_count (surface);
g_clear_object (&priv->buffer);