Changeset 10897

Timestamp:
Jan 12, 2012, 12:41:59 AM (13 years ago)
Author:
ben
Message:

Implements GetVideoMode on OS X (10.6+ compatible), based on patch by Echelon9. Fixes #847.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • ps/trunk/source/lib/sysdep/os/osx/osx.cpp

    r9582 r10897  
    2929
    3030#include <mach-o/dyld.h>
     31
    3132
    3233
     
    6263Status GetVideoMode(int* xres, int* yres, int* bpp, int* freq)
    6364{
    64     // TODO Implement
    65     return ERR::NOT_SUPPORTED;  // NOWARN
     65    // TODO: This breaks 10.5 compatibility, as CGDisplayCopyDisplayMode
     66    //  and CGDisplayModeCopyPixelEncoding were not available
     67    CGDisplayModeRef currentMode = CGDisplayCopyDisplayMode(kCGDirectMainDisplay);
     68
     69    if(xres)
     70        *xres = (int)CGDisplayPixelsWide(kCGDirectMainDisplay);
     71
     72    if(yres)
     73        *yres = (int)CGDisplayPixelsHigh(kCGDirectMainDisplay);
     74
     75    if(bpp)
     76    {
     77        // CGDisplayBitsPerPixel was deprecated in OS X 10.6
     78        CFStringRef pixelEncoding = CGDisplayModeCopyPixelEncoding(currentMode);
     79        if (CFStringCompare(pixelEncoding, CFSTR(IO32BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo)
     80            *bpp = 32;
     81        else if (CFStringCompare(pixelEncoding, CFSTR(IO16BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo)
     82            *bpp = 16;
     83        else if (CFStringCompare(pixelEncoding, CFSTR(IO8BitIndexedPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo)
     84            *bpp = 8;
     85        else    // error
     86            *bpp = 0;
     87
     88        // We're responsible for this
     89        CFRelease(pixelEncoding);
     90    }
     91
     92    if(freq)
     93        *freq = (int)CGDisplayModeGetRefreshRate(currentMode);
     94
     95    // We're responsible for this
     96    CGDisplayModeRelease(currentMode);
     97
     98    return INFO::OK;
    6699}
    67100
Note: See TracChangeset for help on using the changeset viewer.