diff --git a/src/wayland/meta-wayland-buffer.c b/src/wayland/meta-wayland-buffer.c index 6837ee1ca..be7039c2e 100644 --- a/src/wayland/meta-wayland-buffer.c +++ b/src/wayland/meta-wayland-buffer.c @@ -897,6 +897,16 @@ try_acquire_egl_image_scanout (MetaWaylandBuffer *buffer, #endif } +static void +scanout_destroyed (gpointer data, + GObject *where_the_object_was) +{ + MetaWaylandBuffer *buffer = data; + + meta_wayland_buffer_dec_use_count (buffer); + g_object_unref (buffer); +} + CoglScanout * meta_wayland_buffer_try_acquire_scanout (MetaWaylandBuffer *buffer, CoglOnscreen *onscreen) @@ -936,9 +946,15 @@ meta_wayland_buffer_try_acquire_scanout (MetaWaylandBuffer *buffer, return NULL; } - if (scanout) - g_signal_connect (scanout, "scanout-failed", - G_CALLBACK (on_scanout_failed), buffer); + if (!scanout) + return NULL; + + g_signal_connect (scanout, "scanout-failed", + G_CALLBACK (on_scanout_failed), buffer); + + g_object_ref (buffer); + meta_wayland_buffer_inc_use_count (buffer); + g_object_weak_ref (G_OBJECT (scanout), scanout_destroyed, buffer); return scanout; } diff --git a/src/wayland/meta-wayland-surface.c b/src/wayland/meta-wayland-surface.c index d31791bb9..213bccd64 100644 --- a/src/wayland/meta-wayland-surface.c +++ b/src/wayland/meta-wayland-surface.c @@ -2253,39 +2253,18 @@ meta_wayland_surface_get_buffer_height (MetaWaylandSurface *surface) return 0; } -static void -scanout_destroyed (gpointer data, - GObject *where_the_object_was) -{ - MetaWaylandBuffer *buffer = data; - - meta_wayland_buffer_dec_use_count (buffer); - g_object_unref (buffer); -} - CoglScanout * meta_wayland_surface_try_acquire_scanout (MetaWaylandSurface *surface, CoglOnscreen *onscreen) { - CoglScanout *scanout; - MetaWaylandBuffer *buffer; - if (!surface->buffer) return NULL; if (surface->buffer->use_count == 0) return NULL; - scanout = meta_wayland_buffer_try_acquire_scanout (surface->buffer, - onscreen); - if (!scanout) - return NULL; - - buffer = g_object_ref (surface->buffer); - meta_wayland_buffer_inc_use_count (buffer); - g_object_weak_ref (G_OBJECT (scanout), scanout_destroyed, buffer); - - return scanout; + return meta_wayland_buffer_try_acquire_scanout (surface->buffer, + onscreen); } MetaCrtc *