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

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, 9 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
Index: cc/resources/gpu_rasterizer.cc
diff --git a/cc/resources/gpu_rasterizer.cc b/cc/resources/gpu_rasterizer.cc
index d810386da94a2c9ff36475e59590e2d79ed92787..a37c37b2742920d1153c45a75327d61e5db4783a 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;
+
+// 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,26 @@ 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),
+ maxTextures_(kMaxGaneshResourceCacheCount),
+ maxTextureBytes_(kMaxGaneshResourceCacheBytes),
+ cache_cleared_(false) {
+ ContextProvider* worker_context_provider =
vmiura 2015/04/02 19:12:34 As this is in three places, please refactor the co
sohanjg 2015/04/08 09:00:31 Done.
+ 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(*worker_context_provider->GetLock());
+
+ // Allow context to bind to current thread.
+ worker_context_provider->DetachFromThread();
+
+ GrContext* gr_context = worker_context_provider->GrContext();
+ if (gr_context)
+ gr_context->setResourceCacheLimits(maxTextures_, maxTextureBytes_);
+
+ // Allow context to bind to other threads.
+ worker_context_provider->DetachFromThread();
}
GpuRasterizer::~GpuRasterizer() {
@@ -201,4 +231,48 @@ void GpuRasterizer::AddToMultiPictureDraw(const Tile* tile,
multi_picture_draw_.add(sk_surface->getCanvas(), picture.get());
}
+void GpuRasterizer::SetZeroMemoryLimit() {
+ 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();
+
+ // Clear resource cache.
+ GrContext* gr_context = context_provider->GrContext();
+ DCHECK(gr_context);
+ gr_context->setResourceCacheLimits(0, 0);
+
+ // Allow context to bind to other threads.
+ context_provider->DetachFromThread();
+ cache_cleared_ = true;
+}
+
+void GpuRasterizer::SetDefaultMemoryLimit() {
+ if (!cache_cleared_)
+ return;
+
+ 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();
+
+ // Restore resource cache.
+ GrContext* gr_context = context_provider->GrContext();
+ DCHECK(gr_context);
+ gr_context->setResourceCacheLimits(maxTextures_, maxTextureBytes_);
+
+ // Allow context to bind to other threads.
+ context_provider->DetachFromThread();
+}
+
} // namespace cc

Powered by Google App Engine
This is Rietveld 408576698