diff --git a/libweston/backend.h b/libweston/backend.h index baf67073..ff10b363 100644 --- a/libweston/backend.h +++ b/libweston/backend.h @@ -95,6 +95,18 @@ struct weston_backend { */ void (*device_changed)(struct weston_compositor *compositor, dev_t device, bool added); + + /** Verifies if the dmabuf can be used directly/scanned-out by the HW. + * + * @param compositor The compositor. + * @param buffer The dmabuf to verify. + * + * Determines if the buffer can be imported directly by the display + * controller/HW. Back-ends can use this to check if the supplied + * buffer can be scanned-out, as to void importing it into the GPU. + */ + bool (*can_scanout_dmabuf)(struct weston_compositor *compositor, + struct linux_dmabuf_buffer *buffer); }; /* weston_head */ diff --git a/libweston/compositor.c b/libweston/compositor.c index 55f43af4..3531a213 100644 --- a/libweston/compositor.c +++ b/libweston/compositor.c @@ -7519,6 +7519,18 @@ weston_compositor_import_dmabuf(struct weston_compositor *compositor, return renderer->import_dmabuf(compositor, buffer); } +WL_EXPORT bool +weston_compositor_dmabuf_can_scanout(struct weston_compositor *compositor, + struct linux_dmabuf_buffer *buffer) +{ + struct weston_backend *backend = compositor->backend; + + if (backend->can_scanout_dmabuf == NULL) + return false; + + return backend->can_scanout_dmabuf(compositor, buffer); +} + WL_EXPORT void weston_version(int *major, int *minor, int *micro) { diff --git a/libweston/libweston-internal.h b/libweston/libweston-internal.h index 2099f3bc..66c38e86 100644 --- a/libweston/libweston-internal.h +++ b/libweston/libweston-internal.h @@ -79,6 +79,9 @@ weston_compositor_add_pending_output(struct weston_output *output, bool weston_compositor_import_dmabuf(struct weston_compositor *compositor, struct linux_dmabuf_buffer *buffer); +bool +weston_compositor_dmabuf_can_scanout(struct weston_compositor *compositor, + struct linux_dmabuf_buffer *buffer); void weston_compositor_offscreen(struct weston_compositor *compositor); diff --git a/libweston/linux-dmabuf.c b/libweston/linux-dmabuf.c index 48b16e16..796e9826 100644 --- a/libweston/linux-dmabuf.c +++ b/libweston/linux-dmabuf.c @@ -259,9 +259,18 @@ params_create_common(struct wl_client *client, } } + if (buffer->direct_display) { + if (!weston_compositor_dmabuf_can_scanout(buffer->compositor, + buffer)) + goto err_failed; + + goto avoid_gpu_import; + } + if (!weston_compositor_import_dmabuf(buffer->compositor, buffer)) goto err_failed; +avoid_gpu_import: buffer->buffer_resource = wl_resource_create(client, &wl_buffer_interface, 1, buffer_id); @@ -368,6 +377,7 @@ linux_dmabuf_create_params(struct wl_client *client, wl_resource_create(client, &zwp_linux_buffer_params_v1_interface, version, params_id); + buffer->direct_display = false; if (!buffer->params_resource) goto err_dealloc;