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

Side by Side Diff: src/record/SkRecords.h

Issue 248053008: Proof of adoption in SkRecord::replace. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 8 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 | « src/record/SkRecordOpts.cpp ('k') | no next file » | 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 SkRecords_DEFINED 8 #ifndef SkRecords_DEFINED
9 #define SkRecords_DEFINED 9 #define SkRecords_DEFINED
10 10
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 ACT_AS_PTR(fPtr); 126 ACT_AS_PTR(fPtr);
127 private: 127 private:
128 T* fPtr; 128 T* fPtr;
129 }; 129 };
130 130
131 // Like Optional, but ptr must not be NULL. 131 // Like Optional, but ptr must not be NULL.
132 template <typename T> 132 template <typename T>
133 class Adopted : SkNoncopyable { 133 class Adopted : SkNoncopyable {
134 public: 134 public:
135 Adopted(T* ptr) : fPtr(ptr) { SkASSERT(fPtr); } 135 Adopted(T* ptr) : fPtr(ptr) { SkASSERT(fPtr); }
136 ~Adopted() { fPtr->~T(); } 136 Adopted(Adopted* source) {
137 // Transfer ownership from source to this.
138 fPtr = source->fPtr;
139 source->fPtr = NULL;
140 }
141 ~Adopted() { if (fPtr) fPtr->~T(); }
137 142
138 ACT_AS_PTR(fPtr); 143 ACT_AS_PTR(fPtr);
139 private: 144 private:
140 T* fPtr; 145 T* fPtr;
141 }; 146 };
142 147
143 // PODArray doesn't own the pointer's memory, and we assume the data is POD. 148 // PODArray doesn't own the pointer's memory, and we assume the data is POD.
144 template <typename T> 149 template <typename T>
145 class PODArray : SkNoncopyable { 150 class PODArray {
146 public: 151 public:
147 PODArray(T* ptr) : fPtr(ptr) {} 152 PODArray(T* ptr) : fPtr(ptr) {}
153 // Default copy and assign.
148 154
149 ACT_AS_PTR(fPtr); 155 ACT_AS_PTR(fPtr);
150 private: 156 private:
151 T* fPtr; 157 T* fPtr;
152 }; 158 };
153 159
154 #undef ACT_AS_PTR 160 #undef ACT_AS_PTR
155 161
156 // Like SkBitmap, but deep copies pixels if they're not immutable. 162 // Like SkBitmap, but deep copies pixels if they're not immutable.
157 // Using this, we guarantee the immutability of all bitmaps we record. 163 // Using this, we guarantee the immutability of all bitmaps we record.
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 #undef RECORD0 279 #undef RECORD0
274 #undef RECORD1 280 #undef RECORD1
275 #undef RECORD2 281 #undef RECORD2
276 #undef RECORD3 282 #undef RECORD3
277 #undef RECORD4 283 #undef RECORD4
278 #undef RECORD5 284 #undef RECORD5
279 285
280 } // namespace SkRecords 286 } // namespace SkRecords
281 287
282 #endif//SkRecords_DEFINED 288 #endif//SkRecords_DEFINED
OLDNEW
« no previous file with comments | « src/record/SkRecordOpts.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698