[mutter/wayland] wayland: Simply store a MetaWaylandBuffer



commit 2f6f0f252c95b1990e3f23068a51e351acf92d93
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Sat Feb 1 17:45:51 2014 -0500

    wayland: Simply store a MetaWaylandBuffer
    
    There's no need for the MetaWaylandBufferReference abstraction...

 src/wayland/meta-wayland-private.h |    7 ++--
 src/wayland/meta-wayland-seat.c    |    4 +-
 src/wayland/meta-wayland-surface.c |   26 +++++++++++++---
 src/wayland/meta-wayland-surface.h |   10 +-----
 src/wayland/meta-wayland.c         |   58 +++++++++++------------------------
 5 files changed, 46 insertions(+), 59 deletions(-)
---
diff --git a/src/wayland/meta-wayland-private.h b/src/wayland/meta-wayland-private.h
index 6dc9620..efd2e4a 100644
--- a/src/wayland/meta-wayland-private.h
+++ b/src/wayland/meta-wayland-private.h
@@ -102,10 +102,9 @@ gboolean                meta_wayland_compositor_handle_event    (MetaWaylandComp
 MetaLauncher           *meta_wayland_compositor_get_launcher    (MetaWaylandCompositor *compositor);
 gboolean                meta_wayland_compositor_is_native       (MetaWaylandCompositor *compositor);
 
-MetaWaylandBuffer *     meta_wayland_buffer_from_resource       (struct wl_resource *resource);
-
-void                    meta_wayland_buffer_reference           (MetaWaylandBufferReference *ref,
-                                                                MetaWaylandBuffer          *buffer);
+MetaWaylandBuffer *     meta_wayland_buffer_from_resource       (struct wl_resource    *resource);
+void                    meta_wayland_buffer_ref                 (MetaWaylandBuffer     *buffer);
+void                    meta_wayland_buffer_unref               (MetaWaylandBuffer     *buffer);
 
 void                    meta_wayland_compositor_update          (MetaWaylandCompositor *compositor,
                                                                  const ClutterEvent    *event);
diff --git a/src/wayland/meta-wayland-seat.c b/src/wayland/meta-wayland-seat.c
index 4baadac..83987cb 100644
--- a/src/wayland/meta-wayland-seat.c
+++ b/src/wayland/meta-wayland-seat.c
@@ -72,8 +72,8 @@ meta_wayland_seat_update_cursor_surface (MetaWaylandSeat *seat)
   if (seat->cursor_tracker == NULL)
     return;
 
-  if (seat->cursor_surface && seat->cursor_surface->buffer_ref.buffer)
-    buffer = seat->cursor_surface->buffer_ref.buffer->resource;
+  if (seat->cursor_surface && seat->cursor_surface->buffer)
+    buffer = seat->cursor_surface->buffer->resource;
   else
     buffer = NULL;
 
diff --git a/src/wayland/meta-wayland-surface.c b/src/wayland/meta-wayland-surface.c
index 0e8ffae..764ec2c 100644
--- a/src/wayland/meta-wayland-surface.c
+++ b/src/wayland/meta-wayland-surface.c
@@ -72,6 +72,22 @@ typedef struct
 } MetaWaylandSubsurfacePlacementOp;
 
 static void
