Use uint16s for texture coordinates when rendering text.

Allows us to push more vertices into a given vertex buffer, with
a slight performance improvement.

Review URL: https://codereview.chromium.org/917373002
diff --git a/gyp/gpu.gypi b/gyp/gpu.gypi
index 68264f0..fe21d83 100644
--- a/gyp/gpu.gypi
+++ b/gyp/gpu.gypi
@@ -84,6 +84,7 @@
       '<(skia_src_path)/gpu/GrDrawTargetCaps.h',
       '<(skia_src_path)/gpu/GrFlushToGpuDrawTarget.cpp',
       '<(skia_src_path)/gpu/GrFlushToGpuDrawTarget.h',
+      '<(skia_src_path)/gpu/GrFontAtlasSizes.h',
       '<(skia_src_path)/gpu/GrFontScaler.cpp',
       '<(skia_src_path)/gpu/GrFontScaler.h',
       '<(skia_src_path)/gpu/GrGeometryBuffer.h',
diff --git a/include/gpu/GrTypesPriv.h b/include/gpu/GrTypesPriv.h
index 1f86197..412de89 100644
--- a/include/gpu/GrTypesPriv.h
+++ b/include/gpu/GrTypesPriv.h
@@ -116,9 +116,11 @@
     kVec4f_GrVertexAttribType,
 
     kUByte_GrVertexAttribType,   // unsigned byte, e.g. coverage
-    kVec4ub_GrVertexAttribType,   // vector of 4 unsigned bytes, e.g. colors
+    kVec4ub_GrVertexAttribType,  // vector of 4 unsigned bytes, e.g. colors
 
-    kLast_GrVertexAttribType = kVec4ub_GrVertexAttribType
+    kVec2s_GrVertexAttribType,   // vector of 2 shorts, e.g. texture coordinates
+    
+    kLast_GrVertexAttribType = kVec2s_GrVertexAttribType
 };
 static const int kGrVertexAttribTypeCount = kLast_GrVertexAttribType + 1;
 
@@ -127,7 +129,7 @@
  */
 static inline int GrVertexAttribTypeVectorCount(GrVertexAttribType type) {
     SkASSERT(type >= 0 && type < kGrVertexAttribTypeCount);
-    static const int kCounts[] = { 1, 2, 3, 4, 1, 4 };
+    static const int kCounts[] = { 1, 2, 3, 4, 1, 4, 2 };
     return kCounts[type];
 
     GR_STATIC_ASSERT(0 == kFloat_GrVertexAttribType);
@@ -136,6 +138,7 @@
     GR_STATIC_ASSERT(3 == kVec4f_GrVertexAttribType);
     GR_STATIC_ASSERT(4 == kUByte_GrVertexAttribType);
     GR_STATIC_ASSERT(5 == kVec4ub_GrVertexAttribType);
+    GR_STATIC_ASSERT(6 == kVec2s_GrVertexAttribType);
     GR_STATIC_ASSERT(SK_ARRAY_COUNT(kCounts) == kGrVertexAttribTypeCount);
 }
 
@@ -150,7 +153,8 @@
         3*sizeof(float),        // kVec3f_GrVertexAttribType
         4*sizeof(float),        // kVec4f_GrVertexAttribType
         1*sizeof(char),         // kUByte_GrVertexAttribType
-        4*sizeof(char)          // kVec4ub_GrVertexAttribType
+        4*sizeof(char),         // kVec4ub_GrVertexAttribType
+        2*sizeof(int16_t)       // kVec2s_GrVertexAttribType
     };
     return kSizes[type];
 
@@ -160,6 +164,7 @@
     GR_STATIC_ASSERT(3 == kVec4f_GrVertexAttribType);
     GR_STATIC_ASSERT(4 == kUByte_GrVertexAttribType);
     GR_STATIC_ASSERT(5 == kVec4ub_GrVertexAttribType);
+    GR_STATIC_ASSERT(6 == kVec2s_GrVertexAttribType);
     GR_STATIC_ASSERT(SK_ARRAY_COUNT(kSizes) == kGrVertexAttribTypeCount);
 }
 
@@ -173,6 +178,7 @@
         case kUByte_GrVertexAttribType:
         case kFloat_GrVertexAttribType:
             return kFloat_GrSLType;
+        case kVec2s_GrVertexAttribType:
         case kVec2f_GrVertexAttribType:
             return kVec2f_GrSLType;
         case kVec3f_GrVertexAttribType:
diff --git a/src/gpu/GrAADistanceFieldPathRenderer.cpp b/src/gpu/GrAADistanceFieldPathRenderer.cpp
index f2d618e..482358b 100755
--- a/src/gpu/GrAADistanceFieldPathRenderer.cpp
+++ b/src/gpu/GrAADistanceFieldPathRenderer.cpp
@@ -19,10 +19,10 @@
 #include "SkDistanceFieldGen.h"
 #include "SkRTConf.h"
 
-#define ATLAS_TEXTURE_WIDTH 1024
+#define ATLAS_TEXTURE_WIDTH  1024
 #define ATLAS_TEXTURE_HEIGHT 2048
-#define PLOT_WIDTH  256
-#define PLOT_HEIGHT 256
+#define PLOT_WIDTH           256
+#define PLOT_HEIGHT          256
 
 #define NUM_PLOTS_X   (ATLAS_TEXTURE_WIDTH / PLOT_WIDTH)
 #define NUM_PLOTS_Y   (ATLAS_TEXTURE_HEIGHT / PLOT_HEIGHT)
@@ -342,39 +342,41 @@
     bool success = target->reserveVertexAndIndexSpace(4,
                                                       fCachedGeometryProcessor->getVertexStride(),
                                                       0, &vertices, NULL);
