From 8c2fe99ed2c210317786683e8c1f1e86cff0be49 Mon Sep 17 00:00:00 2001 From: "bsalomon@google.com" Date: Tue, 13 Sep 2011 15:27:18 +0000 Subject: 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 --- include/core/SkTLazy.h | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'include/core/SkTLazy.h') 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& 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 -- cgit v1.2.3