Skip to content

Commit

Permalink
Cocoa: Disable deprecated function on macOS 10.12+
Browse files Browse the repository at this point in the history
CGDisplayModeCopyPixelEncoding is deprecated starting with macOS 10.12.
  • Loading branch information
elmindreda committed Nov 16, 2016
1 parent d19a21b commit 9190cf8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ information on what to include when reporting a bug.
- [Cocoa] Bugfix: Window creation failed to set first responder (#876,#883)
- [Cocoa] Bugfix: Removed use of deprecated `CGDisplayIOServicePort` function
(#165,#192,#508,#511)
- [Cocoa] Bugfix: Disabled use of deprecated `CGDisplayModeCopyPixelEncoding`
function on macOS 10.12+
- [EGL] Added support for `EGL_KHR_get_all_proc_addresses` (#871)


Expand Down
7 changes: 6 additions & 1 deletion src/cocoa_monitor.m
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ static GLFWbool modeIsGood(CGDisplayModeRef mode)
if (flags & kDisplayModeStretchedFlag)
return GLFW_FALSE;

#if MAC_OS_X_VERSION_MAX_ALLOWED <= 101200
CFStringRef format = CGDisplayModeCopyPixelEncoding(mode);
if (CFStringCompare(format, CFSTR(IO16BitDirectPixels), 0) &&
CFStringCompare(format, CFSTR(IO32BitDirectPixels), 0))
Expand All @@ -137,6 +138,7 @@ static GLFWbool modeIsGood(CGDisplayModeRef mode)
}

CFRelease(format);
#endif /* MAC_OS_X_VERSION_MAX_ALLOWED */
return GLFW_TRUE;
}

Expand All @@ -157,22 +159,25 @@ static GLFWvidmode vidmodeFromCGDisplayMode(CGDisplayModeRef mode,
result.refreshRate = (int) (time.timeScale / (double) time.timeValue);
}

#if MAC_OS_X_VERSION_MAX_ALLOWED <= 101200
CFStringRef format = CGDisplayModeCopyPixelEncoding(mode);

if (CFStringCompare(format, CFSTR(IO16BitDirectPixels), 0) == 0)
{
result.redBits = 5;
result.greenBits = 5;
result.blueBits = 5;
}
else
#endif /* MAC_OS_X_VERSION_MAX_ALLOWED */
{
result.redBits = 8;
result.greenBits = 8;
result.blueBits = 8;
}

#if MAC_OS_X_VERSION_MAX_ALLOWED <= 101200
CFRelease(format);
#endif /* MAC_OS_X_VERSION_MAX_ALLOWED */
return result;
}

Expand Down

0 comments on commit 9190cf8

Please sign in to comment.