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

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

Issue 936423002: Revert of 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') | tests/SkResourceCacheTest.cpp » ('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 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 fTail = NULL; 54 fTail = NULL;
55 fHash = new Hash; 55 fHash = new Hash;
56 fTotalBytesUsed = 0; 56 fTotalBytesUsed = 0;
57 fCount = 0; 57 fCount = 0;
58 fSingleAllocationByteLimit = 0; 58 fSingleAllocationByteLimit = 0;
59 fAllocator = NULL; 59 fAllocator = NULL;
60 60
61 // One of these should be explicit set by the caller after we return. 61 // One of these should be explicit set by the caller after we return.
62 fTotalByteLimit = 0; 62 fTotalByteLimit = 0;
63 fDiscardableFactory = NULL; 63 fDiscardableFactory = NULL;
64
65 fInsidePurgeAllCounter = 0;
66 } 64 }
67 65
68 #include "SkDiscardableMemory.h" 66 #include "SkDiscardableMemory.h"
69 67
70 class SkOneShotDiscardablePixelRef : public SkPixelRef { 68 class SkOneShotDiscardablePixelRef : public SkPixelRef {
71 public: 69 public:
72 SK_DECLARE_INST_COUNT(SkOneShotDiscardablePixelRef) 70 SK_DECLARE_INST_COUNT(SkOneShotDiscardablePixelRef)
73 // Ownership of the discardablememory is transfered to the pixelref 71 // Ownership of the discardablememory is transfered to the pixelref
74 SkOneShotDiscardablePixelRef(const SkImageInfo&, SkDiscardableMemory*, size_ t rowBytes); 72 SkOneShotDiscardablePixelRef(const SkImageInfo&, SkDiscardableMemory*, size_ t rowBytes);
75 ~SkOneShotDiscardablePixelRef(); 73 ~SkOneShotDiscardablePixelRef();
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 while (rec) { 192 while (rec) {
195 Rec* next = rec->fNext; 193 Rec* next = rec->fNext;
196 SkDELETE(rec); 194 SkDELETE(rec);
197 rec = next; 195 rec = next;
198 } 196 }
199 delete fHash; 197 delete fHash;
200 } 198 }
201 199
202 //////////////////////////////////////////////////////////////////////////////// 200 ////////////////////////////////////////////////////////////////////////////////
203 201
204 bool SkResourceCache::find(const Key& key, FindVisitor visitor, void* context) { 202 bool SkResourceCache::find(const Key& key, VisitorProc visitor, void* context) {
205 Rec* rec = fHash->find(key); 203 Rec* rec = fHash->find(key);
206 if (rec) { 204 if (rec) {
207 if (visitor(*rec, context)) { 205 if (visitor(*rec, context)) {
208 this->moveToHead(rec); // for our LRU 206 this->moveToHead(rec); // for our LRU
209 return true; 207 return true;
210 } else { 208 } else {
211 this->remove(rec); // stale 209 this->remove(rec); // stale
212 return false; 210 return false;
213 } 211 }
214 } 212 }
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 while (rec) { 286 while (rec) {
289 if (!forcePurge && fTotalBytesUsed < byteLimit && fCount < countLimit) { 287 if (!forcePurge && fTotalBytesUsed < byteLimit && fCount < countLimit) {
290 break; 288 break;
291 } 289 }
292 290
293 Rec* prev = rec->fPrev; 291 Rec* prev = rec->fPrev;
294 this->remove(rec); 292 this->remove(rec);
295 rec = prev; 293 rec = prev;
296 } 294 }
297 } 295 }
298
299 void SkResourceCache::purge(const void* nameSpace, PurgeVisitor proc, void* cont ext) {
300 if (this->insidePurgeAll()) {
301 return;
302 }
303
304 // go backwards, just like purgeAsNeeded, just to make the code similar.
305 // could iterate either direction and still be correct.
306 Rec* rec = fTail;
307 while (rec) {
308 Rec* prev = rec->fPrev;
309 if (rec->getKey().getNamespace() == nameSpace) {
310 switch (proc(*rec, context)) {
311 case kRetainAndContinue_PurgeVisitorResult:
312 break;
313 case kPurgeAndContinue_PurgeVisitorResult:
314 this->remove(rec);
315 break;
316 case kRetainAndStop_PurgeVisitorResult:
317 return;
318 case kPurgeAndStop_PurgeVisitorResult:
319 this->remove(rec);
320 return;
321 }
322 }
323 rec = prev;
324 }
325 }
326 296
327 size_t SkResourceCache::setTotalByteLimit(size_t newLimit) { 297 size_t SkResourceCache::setTotalByteLimit(size_t newLimit) {
328 size_t prevLimit = fTotalByteLimit; 298 size_t prevLimit = fTotalByteLimit;
329 fTotalByteLimit = newLimit; 299 fTotalByteLimit = newLimit;
330 if (newLimit < prevLimit) { 300 if (newLimit < prevLimit) {
331 this->purgeAsNeeded(); 301 this->purgeAsNeeded();
332 } 302 }
333 return prevLimit; 303 return prevLimit;
334 } 304 }
335 305
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 size_t SkResourceCache::GetSingleAllocationByteLimit() { 525 size_t SkResourceCache::GetSingleAllocationByteLimit() {
556 SkAutoMutexAcquire am(gMutex); 526 SkAutoMutexAcquire am(gMutex);
557 return get_cache()->getSingleAllocationByteLimit(); 527 return get_cache()->getSingleAllocationByteLimit();
558 } 528 }
559 529
560 size_t SkResourceCache::GetEffectiveSingleAllocationByteLimit() { 530 size_t SkResourceCache::GetEffectiveSingleAllocationByteLimit() {
561 SkAutoMutexAcquire am(gMutex); 531 SkAutoMutexAcquire am(gMutex);
562 return get_cache()->getEffectiveSingleAllocationByteLimit(); 532 return get_cache()->getEffectiveSingleAllocationByteLimit();
563 } 533 }
564 534
565 void SkResourceCache::Purge(const void* nameSpace, PurgeVisitor proc, void* cont ext) {
566 SkAutoMutexAcquire am(gMutex);
567 return get_cache()->purge(nameSpace, proc, context);
568 }
569
570 void SkResourceCache::PurgeAll() { 535 void SkResourceCache::PurgeAll() {
571 SkAutoMutexAcquire am(gMutex); 536 SkAutoMutexAcquire am(gMutex);
572 return get_cache()->purgeAll(); 537 return get_cache()->purgeAll();
573 } 538 }
574 539
575 bool SkResourceCache::Find(const Key& key, FindVisitor visitor, void* context) { 540 bool SkResourceCache::Find(const Key& key, VisitorProc visitor, void* context) {
576 SkAutoMutexAcquire am(gMutex); 541 SkAutoMutexAcquire am(gMutex);
577 return get_cache()->find(key, visitor, context); 542 return get_cache()->find(key, visitor, context);
578 } 543 }
579 544
580 void SkResourceCache::Add(Rec* rec) { 545 void SkResourceCache::Add(Rec* rec) {
581 SkAutoMutexAcquire am(gMutex); 546 SkAutoMutexAcquire am(gMutex);
582 get_cache()->add(rec); 547 get_cache()->add(rec);
583 } 548 }
584 549
585 /////////////////////////////////////////////////////////////////////////////// 550 ///////////////////////////////////////////////////////////////////////////////
(...skipping 17 matching lines...) Expand all
603 } 568 }
604 569
605 size_t SkGraphics::SetResourceCacheSingleAllocationByteLimit(size_t newLimit) { 570 size_t SkGraphics::SetResourceCacheSingleAllocationByteLimit(size_t newLimit) {
606 return SkResourceCache::SetSingleAllocationByteLimit(newLimit); 571 return SkResourceCache::SetSingleAllocationByteLimit(newLimit);
607 } 572 }
608 573
609 void SkGraphics::PurgeResourceCache() { 574 void SkGraphics::PurgeResourceCache() {
610 return SkResourceCache::PurgeAll(); 575 return SkResourceCache::PurgeAll();
611 } 576 }
612 577
OLDNEW
« no previous file with comments | « src/core/SkResourceCache.h ('k') | tests/SkResourceCacheTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698