buffer: Add specific handling for different buffers

pull/55/head
Andri Yngvason 2020-06-23 17:29:48 +00:00
parent 480392e40c
commit 9b136c90de
1 changed files with 50 additions and 3 deletions

View File

@ -14,7 +14,7 @@
extern struct wl_shm* wl_shm; 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) int height, int stride, uint32_t fourcc)
{ {
assert(wl_shm); assert(wl_shm);
@ -24,7 +24,7 @@ struct wv_buffer* wv_buffer_create(enum wv_buffer_type type, int width,
if (!self) if (!self)
return NULL; return NULL;
self->type = type; self->type = WV_BUFFER_SHM;
self->width = width; self->width = width;
self->height = height; self->height = height;
self->stride = stride; self->stride = stride;
@ -63,13 +63,60 @@ failure:
return NULL; 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); wl_buffer_destroy(self->wl_buffer);
munmap(self->pixels, self->size); munmap(self->pixels, self->size);
free(self); 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, struct wv_buffer_pool* wv_buffer_pool_create(enum wv_buffer_type type,
int width, int height, int stride, uint32_t format) int width, int height, int stride, uint32_t format)
{ {