XPFactory lazily initializie in drawstate / GrPaint

BUG=skia:

Review URL: https://codereview.chromium.org/866573002
diff --git a/src/effects/SkGpuBlurUtils.cpp b/src/effects/SkGpuBlurUtils.cpp
index 8603120..758c422 100644
--- a/src/effects/SkGpuBlurUtils.cpp
+++ b/src/effects/SkGpuBlurUtils.cpp
@@ -53,7 +53,6 @@
                                  bool useBounds,
                                  float bounds[2]) {
     GrPaint paint;
-    paint.reset();
     SkAutoTUnref<GrFragmentProcessor> conv(GrConvolutionEffect::CreateGaussian(
         texture, direction, radius, sigma, useBounds, bounds));
     paint.addColorProcessor(conv);
@@ -73,7 +72,6 @@
     SkISize size = SkISize::Make(2 * radiusX + 1,  2 * radiusY + 1);
     SkIPoint kernelOffset = SkIPoint::Make(radiusX, radiusY);
     GrPaint paint;
-    paint.reset();
     SkAutoTUnref<GrFragmentProcessor> conv(GrMatrixConvolutionEffect::CreateGaussian(
             texture, bounds, size, 1.0, 0.0, kernelOffset,
             useBounds ? GrTextureDomain::kClamp_Mode : GrTextureDomain::kIgnore_Mode,
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index 785691d..a0fc678 100755
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -44,13 +44,6 @@
 #include "effects/GrDashingEffect.h"
 #include "effects/GrSingleTextureEffect.h"
 
-#ifdef SK_DEBUG
-    // change this to a 1 to see notifications when partial coverage fails
-    #define GR_DEBUG_PARTIAL_COVERAGE_CHECK 0
-#else
-    #define GR_DEBUG_PARTIAL_COVERAGE_CHECK 0
-#endif
-
 static const size_t DRAW_BUFFER_VBPOOL_BUFFER_SIZE = 1 << 15;
 static const int DRAW_BUFFER_VBPOOL_PREALLOC_BUFFERS = 4;
 
@@ -463,7 +456,6 @@
     context->fFlushToReduceCacheSize = true;
 }
 
-
 GrTexture* GrContext::createUncachedTexture(const GrSurfaceDesc& desc,
                                             void* srcData,
                                             size_t rowBytes) {
@@ -1569,19 +1561,8 @@
 
     ASSERT_OWNED_RESOURCE(fRenderTarget.get());
     if (ds) {
-        if (paint) {
-            SkASSERT(acf);
-            ds->setFromPaint(*paint, fRenderTarget.get());
-#if GR_DEBUG_PARTIAL_COVERAGE_CHECK
-            if ((paint->hasMask()) &&
-                !fDrawState->canUseFracCoveragePrimProc(paint.getColor(), fGpu->caps())) {
-                SkDebugf("Partial pixel coverage will be incorrectly blended.\n");
-            }
-#endif
-        } else {
-            ds->reset();
-            ds->setRenderTarget(fRenderTarget.get());
-        }
+        SkASSERT(paint && acf);
+        ds->setFromPaint(*paint, fRenderTarget.get());
         ds->setState(GrDrawState::kClip_StateBit, fClip && !fClip->fClipStack->isWideOpen());
     }
     fDrawBuffer->setClip(fClip);
diff --git a/src/gpu/GrDrawState.cpp b/src/gpu/GrDrawState.cpp
index 4ec39e7..db70393 100644
--- a/src/gpu/GrDrawState.cpp
+++ b/src/gpu/GrDrawState.cpp
@@ -14,36 +14,18 @@
 #include "GrXferProcessor.h"
 #include "effects/GrPorterDuffXferProcessor.h"
 
-bool GrDrawState::isEqual(const GrDrawState& that, bool explicitLocalCoords) const {
-    if (this->getRenderTarget() != that.getRenderTarget() ||
-        this->fColorStages.count() != that.fColorStages.count() ||
-        this->fCoverageStages.count() != that.fCoverageStages.count() ||
-        this->fFlagBits != that.fFlagBits ||
-        this->fStencilSettings != that.fStencilSettings ||
-        this->fDrawFace != that.fDrawFace) {
-        return false;
-    }
-
-    if (!this->getXPFactory()->isEqual(*that.getXPFactory())) {
-        return false;
-    }
-
-    for (int i = 0; i < this->numColorStages(); i++) {
-        if (this->getColorStage(i) != that.getColorStage(i)) {
-            return false;
-        }
-    }
-    for (int i = 0; i < this->numCoverageStages(); i++) {
-        if (this->getCoverageStage(i) != that.getCoverageStage(i)) {
-            return false;
-        }
-    }
-
-    return true;
+GrDrawState::GrDrawState()
+    : fFlagBits(0x0)
+    , fDrawFace(kBoth_DrawFace)
+    , fColorProcInfoValid(false)
+    , fCoverageProcInfoValid(false)
+    , fColorCache(GrColor_ILLEGAL)
+    , fCoverageCache(GrColor_ILLEGAL)
+    , fColorPrimProc(NULL)
+    , fCoveragePrimProc(NULL) {
+    SkDEBUGCODE(fBlockEffectRemovalCnt = 0;)
 }
 
-//////////////////////////////////////////////////////////////////////////////
-
 GrDrawState& GrDrawState::operator=(const GrDrawState& that) {
     fRenderTarget.reset(SkSafeRef(that.fRenderTarget.get()));
     fFlagBits = that.fFlagBits;
@@ -68,28 +50,6 @@
     return *this;
 }
 
-void GrDrawState::onReset() {
-    SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numFragmentStages());
-    fRenderTarget.reset(NULL);
-
-    fXPFactory.reset(GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode));
-    fColorStages.reset();
-    fCoverageStages.reset();
-
-    fFlagBits = 0x0;
-    fStencilSettings.setDisabled();
-    fDrawFace = kBoth_DrawFace;
-
-    fColorProcInfoValid = false;
-    fCoverageProcInfoValid = false;
-
-    fColorCache = GrColor_ILLEGAL;
-    fCoverageCache = GrColor_ILLEGAL;
-
-    fColorPrimProc = NULL;
-    fCoveragePrimProc = NULL;
-}
-
 void GrDrawState::setFromPaint(const GrPaint& paint, GrRenderTarget* rt) {
     SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numFragmentStages());
 
@@ -142,13 +102,13 @@
     // TODO we want to cache the result of this call, but we can probably clean up the interface
     // so we don't have to pass in a seemingly known coverage
     this->calcCoverageInvariantOutput(GrColor_WHITE);
-    return fXPFactory->canApplyCoverage(fColorProcInfo, fCoverageProcInfo);
+    return this->getXPFactory()->canApplyCoverage(fColorProcInfo, fCoverageProcInfo);
 }
 
 //////////////////////////////////////////////////////////////////////////////s
 
 bool GrDrawState::willEffectReadDstColor() const {
-    return fXPFactory->willReadDst();
+    return this->getXPFactory()->willReadDst();
 }
 
 void GrDrawState::AutoRestoreEffects::set(GrDrawState* ds) {
@@ -179,7 +139,7 @@
 // Some blend modes allow folding a fractional coverage value into the color's alpha channel, while
 // others will blend incorrectly.
 bool GrDrawState::canTweakAlphaForCoverage() const {
-    return fXPFactory->canTweakAlphaForCoverage();
+    return this->getXPFactory()->canTweakAlphaForCoverage();
 }
 
 ////////////////////////////////////////////////////////////////////////////////
diff --git a/src/gpu/GrDrawState.h b/src/gpu/GrDrawState.h
index c02429f..45fc574 100644
--- a/src/gpu/GrDrawState.h
+++ b/src/gpu/GrDrawState.h
@@ -30,11 +30,7 @@
 
 class GrDrawState {
 public:
-    GrDrawState() {
-        SkDEBUGCODE(fBlockEffectRemovalCnt = 0;)
-        this->reset();
-    }
-
+    GrDrawState();
     /**
      * Copies another draw state.
      **/
@@ -46,11 +42,6 @@
     virtual ~GrDrawState();
 
     /**
-     * Resets to the default state. GrProcessors will be removed from all stages.
-     */
-    void reset() { this->onReset(); }
-
-    /**
      * Initializes the GrDrawState based on a GrPaint, view matrix and render target. Note that
      * GrDrawState encompasses more than GrPaint. Aspects of GrDrawState that have no GrPaint
      * equivalents are set to default values with the exception of vertex attribute state which
@@ -102,7 +93,12 @@
     int numCoverageStages() const { return fCoverageStages.count(); }
     int numFragmentStages() const { return this->numColorStages() + this->numCoverageStages(); }
 
-    const GrXPFactory* getXPFactory() const { return fXPFactory.get(); }
+    const GrXPFactory* getXPFactory() const {
+        if (!fXPFactory) {
+            fXPFactory.reset(GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode));
+        }
+        return fXPFactory.get();
+    }
 
     const GrFragmentStage& getColorStage(int idx) const { return fColorStages[idx]; }
     const GrFragmentStage& getCoverageStage(int idx) const { return fCoverageStages[idx]; }
@@ -404,8 +400,6 @@
     GrDrawState& operator= (const GrDrawState& that);
 
 private:
-    bool isEqual(const GrDrawState& that, bool explicitLocalCoords) const;
-
     const GrProcOptInfo& colorProcInfo(const GrPrimitiveProcessor* pp) const {
         this->calcColorInvariantOutput(pp);
         return fColorProcInfo;
@@ -440,8 +434,6 @@
      */
     void calcCoverageInvariantOutput(GrColor) const;
 
-    void onReset();
-
     // Some of the auto restore objects assume that no effects are removed during their lifetime.
     // This is used to assert that this condition holds.
     SkDEBUGCODE(int fBlockEffectRemovalCnt;)
@@ -452,7 +444,7 @@
     uint32_t                                fFlagBits;
     GrStencilSettings                       fStencilSettings;
     DrawFace                                fDrawFace;
-    SkAutoTUnref<const GrXPFactory>         fXPFactory;
+    mutable SkAutoTUnref<const GrXPFactory> fXPFactory;
     FragmentStageArray                      fColorStages;
     FragmentStageArray                      fCoverageStages;
 
diff --git a/src/gpu/GrPaint.cpp b/src/gpu/GrPaint.cpp
index 1df2b39..d35b41f 100644
--- a/src/gpu/GrPaint.cpp
+++ b/src/gpu/GrPaint.cpp
@@ -12,6 +12,12 @@
 #include "effects/GrPorterDuffXferProcessor.h"
 #include "effects/GrSimpleTextureEffect.h"
 
+GrPaint::GrPaint()
+    : fAntiAlias(false)
+    , fDither(false)
+    , fColor(GrColor_WHITE) {
+}
+
 void GrPaint::addColorTextureProcessor(GrTexture* texture, const SkMatrix& matrix) {
     this->addColorProcessor(GrSimpleTextureEffect::Create(texture, matrix))->unref();
 }
@@ -50,10 +56,3 @@
     }
     return false;
 }
-
-void GrPaint::resetStages() {
-    fColorStages.reset();
-    fCoverageStages.reset();
-    fXPFactory.reset(GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode));
-}
-