diff --git a/README.md b/README.md index 418aab94b..7fbd691a0 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ Install dependencies: * EGL and GLESv2 (optional, for the GLES2 renderer) * Vulkan loader, headers and glslang (optional, for the Vulkan renderer) * libdrm -* GBM +* GBM (optional, for the GBM allocator) * libinput (optional, for the libinput backend) * xkbcommon * udev diff --git a/examples/meson.build b/examples/meson.build index 26d103bbb..51e7d3117 100644 --- a/examples/meson.build +++ b/examples/meson.build @@ -5,6 +5,7 @@ wayland_client = dependency('wayland-client') libpng = dependency('libpng', required: false, disabler: true) egl = dependency('egl', required: false, disabler: true) glesv2 = dependency('glesv2', required: false, disabler: true) +gbm = dependency('gbm', required: false, disabler: true) # These versions correspond to ffmpeg 4.0 libavutil = dependency('libavutil', version: '>=56.14.100', required: false, disabler: true) libavcodec = dependency('libavcodec', version: '>=58.18.100', required: false, disabler: true) diff --git a/include/wlr/config.h.in b/include/wlr/config.h.in index 71868a349..0b612271c 100644 --- a/include/wlr/config.h.in +++ b/include/wlr/config.h.in @@ -6,9 +6,10 @@ #mesondefine WLR_HAS_X11_BACKEND #mesondefine WLR_HAS_GLES2_RENDERER - #mesondefine WLR_HAS_VULKAN_RENDERER +#mesondefine WLR_HAS_GBM_ALLOCATOR + #mesondefine WLR_HAS_XWAYLAND #endif diff --git a/meson.build b/meson.build index 5d45073de..971be7e63 100644 --- a/meson.build +++ b/meson.build @@ -92,6 +92,7 @@ features = { 'xwayland': false, 'gles2-renderer': false, 'vulkan-renderer': false, + 'gbm-allocator': false, } internal_features = { 'xcb-errors': false, @@ -125,7 +126,6 @@ drm = dependency('libdrm', 'valgrind=false', ], ) -gbm = dependency('gbm', version: '>=17.1.0') xkbcommon = dependency('xkbcommon') udev = dependency('libudev') pixman = dependency('pixman-1') @@ -136,7 +136,6 @@ wlr_files = [] wlr_deps = [ wayland_server, drm, - gbm, xkbcommon, udev, pixman, diff --git a/meson_options.txt b/meson_options.txt index 550acbe6f..1a439a4d8 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -4,3 +4,5 @@ option('examples', type: 'boolean', value: true, description: 'Build example app option('icon_directory', description: 'Location used to look for cursors (default: ${datadir}/icons)', type: 'string', value: '') option('renderers', type: 'array', choices: ['auto', 'gles2', 'vulkan'], value: ['auto'], description: 'Select built-in renderers') option('backends', type: 'array', choices: ['auto', 'drm', 'libinput', 'x11'], value: ['auto'], description: 'Select built-in backends') +option('allocators', type: 'array', choices: ['auto', 'gbm'], value: ['auto'], + description: 'Select built-in allocators') diff --git a/render/allocator/allocator.c b/render/allocator/allocator.c index 83e836aee..6b96e0239 100644 --- a/render/allocator/allocator.c +++ b/render/allocator/allocator.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -11,10 +12,13 @@ #include "backend/backend.h" #include "render/allocator/allocator.h" #include "render/allocator/drm_dumb.h" -#include "render/allocator/gbm.h" #include "render/allocator/shm.h" #include "render/wlr_renderer.h" +#if WLR_HAS_GBM_ALLOCATOR +#include "render/allocator/gbm.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); @@ -94,6 +98,8 @@ struct wlr_allocator *allocator_autocreate_with_drm_fd( uint32_t renderer_caps = renderer_get_render_buffer_caps(renderer); struct wlr_allocator *alloc = NULL; + +#if WLR_HAS_GBM_ALLOCATOR uint32_t gbm_caps = WLR_BUFFER_CAP_DMABUF; if ((backend_caps & gbm_caps) && (renderer_caps & gbm_caps) && drm_fd >= 0) { @@ -108,6 +114,7 @@ struct wlr_allocator *allocator_autocreate_with_drm_fd( close(gbm_fd); wlr_log(WLR_DEBUG, "Failed to create gbm allocator"); } +#endif uint32_t shm_caps = WLR_BUFFER_CAP_SHM | WLR_BUFFER_CAP_DATA_PTR; if ((backend_caps & shm_caps) && (renderer_caps & shm_caps)) { diff --git a/render/allocator/meson.build b/render/allocator/meson.build index db17ccb2c..f8e452df9 100644 --- a/render/allocator/meson.build +++ b/render/allocator/meson.build @@ -1,9 +1,25 @@ +allocators = get_option('allocators') +if 'auto' in allocators and get_option('auto_features').enabled() + allocators = ['gbm'] +elif 'auto' in renderers and get_option('auto_features').disabled() + allocators = [] +endif + wlr_files += files( 'allocator.c', - 'gbm.c', 'shm.c', 'drm_dumb.c', ) -has = cc.has_function('gbm_bo_get_fd_for_plane', dependencies: [gbm]) -add_project_arguments('-DHAS_GBM_BO_GET_FD_FOR_PLANE=@0@'.format(has.to_int()), language: 'c') +gbm = disabler() +if 'gbm' in allocators or 'auto' in allocators + gbm = dependency('gbm', version: '>=17.1.0', required: 'gbm' in allocators) +endif +if gbm.found() + wlr_files += files('gbm.c') + wlr_deps += gbm + features += { 'gbm-allocator': true } + + has = cc.has_function('gbm_bo_get_fd_for_plane', dependencies: [gbm]) + add_project_arguments('-DHAS_GBM_BO_GET_FD_FOR_PLANE=@0@'.format(has.to_int()), language: 'c') +endif diff --git a/render/gles2/renderer.c b/render/gles2/renderer.c index 5ffd6f85f..e7bfe0e00 100644 --- a/render/gles2/renderer.c +++ b/render/gles2/renderer.c @@ -1,6 +1,5 @@ #include #include -#include #include #include #include diff --git a/render/meson.build b/render/meson.build index a1289edee..2bdcced8f 100644 --- a/render/meson.build +++ b/render/meson.build @@ -16,8 +16,9 @@ wlr_files += files( if 'gles2' in renderers or 'auto' in renderers egl = dependency('egl', required: 'gles2' in renderers) - if egl.found() - wlr_deps += egl + gbm = dependency('gbm', required: 'gles2' in renderers) + if egl.found() and gbm.found() + wlr_deps += [egl, gbm] wlr_files += files('egl.c') endif subdir('gles2')