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

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: rebase 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 TRACE_EVENT0("android_webview",
421 "BrowserViewRenderer::FlushPendingScrollAnimation");
boliu 2015/06/08 16:54:52 Fix trace event name
hush (inactive) 2015/06/09 19:11:33 Done.
422 DCHECK(!pending_fling_animation_.is_null());
423 AnimationCallback animation = pending_fling_animation_;
424 pending_fling_animation_.Reset();
425 animation.Run(animation_time);
426 }
427
417 void BrowserViewRenderer::ReleaseHardware() { 428 void BrowserViewRenderer::ReleaseHardware() {
418 DCHECK(hardware_enabled_); 429 DCHECK(hardware_enabled_);
419 ReturnUnusedResource(shared_renderer_state_.PassUncommittedFrameOnUI()); 430 ReturnUnusedResource(shared_renderer_state_.PassUncommittedFrameOnUI());
420 ReturnResourceFromParent(); 431 ReturnResourceFromParent();
421 DCHECK(shared_renderer_state_.ReturnedResourcesEmptyOnUI()); 432 DCHECK(shared_renderer_state_.ReturnedResourcesEmptyOnUI());
422 433
423 if (compositor_) { 434 if (compositor_) {
424 compositor_->SetMemoryPolicy(0u); 435 compositor_->SetMemoryPolicy(0u);
425 } 436 }
426 437
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 DCHECK_LE(scroll_offset.x(), max_offset.x()); 555 DCHECK_LE(scroll_offset.x(), max_offset.x());
545 DCHECK_LE(scroll_offset.y(), max_offset.y()); 556 DCHECK_LE(scroll_offset.y(), max_offset.y());
546 557
547 client_->ScrollContainerViewTo(scroll_offset); 558 client_->ScrollContainerViewTo(scroll_offset);
548 } 559 }
549 560
550 gfx::Vector2dF BrowserViewRenderer::GetTotalRootLayerScrollOffset() { 561 gfx::Vector2dF BrowserViewRenderer::GetTotalRootLayerScrollOffset() {
551 return scroll_offset_dip_; 562 return scroll_offset_dip_;
552 } 563 }
553 564
554 bool BrowserViewRenderer::IsExternalFlingActive() const { 565 bool BrowserViewRenderer::IsExternalScrollActive() const {
555 return client_->IsFlingActive(); 566 return client_->IsSmoothScrollingActive();
556 } 567 }
557 568
558 void BrowserViewRenderer::UpdateRootLayerState( 569 void BrowserViewRenderer::UpdateRootLayerState(
559 const gfx::Vector2dF& total_scroll_offset_dip, 570 const gfx::Vector2dF& total_scroll_offset_dip,
560 const gfx::Vector2dF& max_scroll_offset_dip, 571 const gfx::Vector2dF& max_scroll_offset_dip,
561 const gfx::SizeF& scrollable_size_dip, 572 const gfx::SizeF& scrollable_size_dip,
562 float page_scale_factor, 573 float page_scale_factor,
563 float min_page_scale_factor, 574 float min_page_scale_factor,
564 float max_page_scale_factor) { 575 float max_page_scale_factor) {
565 TRACE_EVENT_INSTANT1( 576 TRACE_EVENT_INSTANT1(
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 state->SetDouble("max_scroll_offset_dip.x", max_scroll_offset_dip_.x()); 610 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()); 611 state->SetDouble("max_scroll_offset_dip.y", max_scroll_offset_dip_.y());
601 612
602 state->SetDouble("scrollable_size_dip.width", scrollable_size_dip.width()); 613 state->SetDouble("scrollable_size_dip.width", scrollable_size_dip.width());
603 state->SetDouble("scrollable_size_dip.height", scrollable_size_dip.height()); 614 state->SetDouble("scrollable_size_dip.height", scrollable_size_dip.height());
604 615
605 state->SetDouble("page_scale_factor", page_scale_factor_); 616 state->SetDouble("page_scale_factor", page_scale_factor_);
606 return state; 617 return state;
607 } 618 }
608 619
620 void BrowserViewRenderer::SetNeedsAnimateScroll(
621 const AnimationCallback& scroll_animation) {
622 pending_fling_animation_ = scroll_animation;
623 PostInvalidateWithFallback();
boliu 2015/06/08 16:54:52 Actually I'm eating my words. You said it's ok if
hush (inactive) 2015/06/09 19:11:33 Okay. I will just postInvalidate and add a comment
624 }
625
609 void BrowserViewRenderer::DidOverscroll(gfx::Vector2dF accumulated_overscroll, 626 void BrowserViewRenderer::DidOverscroll(gfx::Vector2dF accumulated_overscroll,
610 gfx::Vector2dF latest_overscroll_delta, 627 gfx::Vector2dF latest_overscroll_delta,
611 gfx::Vector2dF current_fling_velocity) { 628 gfx::Vector2dF current_fling_velocity) {
612 const float physical_pixel_scale = dip_scale_ * page_scale_factor_; 629 const float physical_pixel_scale = dip_scale_ * page_scale_factor_;
613 if (accumulated_overscroll == latest_overscroll_delta) 630 if (accumulated_overscroll == latest_overscroll_delta)
614 overscroll_rounding_error_ = gfx::Vector2dF(); 631 overscroll_rounding_error_ = gfx::Vector2dF();
615 gfx::Vector2dF scaled_overscroll_delta = 632 gfx::Vector2dF scaled_overscroll_delta =
616 gfx::ScaleVector2d(latest_overscroll_delta, physical_pixel_scale); 633 gfx::ScaleVector2d(latest_overscroll_delta, physical_pixel_scale);
617 gfx::Vector2d rounded_overscroll_delta = gfx::ToRoundedVector2d( 634 gfx::Vector2d rounded_overscroll_delta = gfx::ToRoundedVector2d(
618 scaled_overscroll_delta + overscroll_rounding_error_); 635 scaled_overscroll_delta + overscroll_rounding_error_);
619 overscroll_rounding_error_ = 636 overscroll_rounding_error_ =
620 scaled_overscroll_delta - rounded_overscroll_delta; 637 scaled_overscroll_delta - rounded_overscroll_delta;
621 client_->DidOverscroll(rounded_overscroll_delta); 638 gfx::Vector2dF fling_velocity_pixels =
639 gfx::ScaleVector2d(current_fling_velocity, physical_pixel_scale);
640
641 client_->DidOverscroll(rounded_overscroll_delta, fling_velocity_pixels);
622 } 642 }
623 643
624 void BrowserViewRenderer::PostInvalidate() { 644 void BrowserViewRenderer::PostInvalidate() {
625 TRACE_EVENT_INSTANT0("android_webview", "BrowserViewRenderer::PostInvalidate", 645 TRACE_EVENT_INSTANT0("android_webview", "BrowserViewRenderer::PostInvalidate",
626 TRACE_EVENT_SCOPE_THREAD); 646 TRACE_EVENT_SCOPE_THREAD);
627 PostInvalidateWithFallback(); 647 PostInvalidateWithFallback();
628 } 648 }
629 649
630 void BrowserViewRenderer::PostInvalidateWithFallback() { 650 void BrowserViewRenderer::PostInvalidateWithFallback() {
631 // Always call view invalidate. We rely the Android framework to ignore the 651 // Always call view invalidate. We rely the Android framework to ignore the
632 // invalidate when it's not needed such as when view is not visible. 652 // invalidate when it's not needed such as when view is not visible.
633 client_->PostInvalidate(); 653 client_->PostInvalidate();
634 654
635 // Stop fallback ticks when one of these is true. 655 // Stop fallback ticks when one of these is true.
636 // 1) Webview is paused. Also need to check we are not in clear view since 656 // 1) Webview is paused. Also need to check we are not in clear view since
637 // paused, offscreen still expect clear view to recover. 657 // paused, offscreen still expect clear view to recover.
638 // 2) If we are attached to window and the window is not visible (eg when 658 // 2) If we are attached to window and the window is not visible (eg when
639 // app is in the background). We are sure in this case the webview is used 659 // app is in the background). We are sure in this case the webview is used
640 // "on-screen" but that updates are not needed when in the background. 660 // "on-screen" but that updates are not needed when in the background.
641 bool throttle_fallback_tick = 661 bool throttle_fallback_tick =
642 (is_paused_ && !clear_view_) || (attached_to_window_ && !window_visible_); 662 (is_paused_ && !clear_view_) || (attached_to_window_ && !window_visible_);
643 663
644 if (throttle_fallback_tick || fallback_tick_pending_) 664 if (throttle_fallback_tick || fallback_tick_pending_ ||
665 !pending_fling_animation_.is_null())
boliu 2015/06/08 16:54:52 don't forget to remove this (Seems to be backward
hush (inactive) 2015/06/09 19:11:33 okay,.. removed this. And yes. The logic here is b
645 return; 666 return;
646 667
647 DCHECK(post_fallback_tick_.IsCancelled()); 668 DCHECK(post_fallback_tick_.IsCancelled());
648 DCHECK(fallback_tick_fired_.IsCancelled()); 669 DCHECK(fallback_tick_fired_.IsCancelled());
649 670
650 post_fallback_tick_.Reset(base::Bind(&BrowserViewRenderer::PostFallbackTick, 671 post_fallback_tick_.Reset(base::Bind(&BrowserViewRenderer::PostFallbackTick,
651 base::Unretained(this))); 672 base::Unretained(this)));
652 ui_task_runner_->PostTask(FROM_HERE, post_fallback_tick_.callback()); 673 ui_task_runner_->PostTask(FROM_HERE, post_fallback_tick_.callback());
653 fallback_tick_pending_ = true; 674 fallback_tick_pending_ = true;
654 } 675 }
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 base::StringAppendF(&str, 748 base::StringAppendF(&str,
728 "overscroll_rounding_error_: %s ", 749 "overscroll_rounding_error_: %s ",
729 overscroll_rounding_error_.ToString().c_str()); 750 overscroll_rounding_error_.ToString().c_str());
730 base::StringAppendF( 751 base::StringAppendF(
731 &str, "on_new_picture_enable: %d ", on_new_picture_enable_); 752 &str, "on_new_picture_enable: %d ", on_new_picture_enable_);
732 base::StringAppendF(&str, "clear_view: %d ", clear_view_); 753 base::StringAppendF(&str, "clear_view: %d ", clear_view_);
733 return str; 754 return str;
734 } 755 }
735 756
736 } // namespace android_webview 757 } // namespace android_webview
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698