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

Unified Diff: cc/tiles/software_image_decode_cache.cc

Issue 2664703002: Move purging from OnMemoryState to OnPurgeMemory() in cc/ (Closed)
Patch Set: Don't call OnPurgeMemory() in OnStateChange() Created 3 years, 10 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
Index: cc/tiles/software_image_decode_cache.cc
diff --git a/cc/tiles/software_image_decode_cache.cc b/cc/tiles/software_image_decode_cache.cc
index 53758c02552fe6e00642649291ca228f984df56b..13ed05129fc5ed5aa18d4b601f743689777f5e44 100644
--- a/cc/tiles/software_image_decode_cache.cc
+++ b/cc/tiles/software_image_decode_cache.cc
@@ -797,12 +797,10 @@ void SoftwareImageDecodeCache::UnrefAtRasterImage(const ImageKey& key) {
}
}
-void SoftwareImageDecodeCache::ReduceCacheUsage() {
+void SoftwareImageDecodeCache::ReduceCacheUsageUntilWithinLimit(size_t limit) {
TRACE_EVENT0("cc", "SoftwareImageDecodeCache::ReduceCacheUsage");
- base::AutoLock lock(lock_);
- size_t num_to_remove = (decoded_images_.size() > max_items_in_cache_)
- ? (decoded_images_.size() - max_items_in_cache_)
- : 0;
+ size_t num_to_remove =
+ (decoded_images_.size() > limit) ? (decoded_images_.size() - limit) : 0;
for (auto it = decoded_images_.rbegin();
num_to_remove != 0 && it != decoded_images_.rend();) {
if (it->second->is_locked()) {
@@ -815,6 +813,11 @@ void SoftwareImageDecodeCache::ReduceCacheUsage() {
}
}
+void SoftwareImageDecodeCache::ReduceCacheUsage() {
+ base::AutoLock lock(lock_);
+ ReduceCacheUsageUntilWithinLimit(max_items_in_cache_);
+}
+
void SoftwareImageDecodeCache::RemovePendingTask(const ImageKey& key,
DecodeTaskType task_type) {
base::AutoLock lock(lock_);
@@ -1173,7 +1176,11 @@ void SoftwareImageDecodeCache::OnMemoryStateChange(base::MemoryState state) {
return;
}
}
- ReduceCacheUsage();
+}
+
+void SoftwareImageDecodeCache::OnPurgeMemory() {
+ base::AutoLock lock(lock_);
+ ReduceCacheUsageUntilWithinLimit(0);
}
} // namespace cc
« cc/tiles/gpu_image_decode_cache.cc ('K') | « cc/tiles/software_image_decode_cache.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698