modernizing API

This commit is contained in:
Stefan Csomor
2017-06-14 21:58:42 +02:00
parent df898c0e44
commit 75831d232c

View File

@@ -227,22 +227,36 @@ static int wxCFDictKeyToInt( CFDictionaryRef desc, CFStringRef key )
return num;
}
static int wxOSXCGDisplayModeGetBitsPerPixel( CGDisplayModeRef theValue )
{
wxCFRef<CFStringRef> 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<CFArrayRef> 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<CGDisplayModeRef> 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<CFArrayRef> 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;
}