+surface_set_buffer (MetaWaylandSurface *surface,
+                    MetaWaylandBuffer  *buffer)
+{
+  if (surface->buffer == buffer)
+    return;
+
+  if (surface->buffer)
+    meta_wayland_buffer_unref (surface->buffer);
+
+  surface->buffer = buffer;
+
+  if (surface->buffer)
+    meta_wayland_buffer_ref (surface->buffer);
+}
+
+static void
 surface_process_damage (MetaWaylandSurface *surface,
                         cairo_region_t *region)
 {
@@ -298,8 +314,8 @@ toplevel_surface_commit (MetaWaylandSurface             *surface,
           int new_width;
           int new_height;
 
-          new_width = surface->buffer_ref.buffer->width;
-          new_height = surface->buffer_ref.buffer->height;
+          new_width = surface->buffer->width;
+          new_height = surface->buffer->height;
           if (new_width != window->rect.width ||
               new_height != window->rect.height ||
               pending->dx != 0 ||
@@ -449,9 +465,9 @@ commit_double_buffered_state (MetaWaylandSurface             *surface,
   gboolean buffer_changed = FALSE;
 
   /* wl_surface.attach */
-  if (pending->newly_attached && pending->buffer != surface->buffer_ref.buffer)
+  if (pending->newly_attached && surface->buffer != pending->buffer)
     {
-      meta_wayland_buffer_reference (&surface->buffer_ref, pending->buffer);
+      surface_set_buffer (surface, pending->buffer);
       buffer_changed = TRUE;
     }
 
@@ -528,7 +544,7 @@ meta_wayland_surface_free (MetaWaylandSurface *surface)
 
   compositor->surfaces = g_list_remove (compositor->surfaces, surface);
 
-  meta_wayland_buffer_reference (&surface->buffer_ref, NULL);
+  surface_set_buffer (surface, NULL);
   double_buffered_state_destroy (&surface->pending);
   g_object_unref (surface->surface_actor);
   if (surface->resource)
diff --git a/src/wayland/meta-wayland-surface.h b/src/wayland/meta-wayland-surface.h
index 454f5d4..129ce8a 100644
--- a/src/wayland/meta-wayland-surface.h
+++ b/src/wayland/meta-wayland-surface.h
@@ -39,13 +39,7 @@ struct _MetaWaylandBuffer
 
   CoglTexture *texture;
   int32_t width, height;
-  uint32_t busy_count;
-};
-
-struct _MetaWaylandBufferReference
-{
-  MetaWaylandBuffer *buffer;
-  struct wl_listener destroy_listener;
+  uint32_t ref_count;
 };
 
 typedef struct
@@ -77,7 +71,7 @@ struct _MetaWaylandSurface
 {
   struct wl_resource *resource;
   MetaWaylandCompositor *compositor;
-  MetaWaylandBufferReference buffer_ref;
+  MetaWaylandBuffer *buffer;
   MetaSurfaceActor *surface_actor;
   MetaWindow *window;
   MetaWaylandSurfaceExtension xdg_surface;
diff --git a/src/wayland/meta-wayland.c b/src/wayland/meta-wayland.c
index 39eedc7..f3e828f 100644
--- a/src/wayland/meta-wayland.c
+++ b/src/wayland/meta-wayland.c
@@ -138,6 +138,24 @@ meta_wayland_buffer_destroy_handler (struct wl_listener *listener,
   g_slice_free (MetaWaylandBuffer, buffer);
 }
 
+void
+meta_wayland_buffer_ref (MetaWaylandBuffer *buffer)
+{
+  buffer->ref_count++;
+}
+
+void
+meta_wayland_buffer_unref (MetaWaylandBuffer *buffer)
+{
+  buffer->ref_count--;
+  if (buffer->ref_count == 0)
+    {
+      g_clear_pointer (&buffer->texture, cogl_object_unref);
+      g_assert (wl_resource_get_client (buffer->resource));
+      wl_resource_queue_event (buffer->resource, WL_BUFFER_RELEASE);
+    }
+}
+
 MetaWaylandBuffer *
 meta_wayland_buffer_from_resource (struct wl_resource *resource)
 {
@@ -165,46 +183,6 @@ meta_wayland_buffer_from_resource (struct wl_resource *resource)
   return buffer;
 }
 
-static void
-meta_wayland_buffer_reference_handle_destroy (struct wl_listener *listener,
-                                              void *data)
-{
-  MetaWaylandBufferReference *ref =
-    wl_container_of (listener, ref, destroy_listener);
-
-  g_assert (data == ref->buffer);
-
-  ref->buffer = NULL;
-}
-
-void
-meta_wayland_buffer_reference (MetaWaylandBufferReference *ref,
-                               MetaWaylandBuffer *buffer)
-{
-  if (ref->buffer && buffer != ref->buffer)
-    {
-      ref->buffer->busy_count--;
-
-      if (ref->buffer->busy_count == 0)
-        {
-         g_clear_pointer (&ref->buffer->texture, cogl_object_unref);
-          g_assert (wl_resource_get_client (ref->buffer->resource));
-          wl_resource_queue_event (ref->buffer->resource, WL_BUFFER_RELEASE);
-        }
-
-      wl_list_remove (&ref->destroy_listener.link);
-    }
-
-  if (buffer && buffer != ref->buffer)
-    {
-      buffer->busy_count++;
-      wl_signal_add (&buffer->destroy_signal, &ref->destroy_listener);
-    }
-
-  ref->buffer = buffer;
-  ref->destroy_listener.notify = meta_wayland_buffer_reference_handle_destroy;
-}
-
 void
 meta_wayland_compositor_set_input_focus (MetaWaylandCompositor *compositor,
                                          MetaWindow            *window)


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