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

Unified Diff: cc/resources/gpu_rasterizer.cc

Issue 1016733002: cc: Free gpu resources when we are invisible or TM is oom. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review comments addressed. Created 5 years, 8 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 | « cc/resources/gpu_rasterizer.h ('k') | cc/resources/rasterizer.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/resources/gpu_rasterizer.cc
diff --git a/cc/resources/gpu_rasterizer.cc b/cc/resources/gpu_rasterizer.cc
index d810386da94a2c9ff36475e59590e2d79ed92787..5a9a8923c200434df6d9c6c2e7b8587a54503955 100644
--- a/cc/resources/gpu_rasterizer.cc
+++ b/cc/resources/gpu_rasterizer.cc
@@ -24,6 +24,17 @@
#include "third_party/skia/include/core/SkSurface.h"
#include "third_party/skia/include/gpu/GrContext.h"
+namespace {
+// The limit of the number of GPU resources we hold in the GrContext's
+// GPU cache.
+const int kMaxGaneshResourceCacheCount = 2048;
enne (OOO) 2015/04/08 17:19:34 Maybe you could make these LayerTreeSettings, and
sohanjg 2015/04/09 09:20:44 OK, but the memory limit we are maintaining in the
hendrikw 2015/04/09 15:43:45 I agree with enne (I think they meant LayerTreeHos
+
+// The limit of the bytes allocated toward GPU resources in the GrContext's
+// GPU cache.
+const size_t kMaxGaneshResourceCacheBytes = 96 * 1024 * 1024;
+
+} // namespace
+
namespace cc {
// static
@@ -46,7 +57,11 @@ GpuRasterizer::GpuRasterizer(ContextProvider* context_provider,
: resource_provider_(resource_provider),
use_distance_field_text_(use_distance_field_text),
threaded_gpu_rasterization_enabled_(threaded_gpu_rasterization_enabled),
- msaa_sample_count_(msaa_sample_count) {
+ msaa_sample_count_(msaa_sample_count),
+ max_textures_(kMaxGaneshResourceCacheCount),
+ max_texture_bytes_(kMaxGaneshResourceCacheBytes),
+ default_memory_limit_set_(true) {
+ SetGrCacheLimits(max_textures_, max_texture_bytes_);
}
GpuRasterizer::~GpuRasterizer() {
@@ -201,4 +216,32 @@ void GpuRasterizer::AddToMultiPictureDraw(const Tile* tile,
multi_picture_draw_.add(sk_surface->getCanvas(), picture.get());
}
+void GpuRasterizer::SetMemoryLimits(bool visible, size_t memory_limit_bytes) {
hendrikw 2015/04/09 15:43:45 Wouldn't it make sense to call freeGpuResources()
+ if (!visible || memory_limit_bytes == 0) {
+ SetGrCacheLimits(0, 0);
+ default_memory_limit_set_ = false;
+ } else if (!default_memory_limit_set_) {
+ SetGrCacheLimits(max_textures_, max_texture_bytes_);
+ }
+}
+
+void GpuRasterizer::SetGrCacheLimits(int textures, int texture_bytes) {
+ ContextProvider* context_provider =
+ resource_provider()->output_surface()->worker_context_provider();
+
+ // The context lock must be held while accessing the context on a
+ // worker thread.
+ base::AutoLock context_lock(*context_provider->GetLock());
+
+ // Allow context to bind to current thread.
+ context_provider->DetachFromThread();
+
+ GrContext* gr_context = context_provider->GrContext();
+ DCHECK(gr_context);
+ gr_context->setResourceCacheLimits(textures, texture_bytes);
+
+ // Allow context to bind to other threads.
+ context_provider->DetachFromThread();
+}
+
} // namespace cc
« no previous file with comments | « cc/resources/gpu_rasterizer.h ('k') | cc/resources/rasterizer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698