OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/tiles/software_image_decode_controller.h" | 5 #include "cc/tiles/software_image_decode_controller.h" |
6 | 6 |
7 #include <inttypes.h> | 7 #include <inttypes.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "base/trace_event/memory_dump_manager.h" | 21 #include "base/trace_event/memory_dump_manager.h" |
22 #include "cc/debug/devtools_instrumentation.h" | 22 #include "cc/debug/devtools_instrumentation.h" |
23 #include "cc/raster/tile_task.h" | 23 #include "cc/raster/tile_task.h" |
24 #include "cc/resources/resource_format_utils.h" | 24 #include "cc/resources/resource_format_utils.h" |
25 #include "cc/tiles/mipmap_util.h" | 25 #include "cc/tiles/mipmap_util.h" |
26 #include "third_party/skia/include/core/SkCanvas.h" | 26 #include "third_party/skia/include/core/SkCanvas.h" |
27 #include "third_party/skia/include/core/SkImage.h" | 27 #include "third_party/skia/include/core/SkImage.h" |
28 #include "third_party/skia/include/core/SkPixmap.h" | 28 #include "third_party/skia/include/core/SkPixmap.h" |
29 #include "ui/gfx/skia_util.h" | 29 #include "ui/gfx/skia_util.h" |
30 | 30 |
31 using base::trace_event::MemoryAllocatorDump; | |
32 using base::trace_event::MemoryDumpLevelOfDetail; | |
33 | |
34 namespace cc { | 31 namespace cc { |
35 namespace { | 32 namespace { |
36 | 33 |
37 // The largest single high quality image to try and process. Images above this | 34 // The largest single high quality image to try and process. Images above this |
38 // size will drop down to medium quality. | 35 // size will drop down to medium quality. |
39 const size_t kMaxHighQualityImageSizeBytes = 64 * 1024 * 1024; | 36 const size_t kMaxHighQualityImageSizeBytes = 64 * 1024 * 1024; |
40 | 37 |
41 // The number of entries to keep around in the cache. This limit can be breached | 38 // The number of entries to keep around in the cache. This limit can be breached |
42 // if more items are locked. That is, locked items ignore this limit. | 39 // if more items are locked. That is, locked items ignore this limit. |
43 // Depending on the memory state of the system, we limit the amount of items | 40 // Depending on the memory state of the system, we limit the amount of items |
(...skipping 729 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
773 void SoftwareImageDecodeController::RemovePendingTask(const ImageKey& key) { | 770 void SoftwareImageDecodeController::RemovePendingTask(const ImageKey& key) { |
774 base::AutoLock lock(lock_); | 771 base::AutoLock lock(lock_); |
775 pending_image_tasks_.erase(key); | 772 pending_image_tasks_.erase(key); |
776 } | 773 } |
777 | 774 |
778 bool SoftwareImageDecodeController::OnMemoryDump( | 775 bool SoftwareImageDecodeController::OnMemoryDump( |
779 const base::trace_event::MemoryDumpArgs& args, | 776 const base::trace_event::MemoryDumpArgs& args, |
780 base::trace_event::ProcessMemoryDump* pmd) { | 777 base::trace_event::ProcessMemoryDump* pmd) { |
781 base::AutoLock lock(lock_); | 778 base::AutoLock lock(lock_); |
782 | 779 |
783 if (args.level_of_detail == MemoryDumpLevelOfDetail::BACKGROUND) { | 780 // Dump each of our caches. |
784 std::string dump_name = | 781 DumpImageMemoryForCache(decoded_images_, "cached", pmd); |
785 base::StringPrintf("cc/image_memory/controller_0x%" PRIXPTR, | 782 DumpImageMemoryForCache(at_raster_decoded_images_, "at_raster", pmd); |
786 reinterpret_cast<uintptr_t>(this)); | |
787 MemoryAllocatorDump* dump = pmd->CreateAllocatorDump(dump_name); | |
788 dump->AddScalar("locked_size", MemoryAllocatorDump::kUnitsBytes, | |
789 locked_images_budget_.GetCurrentUsageSafe()); | |
790 } else { | |
791 // Dump each of our caches. | |
792 DumpImageMemoryForCache(decoded_images_, "cached", pmd); | |
793 DumpImageMemoryForCache(at_raster_decoded_images_, "at_raster", pmd); | |
794 } | |
795 | 783 |
796 // Memory dump can't fail, always return true. | 784 // Memory dump can't fail, always return true. |
797 return true; | 785 return true; |
798 } | 786 } |
799 | 787 |
800 void SoftwareImageDecodeController::DumpImageMemoryForCache( | 788 void SoftwareImageDecodeController::DumpImageMemoryForCache( |
801 const ImageMRUCache& cache, | 789 const ImageMRUCache& cache, |
802 const char* cache_name, | 790 const char* cache_name, |
803 base::trace_event::ProcessMemoryDump* pmd) const { | 791 base::trace_event::ProcessMemoryDump* pmd) const { |
804 lock_.AssertAcquired(); | 792 lock_.AssertAcquired(); |
805 | 793 |
806 for (const auto& image_pair : cache) { | 794 for (const auto& image_pair : cache) { |
| 795 std::string dump_name = base::StringPrintf( |
| 796 "cc/image_memory/controller_0x%" PRIXPTR "/%s/image_%" PRIu64 "_id_%d", |
| 797 reinterpret_cast<uintptr_t>(this), cache_name, |
| 798 image_pair.second->tracing_id(), image_pair.first.image_id()); |
| 799 base::trace_event::MemoryAllocatorDump* dump = |
| 800 image_pair.second->memory()->CreateMemoryAllocatorDump( |
| 801 dump_name.c_str(), pmd); |
| 802 DCHECK(dump); |
807 if (image_pair.second->is_locked()) { | 803 if (image_pair.second->is_locked()) { |
808 std::string dump_name = base::StringPrintf( | 804 dump->AddScalar("locked_size", |
809 "cc/image_memory/controller_0x%" PRIXPTR "/%s/image_%" PRIu64 | 805 base::trace_event::MemoryAllocatorDump::kUnitsBytes, |
810 "_id_%d", | |
811 reinterpret_cast<uintptr_t>(this), cache_name, | |
812 image_pair.second->tracing_id(), image_pair.first.image_id()); | |
813 MemoryAllocatorDump* dump = | |
814 image_pair.second->memory()->CreateMemoryAllocatorDump( | |
815 dump_name.c_str(), pmd); | |
816 DCHECK(dump); | |
817 dump->AddScalar("locked_size", MemoryAllocatorDump::kUnitsBytes, | |
818 image_pair.first.locked_bytes()); | 806 image_pair.first.locked_bytes()); |
819 } | 807 } |
820 } | 808 } |
821 } | 809 } |
822 | 810 |
823 void SoftwareImageDecodeController::SanityCheckState(int line, | 811 void SoftwareImageDecodeController::SanityCheckState(int line, |
824 bool lock_acquired) { | 812 bool lock_acquired) { |
825 #if DCHECK_IS_ON() | 813 #if DCHECK_IS_ON() |
826 if (!lock_acquired) { | 814 if (!lock_acquired) { |
827 base::AutoLock lock(lock_); | 815 base::AutoLock lock(lock_); |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1121 break; | 1109 break; |
1122 case base::MemoryState::UNKNOWN: | 1110 case base::MemoryState::UNKNOWN: |
1123 NOTREACHED(); | 1111 NOTREACHED(); |
1124 return; | 1112 return; |
1125 } | 1113 } |
1126 } | 1114 } |
1127 ReduceCacheUsage(); | 1115 ReduceCacheUsage(); |
1128 } | 1116 } |
1129 | 1117 |
1130 } // namespace cc | 1118 } // namespace cc |
OLD | NEW |