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