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

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

Issue 1266883002: unify pixelref and image ID space, so we can share IDs when we share pixels (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 4 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/core/SkNextID.h ('k') | src/image/SkImage.cpp » ('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 #include "SkBitmapCache.h" 8 #include "SkBitmapCache.h"
9 #include "SkMutex.h" 9 #include "SkMutex.h"
10 #include "SkPixelRef.h" 10 #include "SkPixelRef.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 52
53 SkASSERT(SkIsPow2(PIXELREF_MUTEX_RING_COUNT)); 53 SkASSERT(SkIsPow2(PIXELREF_MUTEX_RING_COUNT));
54 54
55 // atomic_inc might be overkill here. It may be fine if once in a while 55 // atomic_inc might be overkill here. It may be fine if once in a while
56 // we hit a race-condition and two subsequent calls get the same index... 56 // we hit a race-condition and two subsequent calls get the same index...
57 int index = sk_atomic_inc(&gPixelRefMutexRingIndex); 57 int index = sk_atomic_inc(&gPixelRefMutexRingIndex);
58 return &gPixelRefMutexRing[index & (PIXELREF_MUTEX_RING_COUNT - 1)]; 58 return &gPixelRefMutexRing[index & (PIXELREF_MUTEX_RING_COUNT - 1)];
59 } 59 }
60 60
61 /////////////////////////////////////////////////////////////////////////////// 61 ///////////////////////////////////////////////////////////////////////////////
62 #include "SkNextID.h"
62 63
63 static uint32_t next_gen_id() { 64 uint32_t SkNextID::ImageID() {
64 static uint32_t gNextGenID = 0; 65 static uint32_t gID = 0;
65 uint32_t genID; 66 uint32_t id;
66 // Loop in case our global wraps around, as we never want to return a 0. 67 // Loop in case our global wraps around, as we never want to return a 0.
67 do { 68 do {
68 genID = sk_atomic_fetch_add(&gNextGenID, 2u) + 2; // Never set the low bit. 69 id = sk_atomic_fetch_add(&gID, 2u) + 2; // Never set the low bit.
69 } while (0 == genID); 70 } while (0 == id);
70 return genID; 71 return id;
71 } 72 }
72 73
73 /////////////////////////////////////////////////////////////////////////////// 74 ///////////////////////////////////////////////////////////////////////////////
74 75
75 void SkPixelRef::setMutex(SkBaseMutex* mutex) { 76 void SkPixelRef::setMutex(SkBaseMutex* mutex) {
76 if (NULL == mutex) { 77 if (NULL == mutex) {
77 mutex = get_default_mutex(); 78 mutex = get_default_mutex();
78 } 79 }
79 fMutex = mutex; 80 fMutex = mutex;
80 } 81 }
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 return this->onLockPixelsAreWritable(); 294 return this->onLockPixelsAreWritable();
294 } 295 }
295 296
296 bool SkPixelRef::onLockPixelsAreWritable() const { 297 bool SkPixelRef::onLockPixelsAreWritable() const {
297 return true; 298 return true;
298 } 299 }
299 300
300 uint32_t SkPixelRef::getGenerationID() const { 301 uint32_t SkPixelRef::getGenerationID() const {
301 uint32_t id = fTaggedGenID.load(); 302 uint32_t id = fTaggedGenID.load();
302 if (0 == id) { 303 if (0 == id) {
303 uint32_t next = next_gen_id() | 1u; 304 uint32_t next = SkNextID::ImageID() | 1u;
304 if (fTaggedGenID.compare_exchange(&id, next)) { 305 if (fTaggedGenID.compare_exchange(&id, next)) {
305 id = next; // There was no race or we won the race. fTaggedGenID i s next now. 306 id = next; // There was no race or we won the race. fTaggedGenID i s next now.
306 } else { 307 } else {
307 // We lost a race to set fTaggedGenID. compare_exchange() filled id with the winner. 308 // We lost a race to set fTaggedGenID. compare_exchange() filled id with the winner.
308 } 309 }
309 // We can't quite SkASSERT(this->genIDIsUnique()). It could be non-uniqu e 310 // We can't quite SkASSERT(this->genIDIsUnique()). It could be non-uniqu e
310 // if we got here via the else path (pretty unlikely, but possible). 311 // if we got here via the else path (pretty unlikely, but possible).
311 } 312 }
312 return id & ~1u; // Mask off bottom unique bit. 313 return id & ~1u; // Mask off bottom unique bit.
313 } 314 }
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 } 405 }
405 406
406 result->fUnlockProc = unlock_legacy_result; 407 result->fUnlockProc = unlock_legacy_result;
407 result->fUnlockContext = SkRef(this); // this is balanced in our fUnlockPr oc 408 result->fUnlockContext = SkRef(this); // this is balanced in our fUnlockPr oc
408 result->fCTable = fRec.fColorTable; 409 result->fCTable = fRec.fColorTable;
409 result->fPixels = fRec.fPixels; 410 result->fPixels = fRec.fPixels;
410 result->fRowBytes = fRec.fRowBytes; 411 result->fRowBytes = fRec.fRowBytes;
411 result->fSize.set(fInfo.width(), fInfo.height()); 412 result->fSize.set(fInfo.width(), fInfo.height());
412 return true; 413 return true;
413 } 414 }
OLDNEW
« no previous file with comments | « src/core/SkNextID.h ('k') | src/image/SkImage.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698