From 134d967be2dd4ba9531abb8ba8494c3ac423ca72 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Wed, 3 Oct 2018 23:02:45 +1000 Subject: Refactoring and cleanup of GLInterface (now GLContext) --- Source/Core/Common/GL/GLX11Window.cpp | 77 +++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 Source/Core/Common/GL/GLX11Window.cpp (limited to 'Source/Core/Common/GL/GLX11Window.cpp') 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::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(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); + } +} -- cgit v1.2.3 From 9c57a98723997736adea94383668fbdf8a993fd8 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Wed, 3 Oct 2018 23:03:19 +1000 Subject: GLContext: Use host connection This also removes the need for a sleeping event thread. --- Source/Core/Common/GL/GLX11Window.cpp | 48 +++++++++-------------------------- 1 file changed, 12 insertions(+), 36 deletions(-) (limited to 'Source/Core/Common/GL/GLX11Window.cpp') diff --git a/Source/Core/Common/GL/GLX11Window.cpp b/Source/Core/Common/GL/GLX11Window.cpp index 793939377d..681adaa099 100644 --- a/Source/Core/Common/GL/GLX11Window.cpp +++ b/Source/Core/Common/GL/GLX11Window.cpp @@ -4,27 +4,30 @@ #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)) + m_width(width), m_height(height) { } 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); + XUnmapWindow(m_display, m_window); + XDestroyWindow(m_display, m_window); XFreeColormap(m_display, m_color_map); } +void GLX11Window::UpdateDimensions() +{ + XWindowAttributes attribs; + XGetWindowAttributes(m_display, m_parent_window, &attribs); + XResizeWindow(m_display, m_window, attribs.width, attribs.height); + m_width = attribs.width; + m_height = attribs.height; +} + std::unique_ptr GLX11Window::Create(Display* display, Window parent_window, XVisualInfo* vi) { @@ -48,30 +51,3 @@ std::unique_ptr GLX11Window::Create(Display* display, Window parent return std::make_unique(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); - } -} -- cgit v1.2.3