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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 , fStableID(SkNextPixelRefGenerationID()) | 93 , fStableID(SkNextPixelRefGenerationID()) |
94 #endif | 94 #endif |
95 | 95 |
96 { | 96 { |
97 this->setMutex(NULL); | 97 this->setMutex(NULL); |
98 fRec.zero(); | 98 fRec.zero(); |
99 fLockCount = 0; | 99 fLockCount = 0; |
100 this->needsNewGenID(); | 100 this->needsNewGenID(); |
101 fIsImmutable = false; | 101 fIsImmutable = false; |
102 fPreLocked = false; | 102 fPreLocked = false; |
103 fAddedToCache = false; | 103 fAddedToCache.store(false); |
104 } | 104 } |
105 | 105 |
106 | 106 |
107 SkPixelRef::SkPixelRef(const SkImageInfo& info, SkBaseMutex* mutex) | 107 SkPixelRef::SkPixelRef(const SkImageInfo& info, SkBaseMutex* mutex) |
108 : fInfo(validate_info(info)) | 108 : fInfo(validate_info(info)) |
109 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK | 109 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
110 , fStableID(SkNextPixelRefGenerationID()) | 110 , fStableID(SkNextPixelRefGenerationID()) |
111 #endif | 111 #endif |
112 { | 112 { |
113 this->setMutex(mutex); | 113 this->setMutex(mutex); |
114 fRec.zero(); | 114 fRec.zero(); |
115 fLockCount = 0; | 115 fLockCount = 0; |
116 this->needsNewGenID(); | 116 this->needsNewGenID(); |
117 fIsImmutable = false; | 117 fIsImmutable = false; |
118 fPreLocked = false; | 118 fPreLocked = false; |
119 fAddedToCache = false; | 119 fAddedToCache.store(false); |
120 } | 120 } |
121 | 121 |
122 SkPixelRef::~SkPixelRef() { | 122 SkPixelRef::~SkPixelRef() { |
123 this->callGenIDChangeListeners(); | 123 this->callGenIDChangeListeners(); |
124 } | 124 } |
125 | 125 |
126 void SkPixelRef::needsNewGenID() { | 126 void SkPixelRef::needsNewGenID() { |
127 fGenerationID.store(0); | 127 fGenerationID.store(0); |
128 fUniqueGenerationID.store(false); | 128 fUniqueGenerationID.store(false); |
129 } | 129 } |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 } | 220 } |
221 | 221 |
222 // we need to be called *before* the genID gets changed or zerod | 222 // we need to be called *before* the genID gets changed or zerod |
223 void SkPixelRef::callGenIDChangeListeners() { | 223 void SkPixelRef::callGenIDChangeListeners() { |
224 // We don't invalidate ourselves if we think another SkPixelRef is sharing o
ur genID. | 224 // We don't invalidate ourselves if we think another SkPixelRef is sharing o
ur genID. |
225 if (fUniqueGenerationID.load()) { | 225 if (fUniqueGenerationID.load()) { |
226 for (int i = 0; i < fGenIDChangeListeners.count(); i++) { | 226 for (int i = 0; i < fGenIDChangeListeners.count(); i++) { |
227 fGenIDChangeListeners[i]->onChange(); | 227 fGenIDChangeListeners[i]->onChange(); |
228 } | 228 } |
229 | 229 |
230 if (fAddedToCache) { | 230 // TODO: SkAtomic could add "old_value = atomic.xchg(new_value)" to make
this clearer. |
| 231 if (fAddedToCache.load()) { |
231 SkNotifyBitmapGenIDIsStale(this->getGenerationID()); | 232 SkNotifyBitmapGenIDIsStale(this->getGenerationID()); |
232 fAddedToCache = false; | 233 fAddedToCache.store(false); |
233 } | 234 } |
234 } | 235 } |
235 // Listeners get at most one shot, so whether these triggered or not, blow t
hem away. | 236 // Listeners get at most one shot, so whether these triggered or not, blow t
hem away. |
236 fGenIDChangeListeners.deleteAll(); | 237 fGenIDChangeListeners.deleteAll(); |
237 } | 238 } |
238 | 239 |
239 void SkPixelRef::notifyPixelsChanged() { | 240 void SkPixelRef::notifyPixelsChanged() { |
240 #ifdef SK_DEBUG | 241 #ifdef SK_DEBUG |
241 if (fIsImmutable) { | 242 if (fIsImmutable) { |
242 SkDebugf("========== notifyPixelsChanged called on immutable pixelref"); | 243 SkDebugf("========== notifyPixelsChanged called on immutable pixelref"); |
(...skipping 25 matching lines...) Expand all Loading... |
268 | 269 |
269 bool SkPixelRef::onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBy
tes[3], | 270 bool SkPixelRef::onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBy
tes[3], |
270 SkYUVColorSpace* colorSpace) { | 271 SkYUVColorSpace* colorSpace) { |
271 return false; | 272 return false; |
272 } | 273 } |
273 | 274 |
274 size_t SkPixelRef::getAllocatedSizeInBytes() const { | 275 size_t SkPixelRef::getAllocatedSizeInBytes() const { |
275 return 0; | 276 return 0; |
276 } | 277 } |
277 | 278 |
OLD | NEW |