[mutter/wip/carlosg/performance-improvements: 16/23] wayland: Use weak ref to keep track of buffers



commit cf7d9cbf3b3b2e75b131a9529b0bad4f7870b6db
Author: Carlos Garnacho <carlosg gnome org>
Date:   Sat May 6 22:46:06 2017 +0200

    wayland: Use weak ref to keep track of buffers
    
    Instead of using a one-shot signal meant to happen then the buffer
    is being destroyed.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=782344

 src/wayland/meta-wayland-surface.c |   34 +++++++++++++---------------------
 src/wayland/meta-wayland-surface.h |    1 -
 2 files changed, 13 insertions(+), 22 deletions(-)
---
diff --git a/src/wayland/meta-wayland-surface.c b/src/wayland/meta-wayland-surface.c
index 5a0e0ee..d4365fa 100644
--- a/src/wayland/meta-wayland-surface.c
+++ b/src/wayland/meta-wayland-surface.c
@@ -464,14 +464,6 @@ queue_surface_actor_frame_callbacks (MetaWaylandSurface      *surface,
 }
 
 static void
-pending_buffer_resource_destroyed (MetaWaylandBuffer       *buffer,
-                                   MetaWaylandPendingState *pending)
-{
-  g_signal_handler_disconnect (buffer, pending->buffer_destroy_handler_id);
-  pending->buffer = NULL;
-}
-
-static void
 pending_state_init (MetaWaylandPendingState *state)
 {
   state->newly_attached = FALSE;
@@ -503,8 +495,9 @@ pending_state_destroy (MetaWaylandPendingState *state)
   g_clear_pointer (&state->opaque_region, cairo_region_destroy);
 
   if (state->buffer)
-    g_signal_handler_disconnect (state->buffer,
-                                 state->buffer_destroy_handler_id);
+    g_object_remove_weak_pointer (G_OBJECT (state->buffer),
+                                  (gpointer *) &state->buffer);
+
   wl_list_for_each_safe (cb, next, &state->frame_callback_list, link)
     wl_resource_destroy (cb->resource);
 }
@@ -521,7 +514,10 @@ move_pending_state (MetaWaylandPendingState *from,
                     MetaWaylandPendingState *to)
 {
   if (from->buffer)
-    g_signal_handler_disconnect (from->buffer, from->buffer_destroy_handler_id);
+    {
+      g_object_remove_weak_pointer (G_OBJECT (from->buffer),
+                                    (gpointer *) &from->buffer);
+    }
 
   to->newly_attached = from->newly_attached;
   to->buffer = from->buffer;
@@ -547,10 +543,8 @@ move_pending_state (MetaWaylandPendingState *from,
 
   if (to->buffer)
     {
-      to->buffer_destroy_handler_id =
-        g_signal_connect (to->buffer, "resource-destroyed",
-                          G_CALLBACK (pending_buffer_resource_destroyed),
-                          to);
+      g_object_add_weak_pointer (G_OBJECT (to->buffer),
+                                 (gpointer *) &to->buffer);
     }
 
   pending_state_init (from);
@@ -906,8 +900,8 @@ wl_surface_attach (struct wl_client *client,
 
   if (surface->pending->buffer)
     {
-      g_signal_handler_disconnect (surface->pending->buffer,
-                                   surface->pending->buffer_destroy_handler_id);
+      g_object_remove_weak_pointer (G_OBJECT (surface->pending->buffer),
+                                    (gpointer *) &surface->pending->buffer);
     }
 
   surface->pending->newly_attached = TRUE;
@@ -917,10 +911,8 @@ wl_surface_attach (struct wl_client *client,
 
   if (buffer)
     {
-      surface->pending->buffer_destroy_handler_id =
-        g_signal_connect (buffer, "resource-destroyed",
-                          G_CALLBACK (pending_buffer_resource_destroyed),
-                          surface->pending);
+      g_object_add_weak_pointer (G_OBJECT (surface->pending->buffer),
+                                 (gpointer *) &surface->pending->buffer);
     }
 }
 
diff --git a/src/wayland/meta-wayland-surface.h b/src/wayland/meta-wayland-surface.h
index 36e066f..deda384 100644
--- a/src/wayland/meta-wayland-surface.h
+++ b/src/wayland/meta-wayland-surface.h
@@ -123,7 +123,6 @@ struct _MetaWaylandPendingState
   /* wl_surface.attach */
   gboolean newly_attached;
   MetaWaylandBuffer *buffer;
-  gulong buffer_destroy_handler_id;
   int32_t dx;
   int32_t dy;
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]