Replace edge types with GrEdgeEffect. 

This strips out last of the edge types and the fixed function edge attribute and replaces them with using GrEdgeEffect. Also fixes a minor bug when checking attribute counts -- it was using kAttribIndexCount instead of kVertexAttribCnt. 

Original Author: jvanverth@google.com
Review URL: https://codereview.chromium.org/13069003

git-svn-id: http://skia.googlecode.com/svn/trunk@8392 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/gpu/GrAAHairLinePathRenderer.cpp b/src/gpu/GrAAHairLinePathRenderer.cpp
index 80304f8..079c826 100644
--- a/src/gpu/GrAAHairLinePathRenderer.cpp
+++ b/src/gpu/GrAAHairLinePathRenderer.cpp
@@ -18,6 +18,8 @@
 #include "SkStroke.h"
 #include "SkTemplates.h"
 
+#include "effects/GrEdgeEffect.h"
+
 namespace {
 // quadratics are rendered as 5-sided polys in order to bound the
 // AA stroke around the center-curve. See comments in push_quad_index_buffer and
@@ -508,7 +510,6 @@
         {kVec2f_GrVertexAttribType, 0},
         {kVec4f_GrVertexAttribType, sizeof(GrPoint)}
     };
-    static const GrAttribBindings kBindings = GrDrawState::kEdge_AttribBindingsBit;
     SkMatrix viewM = drawState->getViewMatrix();
 
     PREALLOC_PTARRAY(128) lines;
@@ -522,8 +523,7 @@
 
     target->drawState()->setVertexAttribs(kAttribs, SK_ARRAY_COUNT(kAttribs));
     target->drawState()->setAttribIndex(GrDrawState::kPosition_AttribIndex, 0);
-    target->drawState()->setAttribIndex(GrDrawState::kEdge_AttribIndex, 1);
-    target->drawState()->setAttribBindings(kBindings);
+    target->drawState()->setAttribBindings(GrDrawState::kDefault_AttribBindings);
     GrAssert(sizeof(Vertex) == target->getDrawState().getVertexSize());
 
     if (!arg->set(target, vertCnt, 0)) {
@@ -589,8 +589,10 @@
         return false;
     }
 
-    GrDrawState::AutoDeviceCoordDraw adcd;
+    GrDrawTarget::AutoStateRestore asr(target, GrDrawTarget::kPreserve_ASRInit);
     GrDrawState* drawState = target->drawState();
+
+    GrDrawState::AutoDeviceCoordDraw adcd;
     // createGeom transforms the geometry to device space when the matrix does not have
     // perspective.
     if (!drawState->getViewMatrix().hasPerspective()) {
@@ -603,12 +605,21 @@
     // TODO: See whether rendering lines as degenerate quads improves perf
     // when we have a mix
 
-    GrDrawState::VertexEdgeType oldEdgeType = drawState->getVertexEdgeType();
+    enum {
+        // the edge effects share this stage with glyph rendering
+        // (kGlyphMaskStage in GrTextContext) && SW path rendering
+        // (kPathMaskStage in GrSWMaskHelper)
+        kEdgeEffectStage = GrPaint::kTotalStages,
+    };
+    static const int kEdgeAttrIndex = 1;
 
+    GrEffectRef* hairLineEffect = GrEdgeEffect::Create(GrEdgeEffect::kHairLine_EdgeType);
+    GrEffectRef* hairQuadEffect = GrEdgeEffect::Create(GrEdgeEffect::kHairQuad_EdgeType);
+ 
     target->setIndexSourceToBuffer(fLinesIndexBuffer);
     int lines = 0;
     int nBufLines = fLinesIndexBuffer->maxQuads();
-    drawState->setVertexEdgeType(GrDrawState::kHairLine_EdgeType);
+    drawState->setEffect(kEdgeEffectStage, hairLineEffect, kEdgeAttrIndex)->unref();
     while (lines < lineCnt) {
         int n = GrMin(lineCnt - lines, nBufLines);
         target->drawIndexed(kTriangles_GrPrimitiveType,
@@ -621,7 +632,7 @@
 
     target->setIndexSourceToBuffer(fQuadsIndexBuffer);
     int quads = 0;
-    drawState->setVertexEdgeType(GrDrawState::kHairQuad_EdgeType);
+    drawState->setEffect(kEdgeEffectStage, hairQuadEffect, kEdgeAttrIndex)->unref();
     while (quads < quadCnt) {
         int n = GrMin(quadCnt - quads, kNumQuadsInIdxBuffer);
         target->drawIndexed(kTriangles_GrPrimitiveType,
@@ -631,6 +642,6 @@
                             kIdxsPerQuad*n);                   // iCount
         quads += n;
     }
-    drawState->setVertexEdgeType(oldEdgeType);
+
     return true;
 }