Revert r7901 & r7899 to allow DEPS roll



git-svn-id: http://skia.googlecode.com/svn/trunk@7909 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index 3b77b73..0f6fa16 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -352,16 +352,8 @@
         GrTextureParams params(SkShader::kClamp_TileMode, needsFiltering);
         drawState->createTextureEffect(0, clampedTexture, SkMatrix::I(), params);
 
-        // position + texture coordinate
-        static const GrVertexAttrib kVertexAttribs[] = {
-            GrVertexAttrib(kVec2f_GrVertexAttribType, 0),
-            GrVertexAttrib(kVec2f_GrVertexAttribType, sizeof(GrPoint))
-        };
-        static const GrAttribBindings kAttribBindings = GrDrawState::ExplicitTexCoordAttribBindingsBit(0);
-        drawState->setAttribBindings(kAttribBindings);
-        drawState->setVertexAttribs(kVertexAttribs, SK_ARRAY_COUNT(kVertexAttribs));
-        drawState->setAttribIndex(GrDrawState::kPosition_AttribIndex, 0);
-        drawState->setAttribIndex(GrDrawState::kTexCoord_AttribIndex, 1);
+        static const GrVertexLayout layout = GrDrawState::StageTexCoordVertexLayoutBit(0);
+        drawState->setVertexLayout(layout);
         GrDrawTarget::AutoReleaseGeometry arg(fGpu, 4, 0);
 
         if (arg.succeeded()) {
@@ -786,7 +778,7 @@
         // unitSquareVertexBuffer()
 
         static const int worstCaseVertCount = 10;
-        target->drawState()->setDefaultVertexAttribs();
+        target->drawState()->setVertexLayout(GrDrawState::kDefault_VertexLayout);
         GrDrawTarget::AutoReleaseGeometry geo(target, worstCaseVertCount, 0);
 
         if (!geo.succeeded()) {
@@ -829,7 +821,7 @@
             }
 
             GrDrawState* drawState = target->drawState();
-            target->drawState()->setDefaultVertexAttribs();
+            drawState->setVertexLayout(GrDrawState::kDefault_VertexLayout);
             target->setVertexSourceToBuffer(sqVB);
             SkMatrix m;
             m.setAll(rect.width(),    0,             rect.fLeft,
@@ -895,7 +887,7 @@
         GrPrintf("Failed to create static rect vb.\n");
         return;
     }
-    drawState->setDefaultVertexAttribs();
+    drawState->setVertexLayout(GrDrawState::kDefault_VertexLayout);
     target->setVertexSourceToBuffer(sqVB);
     target->drawNonIndexed(kTriangleFan_GrPrimitiveType, 0, 4);
 #else
@@ -920,55 +912,37 @@
     GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW);
     GrDrawState::AutoStageDisable atr(fDrawState);
 
-    GrDrawState* drawState = target->drawState();
-
-    GrVertexAttribArray<3> attribs;
-    size_t currentOffset = 0;
-    int colorOffset = -1, texOffset = -1;
-    GrAttribBindings bindings = GrDrawState::kDefault_AttribBindings;
-
-    // set position attribute
-    drawState->setAttribIndex(GrDrawState::kPosition_AttribIndex, attribs.count());
-    attribs.push_back(GrVertexAttrib(kVec2f_GrVertexAttribType, currentOffset));
-    currentOffset += sizeof(GrPoint);
-
-    // set up optional texture coordinate attributes
+    GrVertexLayout layout = 0;
     if (NULL != texCoords) {
-        bindings |= GrDrawState::ExplicitTexCoordAttribBindingsBit(0);
-        drawState->setAttribIndex(GrDrawState::kTexCoord_AttribIndex, attribs.count());
-        attribs.push_back(GrVertexAttrib(kVec2f_GrVertexAttribType, currentOffset));
-        texOffset = currentOffset;
-        currentOffset += sizeof(GrPoint);
+        layout |= GrDrawState::StageTexCoordVertexLayoutBit(0);
     }
-
-    // set up optional color attributes
     if (NULL != colors) {
-        bindings |= GrDrawState::kColor_AttribBindingsBit;
-        drawState->setAttribIndex(GrDrawState::kColor_AttribIndex, attribs.count());
-        attribs.push_back(GrVertexAttrib(kVec4ub_GrVertexAttribType, currentOffset));
-        colorOffset = currentOffset;
-        currentOffset += sizeof(GrColor);
+        layout |= GrDrawState::kColor_VertexLayoutBit;
     }
+    target->drawState()->setVertexLayout(layout);
 
-    drawState->setVertexAttribs(attribs.begin(), attribs.count());
-    drawState->setAttribBindings(bindings);
-
-    size_t vertexSize = drawState->getVertexSize();
-    GrAssert(vertexSize == currentOffset);
+    int vertexSize = target->getDrawState().getVertexSize();
     if (sizeof(GrPoint) != vertexSize) {
         if (!geo.set(target, vertexCount, 0)) {
             GrPrintf("Failed to get space for vertices!\n");
             return;
         }
+        int texOffset;
+        int colorOffset;
+        GrDrawState::VertexSizeAndOffsets(layout,
+                                          &texOffset,
+                                          &colorOffset,
+                                          NULL,
+                                          NULL);
         void* curVertex = geo.vertices();
 
         for (int i = 0; i < vertexCount; ++i) {
             *((GrPoint*)curVertex) = positions[i];
 
-            if (texOffset >= 0) {
+            if (texOffset > 0) {
                 *(GrPoint*)((intptr_t)curVertex + texOffset) = texCoords[i];
             }
-            if (colorOffset >= 0) {
+            if (colorOffset > 0) {
                 *(GrColor*)((intptr_t)curVertex + colorOffset) = colors[i];
             }
             curVertex = (void*)((intptr_t)curVertex + vertexSize);
@@ -1071,17 +1045,8 @@
         return;
     }
 
-    // position + edge
-    static const GrVertexAttrib kVertexAttribs[] = {
-        GrVertexAttrib(kVec2f_GrVertexAttribType, 0),
-        GrVertexAttrib(kVec4f_GrVertexAttribType, sizeof(GrPoint))
-    };
-    static const GrAttribBindings kAttributeBindings = GrDrawState::kEdge_AttribBindingsBit;
-
-    drawState->setVertexAttribs(kVertexAttribs, SK_ARRAY_COUNT(kVertexAttribs));
-    drawState->setAttribIndex(GrDrawState::kPosition_AttribIndex, 0);
-    drawState->setAttribIndex(GrDrawState::kEdge_AttribIndex, 1);
-    drawState->setAttribBindings(kAttributeBindings);
+    GrVertexLayout layout = GrDrawState::kEdge_VertexLayoutBit;
+    drawState->setVertexLayout(layout);
     GrAssert(sizeof(CircleVertex) == drawState->getVertexSize());
 
     GrDrawTarget::AutoReleaseGeometry geo(target, 4, 0);