buffer: Fix pool release/acquire
parent
0b15b465df
commit
a7283e68fd
38
src/buffer.c
38
src/buffer.c
|
@ -262,16 +262,37 @@ void wv_buffer_pool_resize(struct wv_buffer_pool* pool,
|
||||||
pool->format = format;
|
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* wv_buffer_pool_acquire(struct wv_buffer_pool* pool)
|
||||||
{
|
{
|
||||||
struct wv_buffer* buffer = TAILQ_FIRST(&pool->queue);
|
struct wv_buffer* buffer = TAILQ_FIRST(&pool->queue);
|
||||||
if (buffer) {
|
if (buffer) {
|
||||||
assert(pool->type == buffer->type
|
assert(wv_buffer_pool_match_buffer(pool, buffer));
|
||||||
&& pool->width == buffer->width
|
|
||||||
&& pool->height == buffer->height
|
|
||||||
&& pool->stride == buffer->stride
|
|
||||||
&& pool->format == buffer->format);
|
|
||||||
|
|
||||||
TAILQ_REMOVE(&pool->queue, buffer, link);
|
TAILQ_REMOVE(&pool->queue, buffer, link);
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
@ -285,10 +306,7 @@ void wv_buffer_pool_release(struct wv_buffer_pool* pool,
|
||||||
{
|
{
|
||||||
wv_buffer_unmap(buffer);
|
wv_buffer_unmap(buffer);
|
||||||
|
|
||||||
if (pool->width == buffer->width
|
if (wv_buffer_pool_match_buffer(pool, buffer)) {
|
||||||
&& pool->height == buffer->height
|
|
||||||
&& pool->stride == buffer->stride
|
|
||||||
&& pool->format == buffer->format) {
|
|
||||||
TAILQ_INSERT_TAIL(&pool->queue, buffer, link);
|
TAILQ_INSERT_TAIL(&pool->queue, buffer, link);
|
||||||
} else {
|
} else {
|
||||||
wv_buffer_destroy(buffer);
|
wv_buffer_destroy(buffer);
|
||||||
|
|
Loading…
Reference in New Issue