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" | |
| 10 #include "android_webview/browser/gl_surface_factory.h" | |
| 9 #include "android_webview/browser/scoped_app_gl_state_restore.h" | 11 #include "android_webview/browser/scoped_app_gl_state_restore.h" |
| 10 #include "android_webview/common/aw_switches.h" | 12 #include "android_webview/common/aw_switches.h" |
| 11 #include "android_webview/public/browser/draw_gl.h" | 13 #include "android_webview/public/browser/draw_gl.h" |
| 12 #include "android_webview/public/browser/draw_sw.h" | 14 #include "android_webview/public/browser/draw_sw.h" |
| 13 #include "base/android/jni_android.h" | 15 #include "base/android/jni_android.h" |
| 14 #include "base/auto_reset.h" | 16 #include "base/auto_reset.h" |
| 15 #include "base/command_line.h" | 17 #include "base/command_line.h" |
| 16 #include "base/debug/trace_event.h" | 18 #include "base/debug/trace_event.h" |
| 17 #include "base/lazy_instance.h" | 19 #include "base/lazy_instance.h" |
| 18 #include "base/logging.h" | 20 #include "base/logging.h" |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 179 void BrowserViewRenderer::SetAwDrawSWFunctionTable( | 181 void BrowserViewRenderer::SetAwDrawSWFunctionTable( |
| 180 AwDrawSWFunctionTable* table) { | 182 AwDrawSWFunctionTable* table) { |
| 181 g_sw_draw_functions = table; | 183 g_sw_draw_functions = table; |
| 182 g_is_skia_version_compatible = | 184 g_is_skia_version_compatible = |
| 183 g_sw_draw_functions->is_skia_version_compatible(&SkGraphics::GetVersion); | 185 g_sw_draw_functions->is_skia_version_compatible(&SkGraphics::GetVersion); |
| 184 LOG_IF(WARNING, !g_is_skia_version_compatible) | 186 LOG_IF(WARNING, !g_is_skia_version_compatible) |
| 185 << "Skia versions are not compatible, rendering performance will suffer."; | 187 << "Skia versions are not compatible, rendering performance will suffer."; |
| 186 | 188 |
| 187 gpu::InProcessCommandBuffer::SetScheduleCallback( | 189 gpu::InProcessCommandBuffer::SetScheduleCallback( |
| 188 base::Bind(&ScheduleGpuWork)); | 190 base::Bind(&ScheduleGpuWork)); |
| 191 | |
| 192 DCHECK(!gfx::SurfaceFactoryAndroid::GetInstance()); | |
| 193 gfx::SurfaceFactoryAndroid::SetInstance(GLSurfaceFactory::GetInstance()); | |
| 189 } | 194 } |
| 190 | 195 |
| 191 // static | 196 // static |
| 192 AwDrawSWFunctionTable* BrowserViewRenderer::GetAwDrawSWFunctionTable() { | 197 AwDrawSWFunctionTable* BrowserViewRenderer::GetAwDrawSWFunctionTable() { |
| 193 return g_sw_draw_functions; | 198 return g_sw_draw_functions; |
| 194 } | 199 } |
| 195 | 200 |
| 196 // static | 201 // static |
| 197 bool BrowserViewRenderer::IsSkiaVersionCompatible() { | 202 bool BrowserViewRenderer::IsSkiaVersionCompatible() { |
| 198 DCHECK(g_sw_draw_functions); | 203 DCHECK(g_sw_draw_functions); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 282 return compositor_ && client_->RequestDrawGL(java_canvas); | 287 return compositor_ && client_->RequestDrawGL(java_canvas); |
| 283 } | 288 } |
| 284 // Perform a software draw | 289 // Perform a software draw |
| 285 block_invalidates_ = true; | 290 block_invalidates_ = true; |
| 286 bool result = DrawSWInternal(java_canvas, clip); | 291 bool result = DrawSWInternal(java_canvas, clip); |
| 287 block_invalidates_ = false; | 292 block_invalidates_ = false; |
| 288 EnsureContinuousInvalidation(NULL, false); | 293 EnsureContinuousInvalidation(NULL, false); |
| 289 return result; | 294 return result; |
| 290 } | 295 } |
| 291 | 296 |
| 297 | |
| 298 scoped_refptr<gfx::GLSurface> InProcessViewRenderer::CreateGLSurface() { | |
| 299 DCHECK(!hardware_initialized_); | |
| 300 DCHECK(!gl_surface_); | |
| 301 gl_surface_ = new AwGLSurface; | |
| 302 return gl_surface_; | |
| 303 } | |
| 304 | |
| 305 bool InProcessViewRenderer::InitializeHwDraw() { | |
| 306 TRACE_EVENT0("android_webview", "InitializeHwDraw"); | |
|
no sievers
2013/08/06 17:30:07
Do you need GLSurfaceFactory if you are doing this
boliu
2013/08/06 18:11:16
This brought up something else. We should always h
| |
| 307 GLSurfaceFactory::GetInstance()->SetNextCallback(base::Bind( | |
| 308 &InProcessViewRenderer::CreateGLSurface, base::Unretained(this))); | |
| 309 | |
| 310 hardware_failed_ = !compositor_->InitializeHwDraw(); | |
| 311 hardware_initialized_ = true; | |
| 312 | |
| 313 GLSurfaceFactory::GetInstance()->ResetCallback(); | |
| 314 | |
| 315 return !hardware_failed_; | |
| 316 } | |
| 317 | |
| 292 void InProcessViewRenderer::DrawGL(AwDrawGLInfo* draw_info) { | 318 void InProcessViewRenderer::DrawGL(AwDrawGLInfo* draw_info) { |
| 293 TRACE_EVENT0("android_webview", "InProcessViewRenderer::DrawGL"); | 319 TRACE_EVENT0("android_webview", "InProcessViewRenderer::DrawGL"); |
| 294 DCHECK(visible_); | 320 DCHECK(visible_); |
| 295 | 321 |
| 296 manager_key_ = g_view_renderer_manager.Get().DidDrawGL(manager_key_, this); | 322 manager_key_ = g_view_renderer_manager.Get().DidDrawGL(manager_key_, this); |
| 297 | 323 |
| 298 // We need to watch if the current Android context has changed and enforce | 324 // We need to watch if the current Android context has changed and enforce |
| 299 // a clean-up in the compositor. | 325 // a clean-up in the compositor. |
| 300 EGLContext current_context = eglGetCurrentContext(); | 326 EGLContext current_context = eglGetCurrentContext(); |
| 301 if (!current_context) { | 327 if (!current_context) { |
| 302 TRACE_EVENT_INSTANT0( | 328 TRACE_EVENT_INSTANT0( |
| 303 "android_webview", "EarlyOut_NullEGLContext", TRACE_EVENT_SCOPE_THREAD); | 329 "android_webview", "EarlyOut_NullEGLContext", TRACE_EVENT_SCOPE_THREAD); |
| 304 return; | 330 return; |
| 305 } | 331 } |
| 306 | 332 |
| 307 ScopedAppGLStateRestore state_restore(ScopedAppGLStateRestore::MODE_DRAW); | 333 ScopedAppGLStateRestore state_restore(ScopedAppGLStateRestore::MODE_DRAW); |
| 308 gpu::InProcessCommandBuffer::ProcessGpuWorkOnCurrentThread(); | 334 gpu::InProcessCommandBuffer::ProcessGpuWorkOnCurrentThread(); |
| 309 ScopedAllowGL allow_gl; | 335 ScopedAllowGL allow_gl; |
| 310 | 336 |
| 311 if (attached_to_window_ && compositor_ && !hardware_initialized_) { | 337 if (attached_to_window_ && compositor_ && !hardware_initialized_) { |
| 312 TRACE_EVENT0("android_webview", "InitializeHwDraw"); | 338 if (InitializeHwDraw()) |
| 313 hardware_failed_ = !compositor_->InitializeHwDraw(); | 339 last_egl_context_ = current_context; |
| 314 hardware_initialized_ = true; | 340 else |
| 315 last_egl_context_ = current_context; | |
| 316 | |
| 317 if (hardware_failed_) | |
| 318 return; | 341 return; |
| 319 } | 342 } |
| 320 | 343 |
| 321 if (draw_info->mode == AwDrawGLInfo::kModeProcess) | 344 if (draw_info->mode == AwDrawGLInfo::kModeProcess) |
| 322 return; | 345 return; |
| 323 | 346 |
| 324 // DrawGL may be called without OnDraw, so cancel |fallback_tick_| here as | 347 // DrawGL may be called without OnDraw, so cancel |fallback_tick_| here as |
| 325 // well just to be safe. | 348 // well just to be safe. |
| 326 fallback_tick_.Cancel(); | 349 fallback_tick_.Cancel(); |
| 327 | 350 |
| 328 if (last_egl_context_ != current_context) { | 351 if (last_egl_context_ != current_context) { |
| 329 // TODO(boliu): Handle context lost | 352 // TODO(boliu): Handle context lost |
| 330 TRACE_EVENT_INSTANT0( | 353 TRACE_EVENT_INSTANT0( |
| 331 "android_webview", "EGLContextChanged", TRACE_EVENT_SCOPE_THREAD); | 354 "android_webview", "EGLContextChanged", TRACE_EVENT_SCOPE_THREAD); |
| 332 } | 355 } |
| 333 last_egl_context_ = current_context; | |
| 334 | 356 |
| 335 if (!compositor_) { | 357 if (!compositor_) { |
| 336 TRACE_EVENT_INSTANT0( | 358 TRACE_EVENT_INSTANT0( |
| 337 "android_webview", "EarlyOut_NoCompositor", TRACE_EVENT_SCOPE_THREAD); | 359 "android_webview", "EarlyOut_NoCompositor", TRACE_EVENT_SCOPE_THREAD); |
| 338 return; | 360 return; |
| 339 } | 361 } |
| 340 | 362 |
| 363 DCHECK(gl_surface_); | |
| 364 gl_surface_->SetBackingFrameBufferObject( | |
| 365 state_restore.framebuffer_binding_ext()); | |
| 366 | |
| 341 gfx::Transform transform; | 367 gfx::Transform transform; |
| 342 transform.matrix().setColMajorf(draw_info->transform); | 368 transform.matrix().setColMajorf(draw_info->transform); |
| 343 transform.Translate(scroll_at_start_of_frame_.x(), | 369 transform.Translate(scroll_at_start_of_frame_.x(), |
| 344 scroll_at_start_of_frame_.y()); | 370 scroll_at_start_of_frame_.y()); |
| 345 // TODO(joth): Check return value. | |
| 346 block_invalidates_ = true; | |
| 347 gfx::Rect clip_rect(draw_info->clip_left, | 371 gfx::Rect clip_rect(draw_info->clip_left, |
| 348 draw_info->clip_top, | 372 draw_info->clip_top, |
| 349 draw_info->clip_right - draw_info->clip_left, | 373 draw_info->clip_right - draw_info->clip_left, |
| 350 draw_info->clip_bottom - draw_info->clip_top); | 374 draw_info->clip_bottom - draw_info->clip_top); |
| 375 block_invalidates_ = true; | |
| 376 // TODO(joth): Check return value. | |
| 351 compositor_->DemandDrawHw(gfx::Size(draw_info->width, draw_info->height), | 377 compositor_->DemandDrawHw(gfx::Size(draw_info->width, draw_info->height), |
| 352 transform, | 378 transform, |
| 353 clip_rect, | 379 clip_rect, |
| 354 state_restore.stencil_enabled()); | 380 state_restore.stencil_enabled()); |
| 355 block_invalidates_ = false; | 381 block_invalidates_ = false; |
| 382 gl_surface_->ResetBackingFrameBufferObject(); | |
| 356 | 383 |
| 357 UpdateCachedGlobalVisibleRect(); | 384 UpdateCachedGlobalVisibleRect(); |
| 358 bool drew_full_visible_rect = clip_rect.Contains(cached_global_visible_rect_); | 385 bool drew_full_visible_rect = clip_rect.Contains(cached_global_visible_rect_); |
| 359 EnsureContinuousInvalidation(draw_info, !drew_full_visible_rect); | 386 EnsureContinuousInvalidation(draw_info, !drew_full_visible_rect); |
| 360 } | 387 } |
| 361 | 388 |
| 362 void InProcessViewRenderer::SetGlobalVisibleRect( | 389 void InProcessViewRenderer::SetGlobalVisibleRect( |
| 363 const gfx::Rect& visible_rect) { | 390 const gfx::Rect& visible_rect) { |
| 364 cached_global_visible_rect_ = visible_rect; | 391 cached_global_visible_rect_ = visible_rect; |
| 365 } | 392 } |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 545 NoLongerExpectsDrawGL(); | 572 NoLongerExpectsDrawGL(); |
| 546 if (hardware_initialized_) { | 573 if (hardware_initialized_) { |
| 547 DCHECK(compositor_); | 574 DCHECK(compositor_); |
| 548 | 575 |
| 549 ScopedAppGLStateRestore state_restore( | 576 ScopedAppGLStateRestore state_restore( |
| 550 ScopedAppGLStateRestore::MODE_DETACH_FROM_WINDOW); | 577 ScopedAppGLStateRestore::MODE_DETACH_FROM_WINDOW); |
| 551 gpu::InProcessCommandBuffer::ProcessGpuWorkOnCurrentThread(); | 578 gpu::InProcessCommandBuffer::ProcessGpuWorkOnCurrentThread(); |
| 552 ScopedAllowGL allow_gl; | 579 ScopedAllowGL allow_gl; |
| 553 compositor_->ReleaseHwDraw(); | 580 compositor_->ReleaseHwDraw(); |
| 554 hardware_initialized_ = false; | 581 hardware_initialized_ = false; |
| 582 gl_surface_ = NULL; | |
| 555 } | 583 } |
| 556 | 584 |
| 557 attached_to_window_ = false; | 585 attached_to_window_ = false; |
| 558 } | 586 } |
| 559 | 587 |
| 560 bool InProcessViewRenderer::IsAttachedToWindow() { | 588 bool InProcessViewRenderer::IsAttachedToWindow() { |
| 561 return attached_to_window_; | 589 return attached_to_window_; |
| 562 } | 590 } |
| 563 | 591 |
| 564 bool InProcessViewRenderer::IsViewVisible() { | 592 bool InProcessViewRenderer::IsViewVisible() { |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 776 base::StringAppendF(&str, | 804 base::StringAppendF(&str, |
| 777 "surface width height: [%d %d] ", | 805 "surface width height: [%d %d] ", |
| 778 draw_info->width, | 806 draw_info->width, |
| 779 draw_info->height); | 807 draw_info->height); |
| 780 base::StringAppendF(&str, "is_layer: %d ", draw_info->is_layer); | 808 base::StringAppendF(&str, "is_layer: %d ", draw_info->is_layer); |
| 781 } | 809 } |
| 782 return str; | 810 return str; |
| 783 } | 811 } |
| 784 | 812 |
| 785 } // namespace android_webview | 813 } // namespace android_webview |
| OLD | NEW |