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

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

Issue 676523002: Add SkTypeface::getBounds() (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 1 month 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 | « gm/fontmgr.cpp ('k') | include/core/SkThreadPriv.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 2014 Google Inc. 2 * Copyright 2014 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 SkLazyPtr_DEFINED 8 #ifndef SkLazyPtr_DEFINED
9 #define SkLazyPtr_DEFINED 9 #define SkLazyPtr_DEFINED
10 10
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 // - it has a constructor to zero itself; 140 // - it has a constructor to zero itself;
141 // - it has a destructor to clean up; 141 // - it has a destructor to clean up;
142 // - get() calls SkNew(T) to create the pointer; 142 // - get() calls SkNew(T) to create the pointer;
143 // - get(functor) calls functor to create the pointer. 143 // - get(functor) calls functor to create the pointer.
144 template <typename T, void (*Destroy)(T*) = Private::sk_delete<T> > 144 template <typename T, void (*Destroy)(T*) = Private::sk_delete<T> >
145 class SkLazyPtr : SkNoncopyable { 145 class SkLazyPtr : SkNoncopyable {
146 public: 146 public:
147 SkLazyPtr() : fPtr(NULL) {} 147 SkLazyPtr() : fPtr(NULL) {}
148 ~SkLazyPtr() { if (fPtr) { Destroy((T*)fPtr); } } 148 ~SkLazyPtr() { if (fPtr) { Destroy((T*)fPtr); } }
149 149
150 T* get() { 150 T* get() const {
151 T* ptr = (T*)sk_consume_load(&fPtr); 151 T* ptr = (T*)sk_consume_load(&fPtr);
152 return ptr ? ptr : Private::try_cas<T*, Destroy>(&fPtr, SkNEW(T)); 152 return ptr ? ptr : Private::try_cas<T*, Destroy>(&fPtr, SkNEW(T));
153 } 153 }
154 154
155 template <typename Create> 155 template <typename Create>
156 T* get(const Create& create) { 156 T* get(const Create& create) const {
157 T* ptr = (T*)sk_consume_load(&fPtr); 157 T* ptr = (T*)sk_consume_load(&fPtr);
158 return ptr ? ptr : Private::try_cas<T*, Destroy>(&fPtr, create()); 158 return ptr ? ptr : Private::try_cas<T*, Destroy>(&fPtr, create());
159 } 159 }
160 160
161 private: 161 private:
162 void* fPtr; 162 mutable void* fPtr;
163 }; 163 };
164 164
165 165
166 #endif//SkLazyPtr_DEFINED 166 #endif//SkLazyPtr_DEFINED
OLDNEW
« no previous file with comments | « gm/fontmgr.cpp ('k') | include/core/SkThreadPriv.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698