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

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

Issue 825263005: notify resource caches when pixelref genID goes stale (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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/SkResourceCache.h ('k') | no next file » | 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 2013 Google Inc. 2 * Copyright 2013 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 "SkChecksum.h" 8 #include "SkChecksum.h"
9 #include "SkResourceCache.h" 9 #include "SkResourceCache.h"
10 #include "SkMipMap.h" 10 #include "SkMipMap.h"
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 while (rec) { 192 while (rec) {
193 Rec* next = rec->fNext; 193 Rec* next = rec->fNext;
194 SkDELETE(rec); 194 SkDELETE(rec);
195 rec = next; 195 rec = next;
196 } 196 }
197 delete fHash; 197 delete fHash;
198 } 198 }
199 199
200 //////////////////////////////////////////////////////////////////////////////// 200 ////////////////////////////////////////////////////////////////////////////////
201 201
202 bool SkResourceCache::find(const Key& key, VisitorProc visitor, void* context) { 202 bool SkResourceCache::find(const Key& key, FindVisitor visitor, void* context) {
203 Rec* rec = fHash->find(key); 203 Rec* rec = fHash->find(key);
204 if (rec) { 204 if (rec) {
205 if (visitor(*rec, context)) { 205 if (visitor(*rec, context)) {
206 this->moveToHead(rec); // for our LRU 206 this->moveToHead(rec); // for our LRU
207 return true; 207 return true;
208 } else { 208 } else {
209 this->remove(rec); // stale 209 this->remove(rec); // stale
210 return false; 210 return false;
211 } 211 }
212 } 212 }
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 if (!forcePurge && fTotalBytesUsed < byteLimit && fCount < countLimit) { 287 if (!forcePurge && fTotalBytesUsed < byteLimit && fCount < countLimit) {
288 break; 288 break;
289 } 289 }
290 290
291 Rec* prev = rec->fPrev; 291 Rec* prev = rec->fPrev;
292 this->remove(rec); 292 this->remove(rec);
293 rec = prev; 293 rec = prev;
294 } 294 }
295 } 295 }
296 296
297 void SkResourceCache::purge(const void* nameSpace, PurgeVisitor proc, void* cont ext) {
298 // go backwards, just like purgeAsNeeded, just to make the code similar.
299 // could iterate either direction and still be correct.
300 Rec* rec = fTail;
301 while (rec) {
302 Rec* prev = rec->fPrev;
303 if (rec->getKey().getNamespace() == nameSpace) {
304 switch (proc(*rec, context)) {
305 case kRetainAndContinue_PurgeVisitorResult:
306 break;
mtklein 2015/02/18 18:49:48 Remind me, what does this break out of? Isn't thi
reed1 2015/02/18 19:30:40 break inside a switch just falls out of the switch
307 case kPurgeAndContinue_PurgeVisitorResult:
308 this->remove(rec);
309 break;
310 case kRetainAndStop_PurgeVisitorResult:
311 return;
312 case kPurgeAndStop_PurgeVisitorResult:
313 this->remove(rec);
314 return;
315 }
316 }
317 rec = prev;
318 }
319 }
320
297 size_t SkResourceCache::setTotalByteLimit(size_t newLimit) { 321 size_t SkResourceCache::setTotalByteLimit(size_t newLimit) {
298 size_t prevLimit = fTotalByteLimit; 322 size_t prevLimit = fTotalByteLimit;
299 fTotalByteLimit = newLimit; 323 fTotalByteLimit = newLimit;
300 if (newLimit < prevLimit) { 324 if (newLimit < prevLimit) {
301 this->purgeAsNeeded(); 325 this->purgeAsNeeded();
302 } 326 }
303 return prevLimit; 327 return prevLimit;
304 } 328 }
305 329
306 SkCachedData* SkResourceCache::newCachedData(size_t bytes) { 330 SkCachedData* SkResourceCache::newCachedData(size_t bytes) {
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 size_t SkResourceCache::GetSingleAllocationByteLimit() { 549 size_t SkResourceCache::GetSingleAllocationByteLimit() {
526 SkAutoMutexAcquire am(gMutex); 550 SkAutoMutexAcquire am(gMutex);
527 return get_cache()->getSingleAllocationByteLimit(); 551 return get_cache()->getSingleAllocationByteLimit();
528 } 552 }
529 553
530 size_t SkResourceCache::GetEffectiveSingleAllocationByteLimit() { 554 size_t SkResourceCache::GetEffectiveSingleAllocationByteLimit() {
531 SkAutoMutexAcquire am(gMutex); 555 SkAutoMutexAcquire am(gMutex);
532 return get_cache()->getEffectiveSingleAllocationByteLimit(); 556 return get_cache()->getEffectiveSingleAllocationByteLimit();
533 } 557 }
534 558
559 void SkResourceCache::Purge(const void* nameSpace, PurgeVisitor proc, void* cont ext) {
560 SkAutoMutexAcquire am(gMutex);
561 return get_cache()->purge(nameSpace, proc, context);
562 }
563
535 void SkResourceCache::PurgeAll() { 564 void SkResourceCache::PurgeAll() {
536 SkAutoMutexAcquire am(gMutex); 565 SkAutoMutexAcquire am(gMutex);
537 return get_cache()->purgeAll(); 566 return get_cache()->purgeAll();
538 } 567 }
539 568
540 bool SkResourceCache::Find(const Key& key, VisitorProc visitor, void* context) { 569 bool SkResourceCache::Find(const Key& key, FindVisitor visitor, void* context) {
541 SkAutoMutexAcquire am(gMutex); 570 SkAutoMutexAcquire am(gMutex);
542 return get_cache()->find(key, visitor, context); 571 return get_cache()->find(key, visitor, context);
543 } 572 }
544 573
545 void SkResourceCache::Add(Rec* rec) { 574 void SkResourceCache::Add(Rec* rec) {
546 SkAutoMutexAcquire am(gMutex); 575 SkAutoMutexAcquire am(gMutex);
547 get_cache()->add(rec); 576 get_cache()->add(rec);
548 } 577 }
549 578
550 /////////////////////////////////////////////////////////////////////////////// 579 ///////////////////////////////////////////////////////////////////////////////
(...skipping 17 matching lines...) Expand all
568 } 597 }
569 598
570 size_t SkGraphics::SetResourceCacheSingleAllocationByteLimit(size_t newLimit) { 599 size_t SkGraphics::SetResourceCacheSingleAllocationByteLimit(size_t newLimit) {
571 return SkResourceCache::SetSingleAllocationByteLimit(newLimit); 600 return SkResourceCache::SetSingleAllocationByteLimit(newLimit);
572 } 601 }
573 602
574 void SkGraphics::PurgeResourceCache() { 603 void SkGraphics::PurgeResourceCache() {
575 return SkResourceCache::PurgeAll(); 604 return SkResourceCache::PurgeAll();
576 } 605 }
577 606
OLDNEW
« no previous file with comments | « src/core/SkResourceCache.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698