diff options
author | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2014-04-15 17:53:21 +0000 |
---|---|---|
committer | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2014-04-15 17:53:21 +0000 |
commit | 64b08a1026851a84031713f0e12a3e59d55ce808 (patch) | |
tree | df26732c34ec830af5e9260ab712c7d2982ee319 | |
parent | 51b0d0bc5c82f257dca244c864702c66d84100a2 (diff) |
Fix artifacts in distance field rendering due to bilerp
Because we were using the full distance field glyph rect, there were cases
when a neighboring texel might be set to full value (e.g. we might copy the
glyph over old data after a purge). This was giving artifacts, and insetting
the rect by 1 solves the problem. In doing this, I discovered that removing the
extra 1 texel pad around the glyph meant to handle bilerp, and insetting by 2,
works just as well and saves space in the glyph atlas.
R=bsalomon@google.com
Author: jvanverth@google.com
Review URL: https://codereview.chromium.org/239333002
git-svn-id: http://skia.googlecode.com/svn/trunk@14203 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r-- | src/core/SkDistanceFieldGen.h | 5 | ||||
-rwxr-xr-x | src/gpu/GrDistanceFieldTextContext.cpp | 17 |
2 files changed, 12 insertions, 10 deletions
diff --git a/src/core/SkDistanceFieldGen.h b/src/core/SkDistanceFieldGen.h index 756cff14a3..0510907f8c 100644 --- a/src/core/SkDistanceFieldGen.h +++ b/src/core/SkDistanceFieldGen.h @@ -14,8 +14,9 @@ #define SK_DistanceFieldMagnitude 4 // we need to pad around the original glyph to allow our maximum distance of // SK_DistanceFieldMagnitude texels away from any edge -// we add one to this pad to allow for bilerp -#define SK_DistanceFieldPad (SK_DistanceFieldMagnitude+1) +#define SK_DistanceFieldPad 4 +// the rect we render with is inset from the distance field glyph size to allow for bilerp +#define SK_DistanceFieldInset 2 // for the fragment shader // The distance field is constructed as unsigned char values, so that the zero value is at 128, diff --git a/src/gpu/GrDistanceFieldTextContext.cpp b/src/gpu/GrDistanceFieldTextContext.cpp index 448e709805..238bcca46b 100755 --- a/src/gpu/GrDistanceFieldTextContext.cpp +++ b/src/gpu/GrDistanceFieldTextContext.cpp @@ -14,6 +14,7 @@ #include "GrIndexBuffer.h" #include "GrTextStrike.h" #include "GrTextStrike_impl.h" +#include "SkDistanceFieldGen.h" #include "SkDraw.h" #include "SkGpuDevice.h" #include "SkPath.h" @@ -295,10 +296,10 @@ HAS_ATLAS: SkASSERT(2*sizeof(SkPoint) == fDrawTarget->getDrawState().getVertexSize()); } - SkScalar dx = SkIntToScalar(glyph->fBounds.fLeft); - SkScalar dy = SkIntToScalar(glyph->fBounds.fTop); - SkScalar width = SkIntToScalar(glyph->fBounds.width()); - SkScalar height = SkIntToScalar(glyph->fBounds.height()); + SkScalar dx = SkIntToScalar(glyph->fBounds.fLeft + SK_DistanceFieldInset); + SkScalar dy = SkIntToScalar(glyph->fBounds.fTop + SK_DistanceFieldInset); + SkScalar width = SkIntToScalar(glyph->fBounds.width() - 2*SK_DistanceFieldInset); + SkScalar height = SkIntToScalar(glyph->fBounds.height() - 2*SK_DistanceFieldInset); SkScalar scale = fTextRatio; dx *= scale; @@ -308,10 +309,10 @@ HAS_ATLAS: width *= scale; height *= scale; - SkFixed tx = SkIntToFixed(glyph->fAtlasLocation.fX); - SkFixed ty = SkIntToFixed(glyph->fAtlasLocation.fY); - SkFixed tw = SkIntToFixed(glyph->fBounds.width()); - SkFixed th = SkIntToFixed(glyph->fBounds.height()); + SkFixed tx = SkIntToFixed(glyph->fAtlasLocation.fX + SK_DistanceFieldInset); + SkFixed ty = SkIntToFixed(glyph->fAtlasLocation.fY + SK_DistanceFieldInset); + SkFixed tw = SkIntToFixed(glyph->fBounds.width() - 2*SK_DistanceFieldInset); + SkFixed th = SkIntToFixed(glyph->fBounds.height() - 2*SK_DistanceFieldInset); static const size_t kVertexSize = 2 * sizeof(SkPoint); fVertices[2*fCurrVertex].setRectFan(sx, |