buffer: Add damage field

pull/55/head
Andri Yngvason 2020-06-26 18:05:31 +00:00
parent 21405082a0
commit 0615cd44c6
2 changed files with 30 additions and 0 deletions

View File

@ -5,6 +5,7 @@
#include <unistd.h> #include <unistd.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include <pixman.h>
struct wl_buffer; struct wl_buffer;
struct gbm_bo; struct gbm_bo;
@ -27,6 +28,8 @@ struct wv_buffer {
uint32_t format; uint32_t format;
bool y_inverted; bool y_inverted;
struct pixman_region16 damage;
/* The following is only applicable to DMABUF */ /* The following is only applicable to DMABUF */
struct gbm_bo* bo; struct gbm_bo* bo;
void* bo_map_handle; void* bo_map_handle;
@ -48,6 +51,11 @@ void wv_buffer_destroy(struct wv_buffer* self);
int wv_buffer_map(struct wv_buffer* self); int wv_buffer_map(struct wv_buffer* self);
void wv_buffer_unmap(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, struct wv_buffer_pool* wv_buffer_pool_create(enum wv_buffer_type, int width,
int height, int stride, uint32_t format); 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);

View File

@ -7,6 +7,7 @@
#include <libdrm/drm_fourcc.h> #include <libdrm/drm_fourcc.h>
#include <wayland-client.h> #include <wayland-client.h>
#include <gbm.h> #include <gbm.h>
#include <pixman.h>
#include "linux-dmabuf-unstable-v1.h" #include "linux-dmabuf-unstable-v1.h"
#include "shm.h" #include "shm.h"
@ -54,6 +55,8 @@ struct wv_buffer* wv_buffer_create_shm(int width,
if (!self->wl_buffer) if (!self->wl_buffer)
goto shm_failure; goto shm_failure;
pixman_region_init(&self->damage);
close(fd); close(fd);
return self; return self;
@ -149,6 +152,7 @@ static void wv_buffer_destroy_dmabuf(struct wv_buffer* self)
void wv_buffer_destroy(struct wv_buffer* self) void wv_buffer_destroy(struct wv_buffer* self)
{ {
pixman_region_fini(&self->damage);
wv_buffer_unmap(self); wv_buffer_unmap(self);
switch (self->type) { switch (self->type) {
@ -214,6 +218,23 @@ void wv_buffer_unmap(struct wv_buffer* self)
abort(); 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, 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)
{ {
@ -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, void wv_buffer_pool_release(struct wv_buffer_pool* pool,
struct wv_buffer* buffer) struct wv_buffer* buffer)
{ {
wv_buffer_damage_clear(buffer);
wv_buffer_unmap(buffer); wv_buffer_unmap(buffer);
if (wv_buffer_pool_match_buffer(pool, buffer)) { if (wv_buffer_pool_match_buffer(pool, buffer)) {