wayland: Make additional data in MetaWaylandSurfaceRoleCursor private

This will help subclassing it.
This commit is contained in:
Carlos Garnacho 2016-05-12 15:53:07 +02:00
parent 72ee6b8b65
commit 8e8cdf1873

View File

@ -28,10 +28,10 @@
#include "meta-xwayland.h" #include "meta-xwayland.h"
#include "screen-private.h" #include "screen-private.h"
struct _MetaWaylandSurfaceRoleCursor typedef struct _MetaWaylandSurfaceRoleCursorPrivate MetaWaylandSurfaceRoleCursorPrivate;
{
MetaWaylandSurfaceRole parent;
struct _MetaWaylandSurfaceRoleCursorPrivate
{
int hot_x; int hot_x;
int hot_y; int hot_y;
MetaCursorSprite *cursor_sprite; MetaCursorSprite *cursor_sprite;
@ -39,41 +39,42 @@ struct _MetaWaylandSurfaceRoleCursor
MetaWaylandBuffer *buffer; MetaWaylandBuffer *buffer;
}; };
G_DEFINE_TYPE (MetaWaylandSurfaceRoleCursor, G_DEFINE_TYPE_WITH_PRIVATE (MetaWaylandSurfaceRoleCursor,
meta_wayland_surface_role_cursor, meta_wayland_surface_role_cursor,
META_TYPE_WAYLAND_SURFACE_ROLE) META_TYPE_WAYLAND_SURFACE_ROLE)
static void static void
update_cursor_sprite_texture (MetaWaylandSurfaceRoleCursor *cursor_role) update_cursor_sprite_texture (MetaWaylandSurfaceRoleCursor *cursor_role)
{ {
MetaWaylandSurfaceRoleCursorPrivate *priv = meta_wayland_surface_role_cursor_get_instance_private (cursor_role);
MetaWaylandSurface *surface = meta_wayland_surface_role_get_surface (META_WAYLAND_SURFACE_ROLE (cursor_role)); MetaWaylandSurface *surface = meta_wayland_surface_role_get_surface (META_WAYLAND_SURFACE_ROLE (cursor_role));
MetaWaylandBuffer *buffer = meta_wayland_surface_get_buffer (surface); MetaWaylandBuffer *buffer = meta_wayland_surface_get_buffer (surface);
MetaCursorSprite *cursor_sprite = cursor_role->cursor_sprite; MetaCursorSprite *cursor_sprite = priv->cursor_sprite;
g_return_if_fail (!buffer || buffer->texture); g_return_if_fail (!buffer || buffer->texture);
if (!cursor_role->cursor_renderer || !cursor_sprite) if (!priv->cursor_renderer || !cursor_sprite)
return; return;
if (buffer) if (buffer)
{ {
meta_cursor_sprite_set_texture (cursor_sprite, meta_cursor_sprite_set_texture (cursor_sprite,
buffer->texture, buffer->texture,
cursor_role->hot_x * surface->scale, priv->hot_x * surface->scale,
cursor_role->hot_y * surface->scale); priv->hot_y * surface->scale);
if (cursor_role->buffer) if (priv->buffer)
{ {
struct wl_resource *buffer_resource; struct wl_resource *buffer_resource;
g_assert (cursor_role->buffer == buffer); g_assert (priv->buffer == buffer);
buffer_resource = buffer->resource; buffer_resource = buffer->resource;
meta_cursor_renderer_realize_cursor_from_wl_buffer (cursor_role->cursor_renderer, meta_cursor_renderer_realize_cursor_from_wl_buffer (priv->cursor_renderer,
cursor_sprite, cursor_sprite,
buffer_resource); buffer_resource);
meta_wayland_surface_unref_buffer_use_count (surface); meta_wayland_surface_unref_buffer_use_count (surface);
g_clear_object (&cursor_role->buffer); g_clear_object (&priv->buffer);
} }
} }
else else
@ -81,7 +82,7 @@ update_cursor_sprite_texture (MetaWaylandSurfaceRoleCursor *cursor_role)
meta_cursor_sprite_set_texture (cursor_sprite, NULL, 0, 0); meta_cursor_sprite_set_texture (cursor_sprite, NULL, 0, 0);
} }
meta_cursor_renderer_force_update (cursor_role->cursor_renderer); meta_cursor_renderer_force_update (priv->cursor_renderer);
} }
static void static void
@ -111,13 +112,15 @@ cursor_surface_role_assigned (MetaWaylandSurfaceRole *surface_role)
{ {
MetaWaylandSurfaceRoleCursor *cursor_role = MetaWaylandSurfaceRoleCursor *cursor_role =
META_WAYLAND_SURFACE_ROLE_CURSOR (surface_role); META_WAYLAND_SURFACE_ROLE_CURSOR (surface_role);
MetaWaylandSurfaceRoleCursorPrivate *priv =
meta_wayland_surface_role_cursor_get_instance_private (cursor_role);
MetaWaylandSurface *surface = MetaWaylandSurface *surface =
meta_wayland_surface_role_get_surface (surface_role); meta_wayland_surface_role_get_surface (surface_role);
MetaWaylandBuffer *buffer = meta_wayland_surface_get_buffer (surface); MetaWaylandBuffer *buffer = meta_wayland_surface_get_buffer (surface);
if (buffer) if (buffer)
{ {
g_set_object (&cursor_role->buffer, buffer); g_set_object (&priv->buffer, buffer);
meta_wayland_surface_ref_buffer_use_count (surface); meta_wayland_surface_ref_buffer_use_count (surface);
} }
@ -130,13 +133,15 @@ cursor_surface_role_pre_commit (MetaWaylandSurfaceRole *surface_role,
{ {
MetaWaylandSurfaceRoleCursor *cursor_role = MetaWaylandSurfaceRoleCursor *cursor_role =
META_WAYLAND_SURFACE_ROLE_CURSOR (surface_role); META_WAYLAND_SURFACE_ROLE_CURSOR (surface_role);
MetaWaylandSurfaceRoleCursorPrivate *priv =
meta_wayland_surface_role_cursor_get_instance_private (cursor_role);
MetaWaylandSurface *surface = MetaWaylandSurface *surface =
meta_wayland_surface_role_get_surface (surface_role); meta_wayland_surface_role_get_surface (surface_role);
if (pending->newly_attached && cursor_role->buffer) if (pending->newly_attached && priv->buffer)
{ {
meta_wayland_surface_unref_buffer_use_count (surface); meta_wayland_surface_unref_buffer_use_count (surface);
g_clear_object (&cursor_role->buffer); g_clear_object (&priv->buffer);
} }
} }
@ -146,14 +151,16 @@ cursor_surface_role_commit (MetaWaylandSurfaceRole *surface_role,
{ {
MetaWaylandSurfaceRoleCursor *cursor_role = MetaWaylandSurfaceRoleCursor *cursor_role =
META_WAYLAND_SURFACE_ROLE_CURSOR (surface_role); META_WAYLAND_SURFACE_ROLE_CURSOR (surface_role);
MetaWaylandSurfaceRoleCursorPrivate *priv =
meta_wayland_surface_role_cursor_get_instance_private (cursor_role);
MetaWaylandSurface *surface = MetaWaylandSurface *surface =
meta_wayland_surface_role_get_surface (surface_role); meta_wayland_surface_role_get_surface (surface_role);
MetaWaylandBuffer *buffer = meta_wayland_surface_get_buffer (surface); MetaWaylandBuffer *buffer = meta_wayland_surface_get_buffer (surface);
if (pending->newly_attached) if (pending->newly_attached)
{ {
g_set_object (&cursor_role->buffer, buffer); g_set_object (&priv->buffer, buffer);
if (cursor_role->buffer) if (priv->buffer)
meta_wayland_surface_ref_buffer_use_count (surface); meta_wayland_surface_ref_buffer_use_count (surface);
} }
@ -171,10 +178,12 @@ cursor_surface_role_is_on_output (MetaWaylandSurfaceRole *role,
meta_wayland_surface_role_get_surface (role); meta_wayland_surface_role_get_surface (role);
MetaWaylandSurfaceRoleCursor *cursor_role = MetaWaylandSurfaceRoleCursor *cursor_role =
META_WAYLAND_SURFACE_ROLE_CURSOR (surface->role); META_WAYLAND_SURFACE_ROLE_CURSOR (surface->role);
MetaWaylandSurfaceRoleCursorPrivate *priv =
meta_wayland_surface_role_cursor_get_instance_private (cursor_role);
MetaRectangle rect; MetaRectangle rect;
rect = meta_cursor_renderer_calculate_rect (cursor_role->cursor_renderer, rect = meta_cursor_renderer_calculate_rect (priv->cursor_renderer,
cursor_role->cursor_sprite); priv->cursor_sprite);
return meta_rectangle_overlap (&rect, &monitor->rect); return meta_rectangle_overlap (&rect, &monitor->rect);
} }
@ -183,19 +192,21 @@ cursor_surface_role_dispose (GObject *object)
{ {
MetaWaylandSurfaceRoleCursor *cursor_role = MetaWaylandSurfaceRoleCursor *cursor_role =
META_WAYLAND_SURFACE_ROLE_CURSOR (object); META_WAYLAND_SURFACE_ROLE_CURSOR (object);
MetaWaylandSurfaceRoleCursorPrivate *priv =
meta_wayland_surface_role_cursor_get_instance_private (cursor_role);
MetaWaylandSurface *surface = MetaWaylandSurface *surface =
meta_wayland_surface_role_get_surface (META_WAYLAND_SURFACE_ROLE (object)); meta_wayland_surface_role_get_surface (META_WAYLAND_SURFACE_ROLE (object));
g_signal_handlers_disconnect_by_func (cursor_role->cursor_sprite, g_signal_handlers_disconnect_by_func (priv->cursor_sprite,
cursor_sprite_prepare_at, cursor_role); cursor_sprite_prepare_at, cursor_role);
g_clear_object (&cursor_role->cursor_renderer); g_clear_object (&priv->cursor_renderer);
g_clear_object (&cursor_role->cursor_sprite); g_clear_object (&priv->cursor_sprite);
if (cursor_role->buffer) if (priv->buffer)
{ {
meta_wayland_surface_unref_buffer_use_count (surface); meta_wayland_surface_unref_buffer_use_count (surface);
g_clear_object (&cursor_role->buffer); g_clear_object (&priv->buffer);
} }
G_OBJECT_CLASS (meta_wayland_surface_role_cursor_parent_class)->dispose (object); G_OBJECT_CLASS (meta_wayland_surface_role_cursor_parent_class)->dispose (object);
@ -204,8 +215,11 @@ cursor_surface_role_dispose (GObject *object)
static void static void
meta_wayland_surface_role_cursor_init (MetaWaylandSurfaceRoleCursor *role) meta_wayland_surface_role_cursor_init (MetaWaylandSurfaceRoleCursor *role)
{ {
role->cursor_sprite = meta_cursor_sprite_new (); MetaWaylandSurfaceRoleCursorPrivate *priv =
g_signal_connect_object (role->cursor_sprite, meta_wayland_surface_role_cursor_get_instance_private (role);
priv->cursor_sprite = meta_cursor_sprite_new ();
g_signal_connect_object (priv->cursor_sprite,
"prepare-at", "prepare-at",
G_CALLBACK (cursor_sprite_prepare_at), G_CALLBACK (cursor_sprite_prepare_at),
role, role,
@ -230,7 +244,10 @@ meta_wayland_surface_role_cursor_class_init (MetaWaylandSurfaceRoleCursorClass *
MetaCursorSprite * MetaCursorSprite *
meta_wayland_surface_role_cursor_get_sprite (MetaWaylandSurfaceRoleCursor *cursor_role) meta_wayland_surface_role_cursor_get_sprite (MetaWaylandSurfaceRoleCursor *cursor_role)
{ {
return cursor_role->cursor_sprite; MetaWaylandSurfaceRoleCursorPrivate *priv =
meta_wayland_surface_role_cursor_get_instance_private (cursor_role);
return priv->cursor_sprite;
} }
void void
@ -238,12 +255,15 @@ meta_wayland_surface_role_cursor_set_hotspot (MetaWaylandSurfaceRoleCursor *curs
gint hotspot_x, gint hotspot_x,
gint hotspot_y) gint hotspot_y)
{ {
if (cursor_role->hot_x == hotspot_x && MetaWaylandSurfaceRoleCursorPrivate *priv =
cursor_role->hot_y == hotspot_y) meta_wayland_surface_role_cursor_get_instance_private (cursor_role);
if (priv->hot_x == hotspot_x &&
priv->hot_y == hotspot_y)
return; return;
cursor_role->hot_x = hotspot_x; priv->hot_x = hotspot_x;
cursor_role->hot_y = hotspot_y; priv->hot_y = hotspot_y;
update_cursor_sprite_texture (cursor_role); update_cursor_sprite_texture (cursor_role);
} }
@ -252,30 +272,39 @@ meta_wayland_surface_role_cursor_get_hotspot (MetaWaylandSurfaceRoleCursor *curs
gint *hotspot_x, gint *hotspot_x,
gint *hotspot_y) gint *hotspot_y)
{ {
MetaWaylandSurfaceRoleCursorPrivate *priv =
meta_wayland_surface_role_cursor_get_instance_private (cursor_role);
if (hotspot_x) if (hotspot_x)
*hotspot_x = cursor_role->hot_x; *hotspot_x = priv->hot_x;
if (hotspot_y) if (hotspot_y)
*hotspot_y = cursor_role->hot_y; *hotspot_y = priv->hot_y;
} }
void void
meta_wayland_surface_role_cursor_set_renderer (MetaWaylandSurfaceRoleCursor *cursor_role, meta_wayland_surface_role_cursor_set_renderer (MetaWaylandSurfaceRoleCursor *cursor_role,
MetaCursorRenderer *renderer) MetaCursorRenderer *renderer)
{ {
if (cursor_role->cursor_renderer == renderer) MetaWaylandSurfaceRoleCursorPrivate *priv =
meta_wayland_surface_role_cursor_get_instance_private (cursor_role);
if (priv->cursor_renderer == renderer)
return; return;
if (renderer) if (renderer)
g_object_ref (renderer); g_object_ref (renderer);
if (cursor_role->cursor_renderer) if (priv->cursor_renderer)
g_object_unref (cursor_role->cursor_renderer); g_object_unref (priv->cursor_renderer);
cursor_role->cursor_renderer = renderer; priv->cursor_renderer = renderer;
update_cursor_sprite_texture (cursor_role); update_cursor_sprite_texture (cursor_role);
} }
MetaCursorRenderer * MetaCursorRenderer *
meta_wayland_surface_role_cursor_get_renderer (MetaWaylandSurfaceRoleCursor *cursor_role) meta_wayland_surface_role_cursor_get_renderer (MetaWaylandSurfaceRoleCursor *cursor_role)
{ {
return cursor_role->cursor_renderer; MetaWaylandSurfaceRoleCursorPrivate *priv =
meta_wayland_surface_role_cursor_get_instance_private (cursor_role);
return priv->cursor_renderer;
} }