Don't compare constant color and coverage between GrDrawStates when they are provided by vertex attributes.

R=egdaniel@google.com

Author: bsalomon@google.com

Review URL: https://codereview.chromium.org/439273007
diff --git a/src/gpu/GrBitmapTextContext.cpp b/src/gpu/GrBitmapTextContext.cpp
index 3ca98e4..b2cea2b 100755
--- a/src/gpu/GrBitmapTextContext.cpp
+++ b/src/gpu/GrBitmapTextContext.cpp
@@ -138,10 +138,8 @@
             case kA8_GrMaskFormat:
                 // set back to normal in case we took LCD path previously.
                 drawState->setBlendFunc(fPaint.getSrcBlendCoeff(), fPaint.getDstBlendCoeff());
-                //drawState->setColor(fPaint.getColor());
                 // We're using per-vertex color.
                 SkASSERT(drawState->hasColorVertexAttribute());
-                drawState->setColor(0xFFFFFFFF);
                 break;
             default:
                 SkFAIL("Unexepected mask format.");
diff --git a/src/gpu/GrDistanceFieldTextContext.cpp b/src/gpu/GrDistanceFieldTextContext.cpp
index 003ed40..4321ff1 100755
--- a/src/gpu/GrDistanceFieldTextContext.cpp
+++ b/src/gpu/GrDistanceFieldTextContext.cpp
@@ -218,10 +218,8 @@
         } else {
             // set back to normal in case we took LCD path previously.
             drawState->setBlendFunc(fPaint.getSrcBlendCoeff(), fPaint.getDstBlendCoeff());
-            //drawState->setColor(fPaint.getColor());
             // We're using per-vertex color.
             SkASSERT(drawState->hasColorVertexAttribute());
-            drawState->setColor(0xFFFFFFFF);
         }
         int nGlyphs = fCurrVertex / 4;
         fDrawTarget->setIndexSourceToBuffer(fContext->getQuadIndexBuffer());
diff --git a/src/gpu/GrDrawState.h b/src/gpu/GrDrawState.h
index a4db89d..90bdc64 100644
--- a/src/gpu/GrDrawState.h
+++ b/src/gpu/GrDrawState.h
@@ -267,38 +267,6 @@
         this->setColor((a << 24) | (a << 16) | (a << 8) | a);
     }
 
-    /**
-     * Constructor sets the color to be 'color' which is undone by the destructor.
-     */
-    class AutoColorRestore : public ::SkNoncopyable {
-    public:
-        AutoColorRestore() : fDrawState(NULL), fOldColor(0) {}
-
-        AutoColorRestore(GrDrawState* drawState, GrColor color) {
-            fDrawState = NULL;
-            this->set(drawState, color);
-        }
-
-        void reset() {
-            if (NULL != fDrawState) {
-                fDrawState->setColor(fOldColor);
-                fDrawState = NULL;
-            }
-        }
-
-        void set(GrDrawState* drawState, GrColor color) {
-            this->reset();
-            fDrawState = drawState;
-            fOldColor = fDrawState->getColor();
-            fDrawState->setColor(color);
-        }
-
-        ~AutoColorRestore() { this->reset(); }
-    private:
-        GrDrawState*    fDrawState;
-        GrColor         fOldColor;
-    };
-
     /// @}
 
     ///////////////////////////////////////////////////////////////////////////
@@ -893,10 +861,14 @@
         if draws can be batched. The return value indicates whether combining is possible and, if
         so, which of the two inputs should be used. */
     static CombinedState CombineIfPossible(const GrDrawState& a, const GrDrawState& b) {
+        bool usingVertexColors = a.hasColorVertexAttribute();
+        if (!usingVertexColors && a.fColor != b.fColor) {
+            return kIncompatible_CombinedState;
+        }
+
         if (a.fRenderTarget.get() != b.fRenderTarget.get() ||
             a.fColorStages.count() != b.fColorStages.count() ||
             a.fCoverageStages.count() != b.fCoverageStages.count() ||
-            a.fColor != b.fColor ||
             !a.fViewMatrix.cheapEqualTo(b.fViewMatrix) ||
             a.fSrcBlend != b.fSrcBlend ||
             a.fDstBlend != b.fDstBlend ||
@@ -905,11 +877,15 @@
             a.fVACount != b.fVACount ||
             memcmp(a.fVAPtr, b.fVAPtr, a.fVACount * sizeof(GrVertexAttrib)) ||
             a.fStencilSettings != b.fStencilSettings ||
-            a.fCoverage != b.fCoverage ||
             a.fDrawFace != b.fDrawFace) {
             return kIncompatible_CombinedState;
         }
 
+        bool usingVertexCoverage = a.hasCoverageVertexAttribute();
+        if (!usingVertexCoverage && a.fCoverage != b.fCoverage) {
+            return kIncompatible_CombinedState;
+        }
+
         bool explicitLocalCoords = a.hasLocalCoordAttribute();
         for (int i = 0; i < a.fColorStages.count(); i++) {
             if (!GrEffectStage::AreCompatible(a.fColorStages[i], b.fColorStages[i],
diff --git a/src/gpu/GrInOrderDrawBuffer.cpp b/src/gpu/GrInOrderDrawBuffer.cpp
index 6e44759..954437c 100644
--- a/src/gpu/GrInOrderDrawBuffer.cpp
+++ b/src/gpu/GrInOrderDrawBuffer.cpp
@@ -139,8 +139,6 @@
 void GrInOrderDrawBuffer::onDrawRect(const SkRect& rect,
                                      const SkRect* localRect,
                                      const SkMatrix* localMatrix) {
-    GrDrawState::AutoColorRestore acr;
-
     GrDrawState* drawState = this->drawState();
 
     GrColor color = drawState->getColor();
@@ -150,14 +148,6 @@
                    this->caps()->dualSourceBlendingSupport() || drawState->hasSolidCoverage(),
                    NULL != localRect,
                    &colorOffset, &localOffset);
-    if (colorOffset >= 0) {
-        // We set the draw state's color to white here. This is done so that any batching performed
-        // in our subclass's onDraw() won't get a false from GrDrawState::op== due to a color
-        // mismatch. TODO: Once vertex layout is owned by GrDrawState it should skip comparing the
-        // constant color in its op== when the kColor layout bit is set and then we can remove
-        // this.
-        acr.set(drawState, 0xFFFFFFFF);
-    }
 
     AutoReleaseGeometry geo(this, 4, 0);
     if (!geo.succeeded()) {