Commit d823e370 authored by ananta@chromium.org's avatar ananta@chromium.org

This is in preparation for enabling HiDPI on Windows by default. Most of the...

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
parent 5070353e
......@@ -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));
......
......@@ -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)
......
......@@ -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;
}
......
......@@ -1198,7 +1198,6 @@ void RenderProcessHostImpl::PropagateBrowserCommandLineToRenderer(
#if defined(OS_WIN)
switches::kEnableDirectWrite,
switches::kEnableHighResolutionTime,
switches::kHighDPISupport,
#endif
};
renderer_cmd->CopySwitchesFrom(browser_cmd, kSwitchNames,
......
......@@ -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;
......
......@@ -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) {
......
......@@ -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
......
......@@ -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());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment