mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2026-04-14 08:22:25 -04:00
Merge branch 'gbm-flags' into 'master'
Draft: render/allocator/gbm: add bo_flags arg to create function See merge request wlroots/wlroots!4472
This commit is contained in:
commit
ef3cf54af4
4 changed files with 22 additions and 7 deletions
|
|
@ -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(int drm_fd);
|
||||
struct wlr_allocator *wlr_gbm_allocator_create_with_drm_fd(int drm_fd, uint32_t bo_flags);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
#include "render/wlr_renderer.h"
|
||||
|
||||
#if WLR_HAS_GBM_ALLOCATOR
|
||||
#include <gbm.h>
|
||||
#include "render/allocator/gbm.h"
|
||||
#endif
|
||||
|
||||
|
|
@ -107,7 +108,8 @@ struct wlr_allocator *allocator_autocreate_with_drm_fd(
|
|||
if (gbm_fd < 0) {
|
||||
return NULL;
|
||||
}
|
||||
if ((alloc = wlr_gbm_allocator_create(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);
|
||||
|
|
|
|||
|
|
@ -96,20 +96,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 = alloc->bo_flags;
|
||||
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) {
|
||||
|
|
@ -185,7 +191,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, uint32_t bo_flags) {
|
||||
uint64_t cap;
|
||||
if (drmGetCap(fd, DRM_CAP_PRIME, &cap) ||
|
||||
!(cap & DRM_PRIME_CAP_EXPORT)) {
|
||||
|
|
@ -200,6 +206,7 @@ struct wlr_allocator *wlr_gbm_allocator_create(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);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue