Skip to content

Commit 90fcfdf

Browse files
authored
Bumps text gamma on windows to match skia. (flutter#190477)
fixes flutter#190391 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [ ] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. If this change needs to override an active code freeze, provide a comment explaining why. The code freeze workflow can be overridden by code reviewers. See pinned issues for any active code freezes with guidance. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [AI contribution guidelines]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#ai-contribution-guidelines [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
1 parent 27a2663 commit 90fcfdf

1 file changed

Lines changed: 18 additions & 11 deletions

File tree

‎engine/src/flutter/impeller/entity/contents/text_contents.cc‎

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,31 @@
2020
namespace impeller {
2121
namespace {
2222

23-
// TODO(gaaclarke): Investigate if this is still needed for Windows.
24-
// On Linux we use FreeType to rasterize glyphs. FreeType does not perform
25-
// gamma correction itself during rasterization. Because we render in linear
26-
// space, light text on a dark background would look too thin without
27-
// correction. To compensate, we calculate a contrast/gamma correction
28-
// factor based on the text color's luminance, which is used in the shader
29-
// to adjust the glyph's coverage.
23+
// On Linux we use FreeType and on Windows we use DirectWrite/GDI to rasterize
24+
// glyphs. Because we render in linear space, light text on a dark background
25+
// would look too thin without correction. To compensate, we calculate a
26+
// contrast/gamma correction factor based on the text color's luminance, which
27+
// is used in the shader to adjust the glyph's coverage.
3028
constexpr bool kPlatformGammaCorrectionDefault =
3129
#if FML_OS_LINUX || FML_OS_WIN
3230
true;
3331
#else
3432
false;
3533
#endif
3634

35+
// The contrast/gamma exponent applied in the shader ranges from 1.0 for black
36+
// text to 1.0 + kMaxGammaCorrection for white text. This interpolates the
37+
// exponent based on the text color's luminance. On Linux, 1.2 equates to a
38+
// maximum 2.2 sRGB gamma. On Windows, DirectWrite and GDI employ higher base
39+
// gamma and contrast enhancement, so 1.6 is used to match Skia's perceived
40+
// visual weight and edge sharpness.
41+
constexpr Scalar kMaxGammaCorrection =
42+
#if FML_OS_WIN
43+
1.6f;
44+
#else
45+
1.2f;
46+
#endif
47+
3748
Point SizeToPoint(Size size) {
3849
return Point(size.width, size.height);
3950
}
@@ -285,10 +296,6 @@ bool TextContents::Render(const ContentContext& renderer,
285296
// Calculate relative luminance using Rec. 709 luma coefficients.
286297
Scalar luma =
287298
color.red * 0.2126f + color.green * 0.7152f + color.blue * 0.0722f;
288-
// The contrast/gamma exponent applied in the shader ranges from 1.0 for
289-
// black text to 2.2 (standard sRGB gamma) for white text. This interpolates
290-
// the exponent based on the text color's luminance.
291-
constexpr Scalar kMaxGammaCorrection = 1.2f;
292299
frag_info.text_contrast = 1.0f + luma * kMaxGammaCorrection;
293300
} else {
294301
frag_info.text_contrast = 1.0f;

0 commit comments

Comments
 (0)