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/gl/GrGLProgram.cpp b/src/gpu/gl/GrGLProgram.cpp
index 781e15f..0ca84bc 100644
--- a/src/gpu/gl/GrGLProgram.cpp
+++ b/src/gpu/gl/GrGLProgram.cpp
@@ -35,14 +35,6 @@
 inline const char* dual_source_output_name() { return "dualSourceOut"; }
 }
 
-const GrGLProgram::AttribLayout GrGLProgram::kAttribLayouts[kGrVertexAttribTypeCount] = {
-    {1, GR_GL_FLOAT, false},         // kFloat_GrVertexAttribType
-    {2, GR_GL_FLOAT, false},         // kVec2f_GrVertexAttribType
-    {3, GR_GL_FLOAT, false},         // kVec3f_GrVertexAttribType
-    {4, GR_GL_FLOAT, false},         // kVec4f_GrVertexAttribType
-    {4, GR_GL_UNSIGNED_BYTE, true},  // kVec4ub_GrVertexAttribType
-};
-
 void GrGLProgram::BuildDesc(const GrDrawState& drawState,
                             bool isPoints,
                             GrDrawState::BlendOptFlags blendOpts,
@@ -60,24 +52,24 @@
                                            GrDrawState::kEmitCoverage_BlendOptFlag));
 
     // The descriptor is used as a cache key. Thus when a field of the
-    // descriptor will not affect program generation (because of the attribute
-    // bindings in use or other descriptor field settings) it should be set
+    // descriptor will not affect program generation (because of the vertex
+    // layout in use or other descriptor field settings) it should be set
     // to a canonical value to avoid duplicate programs with different keys.
 
     // Must initialize all fields or cache will have false negatives!
-    desc->fAttribBindings = drawState.getAttribBindings();
+    desc->fVertexLayout = drawState.getVertexLayout();
 
     desc->fEmitsPointSize = isPoints;
 
     bool requiresAttributeColors = !skipColor &&
-                                   SkToBool(desc->fAttribBindings & GrDrawState::kColor_AttribBindingsBit);
+                                   SkToBool(desc->fVertexLayout & GrDrawState::kColor_VertexLayoutBit);
     bool requiresAttributeCoverage = !skipCoverage &&
-                                     SkToBool(desc->fAttribBindings & GrDrawState::kCoverage_AttribBindingsBit);
+                                     SkToBool(desc->fVertexLayout & GrDrawState::kCoverage_VertexLayoutBit);
 
     // fColorInput/fCoverageInput records how colors are specified for the program So we strip the
-    // bits from the bindings to avoid false negatives when searching for an existing program in the
+    // bits from the layout to avoid false negatives when searching for an existing program in the
     // cache.
-    desc->fAttribBindings &= ~(GrDrawState::kColor_AttribBindingsBit | GrDrawState::kCoverage_AttribBindingsBit);
+    desc->fVertexLayout &= ~(GrDrawState::kColor_VertexLayoutBit | GrDrawState::kCoverage_VertexLayoutBit);
 
     desc->fColorFilterXfermode = skipColor ?
                                 SkXfermode::kDst_Mode :
@@ -85,8 +77,8 @@
 
     // no reason to do edge aa or look at per-vertex coverage if coverage is ignored
     if (skipCoverage) {
-        desc->fAttribBindings &= ~(GrDrawState::kEdge_AttribBindingsBit |
-                                   GrDrawState::kCoverage_AttribBindingsBit);
+        desc->fVertexLayout &= ~(GrDrawState::kEdge_VertexLayoutBit |
+                                 GrDrawState::kCoverage_VertexLayoutBit);
     }
 
     bool colorIsTransBlack = SkToBool(blendOpts & GrDrawState::kEmitTransBlack_BlendOptFlag);
@@ -116,7 +108,7 @@
 
     int lastEnabledStage = -1;
 
-    if (!skipCoverage && (desc->fAttribBindings & GrDrawState::kEdge_AttribBindingsBit)) {
+    if (!skipCoverage && (desc->fVertexLayout & GrDrawState::kEdge_VertexLayoutBit)) {
         desc->fVertexEdgeType = drawState.getVertexEdgeType();
         desc->fDiscardIfOutsideEdge = drawState.getStencil().doesWrite();
     } else {
@@ -163,7 +155,7 @@
     // other coverage inputs
     if (!hasCoverage) {
         hasCoverage = requiresAttributeCoverage ||
-                      (desc->fAttribBindings & GrDrawState::kEdge_AttribBindingsBit);
+                      (desc->fVertexLayout & GrDrawState::kEdge_VertexLayoutBit);
     }
 
     if (hasCoverage) {
@@ -190,43 +182,6 @@
             }
         }
     }
