From ed237ff1a68acb517df0d737c8b6d44d783e6269 Mon Sep 17 00:00:00 2001 From: historic_bruno Date: Wed, 11 Jan 2012 23:41:59 +0000 Subject: [PATCH] Implements GetVideoMode on OS X (10.6+ compatible), based on patch by Echelon9. Fixes #847. This was SVN commit r10897. --- source/lib/sysdep/os/osx/osx.cpp | 37 ++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/source/lib/sysdep/os/osx/osx.cpp b/source/lib/sysdep/os/osx/osx.cpp index d4d5af43fd..b3fd13a7c7 100644 --- a/source/lib/sysdep/os/osx/osx.cpp +++ b/source/lib/sysdep/os/osx/osx.cpp @@ -28,6 +28,7 @@ #include "lib/sysdep/gfx.h" #include +#include // "copy" text into the clipboard. replaces previous contents. @@ -61,8 +62,40 @@ namespace gfx { Status GetVideoMode(int* xres, int* yres, int* bpp, int* freq) { - // TODO Implement - return ERR::NOT_SUPPORTED; // NOWARN + // TODO: This breaks 10.5 compatibility, as CGDisplayCopyDisplayMode + // and CGDisplayModeCopyPixelEncoding were not available + CGDisplayModeRef currentMode = CGDisplayCopyDisplayMode(kCGDirectMainDisplay); + + if(xres) + *xres = (int)CGDisplayPixelsWide(kCGDirectMainDisplay); + + if(yres) + *yres = (int)CGDisplayPixelsHigh(kCGDirectMainDisplay); + + if(bpp) + { + // CGDisplayBitsPerPixel was deprecated in OS X 10.6 + CFStringRef pixelEncoding = CGDisplayModeCopyPixelEncoding(currentMode); + if (CFStringCompare(pixelEncoding, CFSTR(IO32BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo) + *bpp = 32; + else if (CFStringCompare(pixelEncoding, CFSTR(IO16BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo) + *bpp = 16; + else if (CFStringCompare(pixelEncoding, CFSTR(IO8BitIndexedPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo) + *bpp = 8; + else // error + *bpp = 0; + + // We're responsible for this + CFRelease(pixelEncoding); + } + + if(freq) + *freq = (int)CGDisplayModeGetRefreshRate(currentMode); + + // We're responsible for this + CGDisplayModeRelease(currentMode); + + return INFO::OK; } Status GetMonitorSize(int* xres, int* yres, int* bpp, int* freq)