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
diff --git a/src/gpu/GrDistanceFieldTextContext.cpp b/src/gpu/GrDistanceFieldTextContext.cpp
index bd3927c..27323c4 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 @@
 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 @@
         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 @@
     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;
 }