From 71b4277852c70b213b530a73fc5a55ba7f4019d1 Mon Sep 17 00:00:00 2001 From: Consolatis <35009135+Consolatis@users.noreply.github.com> Date: Fri, 15 Nov 2024 07:02:52 +0100 Subject: [PATCH] scaled-scene-buffer: allow multiple wlr_buffer_drops() This allows implementations of the interface to share a single wlr_buffer for multiple wlr_scene_buffer nodes and still make the scaled-scene-buffer handle the buffer drops. wlr_scene_buffer holds an implicit lock while using a wlr_buffer and scaled-scene-buffer.c holds additional locks for as long as a buffer is within its internal cache. This should ensure that a shared wlr_buffer never gets actually dropped even if wlr_buffer_drop() has been called by another scaled-scene-buffer instance using the same wlr_buffer. --- src/common/scaled-scene-buffer.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/common/scaled-scene-buffer.c b/src/common/scaled-scene-buffer.c index e6fd49da..e177fd19 100644 --- a/src/common/scaled-scene-buffer.c +++ b/src/common/scaled-scene-buffer.c @@ -41,10 +41,10 @@ _cache_entry_destroy(struct scaled_scene_buffer_cache_entry *cache_entry, bool d wl_list_remove(&cache_entry->link); if (cache_entry->buffer) { /* Allow the buffer to get dropped if there are no further consumers */ - wlr_buffer_unlock(cache_entry->buffer); - if (drop_buffer) { + if (drop_buffer && !cache_entry->buffer->dropped) { wlr_buffer_drop(cache_entry->buffer); } + wlr_buffer_unlock(cache_entry->buffer); } free(cache_entry); } @@ -82,10 +82,10 @@ _update_buffer(struct scaled_scene_buffer *self, double scale) cache_entry = wl_container_of(self->cache.prev, cache_entry, link); if (cache_entry->buffer) { /* Allow the old buffer to get dropped if there are no further consumers */ - wlr_buffer_unlock(cache_entry->buffer); - if (self->drop_buffer) { + if (self->drop_buffer && !cache_entry->buffer->dropped) { wlr_buffer_drop(cache_entry->buffer); } + wlr_buffer_unlock(cache_entry->buffer); } wl_list_remove(&cache_entry->link); }