Buffer Pooling Optimization

This commit is contained in:
Emac07 2023-12-22 11:17:46 -05:00
parent bbabb9aae8
commit 1e86d13b9d

View file

@ -103,30 +103,29 @@ void destroy_buffer(struct pool_buffer *buffer) {
} }
struct pool_buffer *get_next_buffer(struct wl_shm *shm, struct pool_buffer *get_next_buffer(struct wl_shm *shm,
struct pool_buffer pool[static 2], uint32_t width, uint32_t height) { struct pool_buffer pool[static 2],
struct pool_buffer *buffer = NULL; uint32_t width, uint32_t height) {
for (size_t i = 0; i < 2; ++i) {
if (!pool[i].busy &&
(pool[i].width == width && pool[i].height == height)) {
pool[i].busy = true;
return &pool[i];
}
}
for (size_t i = 0; i < 2; ++i) { for (size_t i = 0; i < 2; ++i) {
if (pool[i].busy) { if (!pool[i].busy) {
continue; if (pool[i].width != width || pool[i].height != height) {
} destroy_buffer(&pool[i]);
buffer = &pool[i]; }
} if (create_buffer(shm, &pool[i], width, height, WL_SHM_FORMAT_ARGB8888)) {
pool[i].busy = true;
return &pool[i];
} else {
break; // Unable to create buffer
}
}
}
if (!buffer) { return NULL; // No available buffer found
return NULL;
}
if (buffer->width != width || buffer->height != height) {
destroy_buffer(buffer);
}
if (!buffer->buffer) {
if (!create_buffer(shm, buffer, width, height,
WL_SHM_FORMAT_ARGB8888)) {
return NULL;
}
}
buffer->busy = true;
return buffer;
} }