diff options
author | 2014-02-14 21:48:29 +0000 | |
---|---|---|
committer | 2014-02-14 21:48:29 +0000 | |
commit | 6c89c34614573797ce63e429229b6f7848df0bb7 (patch) | |
tree | 2df08f36c986bc11916b79faceb9350d1cd496f2 /src/gpu/GrDistanceFieldTextContext.cpp | |
parent | 9836bc3fdddd51ed050102d03916cc5c7928dcc6 (diff) |
Improved distance field sampling
There are two different fixes here. First, it computes the distance value properly within the shader. Second, it handles anti-aliasing properly by doing a correction based on the gradient of the texture coordinates.
R=bsalomon@google.com, reed@google.com
Author: jvanverth@google.com
Review URL: https://codereview.chromium.org/149853002
git-svn-id: http://skia.googlecode.com/svn/trunk@13461 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/gpu/GrDistanceFieldTextContext.cpp')
-rwxr-xr-x | src/gpu/GrDistanceFieldTextContext.cpp | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/gpu/GrDistanceFieldTextContext.cpp b/src/gpu/GrDistanceFieldTextContext.cpp index bd3927c648..27323c4e60 100755 --- a/src/gpu/GrDistanceFieldTextContext.cpp +++ b/src/gpu/GrDistanceFieldTextContext.cpp @@ -8,6 +8,7 @@ #include "GrDistanceFieldTextContext.h" #include "GrAtlas.h" #include "GrDrawTarget.h" +#include "GrDrawTargetCaps.h" #include "GrFontScaler.h" #include "SkGlyphCache.h" #include "GrIndexBuffer.h" @@ -46,6 +47,7 @@ GrDistanceFieldTextContext::~GrDistanceFieldTextContext() { bool GrDistanceFieldTextContext::canDraw(const SkPaint& paint) { return !paint.getRasterizer() && !paint.getMaskFilter() && paint.getStyle() == SkPaint::kFill_Style && + fContext->getTextTarget()->caps()->shaderDerivativeSupport() && !SkDraw::ShouldDrawTextAsPaths(paint, fContext->getMatrix()); } @@ -72,8 +74,9 @@ void GrDistanceFieldTextContext::flushGlyphs() { GrTextureParams params(SkShader::kRepeat_TileMode, GrTextureParams::kBilerp_FilterMode); // This effect could be stored with one of the cache objects (atlas?) + SkISize size = fStrike->getAtlasSize(); drawState->addCoverageEffect( - GrDistanceFieldTextureEffect::Create(fCurrTexture, params), + GrDistanceFieldTextureEffect::Create(fCurrTexture, params, size), kGlyphCoordsAttributeIndex)->unref(); if (!GrPixelConfigIsAlphaOnly(fCurrTexture->config())) { @@ -263,22 +266,23 @@ HAS_ATLAS: sy += dy; width *= scale; height *= scale; - + GrFixed tx = SkIntToFixed(glyph->fAtlasLocation.fX); GrFixed ty = SkIntToFixed(glyph->fAtlasLocation.fY); GrFixed tw = SkIntToFixed(glyph->fBounds.width()); GrFixed th = SkIntToFixed(glyph->fBounds.height()); + static const size_t kVertexSize = 2 * sizeof(SkPoint); fVertices[2*fCurrVertex].setRectFan(sx, sy, sx + width, sy + height, - 2 * sizeof(SkPoint)); + kVertexSize); fVertices[2*fCurrVertex+1].setRectFan(SkFixedToFloat(texture->normalizeFixedX(tx)), SkFixedToFloat(texture->normalizeFixedY(ty)), SkFixedToFloat(texture->normalizeFixedX(tx + tw)), SkFixedToFloat(texture->normalizeFixedY(ty + th)), - 2 * sizeof(SkPoint)); + kVertexSize); fCurrVertex += 4; } |