| 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..965c4472d632bfa5d2a3f9866c73d22b2f42fcce 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,23 @@ void MemoryProgramCache::LoadProgram(const std::string& program) {
|
| }
|
| }
|
|
|
| +void MemoryProgramCache::HandleMemoryPressure(
|
| + base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) {
|
| + // Set a low limit on cache size for MEMORY_PRESSURE_LEVEL_MODERATE.
|
| + size_t limit = max_size_bytes_ / 4;
|
| + 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());
|
| + UMA_HISTOGRAM_COUNTS_100000("GPU.ProgramCache.MemoryReleasedOnPressure",
|
| + (initial_size - curr_size_bytes_) / 1024);
|
| +}
|
| +
|
| MemoryProgramCache::ProgramCacheValue::ProgramCacheValue(
|
| GLsizei length,
|
| GLenum format,
|
|
|