From ed1924800de905f5462c8cc6e36fbc60b69d3030 Mon Sep 17 00:00:00 2001 From: ayaka Date: Fri, 9 Apr 2021 10:48:01 +0800 Subject: [PATCH] render: make GLES2 renderer optional Allow selecting whether the GLES2 renderer gets enabled. Co-authored-by: Simon Ser --- examples/meson.build | 12 +++++++++++- include/meson.build | 3 +++ include/wlr/config.h.in | 2 ++ meson.build | 5 +---- meson_options.txt | 1 + render/gles2/meson.build | 9 +++++++++ render/meson.build | 19 +++++++++++++++++-- render/pixman/meson.build | 1 + render/wlr_renderer.c | 18 +++++++++++++++--- 9 files changed, 60 insertions(+), 10 deletions(-) diff --git a/examples/meson.build b/examples/meson.build index 0fee7d92..704c5183 100644 --- a/examples/meson.build +++ b/examples/meson.build @@ -23,6 +23,11 @@ if libavutil.found() and not cc.has_header('libavutil/hwcontext_drm.h', dependen libavutil = disabler() endif +wlr_gles2_renderer = [] +if not features['gles2-renderer'] + wlr_gles2_renderer = disabler() +endif + compositors = { 'simple': { 'src': 'simple.c', @@ -32,18 +37,23 @@ compositors = { }, 'touch': { 'src': ['touch.c', 'cat.c'], + 'dep': [wlr_gles2_renderer], }, 'tablet': { 'src': 'tablet.c', + 'dep': [wlr_gles2_renderer], }, 'rotation': { 'src': ['rotation.c', 'cat.c'], + 'dep': [wlr_gles2_renderer], }, 'multi-pointer': { 'src': 'multi-pointer.c', + 'dep': [wlr_gles2_renderer], }, 'output-layout': { 'src': ['output-layout.c', 'cat.c'], + 'dep': [wlr_gles2_renderer], }, 'fullscreen-shell': { 'src': 'fullscreen-shell.c', @@ -193,7 +203,7 @@ foreach name, info : compositors executable( name, [info.get('src'), extra_src], - dependencies: [wlroots, libdrm], + dependencies: [wlroots, libdrm, info.get('dep', [])], include_directories: [wlr_inc, proto_inc], build_by_default: get_option('examples'), ) diff --git a/include/meson.build b/include/meson.build index 747e5984..90ca8bf3 100644 --- a/include/meson.build +++ b/include/meson.build @@ -9,6 +9,9 @@ if not features.get('xwayland') else subdir('xwayland') endif +if not features.get('gles2-renderer') + exclude_files += ['render/egl.h', 'render/gles2.h'] +endif install_subdir('wlr', install_dir: get_option('includedir'), diff --git a/include/wlr/config.h.in b/include/wlr/config.h.in index ea7bde1a..957609a6 100644 --- a/include/wlr/config.h.in +++ b/include/wlr/config.h.in @@ -3,6 +3,8 @@ #mesondefine WLR_HAS_X11_BACKEND +#mesondefine WLR_HAS_GLES2_RENDERER + #mesondefine WLR_HAS_XWAYLAND #endif diff --git a/meson.build b/meson.build index 560a14ad..4fc4e77f 100644 --- a/meson.build +++ b/meson.build @@ -88,6 +88,7 @@ endif features = { 'x11-backend': false, 'xwayland': false, + 'gles2-renderer': false, } internal_features = { 'xcb-errors': false, @@ -96,8 +97,6 @@ internal_features = { wayland_server = dependency('wayland-server', version: '>=1.19') wayland_client = dependency('wayland-client') wayland_protos = dependency('wayland-protocols', version: '>=1.17') -egl = dependency('egl') -glesv2 = dependency('glesv2') drm = dependency('libdrm', version: '>=2.4.95') gbm = dependency('gbm', version: '>=17.1.0') libinput = dependency('libinput', version: '>=1.14.0') @@ -113,8 +112,6 @@ wlr_deps = [ wayland_server, wayland_client, wayland_protos, - egl, - glesv2, drm, gbm, libinput, diff --git a/meson_options.txt b/meson_options.txt index 37812cf8..a40b06f6 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -3,3 +3,4 @@ option('xwayland', type: 'feature', value: 'auto', yield: true, description: 'En option('x11-backend', type: 'feature', value: 'auto', description: 'Enable X11 backend') option('examples', type: 'boolean', value: true, description: 'Build example applications') option('icon_directory', description: 'Location used to look for cursors (default: ${datadir}/icons)', type: 'string', value: '') +option('renderers', type: 'array', choices: ['auto', 'gles2'], value: ['auto'], description: 'Select built-in renderers') diff --git a/render/gles2/meson.build b/render/gles2/meson.build index d4d62c64..f2cd5fba 100644 --- a/render/gles2/meson.build +++ b/render/gles2/meson.build @@ -1,3 +1,12 @@ +glesv2 = dependency('glesv2', required: 'gles2' in renderers) + +if not (glesv2.found() and egl.found()) + subdir_done() +endif + +features += { 'gles2-renderer': true } +wlr_deps += glesv2 + wlr_files += files( 'pixel_format.c', 'renderer.c', diff --git a/render/meson.build b/render/meson.build index ab0c4424..0a53acdd 100644 --- a/render/meson.build +++ b/render/meson.build @@ -1,7 +1,13 @@ +renderers = get_option('renderers') +if 'auto' in renderers and get_option('auto_features').enabled() + renderers = ['gles2'] +elif 'auto' in renderers and get_option('auto_features').disabled() + renderers = [] +endif + wlr_files += files( 'allocator.c', 'dmabuf.c', - 'egl.c', 'drm_format_set.c', 'gbm_allocator.c', 'pixel_format.c', @@ -11,5 +17,14 @@ wlr_files += files( 'wlr_texture.c', ) -subdir('gles2') +egl = dependency('egl', required: 'gles2' in renderers) +if egl.found() + wlr_deps += egl + wlr_files += files('egl.c') +endif + +if 'gles2' in renderers or 'auto' in renderers + subdir('gles2') +endif + subdir('pixman') diff --git a/render/pixman/meson.build b/render/pixman/meson.build index eb7a0d3a..484cda46 100644 --- a/render/pixman/meson.build +++ b/render/pixman/meson.build @@ -1,4 +1,5 @@ pixman = dependency('pixman-1') + wlr_deps += pixman wlr_files += files( diff --git a/render/wlr_renderer.c b/render/wlr_renderer.c index d520475d..77be3018 100644 --- a/render/wlr_renderer.c +++ b/render/wlr_renderer.c @@ -2,13 +2,19 @@ #include #include #include -#include -#include -#include #include +#include #include #include #include + +#include + +#if WLR_HAS_GLES2_RENDERER +#include +#include +#endif + #include "util/signal.h" #include "render/pixel_format.h" #include "render/wlr_renderer.h" @@ -222,6 +228,7 @@ bool wlr_renderer_init_wl_display(struct wlr_renderer *r, } struct wlr_renderer *wlr_renderer_autocreate_with_drm_fd(int drm_fd) { +#if WLR_HAS_GLES2_RENDERER struct gbm_device *gbm_device = gbm_create_device(drm_fd); if (!gbm_device) { wlr_log(WLR_ERROR, "Failed to create GBM device"); @@ -241,9 +248,14 @@ struct wlr_renderer *wlr_renderer_autocreate_with_drm_fd(int drm_fd) { if (!renderer) { wlr_log(WLR_ERROR, "Failed to create GLES2 renderer"); wlr_egl_destroy(egl); + return NULL; } return renderer; +#endif + + wlr_log(WLR_ERROR, "Failed to initialize any renderer"); + return NULL; } struct wlr_renderer *wlr_renderer_autocreate(struct wlr_backend *backend) {