diff --git a/src/video/cocoa/cocoa_v.mm b/src/video/cocoa/cocoa_v.mm index 3f8413d..80d0d0d 100644 --- a/src/video/cocoa/cocoa_v.mm +++ b/src/video/cocoa/cocoa_v.mm @@ -225,6 +225,80 @@ static void setupApplication() [ NSApp setDelegate:_ottd_main ]; } + +static int CDECL ModeSorter(const OTTD_Point *p1, const OTTD_Point *p2) +{ + if (p1->x < p2->x) return -1; + if (p1->x > p2->x) return +1; + if (p1->y < p2->y) return -1; + if (p1->y > p2->y) return +1; + return 0; +} + +uint QZ_ListModes(OTTD_Point *modes, uint max_modes, CGDirectDisplayID display_id, int device_depth) +{ + CFArrayRef mode_list = CGDisplayAvailableModes(display_id); + 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; + uint16 width, height; + + CFDictionaryRef onemode = (const __CFDictionary*)CFArrayGetValueAtIndex(mode_list, i); + CFNumberRef number = (const __CFNumber*)CFDictionaryGetValue(onemode, kCGDisplayBitsPerPixel); + CFNumberGetValue(number, kCFNumberSInt32Type, &bpp); + + 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++) { + if (modes[i].x == width && modes[i].y == height) { + hasMode = true; + break; + } + } + + if (hasMode) continue; + + /* Add mode to the list */ + modes[count].x = width; + modes[count].y = height; + count++; + } + + /* Sort list smallest to largest */ + QSortT(modes, count, &ModeSorter); + + return count; +} + +/** Small function to test if the main display can display 8 bpp in fullscreen */ +bool QZ_CanDisplay8bpp() +{ + /* 8bpp modes are deprecated starting in 10.5. CoreGraphics will return them + * as available in the display list, but many features (e.g. palette animation) + * will be broken. */ + if (MacOSVersionIsAtLeast(10, 5, 0)) return false; + + OTTD_Point p; + + /* We want to know if 8 bpp is possible in fullscreen and not anything about + * resolutions. Because of this we want to fill a list of 1 resolution of 8 bpp + * on display 0 (main) and return if we found one. */ + return QZ_ListModes(&p, 1, 0, 8); +} + /** * Update the video modus. * @@ -322,9 +396,12 @@ static CocoaSubdriver *QZ_CreateSubdriver(int width, int height, int bpp, bool f if (MacOSVersionIsAtLeast(10, 7, 0)) { ret = QZ_CreateWindowSubdriver(width, height, bpp); if (ret != NULL && fullscreen) ret->ToggleFullscreen(); - } else { + } +#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_9 + else { ret = fullscreen ? QZ_CreateFullscreenSubdriver(width, height, bpp) : QZ_CreateWindowSubdriver(width, height, bpp); } +#endif /* MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_9 */ if (ret != NULL) return ret; if (!fallback) return NULL; @@ -334,7 +411,7 @@ static CocoaSubdriver *QZ_CreateSubdriver(int width, int height, int bpp, bool f ret = QZ_CreateWindowSubdriver(640, 480, bpp); if (ret != NULL) return ret; -#ifdef _DEBUG +#if defined(_DEBUG) && (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_9) /* This Fullscreen mode crashes on OSX 10.7 */ if (!MacOSVersionIsAtLeast(10, 7, 0)) { /* Try fullscreen too when in debug mode */ @@ -342,7 +419,7 @@ static CocoaSubdriver *QZ_CreateSubdriver(int width, int height, int bpp, bool f ret = QZ_CreateFullscreenSubdriver(640, 480, bpp); if (ret != NULL) return ret; } -#endif +#endif /* defined(_DEBUG) && (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_9) */ return NULL; } diff --git a/src/video/cocoa/fullscreen.mm b/src/video/cocoa/fullscreen.mm index e066adf..0683a1a 100644 --- a/src/video/cocoa/fullscreen.mm +++ b/src/video/cocoa/fullscreen.mm @@ -17,6 +17,8 @@ #include "../../stdafx.h" +#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_9 + #define Rect OTTDRect #define Point OTTDPoint #import @@ -74,80 +76,6 @@ struct OTTD_QuartzGammaTable { } @end - -static int CDECL ModeSorter(const OTTD_Point *p1, const OTTD_Point *p2) -{ - if (p1->x < p2->x) return -1; - if (p1->x > p2->x) return +1; - if (p1->y < p2->y) return -1; - if (p1->y > p2->y) return +1; - return 0; -} - -uint QZ_ListModes(OTTD_Point *modes, uint max_modes, CGDirectDisplayID display_id, int device_depth) -{ - CFArrayRef mode_list = CGDisplayAvailableModes(display_id); - 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; - uint16 width, height; - - CFDictionaryRef onemode = (const __CFDictionary*)CFArrayGetValueAtIndex(mode_list, i); - CFNumberRef number = (const __CFNumber*)CFDictionaryGetValue(onemode, kCGDisplayBitsPerPixel); - CFNumberGetValue(number, kCFNumberSInt32Type, &bpp); - - 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++) { - if (modes[i].x == width && modes[i].y == height) { - hasMode = true; - break; - } - } - - if (hasMode) continue; - - /* Add mode to the list */ - modes[count].x = width; - modes[count].y = height; - count++; - } - - /* Sort list smallest to largest */ - QSortT(modes, count, &ModeSorter); - - return count; -} - -/** Small function to test if the main display can display 8 bpp in fullscreen */ -bool QZ_CanDisplay8bpp() -{ - /* 8bpp modes are deprecated starting in 10.5. CoreGraphics will return them - * as available in the display list, but many features (e.g. palette animation) - * will be broken. */ - if (MacOSVersionIsAtLeast(10, 5, 0)) return false; - - OTTD_Point p; - - /* We want to know if 8 bpp is possible in fullscreen and not anything about - * resolutions. Because of this we want to fill a list of 1 resolution of 8 bpp - * on display 0 (main) and return if we found one. */ - return QZ_ListModes(&p, 1, 0, 8); -} - class FullscreenSubdriver: public CocoaSubdriver { CGDirectDisplayID display_id; ///< 0 == main display (only support single display) CFDictionaryRef cur_mode; ///< current mode of the display @@ -592,4 +520,5 @@ CocoaSubdriver *QZ_CreateFullscreenSubdriver(int width, int height, int bpp) return ret; } +#endif /* MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_9 */ #endif /* WITH_COCOA */