buffer: Add buffer type to interface

pull/55/head
Andri Yngvason 2020-06-23 17:20:43 +00:00
parent 59cc119d76
commit 480392e40c
3 changed files with 32 additions and 16 deletions

View File

@ -8,7 +8,13 @@
struct wl_buffer; struct wl_buffer;
enum wv_buffer_type {
WV_BUFFER_UNSPEC = 0,
WV_BUFFER_SHM,
};
struct wv_buffer { struct wv_buffer {
enum wv_buffer_type type;
TAILQ_ENTRY(wv_buffer) link; TAILQ_ENTRY(wv_buffer) link;
struct wl_buffer* wl_buffer; struct wl_buffer* wl_buffer;
void* pixels; void* pixels;
@ -22,18 +28,22 @@ TAILQ_HEAD(wv_buffer_queue, wv_buffer);
struct wv_buffer_pool { struct wv_buffer_pool {
struct wv_buffer_queue queue; struct wv_buffer_queue queue;
enum wv_buffer_type type;
int width, height, stride; int width, height, stride;
uint32_t format; uint32_t format;
}; };
struct wv_buffer* wv_buffer_create(int width, int height, int stride, struct wv_buffer* wv_buffer_create(enum wv_buffer_type, int width, int height,
uint32_t fourcc); int stride, uint32_t fourcc);
void wv_buffer_destroy(struct wv_buffer* self); void wv_buffer_destroy(struct wv_buffer* self);
struct wv_buffer_pool* wv_buffer_pool_create(int width, int height, int stride, int wv_buffer_map(struct wv_buffer* self);
uint32_t format); void wv_buffer_unmap(struct wv_buffer* self);
struct wv_buffer_pool* wv_buffer_pool_create(enum wv_buffer_type, int width,
int height, int stride, uint32_t format);
void wv_buffer_pool_destroy(struct wv_buffer_pool* pool); void wv_buffer_pool_destroy(struct wv_buffer_pool* pool);
void wv_buffer_pool_resize(struct wv_buffer_pool* pool, void wv_buffer_pool_resize(struct wv_buffer_pool* pool, enum wv_buffer_type,
int width, int height, int stride, uint32_t format); int width, int height, int stride, uint32_t format);
struct wv_buffer* wv_buffer_pool_acquire(struct wv_buffer_pool* pool); struct wv_buffer* wv_buffer_pool_acquire(struct wv_buffer_pool* pool);
void wv_buffer_pool_release(struct wv_buffer_pool* pool, void wv_buffer_pool_release(struct wv_buffer_pool* pool,

View File

@ -14,8 +14,8 @@
extern struct wl_shm* wl_shm; extern struct wl_shm* wl_shm;
struct wv_buffer* wv_buffer_create(int width, int height, int stride, struct wv_buffer* wv_buffer_create(enum wv_buffer_type type, int width,
uint32_t fourcc) int height, int stride, uint32_t fourcc)
{ {
assert(wl_shm); assert(wl_shm);
enum wl_shm_format wl_fmt = fourcc_to_wl_shm(fourcc); enum wl_shm_format wl_fmt = fourcc_to_wl_shm(fourcc);
@ -24,6 +24,7 @@ struct wv_buffer* wv_buffer_create(int width, int height, int stride,
if (!self) if (!self)
return NULL; return NULL;
self->type = type;
self->width = width; self->width = width;
self->height = height; self->height = height;
self->stride = stride; self->stride = stride;
@ -69,14 +70,15 @@ void wv_buffer_destroy(struct wv_buffer* self)
free(self); free(self);
} }
struct wv_buffer_pool* wv_buffer_pool_create(int width, int height, int stride, struct wv_buffer_pool* wv_buffer_pool_create(enum wv_buffer_type type,
uint32_t format) int width, int height, int stride, uint32_t format)
{ {
struct wv_buffer_pool* self = calloc(1, sizeof(*self)); struct wv_buffer_pool* self = calloc(1, sizeof(*self));
if (!self) if (!self)
return NULL; return NULL;
TAILQ_INIT(&self->queue); TAILQ_INIT(&self->queue);
self->type = type;
self->width = width; self->width = width;
self->height = height; self->height = height;
self->stride = stride; self->stride = stride;
@ -101,13 +103,15 @@ void wv_buffer_pool_destroy(struct wv_buffer_pool* pool)
} }
void wv_buffer_pool_resize(struct wv_buffer_pool* pool, void wv_buffer_pool_resize(struct wv_buffer_pool* pool,
int width, int height, int stride, uint32_t format) enum wv_buffer_type type, int width, int height, int stride,
uint32_t format)
{ {
if (pool->width != width || pool->height != height if (pool->type != type || pool->width != width || pool->height != height
|| pool->stride != stride || pool->format != format) { || pool->stride != stride || pool->format != format) {
wv_buffer_pool_clear(pool); wv_buffer_pool_clear(pool);
} }
pool->type = type;
pool->width = width; pool->width = width;
pool->height = height; pool->height = height;
pool->stride = stride; pool->stride = stride;
@ -118,7 +122,8 @@ 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->width == buffer->width assert(pool->type == buffer->type
&& pool->width == buffer->width
&& pool->height == buffer->height && pool->height == buffer->height
&& pool->stride == buffer->stride && pool->stride == buffer->stride
&& pool->format == buffer->format); && pool->format == buffer->format);
@ -127,8 +132,8 @@ struct wv_buffer* wv_buffer_pool_acquire(struct wv_buffer_pool* pool)
return buffer; return buffer;
} }
return wv_buffer_create(pool->width, pool->height, pool->stride, return wv_buffer_create(pool->type, pool->width, pool->height,
pool->format); pool->stride, pool->format);
} }
void wv_buffer_pool_release(struct wv_buffer_pool* pool, void wv_buffer_pool_release(struct wv_buffer_pool* pool,

View File

@ -68,7 +68,8 @@ static void screencopy_buffer(void* data,
struct screencopy* self = data; struct screencopy* self = data;
uint32_t fourcc = fourcc_from_wl_shm(format); uint32_t fourcc = fourcc_from_wl_shm(format);
wv_buffer_pool_resize(self->pool, width, height, stride, fourcc); wv_buffer_pool_resize(self->pool, WV_BUFFER_SHM, width, height, stride,
fourcc);
struct wv_buffer* buffer = wv_buffer_pool_acquire(self->pool); struct wv_buffer* buffer = wv_buffer_pool_acquire(self->pool);
if (!buffer) { if (!buffer) {
@ -244,7 +245,7 @@ static void screencopy_render(struct frame_capture* fc,
void screencopy_init(struct screencopy* self) void screencopy_init(struct screencopy* self)
{ {
self->pool = wv_buffer_pool_create(0, 0, 0, 0); self->pool = wv_buffer_pool_create(0, 0, 0, 0, 0);
assert(self->pool); assert(self->pool);
self->timer = aml_timer_new(0, screencopy__poll, self, NULL); self->timer = aml_timer_new(0, screencopy__poll, self, NULL);