OLD | NEW |
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 "SkMessageBus.h" | 9 #include "SkMessageBus.h" |
10 #include "SkMipMap.h" | 10 #include "SkMipMap.h" |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 #ifdef SK_TRACK_PURGE_SHAREDID_HITRATE | 340 #ifdef SK_TRACK_PURGE_SHAREDID_HITRATE |
341 if (found) { | 341 if (found) { |
342 gPurgeHitCounter += 1; | 342 gPurgeHitCounter += 1; |
343 } | 343 } |
344 | 344 |
345 SkDebugf("PurgeShared calls=%d hits=%d rate=%g\n", gPurgeCallCounter, gPurge
HitCounter, | 345 SkDebugf("PurgeShared calls=%d hits=%d rate=%g\n", gPurgeCallCounter, gPurge
HitCounter, |
346 gPurgeHitCounter * 100.0 / gPurgeCallCounter); | 346 gPurgeHitCounter * 100.0 / gPurgeCallCounter); |
347 #endif | 347 #endif |
348 } | 348 } |
349 | 349 |
| 350 void SkResourceCache::visitAll(Visitor visitor, void* context) { |
| 351 // go backwards, just like purgeAsNeeded, just to make the code similar. |
| 352 // could iterate either direction and still be correct. |
| 353 Rec* rec = fTail; |
| 354 while (rec) { |
| 355 visitor(*rec, context); |
| 356 rec = rec->fPrev; |
| 357 } |
| 358 } |
| 359 |
| 360 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 361 |
350 size_t SkResourceCache::setTotalByteLimit(size_t newLimit) { | 362 size_t SkResourceCache::setTotalByteLimit(size_t newLimit) { |
351 size_t prevLimit = fTotalByteLimit; | 363 size_t prevLimit = fTotalByteLimit; |
352 fTotalByteLimit = newLimit; | 364 fTotalByteLimit = newLimit; |
353 if (newLimit < prevLimit) { | 365 if (newLimit < prevLimit) { |
354 this->purgeAsNeeded(); | 366 this->purgeAsNeeded(); |
355 } | 367 } |
356 return prevLimit; | 368 return prevLimit; |
357 } | 369 } |
358 | 370 |
359 SkCachedData* SkResourceCache::newCachedData(size_t bytes) { | 371 SkCachedData* SkResourceCache::newCachedData(size_t bytes) { |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
601 bool SkResourceCache::Find(const Key& key, FindVisitor visitor, void* context) { | 613 bool SkResourceCache::Find(const Key& key, FindVisitor visitor, void* context) { |
602 SkAutoMutexAcquire am(gMutex); | 614 SkAutoMutexAcquire am(gMutex); |
603 return get_cache()->find(key, visitor, context); | 615 return get_cache()->find(key, visitor, context); |
604 } | 616 } |
605 | 617 |
606 void SkResourceCache::Add(Rec* rec) { | 618 void SkResourceCache::Add(Rec* rec) { |
607 SkAutoMutexAcquire am(gMutex); | 619 SkAutoMutexAcquire am(gMutex); |
608 get_cache()->add(rec); | 620 get_cache()->add(rec); |
609 } | 621 } |
610 | 622 |
| 623 void SkResourceCache::VisitAll(Visitor visitor, void* context) { |
| 624 SkAutoMutexAcquire am(gMutex); |
| 625 get_cache()->visitAll(visitor, context); |
| 626 } |
| 627 |
611 void SkResourceCache::PostPurgeSharedID(uint64_t sharedID) { | 628 void SkResourceCache::PostPurgeSharedID(uint64_t sharedID) { |
612 if (sharedID) { | 629 if (sharedID) { |
613 SkMessageBus<PurgeSharedIDMessage>::Post(PurgeSharedIDMessage(sharedID))
; | 630 SkMessageBus<PurgeSharedIDMessage>::Post(PurgeSharedIDMessage(sharedID))
; |
614 } | 631 } |
615 } | 632 } |
616 | 633 |
617 /////////////////////////////////////////////////////////////////////////////// | 634 /////////////////////////////////////////////////////////////////////////////// |
618 | 635 |
619 #include "SkGraphics.h" | 636 #include "SkGraphics.h" |
620 #include "SkImageFilter.h" | 637 #include "SkImageFilter.h" |
(...skipping 16 matching lines...) Expand all Loading... |
637 | 654 |
638 size_t SkGraphics::SetResourceCacheSingleAllocationByteLimit(size_t newLimit) { | 655 size_t SkGraphics::SetResourceCacheSingleAllocationByteLimit(size_t newLimit) { |
639 return SkResourceCache::SetSingleAllocationByteLimit(newLimit); | 656 return SkResourceCache::SetSingleAllocationByteLimit(newLimit); |
640 } | 657 } |
641 | 658 |
642 void SkGraphics::PurgeResourceCache() { | 659 void SkGraphics::PurgeResourceCache() { |
643 SkImageFilter::PurgeCache(); | 660 SkImageFilter::PurgeCache(); |
644 return SkResourceCache::PurgeAll(); | 661 return SkResourceCache::PurgeAll(); |
645 } | 662 } |
646 | 663 |
| 664 ///////////// |
| 665 |
| 666 static void dump_visitor(const SkResourceCache::Rec& rec, void*) { |
| 667 SkDebugf("RC: %12s bytes %9lu discardable %p\n", |
| 668 rec.getCategory(), rec.bytesUsed(), rec.diagnostic_only_getDiscarda
ble()); |
| 669 } |
| 670 |
| 671 void SkResourceCache::TestDumpMemoryStatistics() { |
| 672 VisitAll(dump_visitor, nullptr); |
| 673 } |
OLD | NEW |