From 628e9bad92673c27a974649ee18c48483003347a Mon Sep 17 00:00:00 2001 From: Ryan Houdek Date: Tue, 26 Jan 2016 07:35:17 -0600 Subject: [PATCH] Support a headless EGL option. This is a new option to support completely headless running of Dolphin without X11 on systems that can properly support it. --- CMakeLists.txt | 12 +++++++++++- Source/Core/Common/GL/GLInterface/EGL.h | 2 +- .../Core/Common/GL/GLInterface/GLInterface.cpp | 4 ++++ Source/Core/DolphinWX/CMakeLists.txt | 2 +- Source/Core/DolphinWX/MainNoGUI.cpp | 16 +++++++++------- 5 files changed, 26 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 47ad618e30..15a9d989db 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,7 @@ option(ENABLE_QT2 "Enable Qt2 (use the other experimental Qt interface)" OFF) option(ENABLE_PCH "Use PCH to speed up compilation" ON) option(ENABLE_LTO "Enables Link Time Optimization" OFF) option(ENABLE_GENERIC "Enables generic build that should run on any little-endian host" OFF) +option(ENABLE_HEADLESS "Enables running Dolphin as a headless variant" OFF) # Enable SDL for default on operating systems that aren't OSX, Android, Linux or Windows. if(NOT APPLE AND NOT ANDROID AND NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Linux" AND NOT MSVC) @@ -380,6 +381,15 @@ if(ANDROID) set(USE_EGL 1) endif() +if(ENABLE_HEADLESS) + message("Enabling Headless! Disabling GUI, force enabling EGL!") + set(USE_X11 0) + set(USE_EGL 1) + set(DISABLE_WX 1) + set(ENABLE_QT2 0) + add_definitions(-DUSE_HEADLESS) +endif() + include_directories(Externals/GL) add_definitions(-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE) @@ -457,7 +467,7 @@ if(NOT ANDROID) set(USE_X11 0) - if(UNIX AND NOT APPLE) + if(UNIX AND NOT APPLE AND NOT ENABLE_HEADLESS) include(FindX11) if(TRY_X11 AND X11_FOUND) set(USE_X11 1) diff --git a/Source/Core/Common/GL/GLInterface/EGL.h b/Source/Core/Common/GL/GLInterface/EGL.h index 570844f954..05f07aea5c 100644 --- a/Source/Core/Common/GL/GLInterface/EGL.h +++ b/Source/Core/Common/GL/GLInterface/EGL.h @@ -27,7 +27,7 @@ protected: EGLContext egl_ctx; EGLDisplay egl_dpy; - virtual EGLDisplay OpenDisplay() { return EGL_NO_DISPLAY; } + virtual EGLDisplay OpenDisplay() { return eglGetDisplay(EGL_DEFAULT_DISPLAY); } virtual EGLNativeWindowType InitializePlatform(EGLNativeWindowType host_window, EGLConfig config) { return (EGLNativeWindowType)EGL_DEFAULT_DISPLAY; } virtual void ShutdownPlatform() {} diff --git a/Source/Core/Common/GL/GLInterface/GLInterface.cpp b/Source/Core/Common/GL/GLInterface/GLInterface.cpp index b9a05fd30a..6d4345e5c1 100644 --- a/Source/Core/Common/GL/GLInterface/GLInterface.cpp +++ b/Source/Core/Common/GL/GLInterface/GLInterface.cpp @@ -18,6 +18,8 @@ #else #include "Common/GL/GLInterface/GLX.h" #endif +#elif defined(USE_EGL) && USE_EGL && defined(USE_HEADLESS) +#include "Common/GL/GLInterface/EGL.h" #else #error Platform doesnt have a GLInterface #endif @@ -30,6 +32,8 @@ std::unique_ptr HostGL_CreateGLInterface() return std::make_unique(); #elif defined(_WIN32) return std::make_unique(); + #elif defined(USE_EGL) && defined(USE_HEADLESS) + return std::make_unique(); #elif defined(HAVE_X11) && HAVE_X11 #if defined(USE_EGL) && USE_EGL return std::make_unique(); diff --git a/Source/Core/DolphinWX/CMakeLists.txt b/Source/Core/DolphinWX/CMakeLists.txt index 6cfd187380..c67834889b 100644 --- a/Source/Core/DolphinWX/CMakeLists.txt +++ b/Source/Core/DolphinWX/CMakeLists.txt @@ -194,7 +194,7 @@ if(wxWidgets_FOUND) set(CPACK_PACKAGE_EXECUTABLES ${CPACK_PACKAGE_EXECUTABLES} ${DOLPHIN_EXE}) endif() -if(USE_X11) +if(USE_X11 OR ENABLE_HEADLESS) set(DOLPHIN_NOGUI_EXE ${DOLPHIN_EXE_BASE}-nogui) add_executable(${DOLPHIN_NOGUI_EXE} ${SRCS} ${NOGUI_SRCS}) target_link_libraries(${DOLPHIN_NOGUI_EXE} ${LIBS}) diff --git a/Source/Core/DolphinWX/MainNoGUI.cpp b/Source/Core/DolphinWX/MainNoGUI.cpp index 70f099deb7..180af3ffe2 100644 --- a/Source/Core/DolphinWX/MainNoGUI.cpp +++ b/Source/Core/DolphinWX/MainNoGUI.cpp @@ -35,11 +35,11 @@ static bool running = true; class Platform { public: - virtual void Init() = 0; - virtual void SetTitle(const std::string &title) = 0; - virtual void MainLoop() = 0; - virtual void Shutdown() = 0; - virtual ~Platform() {}; + virtual void Init() {} + virtual void SetTitle(const std::string &title) {} + virtual void MainLoop() { while(running) {} } + virtual void Shutdown() {} + virtual ~Platform() {} }; static Platform* platform; @@ -54,7 +54,7 @@ void Host_Message(int Id) running = false; } -static void* s_window_handle; +static void* s_window_handle = nullptr; void* Host_GetRenderHandle() { return s_window_handle; @@ -291,7 +291,9 @@ class PlatformX11 : public Platform static Platform* GetPlatform() { -#if HAVE_X11 +#if defined(USE_EGL) && defined(USE_HEADLESS) + return new Platform(); +#elif HAVE_X11 return new PlatformX11(); #endif return nullptr;