| Index: ui/base/resource/resource_bundle.cc
|
| diff --git a/ui/base/resource/resource_bundle.cc b/ui/base/resource/resource_bundle.cc
|
| index 56b37619be579c567d53aa2031ca4b4fb83c6d13..95a12db6270002555e95d61bca7da4525481f551 100644
|
| --- a/ui/base/resource/resource_bundle.cc
|
| +++ b/ui/base/resource/resource_bundle.cc
|
| @@ -12,6 +12,7 @@
|
| #include "third_party/skia/include/core/SkBitmap.h"
|
| #include "ui/base/resource/data_pack.h"
|
| #include "ui/gfx/codec/png_codec.h"
|
| +#include "ui/gfx/codec/tiff_codec.h"
|
| #include "ui/gfx/font.h"
|
| #include "ui/gfx/image.h"
|
|
|
| @@ -108,33 +109,80 @@ SkBitmap* ResourceBundle::GetBitmapNamed(int resource_id) {
|
| return const_cast<SkBitmap*>(bitmap);
|
| }
|
|
|
| +bool ResourceBundle::GetBitmapsNamed(int resource_id,
|
| + std::vector<SkBitmap*>& bitmaps) {
|
| + std::vector<gfx::Image*> images;
|
| + if (!GetImagesNamed(resource_id, images))
|
| + return false;
|
| +
|
| + for (std::vector<gfx::Image*>::iterator it = images.begin();
|
| + it != images.end(); ++it) {
|
| + const SkBitmap* bitmap = static_cast<const SkBitmap*>(**it);
|
| + bitmaps.push_back(const_cast<SkBitmap*>(bitmap));
|
| + }
|
| + return true;
|
| +}
|
| +
|
| gfx::Image& ResourceBundle::GetImageNamed(int resource_id) {
|
| - // Check to see if the image is already in the cache.
|
| - {
|
| - base::AutoLock lock_scope(*lock_);
|
| - ImageMap::const_iterator found = images_.find(resource_id);
|
| - if (found != images_.end())
|
| - return *found->second;
|
| + std::vector<gfx::Image*> images;
|
| + if (GetImagesNamed(resource_id, images)) {
|
| + if (!images.empty())
|
| + return **images.begin();
|
| }
|
|
|
| - scoped_ptr<SkBitmap> bitmap(LoadBitmap(resources_data_, resource_id));
|
| - if (bitmap.get()) {
|
| - // The load was successful, so cache the image.
|
| - base::AutoLock lock_scope(*lock_);
|
| + // The load failed to retrieve the image; show a debugging red square.
|
| + NOTREACHED();
|
| + return *GetEmptyImage();
|
| +}
|
|
|
| - // Another thread raced the load and has already cached the image.
|
| - if (images_.count(resource_id))
|
| - return *images_[resource_id];
|
| +bool ResourceBundle::GetImagesNamed(int resource_id,
|
| + std::vector<gfx::Image*>& images) {
|
| + // Check to see if the image is already in the cache.
|
| + if (GetImagesFromCacheNamed(resource_id, images)) {
|
| + return true;
|
| + }
|
|
|
| - gfx::Image* image = new gfx::Image(bitmap.release());
|
| - images_[resource_id] = image;
|
| - return *image;
|
| + std::vector<SkBitmap> bitmaps;
|
| + if (LoadBitmaps(resources_data_, resource_id, bitmaps)) {
|
| + // The load was successful, so cache the images.
|
| + {
|
| + base::AutoLock lock_scope(*lock_);
|
| +
|
| + // Has another thread raced the load and has already cached the image?
|
| + if (!images_.count(resource_id)) {
|
| + std::vector<gfx::Image*>* images_ptr = new std::vector<gfx::Image*>;
|
| + for (std::vector<SkBitmap>::iterator it = bitmaps.begin();
|
| + it != bitmaps.end(); ++it) {
|
| + SkBitmap* bitmap = new SkBitmap(*it);
|
| + gfx::Image* image = new gfx::Image(bitmap);
|
| + images_ptr->push_back(image);
|
| + images_[resource_id] = images_ptr;
|
| + }
|
| + }
|
| + }
|
| + return GetImagesFromCacheNamed(resource_id, images);
|
| }
|
|
|
| - // The load failed to retrieve the image; show a debugging red square.
|
| + // The load failed to retrieve the image.
|
| LOG(WARNING) << "Unable to load image with id " << resource_id;
|
| NOTREACHED(); // Want to assert in debug mode.
|
| - return *GetEmptyImage();
|
| + return false;
|
| +}
|
| +
|
| +bool ResourceBundle::GetImagesFromCacheNamed(int resource_id,
|
| + std::vector<gfx::Image*>& images) {
|
| + base::AutoLock lock_scope(*lock_);
|
| +
|
| + ImageMap::const_iterator found = images_.find(resource_id);
|
| + if (found == images_.end())
|
| + return false;
|
| +
|
| + std::vector<gfx::Image*>* found_images = found->second;
|
| + for (std::vector<gfx::Image*>::const_iterator it = found_images->begin();
|
| + it != found_images->end(); ++it) {
|
| + images.push_back(*it);
|
| + }
|
| + return true;
|
| }
|
|
|
| #if !defined(OS_MACOSX) && !defined(OS_LINUX)
|
| @@ -194,9 +242,10 @@ ResourceBundle::ResourceBundle()
|
| }
|
|
|
| void ResourceBundle::FreeImages() {
|
| - STLDeleteContainerPairSecondPointers(images_.begin(),
|
| - images_.end());
|
| - images_.clear();
|
| + for (ImageMap::iterator i = images_.begin(); i != images_.end(); ++i) {
|
| + STLDeleteContainerPointers(i->second->begin(), i->second->end());
|
| + }
|
| + STLDeleteValues(&images_);
|
| }
|
|
|
| void ResourceBundle::LoadFontsIfNecessary() {
|
| @@ -225,19 +274,25 @@ void ResourceBundle::LoadFontsIfNecessary() {
|
| }
|
|
|
| /* static */
|
| -SkBitmap* ResourceBundle::LoadBitmap(DataHandle data_handle, int resource_id) {
|
| +bool ResourceBundle::LoadBitmaps(DataHandle data_handle, int resource_id,
|
| + std::vector<SkBitmap>& bitmaps) {
|
| scoped_refptr<RefCountedMemory> memory(
|
| LoadResourceBytes(data_handle, resource_id));
|
| if (!memory)
|
| - return NULL;
|
| + return false;
|
|
|
| SkBitmap bitmap;
|
| - if (!gfx::PNGCodec::Decode(memory->front(), memory->size(), &bitmap)) {
|
| - NOTREACHED() << "Unable to decode theme image resource " << resource_id;
|
| - return NULL;
|
| + if (gfx::PNGCodec::Decode(memory->front(), memory->size(), &bitmap)) {
|
| + bitmaps.push_back(bitmap);
|
| + return true;
|
| + }
|
| +
|
| + if (gfx::TIFFCodec::Decode(memory->front(), memory->size(), bitmaps)) {
|
| + return true;
|
| }
|
|
|
| - return new SkBitmap(bitmap);
|
| + NOTREACHED() << "Unable to decode theme image resource " << resource_id;
|
| + return false;
|
| }
|
|
|
| gfx::Image* ResourceBundle::GetEmptyImage() {
|
|
|