diff options
author | avi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-02 21:46:47 +0000 |
---|---|---|
committer | avi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-02 21:46:47 +0000 |
commit | cfd0b58808dcf60b03a2fa434b655f850087c5f4 (patch) | |
tree | 026ad375656d31efedf609a3877af2eb7a8bbd57 /chrome/browser/browser_theme_provider_mac.mm | |
parent | c2def1c60e5809cf6f6171f980c56f2e4b48109e (diff) | |
download | chromium_src-cfd0b58808dcf60b03a2fa434b655f850087c5f4.zip chromium_src-cfd0b58808dcf60b03a2fa434b655f850087c5f4.tar.gz chromium_src-cfd0b58808dcf60b03a2fa434b655f850087c5f4.tar.bz2 |
Aggressively cache theme image pattern colors.
BUG=http://crbug.com/37106 (I hope)
TEST=no visible change, just faster
Review URL: http://codereview.chromium.org/661396
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@40439 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/browser_theme_provider_mac.mm')
-rw-r--r-- | chrome/browser/browser_theme_provider_mac.mm | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/chrome/browser/browser_theme_provider_mac.mm b/chrome/browser/browser_theme_provider_mac.mm index f455d70..805952d 100644 --- a/chrome/browser/browser_theme_provider_mac.mm +++ b/chrome/browser/browser_theme_provider_mac.mm @@ -73,6 +73,32 @@ NSImage* BrowserThemeProvider::GetNSImageNamed(int id, return empty_image; } +NSColor* BrowserThemeProvider::GetNSImageColorNamed(int id, + bool allow_default) const { + DCHECK(CalledOnValidThread()); + + // Check to see if we already have the color in the cache. + NSColorMap::const_iterator nscolor_iter = nscolor_cache_.find(id); + if (nscolor_iter != nscolor_cache_.end()) { + bool cached_is_default = nscolor_iter->second.second; + if (!cached_is_default || allow_default) + return nscolor_iter->second.first; + } + + NSImage* image = GetNSImageNamed(id, allow_default); + if (!image) + return nil; + NSColor* image_color = [NSColor colorWithPatternImage:image]; + + // We loaded successfully. Cache the color. + if (image_color) { + nscolor_cache_[id] = std::make_pair([image_color retain], + !HasCustomImage(id)); + } + + return imageColor; +} + NSColor* BrowserThemeProvider::GetNSColor(int id, bool allow_default) const { DCHECK(CalledOnValidThread()); |