diff options
author | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-12 21:11:45 +0000 |
---|---|---|
committer | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-12 21:11:45 +0000 |
commit | c0336d30f5a822ebc55a49f019e00a2104aced18 (patch) | |
tree | 16bd873562d7de18bdd6c17333cc2d9e12b8f69c /app | |
parent | f36d009a08cb5eaddde1e3c891b793b1c5b3495e (diff) | |
download | chromium_src-c0336d30f5a822ebc55a49f019e00a2104aced18.zip chromium_src-c0336d30f5a822ebc55a49f019e00a2104aced18.tar.gz chromium_src-c0336d30f5a822ebc55a49f019e00a2104aced18.tar.bz2 |
Cleanup: Put #ifdefed typedef below non-#ifdefed declarations. Reorder definitions to match declarations. Use STL util function. Eliminate pointless comment.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/6224005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@71237 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app')
-rw-r--r-- | app/resource_bundle.cc | 135 | ||||
-rw-r--r-- | app/resource_bundle.h | 12 | ||||
-rw-r--r-- | app/resource_bundle_win.cc | 16 |
3 files changed, 80 insertions, 83 deletions
diff --git a/app/resource_bundle.cc b/app/resource_bundle.cc index 93669bc..79d6cd8 100644 --- a/app/resource_bundle.cc +++ b/app/resource_bundle.cc @@ -7,6 +7,7 @@ #include "app/data_pack.h" #include "base/lock.h" #include "base/logging.h" +#include "base/stl_util-inl.h" #include "base/string_piece.h" #include "build/build_config.h" #include "gfx/codec/png_codec.h" @@ -90,51 +91,6 @@ ResourceBundle& ResourceBundle::GetSharedInstance() { return *g_shared_instance_; } -ResourceBundle::ResourceBundle() - : lock_(new Lock), - resources_data_(NULL), - locale_resources_data_(NULL) { -} - -void ResourceBundle::FreeImages() { - for (SkImageMap::iterator i = skia_images_.begin(); - i != skia_images_.end(); i++) { - delete i->second; - } - skia_images_.clear(); -} - -/* static */ -SkBitmap* ResourceBundle::LoadBitmap(DataHandle data_handle, int resource_id) { - scoped_refptr<RefCountedMemory> memory( - LoadResourceBytes(data_handle, resource_id)); - if (!memory) - return NULL; - - SkBitmap bitmap; - if (!gfx::PNGCodec::Decode(memory->front(), memory->size(), &bitmap)) { - NOTREACHED() << "Unable to decode theme image resource " << resource_id; - return NULL; - } - - return new SkBitmap(bitmap); -} - -RefCountedStaticMemory* ResourceBundle::LoadDataResourceBytes( - int resource_id) const { - RefCountedStaticMemory* bytes = - LoadResourceBytes(resources_data_, resource_id); - - // Check all our additional data packs for the resources if it wasn't loaded - // from our main source. - for (std::vector<LoadedDataPack*>::const_iterator it = data_packs_.begin(); - !bytes && it != data_packs_.end(); ++it) { - bytes = (*it)->GetStaticMemory(resource_id); - } - - return bytes; -} - SkBitmap* ResourceBundle::GetBitmapNamed(int resource_id) { // Check to see if we already have the Skia image in the cache. { @@ -180,29 +136,19 @@ SkBitmap* ResourceBundle::GetBitmapNamed(int resource_id) { } } -void ResourceBundle::LoadFontsIfNecessary() { - AutoLock lock_scope(*lock_); - if (!base_font_.get()) { - base_font_.reset(new gfx::Font()); - - bold_font_.reset(new gfx::Font()); - *bold_font_ = - base_font_->DeriveFont(0, base_font_->GetStyle() | gfx::Font::BOLD); - - small_font_.reset(new gfx::Font()); - *small_font_ = base_font_->DeriveFont(kSmallFontSizeDelta); - - medium_font_.reset(new gfx::Font()); - *medium_font_ = base_font_->DeriveFont(kMediumFontSizeDelta); - - medium_bold_font_.reset(new gfx::Font()); - *medium_bold_font_ = - base_font_->DeriveFont(kMediumFontSizeDelta, - base_font_->GetStyle() | gfx::Font::BOLD); +RefCountedStaticMemory* ResourceBundle::LoadDataResourceBytes( + int resource_id) const { + RefCountedStaticMemory* bytes = + LoadResourceBytes(resources_data_, resource_id); - large_font_.reset(new gfx::Font()); - *large_font_ = base_font_->DeriveFont(kLargeFontSizeDelta); + // Check all our additional data packs for the resources if it wasn't loaded + // from our main source. + for (std::vector<LoadedDataPack*>::const_iterator it = data_packs_.begin(); + !bytes && it != data_packs_.end(); ++it) { + bytes = (*it)->GetStaticMemory(resource_id); } + + return bytes; } const gfx::Font& ResourceBundle::GetFont(FontStyle style) { @@ -234,7 +180,62 @@ gfx::NativeImage ResourceBundle::GetNativeImageNamed(int resource_id) { #endif } -// LoadedDataPack implementation +ResourceBundle::ResourceBundle() + : lock_(new Lock), + resources_data_(NULL), + locale_resources_data_(NULL) { +} + +void ResourceBundle::FreeImages() { + STLDeleteContainerPairSecondPointers(skia_images_.begin(), + skia_images_.end()); + skia_images_.clear(); +} + +void ResourceBundle::LoadFontsIfNecessary() { + AutoLock lock_scope(*lock_); + if (!base_font_.get()) { + base_font_.reset(new gfx::Font()); + + bold_font_.reset(new gfx::Font()); + *bold_font_ = + base_font_->DeriveFont(0, base_font_->GetStyle() | gfx::Font::BOLD); + + small_font_.reset(new gfx::Font()); + *small_font_ = base_font_->DeriveFont(kSmallFontSizeDelta); + + medium_font_.reset(new gfx::Font()); + *medium_font_ = base_font_->DeriveFont(kMediumFontSizeDelta); + + medium_bold_font_.reset(new gfx::Font()); + *medium_bold_font_ = + base_font_->DeriveFont(kMediumFontSizeDelta, + base_font_->GetStyle() | gfx::Font::BOLD); + + large_font_.reset(new gfx::Font()); + *large_font_ = base_font_->DeriveFont(kLargeFontSizeDelta); + } +} + +/* static */ +SkBitmap* ResourceBundle::LoadBitmap(DataHandle data_handle, int resource_id) { + scoped_refptr<RefCountedMemory> memory( + LoadResourceBytes(data_handle, resource_id)); + if (!memory) + return NULL; + + SkBitmap bitmap; + if (!gfx::PNGCodec::Decode(memory->front(), memory->size(), &bitmap)) { + NOTREACHED() << "Unable to decode theme image resource " << resource_id; + return NULL; + } + + return new SkBitmap(bitmap); +} + + +// LoadedDataPack ------------------------------------------------------------- + ResourceBundle::LoadedDataPack::LoadedDataPack(const FilePath& path) : path_(path) { // Always preload the data packs so we can maintain constness. diff --git a/app/resource_bundle.h b/app/resource_bundle.h index abe7205..352bc96 100644 --- a/app/resource_bundle.h +++ b/app/resource_bundle.h @@ -29,9 +29,6 @@ class DataPack; namespace base { class Lock; } -#if defined(USE_X11) -typedef struct _GdkPixbuf GdkPixbuf; -#endif namespace gfx { class Font; } @@ -49,6 +46,10 @@ class NSImage; #endif // __OBJC__ #endif // defined(OS_MACOSX) +#if defined(USE_X11) +typedef struct _GdkPixbuf GdkPixbuf; +#endif + // ResourceBundle is a central facility to load images and other resources, // such as theme graphics. // Every resource is loaded only once. @@ -96,11 +97,6 @@ class ResourceBundle { // Gets the bitmap with the specified resource_id from the current module // data. Returns a pointer to a shared instance of the SkBitmap. This shared // bitmap is owned by the resource bundle and should not be freed. - // - // The bitmap is assumed to exist. This function will log in release, and - // assert in debug mode if it does not. On failure, this will return a - // pointer to a shared empty placeholder bitmap so it will be visible what - // is missing. SkBitmap* GetBitmapNamed(int resource_id); // Loads the raw bytes of a data resource into |bytes|, diff --git a/app/resource_bundle_win.cc b/app/resource_bundle_win.cc index 865f903..89a68e1 100644 --- a/app/resource_bundle_win.cc +++ b/app/resource_bundle_win.cc @@ -41,14 +41,6 @@ ResourceBundle::~ResourceBundle() { resources_data_ = NULL; } -void ResourceBundle::UnloadLocaleResources() { - if (locale_resources_data_) { - BOOL rv = FreeLibrary(locale_resources_data_); - DCHECK(rv); - locale_resources_data_ = NULL; - } -} - void ResourceBundle::LoadCommonResources() { // As a convenience, set resources_data_ to the current resource module. DCHECK(NULL == resources_data_) << "common resources already loaded"; @@ -75,6 +67,14 @@ std::string ResourceBundle::LoadLocaleResources( return app_locale; } +void ResourceBundle::UnloadLocaleResources() { + if (locale_resources_data_) { + BOOL rv = FreeLibrary(locale_resources_data_); + DCHECK(rv); + locale_resources_data_ = NULL; + } +} + // static FilePath ResourceBundle::GetLocaleFilePath(const std::string& app_locale) { FilePath locale_path; |