Chromium Code Reviews| Index: src/gpu/GrDrawState.h |
| diff --git a/src/gpu/GrDrawState.h b/src/gpu/GrDrawState.h |
| index de14763a0508fd71ca17c8587aca41b7b0618549..68f14848b8e83187714612e21d29b367241b79ec 100644 |
| --- a/src/gpu/GrDrawState.h |
| +++ b/src/gpu/GrDrawState.h |
| @@ -59,6 +59,7 @@ public: |
| for (int i = 0; i < fCoverageStages.count(); ++i) { |
| fCoverageStages[i].localCoordChange(preConcatMatrix); |
| } |
| + fBlendOptFlags = kInvalid_BlendOptFlag; |
| } |
| } |
| @@ -249,7 +250,10 @@ public: |
| * |
| * @param color the color to set. |
| */ |
| - void setColor(GrColor color) { fColor = color; } |
| + void setColor(GrColor color) { |
| + fColor = color; |
| + fBlendOptFlags = kInvalid_BlendOptFlag; |
| + } |
| GrColor getColor() const { return fColor; } |
| @@ -308,6 +312,7 @@ public: |
| */ |
| void setCoverage(uint8_t coverage) { |
| fCoverage = GrColorPackRGBA(coverage, coverage, coverage, coverage); |
| + fBlendOptFlags = kInvalid_BlendOptFlag; |
| } |
| uint8_t getCoverage() const { |
| @@ -343,12 +348,14 @@ public: |
| const GrEffect* addColorEffect(const GrEffect* effect, int attr0 = -1, int attr1 = -1) { |
| SkASSERT(NULL != effect); |
| SkNEW_APPEND_TO_TARRAY(&fColorStages, GrEffectStage, (effect, attr0, attr1)); |
| + fBlendOptFlags = kInvalid_BlendOptFlag; |
| return effect; |
| } |
| const GrEffect* addCoverageEffect(const GrEffect* effect, int attr0 = -1, int attr1 = -1) { |
| SkASSERT(NULL != effect); |
| SkNEW_APPEND_TO_TARRAY(&fCoverageStages, GrEffectStage, (effect, attr0, attr1)); |
| + fBlendOptFlags = kInvalid_BlendOptFlag; |
| return effect; |
| } |
| @@ -394,9 +401,15 @@ public: |
| int n = fDrawState->fColorStages.count() - fColorEffectCnt; |
| SkASSERT(n >= 0); |
| fDrawState->fColorStages.pop_back_n(n); |
| + if (n > 0) { |
| + fBlendOptFlags = kInvalid_BlendOptFlag; |
| + } |
| n = fDrawState->fCoverageStages.count() - fCoverageEffectCnt; |
|
bsalomon
2014/07/17 19:53:50
int m =
if (n + m > 0)
?
|
| SkASSERT(n >= 0); |
| fDrawState->fCoverageStages.pop_back_n(n); |
| + if (n > 0) { |
| + fBlendOptFlags = kInvalid_BlendOptFlag; |
| + } |
| SkDEBUGCODE(--fDrawState->fBlockEffectRemovalCnt;) |
| } |
| fDrawState = ds; |
| @@ -449,6 +462,7 @@ public: |
| void setBlendFunc(GrBlendCoeff srcCoeff, GrBlendCoeff dstCoeff) { |
| fSrcBlend = srcCoeff; |
| fDstBlend = dstCoeff; |
| + fBlendOptFlags = kInvalid_BlendOptFlag; |
| #ifdef SK_DEBUG |
| if (GrBlendCoeffRefsDst(dstCoeff)) { |
| GrPrintf("Unexpected dst blend coeff. Won't work correctly with coverage stages.\n"); |
| @@ -478,7 +492,10 @@ public: |
| * |
| * @param constant the constant to set |
| */ |
| - void setBlendConstant(GrColor constant) { fBlendConstant = constant; } |
| + void setBlendConstant(GrColor constant) { |
| + fBlendConstant = constant; |
| + fBlendOptFlags = kInvalid_BlendOptFlag; |
| + } |
| /** |
| * Retrieves the last value set by setBlendConstant() |
| @@ -523,6 +540,11 @@ public: |
| * Emit transparent black instead of the src color, no need to compute coverage. |
| */ |
| kEmitTransBlack_BlendOptFlag = 0x10, |
| + /** |
| + * Flag used to invalidate the cached BlendOptFlags, OptSrcCoeff, and OptDstCoeff cached by |
| + * the get BlendOpts function. |
| + */ |
| + kInvalid_BlendOptFlag = 0x20, |
| }; |
| GR_DECL_BITFIELD_OPS_FRIENDS(BlendOptFlags); |
| @@ -535,6 +557,9 @@ public: |
| * |
| * Subclasses of GrDrawTarget that actually draw (as opposed to those that just buffer for |
| * playback) must call this function and respect the flags that replace the output color. |
| + * |
| + * If the cached BlendOptFlags does not have the invalidate bit set, then getBlendOpts will |
| + * simply returned the cached flags and coefficients. Otherwise it will calculate the values. |
| */ |
| BlendOptFlags getBlendOpts(bool forceCoverage = false, |
| GrBlendCoeff* srcCoeff = NULL, |
| @@ -689,6 +714,7 @@ public: |
| */ |
| void setStencil(const GrStencilSettings& settings) { |
| fStencilSettings = settings; |
| + fBlendOptFlags = kInvalid_BlendOptFlag; |
| } |
| /** |
| @@ -696,6 +722,7 @@ public: |
| */ |
| void disableStencil() { |
| fStencilSettings.setDisabled(); |
| + fBlendOptFlags = kInvalid_BlendOptFlag; |
| } |
| const GrStencilSettings& getStencil() const { return fStencilSettings; } |
| @@ -750,6 +777,7 @@ public: |
| void resetStateFlags() { |
| fFlagBits = 0; |
| + fBlendOptFlags = kInvalid_BlendOptFlag; |
| } |
| /** |
| @@ -759,6 +787,7 @@ public: |
| */ |
| void enableState(uint32_t stateBits) { |
| fFlagBits |= stateBits; |
| + fBlendOptFlags = kInvalid_BlendOptFlag; |
| } |
| /** |
| @@ -768,6 +797,7 @@ public: |
| */ |
| void disableState(uint32_t stateBits) { |
| fFlagBits &= ~(stateBits); |
| + fBlendOptFlags = kInvalid_BlendOptFlag; |
| } |
| /** |
| @@ -892,6 +922,9 @@ public: |
| fDrawFace = that.fDrawFace; |
| fColorStages = that.fColorStages; |
| fCoverageStages = that.fCoverageStages; |
| + fOptSrcBlend = that.fOptSrcBlend; |
| + fOptDstBlend = that.fOptDstBlend; |
| + fBlendOptFlags = that.fBlendOptFlags; |
| memcpy(fFixedFunctionVertexAttribIndices, |
| that.fFixedFunctionVertexAttribIndices, |
| @@ -923,8 +956,13 @@ private: |
| fStencilSettings.setDisabled(); |
| fCoverage = 0xffffffff; |
| fDrawFace = kBoth_DrawFace; |
| + |
| + fBlendOptFlags = kInvalid_BlendOptFlag; |
| } |
| + BlendOptFlags calcBlendOpts(bool forceCoverage = false, |
| + GrBlendCoeff* srcCoeff = NULL, |
| + GrBlendCoeff* dstCoeff = NULL) const; |
| // These fields are roughly sorted by decreasing likelihood of being different in op== |
| SkAutoTUnref<GrRenderTarget> fRenderTarget; |
| @@ -943,6 +981,10 @@ private: |
| typedef SkSTArray<4, GrEffectStage> EffectStageArray; |
| EffectStageArray fColorStages; |
| EffectStageArray fCoverageStages; |
| + |
| + mutable GrBlendCoeff fOptSrcBlend; |
| + mutable GrBlendCoeff fOptDstBlend; |
| + mutable BlendOptFlags fBlendOptFlags; |
| // This is simply a different representation of info in fVertexAttribs and thus does |
| // not need to be compared in op==. |