-
-    desc->fPositionAttributeIndex = drawState.getAttribIndex(GrDrawState::kPosition_AttribIndex);
-    if (requiresAttributeColors) {
-        desc->fColorAttributeIndex = drawState.getAttribIndex(GrDrawState::kColor_AttribIndex);
-    } else {
-        desc->fColorAttributeIndex = GrDrawState::kColorOverrideAttribIndexValue;
-    } 
-    if (requiresAttributeCoverage) {
-        desc->fCoverageAttributeIndex = drawState.getAttribIndex(GrDrawState::kCoverage_AttribIndex);
-    } else {
-        desc->fCoverageAttributeIndex = GrDrawState::kCoverageOverrideAttribIndexValue;
-    }
-    desc->fEdgeAttributeIndex     = drawState.getAttribIndex(GrDrawState::kEdge_AttribIndex);
-    desc->fTexCoordAttributeIndex = drawState.getAttribIndex(GrDrawState::kTexCoord_AttribIndex);
-
-#if GR_DEBUG
-    // verify valid vertex attribute state
-    const GrVertexAttrib* vertexAttribs = drawState.getVertexAttribs();
-    GrAssert(desc->fPositionAttributeIndex < GrDrawState::kVertexAttribCnt);
-    GrAssert(kAttribLayouts[vertexAttribs[desc->fPositionAttributeIndex].fType].fCount == 2);
-    if (requiresAttributeColors) {
-        GrAssert(desc->fColorAttributeIndex < GrDrawState::kVertexAttribCnt);
-        GrAssert(kAttribLayouts[vertexAttribs[desc->fColorAttributeIndex].fType].fCount == 4);
-    }
-    if (requiresAttributeCoverage) {
-        GrAssert(desc->fCoverageAttributeIndex < GrDrawState::kVertexAttribCnt);
-        GrAssert(kAttribLayouts[vertexAttribs[desc->fCoverageAttributeIndex].fType].fCount == 4);
-    }
-    if (desc->fAttribBindings & GrDrawState::kEdge_AttribBindingsBit) {
-        GrAssert(desc->fEdgeAttributeIndex < GrDrawState::kVertexAttribCnt);
-        GrAssert(kAttribLayouts[vertexAttribs[desc->fEdgeAttributeIndex].fType].fCount == 4);
-     }
-    if (GrDrawState::AttributesBindExplicitTexCoords(desc->fAttribBindings)) {
-        GrAssert(desc->fTexCoordAttributeIndex < GrDrawState::kVertexAttribCnt);
-        GrAssert(kAttribLayouts[vertexAttribs[desc->fTexCoordAttributeIndex].fType].fCount == 2);
-    }
-#endif
 }
 
 GrGLProgram* GrGLProgram::Create(const GrGLContext& gl,
@@ -411,7 +366,7 @@
 
 bool GrGLProgram::genEdgeCoverage(SkString* coverageVar,
                                   GrGLShaderBuilder* builder) const {
-    if (fDesc.fAttribBindings & GrDrawState::kEdge_AttribBindingsBit) {
+    if (fDesc.fVertexLayout & GrDrawState::kEdge_VertexLayoutBit) {
         const char *vsName, *fsName;
         builder->addVarying(kVec4f_GrSLType, "Edge", &vsName, &fsName);
         builder->fVSAttrs.push_back().set(kVec4f_GrSLType,
@@ -690,7 +645,7 @@
     GrAssert(0 == fProgramID);
 
     GrGLShaderBuilder builder(fContext.info(), fUniformManager);
-    const GrAttribBindings& attribBindings = fDesc.fAttribBindings;
+    const uint32_t& layout = fDesc.fVertexLayout;
 
 #if GR_GL_EXPERIMENTAL_GS
     builder.fUsesGS = fDesc.fExperimentalGS;
@@ -771,7 +726,7 @@
     }
 
     // add texture coordinates that are used to the list of vertex attr decls
-    if (GrDrawState::AttributesBindExplicitTexCoords(attribBindings)) {
+    if (GrDrawState::VertexUsesTexCoords(layout)) {
         builder.fVSAttrs.push_back().set(kVec2f_GrSLType,
             GrGLShaderVar::kAttribute_TypeModifier,
             TEX_ATTR_NAME);
@@ -793,7 +748,7 @@
 
                 const char* inCoords;
                 // figure out what our input coords are
-                if (!GrDrawState::StageBindsExplicitTexCoords(attribBindings, s)) {
+                if (!GrDrawState::StageUsesTexCoords(layout, s)) {
                     inCoords = builder.positionAttribute().c_str();
                 } else {
                     // must have input tex coordinates if stage is enabled.
@@ -887,7 +842,7 @@
 
                     const char* inCoords;
                     // figure out what our input coords are
-                    if (!GrDrawState::StageBindsExplicitTexCoords(attribBindings, s)) {
+                    if (!GrDrawState::StageUsesTexCoords(layout, s)) {
                         inCoords = builder.positionAttribute().c_str();
                     } else {
                         // must have input tex coordinates if stage is
@@ -1011,18 +966,13 @@
 
     // Bind the attrib locations to same values for all shaders
     GL_CALL(BindAttribLocation(fProgramID,
-                               fDesc.fPositionAttributeIndex,
+                               kPositionAttributeIndex,
                                builder.positionAttribute().c_str()));
-    GL_CALL(BindAttribLocation(fProgramID, fDesc.fColorAttributeIndex, COL_ATTR_NAME));
-    GL_CALL(BindAttribLocation(fProgramID, fDesc.fCoverageAttributeIndex, COV_ATTR_NAME));
- 
-    if (fDesc.fAttribBindings & GrDrawState::kEdge_AttribBindingsBit) {
-        GL_CALL(BindAttribLocation(fProgramID, fDesc.fEdgeAttributeIndex, EDGE_ATTR_NAME));
-    }
-    if (GrDrawState::AttributesBindExplicitTexCoords(fDesc.fAttribBindings)) {
-        GL_CALL(BindAttribLocation(fProgramID, fDesc.fTexCoordAttributeIndex, TEX_ATTR_NAME));
-    }
-    
+    GL_CALL(BindAttribLocation(fProgramID, kTexCoordAttributeIndex, TEX_ATTR_NAME));
+    GL_CALL(BindAttribLocation(fProgramID, kColorAttributeIndex, COL_ATTR_NAME));
+    GL_CALL(BindAttribLocation(fProgramID, kCoverageAttributeIndex, COV_ATTR_NAME));
+    GL_CALL(BindAttribLocation(fProgramID, kEdgeAttributeIndex, EDGE_ATTR_NAME));
+
     GL_CALL(LinkProgram(fProgramID));
 
     GrGLint linked = GR_GL_INIT_ZERO;
@@ -1110,14 +1060,14 @@
 void GrGLProgram::setColor(const GrDrawState& drawState,
                            GrColor color,
                            SharedGLState* sharedState) {
-    if (!(drawState.getAttribBindings() & GrDrawState::kColor_AttribBindingsBit)) {
+    if (!(drawState.getVertexLayout() & GrDrawState::kColor_VertexLayoutBit)) {
         switch (fDesc.fColorInput) {
             case GrGLProgram::Desc::kAttribute_ColorInput:
                 if (sharedState->fConstAttribColor != color) {
                     // OpenGL ES only supports the float varieties of glVertexAttrib
                     GrGLfloat c[4];
                     GrColorToRGBAFloat(color, c);
-                    GL_CALL(VertexAttrib4fv(fDesc.fColorAttributeIndex, c));
+                    GL_CALL(VertexAttrib4fv(kColorAttributeIndex, c));
                     sharedState->fConstAttribColor = color;
                 }
                 break;
@@ -1144,14 +1094,14 @@
 void GrGLProgram::setCoverage(const GrDrawState& drawState,
                               GrColor coverage,
                               SharedGLState* sharedState) {
-    if (!(drawState.getAttribBindings() & GrDrawState::kCoverage_AttribBindingsBit)) {
+    if (!(drawState.getVertexLayout() & GrDrawState::kCoverage_VertexLayoutBit)) {
         switch (fDesc.fCoverageInput) {
             case Desc::kAttribute_ColorInput:
                 if (sharedState->fConstAttribCoverage != coverage) {
                     // OpenGL ES only supports the float varieties of  glVertexAttrib
                     GrGLfloat c[4];
                     GrColorToRGBAFloat(coverage, c);
-                    GL_CALL(VertexAttrib4fv(fDesc.fCoverageAttributeIndex, c));
+                    GL_CALL(VertexAttrib4fv(kCoverageAttributeIndex, c));
                     sharedState->fConstAttribCoverage = coverage;
                 }
                 break;
diff --git a/src/gpu/gl/GrGLProgram.h b/src/gpu/gl/GrGLProgram.h
index cde918b..a2958e7 100644
--- a/src/gpu/gl/GrGLProgram.h
+++ b/src/gpu/gl/GrGLProgram.h
@@ -79,6 +79,17 @@
     GrGLuint programID() const { return fProgramID; }
 
     /**
+     * Attribute indices. These should not overlap.
+     */
+    enum {
+        kPositionAttributeIndex = 0,
+        kColorAttributeIndex = 1,
+        kCoverageAttributeIndex = 2,
+        kEdgeAttributeIndex = 3,
+        kTexCoordAttributeIndex = 4,
+    };
+
+    /**
      * Some GL state that is relevant to programs is not stored per-program. In particular vertex
      * attributes are global state. This struct is read and updated by GrGLProgram::setData to
      * allow us to avoid setting this state redundantly.
@@ -171,7 +182,7 @@
         bool                        fDiscardIfOutsideEdge;
 
         // stripped of bits that don't affect program generation
-        GrAttribBindings            fAttribBindings;
+        GrVertexLayout              fVertexLayout;
 
         /** Non-zero if this stage has an effect */
         GrGLEffect::EffectKey       fEffectKeys[GrDrawState::kNumStages];
@@ -188,23 +199,9 @@
         SkBool8                     fEmitsPointSize;
         uint8_t                     fColorFilterXfermode;   // casts to enum SkXfermode::Mode
 
-        int8_t                      fPositionAttributeIndex;
-        int8_t                      fColorAttributeIndex;
-        int8_t                      fCoverageAttributeIndex;
-        int8_t                      fEdgeAttributeIndex;
-        int8_t                      fTexCoordAttributeIndex;
-
         friend class GrGLProgram;
     };
 
-    // Layout information for OpenGL vertex attributes
-    struct AttribLayout {
-        GrGLint     fCount;
-        GrGLenum    fType;
-        GrGLboolean fNormalized;
-    };
-    static const AttribLayout kAttribLayouts[kGrVertexAttribTypeCount];
-
 private:
     GrGLProgram(const GrGLContext& gl,
                 const Desc& desc,
diff --git a/src/gpu/gl/GrGpuGL.cpp b/src/gpu/gl/GrGpuGL.cpp
index 42e83b0..f9c94c4 100644
--- a/src/gpu/gl/GrGpuGL.cpp
+++ b/src/gpu/gl/GrGpuGL.cpp
@@ -182,10 +182,6 @@
 
     fHWGeometryState.setMaxAttribArrays(this->glCaps().maxVertexAttributes());
 
-    GrAssert(this->glCaps().maxVertexAttributes() >= GrDrawState::kVertexAttribCnt);
-    GrAssert(this->glCaps().maxVertexAttributes() > GrDrawState::kColorOverrideAttribIndexValue);
-    GrAssert(this->glCaps().maxVertexAttributes() > GrDrawState::kCoverageOverrideAttribIndexValue);
-
     fLastSuccessfulStencilFmtIdx = 0;
     if (false) { // avoid bit rot, suppress warning
         fbo_test(this->glInterface(), 0, 0);
diff --git a/src/gpu/gl/GrGpuGL_program.cpp b/src/gpu/gl/GrGpuGL_program.cpp
index e5a7183..93af1b9 100644
--- a/src/gpu/gl/GrGpuGL_program.cpp
+++ b/src/gpu/gl/GrGpuGL_program.cpp
@@ -215,30 +215,83 @@
 
 void GrGpuGL::setupGeometry(const DrawInfo& info, size_t* indexOffsetInBytes) {
 
-    GrGLsizei stride = this->getDrawState().getVertexSize();
+    int colorOffset;
+    int coverageOffset;
+    int texCoordOffset;
+    int edgeOffset;
+
+    GrVertexLayout currLayout = this->getDrawState().getVertexLayout();
+
+    GrGLsizei stride = GrDrawState::VertexSizeAndOffsets(currLayout,
+                                                         &texCoordOffset,
+                                                         &colorOffset,
+                                                         &coverageOffset,
+                                                         &edgeOffset);
 
     size_t vertexOffset;
     GrGLVertexBuffer* vb= this->setBuffers(info.isIndexed(), &vertexOffset, indexOffsetInBytes);
     vertexOffset += stride * info.startVertex();
 
-    uint32_t usedAttribArraysMask = 0;
-    const GrVertexAttrib* vertexAttrib = this->getDrawState().getVertexAttribs();
-    int vertexAttribCount = this->getDrawState().getVertexAttribCount();
-    for (int vertexAttribIndex = 0; vertexAttribIndex < vertexAttribCount; 
-         ++vertexAttribIndex, ++vertexAttrib) {
-
-        usedAttribArraysMask |= (1 << vertexAttribIndex);
-        GrVertexAttribType attribType = vertexAttrib->fType;
+    uint32_t usedAttribArraysMask = (1 << GrGLProgram::kPositionAttributeIndex);
+    fHWGeometryState.setAttribArray(this,
+                                    GrGLProgram::kPositionAttributeIndex,
+                                    vb,
+                                    2,
+                                    GR_GL_FLOAT,
+                                    false,
+                                    stride,
+                                    reinterpret_cast<GrGLvoid*>(vertexOffset));
+    if (texCoordOffset > 0) {
+        usedAttribArraysMask |= (1 << GrGLProgram::kTexCoordAttributeIndex);
+        GrGLvoid* texCoordPtr = reinterpret_cast<GrGLvoid*>(vertexOffset + texCoordOffset);
         fHWGeometryState.setAttribArray(this,
-                                        vertexAttribIndex,
+                                        GrGLProgram::kTexCoordAttributeIndex,
                                         vb,
-                                        GrGLProgram::kAttribLayouts[attribType].fCount,
-                                        GrGLProgram::kAttribLayouts[attribType].fType,
-                                        GrGLProgram::kAttribLayouts[attribType].fNormalized,
+                                        2,
+                                        GR_GL_FLOAT,
+                                        false,
                                         stride,
-                                        reinterpret_cast<GrGLvoid*>(
-                                         vertexOffset + vertexAttrib->fOffset));
-     }
+                                        texCoordPtr);
+    }
+
+    if (colorOffset > 0) {
+        usedAttribArraysMask |= (1 << GrGLProgram::kColorAttributeIndex);
+        GrGLvoid* colorPtr = reinterpret_cast<GrGLvoid*>(vertexOffset + colorOffset);
+        fHWGeometryState.setAttribArray(this,
+                                        GrGLProgram::kColorAttributeIndex,
+                                        vb,
+                                        4,
+                                        GR_GL_UNSIGNED_BYTE,
+                                        true,
+                                        stride,
+                                        colorPtr);
+    }
+
+    if (coverageOffset > 0) {
+        usedAttribArraysMask |= (1 << GrGLProgram::kCoverageAttributeIndex);
+        GrGLvoid* coveragePtr = reinterpret_cast<GrGLvoid*>(vertexOffset + coverageOffset);
+        fHWGeometryState.setAttribArray(this,
+                                        GrGLProgram::kCoverageAttributeIndex,
+                                        vb,
+                                        4,
+                                        GR_GL_UNSIGNED_BYTE,
+                                        true,
+                                        stride,
+                                        coveragePtr);
+    }
+
+    if (edgeOffset > 0) {
+        usedAttribArraysMask |= (1 << GrGLProgram::kEdgeAttributeIndex);
+        GrGLvoid* edgePtr = reinterpret_cast<GrGLvoid*>(vertexOffset + edgeOffset);
+        fHWGeometryState.setAttribArray(this,
+                                        GrGLProgram::kEdgeAttributeIndex,
+                                        vb,
+                                        4,
+                                        GR_GL_FLOAT,
+                                        false,
+                                        stride,
+                                        edgePtr);
+    }
 
     fHWGeometryState.disableUnusedAttribArrays(this, usedAttribArraysMask);
 }