mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-26 14:45:58 +01:00
buffer: use wlr_texture_from_buffer for wl_shm_buffer
This commit is contained in:
parent
7c26345826
commit
534615cd55
1 changed files with 17 additions and 15 deletions
|
@ -214,23 +214,25 @@ struct wlr_client_buffer *wlr_client_buffer_import(
|
||||||
struct wlr_texture *texture = NULL;
|
struct wlr_texture *texture = NULL;
|
||||||
bool resource_released = false;
|
bool resource_released = false;
|
||||||
|
|
||||||
struct wl_shm_buffer *shm_buf = wl_shm_buffer_get(resource);
|
if (wl_shm_buffer_get(resource) != NULL) {
|
||||||
if (shm_buf != NULL) {
|
struct wlr_shm_client_buffer *shm_client_buffer =
|
||||||
enum wl_shm_format wl_shm_format = wl_shm_buffer_get_format(shm_buf);
|
shm_client_buffer_create(resource);
|
||||||
uint32_t drm_format = convert_wl_shm_format_to_drm(wl_shm_format);
|
if (shm_client_buffer == NULL) {
|
||||||
int32_t stride = wl_shm_buffer_get_stride(shm_buf);
|
wlr_log(WLR_ERROR, "Failed to create shm client buffer");
|
||||||
int32_t width = wl_shm_buffer_get_width(shm_buf);
|
return NULL;
|
||||||
int32_t height = wl_shm_buffer_get_height(shm_buf);
|
}
|
||||||
|
|
||||||
wl_shm_buffer_begin_access(shm_buf);
|
// Ensure the buffer will be released before being destroyed
|
||||||
void *data = wl_shm_buffer_get_data(shm_buf);
|
wlr_buffer_lock(&shm_client_buffer->base);
|
||||||
texture = wlr_texture_from_pixels(renderer, drm_format, stride,
|
wlr_buffer_drop(&shm_client_buffer->base);
|
||||||
width, height, data);
|
|
||||||
wl_shm_buffer_end_access(shm_buf);
|
|
||||||
|
|
||||||
// We have uploaded the data, we don't need to access the wl_buffer
|
texture = wlr_texture_from_buffer(renderer, &shm_client_buffer->base);
|
||||||
// anymore
|
|
||||||
wl_buffer_send_release(resource);
|
// 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;
|
resource_released = true;
|
||||||
} else if (wlr_renderer_resource_is_wl_drm_buffer(renderer, resource)) {
|
} else if (wlr_renderer_resource_is_wl_drm_buffer(renderer, resource)) {
|
||||||
texture = wlr_texture_from_wl_drm(renderer, resource);
|
texture = wlr_texture_from_wl_drm(renderer, resource);
|
||||||
|
|
Loading…
Reference in a new issue