From 0f0958168615a316ecbe32cce76c583757fb8412 Mon Sep 17 00:00:00 2001 From: Andri Yngvason Date: Tue, 23 Jun 2020 17:29:48 +0000 Subject: [PATCH] buffer: Add specific handling for different buffers --- src/buffer.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 3 deletions(-) diff --git a/src/buffer.c b/src/buffer.c index 46ac4ea..ef0c822 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -14,7 +14,7 @@ extern struct wl_shm* wl_shm; -struct wv_buffer* wv_buffer_create(enum wv_buffer_type type, int width, +struct wv_buffer* wv_buffer_create_shm(int width, int height, int stride, uint32_t fourcc) { assert(wl_shm); @@ -24,7 +24,7 @@ struct wv_buffer* wv_buffer_create(enum wv_buffer_type type, int width, if (!self) return NULL; - self->type = type; + self->type = WV_BUFFER_SHM; self->width = width; self->height = height; self->stride = stride; @@ -63,13 +63,60 @@ failure: return NULL; } -void wv_buffer_destroy(struct wv_buffer* self) +struct wv_buffer* wv_buffer_create(enum wv_buffer_type type, int width, + int height, int stride, uint32_t fourcc) +{ + switch (type) { + case WV_BUFFER_SHM: + return wv_buffer_create_shm(width, height, stride, fourcc); + case WV_BUFFER_UNSPEC:; + } + + abort(); + return NULL; +} + +static void wv_buffer_destroy_shm(struct wv_buffer* self) { wl_buffer_destroy(self->wl_buffer); munmap(self->pixels, self->size); free(self); } +void wv_buffer_destroy(struct wv_buffer* self) +{ + switch (self->type) { + case WV_BUFFER_SHM: + wv_buffer_destroy_shm(self); + return; + case WV_BUFFER_UNSPEC:; + } + + abort(); +} + +int wv_buffer_map(struct wv_buffer* self) +{ + switch (self->type) { + case WV_BUFFER_SHM: + return 0; + case WV_BUFFER_UNSPEC:; + } + + abort(); +} + +void wv_buffer_unmap(struct wv_buffer* self) +{ + switch (self->type) { + case WV_BUFFER_SHM: + return; + case WV_BUFFER_UNSPEC:; + } + + abort(); +} + struct wv_buffer_pool* wv_buffer_pool_create(enum wv_buffer_type type, int width, int height, int stride, uint32_t format) {