From a293a9bd4b00ec902715659c285d99ec827e9dea Mon Sep 17 00:00:00 2001 From: TellowKrinkle Date: Wed, 10 May 2023 19:00:22 -0500 Subject: [PATCH] GS:GL: Fix GLContextAGL compile --- pcsx2/CMakeLists.txt | 2 +- pcsx2/GS/Renderers/OpenGL/GLContextAGL.mm | 42 +++++++---------------- 2 files changed, 13 insertions(+), 31 deletions(-) diff --git a/pcsx2/CMakeLists.txt b/pcsx2/CMakeLists.txt index 105493bd83..d750d405ee 100644 --- a/pcsx2/CMakeLists.txt +++ b/pcsx2/CMakeLists.txt @@ -626,7 +626,7 @@ if(USE_OPENGL) list(APPEND pcsx2GSHeaders GS/Renderers/OpenGL/GLContextWGL.h) target_link_libraries(PCSX2_FLAGS INTERFACE opengl32.lib) elseif(APPLE) - list(APPEND pcsx2GSSources GS/Renderers/OpenGL/GLContextAGL.cpp) + list(APPEND pcsx2GSSources GS/Renderers/OpenGL/GLContextAGL.mm) list(APPEND pcsx2GSHeaders GS/Renderers/OpenGL/GLContextAGL.h) else() if(X11_API OR WAYLAND_API) diff --git a/pcsx2/GS/Renderers/OpenGL/GLContextAGL.mm b/pcsx2/GS/Renderers/OpenGL/GLContextAGL.mm index 0427b9b535..af28a1caba 100644 --- a/pcsx2/GS/Renderers/OpenGL/GLContextAGL.mm +++ b/pcsx2/GS/Renderers/OpenGL/GLContextAGL.mm @@ -24,12 +24,8 @@ #include -#if ! __has_feature(objc_arc) -#error "Compile this with -fobjc-arc" -#endif - GLContextAGL::GLContextAGL(const WindowInfo& wi) - : Context(wi) + : GLContext(wi) { m_opengl_module_handle = dlopen("/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL", RTLD_NOW); if (!m_opengl_module_handle) @@ -45,9 +41,12 @@ GLContextAGL::~GLContextAGL() if (m_opengl_module_handle) dlclose(m_opengl_module_handle); + + [m_pixel_format release]; + [m_context release]; } -std::unique_ptr GLContextAGL::Create(const WindowInfo& wi, gsl::span versions_to_try) +std::unique_ptr GLContextAGL::Create(const WindowInfo& wi, gsl::span versions_to_try) { std::unique_ptr context = std::make_unique(wi); if (!context->Initialize(versions_to_try)) @@ -145,7 +144,7 @@ bool GLContextAGL::SetSwapInterval(s32 interval) return true; } -std::unique_ptr GLContextAGL::CreateSharedContext(const WindowInfo& wi) +std::unique_ptr GLContextAGL::CreateSharedContext(const WindowInfo& wi) { std::unique_ptr context = std::make_unique(wi); @@ -164,8 +163,10 @@ std::unique_ptr GLContextAGL::CreateSharedContext(const WindowInfo& wi) bool GLContextAGL::CreateContext(NSOpenGLContext* share_context, int profile, bool make_current) { - if (m_context) - m_context = nullptr; + [m_context release]; + [m_pixel_format release]; + m_context = nullptr; + m_pixel_format = nullptr; const NSOpenGLPixelFormatAttribute attribs[] = { NSOpenGLPFADoubleBuffer, @@ -202,17 +203,7 @@ void GLContextAGL::BindContextToView() return; } -#ifdef PCSX2_CORE - m_view = (__bridge NSView*)m_wi.window_handle; -#else - // Drawing to wx's wxView somehow causes fighting between us and wx, resulting in massive CPU usage on the main thread and no image - // Avoid that by adding our own subview - CleanupView(); - NSView* const superview = (__bridge NSView*)m_wi.window_handle; - m_view = [[NSView alloc] initWithFrame:[superview frame]]; - [superview addSubview:m_view]; - [m_view setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable]; -#endif + m_view = [static_cast(m_wi.window_handle) retain]; [m_view setWantsBestResolutionOpenGLSurface:YES]; UpdateDimensions(); @@ -222,15 +213,6 @@ void GLContextAGL::BindContextToView() void GLContextAGL::CleanupView() { -#ifndef PCSX2_CORE - if (![NSThread isMainThread]) - { - dispatch_sync(dispatch_get_main_queue(), [this]{ CleanupView(); }); - return; - } - - if (m_view) - [m_view removeFromSuperview]; -#endif + [m_view release]; m_view = nullptr; }