Chromium Code Reviews| 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 "SkPixelRef.h" | 9 #include "SkPixelRef.h" |
| 9 #include "SkThread.h" | 10 #include "SkThread.h" |
| 10 | 11 |
| 11 #ifdef SK_USE_POSIX_THREADS | 12 #ifdef SK_USE_POSIX_THREADS |
| 12 | 13 |
| 13 static SkBaseMutex gPixelRefMutexRing[] = { | 14 static SkBaseMutex gPixelRefMutexRing[] = { |
| 14 SK_BASE_MUTEX_INIT, SK_BASE_MUTEX_INIT, | 15 SK_BASE_MUTEX_INIT, SK_BASE_MUTEX_INIT, |
| 15 SK_BASE_MUTEX_INIT, SK_BASE_MUTEX_INIT, | 16 SK_BASE_MUTEX_INIT, SK_BASE_MUTEX_INIT, |
| 16 SK_BASE_MUTEX_INIT, SK_BASE_MUTEX_INIT, | 17 SK_BASE_MUTEX_INIT, SK_BASE_MUTEX_INIT, |
| 17 SK_BASE_MUTEX_INIT, SK_BASE_MUTEX_INIT, | 18 SK_BASE_MUTEX_INIT, SK_BASE_MUTEX_INIT, |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 216 | 217 |
| 217 void SkPixelRef::addGenIDChangeListener(GenIDChangeListener* listener) { | 218 void SkPixelRef::addGenIDChangeListener(GenIDChangeListener* listener) { |
| 218 if (NULL == listener || !fUniqueGenerationID) { | 219 if (NULL == listener || !fUniqueGenerationID) { |
| 219 // No point in tracking this if we're not going to call it. | 220 // No point in tracking this if we're not going to call it. |
| 220 SkDELETE(listener); | 221 SkDELETE(listener); |
| 221 return; | 222 return; |
| 222 } | 223 } |
| 223 *fGenIDChangeListeners.append() = listener; | 224 *fGenIDChangeListeners.append() = listener; |
| 224 } | 225 } |
| 225 | 226 |
| 227 // we need to be called *before* the genID gets changed or zerod | |
| 226 void SkPixelRef::callGenIDChangeListeners() { | 228 void SkPixelRef::callGenIDChangeListeners() { |
| 227 // We don't invalidate ourselves if we think another SkPixelRef is sharing o ur genID. | 229 // We don't invalidate ourselves if we think another SkPixelRef is sharing o ur genID. |
| 228 if (fUniqueGenerationID) { | 230 if (fUniqueGenerationID) { |
| 229 for (int i = 0; i < fGenIDChangeListeners.count(); i++) { | 231 for (int i = 0; i < fGenIDChangeListeners.count(); i++) { |
| 230 fGenIDChangeListeners[i]->onChange(); | 232 fGenIDChangeListeners[i]->onChange(); |
| 231 } | 233 } |
| 232 } | 234 } |
| 233 // 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. |
| 234 fGenIDChangeListeners.deleteAll(); | 236 fGenIDChangeListeners.deleteAll(); |
| 237 | |
| 238 // if fGenerationID is 0, then perhaps we never had one, and we are in the d estructor | |
| 239 if (fGenerationID) { | |
| 240 SkBitmapCache::NotifyGenIDStale(fGenerationID); | |
|
mtklein
2015/01/07 21:52:43
Feels weird knowing both these calls really grab a
reed1
2015/01/07 22:20:41
Agree on both counts.
*if* we (later) standardize
reed1
2015/02/18 17:30:32
Captured this comment in a comment.
| |
| 241 SkMipMapCache::NotifyGenIDStale(fGenerationID); | |
| 242 } | |
| 235 } | 243 } |
| 236 | 244 |
| 237 void SkPixelRef::notifyPixelsChanged() { | 245 void SkPixelRef::notifyPixelsChanged() { |
| 238 #ifdef SK_DEBUG | 246 #ifdef SK_DEBUG |
| 239 if (fIsImmutable) { | 247 if (fIsImmutable) { |
| 240 SkDebugf("========== notifyPixelsChanged called on immutable pixelref"); | 248 SkDebugf("========== notifyPixelsChanged called on immutable pixelref"); |
| 241 } | 249 } |
| 242 #endif | 250 #endif |
| 243 this->callGenIDChangeListeners(); | 251 this->callGenIDChangeListeners(); |
| 244 this->needsNewGenID(); | 252 this->needsNewGenID(); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 277 | 285 |
| 278 #ifdef SK_BUILD_FOR_ANDROID | 286 #ifdef SK_BUILD_FOR_ANDROID |
| 279 void SkPixelRef::globalRef(void* data) { | 287 void SkPixelRef::globalRef(void* data) { |
| 280 this->ref(); | 288 this->ref(); |
| 281 } | 289 } |
| 282 | 290 |
| 283 void SkPixelRef::globalUnref() { | 291 void SkPixelRef::globalUnref() { |
| 284 this->unref(); | 292 this->unref(); |
| 285 } | 293 } |
| 286 #endif | 294 #endif |
| OLD | NEW |