aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/core/SkTLazy.h
diff options
context:
space:
mode:
authorGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-03-20 17:32:27 +0000
committerGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-03-20 17:32:27 +0000
commitae81d5c4aa1716756b2cfb4c44f27f4dce2716ef (patch)
tree019b5c1b55da3c7da77943f8b93f5cc28da090c2 /include/core/SkTLazy.h
parent723dd790fbef396cd5c6619d0a3656c641b0c3f5 (diff)
Adds local coords to GrEffect system.
Effects can ask the builder for local coords which may or may not be distinct from positions. GrEffectStage tracks changes to relationship between pos and local coords. GrGLEffectMatrix and GrSingleTextureEffect can use either pos or textures as intput coords GrSimpleTextureEffect now allows for an explicit texture coords attribute. Review URL: https://codereview.chromium.org/12531015 git-svn-id: http://skia.googlecode.com/svn/trunk@8264 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'include/core/SkTLazy.h')
-rw-r--r--include/core/SkTLazy.h22
1 files changed, 21 insertions, 1 deletions
diff --git a/include/core/SkTLazy.h b/include/core/SkTLazy.h
index b9052f0d99..1934b5dff9 100644
--- a/include/core/SkTLazy.h
+++ b/include/core/SkTLazy.h
@@ -14,6 +14,9 @@
#include "SkTypes.h"
#include <new>
+template <typename T> class SkTLazy;
+template <typename T> void* operator new(size_t, SkTLazy<T>* lazy);
+
/**
* Efficient way to defer allocating/initializing a class until it is needed
* (if ever).
@@ -44,7 +47,7 @@ public:
/**
* Return a pointer to a default-initialized instance of the class. If a
- * previous instance had been initialzied (either from init() or set()) it
+ * previous instance had been initialized (either from init() or set()) it
* will first be destroyed, so that a freshly initialized instance is
* always returned.
*/
@@ -84,10 +87,27 @@ public:
T* get() const { SkASSERT(this->isValid()); return fPtr; }
private:
+ friend void* operator new<T>(size_t, SkTLazy* lazy);
+
T* fPtr; // NULL or fStorage
char fStorage[sizeof(T)];
};
+// Use the below macro (SkNEW_IN_TLAZY) rather than calling this directly
+template <typename T> void* operator new(size_t, SkTLazy<T>* lazy) {
+ SkASSERT(!lazy->isValid());
+ lazy->fPtr = reinterpret_cast<T*>(lazy->fStorage);
+ return lazy->fPtr;
+}
+
+// Skia doesn't use C++ exceptions but it may be compiled with them enabled. Having an op delete
+// to match the op new silences warnings about missing op delete when a constructor throws an
+// exception.
+template <typename T> void operator delete(void*, SkTLazy<T>) { SK_CRASH(); }
+
+// Use this to construct a T inside an SkTLazy using a non-default constructor.
+#define SkNEW_IN_TLAZY(tlazy_ptr, type_name, args) (new (tlazy_ptr) type_name args)
+
/**
* A helper built on top of SkTLazy to do copy-on-first-write. The object is initialized
* with a const pointer but provides a non-const pointer accessor. The first time the