| 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> |
| 11 #include <functional> | 11 #include <functional> |
| 12 | 12 |
| 13 #include "base/allocator/allocator_extension.h" |
| 13 #include "base/format_macros.h" | 14 #include "base/format_macros.h" |
| 14 #include "base/macros.h" | 15 #include "base/macros.h" |
| 15 #include "base/memory/discardable_memory.h" | 16 #include "base/memory/discardable_memory.h" |
| 16 #include "base/memory/ptr_util.h" | 17 #include "base/memory/ptr_util.h" |
| 17 #include "base/metrics/histogram_macros.h" | 18 #include "base/metrics/histogram_macros.h" |
| 18 #include "base/strings/stringprintf.h" | 19 #include "base/strings/stringprintf.h" |
| 19 #include "base/threading/thread_task_runner_handle.h" | 20 #include "base/threading/thread_task_runner_handle.h" |
| 20 #include "base/trace_event/memory_dump_manager.h" | 21 #include "base/trace_event/memory_dump_manager.h" |
| 21 #include "cc/debug/devtools_instrumentation.h" | 22 #include "cc/debug/devtools_instrumentation.h" |
| 22 #include "cc/raster/tile_task.h" | 23 #include "cc/raster/tile_task.h" |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 at_raster_decoded_images_(ImageMRUCache::NO_AUTO_EVICT), | 148 at_raster_decoded_images_(ImageMRUCache::NO_AUTO_EVICT), |
| 148 locked_images_budget_(locked_memory_limit_bytes), | 149 locked_images_budget_(locked_memory_limit_bytes), |
| 149 format_(format) { | 150 format_(format) { |
| 150 // In certain cases, ThreadTaskRunnerHandle isn't set (Android Webview). | 151 // In certain cases, ThreadTaskRunnerHandle isn't set (Android Webview). |
| 151 // Don't register a dump provider in these cases. | 152 // Don't register a dump provider in these cases. |
| 152 if (base::ThreadTaskRunnerHandle::IsSet()) { | 153 if (base::ThreadTaskRunnerHandle::IsSet()) { |
| 153 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( | 154 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( |
| 154 this, "cc::SoftwareImageDecodeController", | 155 this, "cc::SoftwareImageDecodeController", |
| 155 base::ThreadTaskRunnerHandle::Get()); | 156 base::ThreadTaskRunnerHandle::Get()); |
| 156 } | 157 } |
| 158 memory_pressure_listener_.reset(new base::MemoryPressureListener( |
| 159 base::Bind(&SoftwareImageDecodeController::OnMemoryPressure, |
| 160 base::Unretained(this)))); |
| 157 } | 161 } |
| 158 | 162 |
| 159 SoftwareImageDecodeController::~SoftwareImageDecodeController() { | 163 SoftwareImageDecodeController::~SoftwareImageDecodeController() { |
| 160 DCHECK_EQ(0u, decoded_images_ref_counts_.size()); | 164 DCHECK_EQ(0u, decoded_images_ref_counts_.size()); |
| 161 DCHECK_EQ(0u, at_raster_decoded_images_ref_counts_.size()); | 165 DCHECK_EQ(0u, at_raster_decoded_images_ref_counts_.size()); |
| 162 | 166 |
| 163 // It is safe to unregister, even if we didn't register in the constructor. | 167 // It is safe to unregister, even if we didn't register in the constructor. |
| 164 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( | 168 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( |
| 165 this); | 169 this); |
| 166 } | 170 } |
| (...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 693 base::AutoLock lock(lock_); | 697 base::AutoLock lock(lock_); |
| 694 | 698 |
| 695 // Dump each of our caches. | 699 // Dump each of our caches. |
| 696 DumpImageMemoryForCache(decoded_images_, "cached", pmd); | 700 DumpImageMemoryForCache(decoded_images_, "cached", pmd); |
| 697 DumpImageMemoryForCache(at_raster_decoded_images_, "at_raster", pmd); | 701 DumpImageMemoryForCache(at_raster_decoded_images_, "at_raster", pmd); |
| 698 | 702 |
| 699 // Memory dump can't fail, always return true. | 703 // Memory dump can't fail, always return true. |
| 700 return true; | 704 return true; |
| 701 } | 705 } |
| 702 | 706 |
| 707 void SoftwareImageDecodeController::OnMemoryPressure( |
| 708 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) { |
| 709 decoded_images_.Clear(); |
| 710 at_raster_decoded_images_.Clear(); |
| 711 base::allocator::ReleaseFreeMemory(); |
| 712 } |
| 713 |
| 703 void SoftwareImageDecodeController::DumpImageMemoryForCache( | 714 void SoftwareImageDecodeController::DumpImageMemoryForCache( |
| 704 const ImageMRUCache& cache, | 715 const ImageMRUCache& cache, |
| 705 const char* cache_name, | 716 const char* cache_name, |
| 706 base::trace_event::ProcessMemoryDump* pmd) const { | 717 base::trace_event::ProcessMemoryDump* pmd) const { |
| 707 lock_.AssertAcquired(); | 718 lock_.AssertAcquired(); |
| 708 | 719 |
| 709 for (const auto& image_pair : cache) { | 720 for (const auto& image_pair : cache) { |
| 710 std::string dump_name = base::StringPrintf( | 721 std::string dump_name = base::StringPrintf( |
| 711 "cc/image_memory/controller_0x%" PRIXPTR "/%s/image_%" PRIu64 "_id_%d", | 722 "cc/image_memory/controller_0x%" PRIXPTR "/%s/image_%" PRIu64 "_id_%d", |
| 712 reinterpret_cast<uintptr_t>(this), cache_name, | 723 reinterpret_cast<uintptr_t>(this), cache_name, |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 971 void SoftwareImageDecodeController::MemoryBudget::ResetUsage() { | 982 void SoftwareImageDecodeController::MemoryBudget::ResetUsage() { |
| 972 current_usage_bytes_ = 0; | 983 current_usage_bytes_ = 0; |
| 973 } | 984 } |
| 974 | 985 |
| 975 size_t SoftwareImageDecodeController::MemoryBudget::GetCurrentUsageSafe() | 986 size_t SoftwareImageDecodeController::MemoryBudget::GetCurrentUsageSafe() |
| 976 const { | 987 const { |
| 977 return current_usage_bytes_.ValueOrDie(); | 988 return current_usage_bytes_.ValueOrDie(); |
| 978 } | 989 } |
| 979 | 990 |
| 980 } // namespace cc | 991 } // namespace cc |
| OLD | NEW |