[mutter] wayland: Make MetaWaylandBufferRef reference counted



commit f36120757f4de3eead9245335bc497c596ed88df
Author: Jonas Ådahl <jadahl gmail com>
Date:   Wed Sep 11 21:52:58 2019 +0200

    wayland: Make MetaWaylandBufferRef reference counted
    
    So that we can have a more dynamic ownership.
    
    https://gitlab.gnome.org/GNOME/mutter/merge_requests/798

 src/wayland/meta-wayland-surface.c | 13 +++++++++----
 src/wayland/meta-wayland-surface.h |  1 +
 2 files changed, 10 insertions(+), 4 deletions(-)
---
diff --git a/src/wayland/meta-wayland-surface.c b/src/wayland/meta-wayland-surface.c
index e80c722fa..c3d56d74d 100644
--- a/src/wayland/meta-wayland-surface.c
+++ b/src/wayland/meta-wayland-surface.c
@@ -126,14 +126,20 @@ meta_wayland_buffer_ref_new (void)
   MetaWaylandBufferRef *buffer_ref;
 
   buffer_ref = g_new0 (MetaWaylandBufferRef, 1);
+  g_ref_count_init (&buffer_ref->ref_count);
 
   return buffer_ref;
 }
 
 static void
-meta_wayland_buffer_ref_free (MetaWaylandBufferRef *buffer_ref)
+meta_wayland_buffer_ref_unref (MetaWaylandBufferRef *buffer_ref)
 {
-  g_free (buffer_ref);
+  if (g_ref_count_dec (&buffer_ref->ref_count))
+    {
+      g_warn_if_fail (buffer_ref->use_count == 0);
+      g_clear_object (&buffer_ref->buffer);
+      g_free (buffer_ref);
+    }
 }
 
 static void
@@ -1295,8 +1301,7 @@ wl_surface_destructor (struct wl_resource *resource)
   if (surface->buffer_held)
     meta_wayland_surface_unref_buffer_use_count (surface);
   g_clear_pointer (&surface->texture, cogl_object_unref);
-  g_clear_object (&surface->buffer_ref->buffer);
-  g_clear_pointer (&surface->buffer_ref, meta_wayland_buffer_ref_free);
+  g_clear_pointer (&surface->buffer_ref, meta_wayland_buffer_ref_unref);
 
   g_clear_object (&surface->cached_state);
   g_clear_object (&surface->pending_state);
diff --git a/src/wayland/meta-wayland-surface.h b/src/wayland/meta-wayland-surface.h
index b4ffeb338..9cedba506 100644
--- a/src/wayland/meta-wayland-surface.h
+++ b/src/wayland/meta-wayland-surface.h
@@ -138,6 +138,7 @@ struct _MetaWaylandDragDestFuncs
 
 typedef struct _MetaWaylandBufferRef
 {
+  grefcount ref_count;
   MetaWaylandBuffer *buffer;
   unsigned int use_count;
 } MetaWaylandBufferRef;


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