From 0615cd44c6ebe9e5e9435f2706a280842a18b33c Mon Sep 17 00:00:00 2001 From: Andri Yngvason Date: Fri, 26 Jun 2020 18:05:31 +0000 Subject: [PATCH] buffer: Add damage field --- include/buffer.h | 8 ++++++++ src/buffer.c | 22 ++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/include/buffer.h b/include/buffer.h index 1c87a4b..25fda5f 100644 --- a/include/buffer.h +++ b/include/buffer.h @@ -5,6 +5,7 @@ #include #include #include +#include struct wl_buffer; struct gbm_bo; @@ -27,6 +28,8 @@ struct wv_buffer { uint32_t format; bool y_inverted; + struct pixman_region16 damage; + /* The following is only applicable to DMABUF */ struct gbm_bo* bo; void* bo_map_handle; @@ -48,6 +51,11 @@ void wv_buffer_destroy(struct wv_buffer* self); int wv_buffer_map(struct wv_buffer* self); void wv_buffer_unmap(struct wv_buffer* self); +void wv_buffer_damage_rect(struct wv_buffer* self, int x, int y, int width, + int height); +void wv_buffer_damage_whole(struct wv_buffer* self); +void wv_buffer_damage_clear(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); diff --git a/src/buffer.c b/src/buffer.c index 1830a9e..6f71df6 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -7,6 +7,7 @@ #include #include #include +#include #include "linux-dmabuf-unstable-v1.h" #include "shm.h" @@ -54,6 +55,8 @@ struct wv_buffer* wv_buffer_create_shm(int width, if (!self->wl_buffer) goto shm_failure; + pixman_region_init(&self->damage); + close(fd); return self; @@ -149,6 +152,7 @@ static void wv_buffer_destroy_dmabuf(struct wv_buffer* self) void wv_buffer_destroy(struct wv_buffer* self) { + pixman_region_fini(&self->damage); wv_buffer_unmap(self); switch (self->type) { @@ -214,6 +218,23 @@ void wv_buffer_unmap(struct wv_buffer* self) abort(); } +void wv_buffer_damage_rect(struct wv_buffer* self, int x, int y, int width, + int height) +{ + pixman_region_union_rect(&self->damage, &self->damage, x, y, width, + height); +} + +void wv_buffer_damage_whole(struct wv_buffer* self) +{ + wv_buffer_damage_rect(self, 0, 0, self->width, self->height); +} + +void wv_buffer_damage_clear(struct wv_buffer* self) +{ + pixman_region_clear(&self->damage); +} + struct wv_buffer_pool* wv_buffer_pool_create(enum wv_buffer_type type, int width, int height, int stride, uint32_t format) { @@ -304,6 +325,7 @@ struct wv_buffer* wv_buffer_pool_acquire(struct wv_buffer_pool* pool) void wv_buffer_pool_release(struct wv_buffer_pool* pool, struct wv_buffer* buffer) { + wv_buffer_damage_clear(buffer); wv_buffer_unmap(buffer); if (wv_buffer_pool_match_buffer(pool, buffer)) {