aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/gpu/GrEffectStage.h
diff options
context:
space:
mode:
authorGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-01-23 18:29:21 +0000
committerGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-01-23 18:29:21 +0000
commitbcede394ee5e1b5d10dbb149d69a3ad8b8f2cd3c (patch)
tree0a929142c8c462a8485c7bf7aeb20878498a1d33 /include/gpu/GrEffectStage.h
parentc13ee606d82b3847c7ad09cbbc6d21fab46bdcc7 (diff)
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
Diffstat (limited to 'include/gpu/GrEffectStage.h')
-rw-r--r--include/gpu/GrEffectStage.h58
1 files changed, 57 insertions, 1 deletions
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;)
@@ -96,6 +95,63 @@ public:
}
/**
+ * 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.
*/