diff options
author | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-14 07:28:40 +0000 |
---|---|---|
committer | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-14 07:28:40 +0000 |
commit | 0a4cf456d7ac8a546c72d43b259513e0dc07ab17 (patch) | |
tree | dccfaa43d1c090c9fe40f8814304d6355f595b75 | |
parent | acf2474114d7d07c35553a23f70212b66bcdaab7 (diff) | |
download | chromium_src-0a4cf456d7ac8a546c72d43b259513e0dc07ab17.zip chromium_src-0a4cf456d7ac8a546c72d43b259513e0dc07ab17.tar.gz chromium_src-0a4cf456d7ac8a546c72d43b259513e0dc07ab17.tar.bz2 |
Load the resources for max scale factor first.
- made SCALE_FACTOR_NONE != SCALE_FACTOR_100P
- updated a few places that used SCALE_FACTOR_NONE to load
100P images
- Don't include 200P to supported scale factor unless
we have 200P assets (on chromeos)
BUG=156569
TEST=covered by test.
Review URL: https://chromiumcodereview.appspot.com/11301007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@167622 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | ash/shell/window_watcher.cc | 2 | ||||
-rw-r--r-- | chrome/browser/ui/views/tabs/tab.cc | 1 | ||||
-rw-r--r-- | chrome/browser/ui/webui/favicon_source.cc | 4 | ||||
-rw-r--r-- | chrome/browser/ui/webui/fileicon_source.cc | 2 | ||||
-rw-r--r-- | chrome/browser/ui/webui/web_ui_util.cc | 2 | ||||
-rw-r--r-- | chrome/browser/ui/webui/web_ui_util_unittest.cc | 4 | ||||
-rw-r--r-- | ui/base/layout.cc | 6 | ||||
-rw-r--r-- | ui/base/layout.h | 11 | ||||
-rw-r--r-- | ui/base/layout_unittest.cc | 10 | ||||
-rw-r--r-- | ui/base/resource/resource_bundle.cc | 43 | ||||
-rw-r--r-- | ui/base/resource/resource_bundle.h | 6 | ||||
-rw-r--r-- | ui/base/resource/resource_bundle_android.cc | 2 | ||||
-rw-r--r-- | ui/base/resource/resource_bundle_aurax11.cc | 2 | ||||
-rw-r--r-- | ui/base/resource/resource_bundle_gtk.cc | 2 | ||||
-rw-r--r-- | ui/base/resource/resource_bundle_mac.mm | 2 | ||||
-rw-r--r-- | ui/base/resource/resource_bundle_unittest.cc | 33 | ||||
-rw-r--r-- | ui/gfx/image/image_skia.cc | 13 |
17 files changed, 93 insertions, 52 deletions
diff --git a/ash/shell/window_watcher.cc b/ash/shell/window_watcher.cc index 97fee7d..157a598 100644 --- a/ash/shell/window_watcher.cc +++ b/ash/shell/window_watcher.cc @@ -91,7 +91,7 @@ void WindowWatcher::OnWindowAdded(aura::Window* new_window) { image_count == 2 ? 255 : 0); image_count = (image_count + 1) % 3; item.image = gfx::ImageSkia(gfx::ImageSkiaRep(icon_bitmap, - ui::SCALE_FACTOR_NONE)); + ui::SCALE_FACTOR_100P)); model->Add(item); } diff --git a/chrome/browser/ui/views/tabs/tab.cc b/chrome/browser/ui/views/tabs/tab.cc index eb17a3a..57960e10 100644 --- a/chrome/browser/ui/views/tabs/tab.cc +++ b/chrome/browser/ui/views/tabs/tab.cc @@ -847,6 +847,7 @@ gfx::ImageSkia Tab::GetCachedImage(int resource_id, void Tab::SetCachedImage(int resource_id, ui::ScaleFactor scale_factor, const gfx::ImageSkia& image) { + DCHECK_NE(scale_factor, ui::SCALE_FACTOR_NONE); ImageCacheEntry entry; entry.resource_id = resource_id; entry.scale_factor = scale_factor; diff --git a/chrome/browser/ui/webui/favicon_source.cc b/chrome/browser/ui/webui/favicon_source.cc index de4172b..ef8f4bf 100644 --- a/chrome/browser/ui/webui/favicon_source.cc +++ b/chrome/browser/ui/webui/favicon_source.cc @@ -47,12 +47,12 @@ void FaviconSource::StartDataRequest(const std::string& path, FaviconService* favicon_service = FaviconServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); if (!favicon_service || path.empty()) { - SendDefaultResponse(IconRequest(request_id, 16, ui::SCALE_FACTOR_NONE)); + SendDefaultResponse(IconRequest(request_id, 16, ui::SCALE_FACTOR_100P)); return; } int size_in_dip = gfx::kFaviconSize; - ui::ScaleFactor scale_factor = ui::SCALE_FACTOR_NONE; + ui::ScaleFactor scale_factor = ui::SCALE_FACTOR_100P; FaviconService::Handle handle; if (path.size() > 8 && diff --git a/chrome/browser/ui/webui/fileicon_source.cc b/chrome/browser/ui/webui/fileicon_source.cc index 0e05f07..8f8a80d 100644 --- a/chrome/browser/ui/webui/fileicon_source.cc +++ b/chrome/browser/ui/webui/fileicon_source.cc @@ -75,7 +75,7 @@ void ParseQueryParams(const std::string& query, if (icon_size) *icon_size = IconLoader::NORMAL; if (scale_factor) - *scale_factor = ui::SCALE_FACTOR_NONE; + *scale_factor = ui::SCALE_FACTOR_100P; base::SplitStringIntoKeyValuePairs(query, '=', '&', ¶meters); for (std::vector<KVPair>::const_iterator iter = parameters.begin(); iter != parameters.end(); ++iter) { diff --git a/chrome/browser/ui/webui/web_ui_util.cc b/chrome/browser/ui/webui/web_ui_util.cc index 6a21b1c..c96bbc5 100644 --- a/chrome/browser/ui/webui/web_ui_util.cc +++ b/chrome/browser/ui/webui/web_ui_util.cc @@ -85,7 +85,7 @@ WindowOpenDisposition GetDispositionFromClick(const ListValue* args, bool ParseScaleFactor(const base::StringPiece& identifier, ui::ScaleFactor* scale_factor) { - *scale_factor = ui::SCALE_FACTOR_NONE; + *scale_factor = ui::SCALE_FACTOR_100P; for (size_t i = 0; i < arraysize(kScaleFactorMap); i++) { if (identifier == kScaleFactorMap[i].name) { *scale_factor = kScaleFactorMap[i].scale_factor; diff --git a/chrome/browser/ui/webui/web_ui_util_unittest.cc b/chrome/browser/ui/webui/web_ui_util_unittest.cc index 810921f..63d3b44 100644 --- a/chrome/browser/ui/webui/web_ui_util_unittest.cc +++ b/chrome/browser/ui/webui/web_ui_util_unittest.cc @@ -14,7 +14,7 @@ TEST(WebUIUtilTest, ParsePathAndScale) { web_ui_util::ParsePathAndScale(url, &path, &factor); EXPECT_EQ("random/username@email/and/more", path); - EXPECT_EQ(ui::SCALE_FACTOR_NONE, factor); + EXPECT_EQ(ui::SCALE_FACTOR_100P, factor); GURL url2("chrome://some/random/username@email/and/more@2x"); web_ui_util::ParsePathAndScale(url2, &path, &factor); @@ -29,5 +29,5 @@ TEST(WebUIUtilTest, ParsePathAndScale) { GURL url4("chrome://some/random/username/and/more"); web_ui_util::ParsePathAndScale(url4, &path, &factor); EXPECT_EQ("random/username/and/more", path); - EXPECT_EQ(ui::SCALE_FACTOR_NONE, factor); + EXPECT_EQ(ui::SCALE_FACTOR_100P, factor); } diff --git a/ui/base/layout.cc b/ui/base/layout.cc index 98df1e1..a17ffc6 100644 --- a/ui/base/layout.cc +++ b/ui/base/layout.cc @@ -64,7 +64,7 @@ bool UseTouchOptimizedUI() { } #endif // defined(OS_WIN) -const float kScaleFactorScales[] = {1.0f, 1.4f, 1.8f, 2.0f}; +const float kScaleFactorScales[] = {1.0f, 1.0f, 1.4f, 1.8f, 2.0f}; COMPILE_ASSERT(NUM_SCALE_FACTORS == arraysize(kScaleFactorScales), kScaleFactorScales_incorrect_size); const size_t kScaleFactorScalesLength = arraysize(kScaleFactorScales); @@ -94,7 +94,8 @@ std::vector<ScaleFactor>& GetSupportedScaleFactorsInternal() { supported_scale_factors->push_back(SCALE_FACTOR_140P); supported_scale_factors->push_back(SCALE_FACTOR_180P); } -#elif defined(USE_ASH) +#elif defined(OS_CHROMEOS) + // TODO(oshima): Include 200P only if the device support 200P supported_scale_factors->push_back(SCALE_FACTOR_200P); #endif std::sort(supported_scale_factors->begin(), @@ -134,6 +135,7 @@ ScaleFactor GetScaleFactorFromScale(float scale) { smallest_diff = diff; } } + DCHECK_NE(closest_match, SCALE_FACTOR_NONE); return closest_match; } diff --git a/ui/base/layout.h b/ui/base/layout.h index fcfb974..24663b7 100644 --- a/ui/base/layout.h +++ b/ui/base/layout.h @@ -32,12 +32,12 @@ UI_EXPORT DisplayLayout GetDisplayLayout(); // Supported UI scale factors for the platform. This is used as an index // into the array |kScaleFactorScales| which maps the enum value to a float. +// SCALE_FACTOR_NONE is used for density independent resources such as +// string, html/js files or an image that can be used for any scale factors +// (such as wallpapers). enum ScaleFactor { - SCALE_FACTOR_100P = 0, - - // The scale factor used for unscaled binary data, the 1x (default) scale - // factor data packs. - SCALE_FACTOR_NONE = SCALE_FACTOR_100P, + SCALE_FACTOR_NONE = 0, + SCALE_FACTOR_100P, SCALE_FACTOR_140P, SCALE_FACTOR_180P, SCALE_FACTOR_200P, @@ -51,6 +51,7 @@ UI_EXPORT float GetScaleFactorScale(ScaleFactor scale_factor); // Returns the supported ScaleFactor which most closely matches |scale|. // Converting from float to ScaleFactor is inefficient and should be done as // little as possible. +// TODO(oshima): Make ScaleFactor a class and remove this. UI_EXPORT ScaleFactor GetScaleFactorFromScale(float scale); // Returns the ScaleFactor used by |view|. diff --git a/ui/base/layout_unittest.cc b/ui/base/layout_unittest.cc index 0992d0b..9cda5d5 100644 --- a/ui/base/layout_unittest.cc +++ b/ui/base/layout_unittest.cc @@ -72,12 +72,10 @@ TEST(LayoutTest, GetScaleFactorFromScaleAllSupported) { TEST(LayoutTest, GetMaxScaleFactor) { #if defined(OS_CHROMEOS) - // On Chrome OS, the maximum scale factor differs depending on the devices and - // force-device-scale-factor flag. Tests only the cases not affected by these. - if (!base::chromeos::IsRunningOnChromeOS() && - !CommandLine::ForCurrentProcess()->HasSwitch( - switches::kForceDeviceScaleFactor)) - EXPECT_EQ(SCALE_FACTOR_100P, GetMaxScaleFactor()); + // On Chrome OS, the maximum scale factor is based on + // the available resource pack. In testing environment, + // we always have 200P. + EXPECT_EQ(SCALE_FACTOR_200P, GetMaxScaleFactor()); #else std::vector<ScaleFactor> original_supported_factors = GetSupportedScaleFactors(); diff --git a/ui/base/resource/resource_bundle.cc b/ui/base/resource/resource_bundle.cc index d6eaec2..4bfd4dc 100644 --- a/ui/base/resource/resource_bundle.cc +++ b/ui/base/resource/resource_bundle.cc @@ -123,7 +123,7 @@ class ResourceBundle::ResourceBundleImageSource : public gfx::ImageSkiaSource { ui::ScaleFactor scale_factor) OVERRIDE { SkBitmap image; bool fell_back_to_1x = false; - bool found = rb_->LoadBitmap(resource_id_, scale_factor, + bool found = rb_->LoadBitmap(resource_id_, &scale_factor, &image, &fell_back_to_1x); if (!found) return gfx::ImageSkiaRep(); @@ -375,14 +375,18 @@ gfx::Image& ResourceBundle::GetImageNamed(int resource_id) { DCHECK(!delegate_ && !data_packs_.empty()) << "Missing call to SetResourcesDataDLL?"; - // TODO(oshima): This should be GetPrimaryDisplay().device_scale_factor(), - // but GetPrimaryDisplay() crashes at startup. - ScaleFactor primary_scale_factor = SCALE_FACTOR_100P; + // 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), - primary_scale_factor); + 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. @@ -452,7 +456,8 @@ base::StringPiece ResourceBundle::GetRawDataResourceForScale( } } for (size_t i = 0; i < data_packs_.size(); i++) { - if (data_packs_[i]->GetScaleFactor() == ui::SCALE_FACTOR_100P && + if ((data_packs_[i]->GetScaleFactor() == ui::SCALE_FACTOR_100P || + data_packs_[i]->GetScaleFactor() == ui::SCALE_FACTOR_NONE) && data_packs_[i]->GetStringPiece(resource_id, &data)) return data; } @@ -577,15 +582,6 @@ void ResourceBundle::AddDataPackFromPathInternal(const FilePath& path, void ResourceBundle::AddDataPack(DataPack* data_pack) { data_packs_.push_back(data_pack); -#if defined(OS_CHROMEOS) - // When Chrome is running on desktop and force-device-scale-factor is not - // specified, use SCALE_FACTOR_100P as |max_scale_factor_|. - if (!base::chromeos::IsRunningOnChromeOS() && - !CommandLine::ForCurrentProcess()->HasSwitch( - switches::kForceDeviceScaleFactor)) - return; -#endif - if (GetScaleFactorScale(data_pack->GetScaleFactor()) > GetScaleFactorScale(max_scale_factor_)) max_scale_factor_ = data_pack->GetScaleFactor(); @@ -674,14 +670,23 @@ bool ResourceBundle::LoadBitmap(const ResourceHandle& data_handle, } bool ResourceBundle::LoadBitmap(int resource_id, - ScaleFactor scale_factor, + ScaleFactor* scale_factor, SkBitmap* bitmap, bool* fell_back_to_1x) const { DCHECK(fell_back_to_1x); for (size_t i = 0; i < data_packs_.size(); ++i) { - if (data_packs_[i]->GetScaleFactor() == scale_factor) { - if (LoadBitmap(*data_packs_[i], resource_id, bitmap, fell_back_to_1x)) - return true; + // If the resource is in the package with SCALE_FACTOR_NONE, it + // can be used in any scale factor, but set 100P in ImageSkia so + // that it will be scaled property. + if (data_packs_[i]->GetScaleFactor() == ui::SCALE_FACTOR_NONE && + LoadBitmap(*data_packs_[i], resource_id, bitmap, fell_back_to_1x)) { + *scale_factor = ui::SCALE_FACTOR_100P; + DCHECK(!*fell_back_to_1x); + return true; + } + if (data_packs_[i]->GetScaleFactor() == *scale_factor && + LoadBitmap(*data_packs_[i], resource_id, bitmap, fell_back_to_1x)) { + return true; } } return false; diff --git a/ui/base/resource/resource_bundle.h b/ui/base/resource/resource_bundle.h index de547fc..3c4f3cb 100644 --- a/ui/base/resource/resource_bundle.h +++ b/ui/base/resource/resource_bundle.h @@ -310,9 +310,11 @@ class UI_EXPORT ResourceBundle { bool* fell_back_to_1x) const; // Fills the |bitmap| given the |resource_id| and |scale_factor|. - // Returns false if the resource does not exist. + // Returns false if the resource does not exist. This may fall back to + // the data pack with SCALE_FACTOR_NONE, and when this happens, + // |scale_factor| will be set to SCALE_FACTOR_100P. bool LoadBitmap(int resource_id, - ScaleFactor scale_factor, + ScaleFactor* scale_factor, SkBitmap* bitmap, bool* fell_back_to_1x) const; diff --git a/ui/base/resource/resource_bundle_android.cc b/ui/base/resource/resource_bundle_android.cc index dc43957..bb1c9d7 100644 --- a/ui/base/resource/resource_bundle_android.cc +++ b/ui/base/resource/resource_bundle_android.cc @@ -20,7 +20,7 @@ void ResourceBundle::LoadCommonResources() { FilePath path; PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &path); AddDataPackFromPath(path.AppendASCII("chrome.pak"), - SCALE_FACTOR_100P); + SCALE_FACTOR_NONE); AddDataPackFromPath(path.AppendASCII("chrome_100_percent.pak"), SCALE_FACTOR_100P); } diff --git a/ui/base/resource/resource_bundle_aurax11.cc b/ui/base/resource/resource_bundle_aurax11.cc index ed2873f..810e011 100644 --- a/ui/base/resource/resource_bundle_aurax11.cc +++ b/ui/base/resource/resource_bundle_aurax11.cc @@ -35,7 +35,7 @@ void ResourceBundle::LoadCommonResources() { // scale factor to gfx::ImageSkia::AddRepresentation. AddDataPackFromPath(GetResourcesPakFilePath("chrome.pak"), - SCALE_FACTOR_100P); + SCALE_FACTOR_NONE); AddDataPackFromPath(GetResourcesPakFilePath( "chrome_100_percent.pak"), SCALE_FACTOR_100P); diff --git a/ui/base/resource/resource_bundle_gtk.cc b/ui/base/resource/resource_bundle_gtk.cc index 7040f9e..4bf1bde 100644 --- a/ui/base/resource/resource_bundle_gtk.cc +++ b/ui/base/resource/resource_bundle_gtk.cc @@ -66,7 +66,7 @@ FilePath GetResourcesPakFilePath(const std::string& pak_name) { void ResourceBundle::LoadCommonResources() { AddDataPackFromPath(GetResourcesPakFilePath("chrome.pak"), - SCALE_FACTOR_100P); + SCALE_FACTOR_NONE); AddDataPackFromPath(GetResourcesPakFilePath( "chrome_100_percent.pak"), SCALE_FACTOR_100P); diff --git a/ui/base/resource/resource_bundle_mac.mm b/ui/base/resource/resource_bundle_mac.mm index afaa47a..2ddd057 100644 --- a/ui/base/resource/resource_bundle_mac.mm +++ b/ui/base/resource/resource_bundle_mac.mm @@ -50,7 +50,7 @@ FilePath GetResourcesPakFilePath(NSString* name, NSString* mac_locale) { void ResourceBundle::LoadCommonResources() { AddDataPackFromPath(GetResourcesPakFilePath(@"chrome", nil), - SCALE_FACTOR_100P); + SCALE_FACTOR_NONE); AddDataPackFromPath(GetResourcesPakFilePath(@"chrome_100_percent", nil), SCALE_FACTOR_100P); AddDataPackFromPath(GetResourcesPakFilePath(@"webkit_resources_100_percent", diff --git a/ui/base/resource/resource_bundle_unittest.cc b/ui/base/resource/resource_bundle_unittest.cc index 339e59c..9478d5c 100644 --- a/ui/base/resource/resource_bundle_unittest.cc +++ b/ui/base/resource/resource_bundle_unittest.cc @@ -423,20 +423,29 @@ TEST_F(ResourceBundleImageTest, GetRawDataResource) { // Test requesting image reps at various scale factors from the image returned // via ResourceBundle::GetImageNamed(). TEST_F(ResourceBundleImageTest, GetImageNamed) { - FilePath data_path = dir_path().Append(FILE_PATH_LITERAL("sample.pak")); - FilePath data_2x_path = dir_path().Append(FILE_PATH_LITERAL("sample_2x.pak")); + FilePath data_1x_path = dir_path().AppendASCII("sample_1x.pak"); + FilePath data_2x_path = dir_path().AppendASCII("sample_2x.pak"); // Create the pak files. - CreateDataPackWithSingleBitmap(data_path, 10, base::StringPiece()); + CreateDataPackWithSingleBitmap(data_1x_path, 10, base::StringPiece()); CreateDataPackWithSingleBitmap(data_2x_path, 20, base::StringPiece()); // Load the regular and 2x pak files. ResourceBundle* resource_bundle = CreateResourceBundleWithEmptyLocalePak(); - resource_bundle->AddDataPackFromPath(data_path, SCALE_FACTOR_100P); + resource_bundle->AddDataPackFromPath(data_1x_path, SCALE_FACTOR_100P); resource_bundle->AddDataPackFromPath(data_2x_path, SCALE_FACTOR_200P); + EXPECT_EQ(SCALE_FACTOR_200P, resource_bundle->max_scale_factor()); + gfx::ImageSkia* image_skia = resource_bundle->GetImageSkiaNamed(3); +#if defined(OS_CHROMEOS) + // ChromeOS loads highest scale factor first. + EXPECT_EQ(ui::SCALE_FACTOR_200P, image_skia->image_reps()[0].scale_factor()); +#else + EXPECT_EQ(ui::SCALE_FACTOR_100P, image_skia->image_reps()[0].scale_factor()); +#endif + // Resource ID 3 exists in both 1x and 2x paks. Image reps should be // available for both scale factors in |image_skia|. gfx::ImageSkiaRep image_rep = @@ -482,4 +491,20 @@ TEST_F(ResourceBundleImageTest, GetImageNamedFallback1x) { EXPECT_EQ(20, image_rep.pixel_height()); } +TEST_F(ResourceBundleImageTest, FallbackToNone) { + FilePath data_default_path = dir_path().AppendASCII("sample.pak"); + + // Create the pak files. + CreateDataPackWithSingleBitmap(data_default_path, 10, base::StringPiece()); + + // Load the regular pak files only. + ResourceBundle* resource_bundle = CreateResourceBundleWithEmptyLocalePak(); + resource_bundle->AddDataPackFromPath(data_default_path, SCALE_FACTOR_NONE); + + gfx::ImageSkia* image_skia = resource_bundle->GetImageSkiaNamed(3); + EXPECT_EQ(1u, image_skia->image_reps().size()); + EXPECT_EQ(ui::SCALE_FACTOR_100P, + image_skia->image_reps()[0].scale_factor()); +} + } // namespace ui diff --git a/ui/gfx/image/image_skia.cc b/ui/gfx/image/image_skia.cc index a886ab0..7cc89e4 100644 --- a/ui/gfx/image/image_skia.cc +++ b/ui/gfx/image/image_skia.cc @@ -61,11 +61,18 @@ class ImageSkiaStorage : public base::RefCounted<ImageSkiaStorage>, ImageSkiaStorage(ImageSkiaSource* source, ui::ScaleFactor scale_factor) : source_(source), read_only_(false) { - const ImageSkiaRep& image = *FindRepresentation(scale_factor, true); - if (image.is_null()) + ImageSkia::ImageSkiaReps::iterator it = + FindRepresentation(scale_factor, true); + // TODO(oshima): This is necessary as there are scale indepdent + // resources loaded as 100P. Fix them and remove this. + if (scale_factor != ui::SCALE_FACTOR_100P && + (it == image_reps_.end() || it->is_null())) + it = FindRepresentation(ui::SCALE_FACTOR_100P, true); + + if (it == image_reps_.end() || it->is_null()) source_.reset(); else - size_.SetSize(image.GetWidth(), image.GetHeight()); + size_.SetSize(it->GetWidth(), it->GetHeight()); } bool has_source() const { return source_.get() != NULL; } |