aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/core/SkTLazy.h
diff options
context:
space:
mode:
authorGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-09-13 15:27:18 +0000
committerGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-09-13 15:27:18 +0000
commit8c2fe99ed2c210317786683e8c1f1e86cff0be49 (patch)
tree88ac1a811fb84e37f99ea54bdff3e987745c0c5a /include/core/SkTLazy.h
parentbcb671c82a7341253864cda3a5c46d396402d7fb (diff)
Fix some issues in gpu device with perspective. Add a gm that would have caught them.
Review URL: http://codereview.appspot.com/4994048/ git-svn-id: http://skia.googlecode.com/svn/trunk@2256 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'include/core/SkTLazy.h')
-rw-r--r--include/core/SkTLazy.h23
1 files changed, 15 insertions, 8 deletions
diff --git a/include/core/SkTLazy.h b/include/core/SkTLazy.h
index 752d43bafe..5747da033f 100644
--- a/include/core/SkTLazy.h
+++ b/include/core/SkTLazy.h
@@ -29,14 +29,15 @@ public:
}
SkTLazy(const SkTLazy<T>& src) : fPtr(NULL) {
- const T* ptr = src.get();
- if (ptr) {
- fPtr = new (fStorage) T(*ptr);
+ if (src.isValid()) {
+ fPtr = new (fStorage) T(*src->get());
+ } else {
+ fPtr = NULL;
}
}
~SkTLazy() {
- if (fPtr) {
+ if (this->isValid()) {
fPtr->~T();
}
}
@@ -48,13 +49,13 @@ public:
* always returned.
*/
T* init() {
- if (fPtr) {
+ if (this->isValid()) {
fPtr->~T();
}
fPtr = new (fStorage) T;
return fPtr;
}
-
+
/**
* Copy src into this, and return a pointer to a copy of it. Note this
* will always return the same pointer, so if it is called on a lazy that
@@ -62,19 +63,25 @@ public:
* contents.
*/
T* set(const T& src) {
- if (fPtr) {
+ if (this->isValid()) {
*fPtr = src;
} else {
fPtr = new (fStorage) T(src);
}
return fPtr;
}
+
+ /**
+ * Returns true if a valid object has been initialized in the SkTLazy,
+ * false otherwise.
+ */
+ bool isValid() const { return NULL != fPtr; }
/**
* Returns either NULL, or a copy of the object that was passed to
* set() or the constructor.
*/
- T* get() const { return fPtr; }
+ T* get() const { SkASSERT(this->isValid()); return fPtr; }
private:
T* fPtr; // NULL or fStorage