buffer: make wlr_client_buffer_apply_damage return a bool

We always return the same wlr_client_buffer as the one passed in,
so no need to return anything.
This commit is contained in:
Simon Ser 2021-08-11 17:22:11 +02:00
parent cbe099dcc7
commit bb82b6dada
3 changed files with 14 additions and 21 deletions

View file

@ -178,15 +178,12 @@ struct wlr_client_buffer *wlr_client_buffer_get(struct wlr_buffer *buffer);
*/ */
bool wlr_resource_is_buffer(struct wl_resource *resource); bool wlr_resource_is_buffer(struct wl_resource *resource);
/** /**
* Try to update the buffer's content. On success, returns the updated buffer * Try to update the buffer's content.
* and destroys the provided `buffer`. On error, `buffer` is intact and NULL is
* returned.
* *
* Fails if there's more than one reference to the buffer or if the texture * Fails if there's more than one reference to the buffer or if the texture
* isn't mutable. * isn't mutable.
*/ */
struct wlr_client_buffer *wlr_client_buffer_apply_damage( bool wlr_client_buffer_apply_damage(struct wlr_client_buffer *client_buffer,
struct wlr_client_buffer *buffer, struct wlr_buffer *next, struct wlr_buffer *next, pixman_region32_t *damage);
pixman_region32_t *damage);
#endif #endif

View file

@ -271,36 +271,35 @@ struct wlr_client_buffer *wlr_client_buffer_create(struct wlr_buffer *buffer,
return client_buffer; return client_buffer;
} }
struct wlr_client_buffer *wlr_client_buffer_apply_damage( bool wlr_client_buffer_apply_damage(struct wlr_client_buffer *client_buffer,
struct wlr_client_buffer *client_buffer, struct wlr_buffer *next, struct wlr_buffer *next, pixman_region32_t *damage) {
pixman_region32_t *damage) {
if (client_buffer->base.n_locks > 1) { if (client_buffer->base.n_locks > 1) {
// Someone else still has a reference to the buffer // Someone else still has a reference to the buffer
return NULL; return false;
} }
if ((uint32_t)next->width != client_buffer->texture->width || if ((uint32_t)next->width != client_buffer->texture->width ||
(uint32_t)next->height != client_buffer->texture->height) { (uint32_t)next->height != client_buffer->texture->height) {
return NULL; return false;
} }
if (client_buffer->shm_source_format == DRM_FORMAT_INVALID) { if (client_buffer->shm_source_format == DRM_FORMAT_INVALID) {
// Uploading only damaged regions only works for wl_shm buffers and // Uploading only damaged regions only works for wl_shm buffers and
// mutable textures (created from wl_shm buffer) // mutable textures (created from wl_shm buffer)
return NULL; return false;
} }
void *data; void *data;
uint32_t format; uint32_t format;
size_t stride; size_t stride;
if (!buffer_begin_data_ptr_access(next, &data, &format, &stride)) { if (!buffer_begin_data_ptr_access(next, &data, &format, &stride)) {
return NULL; return false;
} }
if (format != client_buffer->shm_source_format) { if (format != client_buffer->shm_source_format) {
// Uploading to textures can't change the format // Uploading to textures can't change the format
buffer_end_data_ptr_access(next); buffer_end_data_ptr_access(next);
return NULL; return false;
} }
int n; int n;
@ -311,13 +310,13 @@ struct wlr_client_buffer *wlr_client_buffer_apply_damage(
r->x2 - r->x1, r->y2 - r->y1, r->x1, r->y1, r->x2 - r->x1, r->y2 - r->y1, r->x1, r->y1,
r->x1, r->y1, data)) { r->x1, r->y1, data)) {
buffer_end_data_ptr_access(next); buffer_end_data_ptr_access(next);
return NULL; return false;
} }
} }
buffer_end_data_ptr_access(next); buffer_end_data_ptr_access(next);
return client_buffer; return true;
} }
static const struct wlr_buffer_impl shm_client_buffer_impl; static const struct wlr_buffer_impl shm_client_buffer_impl;

View file

@ -364,13 +364,10 @@ static void surface_apply_damage(struct wlr_surface *surface) {
} }
if (surface->buffer != NULL) { if (surface->buffer != NULL) {
struct wlr_client_buffer *updated_buffer = if (wlr_client_buffer_apply_damage(surface->buffer,
wlr_client_buffer_apply_damage(surface->buffer, surface->current.buffer, &surface->buffer_damage)) {
surface->current.buffer, &surface->buffer_damage);
if (updated_buffer != NULL) {
wlr_buffer_unlock(surface->current.buffer); wlr_buffer_unlock(surface->current.buffer);
surface->current.buffer = NULL; surface->current.buffer = NULL;
surface->buffer = updated_buffer;
return; return;
} }
} }