From bb82b6dadaea244356d54c33cc3f0e8a620cd833 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Wed, 11 Aug 2021 17:22:11 +0200 Subject: [PATCH] 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. --- include/wlr/types/wlr_buffer.h | 9 +++------ types/wlr_buffer.c | 19 +++++++++---------- types/wlr_surface.c | 7 ++----- 3 files changed, 14 insertions(+), 21 deletions(-) diff --git a/include/wlr/types/wlr_buffer.h b/include/wlr/types/wlr_buffer.h index 4d9640d8..c714ddb6 100644 --- a/include/wlr/types/wlr_buffer.h +++ b/include/wlr/types/wlr_buffer.h @@ -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); /** - * Try to update the buffer's content. On success, returns the updated buffer - * and destroys the provided `buffer`. On error, `buffer` is intact and NULL is - * returned. + * Try to update the buffer's content. * * Fails if there's more than one reference to the buffer or if the texture * isn't mutable. */ -struct wlr_client_buffer *wlr_client_buffer_apply_damage( - struct wlr_client_buffer *buffer, struct wlr_buffer *next, - pixman_region32_t *damage); +bool wlr_client_buffer_apply_damage(struct wlr_client_buffer *client_buffer, + struct wlr_buffer *next, pixman_region32_t *damage); #endif diff --git a/types/wlr_buffer.c b/types/wlr_buffer.c index 86b138d9..fce20a71 100644 --- a/types/wlr_buffer.c +++ b/types/wlr_buffer.c @@ -271,36 +271,35 @@ struct wlr_client_buffer *wlr_client_buffer_create(struct wlr_buffer *buffer, return client_buffer; } -struct wlr_client_buffer *wlr_client_buffer_apply_damage( - struct wlr_client_buffer *client_buffer, struct wlr_buffer *next, - pixman_region32_t *damage) { +bool wlr_client_buffer_apply_damage(struct wlr_client_buffer *client_buffer, + struct wlr_buffer *next, pixman_region32_t *damage) { if (client_buffer->base.n_locks > 1) { // Someone else still has a reference to the buffer - return NULL; + return false; } if ((uint32_t)next->width != client_buffer->texture->width || (uint32_t)next->height != client_buffer->texture->height) { - return NULL; + return false; } if (client_buffer->shm_source_format == DRM_FORMAT_INVALID) { // Uploading only damaged regions only works for wl_shm buffers and // mutable textures (created from wl_shm buffer) - return NULL; + return false; } void *data; uint32_t format; size_t stride; if (!buffer_begin_data_ptr_access(next, &data, &format, &stride)) { - return NULL; + return false; } if (format != client_buffer->shm_source_format) { // Uploading to textures can't change the format buffer_end_data_ptr_access(next); - return NULL; + return false; } 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->x1, r->y1, data)) { buffer_end_data_ptr_access(next); - return NULL; + return false; } } buffer_end_data_ptr_access(next); - return client_buffer; + return true; } static const struct wlr_buffer_impl shm_client_buffer_impl; diff --git a/types/wlr_surface.c b/types/wlr_surface.c index a82fc5bf..2058e21a 100644 --- a/types/wlr_surface.c +++ b/types/wlr_surface.c @@ -364,13 +364,10 @@ static void surface_apply_damage(struct wlr_surface *surface) { } if (surface->buffer != NULL) { - struct wlr_client_buffer *updated_buffer = - wlr_client_buffer_apply_damage(surface->buffer, - surface->current.buffer, &surface->buffer_damage); - if (updated_buffer != NULL) { + if (wlr_client_buffer_apply_damage(surface->buffer, + surface->current.buffer, &surface->buffer_damage)) { wlr_buffer_unlock(surface->current.buffer); surface->current.buffer = NULL; - surface->buffer = updated_buffer; return; } }