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

Unified Diff: android_webview/browser/in_process_view_renderer.cc

Issue 25082006: [Android WebView] OnMemoryPressure to drop tile memory (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: per view callback Created 7 years, 3 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: android_webview/browser/in_process_view_renderer.cc
diff --git a/android_webview/browser/in_process_view_renderer.cc b/android_webview/browser/in_process_view_renderer.cc
index 39bd2f6b889b0d7338ee44320991b894ca6dca9e..8ab28dfb45bb581289037215d62430b93040d047 100644
--- a/android_webview/browser/in_process_view_renderer.cc
+++ b/android_webview/browser/in_process_view_renderer.cc
@@ -316,6 +316,38 @@ bool InProcessViewRenderer::RequestProcessGL() {
return client_->RequestDrawGL(NULL);
}
+void InProcessViewRenderer::OnMemoryPressure(
+ base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) {
+ // Nothing to release.
+ if (!attached_to_window_ || !compositor_ || !hardware_initialized_)
+ return;
+
+ // Do not release resources on view we expect to get DrawGL soon.
+ client_->UpdateGlobalVisibleRect();
+ if (view_visible_ && window_visible_ &&
+ !cached_global_visible_rect_.IsEmpty()) {
+ return;
+ }
+
+ // Check that the expected EGL context is current. This may not be the case if
+ // the OnMemoryPressure callback is triggered manually in Chromium code.
+ DCHECK(last_egl_context_);
+ if (eglGetCurrentContext() != last_egl_context_)
boliu 2013/10/01 20:10:48 This check is failing, so as is, this patch does n
+ return;
+
+ TRACE_EVENT0("android_webview", "OnMemoryPressure");
+ ScopedAppGLStateRestore state_restore(ScopedAppGLStateRestore::MODE_ON_TRIM);
+ gpu::InProcessCommandBuffer::ProcessGpuWorkOnCurrentThread();
+ ScopedAllowGL allow_gl;
+
+ // Just set the memory limit to 0 and drop all tiles. This will be reset to
+ // normal levels in the next DrawGL call.
+ content::SynchronousCompositorMemoryPolicy policy;
+ policy.bytes_limit = 0;
+ policy.num_resources_limit = 0;
+ compositor_->SetMemoryPolicy(policy);
+}
+
void InProcessViewRenderer::UpdateCachedGlobalVisibleRect() {
client_->UpdateGlobalVisibleRect();
}
@@ -342,8 +374,13 @@ bool InProcessViewRenderer::InitializeHwDraw() {
hardware_failed_ = !compositor_->InitializeHwDraw(gl_surface_);
hardware_initialized_ = true;
- if (hardware_failed_)
+ if (hardware_failed_) {
gl_surface_ = NULL;
+ } else {
+ memory_pressure_listener_.reset(new base::MemoryPressureListener(
+ base::Bind(&InProcessViewRenderer::OnMemoryPressure,
+ base::Unretained(this))));
+ }
return !hardware_failed_;
}
@@ -643,6 +680,7 @@ void InProcessViewRenderer::OnDetachedFromWindow() {
ScopedAllowGL allow_gl;
compositor_->ReleaseHwDraw();
hardware_initialized_ = false;
+ memory_pressure_listener_.reset();
}
gl_surface_ = NULL;
« no previous file with comments | « android_webview/browser/in_process_view_renderer.h ('k') | android_webview/browser/scoped_app_gl_state_restore.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698