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

Side by Side Diff: cc/tiles/gpu_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
« no previous file with comments | « cc/tiles/gpu_image_decode_cache.h ('k') | cc/tiles/gpu_image_decode_cache_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/gpu_image_decode_cache.h" 5 #include "cc/tiles/gpu_image_decode_cache.h"
6 6
7 #include <inttypes.h> 7 #include <inttypes.h>
8 8
9 #include "base/auto_reset.h"
9 #include "base/debug/alias.h" 10 #include "base/debug/alias.h"
10 #include "base/memory/discardable_memory_allocator.h" 11 #include "base/memory/discardable_memory_allocator.h"
11 #include "base/memory/memory_coordinator_client_registry.h" 12 #include "base/memory/memory_coordinator_client_registry.h"
12 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
13 #include "base/metrics/histogram_macros.h" 14 #include "base/metrics/histogram_macros.h"
14 #include "base/numerics/safe_math.h" 15 #include "base/numerics/safe_math.h"
15 #include "base/strings/stringprintf.h" 16 #include "base/strings/stringprintf.h"
16 #include "base/threading/thread_task_runner_handle.h" 17 #include "base/threading/thread_task_runner_handle.h"
17 #include "base/trace_event/memory_dump_manager.h" 18 #include "base/trace_event/memory_dump_manager.h"
18 #include "cc/debug/devtools_instrumentation.h" 19 #include "cc/debug/devtools_instrumentation.h"
(...skipping 1242 matching lines...) Expand 10 before | Expand all | Expand 10 after
1261 return image_data->decode.is_locked(); 1262 return image_data->decode.is_locked();
1262 } 1263 }
1263 1264
1264 bool GpuImageDecodeCache::IsInInUseCacheForTesting( 1265 bool GpuImageDecodeCache::IsInInUseCacheForTesting(
1265 const DrawImage& image) const { 1266 const DrawImage& image) const {
1266 auto found = in_use_cache_.find(GenerateInUseCacheKey(image)); 1267 auto found = in_use_cache_.find(GenerateInUseCacheKey(image));
1267 return found != in_use_cache_.end(); 1268 return found != in_use_cache_.end();
1268 } 1269 }
1269 1270
1270 void GpuImageDecodeCache::OnMemoryStateChange(base::MemoryState state) { 1271 void GpuImageDecodeCache::OnMemoryStateChange(base::MemoryState state) {
1271 switch (state) { 1272 memory_state_ = state;
1272 case base::MemoryState::NORMAL: 1273 }
1273 memory_state_ = state;
1274 break;
1275 case base::MemoryState::THROTTLED:
1276 case base::MemoryState::SUSPENDED: {
1277 memory_state_ = state;
1278 1274
1279 // We've just changed our memory state to a (potentially) more 1275 void GpuImageDecodeCache::OnPurgeMemory() {
1280 // restrictive one. Re-enforce cache limits. 1276 base::AutoLock lock(lock_);
1281 base::AutoLock lock(lock_); 1277 // Temporary changes |memory_state_| to free up cache as much as possible.
1282 EnsureCapacity(0); 1278 base::AutoReset<base::MemoryState> reset(&memory_state_,
1283 break; 1279 base::MemoryState::SUSPENDED);
1284 } 1280 EnsureCapacity(0);
bashi 2017/02/07 00:58:59 It seems EnsureCapacity() changes its behavior bas
ericrk 2017/02/07 19:20:14 Does the coordinator call OnMemoryStateChange(SUSP
bashi 2017/02/09 00:46:18 Thanks. I wasn't aware of the race. Current order
ericrk 2017/02/09 18:36:30 I'm good re-visitng later - once we get to enablin
1285 case base::MemoryState::UNKNOWN:
1286 // NOT_REACHED.
1287 break;
1288 }
1289 } 1281 }
1290 1282
1291 } // namespace cc 1283 } // namespace cc
OLDNEW
« no previous file with comments | « cc/tiles/gpu_image_decode_cache.h ('k') | cc/tiles/gpu_image_decode_cache_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698