From 74645fcb7cea93f471bd0f8adfe9fa1c735c818c Mon Sep 17 00:00:00 2001 From: "avi@chromium.org" Date: Wed, 1 Jul 2009 15:01:06 +0000 Subject: Switch to getting theme images via SkBitmap. BUG=none TEST=none Review URL: http://codereview.chromium.org/151104 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19729 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/browser_theme_provider_mac.mm | 50 ++++++++++++++++++---------- 1 file changed, 32 insertions(+), 18 deletions(-) diff --git a/chrome/browser/browser_theme_provider_mac.mm b/chrome/browser/browser_theme_provider_mac.mm index a1709f9..4c52fe1 100644 --- a/chrome/browser/browser_theme_provider_mac.mm +++ b/chrome/browser/browser_theme_provider_mac.mm @@ -7,35 +7,49 @@ #import #include "base/logging.h" +#include "skia/ext/skia_utils_mac.h" NSImage* BrowserThemeProvider::GetNSImageNamed(int id) { DCHECK(CalledOnValidThread()); + if (!HasCustomImage(id)) + return nil; + // Check to see if we already have the image in the cache. NSImageMap::const_iterator found = nsimage_cache_.find(id); if (found != nsimage_cache_.end()) return found->second; - // Why do we load the file directly into the image rather than doing the whole - // SkBitmap > native conversion that others do? Going direct means: - // - we use the color profiles and other embedded info in the image file - // - we don't fall back to the default resources which we don't use on the Mac - std::vector raw_data; - if (ReadThemeFileData(id, &raw_data)) { - NSData* ns_data = [NSData dataWithBytes:&raw_data.front() - length:raw_data.size()]; - if (ns_data) { - NSImage* nsimage = [[NSImage alloc] initWithData:ns_data]; - - // We loaded successfully. Cache the image. - if (nsimage) { - nsimage_cache_[id] = nsimage; - return nsimage; - } - } + // Why don't we load the file directly into the image instead of the whole + // SkBitmap > native conversion? + // - For consistency with other platforms. + // - To get the generated tinted images. + SkBitmap* bitmap = GetBitmapNamed(id); + NSImage* nsimage = gfx::SkBitmapToNSImage(*bitmap); + + // We loaded successfully. Cache the image. + if (nsimage) { + nsimage_cache_[id] = [nsimage retain]; + return nsimage; + } + + // We failed to retrieve the bitmap, show a debugging red square. + LOG(WARNING) << "Unable to load NSImage with id " << id; + NOTREACHED(); // Want to assert in debug mode. + + static NSImage* empty_image = NULL; + if (!empty_image) { + // The placeholder image is bright red so people notice the problem. This + // image will be leaked, but this code should never be hit. + NSRect image_rect = NSMakeRect(0, 0, 32, 32); + empty_image = [[NSImage alloc] initWithSize:image_rect.size]; + [empty_image lockFocus]; + [[NSColor redColor] set]; + NSRectFill(image_rect); + [empty_image unlockFocus]; } - return nil; + return empty_image; } void BrowserThemeProvider::FreePlatformImages() { -- cgit v1.1