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

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

Issue 554263005: add PurgeResourceCache to track leaks (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 3 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 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 #ifdef USE_HASH 296 #ifdef USE_HASH
297 fHash->remove(rec->getKey()); 297 fHash->remove(rec->getKey());
298 #endif 298 #endif
299 299
300 SkDELETE(rec); 300 SkDELETE(rec);
301 301
302 fTotalBytesUsed -= used; 302 fTotalBytesUsed -= used;
303 fCount -= 1; 303 fCount -= 1;
304 } 304 }
305 305
306 void SkResourceCache::purgeAsNeeded() { 306 void SkResourceCache::purgeAsNeeded(bool forcePurge) {
307 size_t byteLimit; 307 size_t byteLimit;
308 int countLimit; 308 int countLimit;
309 309
310 if (fDiscardableFactory) { 310 if (fDiscardableFactory) {
311 countLimit = SK_DISCARDABLEMEMORY_SCALEDIMAGECACHE_COUNT_LIMIT; 311 countLimit = SK_DISCARDABLEMEMORY_SCALEDIMAGECACHE_COUNT_LIMIT;
312 byteLimit = SK_MaxU32; // no limit based on bytes 312 byteLimit = SK_MaxU32; // no limit based on bytes
313 } else { 313 } else {
314 countLimit = SK_MaxS32; // no limit based on count 314 countLimit = SK_MaxS32; // no limit based on count
315 byteLimit = fTotalByteLimit; 315 byteLimit = fTotalByteLimit;
316 } 316 }
317 317
318 Rec* rec = fTail; 318 Rec* rec = fTail;
319 while (rec) { 319 while (rec) {
320 if (fTotalBytesUsed < byteLimit && fCount < countLimit) { 320 if (!forcePurge && fTotalBytesUsed < byteLimit && fCount < countLimit) {
321 break; 321 break;
322 } 322 }
323 323
324 Rec* prev = rec->fPrev; 324 Rec* prev = rec->fPrev;
325 if (0 == rec->fLockCount) { 325 if (0 == rec->fLockCount) {
326 this->remove(rec); 326 this->remove(rec);
327 } 327 }
328 rec = prev; 328 rec = prev;
329 } 329 }
330 } 330 }
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 size_t SkResourceCache::SetSingleAllocationByteLimit(size_t size) { 557 size_t SkResourceCache::SetSingleAllocationByteLimit(size_t size) {
558 SkAutoMutexAcquire am(gMutex); 558 SkAutoMutexAcquire am(gMutex);
559 return get_cache()->setSingleAllocationByteLimit(size); 559 return get_cache()->setSingleAllocationByteLimit(size);
560 } 560 }
561 561
562 size_t SkResourceCache::GetSingleAllocationByteLimit() { 562 size_t SkResourceCache::GetSingleAllocationByteLimit() {
563 SkAutoMutexAcquire am(gMutex); 563 SkAutoMutexAcquire am(gMutex);
564 return get_cache()->getSingleAllocationByteLimit(); 564 return get_cache()->getSingleAllocationByteLimit();
565 } 565 }
566 566
567 void SkResourceCache::PurgeAll() {
568 SkAutoMutexAcquire am(gMutex);
569 return get_cache()->purgeAll();
570 }
571
567 const SkResourceCache::Rec* SkResourceCache::FindAndLock(const Key& key) { 572 const SkResourceCache::Rec* SkResourceCache::FindAndLock(const Key& key) {
568 SkAutoMutexAcquire am(gMutex); 573 SkAutoMutexAcquire am(gMutex);
569 return get_cache()->findAndLock(key); 574 return get_cache()->findAndLock(key);
570 } 575 }
571 576
572 const SkResourceCache::Rec* SkResourceCache::AddAndLock(Rec* rec) { 577 const SkResourceCache::Rec* SkResourceCache::AddAndLock(Rec* rec) {
573 SkAutoMutexAcquire am(gMutex); 578 SkAutoMutexAcquire am(gMutex);
574 return get_cache()->addAndLock(rec); 579 return get_cache()->addAndLock(rec);
575 } 580 }
576 581
(...skipping 19 matching lines...) Expand all
596 } 601 }
597 602
598 size_t SkGraphics::GetResourceCacheSingleAllocationByteLimit() { 603 size_t SkGraphics::GetResourceCacheSingleAllocationByteLimit() {
599 return SkResourceCache::GetSingleAllocationByteLimit(); 604 return SkResourceCache::GetSingleAllocationByteLimit();
600 } 605 }
601 606
602 size_t SkGraphics::SetResourceCacheSingleAllocationByteLimit(size_t newLimit) { 607 size_t SkGraphics::SetResourceCacheSingleAllocationByteLimit(size_t newLimit) {
603 return SkResourceCache::SetSingleAllocationByteLimit(newLimit); 608 return SkResourceCache::SetSingleAllocationByteLimit(newLimit);
604 } 609 }
605 610
611 void SkGraphics::PurgeResourceCache() {
612 return SkResourceCache::PurgeAll();
613 }
614
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