Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Unified Diff: include/core/SkTLazy.h

Issue 12531015: Adds local coords to GrEffect system. (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | include/gpu/GrBackendEffectFactory.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/core/SkTLazy.h
===================================================================
--- include/core/SkTLazy.h (revision 8241)
+++ include/core/SkTLazy.h (working copy)
@@ -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 @@
/**
* 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 @@
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
« no previous file with comments | « no previous file | include/gpu/GrBackendEffectFactory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698