-    SkASSERT(fCachedGeometryProcessor->getVertexStride() == 2 * sizeof(SkPoint));
+    SkASSERT(fCachedGeometryProcessor->getVertexStride() == sizeof(SkPoint) + sizeof(SkIPoint16));
     GrAlwaysAssert(success);
     
     SkScalar dx = pathData->fBounds.fLeft;
     SkScalar dy = pathData->fBounds.fTop;
-    SkScalar width = pathData->fBounds.width();
-    SkScalar height = pathData->fBounds.height();
+    // need to compute integer sizes for the glyph because we're using
+    // uint16_t tex coords and they need to lie on integer texel bounds
+    int iwidth = SkScalarCeilToInt(pathData->fBounds.width());
+    int iheight = SkScalarCeilToInt(pathData->fBounds.height());
+    // the quad rect before we scale needs to be the same size as the path data in the atlas
+    SkScalar width = SkIntToScalar(iwidth);
+    SkScalar height = SkIntToScalar(iheight);
     
     SkScalar invScale = 1.0f/pathData->fScale;
     dx *= invScale;
     dy *= invScale;
     width *= invScale;
     height *= invScale;
-    
-    SkFixed tx = SkIntToFixed(pathData->fAtlasLocation.fX);
-    SkFixed ty = SkIntToFixed(pathData->fAtlasLocation.fY);
-    SkFixed tw = SkScalarToFixed(pathData->fBounds.width());
-    SkFixed th = SkScalarToFixed(pathData->fBounds.height());
-    
+
+    int u0 = pathData->fAtlasLocation.fX;
+    int v0 = pathData->fAtlasLocation.fY;
+    int u1 = u0 + iwidth;
+    int v1 = v0 + iheight;
     // vertex positions
     SkRect r = SkRect::MakeXYWH(dx, dy, width, height);    
-    size_t vertSize = 2 * sizeof(SkPoint);
+    size_t vertSize = sizeof(SkPoint) + sizeof(SkIPoint16);
     SkPoint* positions = reinterpret_cast<SkPoint*>(vertices);
     positions->setRectFan(r.left(), r.top(), r.right(), r.bottom(), vertSize);
     
     // vertex texture coords
-    intptr_t intPtr = reinterpret_cast<intptr_t>(positions);
-    SkPoint* textureCoords = reinterpret_cast<SkPoint*>(intPtr + vertSize - sizeof(SkPoint));
-    textureCoords->setRectFan(SkFixedToFloat(texture->texturePriv().normalizeFixedX(tx)),
-                              SkFixedToFloat(texture->texturePriv().normalizeFixedY(ty)),
-                              SkFixedToFloat(texture->texturePriv().normalizeFixedX(tx + tw)),
-                              SkFixedToFloat(texture->texturePriv().normalizeFixedY(ty + th)),
-                              vertSize);
+    intptr_t textureCoords = reinterpret_cast<intptr_t>(positions) + vertSize - sizeof(SkIPoint16);
+    ((SkIPoint16*)(textureCoords + 0 * vertSize))->set(u0, v0);
+    ((SkIPoint16*)(textureCoords + 1 * vertSize))->set(u0, v1);
+    ((SkIPoint16*)(textureCoords + 2 * vertSize))->set(u1, v1);
+    ((SkIPoint16*)(textureCoords + 3 * vertSize))->set(u1, v0);
     
     viewMatrix.mapRect(&r);
     target->setIndexSourceToBuffer(fContext->getQuadIndexBuffer());
diff --git a/src/gpu/GrBitmapTextContext.cpp b/src/gpu/GrBitmapTextContext.cpp
index 5e5aa6a..21afc61 100755
--- a/src/gpu/GrBitmapTextContext.cpp
+++ b/src/gpu/GrBitmapTextContext.cpp
@@ -34,12 +34,12 @@
                 "Dump the contents of the font cache before every purge.");
 
 namespace {
-static const size_t kLCDTextVASize = 2 * sizeof(SkPoint);
+static const size_t kLCDTextVASize = sizeof(SkPoint) + sizeof(SkIPoint16);
 
 // position + local coord
-static const size_t kColorTextVASize = 2 * sizeof(SkPoint);
+static const size_t kColorTextVASize = sizeof(SkPoint) + sizeof(SkIPoint16);
 
-static const size_t kGrayTextVASize = 2 * sizeof(SkPoint) + sizeof(GrColor);
+static const size_t kGrayTextVASize = sizeof(SkPoint) + sizeof(GrColor) + sizeof(SkIPoint16);
 
 static const int kVerticesPerGlyph = 4;
 static const int kIndicesPerGlyph = 6;
@@ -421,8 +421,8 @@
     vy += SkIntToFixed(glyph->fBounds.fTop);
 
     // keep them as ints until we've done the clip-test
-    SkFixed width = glyph->fBounds.width();
-    SkFixed height = glyph->fBounds.height();
+    int width = glyph->fBounds.width();
+    int height = glyph->fBounds.height();
 
     // check if we clipped out
     int x = vx >> 16;
@@ -463,10 +463,6 @@
     GrDrawTarget::DrawToken drawToken = fDrawTarget->getCurrentDrawToken();
     glyph->fPlot->setDrawToken(drawToken);
 
-    // now promote them to fixed (TODO: Rethink using fixed pt).
-    width = SkIntToFixed(width);
-    height = SkIntToFixed(height);
-
     // the current texture/maskformat must match what the glyph needs
     GrTexture* texture = glyph->fPlot->texture();
     SkASSERT(texture);
@@ -484,39 +480,66 @@
         fVertices = alloc_vertices(fDrawTarget, fAllocVertexCount, fCurrMaskFormat);
     }
 
