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

Side by Side Diff: src/core/SkPixelRef.cpp

Issue 955803002: SkTRacy<T> -> SkAtomic<T> (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: great warning Created 5 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 unified diff | Download patch
« no previous file with comments | « include/core/SkPixelRef.h ('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 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 #include "SkBitmapCache.h" 8 #include "SkBitmapCache.h"
9 #include "SkPixelRef.h" 9 #include "SkPixelRef.h"
10 #include "SkThread.h" 10 #include "SkThread.h"
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 this->needsNewGenID(); 115 this->needsNewGenID();
116 fIsImmutable = false; 116 fIsImmutable = false;
117 fPreLocked = false; 117 fPreLocked = false;
118 } 118 }
119 119
120 SkPixelRef::~SkPixelRef() { 120 SkPixelRef::~SkPixelRef() {
121 this->callGenIDChangeListeners(); 121 this->callGenIDChangeListeners();
122 } 122 }
123 123
124 void SkPixelRef::needsNewGenID() { 124 void SkPixelRef::needsNewGenID() {
125 fGenerationID = 0; 125 fGenerationID.store(0);
Alexander Potapenko 2015/03/10 09:55:20 Perhaps the sk_memory_order_acquire and sk_memory_
mtklein 2015/03/10 13:33:11 Yep, I think acquire-release is enough too. So fa
126 fUniqueGenerationID = false; 126 fUniqueGenerationID.store(false);
127 } 127 }
128 128
129 void SkPixelRef::cloneGenID(const SkPixelRef& that) { 129 void SkPixelRef::cloneGenID(const SkPixelRef& that) {
130 // This is subtle. We must call that.getGenerationID() to make sure its gen ID isn't 0. 130 // This is subtle. We must call that.getGenerationID() to make sure its gen ID isn't 0.
131 this->fGenerationID = that.getGenerationID(); 131 this->fGenerationID.store(that.getGenerationID());
132 this->fUniqueGenerationID = false; 132 this->fUniqueGenerationID.store(false);
133 that.fUniqueGenerationID = false; 133 that.fUniqueGenerationID.store(false);
134 } 134 }
135 135
136 void SkPixelRef::setPreLocked(void* pixels, size_t rowBytes, SkColorTable* ctabl e) { 136 void SkPixelRef::setPreLocked(void* pixels, size_t rowBytes, SkColorTable* ctabl e) {
137 #ifndef SK_IGNORE_PIXELREF_SETPRELOCKED 137 #ifndef SK_IGNORE_PIXELREF_SETPRELOCKED
138 // only call me in your constructor, otherwise fLockCount tracking can get 138 // only call me in your constructor, otherwise fLockCount tracking can get
139 // out of sync. 139 // out of sync.
140 fRec.fPixels = pixels; 140 fRec.fPixels = pixels;
141 fRec.fColorTable = ctable; 141 fRec.fColorTable = ctable;
142 fRec.fRowBytes = rowBytes; 142 fRec.fRowBytes = rowBytes;
143 fLockCount = SKPIXELREF_PRELOCKED_LOCKCOUNT; 143 fLockCount = SKPIXELREF_PRELOCKED_LOCKCOUNT;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 192
193 bool SkPixelRef::lockPixelsAreWritable() const { 193 bool SkPixelRef::lockPixelsAreWritable() const {
194 return this->onLockPixelsAreWritable(); 194 return this->onLockPixelsAreWritable();
195 } 195 }
196 196
197 bool SkPixelRef::onLockPixelsAreWritable() const { 197 bool SkPixelRef::onLockPixelsAreWritable() const {
198 return true; 198 return true;
199 } 199 }
200 200
201 uint32_t SkPixelRef::getGenerationID() const { 201 uint32_t SkPixelRef::getGenerationID() const {
202 if (0 == fGenerationID) { 202 uint32_t id = fGenerationID.load();
203 fGenerationID = SkNextPixelRefGenerationID(); 203 if (0 == id) {
204 fUniqueGenerationID = true; // The only time we can be sure of this! 204 id = SkNextPixelRefGenerationID();
205 fGenerationID.store(id);
206 fUniqueGenerationID.store(true); // The only time we can be sure of thi s!
205 } 207 }
206 return fGenerationID; 208 return id;
207 } 209 }
208 210
209 void SkPixelRef::addGenIDChangeListener(GenIDChangeListener* listener) { 211 void SkPixelRef::addGenIDChangeListener(GenIDChangeListener* listener) {
210 if (NULL == listener || !fUniqueGenerationID) { 212 if (NULL == listener || !fUniqueGenerationID.load()) {
211 // No point in tracking this if we're not going to call it. 213 // No point in tracking this if we're not going to call it.
212 SkDELETE(listener); 214 SkDELETE(listener);
213 return; 215 return;
214 } 216 }
215 *fGenIDChangeListeners.append() = listener; 217 *fGenIDChangeListeners.append() = listener;
216 } 218 }
217 219
218 // we need to be called *before* the genID gets changed or zerod 220 // we need to be called *before* the genID gets changed or zerod
219 void SkPixelRef::callGenIDChangeListeners() { 221 void SkPixelRef::callGenIDChangeListeners() {
220 // We don't invalidate ourselves if we think another SkPixelRef is sharing o ur genID. 222 // We don't invalidate ourselves if we think another SkPixelRef is sharing o ur genID.
221 if (fUniqueGenerationID) { 223 if (fUniqueGenerationID.load()) {
222 for (int i = 0; i < fGenIDChangeListeners.count(); i++) { 224 for (int i = 0; i < fGenIDChangeListeners.count(); i++) {
223 fGenIDChangeListeners[i]->onChange(); 225 fGenIDChangeListeners[i]->onChange();
224 } 226 }
225 227
226 // If we can flag the pixelref somehow whenever it was actually added to the cache, 228 // If we can flag the pixelref somehow whenever it was actually added to the cache,
227 // perhaps it would be nice to only call this notifier in that case. For now we always 229 // perhaps it would be nice to only call this notifier in that case. For now we always
228 // call it, since we don't know if it was cached or not. 230 // call it, since we don't know if it was cached or not.
229 SkNotifyBitmapGenIDIsStale(fGenerationID); 231 SkNotifyBitmapGenIDIsStale(this->getGenerationID());
230 } 232 }
231 // Listeners get at most one shot, so whether these triggered or not, blow t hem away. 233 // Listeners get at most one shot, so whether these triggered or not, blow t hem away.
232 fGenIDChangeListeners.deleteAll(); 234 fGenIDChangeListeners.deleteAll();
233 } 235 }
234 236
235 void SkPixelRef::notifyPixelsChanged() { 237 void SkPixelRef::notifyPixelsChanged() {
236 #ifdef SK_DEBUG 238 #ifdef SK_DEBUG
237 if (fIsImmutable) { 239 if (fIsImmutable) {
238 SkDebugf("========== notifyPixelsChanged called on immutable pixelref"); 240 SkDebugf("========== notifyPixelsChanged called on immutable pixelref");
239 } 241 }
(...skipping 24 matching lines...) Expand all
264 266
265 bool SkPixelRef::onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBy tes[3], 267 bool SkPixelRef::onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBy tes[3],
266 SkYUVColorSpace* colorSpace) { 268 SkYUVColorSpace* colorSpace) {
267 return false; 269 return false;
268 } 270 }
269 271
270 size_t SkPixelRef::getAllocatedSizeInBytes() const { 272 size_t SkPixelRef::getAllocatedSizeInBytes() const {
271 return 0; 273 return 0;
272 } 274 }
273 275
OLDNEW
« no previous file with comments | « include/core/SkPixelRef.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698