wayland: Refactor surface actor into MetaWaylandActorSurface

All surface roles that do need a backing actor inherit from this
class, it makes sense to move actor management there. This also
means the MetaWaylandActorSurface is in charge of emitting
::geometry-changed on the MetaWaylandSurface.
This commit is contained in:
Carlos Garnacho 2018-04-06 13:27:52 +02:00
parent 8df2a1452c
commit 22485ba36f
5 changed files with 103 additions and 106 deletions

View File

@ -30,30 +30,58 @@
#include "wayland/meta-wayland-surface.h" #include "wayland/meta-wayland-surface.h"
#include "wayland/meta-window-wayland.h" #include "wayland/meta-window-wayland.h"
G_DEFINE_ABSTRACT_TYPE (MetaWaylandActorSurface, typedef struct _MetaWaylandActorSurfacePrivate MetaWaylandActorSurfacePrivate;
struct _MetaWaylandActorSurfacePrivate
{
MetaSurfaceActor *actor;
};
G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (MetaWaylandActorSurface,
meta_wayland_actor_surface, meta_wayland_actor_surface,
META_TYPE_WAYLAND_SURFACE_ROLE) META_TYPE_WAYLAND_SURFACE_ROLE)
static void
meta_wayland_actor_surface_constructed (GObject *object)
{
G_OBJECT_CLASS (meta_wayland_actor_surface_parent_class)->constructed (object);
meta_wayland_actor_surface_reset_actor (META_WAYLAND_ACTOR_SURFACE (object));
}
static void
meta_wayland_actor_surface_finalize (GObject *object)
{
MetaWaylandActorSurfacePrivate *priv =
meta_wayland_actor_surface_get_instance_private (META_WAYLAND_ACTOR_SURFACE (object));
MetaWaylandSurface *surface =
meta_wayland_surface_role_get_surface (META_WAYLAND_SURFACE_ROLE (object));
g_signal_handlers_disconnect_by_func (priv->actor,
meta_wayland_surface_notify_geometry_changed,
surface);
g_object_unref (priv->actor);
G_OBJECT_CLASS (meta_wayland_actor_surface_parent_class)->finalize (object);
}
static void static void
meta_wayland_actor_surface_assigned (MetaWaylandSurfaceRole *surface_role) meta_wayland_actor_surface_assigned (MetaWaylandSurfaceRole *surface_role)
{ {
MetaWaylandActorSurfacePrivate *priv =
meta_wayland_actor_surface_get_instance_private (META_WAYLAND_ACTOR_SURFACE (surface_role));
MetaWaylandSurface *surface = MetaWaylandSurface *surface =
meta_wayland_surface_role_get_surface (surface_role); meta_wayland_surface_role_get_surface (surface_role);
MetaSurfaceActorWayland *surface_actor =
META_SURFACE_ACTOR_WAYLAND (surface->surface_actor);
meta_surface_actor_wayland_add_frame_callbacks (surface_actor, meta_surface_actor_wayland_add_frame_callbacks (META_SURFACE_ACTOR_WAYLAND (priv->actor),
&surface->pending_frame_callback_list); &surface->pending_frame_callback_list);
wl_list_init (&surface->pending_frame_callback_list); wl_list_init (&surface->pending_frame_callback_list);
} }
static void static void
queue_surface_actor_frame_callbacks (MetaWaylandSurface *surface, queue_surface_actor_frame_callbacks (MetaSurfaceActorWayland *surface_actor,
MetaWaylandPendingState *pending) MetaWaylandPendingState *pending)
{ {
MetaSurfaceActorWayland *surface_actor =
META_SURFACE_ACTOR_WAYLAND (surface->surface_actor);
meta_surface_actor_wayland_add_frame_callbacks (surface_actor, meta_surface_actor_wayland_add_frame_callbacks (surface_actor,
&pending->frame_callback_list); &pending->frame_callback_list);
wl_list_init (&pending->frame_callback_list); wl_list_init (&pending->frame_callback_list);
@ -90,6 +118,8 @@ meta_wayland_actor_surface_calculate_scale (MetaWaylandActorSurface *actor_surfa
static void static void
meta_wayland_actor_surface_real_sync_actor_state (MetaWaylandActorSurface *actor_surface) meta_wayland_actor_surface_real_sync_actor_state (MetaWaylandActorSurface *actor_surface)
{ {
MetaWaylandActorSurfacePrivate *priv =
meta_wayland_actor_surface_get_instance_private (actor_surface);
MetaWaylandSurfaceRole *surface_role = MetaWaylandSurfaceRole *surface_role =
META_WAYLAND_SURFACE_ROLE (actor_surface); META_WAYLAND_SURFACE_ROLE (actor_surface);
MetaWaylandSurface *surface = MetaWaylandSurface *surface =
@ -99,7 +129,7 @@ meta_wayland_actor_surface_real_sync_actor_state (MetaWaylandActorSurface *actor
double actor_scale; double actor_scale;
GList *l; GList *l;
surface_actor = surface->surface_actor; surface_actor = priv->actor;
stex = meta_surface_actor_get_texture (surface_actor); stex = meta_surface_actor_get_texture (surface_actor);
actor_scale = meta_wayland_actor_surface_calculate_scale (actor_surface); actor_scale = meta_wayland_actor_surface_calculate_scale (actor_surface);
@ -161,13 +191,16 @@ static void
meta_wayland_actor_surface_commit (MetaWaylandSurfaceRole *surface_role, meta_wayland_actor_surface_commit (MetaWaylandSurfaceRole *surface_role,
MetaWaylandPendingState *pending) MetaWaylandPendingState *pending)
{ {
MetaWaylandActorSurfacePrivate *priv =
meta_wayland_actor_surface_get_instance_private (META_WAYLAND_ACTOR_SURFACE (surface_role));
MetaWaylandActorSurface *actor_surface = MetaWaylandActorSurface *actor_surface =
META_WAYLAND_ACTOR_SURFACE (surface_role); META_WAYLAND_ACTOR_SURFACE (surface_role);
MetaWaylandSurface *surface = MetaWaylandSurface *surface =
meta_wayland_surface_role_get_surface (surface_role); meta_wayland_surface_role_get_surface (surface_role);
MetaWaylandSurface *toplevel_surface; MetaWaylandSurface *toplevel_surface;
queue_surface_actor_frame_callbacks (surface, pending); queue_surface_actor_frame_callbacks (META_SURFACE_ACTOR_WAYLAND (priv->actor),
pending);
toplevel_surface = meta_wayland_surface_get_toplevel (surface); toplevel_surface = meta_wayland_surface_get_toplevel (surface);
if (!toplevel_surface || !toplevel_surface->window) if (!toplevel_surface || !toplevel_surface->window)
@ -180,9 +213,9 @@ static gboolean
meta_wayland_actor_surface_is_on_logical_monitor (MetaWaylandSurfaceRole *surface_role, meta_wayland_actor_surface_is_on_logical_monitor (MetaWaylandSurfaceRole *surface_role,
MetaLogicalMonitor *logical_monitor) MetaLogicalMonitor *logical_monitor)
{ {
MetaWaylandSurface *surface = MetaWaylandActorSurfacePrivate *priv =
meta_wayland_surface_role_get_surface (surface_role); meta_wayland_actor_surface_get_instance_private (META_WAYLAND_ACTOR_SURFACE (surface_role));
ClutterActor *actor = CLUTTER_ACTOR (surface->surface_actor); ClutterActor *actor = CLUTTER_ACTOR (priv->actor);
float x, y, width, height; float x, y, width, height;
cairo_rectangle_int_t actor_rect; cairo_rectangle_int_t actor_rect;
cairo_region_t *region; cairo_region_t *region;
@ -226,6 +259,10 @@ meta_wayland_actor_surface_class_init (MetaWaylandActorSurfaceClass *klass)
{ {
MetaWaylandSurfaceRoleClass *surface_role_class = MetaWaylandSurfaceRoleClass *surface_role_class =
META_WAYLAND_SURFACE_ROLE_CLASS (klass); META_WAYLAND_SURFACE_ROLE_CLASS (klass);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->constructed = meta_wayland_actor_surface_constructed;
object_class->finalize = meta_wayland_actor_surface_finalize;
surface_role_class->assigned = meta_wayland_actor_surface_assigned; surface_role_class->assigned = meta_wayland_actor_surface_assigned;
surface_role_class->commit = meta_wayland_actor_surface_commit; surface_role_class->commit = meta_wayland_actor_surface_commit;
@ -234,3 +271,41 @@ meta_wayland_actor_surface_class_init (MetaWaylandActorSurfaceClass *klass)
klass->sync_actor_state = meta_wayland_actor_surface_real_sync_actor_state; klass->sync_actor_state = meta_wayland_actor_surface_real_sync_actor_state;
} }
MetaSurfaceActor *
meta_wayland_actor_surface_get_actor (MetaWaylandActorSurface *actor_surface)
{
MetaWaylandActorSurfacePrivate *priv =
meta_wayland_actor_surface_get_instance_private (actor_surface);
return priv->actor;
}
void
meta_wayland_actor_surface_reset_actor (MetaWaylandActorSurface *actor_surface)
{
MetaWaylandActorSurfacePrivate *priv =
meta_wayland_actor_surface_get_instance_private (actor_surface);
MetaWaylandSurface *surface =
meta_wayland_surface_role_get_surface (META_WAYLAND_SURFACE_ROLE (actor_surface));
if (priv->actor)
{
g_signal_handlers_disconnect_by_func (priv->actor,
meta_wayland_surface_notify_geometry_changed,
surface);
g_object_unref (priv->actor);
}
priv->actor = g_object_ref_sink (meta_surface_actor_wayland_new (surface));
g_signal_connect_swapped (priv->actor, "notify::allocation",
G_CALLBACK (meta_wayland_surface_notify_geometry_changed),
surface);
g_signal_connect_swapped (priv->actor, "notify::position",
G_CALLBACK (meta_wayland_surface_notify_geometry_changed),
surface);
g_signal_connect_swapped (priv->actor, "notify::mapped",
G_CALLBACK (meta_wayland_surface_notify_geometry_changed),
surface);
}

View File

@ -40,4 +40,7 @@ void meta_wayland_actor_surface_sync_actor_state (MetaWaylandActorSurface *actor
double meta_wayland_actor_surface_calculate_scale (MetaWaylandActorSurface *actor_surface); double meta_wayland_actor_surface_calculate_scale (MetaWaylandActorSurface *actor_surface);
MetaSurfaceActor * meta_wayland_actor_surface_get_actor (MetaWaylandActorSurface *actor_surface);
void meta_wayland_actor_surface_reset_actor (MetaWaylandActorSurface *actor_surface);
#endif /* META_WAYLAND_ACTOR_SURFACE_H */ #endif /* META_WAYLAND_ACTOR_SURFACE_H */

View File

@ -129,18 +129,6 @@ meta_wayland_surface_role_is_on_logical_monitor (MetaWaylandSurfaceRole *surface
static MetaWaylandSurface * static MetaWaylandSurface *
meta_wayland_surface_role_get_toplevel (MetaWaylandSurfaceRole *surface_role); meta_wayland_surface_role_get_toplevel (MetaWaylandSurfaceRole *surface_role);
static void
surface_actor_mapped_notify (MetaSurfaceActorWayland *surface_actor,
GParamSpec *pspec,
MetaWaylandSurface *surface);
static void
surface_actor_allocation_notify (MetaSurfaceActorWayland *surface_actor,
GParamSpec *pspec,
MetaWaylandSurface *surface);
static void
surface_actor_position_notify (MetaSurfaceActorWayland *surface_actor,
GParamSpec *pspec,
MetaWaylandSurface *surface);
static void static void
window_position_changed (MetaWindow *window, window_position_changed (MetaWindow *window,
MetaWaylandSurface *surface); MetaWaylandSurface *surface);
@ -313,7 +301,7 @@ surface_process_damage (MetaWaylandSurface *surface,
cairo_rectangle_int_t rect; cairo_rectangle_int_t rect;
cairo_region_get_rectangle (scaled_region, i, &rect); cairo_region_get_rectangle (scaled_region, i, &rect);
meta_surface_actor_process_damage (surface->surface_actor, meta_surface_actor_process_damage (meta_wayland_surface_get_actor (surface),
rect.x, rect.y, rect.x, rect.y,
rect.width, rect.height); rect.width, rect.height);
} }
@ -660,7 +648,7 @@ meta_wayland_surface_apply_pending_state (MetaWaylandSurface *surface,
CoglSnippet *snippet; CoglSnippet *snippet;
gboolean is_y_inverted; gboolean is_y_inverted;
stex = meta_surface_actor_get_texture (surface->surface_actor); stex = meta_surface_actor_get_texture (meta_wayland_surface_get_actor (surface));
texture = meta_wayland_buffer_get_texture (pending->buffer); texture = meta_wayland_buffer_get_texture (pending->buffer);
snippet = meta_wayland_buffer_create_snippet (pending->buffer); snippet = meta_wayland_buffer_create_snippet (pending->buffer);
is_y_inverted = meta_wayland_buffer_is_y_inverted (pending->buffer); is_y_inverted = meta_wayland_buffer_is_y_inverted (pending->buffer);
@ -1147,7 +1135,7 @@ meta_wayland_surface_set_window (MetaWaylandSurface *surface,
surface->window = window; surface->window = window;
clutter_actor_set_reactive (CLUTTER_ACTOR (surface->surface_actor), !!window); clutter_actor_set_reactive (CLUTTER_ACTOR (meta_wayland_surface_get_actor (surface)), !!window);
sync_drag_dest_funcs (surface); sync_drag_dest_funcs (surface);
if (was_unmapped) if (was_unmapped)
@ -1175,16 +1163,6 @@ wl_surface_destructor (struct wl_resource *resource)
g_signal_emit (surface, surface_signals[SURFACE_DESTROY], 0); g_signal_emit (surface, surface_signals[SURFACE_DESTROY], 0);
g_signal_handlers_disconnect_by_func (surface->surface_actor,
surface_actor_mapped_notify,
surface);
g_signal_handlers_disconnect_by_func (surface->surface_actor,
surface_actor_allocation_notify,
surface);
g_signal_handlers_disconnect_by_func (surface->surface_actor,
surface_actor_position_notify,
surface);
g_clear_object (&surface->role); g_clear_object (&surface->role);
/* If we still have a window at the time of destruction, that means that /* If we still have a window at the time of destruction, that means that
@ -1210,8 +1188,6 @@ wl_surface_destructor (struct wl_resource *resource)
if (surface->input_region) if (surface->input_region)
cairo_region_destroy (surface->input_region); cairo_region_destroy (surface->input_region);
g_object_unref (surface->surface_actor);
meta_wayland_compositor_destroy_frame_callbacks (compositor, surface); meta_wayland_compositor_destroy_frame_callbacks (compositor, surface);
g_hash_table_foreach (surface->outputs_to_destroy_notify_id, surface_output_disconnect_signal, surface); g_hash_table_foreach (surface->outputs_to_destroy_notify_id, surface_output_disconnect_signal, surface);
@ -1233,30 +1209,6 @@ wl_surface_destructor (struct wl_resource *resource)
meta_wayland_compositor_repick (compositor); meta_wayland_compositor_repick (compositor);
} }
static void
surface_actor_mapped_notify (MetaSurfaceActorWayland *surface_actor,
GParamSpec *pspec,
MetaWaylandSurface *surface)
{
g_signal_emit (surface, surface_signals[SURFACE_GEOMETRY_CHANGED], 0);
}
static void
surface_actor_allocation_notify (MetaSurfaceActorWayland *surface_actor,
GParamSpec *pspec,
MetaWaylandSurface *surface)
{
g_signal_emit (surface, surface_signals[SURFACE_GEOMETRY_CHANGED], 0);
}
static void
surface_actor_position_notify (MetaSurfaceActorWayland *surface_actor,
GParamSpec *pspec,
MetaWaylandSurface *surface)
{
g_signal_emit (surface, surface_signals[SURFACE_GEOMETRY_CHANGED], 0);
}
static void static void
window_position_changed (MetaWindow *window, window_position_changed (MetaWindow *window,
MetaWaylandSurface *surface) MetaWaylandSurface *surface)
@ -1271,21 +1223,6 @@ window_actor_effects_completed (MetaWindowActor *window_actor,
meta_wayland_surface_update_outputs_recursively (surface); meta_wayland_surface_update_outputs_recursively (surface);
} }
void
meta_wayland_surface_create_surface_actor (MetaWaylandSurface *surface)
{
MetaSurfaceActor *surface_actor;
surface_actor = meta_surface_actor_wayland_new (surface);
surface->surface_actor = g_object_ref_sink (surface_actor);
}
void
meta_wayland_surface_clear_surface_actor (MetaWaylandSurface *surface)
{
g_clear_object (&surface->surface_actor);
}
MetaWaylandSurface * MetaWaylandSurface *
meta_wayland_surface_create (MetaWaylandCompositor *compositor, meta_wayland_surface_create (MetaWaylandCompositor *compositor,
struct wl_client *client, struct wl_client *client,
@ -1300,23 +1237,8 @@ meta_wayland_surface_create (MetaWaylandCompositor *compositor,
surface->resource = wl_resource_create (client, &wl_surface_interface, wl_resource_get_version (compositor_resource), id); surface->resource = wl_resource_create (client, &wl_surface_interface, wl_resource_get_version (compositor_resource), id);
wl_resource_set_implementation (surface->resource, &meta_wayland_wl_surface_interface, surface, wl_surface_destructor); wl_resource_set_implementation (surface->resource, &meta_wayland_wl_surface_interface, surface, wl_surface_destructor);
surface->surface_actor = g_object_ref_sink (meta_surface_actor_wayland_new (surface));
wl_list_init (&surface->pending_frame_callback_list); wl_list_init (&surface->pending_frame_callback_list);
g_signal_connect_object (surface->surface_actor,
"notify::allocation",
G_CALLBACK (surface_actor_allocation_notify),
surface, 0);
g_signal_connect_object (surface->surface_actor,
"notify::position",
G_CALLBACK (surface_actor_position_notify),
surface, 0);
g_signal_connect_object (surface->surface_actor,
"notify::mapped",
G_CALLBACK (surface_actor_mapped_notify),
surface, 0);
sync_drag_dest_funcs (surface); sync_drag_dest_funcs (surface);
surface->outputs_to_destroy_notify_id = g_hash_table_new (NULL, NULL); surface->outputs_to_destroy_notify_id = g_hash_table_new (NULL, NULL);
@ -1506,7 +1428,7 @@ meta_wayland_surface_get_relative_coordinates (MetaWaylandSurface *surface,
else else
{ {
ClutterActor *actor = ClutterActor *actor =
CLUTTER_ACTOR (meta_surface_actor_get_texture (surface->surface_actor)); CLUTTER_ACTOR (meta_surface_actor_get_texture (meta_wayland_surface_get_actor (surface)));
clutter_actor_transform_stage_point (actor, abs_x, abs_y, sx, sy); clutter_actor_transform_stage_point (actor, abs_x, abs_y, sx, sy);
*sx /= surface->scale; *sx /= surface->scale;
@ -1522,7 +1444,7 @@ meta_wayland_surface_get_absolute_coordinates (MetaWaylandSurface *surface,
float *y) float *y)
{ {
ClutterActor *actor = ClutterActor *actor =
CLUTTER_ACTOR (meta_surface_actor_get_texture (surface->surface_actor)); CLUTTER_ACTOR (meta_surface_actor_get_texture (meta_wayland_surface_get_actor (surface)));
ClutterVertex sv = { ClutterVertex sv = {
.x = sx * surface->scale, .x = sx * surface->scale,
.y = sy * surface->scale, .y = sy * surface->scale,
@ -1807,7 +1729,10 @@ meta_wayland_surface_is_shortcuts_inhibited (MetaWaylandSurface *surface,
MetaSurfaceActor * MetaSurfaceActor *
meta_wayland_surface_get_actor (MetaWaylandSurface *surface) meta_wayland_surface_get_actor (MetaWaylandSurface *surface)
{ {
return surface->surface_actor; if (!surface->role || !META_IS_WAYLAND_ACTOR_SURFACE (surface->role))
return NULL;
return meta_wayland_actor_surface_get_actor (META_WAYLAND_ACTOR_SURFACE (surface->role));
} }
void void

View File

@ -137,7 +137,6 @@ struct _MetaWaylandSurface
/* Generic stuff */ /* Generic stuff */
struct wl_resource *resource; struct wl_resource *resource;
MetaWaylandCompositor *compositor; MetaWaylandCompositor *compositor;
MetaSurfaceActor *surface_actor;
MetaWaylandSurfaceRole *role; MetaWaylandSurfaceRole *role;
MetaWindow *window; MetaWindow *window;
cairo_region_t *input_region; cairo_region_t *input_region;
@ -231,10 +230,6 @@ void meta_wayland_surface_unref_buffer_use_count (MetaWaylandSurf
void meta_wayland_surface_set_window (MetaWaylandSurface *surface, void meta_wayland_surface_set_window (MetaWaylandSurface *surface,
MetaWindow *window); MetaWindow *window);
void meta_wayland_surface_create_surface_actor (MetaWaylandSurface *surface);
void meta_wayland_surface_clear_surface_actor (MetaWaylandSurface *surface);
void meta_wayland_surface_configure_notify (MetaWaylandSurface *surface, void meta_wayland_surface_configure_notify (MetaWaylandSurface *surface,
int new_x, int new_x,
int new_y, int new_y,

View File

@ -707,9 +707,8 @@ meta_wayland_xdg_toplevel_reset (MetaWaylandXdgSurface *xdg_surface)
surface = meta_wayland_surface_role_get_surface (surface_role); surface = meta_wayland_surface_role_get_surface (surface_role);
meta_wayland_surface_destroy_window (surface); meta_wayland_surface_destroy_window (surface);
meta_wayland_surface_clear_surface_actor (surface);
meta_wayland_surface_create_surface_actor (surface); meta_wayland_actor_surface_reset_actor (META_WAYLAND_ACTOR_SURFACE (surface_role));
window = meta_window_wayland_new (meta_get_display (), surface); window = meta_window_wayland_new (meta_get_display (), surface);
meta_wayland_shell_surface_set_window (shell_surface, window); meta_wayland_shell_surface_set_window (shell_surface, window);