-    SkFixed tx = SkIntToFixed(glyph->fAtlasLocation.fX);
-    SkFixed ty = SkIntToFixed(glyph->fAtlasLocation.fY);
-
     SkRect r;
     r.fLeft = SkFixedToFloat(vx);
     r.fTop = SkFixedToFloat(vy);
-    r.fRight = SkFixedToFloat(vx + width);
-    r.fBottom = SkFixedToFloat(vy + height);
+    r.fRight = r.fLeft + width;
+    r.fBottom = r.fTop + height;
 
     fVertexBounds.joinNonEmptyArg(r);
+    
+    int u0 = glyph->fAtlasLocation.fX;
+    int v0 = glyph->fAtlasLocation.fY;
+    int u1 = u0 + width;
+    int v1 = v0 + height;
 
     size_t vertSize = get_vertex_stride(fCurrMaskFormat);
+    intptr_t vertex = reinterpret_cast<intptr_t>(fVertices) + vertSize * fCurrVertex;
 
-    SkPoint* positions = reinterpret_cast<SkPoint*>(
-        reinterpret_cast<intptr_t>(fVertices) + vertSize * fCurrVertex);
-    positions->setRectFan(r.fLeft, r.fTop, r.fRight, r.fBottom, vertSize);
-
-    // The texture coords are last in both the with and without color vertex layouts.
-    SkPoint* textureCoords = reinterpret_cast<SkPoint*>(
-            reinterpret_cast<intptr_t>(positions) + vertSize  - sizeof(SkPoint));
-    textureCoords->setRectFan(SkFixedToFloat(texture->texturePriv().normalizeFixedX(tx)),
-                              SkFixedToFloat(texture->texturePriv().normalizeFixedY(ty)),
-                              SkFixedToFloat(texture->texturePriv().normalizeFixedX(tx + width)),
-                              SkFixedToFloat(texture->texturePriv().normalizeFixedY(ty + height)),
-                              vertSize);
+    // V0
+    SkPoint* position = reinterpret_cast<SkPoint*>(vertex);
+    position->set(r.fLeft, r.fTop);
     if (kA8_GrMaskFormat == fCurrMaskFormat) {
-        // color comes after position.
-        GrColor* colors = reinterpret_cast<GrColor*>(positions + 1);
-        for (int i = 0; i < 4; ++i) {
-           *colors = fPaint.getColor();
-           colors = reinterpret_cast<GrColor*>(reinterpret_cast<intptr_t>(colors) + vertSize);
-        }
+        SkColor* color = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint));
+        *color = fPaint.getColor();
     }
+    SkIPoint16* textureCoords = reinterpret_cast<SkIPoint16*>(vertex + vertSize -
+                                                              sizeof(SkIPoint16));
+    textureCoords->set(u0, v0);
+    vertex += vertSize;
+    
+    // V1
+    position = reinterpret_cast<SkPoint*>(vertex);
+    position->set(r.fLeft, r.fBottom);
+    if (kA8_GrMaskFormat == fCurrMaskFormat) {
+        SkColor* color = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint));
+        *color = fPaint.getColor();
+    }
+    textureCoords = reinterpret_cast<SkIPoint16*>(vertex + vertSize  - sizeof(SkIPoint16));
+    textureCoords->set(u0, v1);
+    vertex += vertSize;
+    
+    // V2
+    position = reinterpret_cast<SkPoint*>(vertex);
+    position->set(r.fRight, r.fBottom);
+    if (kA8_GrMaskFormat == fCurrMaskFormat) {
+        SkColor* color = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint));
+        *color = fPaint.getColor();
+    }
+    textureCoords = reinterpret_cast<SkIPoint16*>(vertex + vertSize  - sizeof(SkIPoint16));
+    textureCoords->set(u1, v1);
+    vertex += vertSize;
+    
+    // V3
+    position = reinterpret_cast<SkPoint*>(vertex);
+    position->set(r.fRight, r.fTop);
+    if (kA8_GrMaskFormat == fCurrMaskFormat) {
+        SkColor* color = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint));
+        *color = fPaint.getColor();
+    }
+    textureCoords = reinterpret_cast<SkIPoint16*>(vertex + vertSize  - sizeof(SkIPoint16));
+    textureCoords->set(u1, v0);
+
     fCurrVertex += 4;
 }
 
diff --git a/src/gpu/GrDistanceFieldTextContext.cpp b/src/gpu/GrDistanceFieldTextContext.cpp
index d3b0170..ee87385 100755
--- a/src/gpu/GrDistanceFieldTextContext.cpp
+++ b/src/gpu/GrDistanceFieldTextContext.cpp
@@ -374,8 +374,8 @@
 }
 
 static size_t get_vertex_stride(bool useColorVerts) {
-    return useColorVerts ? (2 * sizeof(SkPoint) + sizeof(GrColor)) :
-                           (2 * sizeof(SkPoint));
+    return useColorVerts ? (sizeof(SkPoint) + sizeof(GrColor) + sizeof(SkIPoint16)) :
+                           (sizeof(SkPoint) + sizeof(SkIPoint16));
 }
 
 static void* alloc_vertices(GrDrawTarget* drawTarget,
@@ -600,36 +600,59 @@
                                    useColorVerts);
     }
 
-    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);
-
     fVertexBounds.joinNonEmptyArg(glyphRect);
 
+    int u0 = glyph->fAtlasLocation.fX + SK_DistanceFieldInset;
+    int v0 = glyph->fAtlasLocation.fY + SK_DistanceFieldInset;
+    int u1 = u0 + glyph->fBounds.width() - 2*SK_DistanceFieldInset;
+    int v1 = v0 + glyph->fBounds.height() - 2*SK_DistanceFieldInset;
+
     size_t vertSize = get_vertex_stride(useColorVerts);
