| 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.store(false); | 103 fAddedToCache = 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.store(false); | 119 fAddedToCache = 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 // TODO: SkAtomic could add "old_value = atomic.xchg(new_value)" to make
this clearer. | 230 if (fAddedToCache) { |
| 231 if (fAddedToCache.load()) { | |
| 232 SkNotifyBitmapGenIDIsStale(this->getGenerationID()); | 231 SkNotifyBitmapGenIDIsStale(this->getGenerationID()); |
| 233 fAddedToCache.store(false); | 232 fAddedToCache = false; |
| 234 } | 233 } |
| 235 } | 234 } |
| 236 // Listeners get at most one shot, so whether these triggered or not, blow t
hem away. | 235 // Listeners get at most one shot, so whether these triggered or not, blow t
hem away. |
| 237 fGenIDChangeListeners.deleteAll(); | 236 fGenIDChangeListeners.deleteAll(); |
| 238 } | 237 } |
| 239 | 238 |
| 240 void SkPixelRef::notifyPixelsChanged() { | 239 void SkPixelRef::notifyPixelsChanged() { |
| 241 #ifdef SK_DEBUG | 240 #ifdef SK_DEBUG |
| 242 if (fIsImmutable) { | 241 if (fIsImmutable) { |
| 243 SkDebugf("========== notifyPixelsChanged called on immutable pixelref"); | 242 SkDebugf("========== notifyPixelsChanged called on immutable pixelref"); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 269 | 268 |
| 270 bool SkPixelRef::onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBy
tes[3], | 269 bool SkPixelRef::onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBy
tes[3], |
| 271 SkYUVColorSpace* colorSpace) { | 270 SkYUVColorSpace* colorSpace) { |
| 272 return false; | 271 return false; |
| 273 } | 272 } |
| 274 | 273 |
| 275 size_t SkPixelRef::getAllocatedSizeInBytes() const { | 274 size_t SkPixelRef::getAllocatedSizeInBytes() const { |
| 276 return 0; | 275 return 0; |
| 277 } | 276 } |
| 278 | 277 |
| OLD | NEW |