From b992930ebe0c7e59a09cba831cfd9041b3f9dbb4 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Thu, 30 Nov 2023 20:22:41 +0100 Subject: [PATCH 1/3] render/allocator/gbm: use gbm_bo_create_with_modifiers2() if available The flags are not really used now but will be exposed soon. --- render/allocator/gbm.c | 14 ++++++++++---- render/allocator/meson.build | 3 +++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/render/allocator/gbm.c b/render/allocator/gbm.c index 25ddbbae4..2ce7b2fd2 100644 --- a/render/allocator/gbm.c +++ b/render/allocator/gbm.c @@ -97,20 +97,26 @@ static struct wlr_gbm_buffer *create_buffer(struct wlr_gbm_allocator *alloc, bool has_modifier = true; uint64_t fallback_modifier = DRM_FORMAT_MOD_INVALID; - struct gbm_bo *bo = gbm_bo_create_with_modifiers(gbm_device, width, height, + uint32_t flags = GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING; + struct gbm_bo *bo; +#if HAVE_GBM_BO_CREATE_WITH_MODIFIERS2 + bo = gbm_bo_create_with_modifiers2(gbm_device, width, height, + format->format, format->modifiers, format->len, flags); +#else + bo = gbm_bo_create_with_modifiers(gbm_device, width, height, format->format, format->modifiers, format->len); +#endif if (bo == NULL) { - uint32_t usage = GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING; if (format->len == 1 && format->modifiers[0] == DRM_FORMAT_MOD_LINEAR) { - usage |= GBM_BO_USE_LINEAR; + flags |= GBM_BO_USE_LINEAR; fallback_modifier = DRM_FORMAT_MOD_LINEAR; } else if (!wlr_drm_format_has(format, DRM_FORMAT_MOD_INVALID)) { // If the format doesn't accept an implicit modifier, bail out. wlr_log(WLR_ERROR, "gbm_bo_create_with_modifiers failed"); return NULL; } - bo = gbm_bo_create(gbm_device, width, height, format->format, usage); + bo = gbm_bo_create(gbm_device, width, height, format->format, flags); has_modifier = false; } if (bo == NULL) { diff --git a/render/allocator/meson.build b/render/allocator/meson.build index 730a2a41b..a23941b97 100644 --- a/render/allocator/meson.build +++ b/render/allocator/meson.build @@ -22,4 +22,7 @@ if gbm.found() has = cc.has_function('gbm_bo_get_fd_for_plane', dependencies: [gbm]) internal_config.set10('HAVE_GBM_BO_GET_FD_FOR_PLANE', has) + + has = cc.has_function('gbm_bo_create_with_modifiers2', dependencies: [gbm]) + internal_config.set10('HAVE_GBM_BO_CREATE_WITH_MODIFIERS2', has) endif From bf757065553959948f49815c2ed2958ccd109260 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Thu, 30 Nov 2023 21:07:48 +0100 Subject: [PATCH 2/3] render/allocator/gbm: add _with_drm_fd to create function name Reserve wlr_gbm_allocator_create() for a potential future function which takes an already-existing gbm_device as input. --- include/render/allocator/gbm.h | 2 +- render/allocator/allocator.c | 2 +- render/allocator/gbm.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/render/allocator/gbm.h b/include/render/allocator/gbm.h index 7e043faf5..ea3e3243b 100644 --- a/include/render/allocator/gbm.h +++ b/include/render/allocator/gbm.h @@ -29,6 +29,6 @@ struct wlr_gbm_allocator { * * Takes ownership over the FD. */ -struct wlr_allocator *wlr_gbm_allocator_create(int drm_fd); +struct wlr_allocator *wlr_gbm_allocator_create_with_drm_fd(int drm_fd); #endif diff --git a/render/allocator/allocator.c b/render/allocator/allocator.c index f71902f27..ff31fb7e8 100644 --- a/render/allocator/allocator.c +++ b/render/allocator/allocator.c @@ -109,7 +109,7 @@ struct wlr_allocator *allocator_autocreate_with_drm_fd( if (gbm_fd < 0) { return NULL; } - if ((alloc = wlr_gbm_allocator_create(gbm_fd)) != NULL) { + if ((alloc = wlr_gbm_allocator_create_with_drm_fd(gbm_fd)) != NULL) { return alloc; } close(gbm_fd); diff --git a/render/allocator/gbm.c b/render/allocator/gbm.c index 2ce7b2fd2..9c9dc75c6 100644 --- a/render/allocator/gbm.c +++ b/render/allocator/gbm.c @@ -192,7 +192,7 @@ static struct wlr_gbm_allocator *get_gbm_alloc_from_alloc( return alloc; } -struct wlr_allocator *wlr_gbm_allocator_create(int fd) { +struct wlr_allocator *wlr_gbm_allocator_create_with_drm_fd(int fd) { uint64_t cap; if (drmGetCap(fd, DRM_CAP_PRIME, &cap) || !(cap & DRM_PRIME_CAP_EXPORT)) { From a245201dad3a2c0221837015fb260d2aa01c4eb8 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Thu, 30 Nov 2023 21:10:31 +0100 Subject: [PATCH 3/3] render/allocator/gbm: add bo_flags arg to create function This allows callers to opt out of SCANOUT, for instance. --- include/render/allocator/gbm.h | 5 ++++- render/allocator/allocator.c | 4 +++- render/allocator/gbm.c | 5 +++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/include/render/allocator/gbm.h b/include/render/allocator/gbm.h index ea3e3243b..05c05dd3b 100644 --- a/include/render/allocator/gbm.h +++ b/include/render/allocator/gbm.h @@ -20,6 +20,7 @@ struct wlr_gbm_allocator { int fd; struct gbm_device *gbm_device; + uint32_t bo_flags; struct wl_list buffers; // wlr_gbm_buffer.link }; @@ -27,8 +28,10 @@ struct wlr_gbm_allocator { /** * Creates a new GBM allocator from a DRM FD. * + * bo_flags is a bitfield of enum gbm_bo_flags. + * * Takes ownership over the FD. */ -struct wlr_allocator *wlr_gbm_allocator_create_with_drm_fd(int drm_fd); +struct wlr_allocator *wlr_gbm_allocator_create_with_drm_fd(int drm_fd, uint32_t bo_flags); #endif diff --git a/render/allocator/allocator.c b/render/allocator/allocator.c index ff31fb7e8..092db3296 100644 --- a/render/allocator/allocator.c +++ b/render/allocator/allocator.c @@ -16,6 +16,7 @@ #include "render/wlr_renderer.h" #if WLR_HAS_GBM_ALLOCATOR +#include #include "render/allocator/gbm.h" #endif @@ -109,7 +110,8 @@ struct wlr_allocator *allocator_autocreate_with_drm_fd( if (gbm_fd < 0) { return NULL; } - if ((alloc = wlr_gbm_allocator_create_with_drm_fd(gbm_fd)) != NULL) { + uint32_t bo_flags = GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING; + if ((alloc = wlr_gbm_allocator_create_with_drm_fd(gbm_fd, bo_flags)) != NULL) { return alloc; } close(gbm_fd); diff --git a/render/allocator/gbm.c b/render/allocator/gbm.c index 9c9dc75c6..51b87e9ae 100644 --- a/render/allocator/gbm.c +++ b/render/allocator/gbm.c @@ -97,7 +97,7 @@ static struct wlr_gbm_buffer *create_buffer(struct wlr_gbm_allocator *alloc, bool has_modifier = true; uint64_t fallback_modifier = DRM_FORMAT_MOD_INVALID; - uint32_t flags = GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING; + uint32_t flags = alloc->bo_flags; struct gbm_bo *bo; #if HAVE_GBM_BO_CREATE_WITH_MODIFIERS2 bo = gbm_bo_create_with_modifiers2(gbm_device, width, height, @@ -192,7 +192,7 @@ static struct wlr_gbm_allocator *get_gbm_alloc_from_alloc( return alloc; } -struct wlr_allocator *wlr_gbm_allocator_create_with_drm_fd(int fd) { +struct wlr_allocator *wlr_gbm_allocator_create_with_drm_fd(int fd, uint32_t bo_flags) { uint64_t cap; if (drmGetCap(fd, DRM_CAP_PRIME, &cap) || !(cap & DRM_PRIME_CAP_EXPORT)) { @@ -207,6 +207,7 @@ struct wlr_allocator *wlr_gbm_allocator_create_with_drm_fd(int fd) { wlr_allocator_init(&alloc->base, &allocator_impl, WLR_BUFFER_CAP_DMABUF); alloc->fd = fd; + alloc->bo_flags = bo_flags; wl_list_init(&alloc->buffers); alloc->gbm_device = gbm_create_device(fd);