]> git.mdlowis.com Git - proto/labwc.git/commitdiff
scaled-scene-buffer: allow multiple wlr_buffer_drops()
authorConsolatis <35009135+Consolatis@users.noreply.github.com>
Fri, 15 Nov 2024 06:02:52 +0000 (07:02 +0100)
committerJohan Malm <johanmalm@users.noreply.github.com>
Thu, 21 Nov 2024 20:31:41 +0000 (20:31 +0000)
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

index e6fd49da1ffd36441082e55fecb5058f68888303..e177fd197c5efb113e6d0a6b161b66585b668b61 100644 (file)
@@ -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);
        }