From bcede394ee5e1b5d10dbb149d69a3ad8b8f2cd3c Mon Sep 17 00:00:00 2001 From: "bsalomon@google.com" Date: Wed, 23 Jan 2013 18:29:21 +0000 Subject: Add GrDrawState::DeferredState for saving GrDrawStates in GrInOrderDrawBuffer. A future CL will do the unref'ing of GrResources when converting a GrDrawState to a DeferredState. Review URL: https://codereview.appspot.com/7181049 git-svn-id: http://skia.googlecode.com/svn/trunk@7342 2bbb7eff-a529-9590-31e7-b0007b416f81 --- include/gpu/GrEffectStage.h | 58 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) (limited to 'include/gpu/GrEffectStage.h') diff --git a/include/gpu/GrEffectStage.h b/include/gpu/GrEffectStage.h index c09cd450a7..b561aaac25 100644 --- a/include/gpu/GrEffectStage.h +++ b/include/gpu/GrEffectStage.h @@ -20,7 +20,6 @@ class GrEffectStage { public: - GrEffectStage() : fEffectRef (NULL) { GR_DEBUGCODE(fSavedCoordChangeCnt = 0;) @@ -95,6 +94,63 @@ public: GR_DEBUGCODE(savedCoordChange.fEffectRef.reset(NULL);) } + /** + * Used when storing a deferred GrDrawState. The DeferredStage allows resources owned by its + * GrEffect to be recycled through the cache. + */ + class DeferredStage { + public: + DeferredStage() : fEffect(NULL) { + SkDEBUGCODE(fInitialized = false;) + } + + void saveFrom(const GrEffectStage& stage) { + GrAssert(!fInitialized); + if (NULL != stage.fEffectRef) { + stage.fEffectRef->get()->addRef(); + fEffect = stage.fEffectRef->get(); + fCoordChangeMatrix = stage.fCoordChangeMatrix; + } + SkDEBUGCODE(fInitialized = true;) + } + + void restoreTo(GrEffectStage* stage) { + GrAssert(fInitialized); + const GrEffectRef* oldEffectRef = stage->fEffectRef; + if (NULL != fEffect) { + stage->fEffectRef = GrEffect::CreateEffectRef(fEffect); + stage->fCoordChangeMatrix = fCoordChangeMatrix; + } else { + stage->fEffectRef = NULL; + } + SkSafeUnref(oldEffectRef); + } + + bool isEqual(const GrEffectStage& stage) const { + if (NULL == stage.fEffectRef) { + return NULL == fEffect; + } else if (NULL == fEffect) { + return false; + } + + if (!(*stage.getEffect())->isEqual(*fEffect)) { + return false; + } + + return fCoordChangeMatrix == stage.fCoordChangeMatrix; + } + + ~DeferredStage() { + if (NULL != fEffect) { + fEffect->subRef(); + } + } + private: + const GrEffect* fEffect; + SkMatrix fCoordChangeMatrix; + SkDEBUGCODE(bool fInitialized;) + }; + /** * Gets the matrix representing all changes of coordinate system since the GrEffect was * installed in the stage. -- cgit v1.2.3