diff options
author | ananta@chromium.org <ananta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-24 12:44:42 +0000 |
---|---|---|
committer | ananta@chromium.org <ananta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-24 12:44:42 +0000 |
commit | d823e370f31b6dfb96cc90bf07ec4480c40f7135 (patch) | |
tree | 8c84871e48e8d2e9715e78e0a8889d228984c440 | |
parent | 5070353e5ba39fb46a55e4df08743da649619041 (diff) | |
download | chromium_src-d823e370f31b6dfb96cc90bf07ec4480c40f7135.zip chromium_src-d823e370f31b6dfb96cc90bf07ec4480c40f7135.tar.gz chromium_src-d823e370f31b6dfb96cc90bf07ec4480c40f7135.tar.bz2 |
This is in preparation for enabling HiDPI on Windows by default. Most of the changes here are replacing usage of
the ui::GetImageScale function with ui::GetScaleForScaleFactor.
The patch to remove the HiDPI switch and enable it by default will follow. This patch has been incorporated from
girard's patch ( https://codereview.chromium.org/232483005/)
BUG=149881, 362245
Review URL: https://codereview.chromium.org/294863002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@272721 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/extensions/extension_icon_image_unittest.cc | 2 | ||||
-rw-r--r-- | chrome/browser/history/select_favicon_frames_unittest.cc | 2 | ||||
-rw-r--r-- | components/favicon_base/select_favicon_frames.cc | 6 | ||||
-rw-r--r-- | content/browser/renderer_host/render_process_host_impl.cc | 1 | ||||
-rw-r--r-- | ui/base/layout.cc | 2 | ||||
-rw-r--r-- | ui/base/layout_unittest.cc | 16 | ||||
-rw-r--r-- | ui/base/resource/resource_bundle_unittest.cc | 21 | ||||
-rw-r--r-- | ui/base/test/run_all_unittests.cc | 8 |
8 files changed, 37 insertions, 21 deletions
diff --git a/chrome/browser/extensions/extension_icon_image_unittest.cc b/chrome/browser/extensions/extension_icon_image_unittest.cc index a6f0f19..1e4cd56 100644 --- a/chrome/browser/extensions/extension_icon_image_unittest.cc +++ b/chrome/browser/extensions/extension_icon_image_unittest.cc @@ -31,7 +31,7 @@ namespace { SkBitmap CreateBlankBitmapForScale(int size_dip, ui::ScaleFactor scale_factor) { SkBitmap bitmap; - const float scale = ui::GetImageScale(scale_factor); + const float scale = ui::GetScaleForScaleFactor(scale_factor); bitmap.setConfig(SkBitmap::kARGB_8888_Config, static_cast<int>(size_dip * scale), static_cast<int>(size_dip * scale)); diff --git a/chrome/browser/history/select_favicon_frames_unittest.cc b/chrome/browser/history/select_favicon_frames_unittest.cc index d6e2fe9..f82b17a 100644 --- a/chrome/browser/history/select_favicon_frames_unittest.cc +++ b/chrome/browser/history/select_favicon_frames_unittest.cc @@ -44,7 +44,7 @@ SkBitmap MakeBitmap(SkColor color, int w, int h) { SkColor GetColor(const gfx::ImageSkia& image, ui::ScaleFactor factor, int x = -1, int y = -1) { const SkBitmap& bitmap = - image.GetRepresentation(ui::GetImageScale(factor)).sk_bitmap(); + image.GetRepresentation(ui::GetScaleForScaleFactor(factor)).sk_bitmap(); if (x == -1) x = bitmap.width() / 2; if (y == -1) diff --git a/components/favicon_base/select_favicon_frames.cc b/components/favicon_base/select_favicon_frames.cc index 32f7094..888837f 100644 --- a/components/favicon_base/select_favicon_frames.cc +++ b/components/favicon_base/select_favicon_frames.cc @@ -54,7 +54,7 @@ size_t GetCandidateIndexWithBestScore( ResizeMethod* resize_method) { DCHECK_NE(desired_size_in_dip, 0); - float scale = ui::GetImageScale(scale_factor); + float scale = ui::GetScaleForScaleFactor(scale_factor); int desired_size_in_pixel = static_cast<int>(desired_size_in_dip * scale + 0.5f); @@ -182,7 +182,7 @@ SkBitmap GetResizedBitmap(const SkBitmap& source_bitmap, int desired_size_in_dip, ui::ScaleFactor scale_factor, ResizeMethod resize_method) { - float scale = ui::GetImageScale(scale_factor); + float scale = ui::GetScaleForScaleFactor(scale_factor); int desired_size_in_pixel = static_cast<int>(desired_size_in_dip * scale + 0.5f); @@ -223,7 +223,7 @@ gfx::ImageSkia SelectFaviconFrames( result.scale_factor, result.resize_method); multi_image.AddRepresentation(gfx::ImageSkiaRep( - resized_bitmap, ui::GetImageScale(result.scale_factor))); + resized_bitmap, ui::GetScaleForScaleFactor(result.scale_factor))); } return multi_image; } diff --git a/content/browser/renderer_host/render_process_host_impl.cc b/content/browser/renderer_host/render_process_host_impl.cc index bb52683..a38027c 100644 --- a/content/browser/renderer_host/render_process_host_impl.cc +++ b/content/browser/renderer_host/render_process_host_impl.cc @@ -1198,7 +1198,6 @@ void RenderProcessHostImpl::PropagateBrowserCommandLineToRenderer( #if defined(OS_WIN) switches::kEnableDirectWrite, switches::kEnableHighResolutionTime, - switches::kHighDPISupport, #endif }; renderer_cmd->CopySwitchesFrom(browser_cmd, kSwitchNames, diff --git a/ui/base/layout.cc b/ui/base/layout.cc index 2c4baee..86419f4 100644 --- a/ui/base/layout.cc +++ b/ui/base/layout.cc @@ -29,7 +29,7 @@ namespace ui { namespace { bool ScaleFactorComparator(const ScaleFactor& lhs, const ScaleFactor& rhs){ - return GetImageScale(lhs) < GetImageScale(rhs); + return GetScaleForScaleFactor(lhs) < GetScaleForScaleFactor(rhs); } std::vector<ScaleFactor>* g_supported_scale_factors = NULL; diff --git a/ui/base/layout_unittest.cc b/ui/base/layout_unittest.cc index b082bea..310cd09 100644 --- a/ui/base/layout_unittest.cc +++ b/ui/base/layout_unittest.cc @@ -14,14 +14,14 @@ namespace ui { TEST(LayoutTest, GetScaleFactorScale) { - EXPECT_FLOAT_EQ(1.0f, GetImageScale(SCALE_FACTOR_100P)); - EXPECT_FLOAT_EQ(1.25f, GetImageScale(SCALE_FACTOR_125P)); - EXPECT_FLOAT_EQ(1.33f, GetImageScale(SCALE_FACTOR_133P)); - EXPECT_FLOAT_EQ(1.4f, GetImageScale(SCALE_FACTOR_140P)); - EXPECT_FLOAT_EQ(1.5f, GetImageScale(SCALE_FACTOR_150P)); - EXPECT_FLOAT_EQ(1.8f, GetImageScale(SCALE_FACTOR_180P)); - EXPECT_FLOAT_EQ(2.0f, GetImageScale(SCALE_FACTOR_200P)); - EXPECT_FLOAT_EQ(3.0f, GetImageScale(SCALE_FACTOR_300P)); + EXPECT_FLOAT_EQ(1.0f, GetScaleForScaleFactor(SCALE_FACTOR_100P)); + EXPECT_FLOAT_EQ(1.25f, GetScaleForScaleFactor(SCALE_FACTOR_125P)); + EXPECT_FLOAT_EQ(1.33f, GetScaleForScaleFactor(SCALE_FACTOR_133P)); + EXPECT_FLOAT_EQ(1.4f, GetScaleForScaleFactor(SCALE_FACTOR_140P)); + EXPECT_FLOAT_EQ(1.5f, GetScaleForScaleFactor(SCALE_FACTOR_150P)); + EXPECT_FLOAT_EQ(1.8f, GetScaleForScaleFactor(SCALE_FACTOR_180P)); + EXPECT_FLOAT_EQ(2.0f, GetScaleForScaleFactor(SCALE_FACTOR_200P)); + EXPECT_FLOAT_EQ(3.0f, GetScaleForScaleFactor(SCALE_FACTOR_300P)); } TEST(LayoutTest, GetScaleFactorFromScalePartlySupported) { diff --git a/ui/base/resource/resource_bundle_unittest.cc b/ui/base/resource/resource_bundle_unittest.cc index 991dd06..a87ade7 100644 --- a/ui/base/resource/resource_bundle_unittest.cc +++ b/ui/base/resource/resource_bundle_unittest.cc @@ -21,6 +21,9 @@ #include "ui/base/resource/data_pack.h" #include "ui/gfx/codec/png_codec.h" #include "ui/gfx/image/image_skia.h" +#if defined(OS_WIN) +#include "ui/gfx/win/dpi.h" +#endif using ::testing::_; using ::testing::Between; @@ -439,6 +442,9 @@ TEST_F(ResourceBundleImageTest, GetRawDataResource) { // Test requesting image reps at various scale factors from the image returned // via ResourceBundle::GetImageNamed(). TEST_F(ResourceBundleImageTest, GetImageNamed) { +#if defined(OS_WIN) + gfx::ForceHighDPISupportForTesting(2.0); +#endif std::vector<ScaleFactor> supported_factors; supported_factors.push_back(SCALE_FACTOR_100P); supported_factors.push_back(SCALE_FACTOR_200P); @@ -471,16 +477,18 @@ TEST_F(ResourceBundleImageTest, GetImageNamed) { // 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 = - image_skia->GetRepresentation(GetImageScale(ui::SCALE_FACTOR_100P)); + image_skia->GetRepresentation( + GetScaleForScaleFactor(ui::SCALE_FACTOR_100P)); EXPECT_EQ(ui::SCALE_FACTOR_100P, GetSupportedScaleFactor(image_rep.scale())); image_rep = - image_skia->GetRepresentation(GetImageScale(ui::SCALE_FACTOR_200P)); + image_skia->GetRepresentation( + GetScaleForScaleFactor(ui::SCALE_FACTOR_200P)); EXPECT_EQ(ui::SCALE_FACTOR_200P, GetSupportedScaleFactor(image_rep.scale())); // The 1.4x pack was not loaded. Requesting the 1.4x resource should return // either the 1x or the 2x resource. image_rep = image_skia->GetRepresentation( - ui::GetImageScale(ui::SCALE_FACTOR_140P)); + ui::GetScaleForScaleFactor(ui::SCALE_FACTOR_140P)); ui::ScaleFactor scale_factor = GetSupportedScaleFactor(image_rep.scale()); EXPECT_TRUE(scale_factor == ui::SCALE_FACTOR_100P || scale_factor == ui::SCALE_FACTOR_200P); @@ -519,7 +527,8 @@ TEST_F(ResourceBundleImageTest, GetImageNamedFallback1x) { // The image rep for 2x should be available. It should be resized to the // proper 2x size. gfx::ImageSkiaRep image_rep = - image_skia->GetRepresentation(GetImageScale(ui::SCALE_FACTOR_200P)); + image_skia->GetRepresentation(GetScaleForScaleFactor( + ui::SCALE_FACTOR_200P)); EXPECT_EQ(ui::SCALE_FACTOR_200P, GetSupportedScaleFactor(image_rep.scale())); EXPECT_EQ(20, image_rep.pixel_width()); EXPECT_EQ(20, image_rep.pixel_height()); @@ -558,10 +567,10 @@ TEST_F(ResourceBundleImageTest, GetImageNamedFallback1xRounding) { gfx::ImageSkia* image_skia = resource_bundle->GetImageSkiaNamed(3); gfx::ImageSkiaRep image_rep = image_skia->GetRepresentation( - GetImageScale(ui::SCALE_FACTOR_140P)); + GetScaleForScaleFactor(ui::SCALE_FACTOR_140P)); EXPECT_EQ(12, image_rep.pixel_width()); image_rep = image_skia->GetRepresentation( - GetImageScale(ui::SCALE_FACTOR_180P)); + GetScaleForScaleFactor(ui::SCALE_FACTOR_180P)); EXPECT_EQ(15, image_rep.pixel_width()); } #endif diff --git a/ui/base/test/run_all_unittests.cc b/ui/base/test/run_all_unittests.cc index 8573da0..bfc5f26 100644 --- a/ui/base/test/run_all_unittests.cc +++ b/ui/base/test/run_all_unittests.cc @@ -22,6 +22,10 @@ #include "base/mac/bundle_locations.h" #endif +#if defined(OS_WIN) +#include "ui/gfx/win/dpi.h" +#endif + namespace { class UIBaseTestSuite : public base::TestSuite { @@ -43,6 +47,10 @@ UIBaseTestSuite::UIBaseTestSuite(int argc, char** argv) void UIBaseTestSuite::Initialize() { base::TestSuite::Initialize(); +#if defined(OS_WIN) + gfx::ForceHighDPISupportForTesting(1.0); +#endif + #if defined(OS_ANDROID) // Register JNI bindings for android. gfx::android::RegisterJni(base::android::AttachCurrentThread()); |