Skip to content

Commit 4613261

Browse files
committed
[Skia] Text rendered as much less heavy compared to other browsers
https://bugs.webkit.org/show_bug.cgi?id=309152 Reviewed by Carlos Garcia Campos. This change makes all the text rendered by skia look right - i.e. just like in other browsers - by incorrectly blending in linear color space despite target being in non-linear color space. Until this patch, the rendering was done mathematically correct i.e. the blending was done with respect to target's color space. However, historically, many fonts were designed for incorrect blending and hence they look the most "correct" in such a circumstances. As skia internally implements so called "gamma hack", this change tweaks SkSurfaceProps to properly tune it so that text looks correct. Despite chromium uses 0.2 for contrast and 1.2 for gamma, this change chooses 0 for contrast and 1 for gamma, as the results are visually indistinguishable and yet in some reftests, the differences between anti-aliased pixels are smaller. So in other words, this change makes text anti-aliasing more stable (uniform) when it comes to very small, sub-pixel positioning differences. No new tests. Canonical link: https://commits.webkit.org/308692@main
1 parent 0db582d commit 4613261

File tree

13 files changed

+19
-9
lines changed

13 files changed

+19
-9
lines changed

LayoutTests/fast/snapshot/nested-stacking-context.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4-
<meta name="fuzzy" content="maxDifference=0-1; totalPixels=0-10000" />
4+
<meta name="fuzzy" content="maxDifference=0-2; totalPixels=0-10000" />
55
<style>
66
#box {
77
width: 100px;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<!DOCTYPE HTML>
22
<link rel="help" href="https://drafts.csswg.org/css-text-decor-3/#text-shadow-property">
33
<link rel="match" href="color-inherit-ref.html">
4+
<meta name="fuzzy" content="maxDifference=0-1; totalPixels=0-1">
45
<div style="position: absolute; top: 24px; left: 24px; color: blue; text-shadow: 3px 3px;">Hello</div>
56

LayoutTests/imported/w3c/web-platform-tests/css/css-view-transitions/table-caption.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<link rel="author" href="mailto:[email protected]" title="Emilio Cobos Álvarez">
88
<link rel="author" href="https://mozilla.org" title="Mozilla">
99
<link rel="match" href="table-caption-ref.html">
10+
<meta name="fuzzy" content="maxDifference=0-1; totalPixels=0-3">
1011
<style>
1112
table {
1213
view-transition-name: table;

LayoutTests/imported/w3c/web-platform-tests/webvtt/rendering/cues-with-video/processing-model/selectors/cue_function/bold_object/bold_timestamp_future.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<html class="reftest-wait">
33
<title>WebVTT rendering, bold object transition with timestamp, ::cue(b:future) selector</title>
44
<link rel="match" href="bold_timestamp_future-ref.html">
5+
<meta name="fuzzy" content="maxDifference=0-1; totalPixels=0-1">
56
<style>
67
html { overflow:hidden }
78
body { margin:0 }

LayoutTests/imported/w3c/web-platform-tests/webvtt/rendering/cues-with-video/processing-model/selectors/cue_function/not_root_selector.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<html class="reftest-wait">
33
<title>WebVTT rendering, ::cue(:not(:root)) should not match the root</title>
44
<link rel="match" href="not_root_selector-ref.html">
5+
<meta name="fuzzy" content="maxDifference=0-1; totalPixels=0-1">
56
<style>
67
html { overflow:hidden }
78
body { margin:0 }

Source/WebCore/platform/graphics/FontRenderOptions.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ class FontRenderOptions {
8181
#if USE(CAIRO)
8282
const cairo_font_options_t* fontOptions() const { return m_fontOptions.get(); }
8383
#elif USE(SKIA)
84+
// Custom text settings make text look better at the expense of incorrect blending which is industry standard.
85+
static constexpr SkScalar s_textContrast { 0 };
86+
static constexpr SkScalar s_textGamma { 1 };
87+
88+
SkSurfaceProps createSurfaceProps(uint32_t flags = 0) const { return { flags, subpixelOrder(), s_textContrast, s_textGamma }; }
89+
8490
SkFontHinting hinting() const;
8591
SkFont::Edging antialias() const;
8692
SkPixelGeometry subpixelOrder() const;

Source/WebCore/platform/graphics/skia/GraphicsContextSkia.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1154,7 +1154,7 @@ static sk_sp<SkSurface> createAcceleratedSurface(const IntSize& size)
11541154
RELEASE_ASSERT(grContext);
11551155

11561156
auto imageInfo = SkImageInfo::Make(size.width(), size.height(), kRGBA_8888_SkColorType, kPremul_SkAlphaType, SkColorSpace::MakeSRGB());
1157-
SkSurfaceProps properties { 0, FontRenderOptions::singleton().subpixelOrder() };
1157+
SkSurfaceProps properties = FontRenderOptions::singleton().createSurfaceProps();
11581158
auto surface = SkSurfaces::RenderTarget(grContext, skgpu::Budgeted::kNo, imageInfo, PlatformDisplay::sharedDisplay().msaaSampleCount(), kTopLeft_GrSurfaceOrigin, &properties);
11591159
if (!surface || !surface->getCanvas())
11601160
return nullptr;

Source/WebCore/platform/graphics/skia/ImageBufferSkiaAcceleratedBackend.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ std::unique_ptr<ImageBufferSkiaAcceleratedBackend> ImageBufferSkiaAcceleratedBac
121121
flags |= SkSurfaceProps::kDynamicMSAA_Flag;
122122
msaaSampleCount = 1;
123123
}
124-
SkSurfaceProps properties { flags, FontRenderOptions::singleton().subpixelOrder() };
124+
SkSurfaceProps properties = FontRenderOptions::singleton().createSurfaceProps(flags);
125125
auto surface = SkSurfaces::RenderTarget(grContext, skgpu::Budgeted::kNo, imageInfo, msaaSampleCount, kTopLeft_GrSurfaceOrigin, &properties);
126126
if (!surface || !surface->getCanvas())
127127
return nullptr;

Source/WebCore/platform/graphics/skia/ImageBufferSkiaUnacceleratedBackend.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ std::unique_ptr<ImageBufferSkiaUnacceleratedBackend> ImageBufferSkiaUnaccelerate
4646
return nullptr;
4747

4848
auto imageInfo = SkImageInfo::MakeN32Premul(backendSize.width(), backendSize.height(), parameters.colorSpace.platformColorSpace());
49-
SkSurfaceProps properties = { 0, FontRenderOptions::singleton().subpixelOrder() };
49+
SkSurfaceProps properties = FontRenderOptions::singleton().createSurfaceProps();
5050
auto surface = SkSurfaces::Raster(imageInfo, &properties);
5151
if (!surface || !surface->getCanvas())
5252
return nullptr;

Source/WebCore/platform/graphics/skia/PlatformDisplaySkia.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ static unsigned initializeMSAASampleCount(GrDirectContext* grContext)
217217
// knows there are bugs. The only way to know whether our sample count will work is trying to create a
218218
// surface with that value and check whether it works.
219219
auto imageInfo = SkImageInfo::Make(512, 512, kRGBA_8888_SkColorType, kPremul_SkAlphaType, SkColorSpace::MakeSRGB());
220-
SkSurfaceProps properties = { 0, FontRenderOptions::singleton().subpixelOrder() };
220+
SkSurfaceProps properties = FontRenderOptions::singleton().createSurfaceProps();
221221
auto surface = SkSurfaces::RenderTarget(grContext, skgpu::Budgeted::kNo, imageInfo, sampleCount, kTopLeft_GrSurfaceOrigin, &properties);
222222

223223
// If the creation of the surface failed, disable MSAA.

0 commit comments

Comments
 (0)