Commit 84109456 authored by Gyuyoung Kim's avatar Gyuyoung Kim Committed by Commit Bot

CC: Support the memory pressure handler in SoftwareImageDecodeCache

As StagingbufferPool and ResourcePool, SoftwareImageDecodeCache has been
only supporting the MemoryCoordinator. However, it is not enabled by
default. So it would be good if we support the memory pressure handler
until the MemoryCoordinator is enabled by default. Especially, it will
help low-end devices to reduce memory usage under the out-of-memory
situation.

Bug: 856527
Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: I0aace1839b9d0e056f1a2db18f5d9e652c742c5f
Reviewed-on: https://chromium-review.googlesource.com/1122016Reviewed-by: default avatarEric Karl <ericrk@chromium.org>
Commit-Queue: Gyuyoung Kim <gyuyoung.kim@lge.com>
Cr-Commit-Position: refs/heads/master@{#572154}
parent 32e75548
...@@ -172,6 +172,9 @@ SoftwareImageDecodeCache::SoftwareImageDecodeCache( ...@@ -172,6 +172,9 @@ SoftwareImageDecodeCache::SoftwareImageDecodeCache(
} }
// Register this component with base::MemoryCoordinatorClientRegistry. // Register this component with base::MemoryCoordinatorClientRegistry.
base::MemoryCoordinatorClientRegistry::GetInstance()->Register(this); base::MemoryCoordinatorClientRegistry::GetInstance()->Register(this);
memory_pressure_listener_.reset(new base::MemoryPressureListener(
base::BindRepeating(&SoftwareImageDecodeCache::OnMemoryPressure,
base::Unretained(this))));
} }
SoftwareImageDecodeCache::~SoftwareImageDecodeCache() { SoftwareImageDecodeCache::~SoftwareImageDecodeCache() {
...@@ -703,6 +706,19 @@ void SoftwareImageDecodeCache::OnPurgeMemory() { ...@@ -703,6 +706,19 @@ void SoftwareImageDecodeCache::OnPurgeMemory() {
ReduceCacheUsageUntilWithinLimit(0); ReduceCacheUsageUntilWithinLimit(0);
} }
void SoftwareImageDecodeCache::OnMemoryPressure(
base::MemoryPressureListener::MemoryPressureLevel level) {
base::AutoLock lock(lock_);
switch (level) {
case base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE:
case base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE:
break;
case base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL:
ReduceCacheUsageUntilWithinLimit(0);
break;
}
}
SoftwareImageDecodeCache::CacheEntry* SoftwareImageDecodeCache::AddCacheEntry( SoftwareImageDecodeCache::CacheEntry* SoftwareImageDecodeCache::AddCacheEntry(
const CacheKey& key) { const CacheKey& key) {
lock_.AssertAcquired(); lock_.AssertAcquired();
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/containers/mru_cache.h" #include "base/containers/mru_cache.h"
#include "base/memory/memory_coordinator_client.h" #include "base/memory/memory_coordinator_client.h"
#include "base/memory/memory_pressure_listener.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/numerics/safe_math.h" #include "base/numerics/safe_math.h"
#include "base/trace_event/memory_dump_provider.h" #include "base/trace_event/memory_dump_provider.h"
...@@ -115,6 +116,11 @@ class CC_EXPORT SoftwareImageDecodeCache ...@@ -115,6 +116,11 @@ class CC_EXPORT SoftwareImageDecodeCache
void OnMemoryStateChange(base::MemoryState state) override; void OnMemoryStateChange(base::MemoryState state) override;
void OnPurgeMemory() override; void OnPurgeMemory() override;
// TODO(gyuyoung): OnMemoryPressure is deprecated. So this should be removed
// when the memory coordinator is enabled by default.
void OnMemoryPressure(
base::MemoryPressureListener::MemoryPressureLevel level);
// Helper method to get the different tasks. Note that this should be used as // Helper method to get the different tasks. Note that this should be used as
// if it was public (ie, all of the locks need to be properly acquired). // if it was public (ie, all of the locks need to be properly acquired).
TaskResult GetTaskForImageAndRefInternal(const DrawImage& image, TaskResult GetTaskForImageAndRefInternal(const DrawImage& image,
...@@ -141,6 +147,8 @@ class CC_EXPORT SoftwareImageDecodeCache ...@@ -141,6 +147,8 @@ class CC_EXPORT SoftwareImageDecodeCache
// Decoded images and ref counts (predecode path). // Decoded images and ref counts (predecode path).
ImageMRUCache decoded_images_; ImageMRUCache decoded_images_;
std::unique_ptr<base::MemoryPressureListener> memory_pressure_listener_;
// A map of PaintImage::FrameKey to the ImageKeys for cached decodes of this // A map of PaintImage::FrameKey to the ImageKeys for cached decodes of this
// PaintImage. // PaintImage.
std::unordered_map<PaintImage::FrameKey, std::unordered_map<PaintImage::FrameKey,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment