Remove cached OptDrawState from GrDrawState.
authoregdaniel <egdaniel@google.com>
Tue, 11 Nov 2014 15:32:45 +0000 (07:32 -0800)
committerCommit bot <commit-bot@chromium.org>
Tue, 11 Nov 2014 15:32:45 +0000 (07:32 -0800)
Since we now snap and create the ODS one time in the inorder draw buffer,
there is no need for us to keep a cached version of it around.

BUG=skia:

Review URL: https://codereview.chromium.org/701123003

src/gpu/GrDrawState.cpp
src/gpu/GrDrawState.h
src/gpu/GrOptDrawState.cpp
src/gpu/GrOptDrawState.h

index d300f2b..c82c5ad 100644 (file)
@@ -109,8 +109,7 @@ GrDrawState::CombinedState GrDrawState::CombineIfPossible(
 
 //////////////////////////////////////////////////////////////////////////////s
 
-GrDrawState::GrDrawState(const GrDrawState& state, const SkMatrix& preConcatMatrix)
-    : fCachedOptState(NULL) {
+GrDrawState::GrDrawState(const GrDrawState& state, const SkMatrix& preConcatMatrix) {
     SkDEBUGCODE(fBlockEffectRemovalCnt = 0;)
     *this = state;
     if (!preConcatMatrix.isIdentity()) {
@@ -120,7 +119,6 @@ GrDrawState::GrDrawState(const GrDrawState& state, const SkMatrix& preConcatMatr
         for (int i = 0; i < this->numCoverageStages(); ++i) {
             fCoverageStages[i].localCoordChange(preConcatMatrix);
         }
-        this->invalidateOptState();
     }
 }
 
@@ -151,8 +149,6 @@ GrDrawState& GrDrawState::operator=(const GrDrawState& that) {
 
     fHints = that.fHints;
 
-    SkRefCnt_SafeAssign(fCachedOptState, that.fCachedOptState);
-
     memcpy(fFixedFunctionVertexAttribIndices,
             that.fFixedFunctionVertexAttribIndices,
             sizeof(fFixedFunctionVertexAttribIndices));
@@ -186,8 +182,6 @@ void GrDrawState::onReset(const SkMatrix* initialViewMatrix) {
     fDrawFace = kBoth_DrawFace;
 
     fHints = 0;
-
-    this->invalidateOptState();
 }
 
 bool GrDrawState::setIdentityViewMatrix()  {
@@ -204,7 +198,6 @@ bool GrDrawState::setIdentityViewMatrix()  {
             fCoverageStages[s].localCoordChange(invVM);
         }
     }
-    this->invalidateOptState();
     fViewMatrix.reset();
     return true;
 }
@@ -244,7 +237,6 @@ void GrDrawState::setFromPaint(const GrPaint& paint, const SkMatrix& vm, GrRende
 
     this->setBlendFunc(paint.getSrcBlendCoeff(), paint.getDstBlendCoeff());
     this->setCoverage(paint.getCoverage());
-    this->invalidateOptState();
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -342,7 +334,6 @@ void GrDrawState::internalSetVertexAttribs(const GrVertexAttrib* attribs, int co
         overlapCheck |= (mask << offsetShift);
 #endif
     }
-    this->invalidateOptState();
     // Positions must be specified.
     SkASSERT(-1 != fFixedFunctionVertexAttribIndices[kPosition_GrVertexAttribBinding]);
 }
@@ -362,7 +353,6 @@ void GrDrawState::setDefaultVertexAttribs() {
            0xff,
            sizeof(fFixedFunctionVertexAttribIndices));
     fFixedFunctionVertexAttribIndices[kPosition_GrVertexAttribBinding] = 0;
-    this->invalidateOptState();
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -457,9 +447,6 @@ void GrDrawState::AutoRestoreEffects::set(GrDrawState* ds) {
         int n = fDrawState->numCoverageStages() - fCoverageEffectCnt;
         SkASSERT(n >= 0);
         fDrawState->fCoverageStages.pop_back_n(n);
-        if (m + n > 0) {
-            fDrawState->invalidateOptState();
-        }
         SkDEBUGCODE(--fDrawState->fBlockEffectRemovalCnt;)
     }
     fDrawState = ds;
@@ -513,7 +500,6 @@ void GrDrawState::AutoViewMatrixRestore::restore() {
         for (int s = 0; s < numCoverageStages; ++s, ++i) {
             fDrawState->fCoverageStages[s].restoreCoordChange(fSavedCoordChanges[i]);
         }
-        fDrawState->invalidateOptState();
         fDrawState = NULL;
     }
 }
@@ -533,7 +519,6 @@ void GrDrawState::AutoViewMatrixRestore::set(GrDrawState* drawState,
 
     this->doEffectCoordChanges(preconcatMatrix);
     SkDEBUGCODE(++fDrawState->fBlockEffectRemovalCnt;)
-    drawState->invalidateOptState();
 }
 
 bool GrDrawState::AutoViewMatrixRestore::setIdentity(GrDrawState* drawState) {
@@ -547,7 +532,6 @@ bool GrDrawState::AutoViewMatrixRestore::setIdentity(GrDrawState* drawState) {
         return true;
     }
 
-    drawState->invalidateOptState();
     fViewMatrix = drawState->getViewMatrix();
     if (0 == drawState->numTotalStages()) {
         drawState->fViewMatrix.reset();
@@ -604,14 +588,7 @@ void GrDrawState::convertToPendingExec() {
 
 ////////////////////////////////////////////////////////////////////////////////
 
-void GrDrawState::invalidateOptState() const {
-    SkSafeSetNull(fCachedOptState);
-}
-
-////////////////////////////////////////////////////////////////////////////////
-
 GrDrawState::~GrDrawState() {
-    SkSafeUnref(fCachedOptState);
     SkASSERT(0 == fBlockEffectRemovalCnt);
 }
 
index 97516e8..15df975 100644 (file)
@@ -28,12 +28,12 @@ class GrDrawState : public SkRefCnt {
 public:
     SK_DECLARE_INST_COUNT(GrDrawState)
 
-    GrDrawState() : fCachedOptState(NULL) {
+    GrDrawState() {
         SkDEBUGCODE(fBlockEffectRemovalCnt = 0;)
         this->reset();
     }
 
-    GrDrawState(const SkMatrix& initialViewMatrix) : fCachedOptState(NULL) {
+    GrDrawState(const SkMatrix& initialViewMatrix) {
         SkDEBUGCODE(fBlockEffectRemovalCnt = 0;)
         this->reset(initialViewMatrix);
     }
@@ -41,7 +41,7 @@ public:
     /**
      * Copies another draw state.
      **/
-    GrDrawState(const GrDrawState& state) : INHERITED(), fCachedOptState(NULL) {
+    GrDrawState(const GrDrawState& state) : INHERITED() {
         SkDEBUGCODE(fBlockEffectRemovalCnt = 0;)
         *this = state;
     }
@@ -175,7 +175,6 @@ public:
     void setColor(GrColor color) {
         if (color != fColor) {
             fColor = color;
-            this->invalidateOptState();
         }
     }
 
@@ -207,7 +206,6 @@ public:
     void setCoverage(uint8_t coverage) {
         if (coverage != fCoverage) {
             fCoverage = coverage;
-            this->invalidateOptState();
         }
     }
 
@@ -223,7 +221,6 @@ public:
         SkASSERT(geometryProcessor);
         SkASSERT(!this->hasGeometryProcessor());
         fGeometryProcessor.reset(SkRef(geometryProcessor));
-        this->invalidateOptState();
         return geometryProcessor;
     }
 
@@ -267,14 +264,12 @@ public:
     const GrFragmentProcessor* addColorProcessor(const GrFragmentProcessor* effect) {
         SkASSERT(effect);
         SkNEW_APPEND_TO_TARRAY(&fColorStages, GrFragmentStage, (effect));
-        this->invalidateOptState();
         return effect;
     }
 
     const GrFragmentProcessor* addCoverageProcessor(const GrFragmentProcessor* effect) {
         SkASSERT(effect);
         SkNEW_APPEND_TO_TARRAY(&fCoverageStages, GrFragmentStage, (effect));
-        this->invalidateOptState();
         return effect;
     }
 
@@ -415,7 +410,6 @@ public:
         if (srcCoeff != fSrcBlend || dstCoeff != fDstBlend) {
             fSrcBlend = srcCoeff;
             fDstBlend = dstCoeff;
-            this->invalidateOptState();
         }
     #ifdef SK_DEBUG
         if (GrBlendCoeffRefsDst(dstCoeff)) {
@@ -440,7 +434,6 @@ public:
     void setBlendConstant(GrColor constant) {
         if (constant != fBlendConstant) {
             fBlendConstant = constant;
-            this->invalidateOptState();
         }
     }
 
@@ -539,7 +532,6 @@ public:
      */
     void setRenderTarget(GrRenderTarget* target) {
         fRenderTarget.set(SkSafeRef(target), kWrite_GrIOType);
-        this->invalidateOptState();
     }
 
     /// @}
@@ -560,7 +552,6 @@ public:
     void setStencil(const GrStencilSettings& settings) {
         if (settings != fStencilSettings) {
             fStencilSettings = settings;
-            this->invalidateOptState();
         }
     }
 
@@ -570,7 +561,6 @@ public:
     void disableStencil() {
         if (!fStencilSettings.isDisabled()) {
             fStencilSettings.setDisabled();
-            this->invalidateOptState();
         }
     }
 
@@ -630,7 +620,6 @@ public:
     void resetStateFlags() {
         if (0 != fFlagBits) {
             fFlagBits = 0;
-            this->invalidateOptState();
         }
     }
 
@@ -642,7 +631,6 @@ public:
     void enableState(uint32_t stateBits) {
         if (stateBits & ~fFlagBits) {
             fFlagBits |= stateBits;
-            this->invalidateOptState();
         }
     }
 
@@ -654,7 +642,6 @@ public:
     void disableState(uint32_t stateBits) {
         if (stateBits & fFlagBits) {
             fFlagBits &= ~(stateBits);
-            this->invalidateOptState();
         }
     }
 
@@ -809,8 +796,6 @@ private:
      */
     bool srcAlphaWillBeOne() const;
 
-    void invalidateOptState() const;
-
     void onReset(const SkMatrix* initialViewMatrix);
 
     // Some of the auto restore objects assume that no effects are removed during their lifetime.
@@ -847,9 +832,6 @@ private:
     // not need to be compared in op==.
     int fFixedFunctionVertexAttribIndices[kGrFixedFunctionVertexAttribBindingCnt];
 
-    mutable GrOptDrawState* fCachedOptState;
-    mutable uint32_t fCachedCapsID;
-
     friend class GrOptDrawState;
 
     typedef SkRefCnt INHERITED;
index a9d8ec4..c764b43 100644 (file)
@@ -99,39 +99,23 @@ GrOptDrawState* GrOptDrawState::Create(const GrDrawState& drawState,
                                        GrGpu* gpu,
                                        const GrDeviceCoordTexture* dstCopy,
                                        GrGpu::DrawType drawType) {
-    const GrDrawTargetCaps& caps = *gpu->caps();
-    if (NULL == drawState.fCachedOptState || caps.getUniqueID() != drawState.fCachedCapsID) {
-        GrBlendCoeff srcCoeff;
-        GrBlendCoeff dstCoeff;
-        BlendOptFlags blendFlags = (BlendOptFlags) drawState.getBlendOpts(false,
-                                                                          &srcCoeff,
-                                                                          &dstCoeff);
-
-        // If our blend coeffs are set to 0,1 we know we will not end up drawing unless we are
-        // stenciling. When path rendering the stencil settings are not always set on the draw state
-        // so we must check the draw type. In cases where we will skip drawing we simply return a
-        // null GrOptDrawState.
-        if (kZero_GrBlendCoeff == srcCoeff && kOne_GrBlendCoeff == dstCoeff &&
-            !drawState.getStencil().doesWrite() && GrGpu::kStencilPath_DrawType != drawType) {
-            return NULL;
-        }
-
-        drawState.fCachedOptState = SkNEW_ARGS(GrOptDrawState, (drawState, blendFlags, srcCoeff,
-                                                                dstCoeff, gpu, dstCopy, drawType));
-        drawState.fCachedCapsID = caps.getUniqueID();
-    } else {
-#ifdef SK_DEBUG
-        GrBlendCoeff srcCoeff;
-        GrBlendCoeff dstCoeff;
-        BlendOptFlags blendFlags = (BlendOptFlags) drawState.getBlendOpts(false,
-                                                                          &srcCoeff,
-                                                                          &dstCoeff);
-        SkASSERT(GrOptDrawState(drawState, blendFlags, srcCoeff, dstCoeff, gpu, dstCopy,
-                                drawType) == *drawState.fCachedOptState);
-#endif
+    GrBlendCoeff srcCoeff;
+    GrBlendCoeff dstCoeff;
+    BlendOptFlags blendFlags = (BlendOptFlags) drawState.getBlendOpts(false,
+                                                                      &srcCoeff,
+                                                                      &dstCoeff);
+
+    // If our blend coeffs are set to 0,1 we know we will not end up drawing unless we are
+    // stenciling. When path rendering the stencil settings are not always set on the draw state
+    // so we must check the draw type. In cases where we will skip drawing we simply return a
+    // null GrOptDrawState.
+    if (kZero_GrBlendCoeff == srcCoeff && kOne_GrBlendCoeff == dstCoeff &&
+        !drawState.getStencil().doesWrite() && GrGpu::kStencilPath_DrawType != drawType) {
+        return NULL;
     }
-    drawState.fCachedOptState->ref();
-    return drawState.fCachedOptState;
+
+    return SkNEW_ARGS(GrOptDrawState, (drawState, blendFlags, srcCoeff,
+                                       dstCoeff, gpu, dstCopy, drawType));
 }
 
 void GrOptDrawState::setOutputStateInfo(const GrDrawState& ds,
index c32294b..945cbfb 100644 (file)
@@ -27,10 +27,8 @@ class GrDrawState;
 class GrOptDrawState : public SkRefCnt {
 public:
     /**
-     * Returns a snapshot of the current optimized state. If the current drawState has a valid
-     * cached optimiezed state it will simply return a pointer to it otherwise it will create a new
-     * GrOptDrawState. In all cases the GrOptDrawState is reffed and ownership is given to the
-     * caller.
+     * Returns a snapshot of the current optimized state. The GrOptDrawState is reffed and ownership
+     * is given to the caller.
      */
     static GrOptDrawState* Create(const GrDrawState& drawState, GrGpu*,
                                   const GrDeviceCoordTexture* dstCopy, GrGpu::DrawType drawType);