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

Side by Side Diff: cc/tiles/software_image_decode_cache.cc

Issue 2664703002: Move purging from OnMemoryState to OnPurgeMemory() in cc/ (Closed)
Patch Set: 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 765 matching lines...) Expand 10 before | Expand all | Expand 10 after
776 DCHECK(decoded_images_ref_counts_.find(key) == 776 DCHECK(decoded_images_ref_counts_.find(key) ==
777 decoded_images_ref_counts_.end()); 777 decoded_images_ref_counts_.end());
778 at_raster_image_it->second->Unlock(); 778 at_raster_image_it->second->Unlock();
779 decoded_images_.Erase(image_it); 779 decoded_images_.Erase(image_it);
780 decoded_images_.Put(key, std::move(at_raster_image_it->second)); 780 decoded_images_.Put(key, std::move(at_raster_image_it->second));
781 } 781 }
782 at_raster_decoded_images_.Erase(at_raster_image_it); 782 at_raster_decoded_images_.Erase(at_raster_image_it);
783 } 783 }
784 } 784 }
785 785
786 void SoftwareImageDecodeCache::ReduceCacheUsage() { 786 void SoftwareImageDecodeCache::ReduceCacheUsageUntilWithinLimit(size_t limit) {
787 TRACE_EVENT0("cc", "SoftwareImageDecodeCache::ReduceCacheUsage"); 787 TRACE_EVENT0("cc", "SoftwareImageDecodeCache::ReduceCacheUsage");
788 base::AutoLock lock(lock_); 788 size_t num_to_remove =
789 size_t num_to_remove = (decoded_images_.size() > max_items_in_cache_) 789 (decoded_images_.size() > limit) ? (decoded_images_.size() - limit) : 0;
790 ? (decoded_images_.size() - max_items_in_cache_)
791 : 0;
792 for (auto it = decoded_images_.rbegin(); 790 for (auto it = decoded_images_.rbegin();
793 num_to_remove != 0 && it != decoded_images_.rend();) { 791 num_to_remove != 0 && it != decoded_images_.rend();) {
794 if (it->second->is_locked()) { 792 if (it->second->is_locked()) {
795 ++it; 793 ++it;
796 continue; 794 continue;
797 } 795 }
798 796
799 it = decoded_images_.Erase(it); 797 it = decoded_images_.Erase(it);
800 --num_to_remove; 798 --num_to_remove;
801 } 799 }
802 } 800 }
803 801
802 void SoftwareImageDecodeCache::ReduceCacheUsage() {
803 base::AutoLock lock(lock_);
804 ReduceCacheUsageUntilWithinLimit(max_items_in_cache_);
805 }
806
804 void SoftwareImageDecodeCache::RemovePendingTask(const ImageKey& key, 807 void SoftwareImageDecodeCache::RemovePendingTask(const ImageKey& key,
805 DecodeTaskType task_type) { 808 DecodeTaskType task_type) {
806 base::AutoLock lock(lock_); 809 base::AutoLock lock(lock_);
807 switch (task_type) { 810 switch (task_type) {
808 case DecodeTaskType::USE_IN_RASTER_TASKS: 811 case DecodeTaskType::USE_IN_RASTER_TASKS:
809 pending_in_raster_image_tasks_.erase(key); 812 pending_in_raster_image_tasks_.erase(key);
810 break; 813 break;
811 case DecodeTaskType::USE_OUT_OF_RASTER_TASKS: 814 case DecodeTaskType::USE_OUT_OF_RASTER_TASKS:
812 pending_out_of_raster_image_tasks_.erase(key); 815 pending_out_of_raster_image_tasks_.erase(key);
813 break; 816 break;
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
1153 max_items_in_cache_ = kThrottledMaxItemsInCache; 1156 max_items_in_cache_ = kThrottledMaxItemsInCache;
1154 break; 1157 break;
1155 case base::MemoryState::SUSPENDED: 1158 case base::MemoryState::SUSPENDED:
1156 max_items_in_cache_ = kSuspendedMaxItemsInCache; 1159 max_items_in_cache_ = kSuspendedMaxItemsInCache;
1157 break; 1160 break;
1158 case base::MemoryState::UNKNOWN: 1161 case base::MemoryState::UNKNOWN:
1159 NOTREACHED(); 1162 NOTREACHED();
1160 return; 1163 return;
1161 } 1164 }
1162 } 1165 }
1163 ReduceCacheUsage(); 1166 // TODO(bashi): We are going to separate purging from state changes and we
1167 // shouldn't purge memory here (crbug.com/684287). Tentatively call
1168 // OnPurgeMemory() so that we don't break existing experiments.
1169 // (i.e. purge+suspend experiment)
1170 if (state == base::MemoryState::SUSPENDED)
1171 OnPurgeMemory();
ericrk 2017/01/30 15:58:56 This also removes the ability to handle THROTTLED
bashi 2017/01/31 19:30:56 Yes, it's intentional. I'm going to move ReduceCac
1172 }
1173
1174 void SoftwareImageDecodeCache::OnPurgeMemory() {
1175 base::AutoLock lock(lock_);
1176 ReduceCacheUsageUntilWithinLimit(0);
1164 } 1177 }
1165 1178
1166 } // namespace cc 1179 } // 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