GetMonitorAspectRatio.
This commit is contained in:
@@ -12,6 +12,12 @@
|
|||||||
#import <OpenGL/gl.h>
|
#import <OpenGL/gl.h>
|
||||||
#import <mach-o/dyld.h>
|
#import <mach-o/dyld.h>
|
||||||
|
|
||||||
|
// Bad header!
|
||||||
|
extern "C" {
|
||||||
|
#include <IOKit/graphics/IOGraphicsLib.h>
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static const unsigned int g_iStyleMask = NSTitledWindowMask | NSClosableWindowMask |
|
static const unsigned int g_iStyleMask = NSTitledWindowMask | NSClosableWindowMask |
|
||||||
NSMiniaturizableWindowMask | NSResizableWindowMask;
|
NSMiniaturizableWindowMask | NSResizableWindowMask;
|
||||||
static bool g_bResized;
|
static bool g_bResized;
|
||||||
@@ -364,7 +370,8 @@ void LowLevelWindow_Cocoa::SetActualParamsFromMode( CFDictionaryRef mode )
|
|||||||
{
|
{
|
||||||
SInt32 rate;
|
SInt32 rate;
|
||||||
|
|
||||||
if( CFNumberGetValue( (CFNumberRef)CFDictionaryGetValue(mode, CFSTR("RefreshRate")), kCFNumberSInt32Type, &rate) )
|
if( !CFNumberGetValue( (CFNumberRef)CFDictionaryGetValue(mode, CFSTR("RefreshRate")), kCFNumberSInt32Type, &rate) )
|
||||||
|
rate = 60;
|
||||||
m_CurrentParams.rate = rate;
|
m_CurrentParams.rate = rate;
|
||||||
|
|
||||||
if( !m_CurrentParams.windowed )
|
if( !m_CurrentParams.windowed )
|
||||||
@@ -387,6 +394,20 @@ void LowLevelWindow_Cocoa::SetActualParamsFromMode( CFDictionaryRef mode )
|
|||||||
m_CurrentParams.bpp = CGDisplayBitsPerPixel( kCGDirectMainDisplay );
|
m_CurrentParams.bpp = CGDisplayBitsPerPixel( kCGDirectMainDisplay );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int GetIntValue( CFTypeRef r )
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
if( !r || CFGetTypeID(r) != CFNumberGetTypeID() || !CFNumberGetValue(CFNumberRef(r), kCFNumberIntType, &ret) )
|
||||||
|
return 0;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool GetBoolValue( CFTypeRef r )
|
||||||
|
{
|
||||||
|
return r && CFGetTypeID( r ) == CFBooleanGetTypeID() && CFBooleanGetValue( CFBooleanRef(r) );
|
||||||
|
}
|
||||||
|
|
||||||
void LowLevelWindow_Cocoa::GetDisplayResolutions( DisplayResolutions &dr ) const
|
void LowLevelWindow_Cocoa::GetDisplayResolutions( DisplayResolutions &dr ) const
|
||||||
{
|
{
|
||||||
CFArrayRef modes = CGDisplayAvailableModes( kCGDirectMainDisplay );
|
CFArrayRef modes = CGDisplayAvailableModes( kCGDirectMainDisplay );
|
||||||
@@ -396,15 +417,15 @@ void LowLevelWindow_Cocoa::GetDisplayResolutions( DisplayResolutions &dr ) const
|
|||||||
for( CFIndex i = 0; i < count; ++i )
|
for( CFIndex i = 0; i < count; ++i )
|
||||||
{
|
{
|
||||||
CFDictionaryRef dict = (CFDictionaryRef)CFArrayGetValueAtIndex( modes, i );
|
CFDictionaryRef dict = (CFDictionaryRef)CFArrayGetValueAtIndex( modes, i );
|
||||||
CFNumberRef num = (CFNumberRef)CFDictionaryGetValue( dict, CFSTR("Width") );
|
int width = GetIntValue( CFDictionaryGetValue(dict, kCGDisplayWidth) );
|
||||||
SInt32 width, height;
|
int height = GetIntValue( CFDictionaryGetValue(dict, kCGDisplayHeight) );
|
||||||
|
CFTypeRef safe = CFDictionaryGetValue( dict, kCGDisplayModeIsSafeForHardware );
|
||||||
|
//bool stretched = GetBoolValue( CFDictionaryGetValue(dict, kCGDisplayModeIsStretched) );
|
||||||
|
|
||||||
if( !num || !CFNumberGetValue(num, kCFNumberSInt32Type, &width) )
|
if( !width || !height )
|
||||||
continue;
|
continue;
|
||||||
num = (CFNumberRef)CFDictionaryGetValue( dict, CFSTR("Height") );
|
if( safe && !GetBoolValue( safe ) )
|
||||||
if( !num || !CFNumberGetValue(num, kCFNumberSInt32Type, &height) )
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
DisplayResolution res = { width, height };
|
DisplayResolution res = { width, height };
|
||||||
dr.s.insert( res );
|
dr.s.insert( res );
|
||||||
}
|
}
|
||||||
@@ -413,6 +434,15 @@ void LowLevelWindow_Cocoa::GetDisplayResolutions( DisplayResolutions &dr ) const
|
|||||||
|
|
||||||
float LowLevelWindow_Cocoa::GetMonitorAspectRatio() const
|
float LowLevelWindow_Cocoa::GetMonitorAspectRatio() const
|
||||||
{
|
{
|
||||||
|
io_connect_t displayPort = CGDisplayIOServicePort( CGMainDisplayID() );
|
||||||
|
CFDictionaryRef dict = IODisplayCreateInfoDictionary( displayPort, 0 );
|
||||||
|
int width = GetIntValue( CFDictionaryGetValue(dict, CFSTR(kDisplayHorizontalImageSize)) );
|
||||||
|
int height = GetIntValue( CFDictionaryGetValue(dict, CFSTR(kDisplayVerticalImageSize)) );
|
||||||
|
|
||||||
|
CFRelease( dict );
|
||||||
|
|
||||||
|
if( width && height )
|
||||||
|
return float(width)/height;
|
||||||
return 4/3.f;
|
return 4/3.f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user