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/public/browser/draw_gl.h" | 9 #include "android_webview/public/browser/draw_gl.h" |
| 10 #include "android_webview/public/browser/draw_sw.h" | 10 #include "android_webview/public/browser/draw_sw.h" |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 347 // until the DidInitializeCompositor() call, hence it is not set here. | 347 // until the DidInitializeCompositor() call, hence it is not set here. |
| 348 } | 348 } |
| 349 | 349 |
| 350 void InProcessViewRenderer::WebContentsGone() { | 350 void InProcessViewRenderer::WebContentsGone() { |
| 351 web_contents_ = NULL; | 351 web_contents_ = NULL; |
| 352 compositor_ = NULL; | 352 compositor_ = NULL; |
| 353 } | 353 } |
| 354 | 354 |
| 355 bool InProcessViewRenderer::OnDraw(jobject java_canvas, | 355 bool InProcessViewRenderer::OnDraw(jobject java_canvas, |
| 356 bool is_hardware_canvas, | 356 bool is_hardware_canvas, |
| 357 const gfx::Point& scroll, | 357 const gfx::Vector2d& scroll_pix, |
| 358 const gfx::Rect& clip) { | 358 const gfx::Rect& clip) { |
| 359 scroll_at_start_of_frame_ = scroll; | 359 scroll_at_start_of_frame_pix_ = scroll_pix; |
| 360 if (is_hardware_canvas && attached_to_window_ && compositor_ && | 360 if (is_hardware_canvas && attached_to_window_ && compositor_ && |
| 361 HardwareEnabled() && client_->RequestDrawGL(java_canvas)) { | 361 HardwareEnabled() && client_->RequestDrawGL(java_canvas)) { |
| 362 // All set: we'll get a call on DrawGL when the time comes. | 362 // All set: we'll get a call on DrawGL when the time comes. |
| 363 return true; | 363 return true; |
| 364 } | 364 } |
| 365 // Perform a software draw | 365 // Perform a software draw |
| 366 bool result = DrawSWInternal(java_canvas, clip); | 366 bool result = DrawSWInternal(java_canvas, clip); |
| 367 EnsureContinuousInvalidation(); | 367 EnsureContinuousInvalidation(); |
| 368 return result; | 368 return result; |
| 369 } | 369 } |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 400 // TODO(boliu): Handle context lost | 400 // TODO(boliu): Handle context lost |
| 401 } | 401 } |
| 402 | 402 |
| 403 // TODO(boliu): Make sure this is not called before compositor is initialized | 403 // TODO(boliu): Make sure this is not called before compositor is initialized |
| 404 // and GL is ready. Then make this a DCHECK. | 404 // and GL is ready. Then make this a DCHECK. |
| 405 if (!compositor_) | 405 if (!compositor_) |
| 406 return; | 406 return; |
| 407 | 407 |
| 408 gfx::Transform transform; | 408 gfx::Transform transform; |
| 409 transform.matrix().setColMajorf(draw_info->transform); | 409 transform.matrix().setColMajorf(draw_info->transform); |
| 410 transform.Translate(scroll_at_start_of_frame_.x(), | 410 transform.Translate(scroll_at_start_of_frame_pix_.x(), |
| 411 scroll_at_start_of_frame_.y()); | 411 scroll_at_start_of_frame_pix_.y()); |
| 412 // TODO(joth): Check return value. | 412 // TODO(joth): Check return value. |
| 413 compositor_->DemandDrawHw( | 413 compositor_->DemandDrawHw( |
| 414 gfx::Size(draw_info->width, draw_info->height), | 414 gfx::Size(draw_info->width, draw_info->height), |
| 415 transform, | 415 transform, |
| 416 gfx::Rect(draw_info->clip_left, | 416 gfx::Rect(draw_info->clip_left, |
| 417 draw_info->clip_top, | 417 draw_info->clip_top, |
| 418 draw_info->clip_right - draw_info->clip_left, | 418 draw_info->clip_right - draw_info->clip_left, |
| 419 draw_info->clip_bottom - draw_info->clip_top)); | 419 draw_info->clip_bottom - draw_info->clip_top)); |
| 420 | 420 |
| 421 EnsureContinuousInvalidation(); | 421 EnsureContinuousInvalidation(); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 441 TRACE_EVENT0("android_webview", "Render to Aux Bitmap"); | 441 TRACE_EVENT0("android_webview", "Render to Aux Bitmap"); |
| 442 ScopedJavaLocalRef<jobject> jbitmap(java_helper_->CreateBitmap( | 442 ScopedJavaLocalRef<jobject> jbitmap(java_helper_->CreateBitmap( |
| 443 env, clip.width(), clip.height())); | 443 env, clip.width(), clip.height())); |
| 444 if (!jbitmap.obj()) { | 444 if (!jbitmap.obj()) { |
| 445 TRACE_EVENT_INSTANT0("android_webview", "Bitmap Alloc Fail", | 445 TRACE_EVENT_INSTANT0("android_webview", "Bitmap Alloc Fail", |
| 446 TRACE_EVENT_SCOPE_THREAD); | 446 TRACE_EVENT_SCOPE_THREAD); |
| 447 return false; | 447 return false; |
| 448 } | 448 } |
| 449 | 449 |
| 450 if (!RasterizeIntoBitmap(env, jbitmap, | 450 if (!RasterizeIntoBitmap(env, jbitmap, |
| 451 clip.x() - scroll_at_start_of_frame_.x(), | 451 clip.x() - scroll_at_start_of_frame_pix_.x(), |
| 452 clip.y() - scroll_at_start_of_frame_.y(), | 452 clip.y() - scroll_at_start_of_frame_pix_.y(), |
| 453 base::Bind(&InProcessViewRenderer::RenderSW, | 453 base::Bind(&InProcessViewRenderer::RenderSW, |
| 454 base::Unretained(this)))) { | 454 base::Unretained(this)))) { |
| 455 | |
| 455 TRACE_EVENT_INSTANT0("android_webview", "Rasterize Fail", | 456 TRACE_EVENT_INSTANT0("android_webview", "Rasterize Fail", |
| 456 TRACE_EVENT_SCOPE_THREAD); | 457 TRACE_EVENT_SCOPE_THREAD); |
| 457 return false; | 458 return false; |
| 458 } | 459 } |
| 459 | 460 |
| 460 ScopedJavaLocalRef<jobject> jcanvas(env, java_canvas); | 461 ScopedJavaLocalRef<jobject> jcanvas(env, java_canvas); |
| 461 java_helper_->DrawBitmapIntoCanvas(env, jbitmap, jcanvas, | 462 java_helper_->DrawBitmapIntoCanvas(env, jbitmap, jcanvas, |
| 462 clip.x(), clip.y()); | 463 clip.x(), clip.y()); |
| 463 return true; | 464 return true; |
| 464 } | 465 } |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 480 canvas.setMatrix(matrix); | 481 canvas.setMatrix(matrix); |
| 481 | 482 |
| 482 if (pixels->clip_region_size) { | 483 if (pixels->clip_region_size) { |
| 483 SkRegion clip_region; | 484 SkRegion clip_region; |
| 484 size_t bytes_read = clip_region.readFromMemory(pixels->clip_region); | 485 size_t bytes_read = clip_region.readFromMemory(pixels->clip_region); |
| 485 DCHECK_EQ(pixels->clip_region_size, bytes_read); | 486 DCHECK_EQ(pixels->clip_region_size, bytes_read); |
| 486 canvas.setClipRegion(clip_region); | 487 canvas.setClipRegion(clip_region); |
| 487 } else { | 488 } else { |
| 488 canvas.clipRect(gfx::RectToSkRect(clip)); | 489 canvas.clipRect(gfx::RectToSkRect(clip)); |
| 489 } | 490 } |
| 490 canvas.translate(scroll_at_start_of_frame_.x(), | 491 canvas.translate(scroll_at_start_of_frame_pix_.x(), |
| 491 scroll_at_start_of_frame_.y()); | 492 scroll_at_start_of_frame_pix_.y()); |
| 492 | 493 |
| 493 succeeded = RenderSW(&canvas); | 494 succeeded = RenderSW(&canvas); |
| 494 } | 495 } |
| 495 | 496 |
| 496 sw_functions->release_pixels(pixels); | 497 sw_functions->release_pixels(pixels); |
| 497 return succeeded; | 498 return succeeded; |
| 498 } | 499 } |
| 499 | 500 |
| 500 base::android::ScopedJavaLocalRef<jobject> | 501 base::android::ScopedJavaLocalRef<jobject> |
| 501 InProcessViewRenderer::CapturePicture() { | 502 InProcessViewRenderer::CapturePicture() { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 571 attached_to_window_ = false; | 572 attached_to_window_ = false; |
| 572 } | 573 } |
| 573 | 574 |
| 574 bool InProcessViewRenderer::IsAttachedToWindow() { | 575 bool InProcessViewRenderer::IsAttachedToWindow() { |
| 575 return attached_to_window_; | 576 return attached_to_window_; |
| 576 } | 577 } |
| 577 | 578 |
| 578 bool InProcessViewRenderer::IsViewVisible() { | 579 bool InProcessViewRenderer::IsViewVisible() { |
| 579 return view_visible_; | 580 return view_visible_; |
| 580 } | 581 } |
| 581 | |
|
joth
2013/06/18 03:19:50
mistake?
mkosiba (inactive)
2013/06/18 18:09:25
yes
| |
| 582 gfx::Rect InProcessViewRenderer::GetScreenRect() { | 582 gfx::Rect InProcessViewRenderer::GetScreenRect() { |
| 583 return gfx::Rect(client_->GetLocationOnScreen(), gfx::Size(width_, height_)); | 583 return gfx::Rect(client_->GetLocationOnScreen(), gfx::Size(width_, height_)); |
| 584 } | 584 } |
| 585 | 585 |
| 586 void InProcessViewRenderer::DidInitializeCompositor( | 586 void InProcessViewRenderer::DidInitializeCompositor( |
| 587 content::SynchronousCompositor* compositor) { | 587 content::SynchronousCompositor* compositor) { |
| 588 DCHECK(compositor && compositor_ == NULL); | 588 DCHECK(compositor && compositor_ == NULL); |
| 589 compositor_ = compositor; | 589 compositor_ = compositor; |
| 590 hardware_initialized_ = false; | 590 hardware_initialized_ = false; |
| 591 hardware_failed_ = false; | 591 hardware_failed_ = false; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 602 | 602 |
| 603 void InProcessViewRenderer::SetContinuousInvalidate(bool invalidate) { | 603 void InProcessViewRenderer::SetContinuousInvalidate(bool invalidate) { |
| 604 if (continuous_invalidate_ == invalidate) | 604 if (continuous_invalidate_ == invalidate) |
| 605 return; | 605 return; |
| 606 | 606 |
| 607 continuous_invalidate_ = invalidate; | 607 continuous_invalidate_ = invalidate; |
| 608 // TODO(boliu): Handle if not attached to window case. | 608 // TODO(boliu): Handle if not attached to window case. |
| 609 EnsureContinuousInvalidation(); | 609 EnsureContinuousInvalidation(); |
| 610 } | 610 } |
| 611 | 611 |
| 612 void InProcessViewRenderer::ScrollTo(gfx::Vector2dF new_value_css) { | |
| 613 DCHECK(scroll_offset_css_ != new_value_css); | |
| 614 | |
| 615 scroll_offset_css_ = new_value_css; | |
| 616 | |
| 617 if (compositor_) | |
| 618 compositor_->DidChangeRootLayerScrollOffset(); | |
| 619 } | |
| 620 | |
| 612 void InProcessViewRenderer::SetTotalRootLayerScrollOffset( | 621 void InProcessViewRenderer::SetTotalRootLayerScrollOffset( |
| 613 gfx::Vector2dF new_value) { | 622 gfx::Vector2dF new_value_css) { |
| 614 // TODO(mkosiba): Plumb this all the way through to the view. | 623 bool value_changed = scroll_offset_css_ != new_value_css; |
| 615 scroll_offset_ = new_value; | 624 |
| 625 if (!value_changed) | |
| 626 return; | |
| 627 | |
| 628 scroll_offset_css_ = new_value_css; | |
| 629 | |
| 630 client_->ScrollContainerViewTo(new_value_css); | |
| 616 } | 631 } |
| 617 | 632 |
| 618 gfx::Vector2dF InProcessViewRenderer::GetTotalRootLayerScrollOffset() { | 633 gfx::Vector2dF InProcessViewRenderer::GetTotalRootLayerScrollOffset() { |
| 619 return scroll_offset_; | 634 return scroll_offset_css_; |
| 620 } | 635 } |
| 621 | 636 |
| 622 void InProcessViewRenderer::Invalidate() { | 637 void InProcessViewRenderer::Invalidate() { |
| 623 continuous_invalidate_task_pending_ = false; | 638 continuous_invalidate_task_pending_ = false; |
| 624 if (continuous_invalidate_) | 639 if (continuous_invalidate_) |
| 625 client_->Invalidate(); | 640 client_->Invalidate(); |
| 626 } | 641 } |
| 627 | 642 |
| 628 void InProcessViewRenderer::EnsureContinuousInvalidation() { | 643 void InProcessViewRenderer::EnsureContinuousInvalidation() { |
| 629 if (continuous_invalidate_ && !continuous_invalidate_task_pending_) { | 644 if (continuous_invalidate_ && !continuous_invalidate_task_pending_) { |
| 630 base::MessageLoop::current()->PostTask(FROM_HERE, | 645 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 631 base::Bind(&InProcessViewRenderer::Invalidate, | 646 base::Bind(&InProcessViewRenderer::Invalidate, |
| 632 weak_factory_.GetWeakPtr())); | 647 weak_factory_.GetWeakPtr())); |
| 633 continuous_invalidate_task_pending_ = true; | 648 continuous_invalidate_task_pending_ = true; |
| 634 } | 649 } |
| 635 } | 650 } |
| 636 | 651 |
| 637 bool InProcessViewRenderer::RenderSW(SkCanvas* canvas) { | 652 bool InProcessViewRenderer::RenderSW(SkCanvas* canvas) { |
| 638 // TODO(joth): BrowserViewRendererImpl had a bunch of logic for dpi and page | 653 // TODO(joth): BrowserViewRendererImpl had a bunch of logic for dpi and page |
| 639 // scale here. Determine what if any needs bringing over to this class. | 654 // scale here. Determine what if any needs bringing over to this class. |
| 640 return CompositeSW(canvas); | 655 return CompositeSW(canvas); |
| 641 } | 656 } |
| 642 | 657 |
| 643 bool InProcessViewRenderer::CompositeSW(SkCanvas* canvas) { | 658 bool InProcessViewRenderer::CompositeSW(SkCanvas* canvas) { |
| 644 return compositor_ && compositor_->DemandDrawSw(canvas); | 659 return compositor_ && compositor_->DemandDrawSw(canvas); |
| 645 } | 660 } |
| 646 | 661 |
| 647 } // namespace android_webview | 662 } // namespace android_webview |
| OLD | NEW |