diff --git a/src/wayland/meta-wayland-buffer.c b/src/wayland/meta-wayland-buffer.c index f2cf1e723..bb0e8d234 100644 --- a/src/wayland/meta-wayland-buffer.c +++ b/src/wayland/meta-wayland-buffer.c @@ -54,10 +54,31 @@ meta_wayland_buffer_unref (MetaWaylandBuffer *buffer) if (buffer->ref_count == 0) { g_clear_pointer (&buffer->texture, cogl_object_unref); - wl_resource_queue_event (buffer->resource, WL_BUFFER_RELEASE); + + if (buffer->accessible) + meta_wayland_buffer_release_control (buffer); } } +void +meta_wayland_buffer_take_control (MetaWaylandBuffer *buffer) +{ + if (buffer->accessible) + meta_fatal ("buffer control taken twice"); + + buffer->accessible = TRUE; +} + +void +meta_wayland_buffer_release_control (MetaWaylandBuffer *buffer) +{ + if (!buffer->accessible) + meta_fatal ("buffer released when not in control"); + + wl_resource_queue_event (buffer->resource, WL_BUFFER_RELEASE); + buffer->accessible = FALSE; +} + MetaWaylandBuffer * meta_wayland_buffer_from_resource (struct wl_resource *resource) { @@ -93,6 +114,9 @@ meta_wayland_buffer_ensure_texture (MetaWaylandBuffer *buffer) CoglTexture *texture; struct wl_shm_buffer *shm_buffer; + if (!buffer->accessible) + meta_warning ("attempted to process damage on uncommitted buffer"); + if (buffer->texture) goto out; @@ -126,6 +150,9 @@ meta_wayland_buffer_process_damage (MetaWaylandBuffer *buffer, { struct wl_shm_buffer *shm_buffer; + if (!buffer->accessible) + meta_warning ("attempted to process damage on uncommitted buffer"); + shm_buffer = wl_shm_buffer_get (buffer->resource); if (shm_buffer) diff --git a/src/wayland/meta-wayland-buffer.h b/src/wayland/meta-wayland-buffer.h index 8d81c7226..9f6a5bf83 100644 --- a/src/wayland/meta-wayland-buffer.h +++ b/src/wayland/meta-wayland-buffer.h @@ -39,11 +39,15 @@ struct _MetaWaylandBuffer CoglTexture *texture; uint32_t ref_count; + + uint32_t accessible : 1; }; 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_buffer_take_control (MetaWaylandBuffer *buffer); +void meta_wayland_buffer_release_control (MetaWaylandBuffer *buffer); CoglTexture * meta_wayland_buffer_ensure_texture (MetaWaylandBuffer *buffer); void meta_wayland_buffer_process_damage (MetaWaylandBuffer *buffer, cairo_region_t *region); diff --git a/src/wayland/meta-wayland-surface.c b/src/wayland/meta-wayland-surface.c index f9b3f3c07..4f8b244f3 100644 --- a/src/wayland/meta-wayland-surface.c +++ b/src/wayland/meta-wayland-surface.c @@ -596,6 +596,7 @@ apply_pending_state (MetaWaylandSurface *surface, if (pending->buffer) { + meta_wayland_buffer_take_control (pending->buffer); CoglTexture *texture = meta_wayland_buffer_ensure_texture (pending->buffer); meta_surface_actor_wayland_set_texture (META_SURFACE_ACTOR_WAYLAND (surface->surface_actor), texture); } @@ -607,6 +608,9 @@ apply_pending_state (MetaWaylandSurface *surface, if (!cairo_region_is_empty (pending->damage)) surface_process_damage (surface, pending->damage); + if (pending->buffer) + meta_wayland_buffer_release_control (pending->buffer); + surface->offset_x += pending->dx; surface->offset_y += pending->dy;