Remove State struct from GrDrawState

BUG=skia:
R=bsalomon@google.com

Author: egdaniel@google.com

Review URL: https://codereview.chromium.org/464363002
diff --git a/src/gpu/GrDrawState.cpp b/src/gpu/GrDrawState.cpp
index e13c605..ba5d628 100644
--- a/src/gpu/GrDrawState.cpp
+++ b/src/gpu/GrDrawState.cpp
@@ -11,29 +11,6 @@
 
 //////////////////////////////////////////////////////////////////////////////s
 
-bool GrDrawState::State::HaveCompatibleState(const State& a, const State& b,
-                                             bool explicitLocalCoords) {
-    if (a.fColorStages.count() != b.fColorStages.count() ||
-        a.fCoverageStages.count() != b.fCoverageStages.count() ||
-        a.fSrcBlend != b.fSrcBlend ||
-        a.fDstBlend != b.fDstBlend) {
-        return false;
-    }
-    for (int i = 0; i < a.fColorStages.count(); i++) {
-        if (!GrEffectStage::AreCompatible(a.fColorStages[i], b.fColorStages[i],
-                                          explicitLocalCoords)) {
-            return false;
-        }
-    }
-    for (int i = 0; i < a.fCoverageStages.count(); i++) {
-        if (!GrEffectStage::AreCompatible(a.fCoverageStages[i], b.fCoverageStages[i],
-                                          explicitLocalCoords)) {
-            return false;
-        }
-    }
-    return true;
-}
-//////////////////////////////////////////////////////////////////////////////s
 GrDrawState::CombinedState GrDrawState::CombineIfPossible(
     const GrDrawState& a, const GrDrawState& b, const GrDrawTargetCaps& caps) {
 
@@ -43,7 +20,11 @@
     }
 
     if (a.fRenderTarget.get() != b.fRenderTarget.get() ||
+        a.fColorStages.count() != b.fColorStages.count() ||
+        a.fCoverageStages.count() != b.fCoverageStages.count() ||
         !a.fViewMatrix.cheapEqualTo(b.fViewMatrix) ||
+        a.fSrcBlend != b.fSrcBlend ||
+        a.fDstBlend != b.fDstBlend ||
         a.fBlendConstant != b.fBlendConstant ||
         a.fFlagBits != b.fFlagBits ||
         a.fVACount != b.fVACount ||
@@ -59,13 +40,22 @@
     }
 
     bool explicitLocalCoords = a.hasLocalCoordAttribute();
+    for (int i = 0; i < a.numColorStages(); i++) {
+        if (!GrEffectStage::AreCompatible(a.getColorStage(i), b.getColorStage(i),
+                                          explicitLocalCoords)) {
+            return kIncompatible_CombinedState;
+        }
+    }
+    for (int i = 0; i < a.numCoverageStages(); i++) {
+        if (!GrEffectStage::AreCompatible(a.getCoverageStage(i), b.getCoverageStage(i),
+                                          explicitLocalCoords)) {
+            return kIncompatible_CombinedState;
+        }
+    }
 
     SkASSERT(0 == memcmp(a.fFixedFunctionVertexAttribIndices,
                             b.fFixedFunctionVertexAttribIndices,
                             sizeof(a.fFixedFunctionVertexAttribIndices)));
