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

Unified Diff: content/renderer/render_thread_impl.cc

Issue 2257533006: Free worker context resources on idle. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@fix-cleanup2
Patch Set: rebase Created 4 years, 4 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/test/test_context_support.cc ('k') | gpu/command_buffer/client/context_support.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/render_thread_impl.cc
diff --git a/content/renderer/render_thread_impl.cc b/content/renderer/render_thread_impl.cc
index be2f9b1376bf5c2994b23b544c0bbdf9f6e7081f..950f485cffe1baab6071fdbbfa52c0b196479eb3 100644
--- a/content/renderer/render_thread_impl.cc
+++ b/content/renderer/render_thread_impl.cc
@@ -123,6 +123,7 @@
#include "content/renderer/shared_worker/embedded_shared_worker_stub.h"
#include "gin/public/debug.h"
#include "gpu/GLES2/gl2extchromium.h"
+#include "gpu/command_buffer/client/context_support.h"
#include "gpu/command_buffer/client/shared_memory_limits.h"
#include "gpu/ipc/client/command_buffer_proxy_impl.h"
#include "gpu/ipc/client/gpu_channel_host.h"
@@ -160,6 +161,7 @@
#include "third_party/WebKit/public/web/WebView.h"
#include "third_party/icu/source/i18n/unicode/timezone.h"
#include "third_party/skia/include/core/SkGraphics.h"
+#include "third_party/skia/include/gpu/GrContext.h"
#include "ui/base/layout.h"
#include "ui/base/ui_base_switches.h"
@@ -440,6 +442,23 @@ bool IsRunningInMash() {
return cmdline->HasSwitch(switches::kIsRunningInMash);
}
+void OnSharedWorkerContextIdle(cc::ContextProvider* context_provider) {
+ // If we can't acquire the lock, someone has started using this context, so
+ // we are no longer idle.
+ base::Lock* lock = context_provider->GetLock();
+ if (!lock->Try())
+ return;
+
+ context_provider->DetachFromThread();
+ context_provider->BindToCurrentThread();
+
+ context_provider->DeleteCachedResources();
+
+ // Detach from thread to allow a new thread to attach.
+ context_provider->DetachFromThread();
+ lock->Release();
+}
+
} // namespace
// For measuring memory usage after each task. Behind a command line flag.
@@ -2126,6 +2145,13 @@ RenderThreadImpl::SharedCompositorWorkerContextProvider() {
stream_priority);
if (!shared_worker_context_provider_->BindToCurrentThread())
shared_worker_context_provider_ = nullptr;
+
+ // Set the idle callback. This callback is only called if ContextSupport
+ // is alive, so we know that the unretained worker context provider
+ // pointer will also be alive.
+ shared_worker_context_provider_->ContextSupport()->SetIdleCallback(
+ base::Bind(&OnSharedWorkerContextIdle,
+ base::Unretained(shared_worker_context_provider_.get())));
return shared_worker_context_provider_;
}
« no previous file with comments | « cc/test/test_context_support.cc ('k') | gpu/command_buffer/client/context_support.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698