mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-24 14:49:42 -06:00
AGL: Move more UI API calls to the main thread
This commit is contained in:
@ -4,6 +4,9 @@
|
|||||||
#include "Common/GL/GLInterface/AGL.h"
|
#include "Common/GL/GLInterface/AGL.h"
|
||||||
#include "Common/Logging/Log.h"
|
#include "Common/Logging/Log.h"
|
||||||
|
|
||||||
|
// UpdateCachedDimensions and AttachContextToView contain calls to UI APIs, so they must only be
|
||||||
|
// called from the main thread or they risk crashing!
|
||||||
|
|
||||||
static bool UpdateCachedDimensions(NSView* view, u32* width, u32* height)
|
static bool UpdateCachedDimensions(NSView* view, u32* width, u32* height)
|
||||||
{
|
{
|
||||||
NSWindow* window = [view window];
|
NSWindow* window = [view window];
|
||||||
@ -35,12 +38,10 @@ static bool AttachContextToView(NSOpenGLContext* context, NSView* view, u32* wid
|
|||||||
|
|
||||||
(void)UpdateCachedDimensions(view, width, height);
|
(void)UpdateCachedDimensions(view, width, height);
|
||||||
|
|
||||||
// the following calls can crash if not called from the main thread on macOS 10.15
|
[window makeFirstResponder:view];
|
||||||
dispatch_sync(dispatch_get_main_queue(), ^{
|
[context setView:view];
|
||||||
[window makeFirstResponder:view];
|
[window makeKeyAndOrderFront:nil];
|
||||||
[context setView:view];
|
|
||||||
[window makeKeyAndOrderFront:nil];
|
|
||||||
});
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,8 +99,16 @@ bool GLContextAGL::Initialize(const WindowSystemInfo& wsi, bool stereo, bool cor
|
|||||||
|
|
||||||
m_view = static_cast<NSView*>(wsi.render_surface);
|
m_view = static_cast<NSView*>(wsi.render_surface);
|
||||||
m_opengl_mode = Mode::OpenGL;
|
m_opengl_mode = Mode::OpenGL;
|
||||||
if (!AttachContextToView(m_context, m_view, &m_backbuffer_width, &m_backbuffer_height))
|
|
||||||
|
__block bool success;
|
||||||
|
dispatch_sync(dispatch_get_main_queue(), ^{
|
||||||
|
success = AttachContextToView(m_context, m_view, &m_backbuffer_width, &m_backbuffer_height);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!success)
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
[m_context makeCurrentContext];
|
[m_context makeCurrentContext];
|
||||||
return true;
|
return true;
|
||||||
@ -140,11 +149,12 @@ void GLContextAGL::Update()
|
|||||||
if (!m_view)
|
if (!m_view)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (UpdateCachedDimensions(m_view, &m_backbuffer_width, &m_backbuffer_height))
|
dispatch_sync(dispatch_get_main_queue(), ^{
|
||||||
// the following calls can crash if not called from the main thread on macOS 10.15
|
if (UpdateCachedDimensions(m_view, &m_backbuffer_width, &m_backbuffer_height))
|
||||||
dispatch_sync(dispatch_get_main_queue(), ^{
|
{
|
||||||
[m_context update];
|
[m_context update];
|
||||||
});
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLContextAGL::SwapInterval(int interval)
|
void GLContextAGL::SwapInterval(int interval)
|
||||||
|
Reference in New Issue
Block a user