-    if (!State::HaveCompatibleState(a.fState, b.fState, explicitLocalCoords)) {
-        return kIncompatible_CombinedState;
-    }
 
     if (usingVertexColors) {
         // If one is opaque and the other is not then the combined state is not opaque. Moreover,
@@ -102,10 +92,10 @@
     *this = state;
     if (!preConcatMatrix.isIdentity()) {
         for (int i = 0; i < this->numColorStages(); ++i) {
-            fState.fColorStages[i].localCoordChange(preConcatMatrix);
+            fColorStages[i].localCoordChange(preConcatMatrix);
         }
         for (int i = 0; i < this->numCoverageStages(); ++i) {
-            fState.fCoverageStages[i].localCoordChange(preConcatMatrix);
+            fCoverageStages[i].localCoordChange(preConcatMatrix);
         }
         this->invalidateBlendOptFlags();
     }
@@ -116,6 +106,8 @@
     this->setRenderTarget(that.fRenderTarget.get());
     fColor = that.fColor;
     fViewMatrix = that.fViewMatrix;
+    fSrcBlend = that.fSrcBlend;
+    fDstBlend = that.fDstBlend;
     fBlendConstant = that.fBlendConstant;
     fFlagBits = that.fFlagBits;
     fVACount = that.fVACount;
@@ -123,11 +115,12 @@
     fStencilSettings = that.fStencilSettings;
     fCoverage = that.fCoverage;
     fDrawFace = that.fDrawFace;
+    fColorStages = that.fColorStages;
+    fCoverageStages = that.fCoverageStages;
     fOptSrcBlend = that.fOptSrcBlend;
     fOptDstBlend = that.fOptDstBlend;
     fBlendOptFlags = that.fBlendOptFlags;
 
-    fState = that.fState;
     fHints = that.fHints;
 
     memcpy(fFixedFunctionVertexAttribIndices,
@@ -138,7 +131,8 @@
 
 void GrDrawState::onReset(const SkMatrix* initialViewMatrix) {
     SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages());
-    fState.reset();
+    fColorStages.reset();
+    fCoverageStages.reset();
 
     fRenderTarget.reset(NULL);
 
@@ -150,10 +144,12 @@
     } else {
         fViewMatrix = *initialViewMatrix;
     }
+    fSrcBlend = kOne_GrBlendCoeff;
+    fDstBlend = kZero_GrBlendCoeff;
     fBlendConstant = 0x0;
     fFlagBits = 0x0;
     fStencilSettings.setDisabled();
-    fCoverage = 0xffffffff;
+    fCoverage = 0xff;
     fDrawFace = kBoth_DrawFace;
 
     fHints = 0;
@@ -169,10 +165,10 @@
             return false;
         }
         for (int s = 0; s < this->numColorStages(); ++s) {
-            fState.fColorStages[s].localCoordChange(invVM);
+            fColorStages[s].localCoordChange(invVM);
         }
         for (int s = 0; s < this->numCoverageStages(); ++s) {
-            fState.fCoverageStages[s].localCoordChange(invVM);
+            fCoverageStages[s].localCoordChange(invVM);
         }
     }
     fViewMatrix.reset();
@@ -182,14 +178,15 @@
 void GrDrawState::setFromPaint(const GrPaint& paint, const SkMatrix& vm, GrRenderTarget* rt) {
     SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages());
 
-    fState.reset();
+    fColorStages.reset();
+    fCoverageStages.reset();
 
     for (int i = 0; i < paint.numColorStages(); ++i) {
-        fState.fColorStages.push_back(paint.getColorStage(i));
+        fColorStages.push_back(paint.getColorStage(i));
     }
 
     for (int i = 0; i < paint.numCoverageStages(); ++i) {
-        fState.fCoverageStages.push_back(paint.getCoverageStage(i));
+        fCoverageStages.push_back(paint.getCoverageStage(i));
     }
 
     this->setRenderTarget(rt);
@@ -436,7 +433,7 @@
     if (this->hasCoverageVertexAttribute()) {
         validComponentFlags = 0;
     } else {
-        coverage = fCoverage;
+        coverage = this->getCoverageColor();
         validComponentFlags = kRGBA_GrColorComponentFlags;
     }
 
@@ -464,9 +461,9 @@
      Also, if we're directly rendering coverage (isCoverageDrawing) then coverage is treated as
      color by definition.
      */
-    return kOne_GrBlendCoeff == fState.fDstBlend ||
-           kISA_GrBlendCoeff == fState.fDstBlend ||
-           kISC_GrBlendCoeff == fState.fDstBlend ||
+    return kOne_GrBlendCoeff == fDstBlend ||
+           kISA_GrBlendCoeff == fDstBlend ||
+           kISC_GrBlendCoeff == fDstBlend ||
            this->isCoverageDrawing();
 }
 
