From e2828babbed0b58e462f06713687565d8b881170 Mon Sep 17 00:00:00 2001 From: Joshua Ashton Date: Mon, 5 Feb 2024 12:05:04 +0000 Subject: [PATCH] build: Make libavif and SDL2 optional --- meson_options.txt | 2 ++ src/main.cpp | 2 ++ src/meson.build | 13 ++++++++++--- src/steamcompmgr.cpp | 5 +++++ 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/meson_options.txt b/meson_options.txt index c2c90b612..1e7754e8e 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1,5 +1,7 @@ option('pipewire', type: 'feature', description: 'Screen capture via PipeWire') option('drm_backend', type: 'feature', description: 'DRM Atomic Backend') +option('sdl2_backend', type: 'feature', description: 'SDL2 Window Backend') +option('avif_screenshots', type: 'feature', description: 'Support for saving .AVIF HDR screenshots') option('enable_gamescope', type : 'boolean', value : true, description: 'Build Gamescope executable') option('enable_gamescope_wsi_layer', type : 'boolean', value : true, description: 'Build Gamescope layer') option('enable_openvr_support', type : 'boolean', value : true, description: 'OpenVR Integrations') diff --git a/src/main.cpp b/src/main.cpp index a2665d112..a37899df9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -783,9 +783,11 @@ int main(int argc, char **argv) gamescope::IBackend::Set(); break; #endif +#if HAVE_SDL2 case gamescope::GamescopeBackend::SDL: gamescope::IBackend::Set(); break; +#endif #if HAVE_OPENVR case gamescope::GamescopeBackend::OpenVR: gamescope::IBackend::Set(); diff --git a/src/meson.build b/src/meson.build index d23176781..4b2a5bcb1 100644 --- a/src/meson.build +++ b/src/meson.build @@ -19,9 +19,9 @@ thread_dep = dependency('threads') cap_dep = dependency('libcap', required: false) epoll_dep = dependency('epoll-shim', required: false) glm_dep = dependency('glm') -sdl_dep = dependency('SDL2') +sdl_dep = dependency('SDL2', required: get_option('sdl2_backend')) stb_dep = dependency('stb') -avif_dep = dependency('libavif', version: '>=1.0.0') +avif_dep = dependency('libavif', version: '>=1.0.0', required: get_option('avif_screenshots')) wlroots_dep = dependency( 'wlroots', @@ -107,6 +107,14 @@ if drm_dep.found() gamescope_cpp_args += '-DHAVE_DRM=@0@'.format(drm_dep.found().to_int()) endif +if sdl_dep.found() + src += 'sdlwindow.cpp' + gamescope_cpp_args += '-DHAVE_SDL2=@0@'.format(sdl_dep.found().to_int()) +endif + +if avif_dep.found() + gamescope_cpp_args += '-DHAVE_AVIF=@0@'.format(avif_dep.found().to_int()) +endif src = [ 'steamcompmgr.cpp', @@ -116,7 +124,6 @@ src = [ 'headless.cpp', 'wlserver.cpp', 'modegen.cpp', - 'sdlwindow.cpp', 'vblankmanager.cpp', 'rendervulkan.cpp', 'log.cpp', diff --git a/src/steamcompmgr.cpp b/src/steamcompmgr.cpp index e3dae6154..a01e91c60 100644 --- a/src/steamcompmgr.cpp +++ b/src/steamcompmgr.cpp @@ -89,7 +89,9 @@ #include "mwm_hints.h" #include "edid.h" +#if HAVE_AVIF #include "avif/avif.h" +#endif static const int g_nBaseCursorScale = 36; @@ -2908,6 +2910,8 @@ paint_all(bool async) } } + assert( HAVE_AVIF ); +#if HAVE_AVIF avifResult avifResult = AVIF_RESULT_OK; avifImage *pAvifImage = avifImageCreate( g_nOutputWidth, g_nOutputHeight, 10, AVIF_PIXEL_FORMAT_YUV444 ); @@ -2976,6 +2980,7 @@ paint_all(bool async) xwm_log.infof( "Screenshot saved to %s", oScreenshotInfo->szScreenshotPath.c_str() ); bScreenshotSuccess = true; +#endif } else if (pScreenshotTexture->format() == VK_FORMAT_B8G8R8A8_UNORM) {