| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/themes/theme_service.h" | 5 #include "chrome/browser/themes/theme_service.h" |
| 6 | 6 |
| 7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "chrome/browser/themes/browser_theme_pack.h" | 10 #include "chrome/browser/themes/browser_theme_pack.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 | 37 |
| 38 // Check to see if we already have the image in the cache. | 38 // Check to see if we already have the image in the cache. |
| 39 NSImageMap::const_iterator nsimage_iter = nsimage_cache_.find(id); | 39 NSImageMap::const_iterator nsimage_iter = nsimage_cache_.find(id); |
| 40 if (nsimage_iter != nsimage_cache_.end()) | 40 if (nsimage_iter != nsimage_cache_.end()) |
| 41 return nsimage_iter->second; | 41 return nsimage_iter->second; |
| 42 | 42 |
| 43 // Why don't we load the file directly into the image instead of the whole | 43 // Why don't we load the file directly into the image instead of the whole |
| 44 // SkBitmap > native conversion? | 44 // SkBitmap > native conversion? |
| 45 // - For consistency with other platforms. | 45 // - For consistency with other platforms. |
| 46 // - To get the generated tinted images. | 46 // - To get the generated tinted images. |
| 47 SkBitmap* bitmap = GetBitmapNamed(id); | 47 std::vector<SkBitmap*> bitmaps; |
| 48 NSImage* nsimage = gfx::SkBitmapToNSImage(*bitmap); | 48 if (GetBitmapsNamed(id, bitmaps)) { |
| 49 NSImage* nsimage = gfx::SkBitmapsToNSImage(bitmaps); |
| 49 | 50 |
| 50 // We loaded successfully. Cache the image. | 51 // We loaded successfully. Cache the image. |
| 51 if (nsimage) { | 52 if (nsimage) { |
| 52 nsimage_cache_[id] = [nsimage retain]; | 53 nsimage_cache_[id] = [nsimage retain]; |
| 53 return nsimage; | 54 return nsimage; |
| 55 } |
| 54 } | 56 } |
| 55 | 57 |
| 56 // We failed to retrieve the bitmap, show a debugging red square. | 58 // We failed to retrieve the bitmap, show a debugging red square. |
| 57 LOG(WARNING) << "Unable to load NSImage with id " << id; | 59 LOG(WARNING) << "Unable to load NSImage with id " << id; |
| 58 NOTREACHED(); // Want to assert in debug mode. | 60 NOTREACHED(); // Want to assert in debug mode. |
| 59 | 61 |
| 60 static NSImage* empty_image = NULL; | 62 static NSImage* empty_image = NULL; |
| 61 if (!empty_image) { | 63 if (!empty_image) { |
| 62 // The placeholder image is bright red so people notice the problem. This | 64 // The placeholder image is bright red so people notice the problem. This |
| 63 // image will be leaked, but this code should never be hit. | 65 // image will be leaked, but this code should never be hit. |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 } | 306 } |
| 305 nscolor_cache_.clear(); | 307 nscolor_cache_.clear(); |
| 306 | 308 |
| 307 // Free gradients. | 309 // Free gradients. |
| 308 for (NSGradientMap::iterator i = nsgradient_cache_.begin(); | 310 for (NSGradientMap::iterator i = nsgradient_cache_.begin(); |
| 309 i != nsgradient_cache_.end(); i++) { | 311 i != nsgradient_cache_.end(); i++) { |
| 310 [i->second release]; | 312 [i->second release]; |
| 311 } | 313 } |
| 312 nsgradient_cache_.clear(); | 314 nsgradient_cache_.clear(); |
| 313 } | 315 } |
| OLD | NEW |