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

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: comments Created 5 years, 7 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 FlushPendingFlingAnimation(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::SetNeedsAnimateFling(
615 const AnimationCallback& fling_animation) {
616 // TODO(jdduke): Skip invalidate if animation already pending?
aelias_OOO_until_Jul13 2015/05/09 03:32:04 Resolve this TODO one way or the other? Personall
hush (inactive) 2015/05/12 19:08:45 I will just remove this TODO.
617 pending_fling_animation_ = fling_animation;
618 client_->PostInvalidate();
619 }
620
608 void BrowserViewRenderer::DidOverscroll(gfx::Vector2dF accumulated_overscroll, 621 void BrowserViewRenderer::DidOverscroll(gfx::Vector2dF accumulated_overscroll,
609 gfx::Vector2dF latest_overscroll_delta, 622 gfx::Vector2dF latest_overscroll_delta,
610 gfx::Vector2dF current_fling_velocity) { 623 gfx::Vector2dF current_fling_velocity) {
611 const float physical_pixel_scale = dip_scale_ * page_scale_factor_; 624 const float physical_pixel_scale = dip_scale_ * page_scale_factor_;
612 if (accumulated_overscroll == latest_overscroll_delta) 625 if (accumulated_overscroll == latest_overscroll_delta)
613 overscroll_rounding_error_ = gfx::Vector2dF(); 626 overscroll_rounding_error_ = gfx::Vector2dF();
614 gfx::Vector2dF scaled_overscroll_delta = 627 gfx::Vector2dF scaled_overscroll_delta =
615 gfx::ScaleVector2d(latest_overscroll_delta, physical_pixel_scale); 628 gfx::ScaleVector2d(latest_overscroll_delta, physical_pixel_scale);
616 gfx::Vector2d rounded_overscroll_delta = gfx::ToRoundedVector2d( 629 gfx::Vector2d rounded_overscroll_delta = gfx::ToRoundedVector2d(
617 scaled_overscroll_delta + overscroll_rounding_error_); 630 scaled_overscroll_delta + overscroll_rounding_error_);
618 overscroll_rounding_error_ = 631 overscroll_rounding_error_ =
619 scaled_overscroll_delta - rounded_overscroll_delta; 632 scaled_overscroll_delta - rounded_overscroll_delta;
620 client_->DidOverscroll(rounded_overscroll_delta); 633
634 gfx::Vector2dF fling_velocity_pixels =
635 gfx::ScaleVector2d(current_fling_velocity, physical_pixel_scale);
636
637 const bool first_overscroll_x =
638 accumulated_overscroll.x() &&
639 accumulated_overscroll.x() == latest_overscroll_delta.x();
640 const bool first_overscroll_y =
641 accumulated_overscroll.y() &&
642 accumulated_overscroll.y() == latest_overscroll_delta.y();
643
644 client_->DidOverscroll(rounded_overscroll_delta, fling_velocity_pixels,
645 first_overscroll_x, first_overscroll_y);
621 } 646 }
622 647
623 void BrowserViewRenderer::PostInvalidate() { 648 void BrowserViewRenderer::PostInvalidate() {
624 TRACE_EVENT_INSTANT0("android_webview", "BrowserViewRenderer::PostInvalidate", 649 TRACE_EVENT_INSTANT0("android_webview", "BrowserViewRenderer::PostInvalidate",
625 TRACE_EVENT_SCOPE_THREAD); 650 TRACE_EVENT_SCOPE_THREAD);
626 PostInvalidateWithFallback(); 651 PostInvalidateWithFallback();
627 } 652 }
628 653
629 void BrowserViewRenderer::PostInvalidateWithFallback() { 654 void BrowserViewRenderer::PostInvalidateWithFallback() {
630 // Always call view invalidate. We rely the Android framework to ignore the 655 // 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 712
688 void BrowserViewRenderer::ForceFakeCompositeSW() { 713 void BrowserViewRenderer::ForceFakeCompositeSW() {
689 DCHECK(compositor_); 714 DCHECK(compositor_);
690 SkBitmap bitmap; 715 SkBitmap bitmap;
691 bitmap.allocN32Pixels(1, 1); 716 bitmap.allocN32Pixels(1, 1);
692 bitmap.eraseColor(0); 717 bitmap.eraseColor(0);
693 SkCanvas canvas(bitmap); 718 SkCanvas canvas(bitmap);
694 CompositeSW(&canvas); 719 CompositeSW(&canvas);
695 } 720 }
696 721
722 void BrowserViewRenderer::FlushPendingFlingAnimation(
723 base::TimeTicks animation_time) {
724 TRACE_EVENT0("android_webview",
725 "BrowserViewRenderer::FlushPendingFlingAnimation");
726 DCHECK(!pending_fling_animation_.is_null());
727 AnimationCallback animation = pending_fling_animation_;
728 pending_fling_animation_.Reset();
729 animation.Run(animation_time);
730 }
731
697 bool BrowserViewRenderer::CompositeSW(SkCanvas* canvas) { 732 bool BrowserViewRenderer::CompositeSW(SkCanvas* canvas) {
698 DCHECK(compositor_); 733 DCHECK(compositor_);
699 CancelFallbackTick(); 734 CancelFallbackTick();
700 ReturnResourceFromParent(); 735 ReturnResourceFromParent();
701 return compositor_->DemandDrawSw(canvas); 736 return compositor_->DemandDrawSw(canvas);
702 } 737 }
703 738
704 void BrowserViewRenderer::UpdateCompositorIsActive() { 739 void BrowserViewRenderer::UpdateCompositorIsActive() {
705 if (compositor_) 740 if (compositor_)
706 compositor_->SetIsActive(!is_paused_ && 741 compositor_->SetIsActive(!is_paused_ &&
(...skipping 19 matching lines...) Expand all
726 base::StringAppendF(&str, 761 base::StringAppendF(&str,
727 "overscroll_rounding_error_: %s ", 762 "overscroll_rounding_error_: %s ",
728 overscroll_rounding_error_.ToString().c_str()); 763 overscroll_rounding_error_.ToString().c_str());
729 base::StringAppendF( 764 base::StringAppendF(
730 &str, "on_new_picture_enable: %d ", on_new_picture_enable_); 765 &str, "on_new_picture_enable: %d ", on_new_picture_enable_);
731 base::StringAppendF(&str, "clear_view: %d ", clear_view_); 766 base::StringAppendF(&str, "clear_view: %d ", clear_view_);
732 return str; 767 return str;
733 } 768 }
734 769
735 } // namespace android_webview 770 } // namespace android_webview
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698