+    intptr_t vertex = reinterpret_cast<intptr_t>(fVertices) + vertSize * fCurrVertex;
 
-    SkPoint* positions = reinterpret_cast<SkPoint*>(
-                               reinterpret_cast<intptr_t>(fVertices) + vertSize * fCurrVertex);
-    positions->setRectFan(glyphRect.fLeft, glyphRect.fTop, glyphRect.fRight, glyphRect.fBottom,
-                          vertSize);
-
-    // The texture coords are last in both the with and without color vertex layouts.
-    SkPoint* textureCoords = reinterpret_cast<SkPoint*>(
-                               reinterpret_cast<intptr_t>(positions) + vertSize  - sizeof(SkPoint));
-    textureCoords->setRectFan(SkFixedToFloat(texture->texturePriv().normalizeFixedX(tx)),
-                              SkFixedToFloat(texture->texturePriv().normalizeFixedY(ty)),
-                              SkFixedToFloat(texture->texturePriv().normalizeFixedX(tx + tw)),
-                              SkFixedToFloat(texture->texturePriv().normalizeFixedY(ty + th)),
-                              vertSize);
+    // V0
+    SkPoint* position = reinterpret_cast<SkPoint*>(vertex);
+    position->set(glyphRect.fLeft, glyphRect.fTop);
     if (useColorVerts) {
-        // color comes after position.
-        GrColor* colors = reinterpret_cast<GrColor*>(positions + 1);
-        for (int i = 0; i < 4; ++i) {
-            *colors = fPaint.getColor();
-            colors = reinterpret_cast<GrColor*>(reinterpret_cast<intptr_t>(colors) + vertSize);
-        }
+        SkColor* color = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint));
+        *color = fPaint.getColor();
     }
+    SkIPoint16* textureCoords = reinterpret_cast<SkIPoint16*>(vertex + vertSize -
+                                                              sizeof(SkIPoint16));
+    textureCoords->set(u0, v0);
+    vertex += vertSize;
+
+    // V1
+    position = reinterpret_cast<SkPoint*>(vertex);
+    position->set(glyphRect.fLeft, glyphRect.fBottom);
+    if (useColorVerts) {
+        SkColor* color = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint));
+        *color = fPaint.getColor();
+    }
+    textureCoords = reinterpret_cast<SkIPoint16*>(vertex + vertSize  - sizeof(SkIPoint16));
+    textureCoords->set(u0, v1);
+    vertex += vertSize;
+
+    // V2
+    position = reinterpret_cast<SkPoint*>(vertex);
+    position->set(glyphRect.fRight, glyphRect.fBottom);
+    if (useColorVerts) {
+        SkColor* color = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint));
+        *color = fPaint.getColor();
+    }
+    textureCoords = reinterpret_cast<SkIPoint16*>(vertex + vertSize  - sizeof(SkIPoint16));
+    textureCoords->set(u1, v1);
+    vertex += vertSize;
+
+    // V3
+    position = reinterpret_cast<SkPoint*>(vertex);
+    position->set(glyphRect.fRight, glyphRect.fTop);
+    if (useColorVerts) {
+        SkColor* color = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint));
+        *color = fPaint.getColor();
+    }
+    textureCoords = reinterpret_cast<SkIPoint16*>(vertex + vertSize  - sizeof(SkIPoint16));
+    textureCoords->set(u1, v0);
 
     fCurrVertex += 4;
     
diff --git a/src/gpu/GrFontAtlasSizes.h b/src/gpu/GrFontAtlasSizes.h
new file mode 100644
index 0000000..24897e4
--- /dev/null
+++ b/src/gpu/GrFontAtlasSizes.h
@@ -0,0 +1,28 @@
+
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef GrFontAtlasSizes_DEFINED
+#define GrFontAtlasSizes_DEFINED
+
+#define GR_FONT_ATLAS_TEXTURE_WIDTH  1024
+#define GR_FONT_ATLAS_TEXTURE_HEIGHT 2048
+
+#define GR_FONT_ATLAS_PLOT_WIDTH     256
+#define GR_FONT_ATLAS_PLOT_HEIGHT    256
+
+#define GR_FONT_ATLAS_NUM_PLOTS_X   (GR_FONT_ATLAS_TEXTURE_WIDTH / GR_FONT_ATLAS_PLOT_WIDTH)
+#define GR_FONT_ATLAS_NUM_PLOTS_Y   (GR_FONT_ATLAS_TEXTURE_HEIGHT / GR_FONT_ATLAS_PLOT_HEIGHT)
+
+// one over width and height
+#define GR_FONT_ATLAS_RECIP_WIDTH    "0.0009765625"
+#define GR_FONT_ATLAS_RECIP_HEIGHT   "0.00048828125"
+
+// 1/(3*width)
+#define GR_FONT_ATLAS_LCD_DELTA      "0.00032552083"
+
+#endif
diff --git a/src/gpu/GrFontCache.cpp b/src/gpu/GrFontCache.cpp
index 3e83e6c..2bc5567 100644
--- a/src/gpu/GrFontCache.cpp
+++ b/src/gpu/GrFontCache.cpp
@@ -6,6 +6,7 @@
  */
 
 #include "GrFontCache.h"
+#include "GrFontAtlasSizes.h"
 #include "GrGpu.h"
 #include "GrRectanizer.h"
 #include "GrSurfacePriv.h"
@@ -15,15 +16,6 @@
 
 ///////////////////////////////////////////////////////////////////////////////
 
