Distance field path optimizations and clean up.

Adds the following:
- Use cached geometry processor rather than recreating all the time.
- Use context's quad index buffer.

Review URL: https://codereview.chromium.org/683923002
diff --git a/src/gpu/GrAADistanceFieldPathRenderer.cpp b/src/gpu/GrAADistanceFieldPathRenderer.cpp
index e2cee65..bcdbd8e 100755
--- a/src/gpu/GrAADistanceFieldPathRenderer.cpp
+++ b/src/gpu/GrAADistanceFieldPathRenderer.cpp
@@ -21,7 +21,6 @@
 
 #define ATLAS_TEXTURE_WIDTH 1024
 #define ATLAS_TEXTURE_HEIGHT 1024
-
 #define PLOT_WIDTH  256
 #define PLOT_HEIGHT 256
 
@@ -37,6 +36,12 @@
 #endif
 
 ////////////////////////////////////////////////////////////////////////////////
+GrAADistanceFieldPathRenderer::GrAADistanceFieldPathRenderer(GrContext* context)
+    : fContext(context)
+    , fAtlas(NULL)
+    , fEffectFlags(kInvalid_DistanceFieldEffectFlag) {
+}
+
 GrAADistanceFieldPathRenderer::~GrAADistanceFieldPathRenderer() {
     PathDataList::Iter iter;
     iter.init(fPathList, PathDataList::Iter::kHead_IterStart);
@@ -280,7 +285,6 @@
 bool GrAADistanceFieldPathRenderer::internalDrawPath(const SkPath& path,
                                                      const PathData* pathData,
                                                      GrDrawTarget* target) {
-    
     GrTexture* texture = fAtlas->getTexture();
     GrDrawState* drawState = target->drawState();
     GrDrawState::AutoRestoreEffects are(drawState);
@@ -293,8 +297,7 @@
     drawState->setVertexAttribs<gSDFPathVertexAttribs>(SK_ARRAY_COUNT(gSDFPathVertexAttribs),
                                                        kSDFPathVASize);
     void* vertices = NULL;
-    void* indices = NULL;
-    bool success = target->reserveVertexAndIndexSpace(4, 6, &vertices, &indices);
+    bool success = target->reserveVertexAndIndexSpace(4, 0, &vertices, NULL);
     GrAlwaysAssert(success);
     
     SkScalar dx = pathData->fBounds.fLeft;
@@ -328,29 +331,24 @@
                               SkFixedToFloat(texture->texturePriv().normalizeFixedY(ty + th)),
                               vertSize);
     
-    uint16_t* indexPtr = reinterpret_cast<uint16_t*>(indices);
-    *indexPtr++ = 0;
-    *indexPtr++ = 1;
-    *indexPtr++ = 2;
-    *indexPtr++ = 0;
-    *indexPtr++ = 2;
-    *indexPtr++ = 3;
-    
     // set up any flags
     uint32_t flags = 0;
     const SkMatrix& vm = drawState->getViewMatrix();
     flags |= vm.isSimilarity() ? kSimilarity_DistanceFieldEffectFlag : 0;
     
     GrTextureParams params(SkShader::kRepeat_TileMode, GrTextureParams::kBilerp_FilterMode);
-    drawState->setGeometryProcessor(GrDistanceFieldNoGammaTextureEffect::Create(texture,
-                                                                                params,
-                                                                                flags))->unref();
-    
+    if (flags != fEffectFlags) {
+        fCachedGeometryProcessor.reset(GrDistanceFieldNoGammaTextureEffect::Create(texture,
+                                                                                   params,
+                                                                                   flags));
+        fEffectFlags = flags;
+    }
+    drawState->setGeometryProcessor(fCachedGeometryProcessor.get());
 
     vm.mapRect(&r);
+    target->setIndexSourceToBuffer(fContext->getQuadIndexBuffer());
     target->drawIndexedInstances(kTriangles_GrPrimitiveType, 1, 4, 6, &r);
     target->resetVertexSource();
-    target->resetIndexSource();
     
     return true;
 }
diff --git a/src/gpu/GrAADistanceFieldPathRenderer.h b/src/gpu/GrAADistanceFieldPathRenderer.h
index 4c09f12..40430bb 100755
--- a/src/gpu/GrAADistanceFieldPathRenderer.h
+++ b/src/gpu/GrAADistanceFieldPathRenderer.h
@@ -21,11 +21,7 @@
 
 class GrAADistanceFieldPathRenderer : public GrPathRenderer {
 public:
-    GrAADistanceFieldPathRenderer(GrContext* context)
-        : fContext(context)
-        , fAtlas(NULL) {
-    }
-    
+    GrAADistanceFieldPathRenderer(GrContext* context);
     virtual ~GrAADistanceFieldPathRenderer();
     
     virtual bool canDrawPath(const SkPath& path,
@@ -63,6 +59,9 @@
     
     GrContext*                         fContext;
     GrAtlas*                           fAtlas;
+    SkAutoTUnref<GrGeometryProcessor>  fCachedGeometryProcessor;
+    // current set of flags used to create the cached geometry processor
+    uint32_t                           fEffectFlags;
     GrAtlas::ClientPlotUsage           fPlotUsage;
     SkTDynamicHash<PathData, uint32_t> fPathCache;
     PathDataList                       fPathList;
diff --git a/src/gpu/GrDistanceFieldTextContext.cpp b/src/gpu/GrDistanceFieldTextContext.cpp
index 66ec123..118565a 100755
--- a/src/gpu/GrDistanceFieldTextContext.cpp
+++ b/src/gpu/GrDistanceFieldTextContext.cpp
@@ -74,7 +74,7 @@
 
     fEffectTextureUniqueID = SK_InvalidUniqueID;
     fEffectColor = GrColor_ILLEGAL;
-    fEffectFlags = 0;
+    fEffectFlags = kInvalid_DistanceFieldEffectFlag;
 
     fVertices = NULL;
     fCurrVertex = 0;
diff --git a/src/gpu/effects/GrDistanceFieldTextureEffect.h b/src/gpu/effects/GrDistanceFieldTextureEffect.h
index c24673b..ea02d19 100644
--- a/src/gpu/effects/GrDistanceFieldTextureEffect.h
+++ b/src/gpu/effects/GrDistanceFieldTextureEffect.h
@@ -21,6 +21,8 @@
     kUseLCD_DistanceFieldEffectFlag     = 0x04,   // use lcd text
     kBGR_DistanceFieldEffectFlag        = 0x08,   // lcd display has bgr order
     kPortrait_DistanceFieldEffectFlag   = 0x10,   // lcd display is in portrait mode (not used yet)
+
+    kInvalid_DistanceFieldEffectFlag    = 0x80,   // invalid state (for initialization)
     
     kUniformScale_DistanceFieldEffectMask = kSimilarity_DistanceFieldEffectFlag |
                                             kRectToRect_DistanceFieldEffectFlag,