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::TrimMemory(int level) { | |
| 320 // Nothing to drop. | |
| 321 if (!attached_to_window_ || !hardware_initialized_ || !compositor_) | |
| 322 return; | |
| 323 | |
| 324 // Do not release resources on view we expect to get DrawGL soon. | |
| 325 client_->UpdateGlobalVisibleRect(); | |
| 326 if (view_visible_ && window_visible_ && | |
| 327 !cached_global_visible_rect_.IsEmpty()) { | |
| 328 return; | |
| 329 } | |
| 330 | |
| 331 if (!eglGetCurrentContext()) { | |
| 332 NOTREACHED(); | |
| 333 return; | |
| 334 } | |
| 335 | |
| 336 TRACE_EVENT0("android_webview", "InProcessViewRenderer::TrimMemory"); | |
| 337 ScopedAppGLStateRestore state_restore(ScopedAppGLStateRestore::MODE_ON_TRIM); | |
| 338 gpu::InProcessCommandBuffer::ProcessGpuWorkOnCurrentThread(); | |
| 339 ScopedAllowGL allow_gl; | |
| 340 | |
| 341 // Just set the memory limit to 0 and drop all tiles. This will be reset to | |
| 342 // normal levels in the next DrawGL call. | |
| 343 content::SynchronousCompositorMemoryPolicy policy; | |
| 344 policy.bytes_limit = 0; | |
| 345 policy.num_resources_limit = 0; | |
| 346 compositor_->SetMemoryPolicy(policy); | |
| 347 ForceCompositeSW(); | |
|
boliu
2013/10/02 02:14:04
Mad hacks, but don't really have a better idea for
| |
| 348 } | |
| 349 | |
| 319 void InProcessViewRenderer::UpdateCachedGlobalVisibleRect() { | 350 void InProcessViewRenderer::UpdateCachedGlobalVisibleRect() { |
| 320 client_->UpdateGlobalVisibleRect(); | 351 client_->UpdateGlobalVisibleRect(); |
| 321 } | 352 } |
| 322 | 353 |
| 323 bool InProcessViewRenderer::OnDraw(jobject java_canvas, | 354 bool InProcessViewRenderer::OnDraw(jobject java_canvas, |
| 324 bool is_hardware_canvas, | 355 bool is_hardware_canvas, |
| 325 const gfx::Vector2d& scroll, | 356 const gfx::Vector2d& scroll, |
| 326 const gfx::Rect& clip) { | 357 const gfx::Rect& clip) { |
| 327 scroll_at_start_of_frame_ = scroll; | 358 scroll_at_start_of_frame_ = scroll; |
| 328 if (is_hardware_canvas && attached_to_window_ && HardwareEnabled()) { | 359 if (is_hardware_canvas && attached_to_window_ && HardwareEnabled()) { |
| 329 // We should be performing a hardware draw here. If we don't have the | 360 // 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 | 361 // 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. | 362 // thus return false here to clear to background color for this draw. |
| 332 return compositor_ && client_->RequestDrawGL(java_canvas); | 363 return compositor_ && client_->RequestDrawGL(java_canvas); |
| 333 } | 364 } |
| 334 // Perform a software draw | 365 // Perform a software draw |
| 335 return DrawSWInternal(java_canvas, clip); | 366 return DrawSWInternal(java_canvas, clip); |
| 336 } | 367 } |
| 337 | 368 |
| 338 bool InProcessViewRenderer::InitializeHwDraw() { | 369 bool InProcessViewRenderer::InitializeHwDraw() { |
| 339 TRACE_EVENT0("android_webview", "InitializeHwDraw"); | 370 TRACE_EVENT0("android_webview", "InitializeHwDraw"); |
| 340 DCHECK(!gl_surface_); | 371 DCHECK(!gl_surface_); |
| 341 gl_surface_ = new AwGLSurface; | 372 gl_surface_ = new AwGLSurface; |
| 342 hardware_failed_ = !compositor_->InitializeHwDraw(gl_surface_); | 373 hardware_failed_ = !compositor_->InitializeHwDraw(gl_surface_); |
| 343 hardware_initialized_ = true; | 374 hardware_initialized_ = true; |
| 344 | 375 |
| 345 if (hardware_failed_) | 376 if (hardware_failed_) { |
| 346 gl_surface_ = NULL; | 377 gl_surface_ = NULL; |
| 378 } | |
| 347 | 379 |
| 348 return !hardware_failed_; | 380 return !hardware_failed_; |
| 349 } | 381 } |
| 350 | 382 |
| 351 void InProcessViewRenderer::DrawGL(AwDrawGLInfo* draw_info) { | 383 void InProcessViewRenderer::DrawGL(AwDrawGLInfo* draw_info) { |
| 352 TRACE_EVENT0("android_webview", "InProcessViewRenderer::DrawGL"); | 384 TRACE_EVENT0("android_webview", "InProcessViewRenderer::DrawGL"); |
| 353 | 385 |
| 354 manager_key_ = g_view_renderer_manager.Get().DidDrawGL(manager_key_, this); | 386 manager_key_ = g_view_renderer_manager.Get().DidDrawGL(manager_key_, this); |
| 355 | 387 |
| 356 // We need to watch if the current Android context has changed and enforce | 388 // We need to watch if the current Android context has changed and enforce |
| 357 // a clean-up in the compositor. | 389 // a clean-up in the compositor. |
| 358 EGLContext current_context = eglGetCurrentContext(); | 390 EGLContext current_context = eglGetCurrentContext(); |
| 359 if (!current_context) { | 391 if (!current_context) { |
| 360 TRACE_EVENT_INSTANT0( | 392 TRACE_EVENT_INSTANT0( |
| 361 "android_webview", "EarlyOut_NullEGLContext", TRACE_EVENT_SCOPE_THREAD); | 393 "android_webview", "EarlyOut_NullEGLContext", TRACE_EVENT_SCOPE_THREAD); |
| 362 return; | 394 return; |
| 363 } | 395 } |
| 364 | 396 |
| 365 ScopedAppGLStateRestore state_restore(ScopedAppGLStateRestore::MODE_DRAW); | 397 ScopedAppGLStateRestore state_restore(ScopedAppGLStateRestore::MODE_DRAW); |
| 366 gpu::InProcessCommandBuffer::ProcessGpuWorkOnCurrentThread(); | 398 gpu::InProcessCommandBuffer::ProcessGpuWorkOnCurrentThread(); |
| 367 ScopedAllowGL allow_gl; | 399 ScopedAllowGL allow_gl; |
| 368 | 400 |
| 369 if (!attached_to_window_) { | 401 if (!attached_to_window_) { |
| 370 TRACE_EVENT_INSTANT0( | 402 TRACE_EVENT_INSTANT0( |
| 371 "android_webview", "EarlyOut_NotAttached", TRACE_EVENT_SCOPE_THREAD); | 403 "android_webview", "EarlyOut_NotAttached", TRACE_EVENT_SCOPE_THREAD); |
| 372 return; | 404 return; |
| 373 } | 405 } |
| 374 | 406 |
| 375 if (draw_info->mode == AwDrawGLInfo::kModeProcess) { | 407 if (draw_info->mode == AwDrawGLInfo::kModeProcess) { |
| 376 TRACE_EVENT_INSTANT0( | 408 TRACE_EVENT0("android_webview", "EarlyOut_ModeProcess"); |
|
joth
2013/10/02 10:47:01
intended edit?
boliu
2013/10/02 14:09:55
reverted
| |
| 377 "android_webview", "EarlyOut_ModeProcess", TRACE_EVENT_SCOPE_THREAD); | |
| 378 return; | 409 return; |
| 379 } | 410 } |
| 380 | 411 |
| 381 if (compositor_ && !hardware_initialized_) { | 412 if (compositor_ && !hardware_initialized_) { |
| 382 if (InitializeHwDraw()) { | 413 if (InitializeHwDraw()) { |
| 383 last_egl_context_ = current_context; | 414 last_egl_context_ = current_context; |
| 384 } else { | 415 } else { |
| 385 TRACE_EVENT_INSTANT0( | 416 TRACE_EVENT_INSTANT0( |
| 386 "android_webview", "EarlyOut_HwInitFail", TRACE_EVENT_SCOPE_THREAD); | 417 "android_webview", "EarlyOut_HwInitFail", TRACE_EVENT_SCOPE_THREAD); |
| 387 LOG(ERROR) << "WebView hardware initialization failed"; | 418 LOG(ERROR) << "WebView hardware initialization failed"; |
| (...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 862 | 893 |
| 863 void InProcessViewRenderer::FallbackTickFired() { | 894 void InProcessViewRenderer::FallbackTickFired() { |
| 864 TRACE_EVENT1("android_webview", | 895 TRACE_EVENT1("android_webview", |
| 865 "InProcessViewRenderer::FallbackTickFired", | 896 "InProcessViewRenderer::FallbackTickFired", |
| 866 "compositor_needs_continuous_invalidate_", | 897 "compositor_needs_continuous_invalidate_", |
| 867 compositor_needs_continuous_invalidate_); | 898 compositor_needs_continuous_invalidate_); |
| 868 | 899 |
| 869 // This should only be called if OnDraw or DrawGL did not come in time, which | 900 // This should only be called if OnDraw or DrawGL did not come in time, which |
| 870 // means block_invalidates_ must still be true. | 901 // means block_invalidates_ must still be true. |
| 871 DCHECK(block_invalidates_); | 902 DCHECK(block_invalidates_); |
| 872 if (compositor_needs_continuous_invalidate_ && compositor_) { | 903 if (compositor_needs_continuous_invalidate_ && compositor_) |
| 873 SkBitmapDevice device(SkBitmap::kARGB_8888_Config, 1, 1); | 904 ForceCompositeSW(); |
| 874 SkCanvas canvas(&device); | 905 } |
| 875 CompositeSW(&canvas); | 906 |
| 876 } | 907 void InProcessViewRenderer::ForceCompositeSW() { |
|
joth
2013/10/02 10:47:01
maybe ForceFakeCompostieSW() will make it clear (a
boliu
2013/10/02 14:09:55
Done.
| |
| 908 DCHECK(compositor_); | |
| 909 SkBitmapDevice device(SkBitmap::kARGB_8888_Config, 1, 1); | |
| 910 SkCanvas canvas(&device); | |
| 911 CompositeSW(&canvas); | |
| 877 } | 912 } |
| 878 | 913 |
| 879 bool InProcessViewRenderer::CompositeSW(SkCanvas* canvas) { | 914 bool InProcessViewRenderer::CompositeSW(SkCanvas* canvas) { |
| 880 DCHECK(compositor_); | 915 DCHECK(compositor_); |
| 881 | 916 |
| 882 fallback_tick_.Cancel(); | 917 fallback_tick_.Cancel(); |
| 883 block_invalidates_ = true; | 918 block_invalidates_ = true; |
| 884 bool result = compositor_->DemandDrawSw(canvas); | 919 bool result = compositor_->DemandDrawSw(canvas); |
| 885 block_invalidates_ = false; | 920 block_invalidates_ = false; |
| 886 EnsureContinuousInvalidation(NULL, false); | 921 EnsureContinuousInvalidation(NULL, false); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 925 base::StringAppendF(&str, | 960 base::StringAppendF(&str, |
| 926 "surface width height: [%d %d] ", | 961 "surface width height: [%d %d] ", |
| 927 draw_info->width, | 962 draw_info->width, |
| 928 draw_info->height); | 963 draw_info->height); |
| 929 base::StringAppendF(&str, "is_layer: %d ", draw_info->is_layer); | 964 base::StringAppendF(&str, "is_layer: %d ", draw_info->is_layer); |
| 930 } | 965 } |
| 931 return str; | 966 return str; |
| 932 } | 967 } |
| 933 | 968 |
| 934 } // namespace android_webview | 969 } // namespace android_webview |
| OLD | NEW |