Skip to content
This repository has been archived by the owner on Nov 1, 2021. It is now read-only.

Commit

Permalink
buffer: use wlr_texture_from_buffer for wl_shm_buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
emersion authored and bl4ckb0ne committed Jun 7, 2021
1 parent 7c26345 commit 534615c
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions types/wlr_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 534615c

Please sign in to comment.