From a7283e68fd9d026e3b563c5864ef85f2aa22706d Mon Sep 17 00:00:00 2001 From: Andri Yngvason Date: Wed, 24 Jun 2020 20:45:33 +0000 Subject: [PATCH] buffer: Fix pool release/acquire --- src/buffer.c | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/src/buffer.c b/src/buffer.c index e17f5f8..1830a9e 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -262,16 +262,37 @@ void wv_buffer_pool_resize(struct wv_buffer_pool* pool, pool->format = format; } +static bool wv_buffer_pool_match_buffer(struct wv_buffer_pool* pool, + struct wv_buffer* buffer) +{ + if (pool->type != buffer->type) + return false; + + switch (pool->type) { + case WV_BUFFER_SHM: + if (pool->stride != buffer->stride) + return false; + + /* fall-through */ + case WV_BUFFER_DMABUF: + if (pool->width != buffer->width + || pool->height != buffer->height + || pool->format != buffer->format) + return false; + + return true; + case WV_BUFFER_UNSPEC: + abort(); + } + + return false; +} + struct wv_buffer* wv_buffer_pool_acquire(struct wv_buffer_pool* pool) { struct wv_buffer* buffer = TAILQ_FIRST(&pool->queue); if (buffer) { - assert(pool->type == buffer->type - && pool->width == buffer->width - && pool->height == buffer->height - && pool->stride == buffer->stride - && pool->format == buffer->format); - + assert(wv_buffer_pool_match_buffer(pool, buffer)); TAILQ_REMOVE(&pool->queue, buffer, link); return buffer; } @@ -285,10 +306,7 @@ void wv_buffer_pool_release(struct wv_buffer_pool* pool, { wv_buffer_unmap(buffer); - if (pool->width == buffer->width - && pool->height == buffer->height - && pool->stride == buffer->stride - && pool->format == buffer->format) { + if (wv_buffer_pool_match_buffer(pool, buffer)) { TAILQ_INSERT_TAIL(&pool->queue, buffer, link); } else { wv_buffer_destroy(buffer);