Index: src/gpu/GrDrawTarget.cpp |
diff --git a/src/gpu/GrDrawTarget.cpp b/src/gpu/GrDrawTarget.cpp |
index aa475b3ee6855dfe48e1491cb245877c656055ba..02bc8d740b92849bc3f2e960ede9d62b33af7d63 100644 |
--- a/src/gpu/GrDrawTarget.cpp |
+++ b/src/gpu/GrDrawTarget.cpp |
@@ -657,9 +657,10 @@ GrDrawTarget::AutoStateRestore::AutoStateRestore() { |
} |
GrDrawTarget::AutoStateRestore::AutoStateRestore(GrDrawTarget* target, |
- ASRInit init) { |
+ ASRInit init, |
+ const SkMatrix* vm) { |
fDrawTarget = NULL; |
- this->set(target, init); |
+ this->set(target, init, vm); |
} |
GrDrawTarget::AutoStateRestore::~AutoStateRestore() { |
@@ -669,7 +670,31 @@ GrDrawTarget::AutoStateRestore::~AutoStateRestore() { |
} |
} |
-void GrDrawTarget::AutoStateRestore::set(GrDrawTarget* target, ASRInit init) { |
+void GrDrawTarget::AutoStateRestore::set(GrDrawTarget* target, ASRInit init, const SkMatrix* vm) { |
+ GrAssert(NULL == fDrawTarget); |
+ fDrawTarget = target; |
+ fSavedState = target->drawState(); |
+ GrAssert(fSavedState); |
+ fSavedState->ref(); |
+ if (kReset_ASRInit == init) { |
+ if (NULL == vm) { |
+ // calls the default cons |
+ fTempState.init(); |
+ } else { |
+ SkNEW_IN_TLAZY(&fTempState, GrDrawState, (*vm)); |
+ } |
+ } else { |
+ GrAssert(kPreserve_ASRInit == init); |
+ if (NULL == vm) { |
+ fTempState.set(*fSavedState); |
+ } else { |
+ SkNEW_IN_TLAZY(&fTempState, GrDrawState, (*fSavedState, *vm)); |
+ } |
+ } |
+ target->setDrawState(fTempState.get()); |
+} |
+ |
+bool GrDrawTarget::AutoStateRestore::setIdentity(GrDrawTarget* target, ASRInit init) { |
GrAssert(NULL == fDrawTarget); |
fDrawTarget = target; |
fSavedState = target->drawState(); |
@@ -682,8 +707,17 @@ void GrDrawTarget::AutoStateRestore::set(GrDrawTarget* target, ASRInit init) { |
GrAssert(kPreserve_ASRInit == init); |
// calls the copy cons |
fTempState.set(*fSavedState); |
+ if (!fTempState.get()->setIdentityViewMatrix()) { |
+ // let go of any resources held by the temp |
+ fTempState.get()->reset(); |
+ fDrawTarget = NULL; |
+ fSavedState->unref(); |
+ fSavedState = NULL; |
+ return false; |
+ } |
} |
target->setDrawState(fTempState.get()); |
+ return true; |
} |
//////////////////////////////////////////////////////////////////////////////// |