aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core
diff options
context:
space:
mode:
authorGravatar Mike Reed <reed@google.com>2017-03-10 11:30:44 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-03-13 15:44:16 +0000
commitf880b683048b5098e1e62b534902376626ffabac (patch)
treec243e634c743bd87ae16355741d721a7a4c4e4d6 /src/core
parent52fe583a7b21ee1cb04e95b05db9946be899b26d (diff)
use AutoRestore instead of making a copy of the clipstack
BUG=skia: Change-Id: I86683156926f7c63c83790eaf313112ba5fab763 Reviewed-on: https://skia-review.googlesource.com/9532 Reviewed-by: Florin Malita <fmalita@chromium.org> Commit-Queue: Mike Reed <reed@google.com>
Diffstat (limited to 'src/core')
-rw-r--r--src/core/SkClipStack.h21
-rw-r--r--src/core/SkClipStackDevice.h2
2 files changed, 22 insertions, 1 deletions
diff --git a/src/core/SkClipStack.h b/src/core/SkClipStack.h
index e889208f47..9360f4de33 100644
--- a/src/core/SkClipStack.h
+++ b/src/core/SkClipStack.h
@@ -341,6 +341,27 @@ public:
void save();
void restore();
+ class AutoRestore {
+ public:
+ AutoRestore(SkClipStack* cs, bool doSave)
+ : fCS(cs), fSaveCount(cs->getSaveCount())
+ {
+ if (doSave) {
+ fCS->save();
+ }
+ }
+ ~AutoRestore() {
+ SkASSERT(fCS->getSaveCount() >= fSaveCount); // no underflow
+ while (fCS->getSaveCount() > fSaveCount) {
+ fCS->restore();
+ }
+ }
+
+ private:
+ SkClipStack* fCS;
+ const int fSaveCount;
+ };
+
/**
* getBounds places the current finite bound in its first parameter. In its
* second, it indicates which kind of bound is being returned. If
diff --git a/src/core/SkClipStackDevice.h b/src/core/SkClipStackDevice.h
index 1dd321d820..916aaf8455 100644
--- a/src/core/SkClipStackDevice.h
+++ b/src/core/SkClipStackDevice.h
@@ -18,7 +18,7 @@ public:
, fClipStack(fStorage, sizeof(fStorage))
{}
- const SkClipStack& cs() const { return fClipStack; }
+ SkClipStack& cs() { return fClipStack; }
SkIRect devClipBounds() const;