Revert 2830 and 2831.



git-svn-id: http://skia.googlecode.com/svn/trunk@2832 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/gpu/GrGpuGLShaders.cpp b/src/gpu/GrGpuGLShaders.cpp
index 5109a10..9018a4e 100644
--- a/src/gpu/GrGpuGLShaders.cpp
+++ b/src/gpu/GrGpuGLShaders.cpp
@@ -343,7 +343,7 @@
 
     if (GrGLProgram::kSetAsAttribute == 
         fProgramData->fUniLocations.fStages[stage].fTextureMatrixUni) {
-        return fHWDrawState.getSampler(stage).getMatrix();
+        return fHWDrawState.fSamplerStates[stage].getMatrix();
     } else {
         return fProgramData->fTextureMatrices[stage];
     }
@@ -351,9 +351,9 @@
 
 void GrGpuGLShaders::recordHWSamplerMatrix(int stage, const GrMatrix& matrix) {
     GrAssert(fProgramData);
-    if (GrGLProgram::kSetAsAttribute ==
+    if (GrGLProgram::kSetAsAttribute == 
         fProgramData->fUniLocations.fStages[stage].fTextureMatrixUni) {
-        fHWDrawState.sampler(stage)->setMatrix(matrix);
+        fHWDrawState.fSamplerStates[stage].setMatrix(matrix);
     } else {
         fProgramData->fTextureMatrices[stage] = matrix;
     }
@@ -388,68 +388,47 @@
 }
 
 void GrGpuGLShaders::flushViewMatrix() {
+    GrAssert(NULL != fCurrDrawState.fRenderTarget);
+    GrMatrix m;
+    m.setAll(
+        GrIntToScalar(2) / fCurrDrawState.fRenderTarget->width(), 0, -GR_Scalar1,
+        0,-GrIntToScalar(2) / fCurrDrawState.fRenderTarget->height(), GR_Scalar1,
+        0, 0, GrMatrix::I()[8]);
+    m.setConcat(m, fCurrDrawState.fViewMatrix);
 
-    const GrMatrix* hwViewMatrix;
-    // If we are using a uniform for the matrix then the cached value is
-    // stored with each program. If we are using an attribute than it is global
-    // to all programs.
-    if (GrGLProgram::kSetAsAttribute ==
+    // ES doesn't allow you to pass true to the transpose param,
+    // so do our own transpose
+    GrGLfloat mt[]  = {
+        GrScalarToFloat(m[GrMatrix::kMScaleX]),
+        GrScalarToFloat(m[GrMatrix::kMSkewY]),
+        GrScalarToFloat(m[GrMatrix::kMPersp0]),
+        GrScalarToFloat(m[GrMatrix::kMSkewX]),
+        GrScalarToFloat(m[GrMatrix::kMScaleY]),
+        GrScalarToFloat(m[GrMatrix::kMPersp1]),
+        GrScalarToFloat(m[GrMatrix::kMTransX]),
+        GrScalarToFloat(m[GrMatrix::kMTransY]),
+        GrScalarToFloat(m[GrMatrix::kMPersp2])
+    };
+
+    if (GrGLProgram::kSetAsAttribute ==  
         fProgramData->fUniLocations.fViewMatrixUni) {
-        hwViewMatrix = &fHWDrawState.getViewMatrix();
+        int baseIdx = GrGLProgram::ViewMatrixAttributeIdx();
+        GL_CALL(VertexAttrib4fv(baseIdx + 0, mt+0));
+        GL_CALL(VertexAttrib4fv(baseIdx + 1, mt+3));
+        GL_CALL(VertexAttrib4fv(baseIdx + 2, mt+6));
     } else {
-        hwViewMatrix = &fProgramData->fViewMatrix;
-    }
-
-    if (*hwViewMatrix != this->getViewMatrix()) {
-
-        GrRenderTarget* rt = this->getRenderTarget();
-        GrAssert(NULL != rt);
-        GrMatrix m;
-        m.setAll(
-            GrIntToScalar(2) / rt->width(), 0, -GR_Scalar1,
-            0,-GrIntToScalar(2) / rt->height(), GR_Scalar1,
-            0, 0, GrMatrix::I()[8]);
-        m.setConcat(m, this->getViewMatrix());
-
-        // ES doesn't allow you to pass true to the transpose param,
-        // so do our own transpose
-        GrGLfloat mt[]  = {
-            GrScalarToFloat(m[GrMatrix::kMScaleX]),
-            GrScalarToFloat(m[GrMatrix::kMSkewY]),
-            GrScalarToFloat(m[GrMatrix::kMPersp0]),
-            GrScalarToFloat(m[GrMatrix::kMSkewX]),
-            GrScalarToFloat(m[GrMatrix::kMScaleY]),
-            GrScalarToFloat(m[GrMatrix::kMPersp1]),
-            GrScalarToFloat(m[GrMatrix::kMTransX]),
-            GrScalarToFloat(m[GrMatrix::kMTransY]),
-            GrScalarToFloat(m[GrMatrix::kMPersp2])
-        };
-
-        if (GrGLProgram::kSetAsAttribute ==  
-            fProgramData->fUniLocations.fViewMatrixUni) {
-            int baseIdx = GrGLProgram::ViewMatrixAttributeIdx();
-            GL_CALL(VertexAttrib4fv(baseIdx + 0, mt+0));
-            GL_CALL(VertexAttrib4fv(baseIdx + 1, mt+3));
-            GL_CALL(VertexAttrib4fv(baseIdx + 2, mt+6));
-        } else {
-            GrAssert(GrGLProgram::kUnusedUniform != 
-                     fProgramData->fUniLocations.fViewMatrixUni);
-            GL_CALL(UniformMatrix3fv(fProgramData->fUniLocations.fViewMatrixUni,
-                                     1, false, mt));
-        }
-        if (GrGLProgram::kSetAsAttribute ==
-            fProgramData->fUniLocations.fViewMatrixUni) {
-            fHWDrawState.setViewMatrix(this->getViewMatrix());
-        } else {
-            fProgramData->fViewMatrix = this->getViewMatrix();
-        }
+        GrAssert(GrGLProgram::kUnusedUniform != 
+                 fProgramData->fUniLocations.fViewMatrixUni);
+        GL_CALL(UniformMatrix3fv(fProgramData->fUniLocations.fViewMatrixUni,
+                                 1, false, mt));
     }
 }
 
 void GrGpuGLShaders::flushTextureDomain(int s) {
     const GrGLint& uni = fProgramData->fUniLocations.fStages[s].fTexDomUni;
     if (GrGLProgram::kUnusedUniform != uni) {
-        const GrRect &texDom = this->getSampler(s).getTextureDomain();
+        const GrRect &texDom =
+            fCurrDrawState.fSamplerStates[s].getTextureDomain();
 
         if (((1 << s) & fDirtyFlags.fTextureChangedMask) ||
             fProgramData->fTextureDomain[s] != texDom) {
@@ -463,7 +442,7 @@
                 GrScalarToFloat(texDom.bottom())
             };
 
-            GrGLTexture* texture = (GrGLTexture*) this->getTexture(s);
+            GrGLTexture* texture = (GrGLTexture*) fCurrDrawState.fTextures[s];
             GrGLTexture::Orientation orientation = texture->orientation();
 
             // vertical flip if necessary
@@ -482,18 +461,19 @@
 
 void GrGpuGLShaders::flushTextureMatrix(int s) {
     const GrGLint& uni = fProgramData->fUniLocations.fStages[s].fTextureMatrixUni;
-    GrGLTexture* texture = (GrGLTexture*) this->getTexture(s);
+    GrGLTexture* texture = (GrGLTexture*) fCurrDrawState.fTextures[s];
     if (NULL != texture) {
-        const GrMatrix& hwMat = fHWDrawState.getSampler(s).getMatrix();
-        const GrMatrix& currMat = this->getSampler(s).getMatrix();
         if (GrGLProgram::kUnusedUniform != uni &&
             (((1 << s) & fDirtyFlags.fTextureChangedMask) ||
-            hwMat != currMat)) {
+            getHWSamplerMatrix(s) != getSamplerMatrix(s))) {
 
-            GrAssert(NULL != texture);
+            GrAssert(NULL != fCurrDrawState.fTextures[s]);
 
-            GrMatrix m = currMat;
-            GrSamplerState::SampleMode mode = this->getSampler(s).getSampleMode();
+            GrGLTexture* texture = (GrGLTexture*) fCurrDrawState.fTextures[s];
+
+            GrMatrix m = getSamplerMatrix(s);
+            GrSamplerState::SampleMode mode = 
+                fCurrDrawState.fSamplerStates[s].getSampleMode();
             AdjustTextureMatrix(texture, mode, &m);
 
             // ES doesn't allow you to pass true to the transpose param,
@@ -519,7 +499,7 @@
             } else {
                 GL_CALL(UniformMatrix3fv(uni, 1, false, mt));
             }
-            this->recordHWSamplerMatrix(s, currMat);
+            recordHWSamplerMatrix(s, getSamplerMatrix(s));
         }
     }
 }
@@ -527,7 +507,7 @@
 void GrGpuGLShaders::flushRadial2(int s) {
 
     const int &uni = fProgramData->fUniLocations.fStages[s].fRadial2Uni;
-    const GrSamplerState& sampler = fCurrDrawState.getSampler(s);
+    const GrSamplerState& sampler = fCurrDrawState.fSamplerStates[s];
     if (GrGLProgram::kUnusedUniform != uni &&
         (fProgramData->fRadial2CenterX1[s] != sampler.getRadial2CenterX1() ||
          fProgramData->fRadial2Radius0[s]  != sampler.getRadial2Radius0()  ||
@@ -559,7 +539,7 @@
 }
 
 void GrGpuGLShaders::flushConvolution(int s) {
-    const GrSamplerState& sampler = this->getSampler(s);
+    const GrSamplerState& sampler = fCurrDrawState.fSamplerStates[s];
     int kernelUni = fProgramData->fUniLocations.fStages[s].fKernelUni;
     if (GrGLProgram::kUnusedUniform != kernelUni) {
         GL_CALL(Uniform1fv(kernelUni, sampler.getKernelWidth(),
@@ -574,7 +554,7 @@
 void GrGpuGLShaders::flushTexelSize(int s) {
     const int& uni = fProgramData->fUniLocations.fStages[s].fNormalizedTexelSizeUni;
     if (GrGLProgram::kUnusedUniform != uni) {
-        GrGLTexture* texture = (GrGLTexture*) this->getTexture(s);
+        GrGLTexture* texture = (GrGLTexture*) fCurrDrawState.fTextures[s];
         if (texture->width() != fProgramData->fTextureWidth[s] ||
             texture->height() != fProgramData->fTextureHeight[s]) {
 
@@ -590,14 +570,13 @@
 void GrGpuGLShaders::flushEdgeAAData() {
     const int& uni = fProgramData->fUniLocations.fEdgesUni;
     if (GrGLProgram::kUnusedUniform != uni) {
-
-        int count = this->getDrawState().getNumAAEdges();
+        int count = fCurrDrawState.fEdgeAANumEdges;
         GrDrawState::Edge edges[GrDrawState::kMaxEdges];
         // Flip the edges in Y
         float height = 
-            static_cast<float>(this->getRenderTarget()->height());
+            static_cast<float>(fCurrDrawState.fRenderTarget->height());
         for (int i = 0; i < count; ++i) {
-            edges[i] = this->getDrawState().getAAEdges()[i];
+            edges[i] = fCurrDrawState.fEdgeAAEdges[i];
             float b = edges[i].fY;
             edges[i].fY = -b;
             edges[i].fZ += b * height;
@@ -620,16 +599,16 @@
     if (this->getGeomSrc().fVertexLayout & kColor_VertexLayoutBit) {
         // color will be specified per-vertex as an attribute
         // invalidate the const vertex attrib color
-        fHWDrawState.setColor(GrColor_ILLEGAL);
+        fHWDrawState.fColor = GrColor_ILLEGAL;
     } else {
         switch (desc.fColorInput) {
             case ProgramDesc::kAttribute_ColorInput:
-                if (fHWDrawState.getColor() != color) {
+                if (fHWDrawState.fColor != color) {
                     // OpenGL ES only supports the float varities of glVertexAttrib
                     float c[] = GR_COLOR_TO_VEC4(color);
                     GL_CALL(VertexAttrib4fv(GrGLProgram::ColorAttributeIdx(), 
                                             c));
-                    fHWDrawState.setColor(color);
+                    fHWDrawState.fColor = color;
                 }
                 break;
             case ProgramDesc::kUniform_ColorInput:
@@ -650,13 +629,13 @@
                 GrCrash("Unknown color type.");
         }
     }
-    GrColor filterColor = this->getDrawState().getColorFilterColor();
-    int uni = fProgramData->fUniLocations.fColorFilterUni;
-    if (uni != GrGLProgram::kUnusedUniform &&
-        fProgramData->fColorFilterColor != filterColor) {
-        float c[] = GR_COLOR_TO_VEC4(filterColor);
-        GL_CALL(Uniform4fv(uni, 1, c));
-        fProgramData->fColorFilterColor = filterColor;
+    if (fProgramData->fUniLocations.fColorFilterUni
+                != GrGLProgram::kUnusedUniform
+            && fProgramData->fColorFilterColor
+                != fCurrDrawState.fColorFilterColor) {
+        float c[] = GR_COLOR_TO_VEC4(fCurrDrawState.fColorFilterColor);
+        GL_CALL(Uniform4fv(fProgramData->fUniLocations.fColorFilterUni, 1, c));
+        fProgramData->fColorFilterColor = fCurrDrawState.fColorFilterColor;
     }
 }
 
@@ -669,7 +648,7 @@
     if (fDirtyFlags.fRenderTargetChanged) {
         // our coords are in pixel space and the GL matrices map to NDC
         // so if the viewport changed, our matrix is now wrong.
-        fHWDrawState.setViewMatrix(GrMatrix::InvalidMatrix());
+        fHWDrawState.fViewMatrix = GrMatrix::InvalidMatrix();
         // we assume all shader matrices may be wrong after viewport changes
         fProgramCache->invalidateViewMatrices();
     }
@@ -701,11 +680,22 @@
     } else if (blendOpts & kEmitCoverage_BlendOptFlag) {
         color = 0xffffffff;
     } else {
-        color = this->getColor();
+        color = fCurrDrawState.fColor;
     }
     this->flushColor(color);
 
-    this->flushViewMatrix();
+    GrMatrix* currViewMatrix;
+    if (GrGLProgram::kSetAsAttribute == 
+        fProgramData->fUniLocations.fViewMatrixUni) {
+        currViewMatrix = &fHWDrawState.fViewMatrix;
+    } else {
+        currViewMatrix = &fProgramData->fViewMatrix;
+    }
+
+    if (*currViewMatrix != fCurrDrawState.fViewMatrix) {
+        flushViewMatrix();
+        *currViewMatrix = fCurrDrawState.fViewMatrix;
+    }
 
     for (int s = 0; s < GrDrawState::kNumStages; ++s) {
         this->flushTextureMatrix(s);
@@ -719,7 +709,7 @@
         this->flushTextureDomain(s);
     }
     this->flushEdgeAAData();
-    this->resetDirtyFlags();
+    resetDirtyFlags();
     return true;
 }
 
@@ -866,7 +856,6 @@
 void GrGpuGLShaders::buildProgram(GrPrimitiveType type,
                                   BlendOptFlags blendOpts,
                                   GrBlendCoeff dstCoeff) {
-    const GrDrawState& drawState = this->getDrawState();
     ProgramDesc& desc = fCurrentProgram.fProgramDesc;
 
     // This should already have been caught
@@ -896,7 +885,7 @@
 
     desc.fColorFilterXfermode = skipColor ?
                                 SkXfermode::kDst_Mode :
-                                drawState.getColorFilterMode();
+                                fCurrDrawState.fColorFilterXfermode;
 
     // no reason to do edge aa or look at per-vertex coverage if coverage is
     // ignored
@@ -908,7 +897,7 @@
     bool colorIsTransBlack = SkToBool(blendOpts & kEmitTransBlack_BlendOptFlag);
     bool colorIsSolidWhite = (blendOpts & kEmitCoverage_BlendOptFlag) ||
                              (!requiresAttributeColors &&
-                              0xffffffff == this->getColor());
+                              0xffffffff == fCurrDrawState.fColor);
     if (GR_AGGRESSIVE_SHADER_OPTS && colorIsTransBlack) {
         desc.fColorInput = ProgramDesc::kTransBlack_ColorInput;
     } else if (GR_AGGRESSIVE_SHADER_OPTS && colorIsSolidWhite) {
@@ -919,15 +908,16 @@
         desc.fColorInput = ProgramDesc::kAttribute_ColorInput;
     }
 
-    desc.fEdgeAANumEdges = skipCoverage ? 0 : drawState.getNumAAEdges();
+    desc.fEdgeAANumEdges = skipCoverage ? 0 : fCurrDrawState.fEdgeAANumEdges;
     desc.fEdgeAAConcave = desc.fEdgeAANumEdges > 0 &&
-                          drawState.isConcaveEdgeAAState();
+                          SkToBool(fCurrDrawState.fFlagBits &
+                                   kEdgeAAConcave_StateBit);
 
     int lastEnabledStage = -1;
 
     if (!skipCoverage && (desc.fVertexLayout &
                           GrDrawTarget::kEdge_VertexLayoutBit)) {
-        desc.fVertexEdgeType = drawState.getVertexEdgeType();
+        desc.fVertexEdgeType = fCurrDrawState.fVertexEdgeType;
     } else {
         // use canonical value when not set to avoid cache misses
         desc.fVertexEdgeType = GrDrawState::kHairLine_EdgeType;
@@ -939,19 +929,19 @@
         stage.fOptFlags = 0;
         stage.setEnabled(this->isStageEnabled(s));
 
-        bool skip = s < drawState.getFirstCoverageStage() ? skipColor :
-                                                            skipCoverage;
+        bool skip = s < fCurrDrawState.fFirstCoverageStage ? skipColor :
+                                                             skipCoverage;
 
         if (!skip && stage.isEnabled()) {
             lastEnabledStage = s;
-            GrGLTexture* texture = (GrGLTexture*) drawState.getTexture(s);
+            GrGLTexture* texture = (GrGLTexture*) fCurrDrawState.fTextures[s];
             GrAssert(NULL != texture);
-            const GrSamplerState& sampler = drawState.getSampler(s);
+            const GrSamplerState& sampler = fCurrDrawState.fSamplerStates[s];
             // we matrix to invert when orientation is TopDown, so make sure
             // we aren't in that case before flagging as identity.
             if (TextureMatrixIsIdentity(texture, sampler)) {
                 stage.fOptFlags |= StageDesc::kIdentityMatrix_OptFlagBit;
-            } else if (!drawState.getSampler(s).getMatrix().hasPerspective()) {
+            } else if (!getSamplerMatrix(s).hasPerspective()) {
                 stage.fOptFlags |= StageDesc::kNoPerspective_OptFlagBit;
             }
             switch (sampler.getSampleMode()) {
@@ -1034,7 +1024,7 @@
         }
     }
 
-    if (GrPixelConfigIsUnpremultiplied(drawState.getRenderTarget()->config())) {
+    if (GrPixelConfigIsUnpremultiplied(fCurrDrawState.fRenderTarget->config())) {
         desc.fOutputPM = ProgramDesc::kNo_OutputPM;
     } else {
         desc.fOutputPM = ProgramDesc::kYes_OutputPM;
@@ -1056,9 +1046,9 @@
     // immaterial.
     int firstCoverageStage = GrDrawState::kNumStages;
     desc.fFirstCoverageStage = GrDrawState::kNumStages;
-    bool hasCoverage = drawState.getFirstCoverageStage() <= lastEnabledStage;
+    bool hasCoverage = fCurrDrawState.fFirstCoverageStage <= lastEnabledStage;
     if (hasCoverage) {
-        firstCoverageStage = drawState.getFirstCoverageStage();
+        firstCoverageStage = fCurrDrawState.fFirstCoverageStage;
     }
 
     // other coverage inputs