From e6653bc2397f135fb94b2f72ca275c9a188f7889 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Sun, 19 May 2024 19:09:04 +0200 Subject: [PATCH] (Linux) Added a DEINIT_ON_LAUNCH build flag to support KMS/direct framebuffer access --- CMakeLists.txt | 10 ++++++++++ es-app/src/FileData.cpp | 16 ++++++++++++++++ es-app/src/guis/GuiMenu.cpp | 2 +- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 571b4d274..70cf84406 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,6 +44,7 @@ option(RPI "Set to ON to enable a Raspberry Pi specific build" OFF) option(BUNDLED_CERTS "Set to ON to use bundled TLS/SSL certificates" OFF) option(CEC "Set to ON to enable CEC" OFF) option(VIDEO_HW_DECODING "Set to ON to enable FFmpeg HW decoding" OFF) +option(DEINIT_ON_LAUNCH "Set to ON to deinitialize on game launch" OFF) option(CLANG_TIDY "Set to ON to build using the clang-tidy static analyzer" OFF) option(ASAN "Set to ON to build with AddressSanitizer" OFF) option(TSAN "Set to ON to build with ThreadSanitizer" OFF) @@ -357,6 +358,15 @@ if(VIDEO_HW_DECODING) message("-- Building with FFmpeg HW decoding") endif() +if(DEINIT_ON_LAUNCH) + if(CMAKE_SYSTEM_NAME MATCHES Linux) + add_compile_definitions(DEINIT_ON_LAUNCH) + message("-- Building with deinitialization on game launch") + else() + message(FATAL_ERROR "-- Deinitialization on game launch can only be used on Linux") + endif() +endif() + if(AUR_BUILD OR FLATPAK_BUILD OR RETRODECK OR RPI) set(APPLICATION_UPDATER OFF) endif() diff --git a/es-app/src/FileData.cpp b/es-app/src/FileData.cpp index aba50a3fc..988bf1a20 100644 --- a/es-app/src/FileData.cpp +++ b/es-app/src/FileData.cpp @@ -10,6 +10,7 @@ #include "FileData.h" +#include "AudioManager.h" #include "CollectionSystemsManager.h" #include "FileFilterIndex.h" #include "FileSorts.h" @@ -1895,6 +1896,10 @@ void FileData::launchGame() // Trim any leading and trailing whitespace characters as they could cause launch issues. command = Utils::String::trim(command); +#if defined(DEINIT_ON_LAUNCH) + runInBackground = false; +#endif + // swapBuffers() is called here to turn the screen black to eliminate some potential // flickering and to avoid showing the game launch message briefly when returning // from the game. @@ -1966,7 +1971,18 @@ void FileData::launchGame() androidData, mEnvData->mStartPath, romRaw, androidExtrasString, androidExtrasStringArray, androidExtrasBool, androidActivityFlags); #else + +#if defined(DEINIT_ON_LAUNCH) +// Deinit both the AudioManager and the window which allows emulators to launch in KMS mode. +AudioManager::getInstance().deinit(); +window->deinit(); +returnValue = Utils::Platform::launchGameUnix(command, startDirectory, false); +AudioManager::getInstance().init(); +window->init(); +#else returnValue = Utils::Platform::launchGameUnix(command, startDirectory, runInBackground); +#endif + #endif // Notify the user in case of a failed game launch using a popup window. if (returnValue != 0) { diff --git a/es-app/src/guis/GuiMenu.cpp b/es-app/src/guis/GuiMenu.cpp index 5503f468d..0ef4d627c 100644 --- a/es-app/src/guis/GuiMenu.cpp +++ b/es-app/src/guis/GuiMenu.cpp @@ -1653,7 +1653,7 @@ void GuiMenu::openOtherOptions() }); #endif -#if !defined(__ANDROID__) +#if !defined(__ANDROID__) && !defined(DEINIT_ON_LAUNCH) // Run ES in the background when a game has been launched. auto runInBackground = std::make_shared(); runInBackground->setState(Settings::getInstance()->getBool("RunInBackground"));