OLD | NEW |
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 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 return this->onLockPixelsAreWritable(); | 200 return this->onLockPixelsAreWritable(); |
201 } | 201 } |
202 | 202 |
203 bool SkPixelRef::onLockPixelsAreWritable() const { | 203 bool SkPixelRef::onLockPixelsAreWritable() const { |
204 return true; | 204 return true; |
205 } | 205 } |
206 | 206 |
207 uint32_t SkPixelRef::getGenerationID() const { | 207 uint32_t SkPixelRef::getGenerationID() const { |
208 uint32_t id = fTaggedGenID.load(); | 208 uint32_t id = fTaggedGenID.load(); |
209 if (0 == id) { | 209 if (0 == id) { |
210 id = next_gen_id(); | 210 uint32_t next = next_gen_id() | 1u; |
211 fTaggedGenID.store(id | 1u); // TODO(mtklein): should become a compare-
and-swap | 211 if (fTaggedGenID.compare_exchange(&id, next)) { |
212 SkASSERT(this->genIDIsUnique()); | 212 id = next; // There was no race or we won the race. fTaggedGenID i
s next now. |
| 213 } else { |
| 214 // We lost a race to set fTaggedGenID. compare_exchange() filled id
with the winner. |
| 215 } |
| 216 // We can't quite SkASSERT(this->genIDIsUnique()). It could be non-uniqu
e |
| 217 // if we got here via the else path (pretty unlikely, but possible). |
213 } | 218 } |
214 return id & ~1u; // Mask off bottom unique bit. | 219 return id & ~1u; // Mask off bottom unique bit. |
215 } | 220 } |
216 | 221 |
217 void SkPixelRef::addGenIDChangeListener(GenIDChangeListener* listener) { | 222 void SkPixelRef::addGenIDChangeListener(GenIDChangeListener* listener) { |
218 if (NULL == listener || !this->genIDIsUnique()) { | 223 if (NULL == listener || !this->genIDIsUnique()) { |
219 // No point in tracking this if we're not going to call it. | 224 // No point in tracking this if we're not going to call it. |
220 SkDELETE(listener); | 225 SkDELETE(listener); |
221 return; | 226 return; |
222 } | 227 } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 | 278 |
274 bool SkPixelRef::onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBy
tes[3], | 279 bool SkPixelRef::onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBy
tes[3], |
275 SkYUVColorSpace* colorSpace) { | 280 SkYUVColorSpace* colorSpace) { |
276 return false; | 281 return false; |
277 } | 282 } |
278 | 283 |
279 size_t SkPixelRef::getAllocatedSizeInBytes() const { | 284 size_t SkPixelRef::getAllocatedSizeInBytes() const { |
280 return 0; | 285 return 0; |
281 } | 286 } |
282 | 287 |
OLD | NEW |