Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(37)

Side by Side Diff: src/core/SkPixelRef.cpp

Issue 825263005: notify resource caches when pixelref genID goes stale (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add test for purge notifications Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/core/SkBitmapCache.cpp ('k') | src/core/SkResourceCache.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_BUILD_FOR_WIN32 12 #ifdef SK_BUILD_FOR_WIN32
12 // We don't have SK_BASE_MUTEX_INIT on Windows. 13 // We don't have SK_BASE_MUTEX_INIT on Windows.
13 14
14 // must be a power-of-2. undef to just use 1 mutex 15 // must be a power-of-2. undef to just use 1 mutex
15 #define PIXELREF_MUTEX_RING_COUNT 32 16 #define PIXELREF_MUTEX_RING_COUNT 32
16 static SkBaseMutex gPixelRefMutexRing[PIXELREF_MUTEX_RING_COUNT]; 17 static SkBaseMutex gPixelRefMutexRing[PIXELREF_MUTEX_RING_COUNT];
17 18
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 216
216 void SkPixelRef::addGenIDChangeListener(GenIDChangeListener* listener) { 217 void SkPixelRef::addGenIDChangeListener(GenIDChangeListener* listener) {
217 if (NULL == listener || !fUniqueGenerationID) { 218 if (NULL == listener || !fUniqueGenerationID) {
218 // No point in tracking this if we're not going to call it. 219 // No point in tracking this if we're not going to call it.
219 SkDELETE(listener); 220 SkDELETE(listener);
220 return; 221 return;
221 } 222 }
222 *fGenIDChangeListeners.append() = listener; 223 *fGenIDChangeListeners.append() = listener;
223 } 224 }
224 225
226 // we need to be called *before* the genID gets changed or zerod
225 void SkPixelRef::callGenIDChangeListeners() { 227 void SkPixelRef::callGenIDChangeListeners() {
226 // We don't invalidate ourselves if we think another SkPixelRef is sharing o ur genID. 228 // We don't invalidate ourselves if we think another SkPixelRef is sharing o ur genID.
227 if (fUniqueGenerationID) { 229 if (fUniqueGenerationID) {
228 for (int i = 0; i < fGenIDChangeListeners.count(); i++) { 230 for (int i = 0; i < fGenIDChangeListeners.count(); i++) {
229 fGenIDChangeListeners[i]->onChange(); 231 fGenIDChangeListeners[i]->onChange();
230 } 232 }
231 } 233 }
232 // Listeners get at most one shot, so whether these triggered or not, blow t hem away. 234 // Listeners get at most one shot, so whether these triggered or not, blow t hem away.
233 fGenIDChangeListeners.deleteAll(); 235 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 }
234 } 245 }
235 246
236 void SkPixelRef::notifyPixelsChanged() { 247 void SkPixelRef::notifyPixelsChanged() {
237 #ifdef SK_DEBUG 248 #ifdef SK_DEBUG
238 if (fIsImmutable) { 249 if (fIsImmutable) {
239 SkDebugf("========== notifyPixelsChanged called on immutable pixelref"); 250 SkDebugf("========== notifyPixelsChanged called on immutable pixelref");
240 } 251 }
241 #endif 252 #endif
242 this->callGenIDChangeListeners(); 253 this->callGenIDChangeListeners();
243 this->needsNewGenID(); 254 this->needsNewGenID();
(...skipping 21 matching lines...) Expand all
265 276
266 bool SkPixelRef::onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBy tes[3], 277 bool SkPixelRef::onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBy tes[3],
267 SkYUVColorSpace* colorSpace) { 278 SkYUVColorSpace* colorSpace) {
268 return false; 279 return false;
269 } 280 }
270 281
271 size_t SkPixelRef::getAllocatedSizeInBytes() const { 282 size_t SkPixelRef::getAllocatedSizeInBytes() const {
272 return 0; 283 return 0;
273 } 284 }
274 285
OLDNEW
« no previous file with comments | « src/core/SkBitmapCache.cpp ('k') | src/core/SkResourceCache.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698