| Index: trunk/src/ui/base/resource/resource_bundle.cc
|
| ===================================================================
|
| --- trunk/src/ui/base/resource/resource_bundle.cc (revision 224498)
|
| +++ trunk/src/ui/base/resource/resource_bundle.cc (working copy)
|
| @@ -40,14 +40,6 @@
|
| #include "ui/gfx/platform_font_pango.h"
|
| #endif
|
|
|
| -#if defined(OS_WIN)
|
| -#include "ui/gfx/win/dpi.h"
|
| -#endif
|
| -
|
| -#if defined(OS_MACOSX) && !defined(OS_IOS)
|
| -#include "base/mac/mac_util.h"
|
| -#endif
|
| -
|
| namespace ui {
|
|
|
| namespace {
|
| @@ -88,19 +80,18 @@
|
| virtual ~ResourceBundleImageSource() {}
|
|
|
| // gfx::ImageSkiaSource overrides:
|
| - virtual gfx::ImageSkiaRep GetImageForScale(float scale) OVERRIDE {
|
| + virtual gfx::ImageSkiaRep GetImageForScale(
|
| + ui::ScaleFactor scale_factor) OVERRIDE {
|
| SkBitmap image;
|
| bool fell_back_to_1x = false;
|
| - ScaleFactor scale_factor = GetSupportedScaleFactor(scale);
|
| bool found = rb_->LoadBitmap(resource_id_, &scale_factor,
|
| &image, &fell_back_to_1x);
|
| - // Force to a supported scale.
|
| - scale = ui::GetImageScale(scale_factor);
|
| if (!found)
|
| return gfx::ImageSkiaRep();
|
|
|
| if (fell_back_to_1x) {
|
| // GRIT fell back to the 100% image, so rescale it to the correct size.
|
| + float scale = GetScaleFactorScale(scale_factor);
|
| image = skia::ImageOperations::Resize(
|
| image,
|
| skia::ImageOperations::RESIZE_LANCZOS3,
|
| @@ -121,7 +112,7 @@
|
| }
|
| }
|
|
|
| - return gfx::ImageSkiaRep(image, scale);
|
| + return gfx::ImageSkiaRep(image, scale_factor);
|
| }
|
|
|
| private:
|
| @@ -134,7 +125,9 @@
|
| // static
|
| std::string ResourceBundle::InitSharedInstanceWithLocale(
|
| const std::string& pref_locale, Delegate* delegate) {
|
| - InitSharedInstance(delegate);
|
| + DCHECK(g_shared_instance_ == NULL) << "ResourceBundle initialized twice";
|
| + g_shared_instance_ = new ResourceBundle(delegate);
|
| +
|
| g_shared_instance_->LoadCommonResources();
|
| std::string result = g_shared_instance_->LoadLocaleResources(pref_locale);
|
| InitDefaultFont();
|
| @@ -144,7 +137,9 @@
|
| // static
|
| std::string ResourceBundle::InitSharedInstanceLocaleOnly(
|
| const std::string& pref_locale, Delegate* delegate) {
|
| - InitSharedInstance(delegate);
|
| + DCHECK(g_shared_instance_ == NULL) << "ResourceBundle initialized twice";
|
| + g_shared_instance_ = new ResourceBundle(delegate);
|
| +
|
| std::string result = g_shared_instance_->LoadLocaleResources(pref_locale);
|
| InitDefaultFont();
|
| return result;
|
| @@ -153,7 +148,9 @@
|
| // static
|
| void ResourceBundle::InitSharedInstanceWithPakFile(
|
| base::PlatformFile pak_file, bool should_load_common_resources) {
|
| - InitSharedInstance(NULL);
|
| + DCHECK(g_shared_instance_ == NULL) << "ResourceBundle initialized twice";
|
| + g_shared_instance_ = new ResourceBundle(NULL);
|
| +
|
| if (should_load_common_resources)
|
| g_shared_instance_->LoadCommonResources();
|
|
|
| @@ -169,7 +166,9 @@
|
|
|
| // static
|
| void ResourceBundle::InitSharedInstanceWithPakPath(const base::FilePath& path) {
|
| - InitSharedInstance(NULL);
|
| + DCHECK(g_shared_instance_ == NULL) << "ResourceBundle initialized twice";
|
| + g_shared_instance_ = new ResourceBundle(NULL);
|
| +
|
| g_shared_instance_->LoadTestResources(path, path);
|
|
|
| InitDefaultFont();
|
| @@ -342,20 +341,18 @@
|
| DCHECK(!data_packs_.empty()) <<
|
| "Missing call to SetResourcesDataDLL?";
|
|
|
| -#if defined(OS_CHROMEOS)
|
| - ui::ScaleFactor scale_factor_to_load = GetMaxScaleFactor();
|
| -#else
|
| - ui::ScaleFactor scale_factor_to_load = ui::SCALE_FACTOR_100P;
|
| -#endif
|
| -
|
| - float scale = GetImageScale(scale_factor_to_load);
|
| // TODO(oshima): Consider reading the image size from png IHDR chunk and
|
| // skip decoding here and remove #ifdef below.
|
| // ResourceBundle::GetSharedInstance() is destroyed after the
|
| // BrowserMainLoop has finished running. |image_skia| is guaranteed to be
|
| // destroyed before the resource bundle is destroyed.
|
| +#if defined(OS_CHROMEOS)
|
| + ui::ScaleFactor scale_factor_to_load = ui::GetMaxScaleFactor();
|
| +#else
|
| + ui::ScaleFactor scale_factor_to_load = ui::SCALE_FACTOR_100P;
|
| +#endif
|
| gfx::ImageSkia image_skia(new ResourceBundleImageSource(this, resource_id),
|
| - scale);
|
| + scale_factor_to_load);
|
| if (image_skia.isNull()) {
|
| LOG(WARNING) << "Unable to load image with id " << resource_id;
|
| NOTREACHED(); // Want to assert in debug mode.
|
| @@ -513,14 +510,6 @@
|
| LoadFontsIfNecessary();
|
| }
|
|
|
| -ScaleFactor ResourceBundle::GetMaxScaleFactor() const {
|
| -#if defined(OS_CHROMEOS)
|
| - return max_scale_factor_;
|
| -#else
|
| - return GetSupportedScaleFactors().back();
|
| -#endif
|
| -}
|
| -
|
| ResourceBundle::ResourceBundle(Delegate* delegate)
|
| : delegate_(delegate),
|
| images_and_fonts_lock_(new base::Lock),
|
| @@ -533,49 +522,6 @@
|
| UnloadLocaleResources();
|
| }
|
|
|
| -// static
|
| -void ResourceBundle::InitSharedInstance(Delegate* delegate) {
|
| - DCHECK(g_shared_instance_ == NULL) << "ResourceBundle initialized twice";
|
| - g_shared_instance_ = new ResourceBundle(delegate);
|
| - static std::vector<ScaleFactor> supported_scale_factors;
|
| -#if !defined(OS_IOS)
|
| - // On platforms other than iOS, 100P is always a supported scale factor.
|
| - supported_scale_factors.push_back(SCALE_FACTOR_100P);
|
| -#endif
|
| -
|
| -#if defined(OS_ANDROID)
|
| - const gfx::Display display =
|
| - gfx::Screen::GetNativeScreen()->GetPrimaryDisplay();
|
| - const float display_density = display.device_scale_factor();
|
| - const ScaleFactor closest = FindClosestScaleFactorUnsafe(display_density);
|
| - if (closest != SCALE_FACTOR_100P)
|
| - supported_scale_factors.push_back(closest);
|
| -#elif defined(OS_IOS)
|
| - gfx::Display display = gfx::Screen::GetNativeScreen()->GetPrimaryDisplay();
|
| - if (display.device_scale_factor() > 1.0) {
|
| - DCHECK_EQ(2.0, display.device_scale_factor());
|
| - supported_scale_factors.push_back(SCALE_FACTOR_200P);
|
| - } else {
|
| - supported_scale_factors.push_back(SCALE_FACTOR_100P);
|
| - }
|
| -#elif defined(OS_MACOSX)
|
| - if (base::mac::IsOSLionOrLater())
|
| - supported_scale_factors.push_back(SCALE_FACTOR_200P);
|
| -#elif defined(OS_WIN)
|
| - // Have high-DPI resources for 140% and 180% scaling on Windows based on
|
| - // default scaling for Metro mode. Round to nearest supported scale in
|
| - // all cases.
|
| - if (gfx::IsInHighDPIMode()) {
|
| - supported_scale_factors.push_back(SCALE_FACTOR_140P);
|
| - supported_scale_factors.push_back(SCALE_FACTOR_180P);
|
| - }
|
| -#elif defined(OS_CHROMEOS)
|
| - // TODO(oshima): Include 200P only if the device support 200P
|
| - supported_scale_factors.push_back(SCALE_FACTOR_200P);
|
| -#endif
|
| - ui::SetSupportedScaleFactors(supported_scale_factors);
|
| -}
|
| -
|
| void ResourceBundle::FreeImages() {
|
| images_.clear();
|
| }
|
| @@ -608,8 +554,8 @@
|
| void ResourceBundle::AddDataPack(DataPack* data_pack) {
|
| data_packs_.push_back(data_pack);
|
|
|
| - if (GetImageScale(data_pack->GetScaleFactor()) >
|
| - GetImageScale(max_scale_factor_))
|
| + if (GetScaleFactorScale(data_pack->GetScaleFactor()) >
|
| + GetScaleFactorScale(max_scale_factor_))
|
| max_scale_factor_ = data_pack->GetScaleFactor();
|
| }
|
|
|
|
|