Added fading to Cocoa display mode setting.

This commit is contained in:
Keith Pitt 2013-02-24 21:12:21 +01:00 committed by Camilla Berglund
parent 1ae9ce1e0a
commit 34ce04a122
2 changed files with 35 additions and 2 deletions

View File

@ -127,6 +127,29 @@ static GLFWvidmode vidmodeFromCGDisplayMode(CGDisplayModeRef mode)
////// GLFW internal API //////
//////////////////////////////////////////////////////////////////////////
// Starts reservation for display fading
//
CGDisplayFadeReservationToken _glfwBeginFadeReservation(void)
{
CGDisplayFadeReservationToken token = kCGDisplayFadeReservationInvalidToken;
if (CGAcquireDisplayFadeReservation(5, &token) == kCGErrorSuccess)
CGDisplayFade(token, 0.3, kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0.0, 0.0, 0.0, TRUE);
return token;
}
// Ends reservation for display fading
//
void _glfwEndFadeReservation(CGDisplayFadeReservationToken token)
{
if (token != kCGDisplayFadeReservationInvalidToken)
{
CGDisplayFade(token, 0.5, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0.0, 0.0, 0.0, FALSE);
CGReleaseDisplayFadeReservation(token);
}
}
// Change the current video mode
//
GLboolean _glfwSetVideoMode(_GLFWmonitor* monitor, int* width, int* height, int* bpp)
@ -182,9 +205,13 @@ GLboolean _glfwSetVideoMode(_GLFWmonitor* monitor, int* width, int* height, int*
monitor->ns.previousMode = CGDisplayCopyDisplayMode(monitor->ns.displayID);
CGDisplayFadeReservationToken token = _glfwBeginFadeReservation();
CGDisplayCapture(monitor->ns.displayID);
CGDisplaySetDisplayMode(monitor->ns.displayID, bestMode, NULL);
_glfwEndFadeReservation(token);
CFRelease(modes);
return GL_TRUE;
}
@ -193,8 +220,12 @@ GLboolean _glfwSetVideoMode(_GLFWmonitor* monitor, int* width, int* height, int*
//
void _glfwRestoreVideoMode(_GLFWmonitor* monitor)
{
CGDisplayFadeReservationToken token = _glfwBeginFadeReservation();
CGDisplaySetDisplayMode(monitor->ns.displayID, monitor->ns.previousMode, NULL);
CGDisplayRelease(monitor->ns.displayID);
_glfwEndFadeReservation(token);
}

View File

@ -770,9 +770,11 @@ void _glfwPlatformDestroyWindow(_GLFWwindow* window)
if (window->monitor)
{
[[window->ns.object contentView] exitFullScreenModeWithOptions:nil];
_glfwRestoreVideoMode(window->monitor);
// Exit full screen after the video restore to avoid a nasty display
// flickering during the fade.
[[window->ns.object contentView] exitFullScreenModeWithOptions:nil];
}
_glfwDestroyContext(window);