HIThemeBrushCreateCGColor seems to have become very CPU-expensive, cache the results for better performance

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@73208 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Stefan Csomor
2012-12-19 15:30:40 +00:00
parent c1c4c9b471
commit 4e07c80645

View File

@@ -245,11 +245,28 @@ CGColorSpaceRef wxMacGetGenericRGBColorSpace()
#if wxOSX_USE_COCOA_OR_CARBON
CGColorRef wxMacCreateCGColorFromHITheme( ThemeBrush brush )
{
const int maxcachedbrush = 58+5; // negative indices are for metabrushes, cache down to -5)
int brushindex = brush+5;
if ( brushindex < 0 || brush > brushindex )
{
CGColorRef color ;
HIThemeBrushCreateCGColor( brush, &color );
return color;
}
else
{
static bool inited = false;
static CGColorRef themecolors[maxcachedbrush+1];
if ( !inited )
{
for ( int i = 0 ; i <= maxcachedbrush ; ++i )
HIThemeBrushCreateCGColor( i-5, &themecolors[i] );
inited = true;
}
return CGColorRetain(themecolors[brushindex ]);
}
}
//---------------------------------------------------------------------------
// Mac Specific string utility functions