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/scoped_app_gl_state_restore.h" | 10 #include "android_webview/browser/scoped_app_gl_state_restore.h" |
10 #include "android_webview/common/aw_switches.h" | 11 #include "android_webview/common/aw_switches.h" |
11 #include "android_webview/public/browser/draw_gl.h" | 12 #include "android_webview/public/browser/draw_gl.h" |
12 #include "android_webview/public/browser/draw_sw.h" | 13 #include "android_webview/public/browser/draw_sw.h" |
13 #include "base/android/jni_android.h" | 14 #include "base/android/jni_android.h" |
14 #include "base/auto_reset.h" | 15 #include "base/auto_reset.h" |
15 #include "base/command_line.h" | 16 #include "base/command_line.h" |
16 #include "base/debug/trace_event.h" | 17 #include "base/debug/trace_event.h" |
17 #include "base/lazy_instance.h" | 18 #include "base/lazy_instance.h" |
18 #include "base/logging.h" | 19 #include "base/logging.h" |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 return compositor_ && client_->RequestDrawGL(java_canvas); | 283 return compositor_ && client_->RequestDrawGL(java_canvas); |
283 } | 284 } |
284 // Perform a software draw | 285 // Perform a software draw |
285 block_invalidates_ = true; | 286 block_invalidates_ = true; |
286 bool result = DrawSWInternal(java_canvas, clip); | 287 bool result = DrawSWInternal(java_canvas, clip); |
287 block_invalidates_ = false; | 288 block_invalidates_ = false; |
288 EnsureContinuousInvalidation(NULL, false); | 289 EnsureContinuousInvalidation(NULL, false); |
289 return result; | 290 return result; |
290 } | 291 } |
291 | 292 |
| 293 bool InProcessViewRenderer::InitializeHwDraw() { |
| 294 TRACE_EVENT0("android_webview", "InitializeHwDraw"); |
| 295 DCHECK(!gl_surface_); |
| 296 gl_surface_ = new AwGLSurface; |
| 297 hardware_failed_ = !compositor_->InitializeHwDraw(gl_surface_); |
| 298 hardware_initialized_ = true; |
| 299 |
| 300 if (hardware_failed_) |
| 301 gl_surface_ = NULL; |
| 302 |
| 303 return !hardware_failed_; |
| 304 } |
| 305 |
292 void InProcessViewRenderer::DrawGL(AwDrawGLInfo* draw_info) { | 306 void InProcessViewRenderer::DrawGL(AwDrawGLInfo* draw_info) { |
293 TRACE_EVENT0("android_webview", "InProcessViewRenderer::DrawGL"); | 307 TRACE_EVENT0("android_webview", "InProcessViewRenderer::DrawGL"); |
294 DCHECK(visible_); | 308 DCHECK(visible_); |
295 | 309 |
296 manager_key_ = g_view_renderer_manager.Get().DidDrawGL(manager_key_, this); | 310 manager_key_ = g_view_renderer_manager.Get().DidDrawGL(manager_key_, this); |
297 | 311 |
298 // We need to watch if the current Android context has changed and enforce | 312 // We need to watch if the current Android context has changed and enforce |
299 // a clean-up in the compositor. | 313 // a clean-up in the compositor. |
300 EGLContext current_context = eglGetCurrentContext(); | 314 EGLContext current_context = eglGetCurrentContext(); |
301 if (!current_context) { | 315 if (!current_context) { |
302 TRACE_EVENT_INSTANT0( | 316 TRACE_EVENT_INSTANT0( |
303 "android_webview", "EarlyOut_NullEGLContext", TRACE_EVENT_SCOPE_THREAD); | 317 "android_webview", "EarlyOut_NullEGLContext", TRACE_EVENT_SCOPE_THREAD); |
304 return; | 318 return; |
305 } | 319 } |
306 | 320 |
307 ScopedAppGLStateRestore state_restore(ScopedAppGLStateRestore::MODE_DRAW); | 321 ScopedAppGLStateRestore state_restore(ScopedAppGLStateRestore::MODE_DRAW); |
308 gpu::InProcessCommandBuffer::ProcessGpuWorkOnCurrentThread(); | 322 gpu::InProcessCommandBuffer::ProcessGpuWorkOnCurrentThread(); |
309 ScopedAllowGL allow_gl; | 323 ScopedAllowGL allow_gl; |
310 | 324 |
311 if (attached_to_window_ && compositor_ && !hardware_initialized_) { | 325 if (attached_to_window_ && compositor_ && !hardware_initialized_) { |
312 TRACE_EVENT0("android_webview", "InitializeHwDraw"); | 326 if (InitializeHwDraw()) { |
313 hardware_failed_ = !compositor_->InitializeHwDraw(); | 327 last_egl_context_ = current_context; |
314 hardware_initialized_ = true; | 328 } else { |
315 last_egl_context_ = current_context; | |
316 | |
317 if (hardware_failed_) | |
318 return; | 329 return; |
| 330 } |
319 } | 331 } |
320 | 332 |
321 if (draw_info->mode == AwDrawGLInfo::kModeProcess) | 333 if (draw_info->mode == AwDrawGLInfo::kModeProcess) |
322 return; | 334 return; |
323 | 335 |
324 // DrawGL may be called without OnDraw, so cancel |fallback_tick_| here as | 336 // DrawGL may be called without OnDraw, so cancel |fallback_tick_| here as |
325 // well just to be safe. | 337 // well just to be safe. |
326 fallback_tick_.Cancel(); | 338 fallback_tick_.Cancel(); |
327 | 339 |
328 if (last_egl_context_ != current_context) { | 340 if (last_egl_context_ != current_context) { |
329 // TODO(boliu): Handle context lost | 341 // TODO(boliu): Handle context lost |
330 TRACE_EVENT_INSTANT0( | 342 TRACE_EVENT_INSTANT0( |
331 "android_webview", "EGLContextChanged", TRACE_EVENT_SCOPE_THREAD); | 343 "android_webview", "EGLContextChanged", TRACE_EVENT_SCOPE_THREAD); |
332 } | 344 } |
333 last_egl_context_ = current_context; | |
334 | 345 |
335 if (!compositor_) { | 346 if (!compositor_) { |
336 TRACE_EVENT_INSTANT0( | 347 TRACE_EVENT_INSTANT0( |
337 "android_webview", "EarlyOut_NoCompositor", TRACE_EVENT_SCOPE_THREAD); | 348 "android_webview", "EarlyOut_NoCompositor", TRACE_EVENT_SCOPE_THREAD); |
338 return; | 349 return; |
339 } | 350 } |
340 | 351 |
| 352 DCHECK(gl_surface_); |
| 353 gl_surface_->SetBackingFrameBufferObject( |
| 354 state_restore.framebuffer_binding_ext()); |
| 355 |
341 gfx::Transform transform; | 356 gfx::Transform transform; |
342 transform.matrix().setColMajorf(draw_info->transform); | 357 transform.matrix().setColMajorf(draw_info->transform); |
343 transform.Translate(scroll_at_start_of_frame_.x(), | 358 transform.Translate(scroll_at_start_of_frame_.x(), |
344 scroll_at_start_of_frame_.y()); | 359 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, | 360 gfx::Rect clip_rect(draw_info->clip_left, |
348 draw_info->clip_top, | 361 draw_info->clip_top, |
349 draw_info->clip_right - draw_info->clip_left, | 362 draw_info->clip_right - draw_info->clip_left, |
350 draw_info->clip_bottom - draw_info->clip_top); | 363 draw_info->clip_bottom - draw_info->clip_top); |
| 364 block_invalidates_ = true; |
| 365 // TODO(joth): Check return value. |
351 compositor_->DemandDrawHw(gfx::Size(draw_info->width, draw_info->height), | 366 compositor_->DemandDrawHw(gfx::Size(draw_info->width, draw_info->height), |
352 transform, | 367 transform, |
353 clip_rect, | 368 clip_rect, |
354 state_restore.stencil_enabled()); | 369 state_restore.stencil_enabled()); |
355 block_invalidates_ = false; | 370 block_invalidates_ = false; |
| 371 gl_surface_->ResetBackingFrameBufferObject(); |
356 | 372 |
357 UpdateCachedGlobalVisibleRect(); | 373 UpdateCachedGlobalVisibleRect(); |
358 bool drew_full_visible_rect = clip_rect.Contains(cached_global_visible_rect_); | 374 bool drew_full_visible_rect = clip_rect.Contains(cached_global_visible_rect_); |
359 EnsureContinuousInvalidation(draw_info, !drew_full_visible_rect); | 375 EnsureContinuousInvalidation(draw_info, !drew_full_visible_rect); |
360 } | 376 } |
361 | 377 |
362 void InProcessViewRenderer::SetGlobalVisibleRect( | 378 void InProcessViewRenderer::SetGlobalVisibleRect( |
363 const gfx::Rect& visible_rect) { | 379 const gfx::Rect& visible_rect) { |
364 cached_global_visible_rect_ = visible_rect; | 380 cached_global_visible_rect_ = visible_rect; |
365 } | 381 } |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
547 DCHECK(compositor_); | 563 DCHECK(compositor_); |
548 | 564 |
549 ScopedAppGLStateRestore state_restore( | 565 ScopedAppGLStateRestore state_restore( |
550 ScopedAppGLStateRestore::MODE_DETACH_FROM_WINDOW); | 566 ScopedAppGLStateRestore::MODE_DETACH_FROM_WINDOW); |
551 gpu::InProcessCommandBuffer::ProcessGpuWorkOnCurrentThread(); | 567 gpu::InProcessCommandBuffer::ProcessGpuWorkOnCurrentThread(); |
552 ScopedAllowGL allow_gl; | 568 ScopedAllowGL allow_gl; |
553 compositor_->ReleaseHwDraw(); | 569 compositor_->ReleaseHwDraw(); |
554 hardware_initialized_ = false; | 570 hardware_initialized_ = false; |
555 } | 571 } |
556 | 572 |
| 573 gl_surface_ = NULL; |
557 attached_to_window_ = false; | 574 attached_to_window_ = false; |
558 } | 575 } |
559 | 576 |
560 bool InProcessViewRenderer::IsAttachedToWindow() { | 577 bool InProcessViewRenderer::IsAttachedToWindow() { |
561 return attached_to_window_; | 578 return attached_to_window_; |
562 } | 579 } |
563 | 580 |
564 bool InProcessViewRenderer::IsViewVisible() { | 581 bool InProcessViewRenderer::IsViewVisible() { |
565 return visible_; | 582 return visible_; |
566 } | 583 } |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
776 base::StringAppendF(&str, | 793 base::StringAppendF(&str, |
777 "surface width height: [%d %d] ", | 794 "surface width height: [%d %d] ", |
778 draw_info->width, | 795 draw_info->width, |
779 draw_info->height); | 796 draw_info->height); |
780 base::StringAppendF(&str, "is_layer: %d ", draw_info->is_layer); | 797 base::StringAppendF(&str, "is_layer: %d ", draw_info->is_layer); |
781 } | 798 } |
782 return str; | 799 return str; |
783 } | 800 } |
784 | 801 |
785 } // namespace android_webview | 802 } // namespace android_webview |
OLD | NEW |