Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "android_webview/browser/in_process_view_renderer.h" | 5 #include "android_webview/browser/in_process_view_renderer.h" |
| 6 | 6 |
| 7 #include <android/bitmap.h> | 7 #include <android/bitmap.h> |
| 8 | 8 |
| 9 #include "android_webview/browser/aw_gl_surface.h" | 9 #include "android_webview/browser/aw_gl_surface.h" |
| 10 #include "android_webview/browser/scoped_app_gl_state_restore.h" | 10 #include "android_webview/browser/scoped_app_gl_state_restore.h" |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 309 std::stringstream size; | 309 std::stringstream size; |
| 310 size << default_tile_size; | 310 size << default_tile_size; |
| 311 cl->AppendSwitchASCII(switches::kDefaultTileWidth, size.str()); | 311 cl->AppendSwitchASCII(switches::kDefaultTileWidth, size.str()); |
| 312 cl->AppendSwitchASCII(switches::kDefaultTileHeight, size.str()); | 312 cl->AppendSwitchASCII(switches::kDefaultTileHeight, size.str()); |
| 313 } | 313 } |
| 314 | 314 |
| 315 bool InProcessViewRenderer::RequestProcessGL() { | 315 bool InProcessViewRenderer::RequestProcessGL() { |
| 316 return client_->RequestDrawGL(NULL); | 316 return client_->RequestDrawGL(NULL); |
| 317 } | 317 } |
| 318 | 318 |
| 319 void InProcessViewRenderer::OnMemoryPressure( | |
| 320 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) { | |
| 321 // Nothing to release. | |
| 322 if (!attached_to_window_ || !compositor_ || !hardware_initialized_) | |
| 323 return; | |
| 324 | |
| 325 // Do not release resources on view we expect to get DrawGL soon. | |
| 326 client_->UpdateGlobalVisibleRect(); | |
| 327 if (view_visible_ && window_visible_ && | |
| 328 !cached_global_visible_rect_.IsEmpty()) { | |
| 329 return; | |
| 330 } | |
| 331 | |
| 332 // Check that the expected EGL context is current. This may not be the case if | |
| 333 // the OnMemoryPressure callback is triggered manually in Chromium code. | |
| 334 DCHECK(last_egl_context_); | |
| 335 if (eglGetCurrentContext() != last_egl_context_) | |
|
boliu
2013/10/01 20:10:48
This check is failing, so as is, this patch does n
| |
| 336 return; | |
| 337 | |
| 338 TRACE_EVENT0("android_webview", "OnMemoryPressure"); | |
| 339 ScopedAppGLStateRestore state_restore(ScopedAppGLStateRestore::MODE_ON_TRIM); | |
| 340 gpu::InProcessCommandBuffer::ProcessGpuWorkOnCurrentThread(); | |
| 341 ScopedAllowGL allow_gl; | |
| 342 | |
| 343 // Just set the memory limit to 0 and drop all tiles. This will be reset to | |
| 344 // normal levels in the next DrawGL call. | |
| 345 content::SynchronousCompositorMemoryPolicy policy; | |
| 346 policy.bytes_limit = 0; | |
| 347 policy.num_resources_limit = 0; | |
| 348 compositor_->SetMemoryPolicy(policy); | |
| 349 } | |
| 350 | |
| 319 void InProcessViewRenderer::UpdateCachedGlobalVisibleRect() { | 351 void InProcessViewRenderer::UpdateCachedGlobalVisibleRect() { |
| 320 client_->UpdateGlobalVisibleRect(); | 352 client_->UpdateGlobalVisibleRect(); |
| 321 } | 353 } |
| 322 | 354 |
| 323 bool InProcessViewRenderer::OnDraw(jobject java_canvas, | 355 bool InProcessViewRenderer::OnDraw(jobject java_canvas, |
| 324 bool is_hardware_canvas, | 356 bool is_hardware_canvas, |
| 325 const gfx::Vector2d& scroll, | 357 const gfx::Vector2d& scroll, |
| 326 const gfx::Rect& clip) { | 358 const gfx::Rect& clip) { |
| 327 scroll_at_start_of_frame_ = scroll; | 359 scroll_at_start_of_frame_ = scroll; |
| 328 if (is_hardware_canvas && attached_to_window_ && HardwareEnabled()) { | 360 if (is_hardware_canvas && attached_to_window_ && HardwareEnabled()) { |
| 329 // We should be performing a hardware draw here. If we don't have the | 361 // We should be performing a hardware draw here. If we don't have the |
| 330 // comositor yet or if RequestDrawGL fails, it means we failed this draw and | 362 // comositor yet or if RequestDrawGL fails, it means we failed this draw and |
| 331 // thus return false here to clear to background color for this draw. | 363 // thus return false here to clear to background color for this draw. |
| 332 return compositor_ && client_->RequestDrawGL(java_canvas); | 364 return compositor_ && client_->RequestDrawGL(java_canvas); |
| 333 } | 365 } |
| 334 // Perform a software draw | 366 // Perform a software draw |
| 335 return DrawSWInternal(java_canvas, clip); | 367 return DrawSWInternal(java_canvas, clip); |
| 336 } | 368 } |
| 337 | 369 |
| 338 bool InProcessViewRenderer::InitializeHwDraw() { | 370 bool InProcessViewRenderer::InitializeHwDraw() { |
| 339 TRACE_EVENT0("android_webview", "InitializeHwDraw"); | 371 TRACE_EVENT0("android_webview", "InitializeHwDraw"); |
| 340 DCHECK(!gl_surface_); | 372 DCHECK(!gl_surface_); |
| 341 gl_surface_ = new AwGLSurface; | 373 gl_surface_ = new AwGLSurface; |
| 342 hardware_failed_ = !compositor_->InitializeHwDraw(gl_surface_); | 374 hardware_failed_ = !compositor_->InitializeHwDraw(gl_surface_); |
| 343 hardware_initialized_ = true; | 375 hardware_initialized_ = true; |
| 344 | 376 |
| 345 if (hardware_failed_) | 377 if (hardware_failed_) { |
| 346 gl_surface_ = NULL; | 378 gl_surface_ = NULL; |
| 379 } else { | |
| 380 memory_pressure_listener_.reset(new base::MemoryPressureListener( | |
| 381 base::Bind(&InProcessViewRenderer::OnMemoryPressure, | |
| 382 base::Unretained(this)))); | |
| 383 } | |
| 347 | 384 |
| 348 return !hardware_failed_; | 385 return !hardware_failed_; |
| 349 } | 386 } |
| 350 | 387 |
| 351 void InProcessViewRenderer::DrawGL(AwDrawGLInfo* draw_info) { | 388 void InProcessViewRenderer::DrawGL(AwDrawGLInfo* draw_info) { |
| 352 TRACE_EVENT0("android_webview", "InProcessViewRenderer::DrawGL"); | 389 TRACE_EVENT0("android_webview", "InProcessViewRenderer::DrawGL"); |
| 353 | 390 |
| 354 manager_key_ = g_view_renderer_manager.Get().DidDrawGL(manager_key_, this); | 391 manager_key_ = g_view_renderer_manager.Get().DidDrawGL(manager_key_, this); |
| 355 | 392 |
| 356 // We need to watch if the current Android context has changed and enforce | 393 // We need to watch if the current Android context has changed and enforce |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 636 NoLongerExpectsDrawGL(); | 673 NoLongerExpectsDrawGL(); |
| 637 if (hardware_initialized_) { | 674 if (hardware_initialized_) { |
| 638 DCHECK(compositor_); | 675 DCHECK(compositor_); |
| 639 | 676 |
| 640 ScopedAppGLStateRestore state_restore( | 677 ScopedAppGLStateRestore state_restore( |
| 641 ScopedAppGLStateRestore::MODE_DETACH_FROM_WINDOW); | 678 ScopedAppGLStateRestore::MODE_DETACH_FROM_WINDOW); |
| 642 gpu::InProcessCommandBuffer::ProcessGpuWorkOnCurrentThread(); | 679 gpu::InProcessCommandBuffer::ProcessGpuWorkOnCurrentThread(); |
| 643 ScopedAllowGL allow_gl; | 680 ScopedAllowGL allow_gl; |
| 644 compositor_->ReleaseHwDraw(); | 681 compositor_->ReleaseHwDraw(); |
| 645 hardware_initialized_ = false; | 682 hardware_initialized_ = false; |
| 683 memory_pressure_listener_.reset(); | |
| 646 } | 684 } |
| 647 | 685 |
| 648 gl_surface_ = NULL; | 686 gl_surface_ = NULL; |
| 649 attached_to_window_ = false; | 687 attached_to_window_ = false; |
| 650 } | 688 } |
| 651 | 689 |
| 652 bool InProcessViewRenderer::IsAttachedToWindow() { | 690 bool InProcessViewRenderer::IsAttachedToWindow() { |
| 653 return attached_to_window_; | 691 return attached_to_window_; |
| 654 } | 692 } |
| 655 | 693 |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 925 base::StringAppendF(&str, | 963 base::StringAppendF(&str, |
| 926 "surface width height: [%d %d] ", | 964 "surface width height: [%d %d] ", |
| 927 draw_info->width, | 965 draw_info->width, |
| 928 draw_info->height); | 966 draw_info->height); |
| 929 base::StringAppendF(&str, "is_layer: %d ", draw_info->is_layer); | 967 base::StringAppendF(&str, "is_layer: %d ", draw_info->is_layer); |
| 930 } | 968 } |
| 931 return str; | 969 return str; |
| 932 } | 970 } |
| 933 | 971 |
| 934 } // namespace android_webview | 972 } // namespace android_webview |
| OLD | NEW |