Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5489)

Unified Diff: chrome/browser/themes/browser_theme_pack.cc

Issue 6849030: Add support for multi resolution icons (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/themes/browser_theme_pack.cc
diff --git a/chrome/browser/themes/browser_theme_pack.cc b/chrome/browser/themes/browser_theme_pack.cc
index 274cae31a50c9cbbeeb0e0543efd6f2f08dca7b4..b39dc4a9d21cf7c541356eb729ae9b24ee31c205 100644
--- a/chrome/browser/themes/browser_theme_pack.cc
+++ b/chrome/browser/themes/browser_theme_pack.cc
@@ -19,6 +19,7 @@
#include "ui/base/resource/data_pack.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/codec/png_codec.h"
+#include "ui/gfx/codec/tiff_codec.h"
#include "ui/gfx/skbitmap_operations.h"
namespace {
@@ -323,6 +324,10 @@ BrowserThemePack::~BrowserThemePack() {
}
STLDeleteValues(&prepared_images_);
+ for (MultiResImageCache::iterator i = loaded_images_.begin();
+ i != loaded_images_.end(); ++i) {
+ STLDeleteContainerPointers(i->second->begin(), i->second->end());
+ }
STLDeleteValues(&loaded_images_);
}
@@ -493,19 +498,34 @@ bool BrowserThemePack::GetDisplayProperty(int id, int* result) const {
}
SkBitmap* BrowserThemePack::GetBitmapNamed(int idr_id) const {
+ std::vector<SkBitmap*> bitmaps;
+ if (!GetBitmapsNamed(idr_id, bitmaps))
+ return NULL;
+ if (bitmaps.empty())
+ return NULL;
+ return *bitmaps.begin();
+}
+
+bool BrowserThemePack::GetBitmapsNamed(
+ int idr_id, std::vector<SkBitmap*>& bitmaps) const {
int prs_id = GetPersistentIDByIDR(idr_id);
if (prs_id == -1)
- return NULL;
+ return false;
// Check our cache of prepared images, first.
ImageCache::const_iterator image_iter = prepared_images_.find(prs_id);
- if (image_iter != prepared_images_.end())
- return image_iter->second;
+ if (image_iter != prepared_images_.end()) {
+ bitmaps.push_back(image_iter->second);
+ return true;
+ }
// Check if we've already loaded this image.
- image_iter = loaded_images_.find(prs_id);
- if (image_iter != loaded_images_.end())
- return image_iter->second;
+ MultiResImageCache::const_iterator multi_image_iter =
+ loaded_images_.find(prs_id);
+ if (multi_image_iter != loaded_images_.end()) {
+ bitmaps = *(multi_image_iter->second);
+ return true;
+ }
scoped_refptr<RefCountedMemory> memory;
if (data_pack_.get()) {
@@ -518,22 +538,32 @@ SkBitmap* BrowserThemePack::GetBitmapNamed(int idr_id) const {
}
if (memory.get()) {
- // Decode the PNG.
+ // Try to decode it as a PNG.
SkBitmap bitmap;
- if (!gfx::PNGCodec::Decode(memory->front(), memory->size(),
- &bitmap)) {
- NOTREACHED() << "Unable to decode theme image resource " << idr_id
- << " from saved DataPack.";
- return NULL;
+ if (gfx::PNGCodec::Decode(memory->front(), memory->size(),&bitmap)) {
+ std::vector<SkBitmap*>* bitmaps_ptr = new std::vector<SkBitmap*>;
+ bitmaps_ptr->push_back(new SkBitmap(bitmap));
+ loaded_images_[prs_id] = bitmaps_ptr;
+ return true;
}
- SkBitmap* ret = new SkBitmap(bitmap);
- loaded_images_[prs_id] = ret;
+ // Try to decode it as a TIFF.
+ std::vector<SkBitmap> bitmaps;
+ if (gfx::TIFFCodec::Decode(memory->front(), memory->size(), bitmaps)) {
+ std::vector<SkBitmap*>* bitmaps_ptr = new std::vector<SkBitmap*>;
+ for (std::vector<SkBitmap>::iterator it = bitmaps.begin();
+ it != bitmaps.end(); ++it) {
+ bitmaps_ptr->push_back(new SkBitmap(*it));
+ }
+ loaded_images_[prs_id] = bitmaps_ptr;
+ return true;
+ }
- return ret;
+ NOTREACHED() << "Unable to decode theme image resource " << idr_id
+ << " from saved DataPack.";
}
- return NULL;
+ return false;
}
RefCountedMemory* BrowserThemePack::GetRawData(int idr_id) const {

Powered by Google App Engine
This is Rietveld 408576698