-#define GR_ATLAS_TEXTURE_WIDTH 1024
-#define GR_ATLAS_TEXTURE_HEIGHT 2048
-
-#define GR_PLOT_WIDTH  256
-#define GR_PLOT_HEIGHT 256
-
-#define GR_NUM_PLOTS_X   (GR_ATLAS_TEXTURE_WIDTH / GR_PLOT_WIDTH)
-#define GR_NUM_PLOTS_Y   (GR_ATLAS_TEXTURE_HEIGHT / GR_PLOT_HEIGHT)
-
 #define FONT_CACHE_STATS 0
 #if FONT_CACHE_STATS
 static int g_PurgeCount = 0;
@@ -121,12 +113,12 @@
     GrPixelConfig config = mask_format_to_pixel_config(format);
     int atlasIndex = mask_format_to_atlas_index(format);
     if (NULL == fAtlases[atlasIndex]) {
-        SkISize textureSize = SkISize::Make(GR_ATLAS_TEXTURE_WIDTH,
-                                            GR_ATLAS_TEXTURE_HEIGHT);
+        SkISize textureSize = SkISize::Make(GR_FONT_ATLAS_TEXTURE_WIDTH,
+                                            GR_FONT_ATLAS_TEXTURE_HEIGHT);
         fAtlases[atlasIndex] = SkNEW_ARGS(GrAtlas, (fGpu, config, kNone_GrSurfaceFlags,
                                                     textureSize,
-                                                    GR_NUM_PLOTS_X,
-                                                    GR_NUM_PLOTS_Y,
+                                                    GR_FONT_ATLAS_NUM_PLOTS_X,
+                                                    GR_FONT_ATLAS_NUM_PLOTS_Y,
                                                     true));
     }
     return fAtlases[atlasIndex]->addToAtlas(usage, width, height, image, loc);
@@ -289,10 +281,10 @@
     int width = glyph->fBounds.width();
     int height = glyph->fBounds.height();
     int pad = fUseDistanceField ? 2 * SK_DistanceFieldPad : 0;
-    if (width + pad > GR_PLOT_WIDTH) {
+    if (width + pad > GR_FONT_ATLAS_PLOT_WIDTH) {
         return true;
     }
-    if (height + pad > GR_PLOT_HEIGHT) {
+    if (height + pad > GR_FONT_ATLAS_PLOT_HEIGHT) {
         return true;
     }
 
diff --git a/src/gpu/effects/GrBitmapTextGeoProc.cpp b/src/gpu/effects/GrBitmapTextGeoProc.cpp
index 2487b65..54e8891 100644
--- a/src/gpu/effects/GrBitmapTextGeoProc.cpp
+++ b/src/gpu/effects/GrBitmapTextGeoProc.cpp
@@ -6,6 +6,7 @@
  */
 
 #include "GrBitmapTextGeoProc.h"
+#include "GrFontAtlasSizes.h"
 #include "GrInvariantOutput.h"
 #include "GrTexture.h"
 #include "gl/GrGLProcessor.h"
@@ -37,7 +38,10 @@
 
         GrGLVertToFrag v(kVec2f_GrSLType);
         pb->addVarying("TextureCoords", &v);
-        vsBuilder->codeAppendf("%s = %s;", v.vsOut(), cte.inTextureCoords()->fName);
+        // this is only used with text, so our texture bounds always match the glyph atlas
+        vsBuilder->codeAppendf("%s = vec2(" GR_FONT_ATLAS_RECIP_WIDTH ", "
+                               GR_FONT_ATLAS_RECIP_HEIGHT ")*%s;", v.vsOut(),
+                               cte.inTextureCoords()->fName);
 
         // Setup pass through color
         this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor, cte.inColor(),
@@ -122,7 +126,7 @@
         this->setHasVertexColor();
     }
     fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords",
-                                                        kVec2f_GrVertexAttribType));
+                                                        kVec2s_GrVertexAttribType));
     this->addTextureAccess(&fTextureAccess);
 }
 
diff --git a/src/gpu/effects/GrDistanceFieldTextureEffect.cpp b/src/gpu/effects/GrDistanceFieldTextureEffect.cpp
index 1a8a07e..cdf998e 100755
--- a/src/gpu/effects/GrDistanceFieldTextureEffect.cpp
+++ b/src/gpu/effects/GrDistanceFieldTextureEffect.cpp
@@ -6,6 +6,7 @@
  */
 
 #include "GrDistanceFieldTextureEffect.h"
+#include "GrFontAtlasSizes.h"
 #include "GrInvariantOutput.h"
 #include "GrTexture.h"
 #include "SkDistanceFieldGen.h"
@@ -29,7 +30,6 @@
     GrGLDistanceFieldTextureEffect(const GrGeometryProcessor&,
                                    const GrBatchTracker&)
         : fColor(GrColor_ILLEGAL)
-        , fTextureSize(SkISize::Make(-1,-1))
 #ifdef SK_GAMMA_APPLY_TO_A8
         , fLuminance(-1.0f)
 #endif
@@ -49,9 +49,16 @@
         // emit attributes
         vsBuilder->emitAttributes(dfTexEffect);
 
