0

[Text Contrast] Set contrast at compile time

The `IncreaseWindowsTextContrast` feature flag that sets text
contrast to 1.0 at runtime has been enabled-by-default since
version 132. This change enables the new value (1.0) at compile
time. This change also removes the "IncreaseWindowsTextContrast"
feature flag, as it will have no effect when the contrast value is
fixed at compile time.

The advantage of setting this value at compile time is a slight
memory reduction, as Skia will no longer need multiple text contrast
lookup tables.

There were several tests that needed to be updated - a few
reference images needed updates and some additional tests needed
`will-change: transform` added on both test and -expected
files so they both consistently apply LCDText behaviors.


Change-Id: I7f62348b32ff1b295a6beef496f8c6b0322d28df
Bug: 40037626
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6150028
Reviewed-by: Ian Kilpatrick <ikilpatrick@chromium.org>
Reviewed-by: Alison Maher <almaher@microsoft.com>
Commit-Queue: Kurt Catti-Schmidt <kschmi@microsoft.com>
Reviewed-by: Avi Drissman <avi@chromium.org>
Reviewed-by: Dominik Röttsches <drott@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1407508}
This commit is contained in:
Kurt Catti-Schmidt
2025-01-16 12:22:32 -08:00
committed by Chromium LUCI CQ
parent ce5d535a3b
commit debbc59818
14 changed files with 10 additions and 52 deletions

@ -130,7 +130,7 @@ config("skia_config") {
defines += [
"GR_GL_FUNCTION_TYPE=__stdcall",
"SK_GAMMA_SRGB",
"SK_GAMMA_CONTRAST=0.5",
"SK_GAMMA_CONTRAST=1.0",
]
}

@ -891,7 +891,7 @@
"owners": ["drott@chromium.org"],
"platforms": ["Linux", "Mac", "Win", "Fuchsia"],
"bases": [],
"args": ["--enable-font-antialiasing"],
"args": ["--enable-font-antialiasing", "--text-contrast=0.5", "--text-gamma=0.0"],
"expires": "Jan 1, 2026"
},
" Temporary test suite running virtual/text-antialias using FreeType, until ",

Binary file not shown.

Before

(image error) Size: 5.3 KiB

After

(image error) Size: 5.3 KiB

Binary file not shown.

Before

(image error) Size: 15 KiB

After

(image error) Size: 15 KiB

@ -3,4 +3,4 @@
Tests whether visual overflow contains glyph overflow.
Passes if the overhanging part of 'f' character is not clipped off.
</div>
<div style="font-size: 100px">f&nbsp;</div>
<div style="font-size: 100px; will-change: transform;">f&nbsp;</div>

@ -2,5 +2,5 @@
<div>
Tests whether visual overflow contains glyph overflow when there is word-spacing.
Passes if the overhanging part of 'f' character is not clipped off.
<div>
<div style="font-size: 100px; word-spacing: 50px;">o f&nbsp;</div>
</div>
<div style="font-size: 100px; word-spacing: 50px; will-change: transform;">o f&nbsp;</div>

@ -3,4 +3,4 @@
Tests whether visual overflow contains glyph overflow when there is word-spacing.
Passes if the overhanging part of 'f' character is not clipped off.
</div>
<div style="font-size: 100px; word-spacing: 50px; float: left; backface-visibility: hidden">o f</div>
<div style="font-size: 100px; word-spacing: 50px; float: left; backface-visibility: hidden; will-change: transform;">o f</div>

@ -3,4 +3,4 @@
Tests whether visual overflow contains glyph overflow.
Passes if the overhanging part of 'f' character is not clipped off.
</div>
<div style="float: left; font-size: 100px; backface-visibility: hidden; backface-visibility: hidden">f</div>
<div style="float: left; font-size: 100px; backface-visibility: hidden; will-change: transform;">f</div>