@@ -605,11 +602,11 @@
     if (NULL != fDrawState) {
         int m = fDrawState->numColorStages() - fColorEffectCnt;
         SkASSERT(m >= 0);
-        fDrawState->fState.fColorStages.pop_back_n(m);
+        fDrawState->fColorStages.pop_back_n(m);
 
         int n = fDrawState->numCoverageStages() - fCoverageEffectCnt;
         SkASSERT(n >= 0);
-        fDrawState->fState.fCoverageStages.pop_back_n(n);
+        fDrawState->fCoverageStages.pop_back_n(n);
         if (m + n > 0) {
             fDrawState->invalidateBlendOptFlags();
         }
@@ -635,10 +632,10 @@
 
         int i = 0;
         for (int s = 0; s < fNumColorStages; ++s, ++i) {
-            fDrawState->fState.fColorStages[s].restoreCoordChange(fSavedCoordChanges[i]);
+            fDrawState->fColorStages[s].restoreCoordChange(fSavedCoordChanges[i]);
         }
         for (int s = 0; s < numCoverageStages; ++s, ++i) {
-            fDrawState->fState.fCoverageStages[s].restoreCoordChange(fSavedCoordChanges[i]);
+            fDrawState->fCoverageStages[s].restoreCoordChange(fSavedCoordChanges[i]);
         }
         fDrawState = NULL;
     }
@@ -700,12 +697,12 @@
     fNumColorStages = fDrawState->numColorStages();
     for (int s = 0; s < fNumColorStages; ++s, ++i) {
         fDrawState->getColorStage(s).saveCoordChange(&fSavedCoordChanges[i]);
-        fDrawState->fState.fColorStages[s].localCoordChange(coordChangeMatrix);
+        fDrawState->fColorStages[s].localCoordChange(coordChangeMatrix);
     }
 
     int numCoverageStages = fDrawState->numCoverageStages();
     for (int s = 0; s < numCoverageStages; ++s, ++i) {
         fDrawState->getCoverageStage(s).saveCoordChange(&fSavedCoordChanges[i]);
-        fDrawState->fState.fCoverageStages[s].localCoordChange(coordChangeMatrix);
+        fDrawState->fCoverageStages[s].localCoordChange(coordChangeMatrix);
     }
 }
diff --git a/src/gpu/GrDrawState.h b/src/gpu/GrDrawState.h
index 249eeeb..ce0a583 100644
--- a/src/gpu/GrDrawState.h
+++ b/src/gpu/GrDrawState.h
@@ -209,50 +209,18 @@
      * coverage is ignored when per-vertex coverage is provided.
      */
     void setCoverage(uint8_t coverage) {
-        fCoverage = GrColorPackRGBA(coverage, coverage, coverage, coverage);
+        fCoverage = coverage;
         this->invalidateBlendOptFlags();
     }
 
-    uint8_t getCoverage() const { return GrColorUnpackR(fCoverage); }
+    uint8_t getCoverage() const { return fCoverage; }
 
-    GrColor getCoverageColor() const { return fCoverage; }
+    GrColor getCoverageColor() const {
+        return GrColorPackRGBA(fCoverage, fCoverage, fCoverage, fCoverage);
+    }
 
     /// @}
 
-    /**
-     * This struct is here so that the GrDrawState can have multiple instances of state information.
-     * The use of this will come in a future revision when we want to keep track of the original
-     * draw state as well as an optimized version of it.
-     */
-    struct State {
-        State() {
-            this->reset();
-        }
-
-        State(const GrEffectStage* colorArray, int colorCount,
-                      const GrEffectStage* coverageArray, int coverageCount)
-            : fColorStages(colorArray, colorCount), fCoverageStages(coverageArray, coverageCount) {
-                fSrcBlend = kOne_GrBlendCoeff;
-                fDstBlend = kZero_GrBlendCoeff;
-        }
-
-        static bool HaveCompatibleState(const State& a, const State& b, bool explicitLocalCoords);
-
-        void reset() {
-            fSrcBlend = kOne_GrBlendCoeff;
-            fDstBlend = kZero_GrBlendCoeff;
-            fColorStages.reset();
-            fCoverageStages.reset();
-        }
-
-        GrBlendCoeff                        fSrcBlend;
-        GrBlendCoeff                        fDstBlend;
-
-        typedef SkSTArray<4, GrEffectStage> EffectStageArray;
-        EffectStageArray                    fColorStages;
-        EffectStageArray                    fCoverageStages;
-    };
-
     ///////////////////////////////////////////////////////////////////////////
     /// @name Effect Stages
     /// Each stage hosts a GrEffect. The effect produces an output color or coverage in the fragment
