aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Ser <contact@emersion.fr>2021-04-14 20:38:17 +0200
committerSimon Zeni <simon@bl4ckb0ne.ca>2021-06-07 09:22:56 -0400
commit534615cd557567571eaef8b4edf4818c52ee1da7 (patch)
tree5f419beb614fce7312f83305e1f2606824d89224
parent7c263458268bc0013f243c589a9ced125d225db4 (diff)
buffer: use wlr_texture_from_buffer for wl_shm_buffer
-rw-r--r--types/wlr_buffer.c36
1 files changed, 19 insertions, 17 deletions
diff --git a/types/wlr_buffer.c b/types/wlr_buffer.c
index 40d5ae34..147205b9 100644
--- a/types/wlr_buffer.c
+++ b/types/wlr_buffer.c
@@ -214,23 +214,25 @@ struct wlr_client_buffer *wlr_client_buffer_import(
struct wlr_texture *texture = NULL;
bool resource_released = false;
- struct wl_shm_buffer *shm_buf = wl_shm_buffer_get(resource);
- if (shm_buf != NULL) {
- enum wl_shm_format wl_shm_format = wl_shm_buffer_get_format(shm_buf);
- uint32_t drm_format = convert_wl_shm_format_to_drm(wl_shm_format);
- int32_t stride = wl_shm_buffer_get_stride(shm_buf);
- int32_t width = wl_shm_buffer_get_width(shm_buf);
- int32_t height = wl_shm_buffer_get_height(shm_buf);
-
- wl_shm_buffer_begin_access(shm_buf);
- void *data = wl_shm_buffer_get_data(shm_buf);
- texture = wlr_texture_from_pixels(renderer, drm_format, stride,
- width, height, data);
- wl_shm_buffer_end_access(shm_buf);
-
- // We have uploaded the data, we don't need to access the wl_buffer
- // anymore
- wl_buffer_send_release(resource);
+ if (wl_shm_buffer_get(resource) != NULL) {
+ struct wlr_shm_client_buffer *shm_client_buffer =
+ shm_client_buffer_create(resource);
+ if (shm_client_buffer == NULL) {
+ wlr_log(WLR_ERROR, "Failed to create shm client buffer");
+ return NULL;
+ }
+
+ // Ensure the buffer will be released before being destroyed
+ 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);
+
+ // The renderer is responsible for releasing the buffer when
+ // appropriate
resource_released = true;
} else if (wlr_renderer_resource_is_wl_drm_buffer(renderer, resource)) {
texture = wlr_texture_from_wl_drm(renderer, resource);