@ -416,9 +416,6 @@ BASE_FEATURE(kBubbleMetricsApi,
BASE_FEATURE(kUseGammaContrastRegistrySettings,
"UseGammaContrastRegistrySettings",
base::FEATURE_ENABLED_BY_DEFAULT);
BASE_FEATURE(kIncreaseWindowsTextContrast,
"IncreaseWindowsTextContrast",
base::FEATURE_ENABLED_BY_DEFAULT);
#endif // BUILDFLAG(IS_WIN)
BASE_FEATURE(kBubbleFrameViewTitleIsHeading,

@ -209,11 +209,6 @@ BASE_DECLARE_FEATURE(kBubbleMetricsApi);
// If not set, these values fall back to the pre-defined Skia defaults.
COMPONENT_EXPORT(UI_BASE_FEATURES)
BASE_DECLARE_FEATURE(kUseGammaContrastRegistrySettings);
// Increases the contrast of text to align more closely with contemporary
// applications.
COMPONENT_EXPORT(UI_BASE_FEATURES)
BASE_DECLARE_FEATURE(kIncreaseWindowsTextContrast);
#endif // BUILDFLAG(IS_WIN)
COMPONENT_EXPORT(UI_BASE_FEATURES)

@ -92,7 +92,7 @@ class CachedFontRenderParams {
params_->text_contrast = FontUtilWin::GetContrastFromRegistry();
params_->text_gamma = FontUtilWin::GetGammaFromRegistry();
} else {
params_->text_contrast = FontUtilWin::TextGammaContrast();
params_->text_contrast = SK_GAMMA_CONTRAST;
params_->text_gamma = SK_GAMMA_EXPONENT;
}

@ -38,12 +38,6 @@ constexpr float kGammaMultiplier = 1000;
} // namespace
TEST_F(FontRenderParamsTest, SystemFontSettingsDisabled) {
// TODO(crbug.com/40037626)
// Disable IncreaseWindowsTextContrast until SK_GAMMA_CONTRAST is set to 1.0f.
base::test::ScopedFeatureList scoped_features;
scoped_features.InitWithFeatures({},
{features::kIncreaseWindowsTextContrast});
// Ensure that without the feature enabled, the values of `FontRenderParams`
// match Skia default values.
FontRenderParams params =
@ -56,11 +50,8 @@ TEST_F(FontRenderParamsTest, DefaultRegistryState) {
// Ensure that with the feature enabled, the values of `FontRenderParams`
// match the associated registry key values.
base::test::ScopedFeatureList scoped_features;
// TODO(crbug.com/40037626)
// Disable IncreaseWindowsTextContrast until SK_GAMMA_CONTRAST is set to 1.0f.
scoped_features.InitWithFeatures(
{features::kUseGammaContrastRegistrySettings},
{features::kIncreaseWindowsTextContrast});
{features::kUseGammaContrastRegistrySettings}, {});
FontRenderParams params =
GetFontRenderParams(FontRenderParamsQuery(), nullptr);
@ -154,17 +145,4 @@ TEST_F(FontRenderParamsTest, OverrideRegistryValuesAndIncreaseContrast) {
}
}
TEST_F(FontRenderParamsTest, TextGammaContrast) {
// TODO(crbug.com/40037626)
// Disable IncreaseWindowsTextContrast until SK_GAMMA_CONTRAST is set to 1.0f.
base::test::ScopedFeatureList scoped_features;
scoped_features.InitWithFeatures({},
{features::kIncreaseWindowsTextContrast});
EXPECT_EQ(FontUtilWin::TextGammaContrast(), SK_GAMMA_CONTRAST);
}
TEST_F(FontRenderParamsTest, IncreasedContrast) {
EXPECT_EQ(FontUtilWin::TextGammaContrast(), 1.0f);
}
} // namespace gfx

@ -26,7 +26,7 @@ TextParameters GetTextParameters() {
static TextParameters text_parameters;
static std::once_flag flag;
std::call_once(flag, [&] {
text_parameters.contrast = FontUtilWin::TextGammaContrast();
text_parameters.contrast = SK_GAMMA_CONTRAST;
text_parameters.gamma = SK_GAMMA_EXPONENT;
// Only apply values from `IDWriteRenderingParams` if the user has
// the appropriate registry keys set. Otherwise, `IDWriteRenderingParams`
@ -93,15 +93,4 @@ float FontUtilWin::GetGammaFromRegistry() {
return GetTextParameters().gamma;
}
// static
float FontUtilWin::TextGammaContrast() {
if (base::FeatureList::IsEnabled(features::kIncreaseWindowsTextContrast)) {
// On Windows, SK_GAMMA_CONTRAST is currently 0.5. This flag increases it
// to 1.0.
return 1.0f;
} else {
return SK_GAMMA_CONTRAST;
}
}
} // namespace gfx

@ -16,7 +16,6 @@ class FontUtilWin {
static float ClampGamma(float value);
static float GetContrastFromRegistry();
static float GetGammaFromRegistry();
static float TextGammaContrast();
};
} // namespace gfx