Commit ac08f57b authored by vmpstr's avatar vmpstr Committed by Commit bot

cc: Add cache purging to software image decode controller.

This patch adds code that reacts to memory state change signals to
purge unlocked discardable memory when we're throttled or suspended.

R=ericrk@chromium.org
CQ_INCLUDE_TRYBOTS=master.tryserver.blink:linux_precise_blink_rel

Review-Url: https://codereview.chromium.org/2364683004
Cr-Commit-Position: refs/heads/master@{#420750}
parent 26ed6abe
......@@ -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.
const size_t kMaxItemsInCache = 1000;
// Depending on the memory state of the system, we limit the amount of items
// differently.
const size_t kNormalMaxItemsInCache = 1000;
const size_t kThrottledMaxItemsInCache = 100;
const size_t kSuspendedMaxItemsInCache = 0;
// 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.
......@@ -173,7 +177,8 @@ SoftwareImageDecodeController::SoftwareImageDecodeController(
: decoded_images_(ImageMRUCache::NO_AUTO_EVICT),
at_raster_decoded_images_(ImageMRUCache::NO_AUTO_EVICT),
locked_images_budget_(locked_memory_limit_bytes),
format_(format) {
format_(format),
max_items_in_cache_(kNormalMaxItemsInCache) {
// In certain cases, ThreadTaskRunnerHandle isn't set (Android Webview).
// Don't register a dump provider in these cases.
if (base::ThreadTaskRunnerHandle::IsSet()) {
......@@ -747,8 +752,8 @@ 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)
size_t num_to_remove = (decoded_images_.size() > max_items_in_cache_)
? (decoded_images_.size() - max_items_in_cache_)
: 0;
for (auto it = decoded_images_.rbegin();
num_to_remove != 0 && it != decoded_images_.rend();) {
......@@ -1085,22 +1090,24 @@ size_t SoftwareImageDecodeController::MemoryBudget::GetCurrentUsageSafe()
void SoftwareImageDecodeController::OnMemoryStateChange(
base::MemoryState state) {
switch (state) {
case base::MemoryState::NORMAL:
// TODO(tasak): go back to normal state.
break;
case base::MemoryState::THROTTLED:
// TODO(tasak): make the limits of this component's caches smaller to
// save memory usage.
break;
case base::MemoryState::SUSPENDED:
// TODO(tasak): free this component's caches as much as possible before
// suspending renderer.
break;
case base::MemoryState::UNKNOWN:
// NOT_REACHED.
break;
{
base::AutoLock hold(lock_);
switch (state) {
case base::MemoryState::NORMAL:
max_items_in_cache_ = kNormalMaxItemsInCache;
break;
case base::MemoryState::THROTTLED:
max_items_in_cache_ = kThrottledMaxItemsInCache;
break;
case base::MemoryState::SUSPENDED:
max_items_in_cache_ = kSuspendedMaxItemsInCache;
break;
case base::MemoryState::UNKNOWN:
NOTREACHED();
return;
}
}
ReduceCacheUsage();
}
} // namespace cc
......@@ -288,6 +288,7 @@ class CC_EXPORT SoftwareImageDecodeController
MemoryBudget locked_images_budget_;
ResourceFormat format_;
size_t max_items_in_cache_;
// Used to uniquely identify DecodedImages for memory traces.
base::AtomicSequenceNumber next_tracing_id_;
......
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