Chromium Code Reviews| Index: src/gpu/GrDrawState.h |
| diff --git a/src/gpu/GrDrawState.h b/src/gpu/GrDrawState.h |
| index de14763a0508fd71ca17c8587aca41b7b0618549..6af730966a30ac3d7167c12d154dc7a4e75eeefe 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; |
| } |
| } |
| @@ -308,6 +309,7 @@ public: |
| */ |
| void setCoverage(uint8_t coverage) { |
| fCoverage = GrColorPackRGBA(coverage, coverage, coverage, coverage); |
| + fBlendOptFlags = kInvalid_BlendOptFlag; |
| } |
| uint8_t getCoverage() const { |
| @@ -343,12 +345,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; |
| } |
| @@ -449,6 +453,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"); |
| @@ -523,6 +528,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 +545,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 +702,7 @@ public: |
| */ |
| void setStencil(const GrStencilSettings& settings) { |
| fStencilSettings = settings; |
| + fBlendOptFlags = kInvalid_BlendOptFlag; |
| } |
| /** |
| @@ -696,6 +710,7 @@ public: |
| */ |
| void disableStencil() { |
| fStencilSettings.setDisabled(); |
| + fBlendOptFlags = kInvalid_BlendOptFlag; |
| } |
| const GrStencilSettings& getStencil() const { return fStencilSettings; } |
| @@ -750,6 +765,7 @@ public: |
| void resetStateFlags() { |
| fFlagBits = 0; |
| + fBlendOptFlags = kInvalid_BlendOptFlag; |
| } |
| /** |
| @@ -759,6 +775,7 @@ public: |
| */ |
| void enableState(uint32_t stateBits) { |
| fFlagBits |= stateBits; |
| + fBlendOptFlags = kInvalid_BlendOptFlag; |
| } |
| /** |
| @@ -768,6 +785,7 @@ public: |
| */ |
| void disableState(uint32_t stateBits) { |
| fFlagBits &= ~(stateBits); |
| + fBlendOptFlags = kInvalid_BlendOptFlag; |
| } |
| /** |
| @@ -892,6 +910,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 +944,15 @@ private: |
| fStencilSettings.setDisabled(); |
| fCoverage = 0xffffffff; |
| fDrawFace = kBoth_DrawFace; |
| + |
| + fOptSrcBlend = kOne_GrBlendCoeff; |
|
bsalomon
2014/07/17 18:41:03
Do we even need to set the blend flags here?
egdaniel
2014/07/17 19:35:50
By blend flags are you referring to the Src and Ds
|
| + fOptDstBlend = kZero_GrBlendCoeff; |
| + 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 +971,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==. |