GLContext: Use host connection

This also removes the need for a sleeping event thread.
This commit is contained in:
Stenzek
2018-10-03 23:03:19 +10:00
parent 1d827a5223
commit 9c57a98723
18 changed files with 68 additions and 97 deletions

View File

@ -31,7 +31,7 @@ public:
void SwapInterval(int interval) override;
protected:
bool Initialize(void* window_handle, bool stereo, bool core) override;
bool Initialize(void* display_handle, void* window_handle, bool stereo, bool core) override;
bool Initialize(GLContext* main_context) override;
NSView* m_view = nullptr;

View File

@ -55,7 +55,7 @@ void GLContextAGL::Swap()
// Create rendering window.
// Call browser: Core.cpp:EmuThread() > main.cpp:Video_Initialize()
bool GLContextAGL::Initialize(void* window_handle, bool stereo, bool core)
bool GLContextAGL::Initialize(void* display_handle, void* window_handle, bool stereo, bool core)
{
NSOpenGLPixelFormatAttribute attr[] = {
NSOpenGLPFADoubleBuffer,

View File

@ -152,15 +152,16 @@ EGLNativeWindowType GLContextEGL::GetEGLNativeWindow(EGLConfig config)
// Create rendering window.
// Call browser: Core.cpp:EmuThread() > main.cpp:Video_Initialize()
bool GLContextEGL::Initialize(void* window_handle, bool stereo, bool core)
bool GLContextEGL::Initialize(void* display_handle, void* window_handle, bool stereo, bool core)
{
const bool has_handle = !!window_handle;
EGLint egl_major, egl_minor;
bool supports_core_profile = false;
m_egl_display = OpenEGLDisplay();
m_host_display = display_handle;
m_host_window = window_handle;
m_egl_display = OpenEGLDisplay();
m_is_core_context = core;
if (!m_egl_display)
@ -299,6 +300,7 @@ bool GLContextEGL::Initialize(GLContext* main_context)
GLContextEGL* egl_context = static_cast<GLContextEGL*>(main_context);
m_opengl_mode = egl_context->m_opengl_mode;
m_host_display = egl_context->m_host_display;
m_egl_display = egl_context->m_egl_display;
m_is_core_context = egl_context->m_is_core_context;
m_config = egl_context->m_config;

View File

@ -35,13 +35,14 @@ protected:
virtual EGLDisplay OpenEGLDisplay();
virtual EGLNativeWindowType GetEGLNativeWindow(EGLConfig config);
bool Initialize(void* window_handle, bool stereo, bool core) override;
bool Initialize(void* display_handle, void* window_handle, bool stereo, bool core) override;
bool Initialize(GLContext* main_context) override;
bool CreateWindowSurface();
void DestroyWindowSurface();
void DetectMode(bool has_handle);
void* m_host_display = nullptr;
void* m_host_window = nullptr;
EGLConfig m_config;

View File

@ -3,20 +3,19 @@
// Refer to the license.txt file included.
#include "Common/GL/GLInterface/EGLX11.h"
#include "Common/Logging/Log.h"
GLContextEGLX11::~GLContextEGLX11()
GLContextEGLX11::~GLContextEGLX11() = default;
void GLContextEGLX11::Update()
{
if (m_display)
XCloseDisplay(m_display);
m_render_window->UpdateDimensions();
m_backbuffer_width = m_render_window->GetWidth();
m_backbuffer_height = m_render_window->GetHeight();
}
EGLDisplay GLContextEGLX11::OpenEGLDisplay()
{
if (!m_display)
m_display = XOpenDisplay(nullptr);
return eglGetDisplay(m_display);
return eglGetDisplay(static_cast<Display*>(m_host_display));
}
EGLNativeWindowType GLContextEGLX11::GetEGLNativeWindow(EGLConfig config)
@ -28,16 +27,18 @@ EGLNativeWindowType GLContextEGLX11::GetEGLNativeWindow(EGLConfig config)
visTemplate.visualid = vid;
int nVisuals;
XVisualInfo* vi = XGetVisualInfo(m_display, VisualIDMask, &visTemplate, &nVisuals);
XVisualInfo* vi =
XGetVisualInfo(static_cast<Display*>(m_host_display), VisualIDMask, &visTemplate, &nVisuals);
if (m_x_window)
m_x_window.reset();
if (m_render_window)
m_render_window.reset();
m_x_window = GLX11Window::Create(m_display, reinterpret_cast<Window>(m_host_window), vi);
m_backbuffer_width = m_x_window->GetWidth();
m_backbuffer_height = m_x_window->GetHeight();
m_render_window = GLX11Window::Create(static_cast<Display*>(m_host_display),
reinterpret_cast<Window>(m_host_window), vi);
m_backbuffer_width = m_render_window->GetWidth();
m_backbuffer_height = m_render_window->GetHeight();
XFree(vi);
return reinterpret_cast<EGLNativeWindowType>(m_x_window->GetWindow());
return reinterpret_cast<EGLNativeWindowType>(m_render_window->GetWindow());
}

View File

@ -14,10 +14,11 @@ class GLContextEGLX11 : public GLContextEGL
public:
~GLContextEGLX11() override;
void Update() override;
protected:
EGLDisplay OpenEGLDisplay() override;
EGLNativeWindowType GetEGLNativeWindow(EGLConfig config) override;
Display* m_display = nullptr;
std::unique_ptr<GLX11Window> m_x_window;
std::unique_ptr<GLX11Window> m_render_window;
};

View File

@ -56,9 +56,9 @@ void GLContextGLX::Swap()
// Create rendering window.
// Call browser: Core.cpp:EmuThread() > main.cpp:Video_Initialize()
bool GLContextGLX::Initialize(void* window_handle, bool stereo, bool core)
bool GLContextGLX::Initialize(void* display_handle, void* window_handle, bool stereo, bool core)
{
m_display = XOpenDisplay(nullptr);
m_display = static_cast<Display*>(display_handle);
int screen = DefaultScreen(m_display);
// checking glx version
@ -298,16 +298,12 @@ void GLContextGLX::Shutdown()
{
DestroyWindowSurface();
if (m_context)
{
glXDestroyContext(m_display, m_context);
// Don't close the display connection if we are a shared context.
// Saves doing reference counting on this object, and the main context will always
// be shut down last anyway.
if (m_render_window)
{
XCloseDisplay(m_display);
m_context = nullptr;
}
}
}
void GLContextGLX::Update()
{
m_render_window->UpdateDimensions();
m_backbuffer_width = m_render_window->GetWidth();
m_backbuffer_height = m_render_window->GetHeight();
}

View File

@ -24,13 +24,15 @@ public:
bool MakeCurrent() override;
bool ClearCurrent() override;
void Update() override;
void SwapInterval(int Interval) override;
void Swap() override;
void* GetFuncAddress(const std::string& name) override;
protected:
bool Initialize(void* window_handle, bool stereo, bool core) override;
bool Initialize(void* display_handle, void* window_handle, bool stereo, bool core) override;
bool Initialize(GLContext* main_context) override;
Display* m_display = nullptr;

View File

@ -190,7 +190,7 @@ void* GLContextWGL::GetFuncAddress(const std::string& name)
// Create rendering window.
// Call browser: Core.cpp:EmuThread() > main.cpp:Video_Initialize()
bool GLContextWGL::Initialize(void* window_handle, bool stereo, bool core)
bool GLContextWGL::Initialize(void* display_handle, void* window_handle, bool stereo, bool core)
{
if (!window_handle)
return false;

View File

@ -27,7 +27,7 @@ public:
void* GetFuncAddress(const std::string& name) override;
protected:
bool Initialize(void* window_handle, bool stereo, bool core) override;
bool Initialize(void* display_handle, void* window_handle, bool stereo, bool core) override;
bool Initialize(GLContext* main_context) override;
static HGLRC CreateCoreContext(HDC dc, HGLRC share_context);