summaryrefslogtreecommitdiff
path: root/Source/Core/Common/GL/GLX11Window.cpp
diff options
context:
space:
mode:
authorStenzek <stenzek@gmail.com>2018-10-03 23:02:45 +1000
committerStenzek <stenzek@gmail.com>2018-10-20 21:11:34 +1000
commit134d967be2dd4ba9531abb8ba8494c3ac423ca72 (patch)
tree3486a0d8a8f5c1a141bccc1e9cc56306cde327b4 /Source/Core/Common/GL/GLX11Window.cpp
parent74b82bab3b6e4e8a1799bbcbdc5244f20f4d2826 (diff)
Refactoring and cleanup of GLInterface (now GLContext)
Diffstat (limited to 'Source/Core/Common/GL/GLX11Window.cpp')
-rw-r--r--Source/Core/Common/GL/GLX11Window.cpp77
1 files changed, 77 insertions, 0 deletions
diff --git a/Source/Core/Common/GL/GLX11Window.cpp b/Source/Core/Common/GL/GLX11Window.cpp
new file mode 100644
index 0000000000..793939377d
--- /dev/null
+++ b/Source/Core/Common/GL/GLX11Window.cpp
@@ -0,0 +1,77 @@
+// Copyright 2012 Dolphin Emulator Project
+// Licensed under GPLv2+
+// Refer to the license.txt file included.
+
+#include "Common/GL/GLX11Window.h"
+#include "Common/GL/GLContext.h"
+#include "Common/Thread.h"
+
+GLX11Window::GLX11Window(Display* display, Window parent_window, Colormap color_map, Window window,
+ int width, int height)
+ : m_display(display), m_parent_window(parent_window), m_color_map(color_map), m_window(window),
+ m_width(width), m_height(height),
+ m_event_thread(std::thread(&GLX11Window::XEventThread, this))
+{
+}
+
+GLX11Window::~GLX11Window()
+{
+ Window window = m_window;
+ m_window = None;
+ if (m_event_thread.joinable())
+ m_event_thread.join();
+ XUnmapWindow(m_display, window);
+ XDestroyWindow(m_display, window);
+ XFreeColormap(m_display, m_color_map);
+}
+
+std::unique_ptr<GLX11Window> GLX11Window::Create(Display* display, Window parent_window,
+ XVisualInfo* vi)
+{
+ // Set color map for the new window based on the visual.
+ Colormap color_map = XCreateColormap(display, parent_window, vi->visual, AllocNone);
+ XSetWindowAttributes attribs = {};
+ attribs.colormap = color_map;
+
+ // Get the dimensions from the parent window.
+ XWindowAttributes parent_attribs = {};
+ XGetWindowAttributes(display, parent_window, &parent_attribs);
+
+ // Create the window
+ Window window =
+ XCreateWindow(display, parent_window, 0, 0, parent_attribs.width, parent_attribs.height, 0,
+ vi->depth, InputOutput, vi->visual, CWColormap, &attribs);
+ XSelectInput(display, parent_window, StructureNotifyMask);
+ XMapWindow(display, window);
+ XSync(display, True);
+
+ return std::make_unique<GLX11Window>(display, parent_window, color_map, window,
+ parent_attribs.width, parent_attribs.height);
+}
+
+void GLX11Window::XEventThread()
+{
+ // There's a potential race here on m_window. But this thread will disappear soon.
+ while (m_window)
+ {
+ XEvent event;
+ for (int num_events = XPending(m_display); num_events > 0; num_events--)
+ {
+ XNextEvent(m_display, &event);
+ switch (event.type)
+ {
+ case ConfigureNotify:
+ {
+ m_width = event.xconfigure.width;
+ m_height = event.xconfigure.height;
+ XResizeWindow(m_display, m_window, m_width, m_height);
+ g_main_gl_context->SetBackBufferDimensions(m_width, m_height);
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ Common::SleepCurrentThread(20);
+ }
+}