Add new vertex attribute array specification.

This changes the old method of setting vertex layout to a new one where we
specify vertex attribute data separately from attribute bindings (i.e. program
functionality). Attribute data is now set up via an array of generic attribute
types and offsets, and this is mapped to the old program functionality by
setting specific attribute indices. This allows us to create more general 
inputs to shaders.


git-svn-id: http://skia.googlecode.com/svn/trunk@7899 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/gpu/GrAARectRenderer.cpp b/src/gpu/GrAARectRenderer.cpp
index d23c4b4..741b83d 100644
--- a/src/gpu/GrAARectRenderer.cpp
+++ b/src/gpu/GrAARectRenderer.cpp
@@ -13,14 +13,15 @@
 
 namespace {
 
-static GrVertexLayout aa_rect_layout(bool useCoverage) {
-    GrVertexLayout layout = 0;
+static void aa_rect_attributes(bool useCoverage, GrAttribBindings* bindings, 
+                               GrDrawState::AttribIndex* index) {
     if (useCoverage) {
-        layout |= GrDrawState::kCoverage_VertexLayoutBit;
+        *bindings = GrDrawState::kCoverage_AttribBindingsBit;
+        *index = GrDrawState::kCoverage_AttribIndex;
     } else {
-        layout |= GrDrawState::kColor_VertexLayoutBit;
+        *bindings = GrDrawState::kColor_AttribBindingsBit;
+        *index = GrDrawState::kColor_AttribIndex;
     }
-    return layout;
 }
 
 static void set_inset_fan(GrPoint* pts, size_t stride,
@@ -29,6 +30,12 @@
                     r.fRight - dx, r.fBottom - dy, stride);
 }
 
+// position + color/coverage
+static const GrVertexAttrib kVertexAttribs[] = {
+    GrVertexAttrib(kVec2f_GrVertexAttribType, 0),
+    GrVertexAttrib(kVec4ub_GrVertexAttribType, sizeof(GrPoint))
+};
+
 };
 
 void GrAARectRenderer::reset() {
@@ -125,8 +132,15 @@
                                   GrDrawTarget* target,
                                   const GrRect& devRect,
                                   bool useVertexCoverage) {
-    GrVertexLayout layout = aa_rect_layout(useVertexCoverage);
-    target->drawState()->setVertexLayout(layout);
+    GrDrawState* drawState = target->drawState();
+
+    GrAttribBindings bindings;
+    GrDrawState::AttribIndex attribIndex;
+    aa_rect_attributes(useVertexCoverage, &bindings, &attribIndex);
+    drawState->setVertexAttribs(kVertexAttribs, SK_ARRAY_COUNT(kVertexAttribs));
+    drawState->setAttribBindings(bindings);
+    drawState->setAttribIndex(GrDrawState::kPosition_AttribIndex, 0);
+    drawState->setAttribIndex(attribIndex, 1);
 
     GrDrawTarget::AutoReleaseGeometry geo(target, 8, 0);
     if (!geo.succeeded()) {
@@ -141,7 +155,8 @@
     }
 
     intptr_t verts = reinterpret_cast<intptr_t>(geo.vertices());
-    size_t vsize = target->getDrawState().getVertexSize();
+    size_t vsize = drawState->getVertexSize();
+    GrAssert(sizeof(GrPoint) + sizeof(GrColor) == vsize);
 
     GrPoint* fan0Pos = reinterpret_cast<GrPoint*>(verts);
     GrPoint* fan1Pos = reinterpret_cast<GrPoint*>(verts + 4 * vsize);
@@ -177,6 +192,8 @@
                                     const GrRect& devRect,
                                     const GrVec& devStrokeSize,
                                     bool useVertexCoverage) {
+    GrDrawState* drawState = target->drawState();
+
     const SkScalar& dx = devStrokeSize.fX;
     const SkScalar& dy = devStrokeSize.fY;
     const SkScalar rx = SkScalarMul(dx, SK_ScalarHalf);
@@ -195,8 +212,14 @@
         this->fillAARect(gpu, target, r, useVertexCoverage);
         return;
     }
-    GrVertexLayout layout = aa_rect_layout(useVertexCoverage);
-    target->drawState()->setVertexLayout(layout);
+    
+    GrAttribBindings bindings;
+    GrDrawState::AttribIndex attribIndex;
+    aa_rect_attributes(useVertexCoverage, &bindings, &attribIndex);
+    drawState->setVertexAttribs(kVertexAttribs, SK_ARRAY_COUNT(kVertexAttribs));
+    drawState->setAttribBindings(bindings);
+    drawState->setAttribIndex(GrDrawState::kPosition_AttribIndex, 0);
+    drawState->setAttribIndex(attribIndex, 1);
 
     GrDrawTarget::AutoReleaseGeometry geo(target, 16, 0);
     if (!geo.succeeded()) {
@@ -210,7 +233,8 @@
     }
 
     intptr_t verts = reinterpret_cast<intptr_t>(geo.vertices());
-    size_t vsize = target->getDrawState().getVertexSize();
+    size_t vsize = drawState->getVertexSize();
+    GrAssert(sizeof(GrPoint) + sizeof(GrColor) == vsize);
 
     // We create vertices for four nested rectangles. There are two ramps from 0 to full
     // coverage, one on the exterior of the stroke and the other on the interior.