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/allocator/allocator_extension.h" |
9 #include "base/memory/discardable_memory_allocator.h" | 10 #include "base/memory/discardable_memory_allocator.h" |
10 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
11 #include "base/metrics/histogram_macros.h" | 12 #include "base/metrics/histogram_macros.h" |
12 #include "base/numerics/safe_math.h" | 13 #include "base/numerics/safe_math.h" |
13 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
14 #include "base/threading/thread_task_runner_handle.h" | 15 #include "base/threading/thread_task_runner_handle.h" |
15 #include "cc/debug/devtools_instrumentation.h" | 16 #include "cc/debug/devtools_instrumentation.h" |
16 #include "cc/output/context_provider.h" | 17 #include "cc/output/context_provider.h" |
17 #include "cc/raster/tile_task.h" | 18 #include "cc/raster/tile_task.h" |
18 #include "cc/resources/resource_format_utils.h" | 19 #include "cc/resources/resource_format_utils.h" |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 context->GrContext()->threadSafeProxy()); | 352 context->GrContext()->threadSafeProxy()); |
352 } | 353 } |
353 | 354 |
354 // In certain cases, ThreadTaskRunnerHandle isn't set (Android Webview). | 355 // In certain cases, ThreadTaskRunnerHandle isn't set (Android Webview). |
355 // Don't register a dump provider in these cases. | 356 // Don't register a dump provider in these cases. |
356 if (base::ThreadTaskRunnerHandle::IsSet()) { | 357 if (base::ThreadTaskRunnerHandle::IsSet()) { |
357 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( | 358 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( |
358 this, "cc::GpuImageDecodeController", | 359 this, "cc::GpuImageDecodeController", |
359 base::ThreadTaskRunnerHandle::Get()); | 360 base::ThreadTaskRunnerHandle::Get()); |
360 } | 361 } |
| 362 memory_pressure_listener_.reset(new base::MemoryPressureListener(base::Bind( |
| 363 &GpuImageDecodeController::OnMemoryPressure, base::Unretained(this)))); |
361 } | 364 } |
362 | 365 |
363 GpuImageDecodeController::~GpuImageDecodeController() { | 366 GpuImageDecodeController::~GpuImageDecodeController() { |
364 // SetShouldAggressivelyFreeResources will zero our limits and free all | 367 // SetShouldAggressivelyFreeResources will zero our limits and free all |
365 // outstanding image memory. | 368 // outstanding image memory. |
366 SetShouldAggressivelyFreeResources(true); | 369 SetShouldAggressivelyFreeResources(true); |
367 | 370 |
368 // It is safe to unregister, even if we didn't register in the constructor. | 371 // It is safe to unregister, even if we didn't register in the constructor. |
369 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( | 372 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( |
370 this); | 373 this); |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
586 // as the owner in memory traces. | 589 // as the owner in memory traces. |
587 const int kImportance = 3; | 590 const int kImportance = 3; |
588 pmd->CreateSharedGlobalAllocatorDump(guid); | 591 pmd->CreateSharedGlobalAllocatorDump(guid); |
589 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); | 592 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); |
590 } | 593 } |
591 } | 594 } |
592 | 595 |
593 return true; | 596 return true; |
594 } | 597 } |
595 | 598 |
| 599 void GpuImageDecodeController::OnMemoryPressure( |
| 600 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) { |
| 601 SetShouldAggressivelyFreeResources(true); |
| 602 base::allocator::ReleaseFreeMemory(); |
| 603 } |
| 604 |
596 void GpuImageDecodeController::DecodeImage(const DrawImage& draw_image) { | 605 void GpuImageDecodeController::DecodeImage(const DrawImage& draw_image) { |
597 base::AutoLock lock(lock_); | 606 base::AutoLock lock(lock_); |
598 ImageData* image_data = GetImageDataForDrawImage(draw_image); | 607 ImageData* image_data = GetImageDataForDrawImage(draw_image); |
599 DCHECK(image_data); | 608 DCHECK(image_data); |
600 DCHECK(!image_data->is_at_raster); | 609 DCHECK(!image_data->is_at_raster); |
601 DecodeImageIfNecessary(draw_image, image_data); | 610 DecodeImageIfNecessary(draw_image, image_data); |
602 } | 611 } |
603 | 612 |
604 void GpuImageDecodeController::UploadImage(const DrawImage& draw_image) { | 613 void GpuImageDecodeController::UploadImage(const DrawImage& draw_image) { |
605 ContextProvider::ScopedContextLock context_lock(context_); | 614 ContextProvider::ScopedContextLock context_lock(context_); |
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1128 bool GpuImageDecodeController::DiscardableIsLockedForTesting( | 1137 bool GpuImageDecodeController::DiscardableIsLockedForTesting( |
1129 const DrawImage& image) { | 1138 const DrawImage& image) { |
1130 base::AutoLock lock(lock_); | 1139 base::AutoLock lock(lock_); |
1131 auto found = persistent_cache_.Peek(image.image()->uniqueID()); | 1140 auto found = persistent_cache_.Peek(image.image()->uniqueID()); |
1132 DCHECK(found != persistent_cache_.end()); | 1141 DCHECK(found != persistent_cache_.end()); |
1133 ImageData* image_data = found->second.get(); | 1142 ImageData* image_data = found->second.get(); |
1134 return image_data->decode.is_locked(); | 1143 return image_data->decode.is_locked(); |
1135 } | 1144 } |
1136 | 1145 |
1137 } // namespace cc | 1146 } // namespace cc |
OLD | NEW |