From 271efb450c71c872658a424cd633c20a3174e3a0 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Sat, 9 Aug 2014 10:31:27 -0400 Subject: [PATCH] Add back X11 support to EGL Refactor the EGL backend to provide a platform separation here, which is better abstracted away than the old EGL/X11 implementation. --- Source/Core/DolphinWX/CMakeLists.txt | 22 +++++++----- Source/Core/DolphinWX/GLInterface/EGL.cpp | 14 +++----- Source/Core/DolphinWX/GLInterface/EGL.h | 6 +++- .../Core/DolphinWX/GLInterface/EGLAndroid.cpp | 29 ++++++++++++++++ .../Core/DolphinWX/GLInterface/EGLAndroid.h | 15 ++++++++ Source/Core/DolphinWX/GLInterface/EGLX11.cpp | 34 +++++++++++++++++++ Source/Core/DolphinWX/GLInterface/EGLX11.h | 21 ++++++++++++ .../DolphinWX/GLInterface/GLInterface.cpp | 16 ++++++--- 8 files changed, 134 insertions(+), 23 deletions(-) create mode 100644 Source/Core/DolphinWX/GLInterface/EGLAndroid.cpp create mode 100644 Source/Core/DolphinWX/GLInterface/EGLAndroid.h create mode 100644 Source/Core/DolphinWX/GLInterface/EGLX11.cpp create mode 100644 Source/Core/DolphinWX/GLInterface/EGLX11.h diff --git a/Source/Core/DolphinWX/CMakeLists.txt b/Source/Core/DolphinWX/CMakeLists.txt index 65013d0d8c..ebe9940c3d 100644 --- a/Source/Core/DolphinWX/CMakeLists.txt +++ b/Source/Core/DolphinWX/CMakeLists.txt @@ -74,16 +74,22 @@ set(ANDROID_SRCS Android/ButtonManager.cpp if(USE_EGL) set(SRCS ${SRCS} GLInterface/EGL.cpp) -else() - if(WIN32) - set(SRCS ${SRCS} GLInterface/WGL.cpp) - elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") - set(SRCS ${SRCS} GLInterface/AGL.cpp) - else() - set(SRCS ${SRCS} GLInterface/GLX.cpp - GLInterface/X11_Util.cpp) + if(ANDROID) + set(SRCS ${SRCS} GLInterface/EGLAndroid.cpp) + elseif(USE_X11) + set(SRCS ${SRCS} GLInterface/EGLX11.cpp) endif() endif() + +if(WIN32) + set(SRCS ${SRCS} GLInterface/WGL.cpp) +elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + set(SRCS ${SRCS} GLInterface/AGL.cpp) +elseif(USE_X11) + set(SRCS ${SRCS} GLInterface/GLX.cpp + GLInterface/X11_Util.cpp) +endif() + set(SRCS ${SRCS} GLInterface/GLInterface.cpp) set(NOGUI_SRCS MainNoGUI.cpp) diff --git a/Source/Core/DolphinWX/GLInterface/EGL.cpp b/Source/Core/DolphinWX/GLInterface/EGL.cpp index f5f93eec99..c65759f736 100644 --- a/Source/Core/DolphinWX/GLInterface/EGL.cpp +++ b/Source/Core/DolphinWX/GLInterface/EGL.cpp @@ -2,7 +2,6 @@ // Licensed under GPLv2 // Refer to the license.txt file included. -#include "Core/Host.h" #include "DolphinWX/GLInterface/EGL.h" #include "VideoBackends/OGL/GLInterfaceBase.h" #include "VideoCommon/RenderBase.h" @@ -90,7 +89,7 @@ bool cInterfaceEGL::Create(void *window_handle) const char *s; EGLint egl_major, egl_minor; - egl_dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY); + egl_dpy = OpenDisplay(); if (!egl_dpy) { @@ -154,14 +153,8 @@ bool cInterfaceEGL::Create(void *window_handle) else eglBindAPI(EGL_OPENGL_ES_API); - EGLNativeWindowType native_window = (EGLNativeWindowType) window_handle; - - EGLint format; - eglGetConfigAttrib(egl_dpy, config, EGL_NATIVE_VISUAL_ID, &format); - ANativeWindow_setBuffersGeometry(native_window, 0, 0, format); - int none, width, height; - Host_GetRenderWindowSize(none, none, width, height); - GLInterface->SetBackBufferDimensions(width, height); + EGLNativeWindowType host_window = (EGLNativeWindowType) window_handle; + EGLNativeWindowType native_window = InitializePlatform(host_window, config); s = eglQueryString(egl_dpy, EGL_VERSION); INFO_LOG(VIDEO, "EGL_VERSION = %s\n", s); @@ -199,6 +192,7 @@ bool cInterfaceEGL::MakeCurrent() // Close backend void cInterfaceEGL::Shutdown() { + ShutdownPlatform(); if (egl_ctx && !eglMakeCurrent(egl_dpy, egl_surf, egl_surf, egl_ctx)) NOTICE_LOG(VIDEO, "Could not release drawing context."); if (egl_ctx) diff --git a/Source/Core/DolphinWX/GLInterface/EGL.h b/Source/Core/DolphinWX/GLInterface/EGL.h index 5b48b0b272..1ed8ab59a0 100644 --- a/Source/Core/DolphinWX/GLInterface/EGL.h +++ b/Source/Core/DolphinWX/GLInterface/EGL.h @@ -12,11 +12,15 @@ class cInterfaceEGL : public cInterfaceBase { -private: +protected: void DetectMode(); EGLSurface egl_surf; EGLContext egl_ctx; EGLDisplay egl_dpy; + + virtual EGLDisplay OpenDisplay() = 0; + virtual EGLNativeWindowType InitializePlatform(EGLNativeWindowType host_window, EGLConfig config) = 0; + virtual void ShutdownPlatform() = 0; public: void SwapInterval(int Interval); void Swap(); diff --git a/Source/Core/DolphinWX/GLInterface/EGLAndroid.cpp b/Source/Core/DolphinWX/GLInterface/EGLAndroid.cpp new file mode 100644 index 0000000000..f4989f6da4 --- /dev/null +++ b/Source/Core/DolphinWX/GLInterface/EGLAndroid.cpp @@ -0,0 +1,29 @@ +// Copyright 2014 Dolphin Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. + +#include "Core/Host.h" +#include "DolphinWX/GLInterface/EGLAndroid.h" + +EGLDisplay cInterfaceEGLAndroid::OpenDisplay() +{ + return eglGetDisplay(EGL_DEFAULT_DISPLAY); +} + +EGLNativeWindowType cInterfaceEGLAndroid::InitializePlatform(EGLNativeWindowType host_window, EGLConfig config) +{ + EGLint format; + eglGetConfigAttrib(egl_dpy, config, EGL_NATIVE_VISUAL_ID, &format); + ANativeWindow_setBuffersGeometry(host_window, 0, 0, format); + + int none, width, height; + Host_GetRenderWindowSize(none, none, width, height); + GLInterface->SetBackBufferDimensions(width, height); + + return host_window; +} + +void cInterfaceEGLAndroid::ShutdownPlatform() +{ +} + diff --git a/Source/Core/DolphinWX/GLInterface/EGLAndroid.h b/Source/Core/DolphinWX/GLInterface/EGLAndroid.h new file mode 100644 index 0000000000..e79a5a5ec8 --- /dev/null +++ b/Source/Core/DolphinWX/GLInterface/EGLAndroid.h @@ -0,0 +1,15 @@ +// Copyright 2014 Dolphin Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. + +#pragma once + +#include "DolphinWX/GLInterface/EGL.h" + +class cInterfaceEGLAndroid : public cInterfaceEGL +{ +protected: + EGLDisplay OpenDisplay() override; + EGLNativeWindowType InitializePlatform(EGLNativeWindowType host_window, EGLConfig config) override; + void ShutdownPlatform() override; +}; diff --git a/Source/Core/DolphinWX/GLInterface/EGLX11.cpp b/Source/Core/DolphinWX/GLInterface/EGLX11.cpp new file mode 100644 index 0000000000..f8f686f147 --- /dev/null +++ b/Source/Core/DolphinWX/GLInterface/EGLX11.cpp @@ -0,0 +1,34 @@ +// Copyright 2014 Dolphin Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. + +#include "DolphinWX/GLInterface/EGLX11.h" + +EGLDisplay cInterfaceEGLX11::OpenDisplay() +{ + dpy = XOpenDisplay(nullptr); + XWindow.Initialize(dpy); + return eglGetDisplay(dpy); +} + +EGLNativeWindowType cInterfaceEGLX11::InitializePlatform(EGLNativeWindowType host_window, EGLConfig config) +{ + EGLint vid; + eglGetConfigAttrib(egl_dpy, config, EGL_NATIVE_VISUAL_ID, &vid); + + XVisualInfo visTemplate; + visTemplate.visualid = vid; + + XVisualInfo *vi; + int nVisuals; + vi = XGetVisualInfo(dpy, VisualIDMask, &visTemplate, &nVisuals); + + return (EGLNativeWindowType) XWindow.CreateXWindow((Window) host_window, vi); +} + +void cInterfaceEGLX11::ShutdownPlatform() +{ + XWindow.DestroyXWindow(); + XCloseDisplay(dpy); +} + diff --git a/Source/Core/DolphinWX/GLInterface/EGLX11.h b/Source/Core/DolphinWX/GLInterface/EGLX11.h new file mode 100644 index 0000000000..be897d6b3a --- /dev/null +++ b/Source/Core/DolphinWX/GLInterface/EGLX11.h @@ -0,0 +1,21 @@ +// Copyright 2014 Dolphin Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. + +#pragma once + +#include + +#include "DolphinWX/GLInterface/EGL.h" +#include "DolphinWX/GLInterface/X11_Util.h" + +class cInterfaceEGLX11 : public cInterfaceEGL +{ +private: + cX11Window XWindow; + Display *dpy; +protected: + EGLDisplay OpenDisplay() override; + EGLNativeWindowType InitializePlatform(EGLNativeWindowType host_window, EGLConfig config) override; + void ShutdownPlatform() override; +}; diff --git a/Source/Core/DolphinWX/GLInterface/GLInterface.cpp b/Source/Core/DolphinWX/GLInterface/GLInterface.cpp index 14b5bfd392..0c8ea8673b 100644 --- a/Source/Core/DolphinWX/GLInterface/GLInterface.cpp +++ b/Source/Core/DolphinWX/GLInterface/GLInterface.cpp @@ -4,28 +4,36 @@ #include "VideoBackends/OGL/GLInterfaceBase.h" -#if USE_EGL -#include "DolphinWX/GLInterface/EGL.h" +#ifdef ANDROID +#include "DolphinWX/GLInterface/EGLAndroid.h" #elif defined(__APPLE__) #include "DolphinWX/GLInterface/AGL.h" #elif defined(_WIN32) #include "DolphinWX/GLInterface/WGL.h" #elif HAVE_X11 +#if defined(USE_EGL) && USE_EGL +#include "DolphinWX/GLInterface/EGLX11.h" +#else #include "DolphinWX/GLInterface/GLX.h" +#endif #else #error Platform doesnt have a GLInterface #endif cInterfaceBase* HostGL_CreateGLInterface() { - #if defined(USE_EGL) && USE_EGL - return new cInterfaceEGL; + #ifdef ANDROID + return new cInterfaceEGLAndroid; #elif defined(__APPLE__) return new cInterfaceAGL; #elif defined(_WIN32) return new cInterfaceWGL; #elif defined(HAVE_X11) && HAVE_X11 + #if defined(USE_EGL) && USE_EGL + return new cInterfaceEGLX11; + #else return new cInterfaceGLX; + #endif #else return nullptr; #endif