From 3fdf8cf07e989a99fe9de85f2cee3eac7f1f7378 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Tue, 8 Jun 2021 19:49:22 +0200 Subject: [PATCH] buffer: unify texture creation in wlr_client_buffer_import All code-paths now invoke wlr_texture_from_buffer. De-duplicate the calls. --- types/wlr_buffer.c | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/types/wlr_buffer.c b/types/wlr_buffer.c index 8a17c9bf..bedd0347 100644 --- a/types/wlr_buffer.c +++ b/types/wlr_buffer.c @@ -198,7 +198,7 @@ struct wlr_client_buffer *wlr_client_buffer_import( struct wlr_renderer *renderer, struct wl_resource *resource) { assert(wlr_resource_is_buffer(resource)); - struct wlr_texture *texture = NULL; + struct wlr_buffer *buffer; if (wl_shm_buffer_get(resource) != NULL) { struct wlr_shm_client_buffer *shm_client_buffer = shm_client_buffer_create(resource); @@ -208,21 +208,16 @@ struct wlr_client_buffer *wlr_client_buffer_import( } // Ensure the buffer will be released before being destroyed - wlr_buffer_lock(&shm_client_buffer->base); + buffer = wlr_buffer_lock(&shm_client_buffer->base); wlr_buffer_drop(&shm_client_buffer->base); - - texture = wlr_texture_from_buffer(renderer, &shm_client_buffer->base); - - // The renderer should've locked the buffer by now if necessary - wlr_buffer_unlock(&shm_client_buffer->base); } else if (wlr_dmabuf_v1_resource_is_buffer(resource)) { struct wlr_dmabuf_v1_buffer *dmabuf = wlr_dmabuf_v1_buffer_from_buffer_resource(resource); - texture = wlr_texture_from_buffer(renderer, &dmabuf->base); + buffer = wlr_buffer_lock(&dmabuf->base); } else if (wlr_drm_buffer_is_resource(resource)) { struct wlr_drm_buffer *drm_buffer = wlr_drm_buffer_from_resource(resource); - texture = wlr_texture_from_buffer(renderer, &drm_buffer->base); + buffer = wlr_buffer_lock(&drm_buffer->base); } else { wlr_log(WLR_ERROR, "Cannot upload texture: unknown buffer type"); @@ -232,32 +227,34 @@ struct wlr_client_buffer *wlr_client_buffer_import( return NULL; } + struct wlr_texture *texture = wlr_texture_from_buffer(renderer, buffer); + wlr_buffer_unlock(buffer); if (texture == NULL) { - wlr_log(WLR_ERROR, "Failed to upload texture"); + wlr_log(WLR_ERROR, "Failed to create texture"); wl_buffer_send_release(resource); return NULL; } - struct wlr_client_buffer *buffer = + struct wlr_client_buffer *client_buffer = calloc(1, sizeof(struct wlr_client_buffer)); - if (buffer == NULL) { + if (client_buffer == NULL) { wlr_texture_destroy(texture); wl_resource_post_no_memory(resource); return NULL; } - wlr_buffer_init(&buffer->base, &client_buffer_impl, + wlr_buffer_init(&client_buffer->base, &client_buffer_impl, texture->width, texture->height); - buffer->resource = resource; - buffer->texture = texture; + client_buffer->resource = resource; + client_buffer->texture = texture; - wl_resource_add_destroy_listener(resource, &buffer->resource_destroy); - buffer->resource_destroy.notify = client_buffer_resource_handle_destroy; + wl_resource_add_destroy_listener(resource, &client_buffer->resource_destroy); + client_buffer->resource_destroy.notify = client_buffer_resource_handle_destroy; // Ensure the buffer will be released before being destroyed - wlr_buffer_lock(&buffer->base); - wlr_buffer_drop(&buffer->base); + wlr_buffer_lock(&client_buffer->base); + wlr_buffer_drop(&client_buffer->base); - return buffer; + return client_buffer; } struct wlr_client_buffer *wlr_client_buffer_apply_damage(