Index: cc/tiles/software_image_decode_controller.cc |
diff --git a/cc/tiles/software_image_decode_controller.cc b/cc/tiles/software_image_decode_controller.cc |
index bca4e99010465dde00a3a517f0164d4ecdca1f33..8588c12982025aca2ba5567a22330879beee7c0c 100644 |
--- a/cc/tiles/software_image_decode_controller.cc |
+++ b/cc/tiles/software_image_decode_controller.cc |
@@ -37,7 +37,11 @@ const size_t kMaxHighQualityImageSizeBytes = 64 * 1024 * 1024; |
// The number of entries to keep around in the cache. This limit can be breached |
// if more items are locked. That is, locked items ignore this limit. |
+// Depending on the memory state of the system, we limit the amount of items |
+// differently. |
const size_t kMaxItemsInCache = 1000; |
+const size_t kThrottledMaxItemsInCache = 100; |
+const size_t kSuspectedMaxItemsInCache = 0; |
ericrk
2016/09/23 20:18:52
I suspect you meant suspended :D
|
// If the size of the original sized image breaches kMemoryRatioToSubrect but we |
// don't need to scale the image, consider caching only the needed subrect. |
@@ -747,8 +751,13 @@ void SoftwareImageDecodeController::UnrefAtRasterImage(const ImageKey& key) { |
void SoftwareImageDecodeController::ReduceCacheUsage() { |
TRACE_EVENT0("cc", "SoftwareImageDecodeController::ReduceCacheUsage"); |
base::AutoLock lock(lock_); |
- size_t num_to_remove = (decoded_images_.size() > kMaxItemsInCache) |
- ? (decoded_images_.size() - kMaxItemsInCache) |
+ ReduceCacheUsageInternal(kMaxItemsInCache); |
+} |
+ |
+void SoftwareImageDecodeController::ReduceCacheUsageInternal(size_t max_items) { |
+ lock_.AssertAcquired(); |
+ size_t num_to_remove = (decoded_images_.size() > max_items) |
+ ? (decoded_images_.size() - max_items) |
: 0; |
for (auto it = decoded_images_.rbegin(); |
num_to_remove != 0 && it != decoded_images_.rend();) { |
@@ -1085,22 +1094,23 @@ size_t SoftwareImageDecodeController::MemoryBudget::GetCurrentUsageSafe() |
void SoftwareImageDecodeController::OnMemoryStateChange( |
base::MemoryState state) { |
+ size_t num_items_in_cache = kMaxItemsInCache; |
switch (state) { |
case base::MemoryState::NORMAL: |
- // TODO(tasak): go back to normal state. |
- break; |
+ // Nothing to do here. |
+ return; |
case base::MemoryState::THROTTLED: |
- // TODO(tasak): make the limits of this component's caches smaller to |
- // save memory usage. |
+ num_items_in_cache = kThrottledMaxItemsInCache; |
ericrk
2016/09/23 20:18:52
One potential issue is that, if we continue operat
|
break; |
case base::MemoryState::SUSPENDED: |
- // TODO(tasak): free this component's caches as much as possible before |
- // suspending renderer. |
+ num_items_in_cache = kSuspectedMaxItemsInCache; |
break; |
case base::MemoryState::UNKNOWN: |
- // NOT_REACHED. |
- break; |
+ NOTREACHED(); |
+ return; |
} |
+ base::AutoLock hold(lock_); |
+ ReduceCacheUsageInternal(num_items_in_cache); |
} |
} // namespace cc |