@@ -275,14 +243,14 @@
 
     const GrEffect* addColorEffect(const GrEffect* effect, int attr0 = -1, int attr1 = -1) {
         SkASSERT(NULL != effect);
-        SkNEW_APPEND_TO_TARRAY(&fState.fColorStages, GrEffectStage, (effect, attr0, attr1));
+        SkNEW_APPEND_TO_TARRAY(&fColorStages, GrEffectStage, (effect, attr0, attr1));
         this->invalidateBlendOptFlags();
         return effect;
     }
 
     const GrEffect* addCoverageEffect(const GrEffect* effect, int attr0 = -1, int attr1 = -1) {
         SkASSERT(NULL != effect);
-        SkNEW_APPEND_TO_TARRAY(&fState.fCoverageStages, GrEffectStage, (effect, attr0, attr1));
+        SkNEW_APPEND_TO_TARRAY(&fCoverageStages, GrEffectStage, (effect, attr0, attr1));
         this->invalidateBlendOptFlags();
         return effect;
     }
@@ -334,12 +302,12 @@
         int fCoverageEffectCnt;
     };
 
-    int numColorStages() const { return fState.fColorStages.count(); }
-    int numCoverageStages() const { return fState.fCoverageStages.count(); }
+    int numColorStages() const { return fColorStages.count(); }
+    int numCoverageStages() const { return fCoverageStages.count(); }
     int numTotalStages() const { return this->numColorStages() + this->numCoverageStages(); }
 
-    const GrEffectStage& getColorStage(int stageIdx) const { return fState.fColorStages[stageIdx]; }
-    const GrEffectStage& getCoverageStage(int stageIdx) const { return fState.fCoverageStages[stageIdx]; }
+    const GrEffectStage& getColorStage(int stageIdx) const { return fColorStages[stageIdx]; }
+    const GrEffectStage& getCoverageStage(int stageIdx) const { return fCoverageStages[stageIdx]; }
 
     /**
      * Checks whether any of the effects will read the dst pixel color.
@@ -366,8 +334,8 @@
      * @param dstCoef coefficient applied to the dst color.
      */
     void setBlendFunc(GrBlendCoeff srcCoeff, GrBlendCoeff dstCoeff) {
-        fState.fSrcBlend = srcCoeff;
-        fState.fDstBlend = dstCoeff;
+        fSrcBlend = srcCoeff;
+        fDstBlend = dstCoeff;
         this->invalidateBlendOptFlags();
     #ifdef SK_DEBUG
         if (GrBlendCoeffRefsDst(dstCoeff)) {
@@ -379,13 +347,13 @@
     #endif
     }
 
-    GrBlendCoeff getSrcBlendCoeff() const { return fState.fSrcBlend; }
-    GrBlendCoeff getDstBlendCoeff() const { return fState.fDstBlend; }
+    GrBlendCoeff getSrcBlendCoeff() const { return fSrcBlend; }
+    GrBlendCoeff getDstBlendCoeff() const { return fDstBlend; }
 
     void getDstBlendCoeff(GrBlendCoeff* srcBlendCoeff,
                           GrBlendCoeff* dstBlendCoeff) const {
-        *srcBlendCoeff = fState.fSrcBlend;
-        *dstBlendCoeff = fState.fDstBlend;
+        *srcBlendCoeff = fSrcBlend;
+        *dstBlendCoeff = fDstBlend;
     }
 
     /**
@@ -809,15 +777,19 @@
     SkAutoTUnref<GrRenderTarget>        fRenderTarget;
     GrColor                             fColor;
     SkMatrix                            fViewMatrix;
+    GrBlendCoeff                        fSrcBlend;
+    GrBlendCoeff                        fDstBlend;
     GrColor                             fBlendConstant;
     uint32_t                            fFlagBits;
     const GrVertexAttrib*               fVAPtr;
     int                                 fVACount;
     GrStencilSettings                   fStencilSettings;
-    GrColor                             fCoverage;
+    uint8_t                             fCoverage;
     DrawFace                            fDrawFace;
 
-    State                               fState;
+    typedef SkSTArray<4, GrEffectStage> EffectStageArray;
+    EffectStageArray                    fColorStages;
+    EffectStageArray                    fCoverageStages;
 
     uint32_t                            fHints;