]> git.saurik.com Git - wxWidgets.git/commitdiff
HIThemeBrushCreateCGColor seems to have become very CPU-expensive, cache the results...
authorStefan Csomor <csomor@advancedconcepts.ch>
Wed, 19 Dec 2012 15:30:40 +0000 (15:30 +0000)
committerStefan Csomor <csomor@advancedconcepts.ch>
Wed, 19 Dec 2012 15:30:40 +0000 (15:30 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@73208 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/osx/utils_osx.cpp

index 7eb431ad8660ca5f12c82e7ce1c57733ce4942ed..da98e5371a0edab41fabc195e239947025e86877 100644 (file)
@@ -246,9 +246,26 @@ CGColorSpaceRef wxMacGetGenericRGBColorSpace()
 
 CGColorRef wxMacCreateCGColorFromHITheme( ThemeBrush brush )
 {
-    CGColorRef color ;
-    HIThemeBrushCreateCGColor( brush, &color );
-    return color;
+    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 ]);
+    }
 }
 
 //---------------------------------------------------------------------------