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

Side by Side Diff: include/core/SkTLazy.h

Issue 1576183002: SkTCopyOnFirstWrite-based SkPaintFilterCanvas API (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: minor cleanup Created 4 years, 11 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 unified diff | Download patch
« no previous file with comments | « no previous file | include/utils/SkPaintFilterCanvas.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #ifndef SkTLazy_DEFINED 8 #ifndef SkTLazy_DEFINED
9 #define SkTLazy_DEFINED 9 #define SkTLazy_DEFINED
10 10
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 * thing.writable()->changeMe(); // makes a copy of constThing if we didn't c all modifyMe() 124 * thing.writable()->changeMe(); // makes a copy of constThing if we didn't c all modifyMe()
125 * } 125 * }
126 * 126 *
127 * consume_a_thing(thing); // could be constThing or a modified copy. 127 * consume_a_thing(thing); // could be constThing or a modified copy.
128 */ 128 */
129 template <typename T> 129 template <typename T>
130 class SkTCopyOnFirstWrite { 130 class SkTCopyOnFirstWrite {
131 public: 131 public:
132 SkTCopyOnFirstWrite(const T& initial) : fObj(&initial) {} 132 SkTCopyOnFirstWrite(const T& initial) : fObj(&initial) {}
133 133
134 SkTCopyOnFirstWrite(const T* initial) : fObj(initial) {}
135
134 // Constructor for delayed initialization. 136 // Constructor for delayed initialization.
135 SkTCopyOnFirstWrite() : fObj(NULL) {} 137 SkTCopyOnFirstWrite() : fObj(NULL) {}
136 138
137 // Should only be called once, and only if the default constructor was used. 139 // Should only be called once, and only if the default constructor was used.
138 void init(const T& initial) { 140 void init(const T& initial) {
139 SkASSERT(NULL == fObj); 141 SkASSERT(NULL == fObj);
140 SkASSERT(!fLazy.isValid()); 142 SkASSERT(!fLazy.isValid());
141 fObj = &initial; 143 fObj = &initial;
142 } 144 }
143 145
(...skipping 18 matching lines...) Expand all
162 operator const T*() const { return fObj; } 164 operator const T*() const { return fObj; }
163 165
164 const T& operator *() const { return *fObj; } 166 const T& operator *() const { return *fObj; }
165 167
166 private: 168 private:
167 const T* fObj; 169 const T* fObj;
168 SkTLazy<T> fLazy; 170 SkTLazy<T> fLazy;
169 }; 171 };
170 172
171 #endif 173 #endif
OLDNEW
« no previous file with comments | « no previous file | include/utils/SkPaintFilterCanvas.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698