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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/tiles/software_image_decode_cache.h" 5 #include "cc/tiles/software_image_decode_cache.h"
6 6
7 #include <inttypes.h> 7 #include <inttypes.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 779 matching lines...) Expand 10 before | Expand all | Expand 10 after
790 DCHECK(decoded_images_ref_counts_.find(key) == 790 DCHECK(decoded_images_ref_counts_.find(key) ==
791 decoded_images_ref_counts_.end()); 791 decoded_images_ref_counts_.end());
792 at_raster_image_it->second->Unlock(); 792 at_raster_image_it->second->Unlock();
793 decoded_images_.Erase(image_it); 793 decoded_images_.Erase(image_it);
794 decoded_images_.Put(key, std::move(at_raster_image_it->second)); 794 decoded_images_.Put(key, std::move(at_raster_image_it->second));
795 } 795 }
796 at_raster_decoded_images_.Erase(at_raster_image_it); 796 at_raster_decoded_images_.Erase(at_raster_image_it);
797 } 797 }
798 } 798 }
799 799
800 void SoftwareImageDecodeCache::ReduceCacheUsage() { 800 void SoftwareImageDecodeCache::ReduceCacheUsageUntilWithinLimit(size_t limit) {
801 TRACE_EVENT0("cc", "SoftwareImageDecodeCache::ReduceCacheUsage"); 801 TRACE_EVENT0("cc", "SoftwareImageDecodeCache::ReduceCacheUsage");
802 base::AutoLock lock(lock_); 802 size_t num_to_remove =
803 size_t num_to_remove = (decoded_images_.size() > max_items_in_cache_) 803 (decoded_images_.size() > limit) ? (decoded_images_.size() - limit) : 0;
804 ? (decoded_images_.size() - max_items_in_cache_)
805 : 0;
806 for (auto it = decoded_images_.rbegin(); 804 for (auto it = decoded_images_.rbegin();
807 num_to_remove != 0 && it != decoded_images_.rend();) { 805 num_to_remove != 0 && it != decoded_images_.rend();) {
808 if (it->second->is_locked()) { 806 if (it->second->is_locked()) {
809 ++it; 807 ++it;
810 continue; 808 continue;
811 } 809 }
812 810
813 it = decoded_images_.Erase(it); 811 it = decoded_images_.Erase(it);
814 --num_to_remove; 812 --num_to_remove;
815 } 813 }
816 } 814 }
817 815
816 void SoftwareImageDecodeCache::ReduceCacheUsage() {
817 base::AutoLock lock(lock_);
818 ReduceCacheUsageUntilWithinLimit(max_items_in_cache_);
819 }
820
818 void SoftwareImageDecodeCache::RemovePendingTask(const ImageKey& key, 821 void SoftwareImageDecodeCache::RemovePendingTask(const ImageKey& key,
819 DecodeTaskType task_type) { 822 DecodeTaskType task_type) {
820 base::AutoLock lock(lock_); 823 base::AutoLock lock(lock_);
821 switch (task_type) { 824 switch (task_type) {
822 case DecodeTaskType::USE_IN_RASTER_TASKS: 825 case DecodeTaskType::USE_IN_RASTER_TASKS:
823 pending_in_raster_image_tasks_.erase(key); 826 pending_in_raster_image_tasks_.erase(key);
824 break; 827 break;
825 case DecodeTaskType::USE_OUT_OF_RASTER_TASKS: 828 case DecodeTaskType::USE_OUT_OF_RASTER_TASKS:
826 pending_out_of_raster_image_tasks_.erase(key); 829 pending_out_of_raster_image_tasks_.erase(key);
827 break; 830 break;
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
1166 max_items_in_cache_ = kThrottledMaxItemsInCache; 1169 max_items_in_cache_ = kThrottledMaxItemsInCache;
1167 break; 1170 break;
1168 case base::MemoryState::SUSPENDED: 1171 case base::MemoryState::SUSPENDED:
1169 max_items_in_cache_ = kSuspendedMaxItemsInCache; 1172 max_items_in_cache_ = kSuspendedMaxItemsInCache;
1170 break; 1173 break;
1171 case base::MemoryState::UNKNOWN: 1174 case base::MemoryState::UNKNOWN:
1172 NOTREACHED(); 1175 NOTREACHED();
1173 return; 1176 return;
1174 } 1177 }
1175 } 1178 }
1176 ReduceCacheUsage(); 1179 }
1180
1181 void SoftwareImageDecodeCache::OnPurgeMemory() {
1182 base::AutoLock lock(lock_);
1183 ReduceCacheUsageUntilWithinLimit(0);
1177 } 1184 }
1178 1185
1179 } // namespace cc 1186 } // namespace cc
OLDNEW
« 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