-        GrGLVertToFrag v(kVec2f_GrSLType);
-        args.fPB->addVarying("TextureCoords", &v);
-        vsBuilder->codeAppendf("%s = %s;", v.vsOut(), dfTexEffect.inTextureCoords()->fName);
+        GrGLVertToFrag st(kVec2f_GrSLType);
+        args.fPB->addVarying("IntTextureCoords", &st);
+        vsBuilder->codeAppendf("%s = %s;", st.vsOut(), dfTexEffect.inTextureCoords()->fName);
+        
+        GrGLVertToFrag uv(kVec2f_GrSLType);
+        args.fPB->addVarying("TextureCoords", &uv);
+        // this is only used with text, so our texture bounds always match the glyph atlas
+        vsBuilder->codeAppendf("%s = vec2(" GR_FONT_ATLAS_RECIP_WIDTH ", "
+                               GR_FONT_ATLAS_RECIP_HEIGHT ")*%s;", uv.vsOut(),
+                               dfTexEffect.inTextureCoords()->fName);
 
         // Setup pass through color
         this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor,
@@ -64,15 +71,10 @@
         this->emitTransforms(args.fPB, gpArgs->fPositionVar, dfTexEffect.inPosition()->fName,
                              dfTexEffect.localMatrix(), args.fTransformsIn, args.fTransformsOut);
 
-        const char* textureSizeUniName = NULL;
-        fTextureSizeUni = args.fPB->addUniform(GrGLProgramBuilder::kFragment_Visibility,
-                                               kVec2f_GrSLType, kDefault_GrSLPrecision,
-                                               "TextureSize", &textureSizeUniName);
-
         // Use highp to work around aliasing issues
         fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPrecision,
                                                              pb->ctxInfo().standard()));
-        fsBuilder->codeAppendf("vec2 uv = %s;\n", v.fsIn());
+        fsBuilder->codeAppendf("vec2 uv = %s;\n", uv.fsIn());
 
         fsBuilder->codeAppend("\tfloat texColor = ");
         fsBuilder->appendTextureLookup(args.fSamplers[0],
@@ -87,7 +89,7 @@
         // to ensure we're mapping 1:1 from texel space to pixel space.
         fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPrecision,
                                                              pb->ctxInfo().standard()));
-        fsBuilder->codeAppendf("vec2 st = uv*%s;\n", textureSizeUniName);
+        fsBuilder->codeAppendf("vec2 st = %s;\n", st.fsIn());
         fsBuilder->codeAppend("\tfloat afwidth;\n");
         if (dfTexEffect.getFlags() & kSimilarity_DistanceFieldEffectFlag) {
             // this gives us a smooth step across approximately one fragment
@@ -137,16 +139,6 @@
     virtual void setData(const GrGLProgramDataManager& pdman,
                          const GrPrimitiveProcessor& proc,
                          const GrBatchTracker& bt) SK_OVERRIDE {
-        SkASSERT(fTextureSizeUni.isValid());
-
-        GrTexture* texture = proc.texture(0);
-        if (texture->width() != fTextureSize.width() ||
-            texture->height() != fTextureSize.height()) {
-            fTextureSize = SkISize::Make(texture->width(), texture->height());
-            pdman.set2f(fTextureSizeUni,
-                        SkIntToScalar(fTextureSize.width()),
-                        SkIntToScalar(fTextureSize.height()));
-        }
 #ifdef SK_GAMMA_APPLY_TO_A8
         const GrDistanceFieldTextureEffect& dfTexEffect =
                 proc.cast<GrDistanceFieldTextureEffect>();
@@ -184,8 +176,6 @@
 private:
     GrColor       fColor;
     UniformHandle fColorUniform;
-    UniformHandle fTextureSizeUni;
-    SkISize       fTextureSize;
     UniformHandle fLuminanceUni;
 #ifdef SK_GAMMA_APPLY_TO_A8
     float         fLuminance;
@@ -222,7 +212,7 @@
         this->setHasVertexColor();
     }
     fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords",
-                                                          kVec2f_GrVertexAttribType));
+                                                          kVec2s_GrVertexAttribType));
     this->addTextureAccess(&fTextureAccess);
 #ifdef SK_GAMMA_APPLY_TO_A8
     this->addTextureAccess(&fGammaTextureAccess);
@@ -326,7 +316,7 @@
 public:
     GrGLDistanceFieldNoGammaTextureEffect(const GrGeometryProcessor&,
                                           const GrBatchTracker&)
-        : fColor(GrColor_ILLEGAL), fTextureSize(SkISize::Make(-1, -1)) {}
+        : fColor(GrColor_ILLEGAL) {}
 
     void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) SK_OVERRIDE{
         const GrDistanceFieldNoGammaTextureEffect& dfTexEffect =
@@ -344,15 +334,25 @@
         // emit attributes
         vsBuilder->emitAttributes(dfTexEffect);
 
-        GrGLVertToFrag v(kVec2f_GrSLType);
-        args.fPB->addVarying("TextureCoords", &v);
+        GrGLVertToFrag st(kVec2f_GrSLType);
+        args.fPB->addVarying("IntTextureCoords", &st);
+        vsBuilder->codeAppendf("%s = %s;", st.vsOut(), dfTexEffect.inTextureCoords()->fName);
+        
+        const char* recipTextureSizeUniName = NULL;
+        fRecipTextureSizeUni = args.fPB->addUniform(GrGLProgramBuilder::kVertex_Visibility,
+                                                    kVec2f_GrSLType, kDefault_GrSLPrecision,
+                                                    "RecipTextureSize", &recipTextureSizeUniName);
+        GrGLVertToFrag uv(kVec2f_GrSLType);
+        args.fPB->addVarying("TextureCoords", &uv);
+        // this GP can be used with either text or paths, so texture bound params need to
+        // be set by a uniform
+        vsBuilder->codeAppendf("%s = %s*%s;", uv.vsOut(), recipTextureSizeUniName,
+                               dfTexEffect.inTextureCoords()->fName);
 
         // setup pass through color
         this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor,
                                     dfTexEffect.inColor(), &fColorUniform);
 
