| 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 |
| 31 namespace cc { | 34 namespace cc { |
| 32 namespace { | 35 namespace { |
| 33 | 36 |
| 34 // The largest single high quality image to try and process. Images above this | 37 // The largest single high quality image to try and process. Images above this |
| 35 // size will drop down to medium quality. | 38 // size will drop down to medium quality. |
| 36 const size_t kMaxHighQualityImageSizeBytes = 64 * 1024 * 1024; | 39 const size_t kMaxHighQualityImageSizeBytes = 64 * 1024 * 1024; |
| 37 | 40 |
| 38 // The number of entries to keep around in the cache. This limit can be breached | 41 // The number of entries to keep around in the cache. This limit can be breached |
| 39 // if more items are locked. That is, locked items ignore this limit. | 42 // if more items are locked. That is, locked items ignore this limit. |
| 40 // Depending on the memory state of the system, we limit the amount of items | 43 // 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... |
| 770 void SoftwareImageDecodeController::RemovePendingTask(const ImageKey& key) { | 773 void SoftwareImageDecodeController::RemovePendingTask(const ImageKey& key) { |
| 771 base::AutoLock lock(lock_); | 774 base::AutoLock lock(lock_); |
| 772 pending_image_tasks_.erase(key); | 775 pending_image_tasks_.erase(key); |
| 773 } | 776 } |
| 774 | 777 |
| 775 bool SoftwareImageDecodeController::OnMemoryDump( | 778 bool SoftwareImageDecodeController::OnMemoryDump( |
| 776 const base::trace_event::MemoryDumpArgs& args, | 779 const base::trace_event::MemoryDumpArgs& args, |
| 777 base::trace_event::ProcessMemoryDump* pmd) { | 780 base::trace_event::ProcessMemoryDump* pmd) { |
| 778 base::AutoLock lock(lock_); | 781 base::AutoLock lock(lock_); |
| 779 | 782 |
| 780 // Dump each of our caches. | 783 if (args.level_of_detail == MemoryDumpLevelOfDetail::BACKGROUND) { |
| 781 DumpImageMemoryForCache(decoded_images_, "cached", pmd); | 784 std::string dump_name = |
| 782 DumpImageMemoryForCache(at_raster_decoded_images_, "at_raster", pmd); | 785 base::StringPrintf("cc/image_memory/controller_0x%" PRIXPTR, |
| 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 } |
| 783 | 795 |
| 784 // Memory dump can't fail, always return true. | 796 // Memory dump can't fail, always return true. |
| 785 return true; | 797 return true; |
| 786 } | 798 } |
| 787 | 799 |
| 788 void SoftwareImageDecodeController::DumpImageMemoryForCache( | 800 void SoftwareImageDecodeController::DumpImageMemoryForCache( |
| 789 const ImageMRUCache& cache, | 801 const ImageMRUCache& cache, |
| 790 const char* cache_name, | 802 const char* cache_name, |
| 791 base::trace_event::ProcessMemoryDump* pmd) const { | 803 base::trace_event::ProcessMemoryDump* pmd) const { |
| 792 lock_.AssertAcquired(); | 804 lock_.AssertAcquired(); |
| 793 | 805 |
| 794 for (const auto& image_pair : cache) { | 806 for (const auto& image_pair : cache) { |
| 795 std::string dump_name = base::StringPrintf( | 807 std::string dump_name = base::StringPrintf( |
| 796 "cc/image_memory/controller_0x%" PRIXPTR "/%s/image_%" PRIu64 "_id_%d", | 808 "cc/image_memory/controller_0x%" PRIXPTR "/%s/image_%" PRIu64 "_id_%d", |
| 797 reinterpret_cast<uintptr_t>(this), cache_name, | 809 reinterpret_cast<uintptr_t>(this), cache_name, |
| 798 image_pair.second->tracing_id(), image_pair.first.image_id()); | 810 image_pair.second->tracing_id(), image_pair.first.image_id()); |
| 799 base::trace_event::MemoryAllocatorDump* dump = | 811 MemoryAllocatorDump* dump = |
| 800 image_pair.second->memory()->CreateMemoryAllocatorDump( | 812 image_pair.second->memory()->CreateMemoryAllocatorDump( |
| 801 dump_name.c_str(), pmd); | 813 dump_name.c_str(), pmd); |
| 802 DCHECK(dump); | 814 DCHECK(dump); |
| 803 if (image_pair.second->is_locked()) { | 815 if (image_pair.second->is_locked()) { |
| 804 dump->AddScalar("locked_size", | 816 dump->AddScalar("locked_size", MemoryAllocatorDump::kUnitsBytes, |
| 805 base::trace_event::MemoryAllocatorDump::kUnitsBytes, | |
| 806 image_pair.first.locked_bytes()); | 817 image_pair.first.locked_bytes()); |
| 807 } | 818 } |
| 808 } | 819 } |
| 809 } | 820 } |
| 810 | 821 |
| 811 void SoftwareImageDecodeController::SanityCheckState(int line, | 822 void SoftwareImageDecodeController::SanityCheckState(int line, |
| 812 bool lock_acquired) { | 823 bool lock_acquired) { |
| 813 #if DCHECK_IS_ON() | 824 #if DCHECK_IS_ON() |
| 814 if (!lock_acquired) { | 825 if (!lock_acquired) { |
| 815 base::AutoLock lock(lock_); | 826 base::AutoLock lock(lock_); |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1104 break; | 1115 break; |
| 1105 case base::MemoryState::UNKNOWN: | 1116 case base::MemoryState::UNKNOWN: |
| 1106 NOTREACHED(); | 1117 NOTREACHED(); |
| 1107 return; | 1118 return; |
| 1108 } | 1119 } |
| 1109 } | 1120 } |
| 1110 ReduceCacheUsage(); | 1121 ReduceCacheUsage(); |
| 1111 } | 1122 } |
| 1112 | 1123 |
| 1113 } // namespace cc | 1124 } // namespace cc |
| OLD | NEW |