buffer: Add buffer type to interface
parent
17ee85dfd0
commit
473ce5eb23
|
@ -8,7 +8,13 @@
|
|||
|
||||
struct wl_buffer;
|
||||
|
||||
enum wv_buffer_type {
|
||||
WV_BUFFER_UNSPEC = 0,
|
||||
WV_BUFFER_SHM,
|
||||
};
|
||||
|
||||
struct wv_buffer {
|
||||
enum wv_buffer_type type;
|
||||
TAILQ_ENTRY(wv_buffer) link;
|
||||
struct wl_buffer* wl_buffer;
|
||||
void* pixels;
|
||||
|
@ -22,18 +28,22 @@ TAILQ_HEAD(wv_buffer_queue, wv_buffer);
|
|||
|
||||
struct wv_buffer_pool {
|
||||
struct wv_buffer_queue queue;
|
||||
enum wv_buffer_type type;
|
||||
int width, height, stride;
|
||||
uint32_t format;
|
||||
};
|
||||
|
||||
struct wv_buffer* wv_buffer_create(int width, int height, int stride,
|
||||
uint32_t fourcc);
|
||||
struct wv_buffer* wv_buffer_create(enum wv_buffer_type, int width, int height,
|
||||
int stride, uint32_t fourcc);
|
||||
void wv_buffer_destroy(struct wv_buffer* self);
|
||||
|
||||
struct wv_buffer_pool* wv_buffer_pool_create(int width, int height, int stride,
|
||||
uint32_t format);
|
||||
int wv_buffer_map(struct wv_buffer* self);
|
||||
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_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);
|
||||
struct wv_buffer* wv_buffer_pool_acquire(struct wv_buffer_pool* pool);
|
||||
void wv_buffer_pool_release(struct wv_buffer_pool* pool,
|
||||
|
|
23
src/buffer.c
23
src/buffer.c
|
@ -14,8 +14,8 @@
|
|||
|
||||
extern struct wl_shm* wl_shm;
|
||||
|
||||
struct wv_buffer* wv_buffer_create(int width, int height, int stride,
|
||||
uint32_t fourcc)
|
||||
struct wv_buffer* wv_buffer_create(enum wv_buffer_type type, int width,
|
||||
int height, int stride, uint32_t fourcc)
|
||||
{
|
||||
assert(wl_shm);
|
||||
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)
|
||||
return NULL;
|
||||
|
||||
self->type = type;
|
||||
self->width = width;
|
||||
self->height = height;
|
||||
self->stride = stride;
|
||||
|
@ -69,14 +70,15 @@ void wv_buffer_destroy(struct wv_buffer* self)
|
|||
free(self);
|
||||
}
|
||||
|
||||
struct wv_buffer_pool* wv_buffer_pool_create(int width, int height, int stride,
|
||||
uint32_t format)
|
||||
struct wv_buffer_pool* wv_buffer_pool_create(enum wv_buffer_type type,
|
||||
int width, int height, int stride, uint32_t format)
|
||||
{
|
||||
struct wv_buffer_pool* self = calloc(1, sizeof(*self));
|
||||
if (!self)
|
||||
return NULL;
|
||||
|
||||
TAILQ_INIT(&self->queue);
|
||||
self->type = type;
|
||||
self->width = width;
|
||||
self->height = height;
|
||||
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,
|
||||
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) {
|
||||
wv_buffer_pool_clear(pool);
|
||||
}
|
||||
|
||||
pool->type = type;
|
||||
pool->width = width;
|
||||
pool->height = height;
|
||||
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);
|
||||
if (buffer) {
|
||||
assert(pool->width == buffer->width
|
||||
assert(pool->type == buffer->type
|
||||
&& pool->width == buffer->width
|
||||
&& pool->height == buffer->height
|
||||
&& pool->stride == buffer->stride
|
||||
&& pool->format == buffer->format);
|
||||
|
@ -127,8 +132,8 @@ struct wv_buffer* wv_buffer_pool_acquire(struct wv_buffer_pool* pool)
|
|||
return buffer;
|
||||
}
|
||||
|
||||
return wv_buffer_create(pool->width, pool->height, pool->stride,
|
||||
pool->format);
|
||||
return wv_buffer_create(pool->type, pool->width, pool->height,
|
||||
pool->stride, pool->format);
|
||||
}
|
||||
|
||||
void wv_buffer_pool_release(struct wv_buffer_pool* pool,
|
||||
|
|
|
@ -68,7 +68,8 @@ static void screencopy_buffer(void* data,
|
|||
struct screencopy* self = data;
|
||||
|
||||
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);
|
||||
if (!buffer) {
|
||||
|
@ -244,7 +245,7 @@ static void screencopy_render(struct frame_capture* fc,
|
|||
|
||||
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);
|
||||
|
||||
self->timer = aml_timer_new(0, screencopy__poll, self, NULL);
|
||||
|
|
Loading…
Reference in New Issue