From e423e1c663b31676b6b6fa4c2246773daeb568c2 Mon Sep 17 00:00:00 2001 From: bruvzg <7645683+bruvzg@users.noreply.github.com> Date: Thu, 21 Nov 2019 11:01:47 +0200 Subject: [PATCH] [macOS] Remove CVDisplayLink v-sync hack. --- platform/osx/os_osx.h | 3 --- platform/osx/os_osx.mm | 54 ++---------------------------------------- 2 files changed, 2 insertions(+), 55 deletions(-) diff --git a/platform/osx/os_osx.h b/platform/osx/os_osx.h index 09a871f26c46..a61b9234d12e 100644 --- a/platform/osx/os_osx.h +++ b/platform/osx/os_osx.h @@ -113,9 +113,6 @@ class OS_OSX : public OS_Unix { NSOpenGLContext *context; bool layered_window; - bool waiting_for_vsync; - NSCondition *vsync_condition; - CVDisplayLinkRef displayLink; CursorShape cursor_shape; NSCursor *cursors[CURSOR_MAX]; diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm index ba3ac9862e4f..e5166d102b64 100644 --- a/platform/osx/os_osx.mm +++ b/platform/osx/os_osx.mm @@ -115,21 +115,6 @@ static Vector2 get_mouse_pos(NSPoint locationInWindow, CGFloat backingScaleFacto return Vector2(mouse_x, mouse_y); } -// DisplayLinkCallback is called from our DisplayLink OS thread informing us right before -// a screen update is required. We can use it to work around the broken vsync. -static CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeStamp *now, const CVTimeStamp *outputTime, CVOptionFlags flagsIn, CVOptionFlags *flagsOut, void *displayLinkContext) { - OS_OSX *os = (OS_OSX *)displayLinkContext; - - // Set flag so we know we can output our next frame and signal our conditional lock - // if we're not doing vsync this will be ignored - [os->vsync_condition lock]; - os->waiting_for_vsync = false; - [os->vsync_condition signal]; - [os->vsync_condition unlock]; - - return kCVReturnSuccess; -} - @interface GodotApplication : NSApplication @end @@ -1581,15 +1566,6 @@ static void displays_arrangement_changed(CGDirectDisplayID display_id, CGDisplay [context makeCurrentContext]; - // setup our display link, this will inform us when a refresh is needed - CVDisplayLinkCreateWithActiveCGDisplays(&displayLink); - CVDisplayLinkSetOutputCallback(displayLink, &DisplayLinkCallback, this); - CVDisplayLinkSetCurrentCGDisplayFromOpenGLContext(displayLink, context.CGLContextObj, pixelFormat.CGLPixelFormatObj); - CVDisplayLinkStart(displayLink); - - // initialise a conditional lock object - vsync_condition = [[NSCondition alloc] init]; - set_use_vsync(p_desired.use_vsync); [NSApp activateIgnoringOtherApps:YES]; @@ -1682,11 +1658,6 @@ static void displays_arrangement_changed(CGDirectDisplayID display_id, CGDisplay midi_driver.close(); #endif - if (displayLink) { - CVDisplayLinkRelease(displayLink); - } - [vsync_condition release]; - CFNotificationCenterRemoveObserver(CFNotificationCenterGetDistributedCenter(), NULL, kTISNotifySelectedKeyboardInputSourceChanged, NULL); CGDisplayRemoveReconfigurationCallback(displays_arrangement_changed, NULL); @@ -2258,18 +2229,6 @@ virtual void log_error(const char *p_function, const char *p_file, int p_line, c } void OS_OSX::swap_buffers() { - if (is_vsync_enabled()) { - // Wait until our DisplayLink callback unsets our flag... - [vsync_condition lock]; - while (waiting_for_vsync) - [vsync_condition wait]; - - // Make sure we wait again next frame around - waiting_for_vsync = true; - - [vsync_condition unlock]; - } - [context flushBuffer]; } @@ -3009,20 +2968,11 @@ static int get_screen_index(NSScreen *screen) { } void OS_OSX::_set_use_vsync(bool p_enable) { - // CGLCPSwapInterval broke in OSX 10.14 and it seems Apple is not interested in fixing - // it as OpenGL is now deprecated and Metal solves this differently. - // Following SDLs example we're working around this using DisplayLink - // When vsync is enabled we set a flag "waiting_for_vsync" to true. - // This flag is set to false when DisplayLink informs us our display is about to refresh. - - /* CGLContextObj ctx = CGLGetCurrentContext(); + CGLContextObj ctx = CGLGetCurrentContext(); if (ctx) { GLint swapInterval = p_enable ? 1 : 0; CGLSetParameter(ctx, kCGLCPSwapInterval, &swapInterval); - }*/ - - ///TODO Maybe pause/unpause display link? - waiting_for_vsync = p_enable; + } } OS_OSX *OS_OSX::singleton = NULL;