OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/gpu_image_decode_controller.h" | 5 #include "cc/tiles/gpu_image_decode_controller.h" |
6 | 6 |
7 #include <inttypes.h> | 7 #include <inttypes.h> |
8 | 8 |
9 #include "base/memory/discardable_memory_allocator.h" | 9 #include "base/memory/discardable_memory_allocator.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
11 #include "base/metrics/histogram_macros.h" | 11 #include "base/metrics/histogram_macros.h" |
12 #include "base/numerics/safe_math.h" | 12 #include "base/numerics/safe_math.h" |
13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
14 #include "base/threading/thread_task_runner_handle.h" | 14 #include "base/threading/thread_task_runner_handle.h" |
15 #include "base/trace_event/memory_dump_manager.h" | 15 #include "base/trace_event/memory_dump_manager.h" |
16 #include "cc/debug/devtools_instrumentation.h" | 16 #include "cc/debug/devtools_instrumentation.h" |
17 #include "cc/output/context_provider.h" | 17 #include "cc/output/context_provider.h" |
18 #include "cc/raster/tile_task.h" | 18 #include "cc/raster/tile_task.h" |
19 #include "cc/resources/resource_format_utils.h" | 19 #include "cc/resources/resource_format_utils.h" |
20 #include "cc/tiles/mipmap_util.h" | 20 #include "cc/tiles/mipmap_util.h" |
| 21 #include "components/memory_coordinator/common/client_registry.h" |
21 #include "gpu/command_buffer/client/context_support.h" | 22 #include "gpu/command_buffer/client/context_support.h" |
22 #include "gpu/command_buffer/client/gles2_interface.h" | 23 #include "gpu/command_buffer/client/gles2_interface.h" |
23 #include "gpu_image_decode_controller.h" | 24 #include "gpu_image_decode_controller.h" |
24 #include "skia/ext/texture_handle.h" | 25 #include "skia/ext/texture_handle.h" |
25 #include "third_party/skia/include/core/SkCanvas.h" | 26 #include "third_party/skia/include/core/SkCanvas.h" |
26 #include "third_party/skia/include/core/SkRefCnt.h" | 27 #include "third_party/skia/include/core/SkRefCnt.h" |
27 #include "third_party/skia/include/core/SkSurface.h" | 28 #include "third_party/skia/include/core/SkSurface.h" |
28 #include "third_party/skia/include/gpu/GrContext.h" | 29 #include "third_party/skia/include/gpu/GrContext.h" |
29 #include "third_party/skia/include/gpu/GrTexture.h" | 30 #include "third_party/skia/include/gpu/GrTexture.h" |
30 #include "ui/gfx/skia_util.h" | 31 #include "ui/gfx/skia_util.h" |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 context->GrContext()->threadSafeProxy()); | 342 context->GrContext()->threadSafeProxy()); |
342 } | 343 } |
343 | 344 |
344 // In certain cases, ThreadTaskRunnerHandle isn't set (Android Webview). | 345 // In certain cases, ThreadTaskRunnerHandle isn't set (Android Webview). |
345 // Don't register a dump provider in these cases. | 346 // Don't register a dump provider in these cases. |
346 if (base::ThreadTaskRunnerHandle::IsSet()) { | 347 if (base::ThreadTaskRunnerHandle::IsSet()) { |
347 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( | 348 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( |
348 this, "cc::GpuImageDecodeController", | 349 this, "cc::GpuImageDecodeController", |
349 base::ThreadTaskRunnerHandle::Get()); | 350 base::ThreadTaskRunnerHandle::Get()); |
350 } | 351 } |
| 352 // Register this component with memory_coordinator::ClientRegistry. |
| 353 memory_coordinator::ClientRegistry* registry = |
| 354 memory_coordinator::ClientRegistry::GetInstance(); |
| 355 if (registry) |
| 356 registry->RegisterClient(this); |
351 } | 357 } |
352 | 358 |
353 GpuImageDecodeController::~GpuImageDecodeController() { | 359 GpuImageDecodeController::~GpuImageDecodeController() { |
354 // SetShouldAggressivelyFreeResources will zero our limits and free all | 360 // SetShouldAggressivelyFreeResources will zero our limits and free all |
355 // outstanding image memory. | 361 // outstanding image memory. |
356 SetShouldAggressivelyFreeResources(true); | 362 SetShouldAggressivelyFreeResources(true); |
357 | 363 |
358 // It is safe to unregister, even if we didn't register in the constructor. | 364 // It is safe to unregister, even if we didn't register in the constructor. |
359 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( | 365 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( |
360 this); | 366 this); |
| 367 // Unregister this component with memory_coordinator::ClientRegistry. |
| 368 memory_coordinator::ClientRegistry* registry = |
| 369 memory_coordinator::ClientRegistry::GetInstance(); |
| 370 if (registry) |
| 371 registry->UnregisterClient(this); |
361 } | 372 } |
362 | 373 |
363 bool GpuImageDecodeController::GetTaskForImageAndRef( | 374 bool GpuImageDecodeController::GetTaskForImageAndRef( |
364 const DrawImage& draw_image, | 375 const DrawImage& draw_image, |
365 const TracingInfo& tracing_info, | 376 const TracingInfo& tracing_info, |
366 scoped_refptr<TileTask>* task) { | 377 scoped_refptr<TileTask>* task) { |
367 if (SkipImage(draw_image)) { | 378 if (SkipImage(draw_image)) { |
368 *task = nullptr; | 379 *task = nullptr; |
369 return false; | 380 return false; |
370 } | 381 } |
(...skipping 747 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1118 | 1129 |
1119 bool GpuImageDecodeController::DiscardableIsLockedForTesting( | 1130 bool GpuImageDecodeController::DiscardableIsLockedForTesting( |
1120 const DrawImage& image) { | 1131 const DrawImage& image) { |
1121 base::AutoLock lock(lock_); | 1132 base::AutoLock lock(lock_); |
1122 auto found = persistent_cache_.Peek(image.image()->uniqueID()); | 1133 auto found = persistent_cache_.Peek(image.image()->uniqueID()); |
1123 DCHECK(found != persistent_cache_.end()); | 1134 DCHECK(found != persistent_cache_.end()); |
1124 ImageData* image_data = found->second.get(); | 1135 ImageData* image_data = found->second.get(); |
1125 return image_data->decode.is_locked(); | 1136 return image_data->decode.is_locked(); |
1126 } | 1137 } |
1127 | 1138 |
| 1139 void GpuImageDecodeController::OnMemoryStateChange( |
| 1140 memory_coordinator::mojom::MemoryState state) { |
| 1141 switch (state) { |
| 1142 case memory_coordinator::mojom::MemoryState::NORMAL: |
| 1143 // TODO(tasak): go back to normal state. |
| 1144 break; |
| 1145 case memory_coordinator::mojom::MemoryState::THROTTLED: |
| 1146 // TODO(tasak): make the limits of this component's caches smaller to |
| 1147 // save memory usage. |
| 1148 break; |
| 1149 case memory_coordinator::mojom::MemoryState::SUSPENDED: |
| 1150 // TODO(tasak): free this component's caches as much as possible before |
| 1151 // suspending renderer. |
| 1152 break; |
| 1153 default: |
| 1154 // NOT_REACHED. |
| 1155 break; |
| 1156 } |
| 1157 } |
| 1158 |
1128 } // namespace cc | 1159 } // namespace cc |
OLD | NEW |