-        vsBuilder->codeAppendf("%s = %s;", v.vsOut(), dfTexEffect.inTextureCoords()->fName);
-
         // Setup position
         this->setupPosition(pb, gpArgs, dfTexEffect.inPosition()->fName, dfTexEffect.viewMatrix());
 
@@ -360,15 +360,10 @@
         this->emitTransforms(args.fPB, gpArgs->fPositionVar, dfTexEffect.inPosition()->fName,
                              dfTexEffect.localMatrix(), args.fTransformsIn, args.fTransformsOut);
 
-        const char* textureSizeUniName = NULL;
-        fTextureSizeUni = args.fPB->addUniform(GrGLProgramBuilder::kFragment_Visibility,
-                                              kVec2f_GrSLType, kDefault_GrSLPrecision,
-                                              "TextureSize", &textureSizeUniName);
-
         // Use highp to work around aliasing issues
         fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPrecision,
                                                              pb->ctxInfo().standard()));
-        fsBuilder->codeAppendf("vec2 uv = %s;", v.fsIn());
+        fsBuilder->codeAppendf("vec2 uv = %s;", uv.fsIn());
 
         fsBuilder->codeAppend("float texColor = ");
         fsBuilder->appendTextureLookup(args.fSamplers[0],
@@ -383,7 +378,7 @@
         // to ensure we're mapping 1:1 from texel space to pixel space.
         fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPrecision,
                                                              pb->ctxInfo().standard()));
-        fsBuilder->codeAppendf("vec2 st = uv*%s;", textureSizeUniName);
+        fsBuilder->codeAppendf("vec2 st = %s;", st.fsIn());
         fsBuilder->codeAppend("float afwidth;");
         if (dfTexEffect.getFlags() & kSimilarity_DistanceFieldEffectFlag) {
             // this gives us a smooth step across approximately one fragment
@@ -418,15 +413,15 @@
     virtual void setData(const GrGLProgramDataManager& pdman,
                          const GrPrimitiveProcessor& proc,
                          const GrBatchTracker& bt) SK_OVERRIDE {
-        SkASSERT(fTextureSizeUni.isValid());
+        SkASSERT(fRecipTextureSizeUni.isValid());
 
         GrTexture* texture = proc.texture(0);
         if (texture->width() != fTextureSize.width() || 
             texture->height() != fTextureSize.height()) {
             fTextureSize = SkISize::Make(texture->width(), texture->height());
-            pdman.set2f(fTextureSizeUni,
-                        SkIntToScalar(fTextureSize.width()),
-                        SkIntToScalar(fTextureSize.height()));
+            pdman.set2f(fRecipTextureSizeUni,
+                        1.0f/SkIntToScalar(fTextureSize.width()),
+                        1.0f/SkIntToScalar(fTextureSize.height()));
         }
 
         this->setUniformViewMatrix(pdman, proc.viewMatrix());
@@ -457,7 +452,7 @@
 
 private:
     UniformHandle fColorUniform;
-    UniformHandle fTextureSizeUni;
+    UniformHandle fRecipTextureSizeUni;
     GrColor       fColor;
     SkISize       fTextureSize;
 
@@ -485,7 +480,7 @@
         this->setHasVertexColor();
     }
     fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords",
-                                                          kVec2f_GrVertexAttribType));
+                                                          kVec2s_GrVertexAttribType));
     this->addTextureAccess(&fTextureAccess);
 }
 
@@ -572,7 +567,6 @@
     GrGLDistanceFieldLCDTextureEffect(const GrGeometryProcessor&,
                                       const GrBatchTracker&)
     : fColor(GrColor_ILLEGAL)
-    , fTextureSize(SkISize::Make(-1,-1))
     , fTextColor(GrColor_ILLEGAL) {}
 
     void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) SK_OVERRIDE{
@@ -586,10 +580,17 @@
         // emit attributes
         vsBuilder->emitAttributes(dfTexEffect);
 
-        GrGLVertToFrag v(kVec2f_GrSLType);
-        args.fPB->addVarying("TextureCoords", &v);
-        vsBuilder->codeAppendf("%s = %s;", v.vsOut(), dfTexEffect.inTextureCoords()->fName);
-
+        GrGLVertToFrag st(kVec2f_GrSLType);
+        args.fPB->addVarying("IntTextureCoords", &st);
+        vsBuilder->codeAppendf("%s = %s;", st.vsOut(), dfTexEffect.inTextureCoords()->fName);
+        
+        GrGLVertToFrag uv(kVec2f_GrSLType);
+        args.fPB->addVarying("TextureCoords", &uv);
+        // this is only used with text, so our texture bounds always match the glyph atlas
+        vsBuilder->codeAppendf("%s = vec2(" GR_FONT_ATLAS_RECIP_WIDTH ", "
+                               GR_FONT_ATLAS_RECIP_HEIGHT ")*%s;", uv.vsOut(),
+                               dfTexEffect.inTextureCoords()->fName);
+        
         // setup pass through color
         this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor, NULL,
                                     &fColorUniform);
@@ -601,12 +602,6 @@
         this->emitTransforms(args.fPB, gpArgs->fPositionVar, dfTexEffect.inPosition()->fName,
                              dfTexEffect.localMatrix(), args.fTransformsIn, args.fTransformsOut);
 
-        const char* textureSizeUniName = NULL;
-        // width, height, 1/(3*width)
-        fTextureSizeUni = args.fPB->addUniform(GrGLProgramBuilder::kFragment_Visibility,
-                                              kVec3f_GrSLType, kDefault_GrSLPrecision,
-                                              "TextureSize", &textureSizeUniName);
-
         GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder();
 
         SkAssertResult(fsBuilder->enableFeature(
@@ -616,18 +611,24 @@
         // Use highp to work around aliasing issues
         fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPrecision,
                                                              pb->ctxInfo().standard()));
