mirror of
https://git.sr.ht/~leon_plickat/wayneko
synced 2025-09-19 07:53:21 +02:00
buffer pool: cull buffers
This commit is contained in:
parent
abba39daf9
commit
b8bdb2b238
1 changed files with 20 additions and 2 deletions
22
wayneko.c
22
wayneko.c
|
@ -102,7 +102,8 @@ struct timespec last_tick;
|
|||
* keep all those extra buffers around if we can avoid it, as to not have
|
||||
* unecessary memory overhead.
|
||||
*/
|
||||
int max_buffer_multiplicity = 3;
|
||||
const int max_buffer_multiplicity = 3;
|
||||
const int surface_amount = 1;
|
||||
|
||||
struct wl_list buffer_pool;
|
||||
|
||||
|
@ -406,6 +407,22 @@ static struct Buffer *buffer_pool_new_buffer (uint32_t width, uint32_t height)
|
|||
return buffer;
|
||||
}
|
||||
|
||||
static void buffer_pool_cull_buffers (void)
|
||||
{
|
||||
int to_remove = wl_list_length(&buffer_pool) - (max_buffer_multiplicity * surface_amount);
|
||||
struct Buffer *buffer, *tmp;
|
||||
wl_list_for_each_safe(buffer, tmp, &buffer_pool, link)
|
||||
{
|
||||
if (to_remove == 0)
|
||||
break;
|
||||
if (buffer->busy)
|
||||
continue;
|
||||
buffer_finish(buffer);
|
||||
buffer_destroy(buffer);
|
||||
to_remove--;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a buffer of the specified dimenisons. If possible an idle buffer is
|
||||
* reused, otherweise a new one is created.
|
||||
|
@ -416,7 +433,8 @@ static struct Buffer *buffer_pool_next_buffer (uint32_t width, uint32_t height)
|
|||
if ( ret == NULL )
|
||||
ret = buffer_pool_new_buffer(width, height);
|
||||
|
||||
// XXX cull buffers
|
||||
if ( wl_list_length(&buffer_pool) > max_buffer_multiplicity * surface_amount )
|
||||
buffer_pool_cull_buffers();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue