aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/effects/GrDistanceFieldGeoProc.cpp
diff options
context:
space:
mode:
authorGravatar Jim Van Verth <jvanverth@google.com>2017-07-06 16:36:55 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-07-06 21:24:17 +0000
commit90e89b366a7dc90111c861ba76c492ce1743a0d1 (patch)
treefe2c43e52dc3d811669b107f5124c39c4acb0e72 /src/gpu/effects/GrDistanceFieldGeoProc.cpp
parent24a2ecfa256042efd57fd97b23dbce5a49b92a94 (diff)
Add proper aliased support for SDF text
Previously, when asked to render aliased text with distance fields, we would get the aliased glyph from the cache and then try to anti-alias the edge. This change instead grabs the anti-aliased glyph, then deliberately aliases the edge. Bug: chromium:707979 Change-Id: I05766af17d7ae58bca27aaffd9e08e5c586e789c Reviewed-on: https://skia-review.googlesource.com/21728 Commit-Queue: Jim Van Verth <jvanverth@google.com> Reviewed-by: Brian Salomon <bsalomon@google.com>
Diffstat (limited to 'src/gpu/effects/GrDistanceFieldGeoProc.cpp')
-rw-r--r--src/gpu/effects/GrDistanceFieldGeoProc.cpp12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/gpu/effects/GrDistanceFieldGeoProc.cpp b/src/gpu/effects/GrDistanceFieldGeoProc.cpp
index f0f4ec4fa3..c8dd4ebd77 100644
--- a/src/gpu/effects/GrDistanceFieldGeoProc.cpp
+++ b/src/gpu/effects/GrDistanceFieldGeoProc.cpp
@@ -77,6 +77,8 @@ public:
bool isSimilarity = SkToBool(dfTexEffect.getFlags() & kSimilarity_DistanceFieldEffectFlag);
bool isGammaCorrect =
SkToBool(dfTexEffect.getFlags() & kGammaCorrect_DistanceFieldEffectFlag);
+ bool isAliased =
+ SkToBool(dfTexEffect.getFlags() & kAliased_DistanceFieldEffectFlag);
varyingHandler->addVarying("TextureCoords", &uv, kHigh_GrSLPrecision);
vertBuilder->codeAppendf("%s = %s;", uv.vsOut(), dfTexEffect.inTextureCoords()->fName);
@@ -158,10 +160,12 @@ public:
fragBuilder->codeAppend("afwidth = " SK_DistanceFieldAAFactor "*length(grad);");
}
- // The smoothstep falloff compensates for the non-linear sRGB response curve. If we are
- // doing gamma-correct rendering (to an sRGB or F16 buffer), then we actually want distance
- // mapped linearly to coverage, so use a linear step:
- if (isGammaCorrect) {
+ if (isAliased) {
+ fragBuilder->codeAppend("float val = distance > 0 ? 1.0 : 0.0;");
+ } else if (isGammaCorrect) {
+ // The smoothstep falloff compensates for the non-linear sRGB response curve. If we are
+ // doing gamma-correct rendering (to an sRGB or F16 buffer), then we actually want
+ // distance mapped linearly to coverage, so use a linear step:
fragBuilder->codeAppend(
"float val = clamp((distance + afwidth) / (2.0 * afwidth), 0.0, 1.0);");
} else {