diff --git a/src/osx/core/display.cpp b/src/osx/core/display.cpp index 11696b8d37..b77018084b 100644 --- a/src/osx/core/display.cpp +++ b/src/osx/core/display.cpp @@ -227,22 +227,36 @@ static int wxCFDictKeyToInt( CFDictionaryRef desc, CFStringRef key ) return num; } +static int wxOSXCGDisplayModeGetBitsPerPixel( CGDisplayModeRef theValue ) +{ + wxCFRef pixelEncoding( CGDisplayModeCopyPixelEncoding(theValue) ); + int depth = 0; + if ( CFStringCompare( pixelEncoding, CFSTR(IO32BitDirectPixels) , kCFCompareCaseInsensitive) == kCFCompareEqualTo ) + depth = 32; + else if ( CFStringCompare( pixelEncoding, CFSTR(IO16BitDirectPixels) , kCFCompareCaseInsensitive) == kCFCompareEqualTo ) + depth = 16; + else if ( CFStringCompare( pixelEncoding, CFSTR(IO8BitIndexedPixels) , kCFCompareCaseInsensitive) == kCFCompareEqualTo ) + depth = 8; + + return depth; +} + wxArrayVideoModes wxDisplayImplMacOSX::GetModes(const wxVideoMode& mode) const { wxArrayVideoModes resultModes; - CFArrayRef theArray = CGDisplayAvailableModes( m_id ); - + wxCFRef theArray(CGDisplayCopyAllDisplayModes( m_id ,NULL ) ); + for (CFIndex i = 0; i < CFArrayGetCount(theArray); ++i) { - CFDictionaryRef theValue = (CFDictionaryRef) CFArrayGetValueAtIndex( theArray, i ); - + CGDisplayModeRef theValue = (CGDisplayModeRef) CFArrayGetValueAtIndex( theArray, i ); + wxVideoMode theMode( - wxCFDictKeyToInt( theValue, kCGDisplayWidth ), - wxCFDictKeyToInt( theValue, kCGDisplayHeight ), - wxCFDictKeyToInt( theValue, kCGDisplayBitsPerPixel ), - wxCFDictKeyToInt( theValue, kCGDisplayRefreshRate )); - + CGDisplayModeGetWidth(theValue), + CGDisplayModeGetHeight(theValue), + wxOSXCGDisplayModeGetBitsPerPixel(theValue), + CGDisplayModeGetRefreshRate(theValue)); + if (theMode.Matches( mode )) resultModes.Add( theMode ); } @@ -252,13 +266,13 @@ wxArrayVideoModes wxDisplayImplMacOSX::GetModes(const wxVideoMode& mode) const wxVideoMode wxDisplayImplMacOSX::GetCurrentMode() const { - CFDictionaryRef theValue = CGDisplayCurrentMode( m_id ); - + wxCFRef theValue( CGDisplayCopyDisplayMode( m_id ) ); + return wxVideoMode( - wxCFDictKeyToInt( theValue, kCGDisplayWidth ), - wxCFDictKeyToInt( theValue, kCGDisplayHeight ), - wxCFDictKeyToInt( theValue, kCGDisplayBitsPerPixel ), - wxCFDictKeyToInt( theValue, kCGDisplayRefreshRate )); + CGDisplayModeGetWidth(theValue), + CGDisplayModeGetHeight(theValue), + wxOSXCGDisplayModeGetBitsPerPixel(theValue), + CGDisplayModeGetRefreshRate(theValue)); } bool wxDisplayImplMacOSX::ChangeMode( const wxVideoMode& mode ) @@ -271,20 +285,32 @@ bool wxDisplayImplMacOSX::ChangeMode( const wxVideoMode& mode ) } #endif - boolean_t bExactMatch; - CFDictionaryRef theCGMode = CGDisplayBestModeForParametersAndRefreshRate( - m_id, - (size_t)mode.GetDepth(), - (size_t)mode.GetWidth(), - (size_t)mode.GetHeight(), - (double)mode.GetRefresh(), - &bExactMatch ); - - bool bOK = bExactMatch; - - if (bOK) - bOK = CGDisplaySwitchToMode( m_id, theCGMode ) == CGDisplayNoErr; - + wxCHECK_MSG( mode.GetWidth() && mode.GetHeight(), false, + wxT("at least the width and height must be specified") ); + + bool bOK = false; + wxCFRef theArray(CGDisplayCopyAllDisplayModes( m_id ,NULL ) ); + + for (CFIndex i = 0; i < CFArrayGetCount(theArray); ++i) + { + CGDisplayModeRef theValue = (CGDisplayModeRef) CFArrayGetValueAtIndex( theArray, i ); + + wxVideoMode theMode( + CGDisplayModeGetWidth(theValue), + CGDisplayModeGetHeight(theValue), + wxOSXCGDisplayModeGetBitsPerPixel(theValue), + CGDisplayModeGetRefreshRate(theValue)); + + if ( theMode.GetWidth() == mode.GetWidth() && theMode.GetHeight() == mode.GetHeight() && + ( mode.GetDepth() == 0 || theMode.GetDepth() == mode.GetDepth() ) && + ( mode.GetRefresh() == 0 || theMode.GetRefresh() == mode.GetRefresh() ) ) + { + CGDisplaySetDisplayMode( m_id, theValue , NULL ); + bOK = true; + break; + } + } + return bOK; }