From 2d974b60864e0917881d687e29a328c032888a03 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Sat, 9 Aug 2014 09:49:45 -0400 Subject: [PATCH] GLInterface: Destroy GLWin Everything is now safely tucked inside each individual GLInterface. --- .../Core/DolphinWX/Android/ButtonManager.cpp | 4 +- Source/Core/DolphinWX/DolphinWX.vcxproj | 3 +- .../Core/DolphinWX/DolphinWX.vcxproj.filters | 1 - Source/Core/DolphinWX/GLInterface/AGL.cpp | 39 ++++++------ Source/Core/DolphinWX/GLInterface/AGL.h | 3 + Source/Core/DolphinWX/GLInterface/EGL.cpp | 59 +++++++++---------- Source/Core/DolphinWX/GLInterface/EGL.h | 3 + .../DolphinWX/GLInterface/GLInterface.cpp | 13 +++- .../Core/DolphinWX/GLInterface/GLInterface.h | 42 ------------- Source/Core/DolphinWX/GLInterface/GLX.cpp | 44 +++++++------- Source/Core/DolphinWX/GLInterface/GLX.h | 5 ++ Source/Core/DolphinWX/GLInterface/WGL.cpp | 2 +- .../Core/DolphinWX/GLInterface/X11_Util.cpp | 57 ++++++++++-------- Source/Core/DolphinWX/GLInterface/X11_Util.h | 9 ++- .../ControllerInterface.cpp | 4 -- 15 files changed, 141 insertions(+), 147 deletions(-) delete mode 100644 Source/Core/DolphinWX/GLInterface/GLInterface.h diff --git a/Source/Core/DolphinWX/Android/ButtonManager.cpp b/Source/Core/DolphinWX/Android/ButtonManager.cpp index c6d70f3c5e..8d6d241a36 100644 --- a/Source/Core/DolphinWX/Android/ButtonManager.cpp +++ b/Source/Core/DolphinWX/Android/ButtonManager.cpp @@ -4,8 +4,10 @@ #include +#include "Common/FileUtil.h" +#include "Common/IniFile.h" +#include "Common/Thread.h" #include "DolphinWX/Android/ButtonManager.h" -#include "DolphinWX/GLInterface/GLInterface.h" namespace ButtonManager { diff --git a/Source/Core/DolphinWX/DolphinWX.vcxproj b/Source/Core/DolphinWX/DolphinWX.vcxproj index 4f2b7cb0e0..c6b38f7f9b 100644 --- a/Source/Core/DolphinWX/DolphinWX.vcxproj +++ b/Source/Core/DolphinWX/DolphinWX.vcxproj @@ -1,4 +1,4 @@ - + @@ -100,7 +100,6 @@ - diff --git a/Source/Core/DolphinWX/DolphinWX.vcxproj.filters b/Source/Core/DolphinWX/DolphinWX.vcxproj.filters index e9aa9317c1..e85ffbb88c 100644 --- a/Source/Core/DolphinWX/DolphinWX.vcxproj.filters +++ b/Source/Core/DolphinWX/DolphinWX.vcxproj.filters @@ -282,7 +282,6 @@ GUI - GUI\Video diff --git a/Source/Core/DolphinWX/GLInterface/AGL.cpp b/Source/Core/DolphinWX/GLInterface/AGL.cpp index 6f79a8bec0..c82ea0bc2c 100644 --- a/Source/Core/DolphinWX/GLInterface/AGL.cpp +++ b/Source/Core/DolphinWX/GLInterface/AGL.cpp @@ -4,14 +4,15 @@ #include -#include "DolphinWX/GLInterface/GLInterface.h" +#include "DolphinWX/GLInterface/AGL.h" + #include "VideoCommon/RenderBase.h" #include "VideoCommon/VertexShaderManager.h" #include "VideoCommon/VideoConfig.h" void cInterfaceAGL::Swap() { - [GLWin.cocoaCtx flushBuffer]; + [cocoaCtx flushBuffer]; } // Create rendering window. @@ -19,13 +20,13 @@ void cInterfaceAGL::Swap() bool cInterfaceAGL::Create(void *window_handle) { // FIXME: Get rid of the explicit use of wxPanel here. This shouldn't be necessary. - GLWin.cocoaWin = reinterpret_cast(((wxPanel*)window_handle)->GetHandle()); - NSSize size = [GLWin.cocoaWin frame].size; + cocoaWin = reinterpret_cast(((wxPanel*)window_handle)->GetHandle()); + NSSize size = [cocoaWin frame].size; // Enable high-resolution display support. - [GLWin.cocoaWin setWantsBestResolutionOpenGLSurface:YES]; + [cocoaWin setWantsBestResolutionOpenGLSurface:YES]; - NSWindow *window = [GLWin.cocoaWin window]; + NSWindow *window = [cocoaWin window]; float scale = [window backingScaleFactor]; size.width *= scale; @@ -43,21 +44,21 @@ bool cInterfaceAGL::Create(void *window_handle) return false; } - GLWin.cocoaCtx = [[NSOpenGLContext alloc] + cocoaCtx = [[NSOpenGLContext alloc] initWithFormat: fmt shareContext: nil]; [fmt release]; - if (GLWin.cocoaCtx == nil) { + if (cocoaCtx == nil) { ERROR_LOG(VIDEO, "failed to create context"); return false; } - if (GLWin.cocoaWin == nil) { + if (cocoaWin == nil) { ERROR_LOG(VIDEO, "failed to create window"); return false; } - [window makeFirstResponder:GLWin.cocoaWin]; - [GLWin.cocoaCtx setView: GLWin.cocoaWin]; + [window makeFirstResponder:cocoaWin]; + [cocoaCtx setView: cocoaWin]; [window makeKeyAndOrderFront: nil]; return true; @@ -65,7 +66,7 @@ bool cInterfaceAGL::Create(void *window_handle) bool cInterfaceAGL::MakeCurrent() { - [GLWin.cocoaCtx makeCurrentContext]; + [cocoaCtx makeCurrentContext]; return true; } @@ -79,15 +80,15 @@ bool cInterfaceAGL::ClearCurrent() // Close backend void cInterfaceAGL::Shutdown() { - [GLWin.cocoaCtx clearDrawable]; - [GLWin.cocoaCtx release]; - GLWin.cocoaCtx = nil; + [cocoaCtx clearDrawable]; + [cocoaCtx release]; + cocoaCtx = nil; } void cInterfaceAGL::Update() { - NSWindow *window = [GLWin.cocoaWin window]; - NSSize size = [GLWin.cocoaWin frame].size; + NSWindow *window = [cocoaWin window]; + NSSize size = [cocoaWin frame].size; float scale = [window backingScaleFactor]; size.width *= scale; @@ -100,11 +101,11 @@ void cInterfaceAGL::Update() s_backbuffer_width = size.width; s_backbuffer_height = size.height; - [GLWin.cocoaCtx update]; + [cocoaCtx update]; } void cInterfaceAGL::SwapInterval(int interval) { - [GLWin.cocoaCtx setValues:(GLint *)&interval forParameter:NSOpenGLCPSwapInterval]; + [cocoaCtx setValues:(GLint *)&interval forParameter:NSOpenGLCPSwapInterval]; } diff --git a/Source/Core/DolphinWX/GLInterface/AGL.h b/Source/Core/DolphinWX/GLInterface/AGL.h index 7def0dd2d2..8ab0dedc0c 100644 --- a/Source/Core/DolphinWX/GLInterface/AGL.h +++ b/Source/Core/DolphinWX/GLInterface/AGL.h @@ -12,6 +12,9 @@ class cInterfaceAGL : public cInterfaceBase { +private: + NSView *cocoaWin; + NSOpenGLContext *cocoaCtx; public: void Swap(); bool Create(void *window_handle); diff --git a/Source/Core/DolphinWX/GLInterface/EGL.cpp b/Source/Core/DolphinWX/GLInterface/EGL.cpp index b6b52ead0a..f5f93eec99 100644 --- a/Source/Core/DolphinWX/GLInterface/EGL.cpp +++ b/Source/Core/DolphinWX/GLInterface/EGL.cpp @@ -3,17 +3,18 @@ // Refer to the license.txt file included. #include "Core/Host.h" -#include "DolphinWX/GLInterface/GLInterface.h" +#include "DolphinWX/GLInterface/EGL.h" +#include "VideoBackends/OGL/GLInterfaceBase.h" #include "VideoCommon/RenderBase.h" // Show the current FPS void cInterfaceEGL::Swap() { - eglSwapBuffers(GLWin.egl_dpy, GLWin.egl_surf); + eglSwapBuffers(egl_dpy, egl_surf); } void cInterfaceEGL::SwapInterval(int Interval) { - eglSwapInterval(GLWin.egl_dpy, Interval); + eglSwapInterval(egl_dpy, Interval); } void* cInterfaceEGL::GetFuncAddress(const std::string& name) @@ -39,7 +40,7 @@ void cInterfaceEGL::DetectMode() EGL_NONE }; // Get how many configs there are - if (!eglChooseConfig( GLWin.egl_dpy, attribs, nullptr, 0, &num_configs)) + if (!eglChooseConfig( egl_dpy, attribs, nullptr, 0, &num_configs)) { INFO_LOG(VIDEO, "Error: couldn't get an EGL visual config\n"); goto err_exit; @@ -48,7 +49,7 @@ void cInterfaceEGL::DetectMode() config = new EGLConfig[num_configs]; // Get all the configurations - if (!eglChooseConfig(GLWin.egl_dpy, attribs, config, num_configs, &num_configs)) + if (!eglChooseConfig(egl_dpy, attribs, config, num_configs, &num_configs)) { INFO_LOG(VIDEO, "Error: couldn't get an EGL visual config\n"); goto err_exit; @@ -58,7 +59,7 @@ void cInterfaceEGL::DetectMode() { EGLint attribVal; bool ret; - ret = eglGetConfigAttrib(GLWin.egl_dpy, config[i], EGL_RENDERABLE_TYPE, &attribVal); + ret = eglGetConfigAttrib(egl_dpy, config[i], EGL_RENDERABLE_TYPE, &attribVal); if (ret) { if (attribVal & EGL_OPENGL_BIT) @@ -89,15 +90,15 @@ bool cInterfaceEGL::Create(void *window_handle) const char *s; EGLint egl_major, egl_minor; - GLWin.egl_dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY); + egl_dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY); - if (!GLWin.egl_dpy) + if (!egl_dpy) { INFO_LOG(VIDEO, "Error: eglGetDisplay() failed\n"); return false; } - if (!eglInitialize(GLWin.egl_dpy, &egl_major, &egl_minor)) + if (!eglInitialize(egl_dpy, &egl_major, &egl_minor)) { INFO_LOG(VIDEO, "Error: eglInitialize() failed\n"); return false; @@ -142,7 +143,7 @@ bool cInterfaceEGL::Create(void *window_handle) break; } - if (!eglChooseConfig( GLWin.egl_dpy, attribs, &config, 1, &num_configs)) + if (!eglChooseConfig( egl_dpy, attribs, &config, 1, &num_configs)) { INFO_LOG(VIDEO, "Error: couldn't get an EGL visual config\n"); exit(1); @@ -153,38 +154,36 @@ bool cInterfaceEGL::Create(void *window_handle) else eglBindAPI(EGL_OPENGL_ES_API); - EGLNativeWindowType native_window = window_handle; + EGLNativeWindowType native_window = (EGLNativeWindowType) window_handle; EGLint format; - eglGetConfigAttrib(GLWin.egl_dpy, config, EGL_NATIVE_VISUAL_ID, &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); - GLWin.width = width; - GLWin.height = height; GLInterface->SetBackBufferDimensions(width, height); - s = eglQueryString(GLWin.egl_dpy, EGL_VERSION); + s = eglQueryString(egl_dpy, EGL_VERSION); INFO_LOG(VIDEO, "EGL_VERSION = %s\n", s); - s = eglQueryString(GLWin.egl_dpy, EGL_VENDOR); + s = eglQueryString(egl_dpy, EGL_VENDOR); INFO_LOG(VIDEO, "EGL_VENDOR = %s\n", s); - s = eglQueryString(GLWin.egl_dpy, EGL_EXTENSIONS); + s = eglQueryString(egl_dpy, EGL_EXTENSIONS); INFO_LOG(VIDEO, "EGL_EXTENSIONS = %s\n", s); - s = eglQueryString(GLWin.egl_dpy, EGL_CLIENT_APIS); + s = eglQueryString(egl_dpy, EGL_CLIENT_APIS); INFO_LOG(VIDEO, "EGL_CLIENT_APIS = %s\n", s); - GLWin.egl_ctx = eglCreateContext(GLWin.egl_dpy, config, EGL_NO_CONTEXT, ctx_attribs ); - if (!GLWin.egl_ctx) + egl_ctx = eglCreateContext(egl_dpy, config, EGL_NO_CONTEXT, ctx_attribs ); + if (!egl_ctx) { INFO_LOG(VIDEO, "Error: eglCreateContext failed\n"); exit(1); } - GLWin.egl_surf = eglCreateWindowSurface(GLWin.egl_dpy, config, native_window, nullptr); - if (!GLWin.egl_surf) + egl_surf = eglCreateWindowSurface(egl_dpy, config, native_window, nullptr); + if (!egl_surf) { INFO_LOG(VIDEO, "Error: eglCreateWindowSurface failed\n"); exit(1); @@ -195,22 +194,22 @@ bool cInterfaceEGL::Create(void *window_handle) bool cInterfaceEGL::MakeCurrent() { - return eglMakeCurrent(GLWin.egl_dpy, GLWin.egl_surf, GLWin.egl_surf, GLWin.egl_ctx); + return eglMakeCurrent(egl_dpy, egl_surf, egl_surf, egl_ctx); } // Close backend void cInterfaceEGL::Shutdown() { - if (GLWin.egl_ctx && !eglMakeCurrent(GLWin.egl_dpy, GLWin.egl_surf, GLWin.egl_surf, GLWin.egl_ctx)) + if (egl_ctx && !eglMakeCurrent(egl_dpy, egl_surf, egl_surf, egl_ctx)) NOTICE_LOG(VIDEO, "Could not release drawing context."); - if (GLWin.egl_ctx) + if (egl_ctx) { - eglMakeCurrent(GLWin.egl_dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); - if (!eglDestroyContext(GLWin.egl_dpy, GLWin.egl_ctx)) + eglMakeCurrent(egl_dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); + if (!eglDestroyContext(egl_dpy, egl_ctx)) NOTICE_LOG(VIDEO, "Could not destroy drawing context."); - if (!eglDestroySurface(GLWin.egl_dpy, GLWin.egl_surf)) + if (!eglDestroySurface(egl_dpy, egl_surf)) NOTICE_LOG(VIDEO, "Could not destroy window surface."); - if (!eglTerminate(GLWin.egl_dpy)) + if (!eglTerminate(egl_dpy)) NOTICE_LOG(VIDEO, "Could not destroy display connection."); - GLWin.egl_ctx = nullptr; + egl_ctx = nullptr; } } diff --git a/Source/Core/DolphinWX/GLInterface/EGL.h b/Source/Core/DolphinWX/GLInterface/EGL.h index 480029419a..5b48b0b272 100644 --- a/Source/Core/DolphinWX/GLInterface/EGL.h +++ b/Source/Core/DolphinWX/GLInterface/EGL.h @@ -14,6 +14,9 @@ class cInterfaceEGL : public cInterfaceBase { private: void DetectMode(); + EGLSurface egl_surf; + EGLContext egl_ctx; + EGLDisplay egl_dpy; public: void SwapInterval(int Interval); void Swap(); diff --git a/Source/Core/DolphinWX/GLInterface/GLInterface.cpp b/Source/Core/DolphinWX/GLInterface/GLInterface.cpp index bb9ce669e2..14b5bfd392 100644 --- a/Source/Core/DolphinWX/GLInterface/GLInterface.cpp +++ b/Source/Core/DolphinWX/GLInterface/GLInterface.cpp @@ -2,10 +2,19 @@ // Licensed under GPLv2 // Refer to the license.txt file included. -#include "DolphinWX/GLInterface/GLInterface.h" #include "VideoBackends/OGL/GLInterfaceBase.h" -GLWindow GLWin; +#if USE_EGL +#include "DolphinWX/GLInterface/EGL.h" +#elif defined(__APPLE__) +#include "DolphinWX/GLInterface/AGL.h" +#elif defined(_WIN32) +#include "DolphinWX/GLInterface/WGL.h" +#elif HAVE_X11 +#include "DolphinWX/GLInterface/GLX.h" +#else +#error Platform doesnt have a GLInterface +#endif cInterfaceBase* HostGL_CreateGLInterface() { diff --git a/Source/Core/DolphinWX/GLInterface/GLInterface.h b/Source/Core/DolphinWX/GLInterface/GLInterface.h deleted file mode 100644 index ee894b34dc..0000000000 --- a/Source/Core/DolphinWX/GLInterface/GLInterface.h +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2013 Dolphin Emulator Project -// Licensed under GPLv2 -// Refer to the license.txt file included. - -#pragma once - -#include "Common/Thread.h" - -#if USE_EGL -#include "DolphinWX/GLInterface/EGL.h" -#elif defined(__APPLE__) -#include "DolphinWX/GLInterface/AGL.h" -#elif defined(_WIN32) -#include "DolphinWX/GLInterface/WGL.h" -#elif HAVE_X11 -#include "DolphinWX/GLInterface/GLX.h" -#include -#else -#error Platform doesnt have a GLInterface -#endif - -typedef struct { -#if USE_EGL - EGLSurface egl_surf; - EGLContext egl_ctx; - EGLDisplay egl_dpy; -#elif defined(__APPLE__) - NSView *cocoaWin; - NSOpenGLContext *cocoaCtx; -#elif HAVE_X11 - GLXContext ctx; - int screen; - Window win; - Window parent; - Display *dpy; - XVisualInfo *vi; - XSetWindowAttributes attr; - std::thread xEventThread; -#endif -} GLWindow; - -extern GLWindow GLWin; diff --git a/Source/Core/DolphinWX/GLInterface/GLX.cpp b/Source/Core/DolphinWX/GLInterface/GLX.cpp index 0365e5d8b9..acfcab6a69 100644 --- a/Source/Core/DolphinWX/GLInterface/GLX.cpp +++ b/Source/Core/DolphinWX/GLInterface/GLX.cpp @@ -4,7 +4,7 @@ #include -#include "DolphinWX/GLInterface/GLInterface.h" +#include "DolphinWX/GLInterface/GLX.h" #include "VideoCommon/RenderBase.h" #include "VideoCommon/VideoConfig.h" @@ -26,7 +26,7 @@ void* cInterfaceGLX::GetFuncAddress(const std::string& name) void cInterfaceGLX::Swap() { - glXSwapBuffers(GLWin.dpy, GLWin.win); + glXSwapBuffers(dpy, win); } // Create rendering window. @@ -58,26 +58,25 @@ bool cInterfaceGLX::Create(void *window_handle) GLX_DOUBLEBUFFER, None }; - GLWin.dpy = XOpenDisplay(nullptr); - GLWin.parent = (Window)window_handle; - GLWin.screen = DefaultScreen(GLWin.dpy); + dpy = XOpenDisplay(nullptr); + int screen = DefaultScreen(dpy); - glXQueryVersion(GLWin.dpy, &glxMajorVersion, &glxMinorVersion); + glXQueryVersion(dpy, &glxMajorVersion, &glxMinorVersion); NOTICE_LOG(VIDEO, "glX-Version %d.%d", glxMajorVersion, glxMinorVersion); // Get an appropriate visual - GLWin.vi = glXChooseVisual(GLWin.dpy, GLWin.screen, attrListDbl); - if (GLWin.vi == nullptr) + vi = glXChooseVisual(dpy, screen, attrListDbl); + if (vi == nullptr) { - GLWin.vi = glXChooseVisual(GLWin.dpy, GLWin.screen, attrListSgl); - if (GLWin.vi != nullptr) + vi = glXChooseVisual(dpy, screen, attrListSgl); + if (vi != nullptr) { ERROR_LOG(VIDEO, "Only single buffered visual!"); } else { - GLWin.vi = glXChooseVisual(GLWin.dpy, GLWin.screen, attrListDefault); - if (GLWin.vi == nullptr) + vi = glXChooseVisual(dpy, screen, attrListDefault); + if (vi == nullptr) { ERROR_LOG(VIDEO, "Could not choose visual (glXChooseVisual)"); return false; @@ -88,20 +87,23 @@ bool cInterfaceGLX::Create(void *window_handle) NOTICE_LOG(VIDEO, "Got double buffered visual!"); // Create a GLX context. - GLWin.ctx = glXCreateContext(GLWin.dpy, GLWin.vi, nullptr, GL_TRUE); - if (!GLWin.ctx) + ctx = glXCreateContext(dpy, vi, nullptr, GL_TRUE); + if (!ctx) { PanicAlert("Unable to create GLX context."); return false; } - XWindow.CreateXWindow(); + XWindow.Initialize(dpy); + + Window parent = (Window)window_handle; + win = XWindow.CreateXWindow(parent, vi); return true; } bool cInterfaceGLX::MakeCurrent() { - bool success = glXMakeCurrent(GLWin.dpy, GLWin.win, GLWin.ctx); + bool success = glXMakeCurrent(dpy, win, ctx); if (success) { // load this function based on the current bound context @@ -112,7 +114,7 @@ bool cInterfaceGLX::MakeCurrent() bool cInterfaceGLX::ClearCurrent() { - return glXMakeCurrent(GLWin.dpy, None, nullptr); + return glXMakeCurrent(dpy, None, nullptr); } @@ -120,11 +122,11 @@ bool cInterfaceGLX::ClearCurrent() void cInterfaceGLX::Shutdown() { XWindow.DestroyXWindow(); - if (GLWin.ctx) + if (ctx) { - glXDestroyContext(GLWin.dpy, GLWin.ctx); - XCloseDisplay(GLWin.dpy); - GLWin.ctx = nullptr; + glXDestroyContext(dpy, ctx); + XCloseDisplay(dpy); + ctx = nullptr; } } diff --git a/Source/Core/DolphinWX/GLInterface/GLX.h b/Source/Core/DolphinWX/GLInterface/GLX.h index 2e811fd323..0aa9c71a59 100644 --- a/Source/Core/DolphinWX/GLInterface/GLX.h +++ b/Source/Core/DolphinWX/GLInterface/GLX.h @@ -5,6 +5,7 @@ #pragma once #include +#include #include "DolphinWX/GLInterface/X11_Util.h" #include "VideoBackends/OGL/GLInterfaceBase.h" @@ -13,6 +14,10 @@ class cInterfaceGLX : public cInterfaceBase { private: cX11Window XWindow; + Display *dpy; + Window win; + GLXContext ctx; + XVisualInfo *vi; public: friend class cX11Window; void SwapInterval(int Interval) override; diff --git a/Source/Core/DolphinWX/GLInterface/WGL.cpp b/Source/Core/DolphinWX/GLInterface/WGL.cpp index 5783999274..89a6a381b1 100644 --- a/Source/Core/DolphinWX/GLInterface/WGL.cpp +++ b/Source/Core/DolphinWX/GLInterface/WGL.cpp @@ -6,7 +6,7 @@ #include "Core/Host.h" -#include "DolphinWX/GLInterface/GLInterface.h" +#include "DolphinWX/GLInterface/WGL.h" #include "VideoCommon/RenderBase.h" #include "VideoCommon/VertexShaderManager.h" diff --git a/Source/Core/DolphinWX/GLInterface/X11_Util.cpp b/Source/Core/DolphinWX/GLInterface/X11_Util.cpp index 21096fbb1a..0842a34d65 100644 --- a/Source/Core/DolphinWX/GLInterface/X11_Util.cpp +++ b/Source/Core/DolphinWX/GLInterface/X11_Util.cpp @@ -2,50 +2,61 @@ // Licensed under GPLv2 // Refer to the license.txt file included. +#include "Common/Thread.h" #include "Core/Host.h" -#include "DolphinWX/GLInterface/GLInterface.h" +#include "DolphinWX/GLInterface/X11_Util.h" +#include "VideoBackends/OGL/GLInterfaceBase.h" #include "VideoCommon/VideoConfig.h" -void cX11Window::CreateXWindow(void) +void cX11Window::Initialize(Display *_dpy) { + dpy = _dpy; +} + +Window cX11Window::CreateXWindow(Window parent, XVisualInfo *vi) +{ + XSetWindowAttributes attr; + + colormap = XCreateColormap(dpy, parent, vi->visual, AllocNone); + // Setup window attributes - GLWin.attr.colormap = XCreateColormap(GLWin.dpy, - GLWin.parent, GLWin.vi->visual, AllocNone); - GLWin.attr.background_pixel = BlackPixel(GLWin.dpy, GLWin.screen); - GLWin.attr.border_pixel = 0; + attr.colormap = colormap; + attr.background_pixel = BlackPixel(dpy, 0); + attr.border_pixel = 0; // Create the window - GLWin.win = XCreateWindow(GLWin.dpy, GLWin.parent, - 0, 0, 1, 1, 0, - GLWin.vi->depth, InputOutput, GLWin.vi->visual, - CWBorderPixel | CWBackPixel | CWColormap, &GLWin.attr); - XSelectInput(GLWin.dpy, GLWin.parent, StructureNotifyMask); - XMapWindow(GLWin.dpy, GLWin.win); - XSync(GLWin.dpy, True); + win = XCreateWindow(dpy, parent, + 0, 0, 1, 1, 0, + vi->depth, InputOutput, vi->visual, + CWBorderPixel | CWBackPixel | CWColormap, &attr); + XSelectInput(dpy, parent, StructureNotifyMask); + XMapWindow(dpy, win); + XSync(dpy, True); - GLWin.xEventThread = std::thread(&cX11Window::XEventThread, this); + xEventThread = std::thread(&cX11Window::XEventThread, this); + + return win; } void cX11Window::DestroyXWindow(void) { - XUnmapWindow(GLWin.dpy, GLWin.win); - GLWin.win = 0; - if (GLWin.xEventThread.joinable()) - GLWin.xEventThread.join(); - XFreeColormap(GLWin.dpy, GLWin.attr.colormap); + XUnmapWindow(dpy, win); + if (xEventThread.joinable()) + xEventThread.join(); + XFreeColormap(dpy, colormap); } void cX11Window::XEventThread() { - while (GLWin.win) + while (win) { XEvent event; - for (int num_events = XPending(GLWin.dpy); num_events > 0; num_events--) + for (int num_events = XPending(dpy); num_events > 0; num_events--) { - XNextEvent(GLWin.dpy, &event); + XNextEvent(dpy, &event); switch (event.type) { case ConfigureNotify: - XResizeWindow(GLWin.dpy, GLWin.win, event.xconfigure.width, event.xconfigure.height); + XResizeWindow(dpy, win, event.xconfigure.width, event.xconfigure.height); GLInterface->SetBackBufferDimensions(event.xconfigure.width, event.xconfigure.height); break; default: diff --git a/Source/Core/DolphinWX/GLInterface/X11_Util.h b/Source/Core/DolphinWX/GLInterface/X11_Util.h index d8c293378c..6913dd2f4c 100644 --- a/Source/Core/DolphinWX/GLInterface/X11_Util.h +++ b/Source/Core/DolphinWX/GLInterface/X11_Util.h @@ -5,6 +5,7 @@ #pragma once #include +#include #include #include #include @@ -13,7 +14,13 @@ class cX11Window { private: void XEventThread(); + std::thread xEventThread; + Colormap colormap; public: - void CreateXWindow(void); + void Initialize(Display *dpy); + Window CreateXWindow(Window parent, XVisualInfo *vi); void DestroyXWindow(void); + + Display *dpy; + Window win; }; diff --git a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp index d90b3bf02a..6d9d3b82a2 100644 --- a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp +++ b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp @@ -5,10 +5,6 @@ #include "Common/Thread.h" #include "InputCommon/ControllerInterface/ControllerInterface.h" -#if USE_EGL -#include "DolphinWX/GLInterface/GLInterface.h" -#endif - #ifdef CIFACE_USE_XINPUT #include "InputCommon/ControllerInterface/XInput/XInput.h" #endif