Chromium Code Reviews| 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; |