Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(386)

Side by Side Diff: android_webview/browser/browser_view_renderer.cc

Issue 1063853005: Unify Android Webview and Chrome's fling (Closed) Base URL: https://chromium.googlesource.com/a/chromium/src.git@master
Patch Set: add a todo Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 FlushPendingScrollAnimation(animation_time);
421 }
422
417 void BrowserViewRenderer::ReleaseHardware() { 423 void BrowserViewRenderer::ReleaseHardware() {
418 DCHECK(hardware_enabled_); 424 DCHECK(hardware_enabled_);
419 ReturnUnusedResource(shared_renderer_state_.PassUncommittedFrameOnUI()); 425 ReturnUnusedResource(shared_renderer_state_.PassUncommittedFrameOnUI());
420 ReturnResourceFromParent(); 426 ReturnResourceFromParent();
421 DCHECK(shared_renderer_state_.ReturnedResourcesEmptyOnUI()); 427 DCHECK(shared_renderer_state_.ReturnedResourcesEmptyOnUI());
422 428
423 if (compositor_) { 429 if (compositor_) {
424 compositor_->SetMemoryPolicy(0u); 430 compositor_->SetMemoryPolicy(0u);
425 } 431 }
426 432
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 DCHECK_LE(scroll_offset.x(), max_offset.x()); 549 DCHECK_LE(scroll_offset.x(), max_offset.x());
544 DCHECK_LE(scroll_offset.y(), max_offset.y()); 550 DCHECK_LE(scroll_offset.y(), max_offset.y());
545 551
546 client_->ScrollContainerViewTo(scroll_offset); 552 client_->ScrollContainerViewTo(scroll_offset);
547 } 553 }
548 554
549 gfx::Vector2dF BrowserViewRenderer::GetTotalRootLayerScrollOffset() { 555 gfx::Vector2dF BrowserViewRenderer::GetTotalRootLayerScrollOffset() {
550 return scroll_offset_dip_; 556 return scroll_offset_dip_;
551 } 557 }
552 558
553 bool BrowserViewRenderer::IsExternalFlingActive() const { 559 bool BrowserViewRenderer::IsExternalScrollActive() const {
554 return client_->IsFlingActive(); 560 return client_->IsSmoothScrollingActive();
555 } 561 }
556 562
557 void BrowserViewRenderer::UpdateRootLayerState( 563 void BrowserViewRenderer::UpdateRootLayerState(
558 const gfx::Vector2dF& total_scroll_offset_dip, 564 const gfx::Vector2dF& total_scroll_offset_dip,
559 const gfx::Vector2dF& max_scroll_offset_dip, 565 const gfx::Vector2dF& max_scroll_offset_dip,
560 const gfx::SizeF& scrollable_size_dip, 566 const gfx::SizeF& scrollable_size_dip,
561 float page_scale_factor, 567 float page_scale_factor,
562 float min_page_scale_factor, 568 float min_page_scale_factor,
563 float max_page_scale_factor) { 569 float max_page_scale_factor) {
564 TRACE_EVENT_INSTANT1( 570 TRACE_EVENT_INSTANT1(
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 state->SetDouble("max_scroll_offset_dip.x", max_scroll_offset_dip_.x()); 604 state->SetDouble("max_scroll_offset_dip.x", max_scroll_offset_dip_.x());
599 state->SetDouble("max_scroll_offset_dip.y", max_scroll_offset_dip_.y()); 605 state->SetDouble("max_scroll_offset_dip.y", max_scroll_offset_dip_.y());
600 606
601 state->SetDouble("scrollable_size_dip.width", scrollable_size_dip.width()); 607 state->SetDouble("scrollable_size_dip.width", scrollable_size_dip.width());
602 state->SetDouble("scrollable_size_dip.height", scrollable_size_dip.height()); 608 state->SetDouble("scrollable_size_dip.height", scrollable_size_dip.height());
603 609
604 state->SetDouble("page_scale_factor", page_scale_factor_); 610 state->SetDouble("page_scale_factor", page_scale_factor_);
605 return state; 611 return state;
606 } 612 }
607 613
614 void BrowserViewRenderer::SetNeedsAnimateScroll(
615 const AnimationCallback& scroll_animation) {
616 pending_fling_animation_ = scroll_animation;
617 client_->PostInvalidate();
boliu 2015/05/29 19:42:47 Conceptually this feels wrong. What does "SetNeedA
hush (inactive) 2015/06/05 21:47:21 We've discussed this in person. The fling animatio
618 }
619
608 void BrowserViewRenderer::DidOverscroll(gfx::Vector2dF accumulated_overscroll, 620 void BrowserViewRenderer::DidOverscroll(gfx::Vector2dF accumulated_overscroll,
609 gfx::Vector2dF latest_overscroll_delta, 621 gfx::Vector2dF latest_overscroll_delta,
610 gfx::Vector2dF current_fling_velocity) { 622 gfx::Vector2dF current_fling_velocity) {
611 const float physical_pixel_scale = dip_scale_ * page_scale_factor_; 623 const float physical_pixel_scale = dip_scale_ * page_scale_factor_;
612 if (accumulated_overscroll == latest_overscroll_delta) 624 if (accumulated_overscroll == latest_overscroll_delta)
613 overscroll_rounding_error_ = gfx::Vector2dF(); 625 overscroll_rounding_error_ = gfx::Vector2dF();
614 gfx::Vector2dF scaled_overscroll_delta = 626 gfx::Vector2dF scaled_overscroll_delta =
615 gfx::ScaleVector2d(latest_overscroll_delta, physical_pixel_scale); 627 gfx::ScaleVector2d(latest_overscroll_delta, physical_pixel_scale);
616 gfx::Vector2d rounded_overscroll_delta = gfx::ToRoundedVector2d( 628 gfx::Vector2d rounded_overscroll_delta = gfx::ToRoundedVector2d(
617 scaled_overscroll_delta + overscroll_rounding_error_); 629 scaled_overscroll_delta + overscroll_rounding_error_);
618 overscroll_rounding_error_ = 630 overscroll_rounding_error_ =
619 scaled_overscroll_delta - rounded_overscroll_delta; 631 scaled_overscroll_delta - rounded_overscroll_delta;
620 client_->DidOverscroll(rounded_overscroll_delta); 632
boliu 2015/05/29 19:42:47 nit: blank lines
hush (inactive) 2015/06/05 21:47:21 Done.
633 gfx::Vector2dF fling_velocity_pixels =
634 gfx::ScaleVector2d(current_fling_velocity, physical_pixel_scale);
635
636 client_->DidOverscroll(rounded_overscroll_delta, fling_velocity_pixels);
621 } 637 }
622 638
623 void BrowserViewRenderer::PostInvalidate() { 639 void BrowserViewRenderer::PostInvalidate() {
624 TRACE_EVENT_INSTANT0("android_webview", "BrowserViewRenderer::PostInvalidate", 640 TRACE_EVENT_INSTANT0("android_webview", "BrowserViewRenderer::PostInvalidate",
625 TRACE_EVENT_SCOPE_THREAD); 641 TRACE_EVENT_SCOPE_THREAD);
626 PostInvalidateWithFallback(); 642 PostInvalidateWithFallback();
627 } 643 }
628 644
629 void BrowserViewRenderer::PostInvalidateWithFallback() { 645 void BrowserViewRenderer::PostInvalidateWithFallback() {
630 // Always call view invalidate. We rely the Android framework to ignore the 646 // Always call view invalidate. We rely the Android framework to ignore the
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 703
688 void BrowserViewRenderer::ForceFakeCompositeSW() { 704 void BrowserViewRenderer::ForceFakeCompositeSW() {
689 DCHECK(compositor_); 705 DCHECK(compositor_);
690 SkBitmap bitmap; 706 SkBitmap bitmap;
691 bitmap.allocN32Pixels(1, 1); 707 bitmap.allocN32Pixels(1, 1);
692 bitmap.eraseColor(0); 708 bitmap.eraseColor(0);
693 SkCanvas canvas(bitmap); 709 SkCanvas canvas(bitmap);
694 CompositeSW(&canvas); 710 CompositeSW(&canvas);
695 } 711 }
696 712
713 void BrowserViewRenderer::FlushPendingScrollAnimation(
boliu 2015/05/29 19:42:47 There is only one call site. Just inline this?
hush (inactive) 2015/06/05 21:47:21 Done.
714 base::TimeTicks animation_time) {
715 TRACE_EVENT0("android_webview",
716 "BrowserViewRenderer::FlushPendingScrollAnimation");
717 DCHECK(!pending_fling_animation_.is_null());
718 AnimationCallback animation = pending_fling_animation_;
719 pending_fling_animation_.Reset();
720 animation.Run(animation_time);
721 }
722
697 bool BrowserViewRenderer::CompositeSW(SkCanvas* canvas) { 723 bool BrowserViewRenderer::CompositeSW(SkCanvas* canvas) {
698 DCHECK(compositor_); 724 DCHECK(compositor_);
699 CancelFallbackTick(); 725 CancelFallbackTick();
700 ReturnResourceFromParent(); 726 ReturnResourceFromParent();
701 return compositor_->DemandDrawSw(canvas); 727 return compositor_->DemandDrawSw(canvas);
702 } 728 }
703 729
704 void BrowserViewRenderer::UpdateCompositorIsActive() { 730 void BrowserViewRenderer::UpdateCompositorIsActive() {
705 if (compositor_) 731 if (compositor_)
706 compositor_->SetIsActive(!is_paused_ && 732 compositor_->SetIsActive(!is_paused_ &&
(...skipping 19 matching lines...) Expand all
726 base::StringAppendF(&str, 752 base::StringAppendF(&str,
727 "overscroll_rounding_error_: %s ", 753 "overscroll_rounding_error_: %s ",
728 overscroll_rounding_error_.ToString().c_str()); 754 overscroll_rounding_error_.ToString().c_str());
729 base::StringAppendF( 755 base::StringAppendF(
730 &str, "on_new_picture_enable: %d ", on_new_picture_enable_); 756 &str, "on_new_picture_enable: %d ", on_new_picture_enable_);
731 base::StringAppendF(&str, "clear_view: %d ", clear_view_); 757 base::StringAppendF(&str, "clear_view: %d ", clear_view_);
732 return str; 758 return str;
733 } 759 }
734 760
735 } // namespace android_webview 761 } // namespace android_webview
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698