mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2025-11-13 13:29:44 -05:00
types/wlr_buffer: split wlr_client_buffer_import function
`wlr_client_buffer_import` is splitted in two distincts function: - wlr_buffer_from_resource, which transforms a wl_resource into a wlr_buffer - wlr_client_buffer_create, which creates a wlr_client_buffer from a wlr_buffer by creating a texture from it and copying its wl_resource
This commit is contained in:
parent
f67cfb2ce2
commit
6d8029b07e
3 changed files with 27 additions and 23 deletions
|
|
@ -194,9 +194,9 @@ static void client_buffer_resource_handle_destroy(struct wl_listener *listener,
|
|||
// which case we'll read garbage. We decide to accept this risk.
|
||||
}
|
||||
|
||||
struct wlr_client_buffer *wlr_client_buffer_import(
|
||||
struct wlr_renderer *renderer, struct wl_resource *resource) {
|
||||
assert(wlr_resource_is_buffer(resource));
|
||||
struct wlr_buffer *wlr_buffer_from_resource(struct wlr_renderer *renderer,
|
||||
struct wl_resource *resource) {
|
||||
assert(resource && wlr_resource_is_buffer(resource));
|
||||
|
||||
struct wlr_buffer *buffer;
|
||||
if (wl_shm_buffer_get(resource) != NULL) {
|
||||
|
|
@ -219,16 +219,16 @@ struct wlr_client_buffer *wlr_client_buffer_import(
|
|||
wlr_drm_buffer_from_resource(resource);
|
||||
buffer = wlr_buffer_lock(&drm_buffer->base);
|
||||
} else {
|
||||
wlr_log(WLR_ERROR, "Cannot upload texture: unknown buffer type");
|
||||
|
||||
// Instead of just logging the error, also disconnect the client with a
|
||||
// fatal protocol error so that it's clear something went wrong.
|
||||
wl_resource_post_error(resource, 0, "unknown buffer type");
|
||||
wlr_log(WLR_ERROR, "Unknown buffer type");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
struct wlr_client_buffer *wlr_client_buffer_create(struct wlr_buffer *buffer,
|
||||
struct wlr_renderer *renderer, struct wl_resource *resource) {
|
||||
struct wlr_texture *texture = wlr_texture_from_buffer(renderer, buffer);
|
||||
wlr_buffer_unlock(buffer);
|
||||
if (texture == NULL) {
|
||||
wlr_log(WLR_ERROR, "Failed to create texture");
|
||||
wl_buffer_send_release(resource);
|
||||
|
|
@ -308,10 +308,6 @@ struct wlr_client_buffer *wlr_client_buffer_apply_damage(
|
|||
|
||||
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);
|
||||
|
||||
wl_list_remove(&buffer->resource_destroy.link);
|
||||
wl_resource_add_destroy_listener(resource, &buffer->resource_destroy);
|
||||
buffer->resource_destroy.notify = client_buffer_resource_handle_destroy;
|
||||
|
|
|
|||
|
|
@ -365,12 +365,13 @@ static void surface_apply_damage(struct wlr_surface *surface) {
|
|||
}
|
||||
}
|
||||
|
||||
struct wlr_client_buffer *buffer =
|
||||
wlr_client_buffer_import(surface->renderer, resource);
|
||||
struct wlr_client_buffer *buffer = wlr_client_buffer_create(
|
||||
surface->current.buffer, surface->renderer, resource);
|
||||
if (buffer == NULL) {
|
||||
wlr_log(WLR_ERROR, "Failed to upload buffer");
|
||||
return;
|
||||
}
|
||||
wlr_buffer_unlock(surface->current.buffer);
|
||||
|
||||
if (surface->buffer != NULL) {
|
||||
wlr_buffer_unlock(&surface->buffer->base);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue