Chromium Code Reviews| Index: gpu/command_buffer/service/memory_program_cache.cc |
| diff --git a/gpu/command_buffer/service/memory_program_cache.cc b/gpu/command_buffer/service/memory_program_cache.cc |
| index 3b4fe79dd51682c7c2212114a6a18277a4da5230..8ae2acd7a7f2e7f003815ce37092c839c264bb3a 100644 |
| --- a/gpu/command_buffer/service/memory_program_cache.cc |
| +++ b/gpu/command_buffer/service/memory_program_cache.cc |
| @@ -7,8 +7,10 @@ |
| #include <stddef.h> |
| #include "base/base64.h" |
| +#include "base/bind.h" |
| #include "base/callback.h" |
| #include "base/command_line.h" |
| +#include "base/metrics/histogram_functions.h" |
| #include "base/metrics/histogram_macros.h" |
| #include "base/sha1.h" |
| #include "base/strings/string_number_conversions.h" |
| @@ -220,7 +222,10 @@ MemoryProgramCache::MemoryProgramCache( |
| disable_program_caching_for_transform_feedback), |
| curr_size_bytes_(0), |
| store_(ProgramMRUCache::NO_AUTO_EVICT), |
| - activity_flags_(activity_flags) {} |
| + activity_flags_(activity_flags), |
| + memory_pressure_listener_( |
| + base::Bind(&MemoryProgramCache::HandleMemoryPressure, |
| + base::Unretained(this))) {} |
| MemoryProgramCache::~MemoryProgramCache() {} |
| @@ -471,6 +476,22 @@ void MemoryProgramCache::LoadProgram(const std::string& program) { |
| } |
| } |
| +void MemoryProgramCache::HandleMemoryPressure( |
| + base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) { |
| + size_t limit = max_size_bytes_ / 4; |
|
vmiura
2017/06/03 04:05:32
nit: Could you add a comment why this is "max_size
ssid
2017/06/05 19:42:45
Added comment.
|
| + if (memory_pressure_level == |
| + base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) { |
| + limit = 0; |
| + } |
| + if (curr_size_bytes_ <= limit) |
| + return; |
| + size_t initial_size = curr_size_bytes_; |
| + while (curr_size_bytes_ > limit && !store_.empty()) |
| + store_.Erase(store_.rbegin()); |
| + base::UmaHistogramCounts100000("GPU.ProgramCache.MemoryReleasedOnPressure", |
| + (initial_size - curr_size_bytes_) / 1024); |
| +} |
| + |
| MemoryProgramCache::ProgramCacheValue::ProgramCacheValue( |
| GLsizei length, |
| GLenum format, |