From 8d7e5cdb49a1a5247df612157ecffdd8e68923d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Thu, 21 Feb 2019 00:35:53 +0100 Subject: [PATCH] NSGL: Update current display for display link This solution of one display link per window is far from ideal but is still better than no solution. As a side-effect this fixes swap interval breaking being ignored for occluded windows on earlier versions of macOS. Fixes #680. Fixes #1337. Related to #1417. Fixes #1435. --- src/cocoa_monitor.m | 2 -- src/cocoa_platform.h | 3 +++ src/cocoa_window.m | 6 ++++++ src/nsgl_context.h | 3 +-- src/nsgl_context.m | 18 +++++++++++++----- 5 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/cocoa_monitor.m b/src/cocoa_monitor.m index acaba8c4..a5138572 100644 --- a/src/cocoa_monitor.m +++ b/src/cocoa_monitor.m @@ -32,8 +32,6 @@ #include #include -#include -#include #include diff --git a/src/cocoa_platform.h b/src/cocoa_platform.h index 7f188492..9c28cb67 100644 --- a/src/cocoa_platform.h +++ b/src/cocoa_platform.h @@ -28,6 +28,9 @@ #include #include +#include +#include + #if defined(__OBJC__) #import #else diff --git a/src/cocoa_window.m b/src/cocoa_window.m index 11702778..888edc9a 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -338,6 +338,12 @@ static const NSRange kEmptyRange = { NSNotFound, 0 }; _glfwInputWindowFocus(window, GLFW_FALSE); } +- (void)windowDidChangeScreen:(NSNotification *)notification +{ + if (window->context.source == GLFW_NATIVE_CONTEXT_API) + _glfwUpdateDisplayLinkDisplayNSGL(window); +} + @end diff --git a/src/nsgl_context.h b/src/nsgl_context.h index 9f2ebb52..27af3335 100755 --- a/src/nsgl_context.h +++ b/src/nsgl_context.h @@ -27,8 +27,6 @@ #define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextNSGL nsgl #define _GLFW_PLATFORM_LIBRARY_CONTEXT_STATE _GLFWlibraryNSGL nsgl -#import - #include @@ -61,4 +59,5 @@ GLFWbool _glfwCreateContextNSGL(_GLFWwindow* window, const _GLFWctxconfig* ctxconfig, const _GLFWfbconfig* fbconfig); void _glfwDestroyContextNSGL(_GLFWwindow* window); +void _glfwUpdateDisplayLinkDisplayNSGL(_GLFWwindow* window); diff --git a/src/nsgl_context.m b/src/nsgl_context.m index 2c104187..72ed3597 100755 --- a/src/nsgl_context.m +++ b/src/nsgl_context.m @@ -367,6 +367,8 @@ GLFWbool _glfwCreateContextNSGL(_GLFWwindow* window, [window->context.nsgl.object setView:window->ns.view]; + window->context.nsgl.swapIntervalCond = [NSCondition new]; + window->context.makeCurrent = makeContextCurrentNSGL; window->context.swapBuffers = swapBuffersNSGL; window->context.swapInterval = swapIntervalNSGL; @@ -378,16 +380,22 @@ GLFWbool _glfwCreateContextNSGL(_GLFWwindow* window, CVDisplayLinkSetOutputCallback(window->context.nsgl.displayLink, &displayLinkCallback, window); - CVDisplayLinkSetCurrentCGDisplayFromOpenGLContext(window->context.nsgl.displayLink, - (CGLContextObj) window->context.nsgl.object, - (CGLPixelFormatObj) window->context.nsgl.pixelFormat); CVDisplayLinkStart(window->context.nsgl.displayLink); - window->context.nsgl.swapIntervalCond = [NSCondition new]; - + _glfwUpdateDisplayLinkDisplayNSGL(window); return GLFW_TRUE; } +void _glfwUpdateDisplayLinkDisplayNSGL(_GLFWwindow* window) +{ + CGDirectDisplayID displayID = + [[[window->ns.object screen] deviceDescription][@"NSScreenNumber"] unsignedIntValue]; + if (!displayID) + return; + + CVDisplayLinkSetCurrentCGDisplay(window->context.nsgl.displayLink, displayID); +} + ////////////////////////////////////////////////////////////////////////// ////// GLFW native API //////