| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <functional> | 10 #include <functional> |
| 11 | 11 |
| 12 #include "base/format_macros.h" | 12 #include "base/format_macros.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/discardable_memory.h" | 14 #include "base/memory/discardable_memory.h" |
| 15 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
| 16 #include "base/metrics/histogram_macros.h" | 16 #include "base/metrics/histogram_macros.h" |
| 17 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
| 18 #include "base/threading/thread_task_runner_handle.h" | 18 #include "base/threading/thread_task_runner_handle.h" |
| 19 #include "base/trace_event/memory_dump_manager.h" | 19 #include "base/trace_event/memory_dump_manager.h" |
| 20 #include "cc/debug/devtools_instrumentation.h" | 20 #include "cc/debug/devtools_instrumentation.h" |
| 21 #include "cc/raster/tile_task.h" | 21 #include "cc/raster/tile_task.h" |
| 22 #include "third_party/skia/include/core/SkCanvas.h" | 22 #include "third_party/skia/include/core/SkCanvas.h" |
| 23 #include "third_party/skia/include/core/SkImage.h" | 23 #include "third_party/skia/include/core/SkImage.h" |
| 24 #include "third_party/skia/include/core/SkPixmap.h" | 24 #include "third_party/skia/include/core/SkPixmap.h" |
| 25 #include "ui/gfx/skia_util.h" | 25 #include "ui/gfx/skia_util.h" |
| 26 | 26 |
| 27 namespace cc { | 27 namespace cc { |
| 28 namespace { | 28 namespace { |
| 29 | 29 |
| 30 // The amount of memory we can lock ahead of time (128MB). This limit is only | |
| 31 // used to inform the caller of the amount of space available in the cache. The | |
| 32 // caller can still request tasks which can cause this limit to be breached. | |
| 33 const size_t kLockedMemoryLimitBytes = 128 * 1024 * 1024; | |
| 34 | |
| 35 // The largest single high quality image to try and process. Images above this | 30 // The largest single high quality image to try and process. Images above this |
| 36 // size will drop down to medium quality. | 31 // size will drop down to medium quality. |
| 37 const size_t kMaxHighQualityImageSizeBytes = 64 * 1024 * 1024; | 32 const size_t kMaxHighQualityImageSizeBytes = 64 * 1024 * 1024; |
| 38 | 33 |
| 39 // The number of entries to keep around in the cache. This limit can be breached | 34 // The number of entries to keep around in the cache. This limit can be breached |
| 40 // if more items are locked. That is, locked items ignore this limit. | 35 // if more items are locked. That is, locked items ignore this limit. |
| 41 const size_t kMaxItemsInCache = 1000; | 36 const size_t kMaxItemsInCache = 1000; |
| 42 | 37 |
| 43 class AutoRemoveKeyFromTaskMap { | 38 class AutoRemoveKeyFromTaskMap { |
| 44 public: | 39 public: |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 success); | 173 success); |
| 179 case TilePriority::EVENTUALLY: | 174 case TilePriority::EVENTUALLY: |
| 180 UMA_HISTOGRAM_BOOLEAN( | 175 UMA_HISTOGRAM_BOOLEAN( |
| 181 "Renderer4.LockExistingCachedImage.Software.EVENTUALLY", success); | 176 "Renderer4.LockExistingCachedImage.Software.EVENTUALLY", success); |
| 182 } | 177 } |
| 183 } | 178 } |
| 184 | 179 |
| 185 } // namespace | 180 } // namespace |
| 186 | 181 |
| 187 SoftwareImageDecodeController::SoftwareImageDecodeController( | 182 SoftwareImageDecodeController::SoftwareImageDecodeController( |
| 188 ResourceFormat format) | 183 ResourceFormat format, |
| 184 size_t locked_memory_limit_bytes) |
| 189 : decoded_images_(ImageMRUCache::NO_AUTO_EVICT), | 185 : decoded_images_(ImageMRUCache::NO_AUTO_EVICT), |
| 190 at_raster_decoded_images_(ImageMRUCache::NO_AUTO_EVICT), | 186 at_raster_decoded_images_(ImageMRUCache::NO_AUTO_EVICT), |
| 191 locked_images_budget_(kLockedMemoryLimitBytes), | 187 locked_images_budget_(locked_memory_limit_bytes), |
| 192 format_(format) { | 188 format_(format) { |
| 193 // In certain cases, ThreadTaskRunnerHandle isn't set (Android Webview). | 189 // In certain cases, ThreadTaskRunnerHandle isn't set (Android Webview). |
| 194 // Don't register a dump provider in these cases. | 190 // Don't register a dump provider in these cases. |
| 195 if (base::ThreadTaskRunnerHandle::IsSet()) { | 191 if (base::ThreadTaskRunnerHandle::IsSet()) { |
| 196 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( | 192 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( |
| 197 this, "cc::SoftwareImageDecodeController", | 193 this, "cc::SoftwareImageDecodeController", |
| 198 base::ThreadTaskRunnerHandle::Get()); | 194 base::ThreadTaskRunnerHandle::Get()); |
| 199 } | 195 } |
| 200 } | 196 } |
| 201 | 197 |
| 202 SoftwareImageDecodeController::SoftwareImageDecodeController() | |
| 203 : SoftwareImageDecodeController(RGBA_8888) {} | |
| 204 | |
| 205 SoftwareImageDecodeController::~SoftwareImageDecodeController() { | 198 SoftwareImageDecodeController::~SoftwareImageDecodeController() { |
| 206 DCHECK_EQ(0u, decoded_images_ref_counts_.size()); | 199 DCHECK_EQ(0u, decoded_images_ref_counts_.size()); |
| 207 DCHECK_EQ(0u, at_raster_decoded_images_ref_counts_.size()); | 200 DCHECK_EQ(0u, at_raster_decoded_images_ref_counts_.size()); |
| 208 | 201 |
| 209 // It is safe to unregister, even if we didn't register in the constructor. | 202 // It is safe to unregister, even if we didn't register in the constructor. |
| 210 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( | 203 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( |
| 211 this); | 204 this); |
| 212 } | 205 } |
| 213 | 206 |
| 214 bool SoftwareImageDecodeController::GetTaskForImageAndRef( | 207 bool SoftwareImageDecodeController::GetTaskForImageAndRef( |
| (...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 768 | 761 |
| 769 void SoftwareImageDecodeController::SanityCheckState(int line, | 762 void SoftwareImageDecodeController::SanityCheckState(int line, |
| 770 bool lock_acquired) { | 763 bool lock_acquired) { |
| 771 #if DCHECK_IS_ON() | 764 #if DCHECK_IS_ON() |
| 772 if (!lock_acquired) { | 765 if (!lock_acquired) { |
| 773 base::AutoLock lock(lock_); | 766 base::AutoLock lock(lock_); |
| 774 SanityCheckState(line, true); | 767 SanityCheckState(line, true); |
| 775 return; | 768 return; |
| 776 } | 769 } |
| 777 | 770 |
| 778 MemoryBudget budget(kLockedMemoryLimitBytes); | 771 MemoryBudget budget(locked_images_budget_.total_limit_bytes()); |
| 779 for (const auto& image_pair : decoded_images_) { | 772 for (const auto& image_pair : decoded_images_) { |
| 780 const auto& key = image_pair.first; | 773 const auto& key = image_pair.first; |
| 781 const auto& image = image_pair.second; | 774 const auto& image = image_pair.second; |
| 782 | 775 |
| 783 auto ref_it = decoded_images_ref_counts_.find(key); | 776 auto ref_it = decoded_images_ref_counts_.find(key); |
| 784 if (image->is_locked()) { | 777 if (image->is_locked()) { |
| 785 budget.AddUsage(key.locked_bytes()); | 778 budget.AddUsage(key.locked_bytes()); |
| 786 DCHECK(ref_it != decoded_images_ref_counts_.end()) << line; | 779 DCHECK(ref_it != decoded_images_ref_counts_.end()) << line; |
| 787 } else { | 780 } else { |
| 788 DCHECK(ref_it == decoded_images_ref_counts_.end() || | 781 DCHECK(ref_it == decoded_images_ref_counts_.end() || |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 971 void SoftwareImageDecodeController::MemoryBudget::ResetUsage() { | 964 void SoftwareImageDecodeController::MemoryBudget::ResetUsage() { |
| 972 current_usage_bytes_ = 0; | 965 current_usage_bytes_ = 0; |
| 973 } | 966 } |
| 974 | 967 |
| 975 size_t SoftwareImageDecodeController::MemoryBudget::GetCurrentUsageSafe() | 968 size_t SoftwareImageDecodeController::MemoryBudget::GetCurrentUsageSafe() |
| 976 const { | 969 const { |
| 977 return current_usage_bytes_.ValueOrDie(); | 970 return current_usage_bytes_.ValueOrDie(); |
| 978 } | 971 } |
| 979 | 972 |
| 980 } // namespace cc | 973 } // namespace cc |
| OLD | NEW |