mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2026-04-21 06:46:46 -04:00
wlr_linux_dmabuf: Refactor to prevent double dmabuf import
Instead, we'll initialize the buffer just enough so that renderers can work with it and if the dmabuf import was successful, we continue initializing the buffer. This will allow the dmabuf texture to addon itself onto the buffer for further use without another import.
This commit is contained in:
parent
248a33a026
commit
e594a59036
1 changed files with 13 additions and 15 deletions
|
|
@ -201,17 +201,15 @@ static void buffer_handle_resource_destroy(struct wl_resource *buffer_resource)
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool check_import_dmabuf(struct wlr_linux_dmabuf_v1 *linux_dmabuf,
|
static bool check_import_dmabuf(struct wlr_linux_dmabuf_v1 *linux_dmabuf,
|
||||||
struct wlr_dmabuf_attributes *attribs) {
|
struct wlr_buffer *dmabuf) {
|
||||||
struct wlr_texture *texture =
|
struct wlr_raster *raster = wlr_raster_create(dmabuf);
|
||||||
wlr_texture_from_dmabuf(linux_dmabuf->renderer, attribs);
|
if (!raster) {
|
||||||
if (texture == NULL) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We can import the image, good. No need to keep it since wlr_surface will
|
bool success = wlr_renderer_raster_upload(linux_dmabuf->renderer, raster);
|
||||||
// import it again on commit.
|
wlr_raster_unlock(raster);
|
||||||
wlr_texture_destroy(texture);
|
return success;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void params_create_common(struct wl_resource *params_resource,
|
static void params_create_common(struct wl_resource *params_resource,
|
||||||
|
|
@ -331,17 +329,19 @@ static void params_create_common(struct wl_resource *params_resource,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check if dmabuf is usable */
|
|
||||||
if (!check_import_dmabuf(linux_dmabuf, &attribs)) {
|
|
||||||
goto err_failed;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct wlr_dmabuf_v1_buffer *buffer = calloc(1, sizeof(*buffer));
|
struct wlr_dmabuf_v1_buffer *buffer = calloc(1, sizeof(*buffer));
|
||||||
if (!buffer) {
|
if (!buffer) {
|
||||||
wl_resource_post_no_memory(params_resource);
|
wl_resource_post_no_memory(params_resource);
|
||||||
goto err_failed;
|
goto err_failed;
|
||||||
}
|
}
|
||||||
wlr_buffer_init(&buffer->base, &buffer_impl, attribs.width, attribs.height);
|
wlr_buffer_init(&buffer->base, &buffer_impl, attribs.width, attribs.height);
|
||||||
|
buffer->attributes = attribs;
|
||||||
|
|
||||||
|
/* Check if dmabuf is usable */
|
||||||
|
if (!check_import_dmabuf(linux_dmabuf, &buffer->base)) {
|
||||||
|
free(buffer);
|
||||||
|
goto err_failed;
|
||||||
|
}
|
||||||
|
|
||||||
struct wl_client *client = wl_resource_get_client(params_resource);
|
struct wl_client *client = wl_resource_get_client(params_resource);
|
||||||
buffer->resource = wl_resource_create(client, &wl_buffer_interface,
|
buffer->resource = wl_resource_create(client, &wl_buffer_interface,
|
||||||
|
|
@ -354,8 +354,6 @@ static void params_create_common(struct wl_resource *params_resource,
|
||||||
wl_resource_set_implementation(buffer->resource,
|
wl_resource_set_implementation(buffer->resource,
|
||||||
&wl_buffer_impl, buffer, buffer_handle_resource_destroy);
|
&wl_buffer_impl, buffer, buffer_handle_resource_destroy);
|
||||||
|
|
||||||
buffer->attributes = attribs;
|
|
||||||
|
|
||||||
buffer->release.notify = buffer_handle_release;
|
buffer->release.notify = buffer_handle_release;
|
||||||
wl_signal_add(&buffer->base.events.release, &buffer->release);
|
wl_signal_add(&buffer->base.events.release, &buffer->release);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue