Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1545)

Unified Diff: cc/tiles/software_image_decode_controller.cc

Issue 2364683004: cc: Add cache purging to software image decode controller. (Closed)
Patch Set: memory: update Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « cc/tiles/software_image_decode_controller.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..be626eb53e490edd03f8fda131da0c912a5be9ec 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.
-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
« no previous file with comments | « cc/tiles/software_image_decode_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698