Ticket #847: t847_osx-getvideomode-v2.patch

File t847_osx-getvideomode-v2.patch, 1.3 KB (added by Echelon9, 12 years ago)
  • source/lib/sysdep/os/osx/osx.cpp

     
    2828#include "lib/sysdep/gfx.h"
    2929
    3030#include <mach-o/dyld.h>
     31#include <ApplicationServices/ApplicationServices.h>
    3132
    3233
    3334// "copy" text into the clipboard. replaces previous contents.
     
    6162
    6263Status GetVideoMode(int* xres, int* yres, int* bpp, int* freq)
    6364{
    64     // TODO Implement
    65     return ERR::NOT_SUPPORTED;  // NOWARN
     65    CGDisplayModeRef currentMode = CGDisplayCopyDisplayMode(kCGDirectMainDisplay);
     66    CFStringRef pixelEncoding = CGDisplayModeCopyPixelEncoding(currentMode);
     67     
     68    if(xres)
     69        *xres = (int)CGDisplayPixelsWide(kCGDirectMainDisplay);
     70    if(yres)
     71        *yres = (int)CGDisplayPixelsHigh(kCGDirectMainDisplay);
     72    if(bpp)
     73        // *bpp  = (int)CGDisplayBitsPerPixel(kCGDirectMainDisplay); -- CGDisplayBitsPerPixel() deprecated in OS X 10.7
     74        if (CFStringCompare(pixelEncoding,CFSTR(IO32BitDirectPixels),0)==0)
     75            *bpp = 32;
     76        else if (CFStringCompare(pixelEncoding,CFSTR(IO16BitDirectPixels),0)==0)
     77            *bpp = 16;
     78        else
     79            *bpp = 8;
     80    if(freq)
     81        *freq = (int)CGDisplayModeGetRefreshRate(currentMode);
     82   
     83    return INFO::OK;
    6684}
    6785
    6886Status GetMonitorSize(int* xres, int* yres, int* bpp, int* freq)