summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Lutz <michi@icosahedron.de>2018-04-03 22:08:01 +0200
committerMichael Lutz <michi@icosahedron.de>2018-04-10 23:30:01 +0200
commit6c3902ac41113e6e4a87e0a7e9cc9f96062402c4 (patch)
tree23142c9b8613c6b8f78a4027f8ec126a7f21543c
parent964d310cdadf2133bc1bb0682c46b9c72a8dbd90 (diff)
downloadopenttd-6c3902ac41113e6e4a87e0a7e9cc9f96062402c4.tar.xz
Codechange: [OSX] Use newer APIs to get resolution information when available.
-rw-r--r--src/os/macosx/osx_stdafx.h4
-rw-r--r--src/video/cocoa/cocoa_v.mm70
2 files changed, 61 insertions, 13 deletions
diff --git a/src/os/macosx/osx_stdafx.h b/src/os/macosx/osx_stdafx.h
index 70fff822f..70dc8030c 100644
--- a/src/os/macosx/osx_stdafx.h
+++ b/src/os/macosx/osx_stdafx.h
@@ -57,6 +57,10 @@
#define MAC_OS_X_VERSION_10_10 101000
#endif
+#ifndef MAC_OS_X_VERSION_10_11
+#define MAC_OS_X_VERSION_10_11 101100
+#endif
+
#define __STDC_LIMIT_MACROS
#include <stdint.h>
diff --git a/src/video/cocoa/cocoa_v.mm b/src/video/cocoa/cocoa_v.mm
index 8922d3289..0368816ca 100644
--- a/src/video/cocoa/cocoa_v.mm
+++ b/src/video/cocoa/cocoa_v.mm
@@ -237,31 +237,71 @@ static int CDECL ModeSorter(const OTTD_Point *p1, const OTTD_Point *p2)
return 0;
}
+static void QZ_GetDisplayModeInfo(CFArrayRef modes, CFIndex i, int &bpp, uint16 &width, uint16 &height)
+{
+ bpp = 0;
+ width = 0;
+ height = 0;
+
+#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6)
+ if (MacOSVersionIsAtLeast(10, 6, 0)) {
+ CGDisplayModeRef mode = (CGDisplayModeRef)CFArrayGetValueAtIndex(modes, i);
+
+ width = (uint16)CGDisplayModeGetWidth(mode);
+ height = (uint16)CGDisplayModeGetHeight(mode);
+
+#if (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_11)
+ /* Extract bit depth from mode string. */
+ CFStringRef pixEnc = CGDisplayModeCopyPixelEncoding(mode);
+ if (CFStringCompare(pixEnc, CFSTR(IO32BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo) bpp = 32;
+ if (CFStringCompare(pixEnc, CFSTR(IO16BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo) bpp = 16;
+ if (CFStringCompare(pixEnc, CFSTR(IO8BitIndexedPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo) bpp = 8;
+ CFRelease(pixEnc);
+#else
+ /* CGDisplayModeCopyPixelEncoding is deprecated on OSX 10.11+, but there are no 8 bpp modes anyway... */
+ bpp = 32;
+#endif
+ } else
+#endif
+ {
+ int intvalue;
+
+ CFDictionaryRef onemode = (const __CFDictionary*)CFArrayGetValueAtIndex(modes, i);
+ CFNumberRef number = (const __CFNumber*)CFDictionaryGetValue(onemode, kCGDisplayBitsPerPixel);
+ CFNumberGetValue(number, kCFNumberSInt32Type, &intvalue);
+ bpp = intvalue;
+
+ number = (const __CFNumber*)CFDictionaryGetValue(onemode, kCGDisplayWidth);
+ CFNumberGetValue(number, kCFNumberSInt32Type, &intvalue);
+ width = (uint16)intvalue;
+
+ number = (const __CFNumber*)CFDictionaryGetValue(onemode, kCGDisplayHeight);
+ CFNumberGetValue(number, kCFNumberSInt32Type, &intvalue);
+ height = (uint16)intvalue;
+ }
+}
+
uint QZ_ListModes(OTTD_Point *modes, uint max_modes, CGDirectDisplayID display_id, int device_depth)
{
- CFArrayRef mode_list = CGDisplayAvailableModes(display_id);
+#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6) && (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_6)
+ CFArrayRef mode_list = MacOSVersionIsAtLeast(10, 6, 0) ? CGDisplayCopyAllDisplayModes(display_id, NULL) : CGDisplayAvailableModes(display_id);
+#elif (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6)
+ CFArrayRef mode_list = CGDisplayCopyAllDisplayModes(display_id, NULL);
+#else
+ CFArrayRef mode_list = CGDisplayAvailableModes(display_id);
+#endif
CFIndex num_modes = CFArrayGetCount(mode_list);
/* Build list of modes with the requested bpp */
uint count = 0;
for (CFIndex i = 0; i < num_modes && count < max_modes; i++) {
- int intvalue, bpp;
+ int bpp;
uint16 width, height;
- CFDictionaryRef onemode = (const __CFDictionary*)CFArrayGetValueAtIndex(mode_list, i);
- CFNumberRef number = (const __CFNumber*)CFDictionaryGetValue(onemode, kCGDisplayBitsPerPixel);
- CFNumberGetValue(number, kCFNumberSInt32Type, &bpp);
+ QZ_GetDisplayModeInfo(mode_list, i, bpp, width, height);
if (bpp != device_depth) continue;
- number = (const __CFNumber*)CFDictionaryGetValue(onemode, kCGDisplayWidth);
- CFNumberGetValue(number, kCFNumberSInt32Type, &intvalue);
- width = (uint16)intvalue;
-
- number = (const __CFNumber*)CFDictionaryGetValue(onemode, kCGDisplayHeight);
- CFNumberGetValue(number, kCFNumberSInt32Type, &intvalue);
- height = (uint16)intvalue;
-
/* Check if mode is already in the list */
bool hasMode = false;
for (uint i = 0; i < count; i++) {
@@ -282,6 +322,10 @@ uint QZ_ListModes(OTTD_Point *modes, uint max_modes, CGDirectDisplayID display_i
/* Sort list smallest to largest */
QSortT(modes, count, &ModeSorter);
+#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6)
+ if (MacOSVersionIsAtLeast(10, 6, 0)) CFRelease(mode_list);
+#endif
+
return count;
}