OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/browser_view_renderer.h" | 5 #include "android_webview/browser/browser_view_renderer.h" |
6 | 6 |
7 #include "android_webview/browser/browser_view_renderer_client.h" | 7 #include "android_webview/browser/browser_view_renderer_client.h" |
8 #include "android_webview/browser/child_frame.h" | 8 #include "android_webview/browser/child_frame.h" |
9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 } | 407 } |
408 | 408 |
409 void BrowserViewRenderer::OnDetachedFromWindow() { | 409 void BrowserViewRenderer::OnDetachedFromWindow() { |
410 TRACE_EVENT0("android_webview", "BrowserViewRenderer::OnDetachedFromWindow"); | 410 TRACE_EVENT0("android_webview", "BrowserViewRenderer::OnDetachedFromWindow"); |
411 shared_renderer_state_.ReleaseHardwareDrawIfNeededOnUI(); | 411 shared_renderer_state_.ReleaseHardwareDrawIfNeededOnUI(); |
412 attached_to_window_ = false; | 412 attached_to_window_ = false; |
413 DCHECK(!hardware_enabled_); | 413 DCHECK(!hardware_enabled_); |
414 UpdateCompositorIsActive(); | 414 UpdateCompositorIsActive(); |
415 } | 415 } |
416 | 416 |
| 417 void BrowserViewRenderer::OnComputeScroll(base::TimeTicks animation_time) { |
| 418 if (pending_fling_animation_.is_null()) |
| 419 return; |
| 420 TRACE_EVENT0("android_webview", "BrowserViewRenderer::OnComputeScroll"); |
| 421 DCHECK(!pending_fling_animation_.is_null()); |
| 422 AnimationCallback animation = pending_fling_animation_; |
| 423 pending_fling_animation_.Reset(); |
| 424 animation.Run(animation_time); |
| 425 } |
| 426 |
417 void BrowserViewRenderer::ReleaseHardware() { | 427 void BrowserViewRenderer::ReleaseHardware() { |
418 DCHECK(hardware_enabled_); | 428 DCHECK(hardware_enabled_); |
419 ReturnUnusedResource(shared_renderer_state_.PassUncommittedFrameOnUI()); | 429 ReturnUnusedResource(shared_renderer_state_.PassUncommittedFrameOnUI()); |
420 ReturnResourceFromParent(); | 430 ReturnResourceFromParent(); |
421 DCHECK(shared_renderer_state_.ReturnedResourcesEmptyOnUI()); | 431 DCHECK(shared_renderer_state_.ReturnedResourcesEmptyOnUI()); |
422 | 432 |
423 if (compositor_) { | 433 if (compositor_) { |
424 compositor_->SetMemoryPolicy(0u); | 434 compositor_->SetMemoryPolicy(0u); |
425 } | 435 } |
426 | 436 |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
544 DCHECK_LE(scroll_offset.x(), max_offset.x()); | 554 DCHECK_LE(scroll_offset.x(), max_offset.x()); |
545 DCHECK_LE(scroll_offset.y(), max_offset.y()); | 555 DCHECK_LE(scroll_offset.y(), max_offset.y()); |
546 | 556 |
547 client_->ScrollContainerViewTo(scroll_offset); | 557 client_->ScrollContainerViewTo(scroll_offset); |
548 } | 558 } |
549 | 559 |
550 gfx::Vector2dF BrowserViewRenderer::GetTotalRootLayerScrollOffset() { | 560 gfx::Vector2dF BrowserViewRenderer::GetTotalRootLayerScrollOffset() { |
551 return scroll_offset_dip_; | 561 return scroll_offset_dip_; |
552 } | 562 } |
553 | 563 |
554 bool BrowserViewRenderer::IsExternalFlingActive() const { | 564 bool BrowserViewRenderer::IsExternalScrollActive() const { |
555 return client_->IsFlingActive(); | 565 return client_->IsSmoothScrollingActive(); |
556 } | 566 } |
557 | 567 |
558 void BrowserViewRenderer::UpdateRootLayerState( | 568 void BrowserViewRenderer::UpdateRootLayerState( |
559 const gfx::Vector2dF& total_scroll_offset_dip, | 569 const gfx::Vector2dF& total_scroll_offset_dip, |
560 const gfx::Vector2dF& max_scroll_offset_dip, | 570 const gfx::Vector2dF& max_scroll_offset_dip, |
561 const gfx::SizeF& scrollable_size_dip, | 571 const gfx::SizeF& scrollable_size_dip, |
562 float page_scale_factor, | 572 float page_scale_factor, |
563 float min_page_scale_factor, | 573 float min_page_scale_factor, |
564 float max_page_scale_factor) { | 574 float max_page_scale_factor) { |
565 TRACE_EVENT_INSTANT1( | 575 TRACE_EVENT_INSTANT1( |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
599 state->SetDouble("max_scroll_offset_dip.x", max_scroll_offset_dip_.x()); | 609 state->SetDouble("max_scroll_offset_dip.x", max_scroll_offset_dip_.x()); |
600 state->SetDouble("max_scroll_offset_dip.y", max_scroll_offset_dip_.y()); | 610 state->SetDouble("max_scroll_offset_dip.y", max_scroll_offset_dip_.y()); |
601 | 611 |
602 state->SetDouble("scrollable_size_dip.width", scrollable_size_dip.width()); | 612 state->SetDouble("scrollable_size_dip.width", scrollable_size_dip.width()); |
603 state->SetDouble("scrollable_size_dip.height", scrollable_size_dip.height()); | 613 state->SetDouble("scrollable_size_dip.height", scrollable_size_dip.height()); |
604 | 614 |
605 state->SetDouble("page_scale_factor", page_scale_factor_); | 615 state->SetDouble("page_scale_factor", page_scale_factor_); |
606 return state; | 616 return state; |
607 } | 617 } |
608 | 618 |
| 619 void BrowserViewRenderer::SetNeedsAnimateScroll( |
| 620 const AnimationCallback& scroll_animation) { |
| 621 pending_fling_animation_ = scroll_animation; |
| 622 // No need to reschedule the fallback tick here because the compositor is |
| 623 // fine with the animation not being ticked. The invalidate could happen some |
| 624 // time later, or not at all. |
| 625 client_->PostInvalidate(); |
| 626 } |
| 627 |
609 void BrowserViewRenderer::DidOverscroll(gfx::Vector2dF accumulated_overscroll, | 628 void BrowserViewRenderer::DidOverscroll(gfx::Vector2dF accumulated_overscroll, |
610 gfx::Vector2dF latest_overscroll_delta, | 629 gfx::Vector2dF latest_overscroll_delta, |
611 gfx::Vector2dF current_fling_velocity) { | 630 gfx::Vector2dF current_fling_velocity) { |
612 const float physical_pixel_scale = dip_scale_ * page_scale_factor_; | 631 const float physical_pixel_scale = dip_scale_ * page_scale_factor_; |
613 if (accumulated_overscroll == latest_overscroll_delta) | 632 if (accumulated_overscroll == latest_overscroll_delta) |
614 overscroll_rounding_error_ = gfx::Vector2dF(); | 633 overscroll_rounding_error_ = gfx::Vector2dF(); |
615 gfx::Vector2dF scaled_overscroll_delta = | 634 gfx::Vector2dF scaled_overscroll_delta = |
616 gfx::ScaleVector2d(latest_overscroll_delta, physical_pixel_scale); | 635 gfx::ScaleVector2d(latest_overscroll_delta, physical_pixel_scale); |
617 gfx::Vector2d rounded_overscroll_delta = gfx::ToRoundedVector2d( | 636 gfx::Vector2d rounded_overscroll_delta = gfx::ToRoundedVector2d( |
618 scaled_overscroll_delta + overscroll_rounding_error_); | 637 scaled_overscroll_delta + overscroll_rounding_error_); |
619 overscroll_rounding_error_ = | 638 overscroll_rounding_error_ = |
620 scaled_overscroll_delta - rounded_overscroll_delta; | 639 scaled_overscroll_delta - rounded_overscroll_delta; |
621 client_->DidOverscroll(rounded_overscroll_delta); | 640 gfx::Vector2dF fling_velocity_pixels = |
| 641 gfx::ScaleVector2d(current_fling_velocity, physical_pixel_scale); |
| 642 |
| 643 client_->DidOverscroll(rounded_overscroll_delta, fling_velocity_pixels); |
622 } | 644 } |
623 | 645 |
624 void BrowserViewRenderer::PostInvalidate() { | 646 void BrowserViewRenderer::PostInvalidate() { |
625 TRACE_EVENT_INSTANT0("android_webview", "BrowserViewRenderer::PostInvalidate", | 647 TRACE_EVENT_INSTANT0("android_webview", "BrowserViewRenderer::PostInvalidate", |
626 TRACE_EVENT_SCOPE_THREAD); | 648 TRACE_EVENT_SCOPE_THREAD); |
627 PostInvalidateWithFallback(); | 649 PostInvalidateWithFallback(); |
628 } | 650 } |
629 | 651 |
630 void BrowserViewRenderer::PostInvalidateWithFallback() { | 652 void BrowserViewRenderer::PostInvalidateWithFallback() { |
631 // Always call view invalidate. We rely the Android framework to ignore the | 653 // Always call view invalidate. We rely the Android framework to ignore the |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
727 base::StringAppendF(&str, | 749 base::StringAppendF(&str, |
728 "overscroll_rounding_error_: %s ", | 750 "overscroll_rounding_error_: %s ", |
729 overscroll_rounding_error_.ToString().c_str()); | 751 overscroll_rounding_error_.ToString().c_str()); |
730 base::StringAppendF( | 752 base::StringAppendF( |
731 &str, "on_new_picture_enable: %d ", on_new_picture_enable_); | 753 &str, "on_new_picture_enable: %d ", on_new_picture_enable_); |
732 base::StringAppendF(&str, "clear_view: %d ", clear_view_); | 754 base::StringAppendF(&str, "clear_view: %d ", clear_view_); |
733 return str; | 755 return str; |
734 } | 756 } |
735 | 757 |
736 } // namespace android_webview | 758 } // namespace android_webview |
OLD | NEW |