diff --git a/xbmc/windowing/osx/OpenGL/OSXGLView.h b/xbmc/windowing/osx/OpenGL/OSXGLView.h index 54a85a232fd15..016e102e78cd8 100644 --- a/xbmc/windowing/osx/OpenGL/OSXGLView.h +++ b/xbmc/windowing/osx/OpenGL/OSXGLView.h @@ -15,12 +15,6 @@ - (id)initWithFrame:(NSRect)frameRect; - (CGLContextObj)getGLContextObj; -/** - * @brief Application renders out of the NSOpenGLView drawRect (on a different thread). Hence the current - * NSOpenGLContext needs to be make current so that the view on the context is valid for rendering. - * This should be done whenever gl calls are about to be done. - */ -- (void)NotifyContext; /** * @brief Update the current OpenGL context (view is set before updating) */ @@ -30,9 +24,4 @@ */ - (void)FlushBuffer; -/** - * @brief Specifies if the glContext is currently owned by the view - */ -@property(atomic, assign) BOOL glContextOwned; - @end diff --git a/xbmc/windowing/osx/OpenGL/OSXGLView.mm b/xbmc/windowing/osx/OpenGL/OSXGLView.mm index 195ea0d889007..857174838a4af 100644 --- a/xbmc/windowing/osx/OpenGL/OSXGLView.mm +++ b/xbmc/windowing/osx/OpenGL/OSXGLView.mm @@ -20,8 +20,6 @@ @implementation OSXGLView NSTrackingArea* m_trackingArea; } -@synthesize glContextOwned; - - (void)SendInputEvent:(NSEvent*)nsEvent { CWinSystemOSX* winSystem = dynamic_cast(CServiceBroker::GetWinSystem()); @@ -88,14 +86,6 @@ - (BOOL)acceptsFirstResponder - (void)drawRect:(NSRect)rect { - // whenever the view/window is resized the glContext is made current to the main (rendering) thread. - // Since kodi does its rendering on the application main thread (not the macOS rendering thread), we - // need to store this so that on a subsquent frame render we get the ownership of the gl context again. - // doing this blindly without any sort of control may stall the main thread and lead to low GUI fps - // since the glContext ownership needs to be obtained from the rendering thread (diverged from the actual - // thread doing the rendering calls). - [self setGlContextOwned:TRUE]; - static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ [self setOpenGLContext:m_glcontext]; @@ -215,17 +205,8 @@ - (CGLContextObj)getGLContextObj - (void)Update { assert(m_glcontext); - [self NotifyContext]; - [m_glcontext update]; -} - -- (void)NotifyContext -{ - assert(m_glcontext); - // signals/notifies the context that this view is current (required if we render out of DrawRect) - // ownership of the context is transferred to the callee thread [m_glcontext makeCurrentContext]; - [self setGlContextOwned:FALSE]; + [m_glcontext update]; } - (void)FlushBuffer diff --git a/xbmc/windowing/osx/OpenGL/WindowControllerMacOS.mm b/xbmc/windowing/osx/OpenGL/WindowControllerMacOS.mm index 5bfb6b0d22925..4f50a49dbc410 100644 --- a/xbmc/windowing/osx/OpenGL/WindowControllerMacOS.mm +++ b/xbmc/windowing/osx/OpenGL/WindowControllerMacOS.mm @@ -22,6 +22,8 @@ @implementation XBMCWindowControllerMacOS +bool m_inFullscreenTransition = false; + - (nullable instancetype)initWithTitle:(NSString*)title defaultSize:(NSSize)size { auto frame = NSMakeRect(0, 0, size.width, size.height); @@ -77,6 +79,30 @@ - (void)windowDidResize:(NSNotification*)aNotification } } +- (void)windowWillStartLiveResize:(NSNotification*)notification +{ + if (m_inFullscreenTransition) + return; + + std::shared_ptr appPort = CServiceBroker::GetAppPort(); + if (appPort) + { + appPort->SetRenderGUI(false); + } +} + +- (void)windowDidEndLiveResize:(NSNotification*)notification +{ + if (m_inFullscreenTransition) + return; + + std::shared_ptr appPort = CServiceBroker::GetAppPort(); + if (appPort) + { + appPort->SetRenderGUI(true); + } +} + - (void)windowDidMiniaturize:(NSNotification*)aNotification { g_application.m_AppFocused = false; @@ -170,8 +196,14 @@ - (NSSize)windowWillResize:(NSWindow*)sender toSize:(NSSize)frameSize return frameSize; } +- (void)windowWillExitFullScreen:(NSNotification*)notification +{ + m_inFullscreenTransition = true; +} + - (void)windowWillEnterFullScreen:(NSNotification*)pNotification { + m_inFullscreenTransition = true; CWinSystemOSX* winSystem = dynamic_cast(CServiceBroker::GetWinSystem()); if (!winSystem) return; @@ -209,6 +241,7 @@ - (NSApplicationPresentationOptions)window:(NSWindow*)window - (void)windowDidExitFullScreen:(NSNotification*)pNotification { + m_inFullscreenTransition = false; auto winSystem = dynamic_cast(CServiceBroker::GetWinSystem()); if (!winSystem) return; @@ -235,6 +268,7 @@ - (void)windowDidExitFullScreen:(NSNotification*)pNotification - (void)windowDidEnterFullScreen:(NSNotification*)notification { + m_inFullscreenTransition = false; auto winSystem = dynamic_cast(CServiceBroker::GetWinSystem()); if (!winSystem) return; diff --git a/xbmc/windowing/osx/WinSystemOSX.h b/xbmc/windowing/osx/WinSystemOSX.h index c431d70cd9b81..899e52486b9a0 100644 --- a/xbmc/windowing/osx/WinSystemOSX.h +++ b/xbmc/windowing/osx/WinSystemOSX.h @@ -71,7 +71,6 @@ class CWinSystemOSX : public CWinSystemBase, public ITimerCallback void MoveToScreen(unsigned int screenIdx) override; void OnMove(int x, int y) override; void OnChangeScreen(unsigned int screenIdx) override; - CGraphicContext& GetGfxContext() const override; bool HasValidResolution() const; std::string GetClipboardText() override; diff --git a/xbmc/windowing/osx/WinSystemOSX.mm b/xbmc/windowing/osx/WinSystemOSX.mm index 04a0670a1702c..007fc14be3fd0 100644 --- a/xbmc/windowing/osx/WinSystemOSX.mm +++ b/xbmc/windowing/osx/WinSystemOSX.mm @@ -1304,18 +1304,6 @@ static void DisplayReconfigured(CGDirectDisplayID display, return cglcontex; } -CGraphicContext& CWinSystemOSX::GetGfxContext() const -{ - if (m_glView && [m_glView glContextOwned]) - { - dispatch_sync(dispatch_get_main_queue(), ^{ - [m_glView NotifyContext]; - }); - } - - return CWinSystemBase::GetGfxContext(); -} - bool CWinSystemOSX::FlushBuffer() { if (m_appWindow)