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/format_macros.h" | 13 #include "base/format_macros.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/memory/discardable_memory.h" | 15 #include "base/memory/discardable_memory.h" |
| 16 #include "base/memory/memory_coordinator_client_registry.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" |
23 #include "cc/resources/resource_format_utils.h" | 24 #include "cc/resources/resource_format_utils.h" |
24 #include "cc/tiles/mipmap_util.h" | 25 #include "cc/tiles/mipmap_util.h" |
25 #include "third_party/skia/include/core/SkCanvas.h" | 26 #include "third_party/skia/include/core/SkCanvas.h" |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 at_raster_decoded_images_(ImageMRUCache::NO_AUTO_EVICT), | 174 at_raster_decoded_images_(ImageMRUCache::NO_AUTO_EVICT), |
174 locked_images_budget_(locked_memory_limit_bytes), | 175 locked_images_budget_(locked_memory_limit_bytes), |
175 format_(format) { | 176 format_(format) { |
176 // In certain cases, ThreadTaskRunnerHandle isn't set (Android Webview). | 177 // In certain cases, ThreadTaskRunnerHandle isn't set (Android Webview). |
177 // Don't register a dump provider in these cases. | 178 // Don't register a dump provider in these cases. |
178 if (base::ThreadTaskRunnerHandle::IsSet()) { | 179 if (base::ThreadTaskRunnerHandle::IsSet()) { |
179 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( | 180 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( |
180 this, "cc::SoftwareImageDecodeController", | 181 this, "cc::SoftwareImageDecodeController", |
181 base::ThreadTaskRunnerHandle::Get()); | 182 base::ThreadTaskRunnerHandle::Get()); |
182 } | 183 } |
| 184 // Register this component with base::MemoryCoordinatorClientRegistry. |
| 185 base::MemoryCoordinatorClientRegistry::GetInstance()->Register(this); |
183 } | 186 } |
184 | 187 |
185 SoftwareImageDecodeController::~SoftwareImageDecodeController() { | 188 SoftwareImageDecodeController::~SoftwareImageDecodeController() { |
186 DCHECK_EQ(0u, decoded_images_ref_counts_.size()); | 189 DCHECK_EQ(0u, decoded_images_ref_counts_.size()); |
187 DCHECK_EQ(0u, at_raster_decoded_images_ref_counts_.size()); | 190 DCHECK_EQ(0u, at_raster_decoded_images_ref_counts_.size()); |
188 | 191 |
189 // It is safe to unregister, even if we didn't register in the constructor. | 192 // It is safe to unregister, even if we didn't register in the constructor. |
190 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( | 193 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( |
191 this); | 194 this); |
| 195 // Unregister this component with memory_coordinator::ClientRegistry. |
| 196 base::MemoryCoordinatorClientRegistry::GetInstance()->Unregister(this); |
192 } | 197 } |
193 | 198 |
194 bool SoftwareImageDecodeController::GetTaskForImageAndRef( | 199 bool SoftwareImageDecodeController::GetTaskForImageAndRef( |
195 const DrawImage& image, | 200 const DrawImage& image, |
196 const TracingInfo& tracing_info, | 201 const TracingInfo& tracing_info, |
197 scoped_refptr<TileTask>* task) { | 202 scoped_refptr<TileTask>* task) { |
198 // If the image already exists or if we're going to create a task for it, then | 203 // If the image already exists or if we're going to create a task for it, then |
199 // we'll likely need to ref this image (the exception is if we're prerolling | 204 // we'll likely need to ref this image (the exception is if we're prerolling |
200 // the image only). That means the image is or will be in the cache. When the | 205 // the image only). That means the image is or will be in the cache. When the |
201 // ref goes to 0, it will be unpinned but will remain in the cache. If the | 206 // ref goes to 0, it will be unpinned but will remain in the cache. If the |
(...skipping 869 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1071 | 1076 |
1072 void SoftwareImageDecodeController::MemoryBudget::ResetUsage() { | 1077 void SoftwareImageDecodeController::MemoryBudget::ResetUsage() { |
1073 current_usage_bytes_ = 0; | 1078 current_usage_bytes_ = 0; |
1074 } | 1079 } |
1075 | 1080 |
1076 size_t SoftwareImageDecodeController::MemoryBudget::GetCurrentUsageSafe() | 1081 size_t SoftwareImageDecodeController::MemoryBudget::GetCurrentUsageSafe() |
1077 const { | 1082 const { |
1078 return current_usage_bytes_.ValueOrDie(); | 1083 return current_usage_bytes_.ValueOrDie(); |
1079 } | 1084 } |
1080 | 1085 |
| 1086 void SoftwareImageDecodeController::OnMemoryStateChange( |
| 1087 base::MemoryState state) { |
| 1088 switch (state) { |
| 1089 case base::MemoryState::NORMAL: |
| 1090 // TODO(tasak): go back to normal state. |
| 1091 break; |
| 1092 case base::MemoryState::THROTTLED: |
| 1093 // TODO(tasak): make the limits of this component's caches smaller to |
| 1094 // save memory usage. |
| 1095 break; |
| 1096 case base::MemoryState::SUSPENDED: |
| 1097 // TODO(tasak): free this component's caches as much as possible before |
| 1098 // suspending renderer. |
| 1099 break; |
| 1100 case base::MemoryState::UNKNOWN: |
| 1101 // NOT_REACHED. |
| 1102 break; |
| 1103 } |
| 1104 } |
| 1105 |
1081 } // namespace cc | 1106 } // namespace cc |
OLD | NEW |