| Index: ui/base/resource/resource_bundle_linux.cc
|
| diff --git a/ui/base/resource/resource_bundle_linux.cc b/ui/base/resource/resource_bundle_linux.cc
|
| index eff8bdca45331c81a608cd1488bf5dd973ff2312..437f7258f269d83479146842d538426c14e94d77 100644
|
| --- a/ui/base/resource/resource_bundle_linux.cc
|
| +++ b/ui/base/resource/resource_bundle_linux.cc
|
| @@ -19,6 +19,7 @@
|
| #include "ui/base/ui_base_paths.h"
|
| #include "ui/gfx/font.h"
|
| #include "ui/gfx/gtk_util.h"
|
| +#include "ui/gfx/image.h"
|
|
|
| namespace ui {
|
|
|
| @@ -57,14 +58,6 @@ GdkPixbuf* LoadPixbuf(RefCountedStaticMemory* data, bool rtl_enabled) {
|
|
|
| } // namespace
|
|
|
| -void ResourceBundle::FreeGdkPixBufs() {
|
| - for (GdkPixbufMap::iterator i = gdk_pixbufs_.begin();
|
| - i != gdk_pixbufs_.end(); i++) {
|
| - g_object_unref(i->second);
|
| - }
|
| - gdk_pixbufs_.clear();
|
| -}
|
| -
|
| // static
|
| FilePath ResourceBundle::GetResourcesFilePath() {
|
| FilePath resources_file_path;
|
| @@ -86,15 +79,19 @@ FilePath ResourceBundle::GetLocaleFilePath(const std::string& app_locale) {
|
| return locale_file_path;
|
| }
|
|
|
| -GdkPixbuf* ResourceBundle::GetPixbufImpl(int resource_id, bool rtl_enabled) {
|
| +gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id) {
|
| + return *GetPixbufImpl(resource_id, false);
|
| +}
|
| +
|
| +gfx::Image* ResourceBundle::GetPixbufImpl(int resource_id, bool rtl_enabled) {
|
| // Use the negative |resource_id| for the key for BIDI-aware images.
|
| int key = rtl_enabled ? -resource_id : resource_id;
|
|
|
| - // Check to see if we already have the pixbuf in the cache.
|
| + // Check to see if the image is already in the cache.
|
| {
|
| base::AutoLock lock_scope(*lock_);
|
| - GdkPixbufMap::const_iterator found = gdk_pixbufs_.find(key);
|
| - if (found != gdk_pixbufs_.end())
|
| + ImageMap::const_iterator found = images_.find(key);
|
| + if (found != images_.end())
|
| return found->second;
|
| }
|
|
|
| @@ -102,47 +99,32 @@ GdkPixbuf* ResourceBundle::GetPixbufImpl(int resource_id, bool rtl_enabled) {
|
| LoadDataResourceBytes(resource_id));
|
| GdkPixbuf* pixbuf = LoadPixbuf(data.get(), rtl_enabled);
|
|
|
| - // We loaded successfully. Cache the pixbuf.
|
| + // The load was successful, so cache the image.
|
| if (pixbuf) {
|
| base::AutoLock lock_scope(*lock_);
|
|
|
| - // Another thread raced us, and has already cached the pixbuf.
|
| - if (gdk_pixbufs_.count(key)) {
|
| + // Another thread raced the load and has already cached the image.
|
| + if (images_.count(key)) {
|
| g_object_unref(pixbuf);
|
| - return gdk_pixbufs_[key];
|
| + return images_[key];
|
| }
|
|
|
| - gdk_pixbufs_[key] = pixbuf;
|
| - return pixbuf;
|
| + gfx::Image* image = new gfx::Image(pixbuf); // Takes ownership.
|
| + images_[key] = image;
|
| + return image;
|
| }
|
|
|
| - // We failed to retrieve the bitmap, show a debugging red square.
|
| - {
|
| - LOG(WARNING) << "Unable to load GdkPixbuf with id " << resource_id;
|
| - NOTREACHED(); // Want to assert in debug mode.
|
| -
|
| - base::AutoLock lock_scope(*lock_); // Guard empty_bitmap initialization.
|
| -
|
| - static GdkPixbuf* empty_bitmap = NULL;
|
| - if (!empty_bitmap) {
|
| - // The placeholder bitmap is bright red so people notice the problem.
|
| - // This bitmap will be leaked, but this code should never be hit.
|
| - scoped_ptr<SkBitmap> skia_bitmap(new SkBitmap());
|
| - skia_bitmap->setConfig(SkBitmap::kARGB_8888_Config, 32, 32);
|
| - skia_bitmap->allocPixels();
|
| - skia_bitmap->eraseARGB(255, 255, 0, 0);
|
| - empty_bitmap = gfx::GdkPixbufFromSkBitmap(skia_bitmap.get());
|
| - }
|
| - return empty_bitmap;
|
| - }
|
| + LOG(WARNING) << "Unable to pixbuf with id " << resource_id;
|
| + NOTREACHED(); // Want to assert in debug mode.
|
| + return GetEmptyImage();
|
| }
|
|
|
| GdkPixbuf* ResourceBundle::GetPixbufNamed(int resource_id) {
|
| - return GetPixbufImpl(resource_id, false);
|
| + return *GetPixbufImpl(resource_id, false);
|
| }
|
|
|
| GdkPixbuf* ResourceBundle::GetRTLEnabledPixbufNamed(int resource_id) {
|
| - return GetPixbufImpl(resource_id, true);
|
| + return *GetPixbufImpl(resource_id, true);
|
| }
|
|
|
| } // namespace ui
|
|
|