From 9fdffba170c84f73795eb13ea9f0841aee285f6a Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Thu, 3 Oct 2024 12:33:38 +0200 Subject: [PATCH] render/allocator: use udmabuf allocator automatically It makes sense to use udmabuf when the backend wants shm, the renderer wants DMA-BUFs, and we don't have a DRM FD because we're running with a software renderer (e.g. llvmpipe or lavapipe). --- render/allocator/allocator.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/render/allocator/allocator.c b/render/allocator/allocator.c index 5e426c3c8..29dc9e72a 100644 --- a/render/allocator/allocator.c +++ b/render/allocator/allocator.c @@ -17,6 +17,10 @@ #include "render/allocator/gbm.h" #endif +#if WLR_HAS_UDMABUF_ALLOCATOR +#include "render/allocator/udmabuf.h" +#endif + void wlr_allocator_init(struct wlr_allocator *alloc, const struct wlr_allocator_interface *impl, uint32_t buffer_caps) { assert(impl && impl->destroy && impl->create_buffer); @@ -146,6 +150,20 @@ struct wlr_allocator *wlr_allocator_autocreate(struct wlr_backend *backend, wlr_log(WLR_DEBUG, "Failed to create drm dumb allocator"); } + uint32_t udmabuf_caps = WLR_BUFFER_CAP_DMABUF | WLR_BUFFER_CAP_SHM; + if ((backend_caps & udmabuf_caps) && (renderer_caps & udmabuf_caps) && + drm_fd < 0) { +#if WLR_HAS_UDMABUF_ALLOCATOR + wlr_log(WLR_DEBUG, "Trying udmabuf allocator"); + if ((alloc = wlr_udmabuf_allocator_create()) != NULL) { + return alloc; + } + wlr_log(WLR_DEBUG, "Failed to create udmabuf allocator"); +#else + wlr_log(WLR_DEBUG, "Skipping udmabuf allocator: disabled at compile-time"); +#endif + } + wlr_log(WLR_ERROR, "Failed to create allocator"); return NULL; }