Commit f00044b1 authored by Malay Keshav's avatar Malay Keshav Committed by Commit Bot

Enable subpixel positioning for chrome os for fractional dsf

This patch enables the font subpixel positioning for the browser ui
and blink for fractional device scale factors.

It also adds a switch to force disable subpixel positioning for
easier debugging and testing on devices.

Bug: 839214
Change-Id: If8fd7dbc39ac3950bc27b5b7435b482fb4931065
Component: Font, subpixel positioning, kerning
Reviewed-on: https://chromium-review.googlesource.com/1053289Reviewed-by: default avatarNico Weber <thakis@chromium.org>
Reviewed-by: default avatarDan Erat <derat@chromium.org>
Commit-Queue: Malay Keshav <malaykeshav@chromium.org>
Cr-Commit-Position: refs/heads/master@{#558764}
parent fa98bfef
...@@ -3376,8 +3376,97 @@ class FontTestHelper : public AshTestBase { ...@@ -3376,8 +3376,97 @@ class FontTestHelper : public AshTestBase {
DISALLOW_COPY_AND_ASSIGN(FontTestHelper); DISALLOW_COPY_AND_ASSIGN(FontTestHelper);
}; };
bool IsTextSubpixelPositioningEnabled() {
gfx::FontRenderParams params =
gfx::GetFontRenderParams(gfx::FontRenderParamsQuery(), nullptr);
return params.subpixel_positioning;
}
gfx::FontRenderParams::Hinting GetFontHintingParams() {
gfx::FontRenderParams params =
gfx::GetFontRenderParams(gfx::FontRenderParamsQuery(), nullptr);
return params.hinting;
}
} // namespace } // namespace
using DisplayManagerFontTest = testing::Test;
TEST_F(DisplayManagerFontTest, TextSubpixelPositioningWithDsf100Internal) {
FontTestHelper helper(1.0f, FontTestHelper::INTERNAL);
ASSERT_DOUBLE_EQ(
1.0f,
display::Screen::GetScreen()->GetPrimaryDisplay().device_scale_factor());
EXPECT_FALSE(IsTextSubpixelPositioningEnabled());
EXPECT_NE(gfx::FontRenderParams::HINTING_NONE, GetFontHintingParams());
}
TEST_F(DisplayManagerFontTest, TextSubpixelPositioningWithDsf200Internal) {
FontTestHelper helper(2.0f, FontTestHelper::INTERNAL);
ASSERT_DOUBLE_EQ(
2.0f,
display::Screen::GetScreen()->GetPrimaryDisplay().device_scale_factor());
EXPECT_FALSE(IsTextSubpixelPositioningEnabled());
EXPECT_NE(gfx::FontRenderParams::HINTING_NONE, GetFontHintingParams());
display::test::DisplayManagerTestApi(helper.display_manager())
.SetDisplayUIScale(display::Screen::GetScreen()->GetPrimaryDisplay().id(),
2.0f);
ASSERT_DOUBLE_EQ(
1.0f,
display::Screen::GetScreen()->GetPrimaryDisplay().device_scale_factor());
EXPECT_FALSE(IsTextSubpixelPositioningEnabled());
EXPECT_NE(gfx::FontRenderParams::HINTING_NONE, GetFontHintingParams());
}
TEST_F(DisplayManagerFontTest, TextSubpixelPositioningWithDsf100External) {
FontTestHelper helper(1.0f, FontTestHelper::EXTERNAL);
ASSERT_DOUBLE_EQ(
1.0f,
display::Screen::GetScreen()->GetPrimaryDisplay().device_scale_factor());
EXPECT_FALSE(IsTextSubpixelPositioningEnabled());
EXPECT_NE(gfx::FontRenderParams::HINTING_NONE, GetFontHintingParams());
}
TEST_F(DisplayManagerFontTest, TextSubpixelPositioningWithDsf125External) {
FontTestHelper helper(1.25f, FontTestHelper::EXTERNAL);
ASSERT_DOUBLE_EQ(
1.25f,
display::Screen::GetScreen()->GetPrimaryDisplay().device_scale_factor());
EXPECT_TRUE(IsTextSubpixelPositioningEnabled());
EXPECT_EQ(gfx::FontRenderParams::HINTING_NONE, GetFontHintingParams());
}
TEST_F(DisplayManagerFontTest, TextSubpixelPositioningWithDsf200External) {
FontTestHelper helper(2.0f, FontTestHelper::EXTERNAL);
ASSERT_DOUBLE_EQ(
2.0f,
display::Screen::GetScreen()->GetPrimaryDisplay().device_scale_factor());
EXPECT_FALSE(IsTextSubpixelPositioningEnabled());
EXPECT_NE(gfx::FontRenderParams::HINTING_NONE, GetFontHintingParams());
}
TEST_F(DisplayManagerFontTest,
TextSubpixelPositioningWithDsf125InternalWithScaling) {
FontTestHelper helper(1.25f, FontTestHelper::INTERNAL);
ASSERT_DOUBLE_EQ(
1.0f,
display::Screen::GetScreen()->GetPrimaryDisplay().device_scale_factor());
EXPECT_FALSE(IsTextSubpixelPositioningEnabled());
EXPECT_NE(gfx::FontRenderParams::HINTING_NONE, GetFontHintingParams());
display::test::DisplayManagerTestApi(helper.display_manager())
.SetDisplayUIScale(display::Screen::GetScreen()->GetPrimaryDisplay().id(),
0.8f);
ASSERT_DOUBLE_EQ(
1.25f,
display::Screen::GetScreen()->GetPrimaryDisplay().device_scale_factor());
EXPECT_TRUE(IsTextSubpixelPositioningEnabled());
EXPECT_EQ(gfx::FontRenderParams::HINTING_NONE, GetFontHintingParams());
}
TEST_F(DisplayManagerTest, CheckInitializationOfRotationProperty) { TEST_F(DisplayManagerTest, CheckInitializationOfRotationProperty) {
int64_t id = display_manager()->GetDisplayAt(0).id(); int64_t id = display_manager()->GetDisplayAt(0).id();
display_manager()->RegisterDisplayProperty( display_manager()->RegisterDisplayProperty(
......
...@@ -278,11 +278,16 @@ FontRenderParams GetFontRenderParams(const FontRenderParamsQuery& query, ...@@ -278,11 +278,16 @@ FontRenderParams GetFontRenderParams(const FontRenderParamsQuery& query,
params.hinting = FontRenderParams::HINTING_FULL; params.hinting = FontRenderParams::HINTING_FULL;
params.subpixel_rendering = FontRenderParams::SUBPIXEL_RENDERING_NONE; params.subpixel_rendering = FontRenderParams::SUBPIXEL_RENDERING_NONE;
params.subpixel_positioning = false; params.subpixel_positioning = false;
} else { } else if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kDisableFontSubpixelPositioning)) {
#if !defined(OS_CHROMEOS) #if !defined(OS_CHROMEOS)
params.subpixel_positioning = actual_query.device_scale_factor > 1.0f; params.subpixel_positioning = actual_query.device_scale_factor > 1.0f;
#else #else
params.subpixel_positioning = false; // We want to enable subpixel positioning for fractional dsf.
params.subpixel_positioning =
std::abs(std::round(actual_query.device_scale_factor) -
actual_query.device_scale_factor) >
std::numeric_limits<float>::epsilon();
#endif // !defined(OS_CHROMEOS) #endif // !defined(OS_CHROMEOS)
// To enable subpixel positioning, we need to disable hinting. // To enable subpixel positioning, we need to disable hinting.
......
...@@ -310,9 +310,20 @@ TEST_F(FontRenderParamsTest, ForceSubpixelPositioning) { ...@@ -310,9 +310,20 @@ TEST_F(FontRenderParamsTest, ForceSubpixelPositioning) {
FontRenderParams params = FontRenderParams params =
GetFontRenderParams(FontRenderParamsQuery(), NULL); GetFontRenderParams(FontRenderParamsQuery(), NULL);
EXPECT_TRUE(params.antialiasing); EXPECT_TRUE(params.antialiasing);
EXPECT_TRUE(params.subpixel_positioning);
SetFontRenderParamsDeviceScaleFactor(1.0f);
}
ClearFontRenderParamsCacheForTest();
SetFontRenderParamsDeviceScaleFactor(2.f);
// Subpixel positioning should be forced on non-Chrome-OS.
{
FontRenderParams params =
GetFontRenderParams(FontRenderParamsQuery(), nullptr);
EXPECT_TRUE(params.antialiasing);
#if !defined(OS_CHROMEOS) #if !defined(OS_CHROMEOS)
EXPECT_TRUE(params.subpixel_positioning); EXPECT_TRUE(params.subpixel_positioning);
#else #else
// Integral scale factor does not require subpixel positioning.
EXPECT_FALSE(params.subpixel_positioning); EXPECT_FALSE(params.subpixel_positioning);
#endif // !defined(OS_CHROMEOS) #endif // !defined(OS_CHROMEOS)
SetFontRenderParamsDeviceScaleFactor(1.0f); SetFontRenderParamsDeviceScaleFactor(1.0f);
......
...@@ -18,6 +18,11 @@ const char kDisableDirectWriteForUI[] = "disable-directwrite-for-ui"; ...@@ -18,6 +18,11 @@ const char kDisableDirectWriteForUI[] = "disable-directwrite-for-ui";
const char kEnableHarfBuzzRenderText[] = "enable-harfbuzz-rendertext"; const char kEnableHarfBuzzRenderText[] = "enable-harfbuzz-rendertext";
#endif #endif
// Force disables font subpixel positioning. This affects the character glyph
// sharpness, kerning, hinting and layout.
const char kDisableFontSubpixelPositioning[] =
"disable-font-subpixel-positioning";
// Run in headless mode, i.e., without a UI or display server dependencies. // Run in headless mode, i.e., without a UI or display server dependencies.
const char kHeadless[] = "headless"; const char kHeadless[] = "headless";
......
...@@ -19,6 +19,8 @@ GFX_SWITCHES_EXPORT extern const char kDisableDirectWriteForUI[]; ...@@ -19,6 +19,8 @@ GFX_SWITCHES_EXPORT extern const char kDisableDirectWriteForUI[];
GFX_SWITCHES_EXPORT extern const char kEnableHarfBuzzRenderText[]; GFX_SWITCHES_EXPORT extern const char kEnableHarfBuzzRenderText[];
#endif #endif
GFX_SWITCHES_EXPORT extern const char kDisableFontSubpixelPositioning[];
GFX_SWITCHES_EXPORT extern const char kHeadless[]; GFX_SWITCHES_EXPORT extern const char kHeadless[];
} // namespace switches } // namespace switches
......
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