| 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" | |
| 9 #include "SkPixelRef.h" | 8 #include "SkPixelRef.h" |
| 10 #include "SkThread.h" | 9 #include "SkThread.h" |
| 11 | 10 |
| 12 #ifdef SK_BUILD_FOR_WIN32 | 11 #ifdef SK_BUILD_FOR_WIN32 |
| 13 // We don't have SK_BASE_MUTEX_INIT on Windows. | 12 // We don't have SK_BASE_MUTEX_INIT on Windows. |
| 14 | 13 |
| 15 // must be a power-of-2. undef to just use 1 mutex | 14 // must be a power-of-2. undef to just use 1 mutex |
| 16 #define PIXELREF_MUTEX_RING_COUNT 32 | 15 #define PIXELREF_MUTEX_RING_COUNT 32 |
| 17 static SkBaseMutex gPixelRefMutexRing[PIXELREF_MUTEX_RING_COUNT]; | 16 static SkBaseMutex gPixelRefMutexRing[PIXELREF_MUTEX_RING_COUNT]; |
| 18 | 17 |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 | 215 |
| 217 void SkPixelRef::addGenIDChangeListener(GenIDChangeListener* listener) { | 216 void SkPixelRef::addGenIDChangeListener(GenIDChangeListener* listener) { |
| 218 if (NULL == listener || !fUniqueGenerationID) { | 217 if (NULL == listener || !fUniqueGenerationID) { |
| 219 // No point in tracking this if we're not going to call it. | 218 // No point in tracking this if we're not going to call it. |
| 220 SkDELETE(listener); | 219 SkDELETE(listener); |
| 221 return; | 220 return; |
| 222 } | 221 } |
| 223 *fGenIDChangeListeners.append() = listener; | 222 *fGenIDChangeListeners.append() = listener; |
| 224 } | 223 } |
| 225 | 224 |
| 226 // we need to be called *before* the genID gets changed or zerod | |
| 227 void SkPixelRef::callGenIDChangeListeners() { | 225 void SkPixelRef::callGenIDChangeListeners() { |
| 228 // We don't invalidate ourselves if we think another SkPixelRef is sharing o
ur genID. | 226 // We don't invalidate ourselves if we think another SkPixelRef is sharing o
ur genID. |
| 229 if (fUniqueGenerationID) { | 227 if (fUniqueGenerationID) { |
| 230 for (int i = 0; i < fGenIDChangeListeners.count(); i++) { | 228 for (int i = 0; i < fGenIDChangeListeners.count(); i++) { |
| 231 fGenIDChangeListeners[i]->onChange(); | 229 fGenIDChangeListeners[i]->onChange(); |
| 232 } | 230 } |
| 233 } | 231 } |
| 234 // Listeners get at most one shot, so whether these triggered or not, blow t
hem away. | 232 // Listeners get at most one shot, so whether these triggered or not, blow t
hem away. |
| 235 fGenIDChangeListeners.deleteAll(); | 233 fGenIDChangeListeners.deleteAll(); |
| 236 | |
| 237 // if fGenerationID is 0, then perhaps we never had one, and we are in the d
estructor | |
| 238 if (fGenerationID) { | |
| 239 // If the ResourceCache ever generalizes/standardizes on accessing the g
en-id field, | |
| 240 // then it would be more efficient to roll these together, and only grab
the mutex | |
| 241 // and fixing the resources once... | |
| 242 SkBitmapCache::NotifyGenIDStale(fGenerationID); | |
| 243 SkMipMapCache::NotifyGenIDStale(fGenerationID); | |
| 244 } | |
| 245 } | 234 } |
| 246 | 235 |
| 247 void SkPixelRef::notifyPixelsChanged() { | 236 void SkPixelRef::notifyPixelsChanged() { |
| 248 #ifdef SK_DEBUG | 237 #ifdef SK_DEBUG |
| 249 if (fIsImmutable) { | 238 if (fIsImmutable) { |
| 250 SkDebugf("========== notifyPixelsChanged called on immutable pixelref"); | 239 SkDebugf("========== notifyPixelsChanged called on immutable pixelref"); |
| 251 } | 240 } |
| 252 #endif | 241 #endif |
| 253 this->callGenIDChangeListeners(); | 242 this->callGenIDChangeListeners(); |
| 254 this->needsNewGenID(); | 243 this->needsNewGenID(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 276 | 265 |
| 277 bool SkPixelRef::onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBy
tes[3], | 266 bool SkPixelRef::onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBy
tes[3], |
| 278 SkYUVColorSpace* colorSpace) { | 267 SkYUVColorSpace* colorSpace) { |
| 279 return false; | 268 return false; |
| 280 } | 269 } |
| 281 | 270 |
| 282 size_t SkPixelRef::getAllocatedSizeInBytes() const { | 271 size_t SkPixelRef::getAllocatedSizeInBytes() const { |
| 283 return 0; | 272 return 0; |
| 284 } | 273 } |
| 285 | 274 |
| OLD | NEW |