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.
This commit is contained in:
Jasper St. Pierre 2014-08-09 10:31:27 -04:00
parent e39543b963
commit 271efb450c
8 changed files with 134 additions and 23 deletions

View File

@ -74,16 +74,22 @@ set(ANDROID_SRCS Android/ButtonManager.cpp
if(USE_EGL) if(USE_EGL)
set(SRCS ${SRCS} GLInterface/EGL.cpp) set(SRCS ${SRCS} GLInterface/EGL.cpp)
else() if(ANDROID)
if(WIN32) set(SRCS ${SRCS} GLInterface/EGLAndroid.cpp)
set(SRCS ${SRCS} GLInterface/WGL.cpp) elseif(USE_X11)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") set(SRCS ${SRCS} GLInterface/EGLX11.cpp)
set(SRCS ${SRCS} GLInterface/AGL.cpp)
else()
set(SRCS ${SRCS} GLInterface/GLX.cpp
GLInterface/X11_Util.cpp)
endif() endif()
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(SRCS ${SRCS} GLInterface/GLInterface.cpp)
set(NOGUI_SRCS MainNoGUI.cpp) set(NOGUI_SRCS MainNoGUI.cpp)

View File

@ -2,7 +2,6 @@
// Licensed under GPLv2 // Licensed under GPLv2
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include "Core/Host.h"
#include "DolphinWX/GLInterface/EGL.h" #include "DolphinWX/GLInterface/EGL.h"
#include "VideoBackends/OGL/GLInterfaceBase.h" #include "VideoBackends/OGL/GLInterfaceBase.h"
#include "VideoCommon/RenderBase.h" #include "VideoCommon/RenderBase.h"
@ -90,7 +89,7 @@ bool cInterfaceEGL::Create(void *window_handle)
const char *s; const char *s;
EGLint egl_major, egl_minor; EGLint egl_major, egl_minor;
egl_dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY); egl_dpy = OpenDisplay();
if (!egl_dpy) if (!egl_dpy)
{ {
@ -154,14 +153,8 @@ bool cInterfaceEGL::Create(void *window_handle)
else else
eglBindAPI(EGL_OPENGL_ES_API); eglBindAPI(EGL_OPENGL_ES_API);
EGLNativeWindowType native_window = (EGLNativeWindowType) window_handle; EGLNativeWindowType host_window = (EGLNativeWindowType) window_handle;
EGLNativeWindowType native_window = InitializePlatform(host_window, config);
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);
s = eglQueryString(egl_dpy, EGL_VERSION); s = eglQueryString(egl_dpy, EGL_VERSION);
INFO_LOG(VIDEO, "EGL_VERSION = %s\n", s); INFO_LOG(VIDEO, "EGL_VERSION = %s\n", s);
@ -199,6 +192,7 @@ bool cInterfaceEGL::MakeCurrent()
// Close backend // Close backend
void cInterfaceEGL::Shutdown() void cInterfaceEGL::Shutdown()
{ {
ShutdownPlatform();
if (egl_ctx && !eglMakeCurrent(egl_dpy, egl_surf, egl_surf, egl_ctx)) if (egl_ctx && !eglMakeCurrent(egl_dpy, egl_surf, egl_surf, egl_ctx))
NOTICE_LOG(VIDEO, "Could not release drawing context."); NOTICE_LOG(VIDEO, "Could not release drawing context.");
if (egl_ctx) if (egl_ctx)

View File

@ -12,11 +12,15 @@
class cInterfaceEGL : public cInterfaceBase class cInterfaceEGL : public cInterfaceBase
{ {
private: protected:
void DetectMode(); void DetectMode();
EGLSurface egl_surf; EGLSurface egl_surf;
EGLContext egl_ctx; EGLContext egl_ctx;
EGLDisplay egl_dpy; EGLDisplay egl_dpy;
virtual EGLDisplay OpenDisplay() = 0;
virtual EGLNativeWindowType InitializePlatform(EGLNativeWindowType host_window, EGLConfig config) = 0;
virtual void ShutdownPlatform() = 0;
public: public:
void SwapInterval(int Interval); void SwapInterval(int Interval);
void Swap(); void Swap();

View File

@ -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()
{
}

View File

@ -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;
};

View File

@ -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);
}

View File

@ -0,0 +1,21 @@
// Copyright 2014 Dolphin Emulator Project
// Licensed under GPLv2
// Refer to the license.txt file included.
#pragma once
#include <X11/Xlib.h>
#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;
};

View File

@ -4,28 +4,36 @@
#include "VideoBackends/OGL/GLInterfaceBase.h" #include "VideoBackends/OGL/GLInterfaceBase.h"
#if USE_EGL #ifdef ANDROID
#include "DolphinWX/GLInterface/EGL.h" #include "DolphinWX/GLInterface/EGLAndroid.h"
#elif defined(__APPLE__) #elif defined(__APPLE__)
#include "DolphinWX/GLInterface/AGL.h" #include "DolphinWX/GLInterface/AGL.h"
#elif defined(_WIN32) #elif defined(_WIN32)
#include "DolphinWX/GLInterface/WGL.h" #include "DolphinWX/GLInterface/WGL.h"
#elif HAVE_X11 #elif HAVE_X11
#if defined(USE_EGL) && USE_EGL
#include "DolphinWX/GLInterface/EGLX11.h"
#else
#include "DolphinWX/GLInterface/GLX.h" #include "DolphinWX/GLInterface/GLX.h"
#endif
#else #else
#error Platform doesnt have a GLInterface #error Platform doesnt have a GLInterface
#endif #endif
cInterfaceBase* HostGL_CreateGLInterface() cInterfaceBase* HostGL_CreateGLInterface()
{ {
#if defined(USE_EGL) && USE_EGL #ifdef ANDROID
return new cInterfaceEGL; return new cInterfaceEGLAndroid;
#elif defined(__APPLE__) #elif defined(__APPLE__)
return new cInterfaceAGL; return new cInterfaceAGL;
#elif defined(_WIN32) #elif defined(_WIN32)
return new cInterfaceWGL; return new cInterfaceWGL;
#elif defined(HAVE_X11) && HAVE_X11 #elif defined(HAVE_X11) && HAVE_X11
#if defined(USE_EGL) && USE_EGL
return new cInterfaceEGLX11;
#else
return new cInterfaceGLX; return new cInterfaceGLX;
#endif
#else #else
return nullptr; return nullptr;
#endif #endif