From 5a701547a45df414b25addac0709f68087117e32 Mon Sep 17 00:00:00 2001 From: Marius Vlad Date: Sat, 16 Nov 2019 20:26:52 +0200 Subject: [PATCH] libweston: Add the ability to determine if a dmabuf is scanout-capable Adds a new callback 'can_scanout_dmabuf' in weston_backend, which can be set by the back-end do determine if the buffer supplied can be imported directly by KMS. This patch adds a wrapper over it, 'weston_compositor_dmabuf_can_scanout' which is called before importing the dmabuf in the GPU if the direct_display dmabuf is being set. If that's true and the check failed, we refuse to create a wl_buffer. This patch avoids importing in the GPU. Signed-off-by: Marius Vlad --- libweston/backend.h | 12 ++++++++++++ libweston/compositor.c | 12 ++++++++++++ libweston/libweston-internal.h | 3 +++ libweston/linux-dmabuf.c | 10 ++++++++++ 4 files changed, 37 insertions(+) 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; -- 2.34.1