Skip to content

Commit

Permalink
Merge pull request xbmc#25026 from enen92/macos_avoid_refreshresize
Browse files Browse the repository at this point in the history
  • Loading branch information
jenkins4kodi authored Apr 21, 2024
2 parents 39b72ae + e011e3f commit c48c9e6
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 44 deletions.
11 changes: 0 additions & 11 deletions xbmc/windowing/osx/OpenGL/OSXGLView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
*/
Expand All @@ -30,9 +24,4 @@
*/
- (void)FlushBuffer;

/**
* @brief Specifies if the glContext is currently owned by the view
*/
@property(atomic, assign) BOOL glContextOwned;

@end
21 changes: 1 addition & 20 deletions xbmc/windowing/osx/OpenGL/OSXGLView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ @implementation OSXGLView
NSTrackingArea* m_trackingArea;
}

@synthesize glContextOwned;

- (void)SendInputEvent:(NSEvent*)nsEvent
{
CWinSystemOSX* winSystem = dynamic_cast<CWinSystemOSX*>(CServiceBroker::GetWinSystem());
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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
Expand Down
34 changes: 34 additions & 0 deletions xbmc/windowing/osx/OpenGL/WindowControllerMacOS.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -77,6 +79,30 @@ - (void)windowDidResize:(NSNotification*)aNotification
}
}

- (void)windowWillStartLiveResize:(NSNotification*)notification
{
if (m_inFullscreenTransition)
return;

std::shared_ptr<CAppInboundProtocol> appPort = CServiceBroker::GetAppPort();
if (appPort)
{
appPort->SetRenderGUI(false);
}
}

- (void)windowDidEndLiveResize:(NSNotification*)notification
{
if (m_inFullscreenTransition)
return;

std::shared_ptr<CAppInboundProtocol> appPort = CServiceBroker::GetAppPort();
if (appPort)
{
appPort->SetRenderGUI(true);
}
}

- (void)windowDidMiniaturize:(NSNotification*)aNotification
{
g_application.m_AppFocused = false;
Expand Down Expand Up @@ -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<CWinSystemOSX*>(CServiceBroker::GetWinSystem());
if (!winSystem)
return;
Expand Down Expand Up @@ -209,6 +241,7 @@ - (NSApplicationPresentationOptions)window:(NSWindow*)window

- (void)windowDidExitFullScreen:(NSNotification*)pNotification
{
m_inFullscreenTransition = false;
auto winSystem = dynamic_cast<CWinSystemOSX*>(CServiceBroker::GetWinSystem());
if (!winSystem)
return;
Expand All @@ -235,6 +268,7 @@ - (void)windowDidExitFullScreen:(NSNotification*)pNotification

- (void)windowDidEnterFullScreen:(NSNotification*)notification
{
m_inFullscreenTransition = false;
auto winSystem = dynamic_cast<CWinSystemOSX*>(CServiceBroker::GetWinSystem());
if (!winSystem)
return;
Expand Down
1 change: 0 additions & 1 deletion xbmc/windowing/osx/WinSystemOSX.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 0 additions & 12 deletions xbmc/windowing/osx/WinSystemOSX.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c48c9e6

Please sign in to comment.