Commit 6cd1ca5e authored by oshima's avatar oshima Committed by Commit bot

Cleanup: Enable 125DSFForUIScaling on by default

* Fix typo
* Introduced Scoped125DSFForUIScaling to temporarily disable it for testing.
* Make sure id isn't invalid when checking if it's internal.
 This problem exists only in unit tests, not in production.

BUG=None

Review URL: https://codereview.chromium.org/1251573006

Cr-Commit-Position: refs/heads/master@{#339822}
parent ba0f0b62
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
namespace ash { namespace ash {
namespace { namespace {
bool use_125_dsf_for_ui_scaling = false; bool use_125_dsf_for_ui_scaling = true;
// Check the content of |spec| and fill |bounds| and |device_scale_factor|. // Check the content of |spec| and fill |bounds| and |device_scale_factor|.
// Returns true when |bounds| is found. // Returns true when |bounds| is found.
...@@ -61,6 +61,11 @@ struct DisplayModeSorter { ...@@ -61,6 +61,11 @@ struct DisplayModeSorter {
bool is_internal; bool is_internal;
}; };
bool IsInternalDisplayId(int64 id) {
return id == gfx::Display::InternalDisplayId() &&
id != gfx::Display::kInvalidDisplayID;
}
} // namespace } // namespace
DisplayMode::DisplayMode() DisplayMode::DisplayMode()
...@@ -84,12 +89,11 @@ DisplayMode::DisplayMode(const gfx::Size& size, ...@@ -84,12 +89,11 @@ DisplayMode::DisplayMode(const gfx::Size& size,
gfx::Size DisplayMode::GetSizeInDIP(bool is_internal) const { gfx::Size DisplayMode::GetSizeInDIP(bool is_internal) const {
gfx::SizeF size_dip(size); gfx::SizeF size_dip(size);
size_dip.Scale(ui_scale); size_dip.Scale(ui_scale);
// DSF=1.25 is special. The screen is drawn with DSF=1.25 in some mode but it // DSF=1.25 is special on internal display. The screen is drawn with DSF=1.25
// doesn't affect the screen size computation. // but it doesn't affect the screen size computation.
if (!(use_125_dsf_for_ui_scaling && is_internal) || if (use_125_dsf_for_ui_scaling && is_internal && device_scale_factor == 1.25f)
device_scale_factor != 1.25f) { return gfx::ToFlooredSize(size_dip);
size_dip.Scale(1.0f / device_scale_factor); size_dip.Scale(1.0f / device_scale_factor);
}
return gfx::ToFlooredSize(size_dip); return gfx::ToFlooredSize(size_dip);
} }
...@@ -105,11 +109,6 @@ DisplayInfo DisplayInfo::CreateFromSpec(const std::string& spec) { ...@@ -105,11 +109,6 @@ DisplayInfo DisplayInfo::CreateFromSpec(const std::string& spec) {
return CreateFromSpecWithID(spec, gfx::Display::kInvalidDisplayID); return CreateFromSpecWithID(spec, gfx::Display::kInvalidDisplayID);
} }
// static
void DisplayInfo::SetUse125DSFForUIScaling(bool enable) {
use_125_dsf_for_ui_scaling = enable;
}
// static // static
DisplayInfo DisplayInfo::CreateFromSpecWithID(const std::string& spec, DisplayInfo DisplayInfo::CreateFromSpecWithID(const std::string& spec,
int64 id) { int64 id) {
...@@ -231,6 +230,11 @@ DisplayInfo DisplayInfo::CreateFromSpecWithID(const std::string& spec, ...@@ -231,6 +230,11 @@ DisplayInfo DisplayInfo::CreateFromSpecWithID(const std::string& spec,
return display_info; return display_info;
} }
// static
void DisplayInfo::SetUse125DSFForUIScalingForTest(bool enable) {
use_125_dsf_for_ui_scaling = enable;
}
DisplayInfo::DisplayInfo() DisplayInfo::DisplayInfo()
: id_(gfx::Display::kInvalidDisplayID), : id_(gfx::Display::kInvalidDisplayID),
has_overscan_(false), has_overscan_(false),
...@@ -321,7 +325,7 @@ void DisplayInfo::SetBounds(const gfx::Rect& new_bounds_in_native) { ...@@ -321,7 +325,7 @@ void DisplayInfo::SetBounds(const gfx::Rect& new_bounds_in_native) {
} }
float DisplayInfo::GetEffectiveDeviceScaleFactor() const { float DisplayInfo::GetEffectiveDeviceScaleFactor() const {
if (Use125DSFRorUIScaling() && device_scale_factor_ == 1.25f) if (Use125DSFForUIScaling() && device_scale_factor_ == 1.25f)
return (configured_ui_scale_ == 0.8f) ? 1.25f : 1.0f; return (configured_ui_scale_ == 0.8f) ? 1.25f : 1.0f;
if (device_scale_factor_ == configured_ui_scale_) if (device_scale_factor_ == configured_ui_scale_)
return 1.0f; return 1.0f;
...@@ -329,7 +333,7 @@ float DisplayInfo::GetEffectiveDeviceScaleFactor() const { ...@@ -329,7 +333,7 @@ float DisplayInfo::GetEffectiveDeviceScaleFactor() const {
} }
float DisplayInfo::GetEffectiveUIScale() const { float DisplayInfo::GetEffectiveUIScale() const {
if (Use125DSFRorUIScaling() && device_scale_factor_ == 1.25f) if (Use125DSFForUIScaling() && device_scale_factor_ == 1.25f)
return (configured_ui_scale_ == 0.8f) ? 1.0f : configured_ui_scale_; return (configured_ui_scale_ == 0.8f) ? 1.0f : configured_ui_scale_;
if (device_scale_factor_ == configured_ui_scale_) if (device_scale_factor_ == configured_ui_scale_)
return 1.0f; return 1.0f;
...@@ -367,7 +371,7 @@ void DisplayInfo::SetDisplayModes( ...@@ -367,7 +371,7 @@ void DisplayInfo::SetDisplayModes(
const std::vector<DisplayMode>& display_modes) { const std::vector<DisplayMode>& display_modes) {
display_modes_ = display_modes; display_modes_ = display_modes;
std::sort(display_modes_.begin(), display_modes_.end(), std::sort(display_modes_.begin(), display_modes_.end(),
DisplayModeSorter(id_ == gfx::Display::InternalDisplayId())); DisplayModeSorter(IsInternalDisplayId(id_)));
} }
gfx::Size DisplayInfo::GetNativeModeSize() const { gfx::Size DisplayInfo::GetNativeModeSize() const {
...@@ -429,8 +433,8 @@ bool DisplayInfo::IsColorProfileAvailable( ...@@ -429,8 +433,8 @@ bool DisplayInfo::IsColorProfileAvailable(
profile) != available_color_profiles_.end(); profile) != available_color_profiles_.end();
} }
bool DisplayInfo::Use125DSFRorUIScaling() const { bool DisplayInfo::Use125DSFForUIScaling() const {
return use_125_dsf_for_ui_scaling && id_ == gfx::Display::InternalDisplayId(); return use_125_dsf_for_ui_scaling && IsInternalDisplayId(id_);
} }
} // namespace ash } // namespace ash
...@@ -86,14 +86,14 @@ class ASH_EXPORT DisplayInfo { ...@@ -86,14 +86,14 @@ class ASH_EXPORT DisplayInfo {
static DisplayInfo CreateFromSpecWithID(const std::string& spec, static DisplayInfo CreateFromSpecWithID(const std::string& spec,
int64 id); int64 id);
DisplayInfo();
DisplayInfo(int64 id, const std::string& name, bool has_overscan);
~DisplayInfo();
// When this is set to true on the device whose internal display has // When this is set to true on the device whose internal display has
// 1.25 dsf, Chrome uses 1.0f as a default scale factor, and uses // 1.25 dsf, Chrome uses 1.0f as a default scale factor, and uses
// dsf 1.25 when UI scaling is set to 0.8f. // dsf 1.25 when UI scaling is set to 0.8f.
static void SetUse125DSFForUIScaling(bool enable); static void SetUse125DSFForUIScalingForTest(bool enable);
DisplayInfo();
DisplayInfo(int64 id, const std::string& name, bool has_overscan);
~DisplayInfo();
int64 id() const { return id_; } int64 id() const { return id_; }
...@@ -235,7 +235,7 @@ class ASH_EXPORT DisplayInfo { ...@@ -235,7 +235,7 @@ class ASH_EXPORT DisplayInfo {
private: private:
// Returns true if this display should use DSF=1.25 for UI scaling; i.e. // Returns true if this display should use DSF=1.25 for UI scaling; i.e.
// SetUse125DSFForUIScaling(true) is called and this is the internal display. // SetUse125DSFForUIScaling(true) is called and this is the internal display.
bool Use125DSFRorUIScaling() const; bool Use125DSFForUIScaling() const;
int64 id_; int64 id_;
std::string name_; std::string name_;
......
...@@ -110,23 +110,19 @@ TEST_F(DisplayInfoTest, DisplayModeGetSizeInDIPHiDPI) { ...@@ -110,23 +110,19 @@ TEST_F(DisplayInfoTest, DisplayModeGetSizeInDIPHiDPI) {
} }
TEST_F(DisplayInfoTest, DisplayModeGetSizeInDIP125) { TEST_F(DisplayInfoTest, DisplayModeGetSizeInDIP125) {
DisplayInfo::SetUse125DSFForUIScaling(true);
gfx::Size size(1920, 1080); gfx::Size size(1920, 1080);
EXPECT_EQ("2400x1350", GetModeSizeInDIP(size, 1.25f, 1.25f, true)); EXPECT_EQ("2400x1350", GetModeSizeInDIP(size, 1.25f, 1.25f, true));
EXPECT_EQ("1920x1080", GetModeSizeInDIP(size, 1.25f, 1.0f, true)); EXPECT_EQ("1920x1080", GetModeSizeInDIP(size, 1.25f, 1.0f, true));
EXPECT_EQ("1536x864", GetModeSizeInDIP(size, 1.25f, 0.8f, true)); EXPECT_EQ("1536x864", GetModeSizeInDIP(size, 1.25f, 0.8f, true));
EXPECT_EQ("1200x675", GetModeSizeInDIP(size, 1.25f, 0.625f, true)); EXPECT_EQ("1200x675", GetModeSizeInDIP(size, 1.25f, 0.625f, true));
EXPECT_EQ("960x540", GetModeSizeInDIP(size, 1.25f, 0.5f, true)); EXPECT_EQ("960x540", GetModeSizeInDIP(size, 1.25f, 0.5f, true));
DisplayInfo::SetUse125DSFForUIScaling(false);
} }
TEST_F(DisplayInfoTest, DisplayModeGetSizeForExternal4K) { TEST_F(DisplayInfoTest, DisplayModeGetSizeForExternal4K) {
DisplayInfo::SetUse125DSFForUIScaling(true);
gfx::Size size(3840, 2160); gfx::Size size(3840, 2160);
EXPECT_EQ("1920x1080", GetModeSizeInDIP(size, 2.0f, 1.0f, false)); EXPECT_EQ("1920x1080", GetModeSizeInDIP(size, 2.0f, 1.0f, false));
EXPECT_EQ("3072x1728", GetModeSizeInDIP(size, 1.25f, 1.0f, false)); EXPECT_EQ("3072x1728", GetModeSizeInDIP(size, 1.25f, 1.0f, false));
EXPECT_EQ("3840x2160", GetModeSizeInDIP(size, 1.0f, 1.0f, false)); EXPECT_EQ("3840x2160", GetModeSizeInDIP(size, 1.0f, 1.0f, false));
DisplayInfo::SetUse125DSFForUIScaling(false);
} }
} // namespace ash } // namespace ash
...@@ -136,10 +136,6 @@ DisplayManager::DisplayManager() ...@@ -136,10 +136,6 @@ DisplayManager::DisplayManager()
registered_internal_display_rotation_(gfx::Display::ROTATE_0), registered_internal_display_rotation_(gfx::Display::ROTATE_0),
weak_ptr_factory_(this) { weak_ptr_factory_(this) {
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
// Enable only on the device so that DisplayManagerFontTest passes.
if (base::SysInfo::IsRunningOnChromeOS())
DisplayInfo::SetUse125DSFForUIScaling(true);
change_display_upon_host_resize_ = !base::SysInfo::IsRunningOnChromeOS(); change_display_upon_host_resize_ = !base::SysInfo::IsRunningOnChromeOS();
#endif #endif
gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_ALTERNATE, screen_.get()); gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_ALTERNATE, screen_.get());
......
...@@ -942,7 +942,7 @@ TEST_F(DisplayManagerTest, Rotate) { ...@@ -942,7 +942,7 @@ TEST_F(DisplayManagerTest, Rotate) {
} }
TEST_F(DisplayManagerTest, UIScale) { TEST_F(DisplayManagerTest, UIScale) {
DisplayInfo::SetUse125DSFForUIScaling(false); test::ScopedDisable125DSFForUIScaling disable;
UpdateDisplay("1280x800"); UpdateDisplay("1280x800");
int64 display_id = Shell::GetScreen()->GetPrimaryDisplay().id(); int64 display_id = Shell::GetScreen()->GetPrimaryDisplay().id();
...@@ -1113,9 +1113,7 @@ TEST_F(DisplayManagerTest, UIScaleWithDisplayMode) { ...@@ -1113,9 +1113,7 @@ TEST_F(DisplayManagerTest, UIScaleWithDisplayMode) {
display_manager()->GetActiveModeForDisplayId(display_id))); display_manager()->GetActiveModeForDisplayId(display_id)));
} }
TEST_F(DisplayManagerTest, Use125DSFRorUIScaling) { TEST_F(DisplayManagerTest, Use125DSFForUIScaling) {
DisplayInfo::SetUse125DSFForUIScaling(true);
int64 display_id = Shell::GetScreen()->GetPrimaryDisplay().id(); int64 display_id = Shell::GetScreen()->GetPrimaryDisplay().id();
test::DisplayManagerTestApi(display_manager()) test::DisplayManagerTestApi(display_manager())
.SetInternalDisplayId(display_id); .SetInternalDisplayId(display_id);
...@@ -1138,8 +1136,6 @@ TEST_F(DisplayManagerTest, Use125DSFRorUIScaling) { ...@@ -1138,8 +1136,6 @@ TEST_F(DisplayManagerTest, Use125DSFRorUIScaling) {
EXPECT_EQ(1.0f, GetDisplayInfoAt(0).GetEffectiveDeviceScaleFactor()); EXPECT_EQ(1.0f, GetDisplayInfoAt(0).GetEffectiveDeviceScaleFactor());
EXPECT_EQ(1.25f, GetDisplayInfoAt(0).GetEffectiveUIScale()); EXPECT_EQ(1.25f, GetDisplayInfoAt(0).GetEffectiveUIScale());
EXPECT_EQ("2400x1350", GetDisplayForId(display_id).size().ToString()); EXPECT_EQ("2400x1350", GetDisplayForId(display_id).size().ToString());
DisplayInfo::SetUse125DSFForUIScaling(false);
} }
TEST_F(DisplayManagerTest, UIScaleInUnifiedMode) { TEST_F(DisplayManagerTest, UIScaleInUnifiedMode) {
...@@ -1727,6 +1723,7 @@ TEST_F(DisplayManagerFontTest, TextSubpixelPositioningWithDsf100Internal) { ...@@ -1727,6 +1723,7 @@ TEST_F(DisplayManagerFontTest, TextSubpixelPositioningWithDsf100Internal) {
} }
TEST_F(DisplayManagerFontTest, TextSubpixelPositioningWithDsf125Internal) { TEST_F(DisplayManagerFontTest, TextSubpixelPositioningWithDsf125Internal) {
test::ScopedDisable125DSFForUIScaling disable;
FontTestHelper helper(1.25f, FontTestHelper::INTERNAL); FontTestHelper helper(1.25f, FontTestHelper::INTERNAL);
ASSERT_DOUBLE_EQ( ASSERT_DOUBLE_EQ(
1.25f, Shell::GetScreen()->GetPrimaryDisplay().device_scale_factor()); 1.25f, Shell::GetScreen()->GetPrimaryDisplay().device_scale_factor());
...@@ -1776,7 +1773,6 @@ TEST_F(DisplayManagerFontTest, TextSubpixelPositioningWithDsf200External) { ...@@ -1776,7 +1773,6 @@ TEST_F(DisplayManagerFontTest, TextSubpixelPositioningWithDsf200External) {
TEST_F(DisplayManagerFontTest, TEST_F(DisplayManagerFontTest,
TextSubpixelPositioningWithDsf125InternalWithScaling) { TextSubpixelPositioningWithDsf125InternalWithScaling) {
DisplayInfo::SetUse125DSFForUIScaling(true);
FontTestHelper helper(1.25f, FontTestHelper::INTERNAL); FontTestHelper helper(1.25f, FontTestHelper::INTERNAL);
ASSERT_DOUBLE_EQ( ASSERT_DOUBLE_EQ(
1.0f, Shell::GetScreen()->GetPrimaryDisplay().device_scale_factor()); 1.0f, Shell::GetScreen()->GetPrimaryDisplay().device_scale_factor());
...@@ -1790,8 +1786,6 @@ TEST_F(DisplayManagerFontTest, ...@@ -1790,8 +1786,6 @@ TEST_F(DisplayManagerFontTest,
1.25f, Shell::GetScreen()->GetPrimaryDisplay().device_scale_factor()); 1.25f, Shell::GetScreen()->GetPrimaryDisplay().device_scale_factor());
EXPECT_TRUE(IsTextSubpixelPositioningEnabled()); EXPECT_TRUE(IsTextSubpixelPositioningEnabled());
EXPECT_EQ(gfx::FontRenderParams::HINTING_NONE, GetFontHintingParams()); EXPECT_EQ(gfx::FontRenderParams::HINTING_NONE, GetFontHintingParams());
DisplayInfo::SetUse125DSFForUIScaling(false);
} }
TEST_F(DisplayManagerTest, CheckInitializationOfRotationProperty) { TEST_F(DisplayManagerTest, CheckInitializationOfRotationProperty) {
......
...@@ -169,5 +169,13 @@ void DisplayManagerTestApi::SetAvailableColorProfiles( ...@@ -169,5 +169,13 @@ void DisplayManagerTestApi::SetAvailableColorProfiles(
profiles); profiles);
} }
ScopedDisable125DSFForUIScaling::ScopedDisable125DSFForUIScaling() {
DisplayInfo::SetUse125DSFForUIScalingForTest(false);
}
ScopedDisable125DSFForUIScaling::~ScopedDisable125DSFForUIScaling() {
DisplayInfo::SetUse125DSFForUIScalingForTest(true);
}
} // namespace test } // namespace test
} // namespace ash } // namespace ash
...@@ -66,6 +66,15 @@ class DisplayManagerTestApi { ...@@ -66,6 +66,15 @@ class DisplayManagerTestApi {
DISALLOW_COPY_AND_ASSIGN(DisplayManagerTestApi); DISALLOW_COPY_AND_ASSIGN(DisplayManagerTestApi);
}; };
class ScopedDisable125DSFForUIScaling {
public:
ScopedDisable125DSFForUIScaling();
~ScopedDisable125DSFForUIScaling();
private:
DISALLOW_COPY_AND_ASSIGN(ScopedDisable125DSFForUIScaling);
};
} // namespace test } // namespace test
} // namespace ash } // namespace ash
......
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