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

Unified Diff: gpu/command_buffer/service/memory_program_cache.cc

Issue 2921653005: GLES ProgramCache listens to memory pressure (Closed)
Patch Set: low-end check only on Android. Created 3 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « gpu/command_buffer/service/memory_program_cache.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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,
« no previous file with comments | « gpu/command_buffer/service/memory_program_cache.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698