From 22485ba36f9c6a41a6dd9344606640f0003503d1 Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Fri, 6 Apr 2018 13:27:52 +0200 Subject: [PATCH] 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. --- src/wayland/meta-wayland-actor-surface.c | 105 +++++++++++++++++++---- src/wayland/meta-wayland-actor-surface.h | 3 + src/wayland/meta-wayland-surface.c | 93 ++------------------ src/wayland/meta-wayland-surface.h | 5 -- src/wayland/meta-wayland-xdg-shell.c | 3 +- 5 files changed, 103 insertions(+), 106 deletions(-) diff --git a/src/wayland/meta-wayland-actor-surface.c b/src/wayland/meta-wayland-actor-surface.c index c10694a2a..43e88aac4 100644 --- a/src/wayland/meta-wayland-actor-surface.c +++ b/src/wayland/meta-wayland-actor-surface.c @@ -30,30 +30,58 @@ #include "wayland/meta-wayland-surface.h" #include "wayland/meta-window-wayland.h" -G_DEFINE_ABSTRACT_TYPE (MetaWaylandActorSurface, - meta_wayland_actor_surface, - META_TYPE_WAYLAND_SURFACE_ROLE) +typedef struct _MetaWaylandActorSurfacePrivate MetaWaylandActorSurfacePrivate; + +struct _MetaWaylandActorSurfacePrivate +{ + MetaSurfaceActor *actor; +}; + +G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (MetaWaylandActorSurface, + meta_wayland_actor_surface, + 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 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 = 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); wl_list_init (&surface->pending_frame_callback_list); } static void -queue_surface_actor_frame_callbacks (MetaWaylandSurface *surface, +queue_surface_actor_frame_callbacks (MetaSurfaceActorWayland *surface_actor, MetaWaylandPendingState *pending) { - MetaSurfaceActorWayland *surface_actor = - META_SURFACE_ACTOR_WAYLAND (surface->surface_actor); - meta_surface_actor_wayland_add_frame_callbacks (surface_actor, &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 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 = META_WAYLAND_SURFACE_ROLE (actor_surface); MetaWaylandSurface *surface = @@ -99,7 +129,7 @@ meta_wayland_actor_surface_real_sync_actor_state (MetaWaylandActorSurface *actor double actor_scale; GList *l; - surface_actor = surface->surface_actor; + surface_actor = priv->actor; stex = meta_surface_actor_get_texture (surface_actor); actor_scale = meta_wayland_actor_surface_calculate_scale (actor_surface); @@ -161,13 +191,16 @@ static void meta_wayland_actor_surface_commit (MetaWaylandSurfaceRole *surface_role, MetaWaylandPendingState *pending) { + MetaWaylandActorSurfacePrivate *priv = + meta_wayland_actor_surface_get_instance_private (META_WAYLAND_ACTOR_SURFACE (surface_role)); MetaWaylandActorSurface *actor_surface = META_WAYLAND_ACTOR_SURFACE (surface_role); MetaWaylandSurface *surface = meta_wayland_surface_role_get_surface (surface_role); 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); if (!toplevel_surface || !toplevel_surface->window) @@ -180,9 +213,9 @@ static gboolean meta_wayland_actor_surface_is_on_logical_monitor (MetaWaylandSurfaceRole *surface_role, MetaLogicalMonitor *logical_monitor) { - MetaWaylandSurface *surface = - meta_wayland_surface_role_get_surface (surface_role); - ClutterActor *actor = CLUTTER_ACTOR (surface->surface_actor); + MetaWaylandActorSurfacePrivate *priv = + meta_wayland_actor_surface_get_instance_private (META_WAYLAND_ACTOR_SURFACE (surface_role)); + ClutterActor *actor = CLUTTER_ACTOR (priv->actor); float x, y, width, height; cairo_rectangle_int_t actor_rect; cairo_region_t *region; @@ -226,6 +259,10 @@ meta_wayland_actor_surface_class_init (MetaWaylandActorSurfaceClass *klass) { MetaWaylandSurfaceRoleClass *surface_role_class = 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->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; } + +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); +} diff --git a/src/wayland/meta-wayland-actor-surface.h b/src/wayland/meta-wayland-actor-surface.h index a5cc24455..7c771dc70 100644 --- a/src/wayland/meta-wayland-actor-surface.h +++ b/src/wayland/meta-wayland-actor-surface.h @@ -40,4 +40,7 @@ void meta_wayland_actor_surface_sync_actor_state (MetaWaylandActorSurface *actor 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 */ diff --git a/src/wayland/meta-wayland-surface.c b/src/wayland/meta-wayland-surface.c index 604d47e96..2acebdb0b 100644 --- a/src/wayland/meta-wayland-surface.c +++ b/src/wayland/meta-wayland-surface.c @@ -129,18 +129,6 @@ meta_wayland_surface_role_is_on_logical_monitor (MetaWaylandSurfaceRole *surface static MetaWaylandSurface * 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 window_position_changed (MetaWindow *window, MetaWaylandSurface *surface); @@ -313,7 +301,7 @@ surface_process_damage (MetaWaylandSurface *surface, cairo_rectangle_int_t 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.width, rect.height); } @@ -660,7 +648,7 @@ meta_wayland_surface_apply_pending_state (MetaWaylandSurface *surface, CoglSnippet *snippet; 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); snippet = meta_wayland_buffer_create_snippet (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; - 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); 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_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); /* 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) cairo_region_destroy (surface->input_region); - g_object_unref (surface->surface_actor); - meta_wayland_compositor_destroy_frame_callbacks (compositor, 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); } -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 window_position_changed (MetaWindow *window, MetaWaylandSurface *surface) @@ -1271,21 +1223,6 @@ window_actor_effects_completed (MetaWindowActor *window_actor, 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 * meta_wayland_surface_create (MetaWaylandCompositor *compositor, 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); 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); - 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); 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 { 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); *sx /= surface->scale; @@ -1522,7 +1444,7 @@ meta_wayland_surface_get_absolute_coordinates (MetaWaylandSurface *surface, float *y) { 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 = { .x = sx * surface->scale, .y = sy * surface->scale, @@ -1807,7 +1729,10 @@ meta_wayland_surface_is_shortcuts_inhibited (MetaWaylandSurface *surface, MetaSurfaceActor * 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 diff --git a/src/wayland/meta-wayland-surface.h b/src/wayland/meta-wayland-surface.h index 92ce1050a..9921ee24e 100644 --- a/src/wayland/meta-wayland-surface.h +++ b/src/wayland/meta-wayland-surface.h @@ -137,7 +137,6 @@ struct _MetaWaylandSurface /* Generic stuff */ struct wl_resource *resource; MetaWaylandCompositor *compositor; - MetaSurfaceActor *surface_actor; MetaWaylandSurfaceRole *role; MetaWindow *window; 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, 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, int new_x, int new_y, diff --git a/src/wayland/meta-wayland-xdg-shell.c b/src/wayland/meta-wayland-xdg-shell.c index cffffa840..c750d3f66 100644 --- a/src/wayland/meta-wayland-xdg-shell.c +++ b/src/wayland/meta-wayland-xdg-shell.c @@ -707,9 +707,8 @@ meta_wayland_xdg_toplevel_reset (MetaWaylandXdgSurface *xdg_surface) surface = meta_wayland_surface_role_get_surface (surface_role); 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); meta_wayland_shell_surface_set_window (shell_surface, window);