-        fsBuilder->codeAppendf("vec2 uv = %s;\n", v.fsIn());
+        fsBuilder->codeAppendf("vec2 uv = %s;\n", uv.fsIn());
         fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPrecision,
                                                              pb->ctxInfo().standard()));
-        fsBuilder->codeAppendf("vec2 st = uv*%s.xy;\n", textureSizeUniName);
+        fsBuilder->codeAppendf("vec2 st = %s;\n", st.fsIn());
         bool isUniformScale = !!(dfTexEffect.getFlags() & kUniformScale_DistanceFieldEffectMask);
+        
+        if (dfTexEffect.getFlags() & kBGR_DistanceFieldEffectFlag) {
+            fsBuilder->codeAppend("float delta = -" GR_FONT_ATLAS_LCD_DELTA ";\n");
+        } else {
+            fsBuilder->codeAppend("float delta = " GR_FONT_ATLAS_LCD_DELTA ";\n");
+        }
         if (isUniformScale) {
             fsBuilder->codeAppend("\tfloat dx = dFdx(st.x);\n");
-            fsBuilder->codeAppendf("\tvec2 offset = vec2(dx*%s.z, 0.0);\n", textureSizeUniName);
+            fsBuilder->codeAppend("\tvec2 offset = vec2(dx*delta, 0.0);\n");
         } else {
             fsBuilder->codeAppend("\tvec2 Jdx = dFdx(st);\n");
             fsBuilder->codeAppend("\tvec2 Jdy = dFdy(st);\n");
-            fsBuilder->codeAppendf("\tvec2 offset = %s.z*Jdx;\n", textureSizeUniName);
+            fsBuilder->codeAppend("\tvec2 offset = delta*Jdx;\n");
         }
 
         // green is distance to uv center
@@ -688,7 +689,6 @@
 
         // adjust based on gamma
         const char* textColorUniName = NULL;
-        // width, height, 1/(3*width)
         fTextColorUni = args.fPB->addUniform(GrGLProgramBuilder::kFragment_Visibility,
                                              kVec3f_GrSLType, kDefault_GrSLPrecision,
                                              "TextColor", &textColorUniName);
@@ -717,25 +717,10 @@
     virtual void setData(const GrGLProgramDataManager& pdman,
                          const GrPrimitiveProcessor& processor,
                          const GrBatchTracker& bt) SK_OVERRIDE {
-        SkASSERT(fTextureSizeUni.isValid());
         SkASSERT(fTextColorUni.isValid());
 
         const GrDistanceFieldLCDTextureEffect& dfTexEffect =
                 processor.cast<GrDistanceFieldLCDTextureEffect>();
-        GrTexture* texture = processor.texture(0);
-        if (texture->width() != fTextureSize.width() ||
-            texture->height() != fTextureSize.height()) {
-            fTextureSize = SkISize::Make(texture->width(), texture->height());
-            float delta = 1.0f/(3.0f*texture->width());
-            if (dfTexEffect.getFlags() & kBGR_DistanceFieldEffectFlag) {
-                delta = -delta;
-            }
-            pdman.set3f(fTextureSizeUni,
-                        SkIntToScalar(fTextureSize.width()),
-                        SkIntToScalar(fTextureSize.height()),
-                        delta);
-        }
-
         GrColor textColor = dfTexEffect.getTextColor();
         if (textColor != fTextColor) {
             static const float ONE_OVER_255 = 1.f / 255.f;
@@ -775,8 +760,6 @@
 private:
     GrColor       fColor;
     UniformHandle fColorUniform;
-    UniformHandle fTextureSizeUni;
-    SkISize       fTextureSize;
     UniformHandle fTextColorUni;
     SkColor       fTextColor;
 
@@ -800,7 +783,7 @@
     this->initClassID<GrDistanceFieldLCDTextureEffect>();
     fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertexAttribType));
     fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords",
-                                                          kVec2f_GrVertexAttribType));
+                                                          kVec2s_GrVertexAttribType));
     this->addTextureAccess(&fTextureAccess);
     this->addTextureAccess(&fGammaTextureAccess);
 }
diff --git a/src/gpu/gl/GrGLVertexArray.h b/src/gpu/gl/GrGLVertexArray.h
index f795ed8..4143ad4 100644
--- a/src/gpu/gl/GrGLVertexArray.h
+++ b/src/gpu/gl/GrGLVertexArray.h
@@ -34,6 +34,7 @@
         {4, GR_GL_FLOAT, false},         // kVec4f_GrVertexAttribType
         {1, GR_GL_UNSIGNED_BYTE, true},  // kUByte_GrVertexAttribType
         {4, GR_GL_UNSIGNED_BYTE, true},  // kVec4ub_GrVertexAttribType
+        {2, GR_GL_SHORT, false},         // kVec2s_GrVertexAttribType
     };
     GR_STATIC_ASSERT(0 == kFloat_GrVertexAttribType);
     GR_STATIC_ASSERT(1 == kVec2f_GrVertexAttribType);
@@ -41,6 +42,7 @@
     GR_STATIC_ASSERT(3 == kVec4f_GrVertexAttribType);
     GR_STATIC_ASSERT(4 == kUByte_GrVertexAttribType);
     GR_STATIC_ASSERT(5 == kVec4ub_GrVertexAttribType);
+    GR_STATIC_ASSERT(6 == kVec2s_GrVertexAttribType);
     GR_STATIC_ASSERT(SK_ARRAY_COUNT(kLayouts) == kGrVertexAttribTypeCount);
     return kLayouts[type];
 }