Chromium Code Reviews| 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 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 537 fPurgeSharedIDInbox.poll(&msgs); | 537 fPurgeSharedIDInbox.poll(&msgs); |
| 538 for (int i = 0; i < msgs.count(); ++i) { | 538 for (int i = 0; i < msgs.count(); ++i) { |
| 539 this->purgeSharedID(msgs[i].fSharedID); | 539 this->purgeSharedID(msgs[i].fSharedID); |
| 540 } | 540 } |
| 541 } | 541 } |
| 542 | 542 |
| 543 /////////////////////////////////////////////////////////////////////////////// | 543 /////////////////////////////////////////////////////////////////////////////// |
| 544 | 544 |
| 545 SK_DECLARE_STATIC_MUTEX(gMutex); | 545 SK_DECLARE_STATIC_MUTEX(gMutex); |
| 546 static SkResourceCache* gResourceCache = nullptr; | 546 static SkResourceCache* gResourceCache = nullptr; |
| 547 static void cleanup_gResourceCache() { | |
| 548 // We'll clean this up in our own tests, but disable for clients. | |
| 549 // Chrome seems to have funky multi-process things going on in unit tests th at | |
| 550 // makes this unsafe to delete when the main process atexit()s. | |
| 551 // SkLazyPtr does the same sort of thing. | |
|
mtklein
2016/04/28 20:46:00
Ah, good. SkLazyPtr was deleted but this comment
| |
| 552 #if SK_DEVELOPER | |
| 553 delete gResourceCache; | |
| 554 #endif | |
| 555 } | |
| 556 | 547 |
| 557 /** Must hold gMutex when calling. */ | 548 /** Must hold gMutex when calling. */ |
| 558 static SkResourceCache* get_cache() { | 549 static SkResourceCache* get_cache() { |
| 559 // gMutex is always held when this is called, so we don't need to be fancy i n here. | 550 // gMutex is always held when this is called, so we don't need to be fancy i n here. |
| 560 gMutex.assertHeld(); | 551 gMutex.assertHeld(); |
| 561 if (nullptr == gResourceCache) { | 552 if (nullptr == gResourceCache) { |
| 562 #ifdef SK_USE_DISCARDABLE_SCALEDIMAGECACHE | 553 #ifdef SK_USE_DISCARDABLE_SCALEDIMAGECACHE |
| 563 gResourceCache = new SkResourceCache(SkDiscardableMemory::Create); | 554 gResourceCache = new SkResourceCache(SkDiscardableMemory::Create); |
| 564 #else | 555 #else |
| 565 gResourceCache = new SkResourceCache(SK_DEFAULT_IMAGE_CACHE_LIMIT); | 556 gResourceCache = new SkResourceCache(SK_DEFAULT_IMAGE_CACHE_LIMIT); |
| 566 #endif | 557 #endif |
| 567 atexit(cleanup_gResourceCache); | |
| 568 } | 558 } |
| 569 return gResourceCache; | 559 return gResourceCache; |
| 570 } | 560 } |
| 571 | 561 |
| 572 size_t SkResourceCache::GetTotalBytesUsed() { | 562 size_t SkResourceCache::GetTotalBytesUsed() { |
| 573 SkAutoMutexAcquire am(gMutex); | 563 SkAutoMutexAcquire am(gMutex); |
| 574 return get_cache()->getTotalBytesUsed(); | 564 return get_cache()->getTotalBytesUsed(); |
| 575 } | 565 } |
| 576 | 566 |
| 577 size_t SkResourceCache::GetTotalByteLimit() { | 567 size_t SkResourceCache::GetTotalByteLimit() { |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 700 dump->dumpNumericValue(dumpName.c_str(), "size", "bytes", rec.bytesUsed( )); | 690 dump->dumpNumericValue(dumpName.c_str(), "size", "bytes", rec.bytesUsed( )); |
| 701 dump->setMemoryBacking(dumpName.c_str(), "malloc", nullptr); | 691 dump->setMemoryBacking(dumpName.c_str(), "malloc", nullptr); |
| 702 } | 692 } |
| 703 } | 693 } |
| 704 | 694 |
| 705 void SkResourceCache::DumpMemoryStatistics(SkTraceMemoryDump* dump) { | 695 void SkResourceCache::DumpMemoryStatistics(SkTraceMemoryDump* dump) { |
| 706 // Since resource could be backed by malloc or discardable, the cache always dumps detailed | 696 // Since resource could be backed by malloc or discardable, the cache always dumps detailed |
| 707 // stats to be accurate. | 697 // stats to be accurate. |
| 708 VisitAll(sk_trace_dump_visitor, dump); | 698 VisitAll(sk_trace_dump_visitor, dump); |
| 709 } | 699 } |
| OLD | NEW |