diff options
author | bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-05-21 13:21:46 +0000 |
---|---|---|
committer | bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-05-21 13:21:46 +0000 |
commit | a4d8fc24736e77fd8c588c4be63e3c15a4154860 (patch) | |
tree | 2c36e4f0211dacb8db61561ca5700386ebc521be | |
parent | b45a1b46ee25e9b19800b028bb1ca925212ac7b4 (diff) |
Stop using GrDrawState to track GPU's blend state
git-svn-id: http://skia.googlecode.com/svn/trunk@4007 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r-- | include/gpu/GrTypes.h | 2 | ||||
-rw-r--r-- | src/gpu/gl/GrGpuGL.cpp | 48 | ||||
-rw-r--r-- | src/gpu/gl/GrGpuGL.h | 23 |
3 files changed, 45 insertions, 28 deletions
diff --git a/include/gpu/GrTypes.h b/include/gpu/GrTypes.h index e3e5357075..0486cbf734 100644 --- a/include/gpu/GrTypes.h +++ b/include/gpu/GrTypes.h @@ -225,6 +225,8 @@ static inline bool GrIsPrimTypeTris(GrPrimitiveType type) { * Coeffecients for alpha-blending. */ enum GrBlendCoeff { + kInvalid_BlendCoeff = -1, + kZero_BlendCoeff, //<! 0 kOne_BlendCoeff, //<! 1 kSC_BlendCoeff, //<! src color diff --git a/src/gpu/gl/GrGpuGL.cpp b/src/gpu/gl/GrGpuGL.cpp index 2966f59633..805d5134e8 100644 --- a/src/gpu/gl/GrGpuGL.cpp +++ b/src/gpu/gl/GrGpuGL.cpp @@ -456,10 +456,6 @@ void GrGpuGL::onResetContext() { this->glCaps().print(); } - // We detect cases when blending is effectively off - fHWBlendDisabled = false; - GL_CALL(Enable(GR_GL_BLEND)); - // we don't use the zb at all GL_CALL(Disable(GR_GL_DEPTH_TEST)); GL_CALL(DepthMask(GR_GL_FALSE)); @@ -486,11 +482,7 @@ void GrGpuGL::onResetContext() { // invalid fActiveTextureUnitIdx = -1; - // illegal values - fHWDrawState.setBlendFunc((GrBlendCoeff)0xFF, (GrBlendCoeff)0xFF); - - fHWDrawState.setBlendConstant(0x00000000); - GL_CALL(BlendColor(0,0,0,0)); + fHWBlendState.invalidate(); fHWDrawState.setColor(GrColor_ILLEGAL); @@ -1976,15 +1968,16 @@ void GrGpuGL::flushBlend(GrPrimitiveType type, GrBlendCoeff srcCoeff, GrBlendCoeff dstCoeff) { if (GrIsPrimTypeLines(type) && this->willUseHWAALines()) { - if (fHWBlendDisabled) { + if (kYes_TriState != fHWBlendState.fEnabled) { GL_CALL(Enable(GR_GL_BLEND)); - fHWBlendDisabled = false; + fHWBlendState.fEnabled = kYes_TriState; } - if (kSA_BlendCoeff != fHWDrawState.getSrcBlendCoeff() || - kISA_BlendCoeff != fHWDrawState.getDstBlendCoeff()) { + if (kSA_BlendCoeff != fHWBlendState.fSrcCoeff || + kISA_BlendCoeff != fHWBlendState.fDstCoeff) { GL_CALL(BlendFunc(gXfermodeCoeff2Blend[kSA_BlendCoeff], gXfermodeCoeff2Blend[kISA_BlendCoeff])); - fHWDrawState.setBlendFunc(kSA_BlendCoeff, kISA_BlendCoeff); + fHWBlendState.fSrcCoeff = kSA_BlendCoeff; + fHWBlendState.fDstCoeff = kISA_BlendCoeff; } } else { // any optimization to disable blending should @@ -1992,25 +1985,28 @@ void GrGpuGL::flushBlend(GrPrimitiveType type, // to (1, 0). bool blendOff = kOne_BlendCoeff == srcCoeff && kZero_BlendCoeff == dstCoeff; - if (fHWBlendDisabled != blendOff) { - if (blendOff) { + if (blendOff) { + if (kNo_TriState != fHWBlendState.fEnabled) { GL_CALL(Disable(GR_GL_BLEND)); - } else { + fHWBlendState.fEnabled = kNo_TriState; + } + } else { + if (kYes_TriState != fHWBlendState.fEnabled) { GL_CALL(Enable(GR_GL_BLEND)); + fHWBlendState.fEnabled = kYes_TriState; } - fHWBlendDisabled = blendOff; - } - if (!blendOff) { - if (fHWDrawState.getSrcBlendCoeff() != srcCoeff || - fHWDrawState.getDstBlendCoeff() != dstCoeff) { + if (fHWBlendState.fSrcCoeff != srcCoeff || + fHWBlendState.fDstCoeff != dstCoeff) { GL_CALL(BlendFunc(gXfermodeCoeff2Blend[srcCoeff], gXfermodeCoeff2Blend[dstCoeff])); - fHWDrawState.setBlendFunc(srcCoeff, dstCoeff); + fHWBlendState.fSrcCoeff = srcCoeff; + fHWBlendState.fDstCoeff = dstCoeff; } GrColor blendConst = this->getDrawState().getBlendConstant(); if ((BlendCoeffReferencesConstant(srcCoeff) || BlendCoeffReferencesConstant(dstCoeff)) && - fHWDrawState.getBlendConstant() != blendConst) { + (!fHWBlendState.fConstColorValid || + fHWBlendState.fConstColor != blendConst)) { float c[] = { GrColorUnpackR(blendConst) / 255.f, @@ -2019,12 +2015,12 @@ void GrGpuGL::flushBlend(GrPrimitiveType type, GrColorUnpackA(blendConst) / 255.f }; GL_CALL(BlendColor(c[0], c[1], c[2], c[3])); - fHWDrawState.setBlendConstant(blendConst); + fHWBlendState.fConstColor = blendConst; + fHWBlendState.fConstColorValid = true; } } } } - namespace { unsigned gr_to_gl_filter(GrSamplerState::Filter filter) { diff --git a/src/gpu/gl/GrGpuGL.h b/src/gpu/gl/GrGpuGL.h index b22b44f204..d5c9c27fa5 100644 --- a/src/gpu/gl/GrGpuGL.h +++ b/src/gpu/gl/GrGpuGL.h @@ -50,6 +50,12 @@ public: protected: GrGpuGL(const GrGLContextInfo& ctxInfo); + enum TriState { + kNo_TriState, + kYes_TriState, + kUnknown_TriState + }; + struct { size_t fVertexOffset; GrVertexLayout fVertexLayout; @@ -242,10 +248,23 @@ private: GrGLContextInfo fGLContextInfo; - bool fHWBlendDisabled; - int fActiveTextureUnitIdx; + struct { + GrBlendCoeff fSrcCoeff; + GrBlendCoeff fDstCoeff; + GrColor fConstColor; + bool fConstColorValid; + TriState fEnabled; + + void invalidate() { + fSrcCoeff = kInvalid_BlendCoeff; + fDstCoeff = kInvalid_BlendCoeff; + fConstColorValid = false; + fEnabled = kUnknown_TriState; + } + } fHWBlendState; + // we record what stencil format worked last time to hopefully exit early // from our loop that tries stencil formats and calls check fb status. int fLastSuccessfulStencilFmtIdx; |