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

Side by Side Diff: cc/trees/layer_tree_host_impl.cc

Issue 2189583004: [not for review - epic CL] Adding Elastic+Momentum+Layered scrolling to views::ScrollView Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Combined rebase Created 4 years, 4 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 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 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 "cc/trees/layer_tree_host_impl.h" 5 #include "cc/trees/layer_tree_host_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 DCHECK(!resource_provider_); 282 DCHECK(!resource_provider_);
283 DCHECK(!resource_pool_); 283 DCHECK(!resource_pool_);
284 DCHECK(!tile_task_manager_); 284 DCHECK(!tile_task_manager_);
285 DCHECK(!single_thread_synchronous_task_graph_runner_); 285 DCHECK(!single_thread_synchronous_task_graph_runner_);
286 DCHECK(!image_decode_controller_); 286 DCHECK(!image_decode_controller_);
287 287
288 if (input_handler_client_) { 288 if (input_handler_client_) {
289 input_handler_client_->WillShutdown(); 289 input_handler_client_->WillShutdown();
290 input_handler_client_ = NULL; 290 input_handler_client_ = NULL;
291 } 291 }
292 if (scroll_elasticity_helper_) 292 root_scroll_elasticity_helper_.reset();
293 scroll_elasticity_helper_.reset();
294 293
295 // The layer trees must be destroyed before the layer tree host. We've 294 // The layer trees must be destroyed before the layer tree host. We've
296 // made a contract with our animation controllers that the animation_host 295 // made a contract with our animation controllers that the animation_host
297 // will outlive them, and we must make good. 296 // will outlive them, and we must make good.
298 if (recycle_tree_) 297 if (recycle_tree_)
299 recycle_tree_->Shutdown(); 298 recycle_tree_->Shutdown();
300 if (pending_tree_) 299 if (pending_tree_)
301 pending_tree_->Shutdown(); 300 pending_tree_->Shutdown();
302 active_tree_->Shutdown(); 301 active_tree_->Shutdown();
303 recycle_tree_ = nullptr; 302 recycle_tree_ = nullptr;
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 return layer_impl != NULL; 605 return layer_impl != NULL;
607 } 606 }
608 607
609 std::unique_ptr<SwapPromiseMonitor> 608 std::unique_ptr<SwapPromiseMonitor>
610 LayerTreeHostImpl::CreateLatencyInfoSwapPromiseMonitor( 609 LayerTreeHostImpl::CreateLatencyInfoSwapPromiseMonitor(
611 ui::LatencyInfo* latency) { 610 ui::LatencyInfo* latency) {
612 return base::WrapUnique( 611 return base::WrapUnique(
613 new LatencyInfoSwapPromiseMonitor(latency, NULL, this)); 612 new LatencyInfoSwapPromiseMonitor(latency, NULL, this));
614 } 613 }
615 614
616 ScrollElasticityHelper* LayerTreeHostImpl::CreateScrollElasticityHelper() { 615 ScrollElasticityHelper* LayerTreeHostImpl::CreateRootScrollElasticityHelper() {
617 DCHECK(!scroll_elasticity_helper_); 616 DCHECK(!root_scroll_elasticity_helper_);
618 if (settings_.enable_elastic_overscroll) { 617 if (settings_.enable_elastic_overscroll) {
619 scroll_elasticity_helper_.reset( 618 root_scroll_elasticity_helper_.reset(
620 ScrollElasticityHelper::CreateForLayerTreeHostImpl(this)); 619 ScrollElasticityHelper::CreateForLayerTreeHostImpl(this));
621 } 620 }
622 return scroll_elasticity_helper_.get(); 621 return root_scroll_elasticity_helper_.get();
622 }
623
624 base::WeakPtr<ScrollElasticityHelper>
625 LayerTreeHostImpl::ScrollElasticityHelperForScrollingLayer() {
626 LayerImpl* scrolling_layer_impl = CurrentlyScrollingLayer();
627 if (!scrolling_layer_impl)
628 return nullptr;
629
630 return ScrollElasticityHelperForId(scrolling_layer_impl->id())->GetWeakPtr();
631 }
632
633 gfx::ScrollOffset LayerTreeHostImpl::GetScrollOffsetForLayer(int layer_id) {
634 LayerImpl* layer = active_tree()->FindActiveTreeLayerById(layer_id);
635 return layer ? layer->CurrentScrollOffset() : gfx::ScrollOffset();
636 }
637
638 bool LayerTreeHostImpl::ScrollLayerTo(int layer_id,
639 const gfx::ScrollOffset& offset) {
640 LayerImpl* layer = active_tree()->FindActiveTreeLayerById(layer_id);
641 if (!layer)
642 return false;
643
644 layer->ScrollBy(
645 ScrollOffsetToVector2dF(offset - layer->CurrentScrollOffset()));
646 return true;
623 } 647 }
624 648
625 void LayerTreeHostImpl::QueueSwapPromiseForMainThreadScrollUpdate( 649 void LayerTreeHostImpl::QueueSwapPromiseForMainThreadScrollUpdate(
626 std::unique_ptr<SwapPromise> swap_promise) { 650 std::unique_ptr<SwapPromise> swap_promise) {
627 swap_promises_for_main_thread_scroll_update_.push_back( 651 swap_promises_for_main_thread_scroll_update_.push_back(
628 std::move(swap_promise)); 652 std::move(swap_promise));
629 } 653 }
630 654
631 void LayerTreeHostImpl::TrackDamageForAllSurfaces( 655 void LayerTreeHostImpl::TrackDamageForAllSurfaces(
632 const LayerImplList& render_surface_layer_list) { 656 const LayerImplList& render_surface_layer_list) {
(...skipping 2000 matching lines...) Expand 10 before | Expand all | Expand 10 after
2633 scroll_status.thread = SCROLL_ON_IMPL_THREAD; 2657 scroll_status.thread = SCROLL_ON_IMPL_THREAD;
2634 ScrollAnimationAbort(scrolling_layer_impl); 2658 ScrollAnimationAbort(scrolling_layer_impl);
2635 2659
2636 top_controls_manager_->ScrollBegin(); 2660 top_controls_manager_->ScrollBegin();
2637 2661
2638 active_tree_->SetCurrentlyScrollingLayer(scrolling_layer_impl); 2662 active_tree_->SetCurrentlyScrollingLayer(scrolling_layer_impl);
2639 // TODO(majidvp): get rid of wheel_scrolling_ and set is_direct_manipulation 2663 // TODO(majidvp): get rid of wheel_scrolling_ and set is_direct_manipulation
2640 // in input_handler_proxy instead. 2664 // in input_handler_proxy instead.
2641 wheel_scrolling_ = IsWheelBasedScroll(type); 2665 wheel_scrolling_ = IsWheelBasedScroll(type);
2642 scroll_state->set_is_direct_manipulation(!wheel_scrolling_); 2666 scroll_state->set_is_direct_manipulation(!wheel_scrolling_);
2643 // Invoke |DistributeScrollDelta| even with zero delta and velocity to ensure 2667 // Invoke |DistributeScrollDelta| even with zero delta and velocity to process
2644 // scroll customization callbacks are invoked. 2668 // overscroll and ensure scroll customization callbacks are invoked.
2645 DistributeScrollDelta(scroll_state); 2669 DistributeScrollDelta(scroll_state);
2646 2670
2647 client_->RenewTreePriority(); 2671 client_->RenewTreePriority();
2648 RecordCompositorSlowScrollMetric(type, CC_THREAD); 2672 RecordCompositorSlowScrollMetric(type, CC_THREAD);
2649 2673
2650 return scroll_status; 2674 return scroll_status;
2651 } 2675 }
2652 2676
2653 InputHandler::ScrollStatus LayerTreeHostImpl::RootScrollBegin( 2677 InputHandler::ScrollStatus LayerTreeHostImpl::RootScrollBegin(
2654 ScrollState* scroll_state, 2678 ScrollState* scroll_state,
2655 InputHandler::ScrollInputType type) { 2679 InputHandler::ScrollInputType type) {
2656 TRACE_EVENT0("cc", "LayerTreeHostImpl::RootScrollBegin"); 2680 TRACE_EVENT0("cc", "LayerTreeHostImpl::RootScrollBegin");
2657 2681
2658 ClearCurrentlyScrollingLayer(); 2682 ClearCurrentlyScrollingLayer();
2659 2683
2660 return ScrollBeginImpl(scroll_state, InnerViewportScrollLayer(), type); 2684 return ScrollBeginImpl(scroll_state, InnerViewportScrollLayer(), type);
2661 } 2685 }
2662 2686
2663 InputHandler::ScrollStatus LayerTreeHostImpl::ScrollBegin( 2687 InputHandler::ScrollStatus LayerTreeHostImpl::ScrollBegin(
2664 ScrollState* scroll_state, 2688 ScrollState* scroll_state,
2665 InputHandler::ScrollInputType type) { 2689 InputHandler::ScrollInputType type) {
2666 ScrollStatus scroll_status; 2690 ScrollStatus scroll_status;
2667 scroll_status.main_thread_scrolling_reasons = 2691 scroll_status.main_thread_scrolling_reasons =
2668 MainThreadScrollingReason::kNotScrollingOnMain; 2692 MainThreadScrollingReason::kNotScrollingOnMain;
2669 TRACE_EVENT0("cc", "LayerTreeHostImpl::ScrollBegin"); 2693 TRACE_EVENT0("cc", "LayerTreeHostImpl::ScrollBegin");
2670 2694
2671 ClearCurrentlyScrollingLayer(); 2695 ClearCurrentlyScrollingLayer();
2672 2696
2697 if (!scroll_state->is_beginning()) {
2698 DCHECK(scroll_state->is_in_inertial_phase());
2699 // When transitioning into a "flick", try to find the layer that was
2700 // already scrolling. Without this, a flick may begin after elastic
2701 // overscroll moves the scrolling layer out from beneath the event, causing
2702 // a failed hit test.
2703 LayerImpl* scrolling_layer_impl =
2704 active_tree_->LayerById(active_tree_->LastScrolledLayerId());
2705 if (scrolling_layer_impl)
2706 return ScrollBeginImpl(scroll_state, scrolling_layer_impl, type);
2707 }
2708
2673 gfx::Point viewport_point(scroll_state->position_x(), 2709 gfx::Point viewport_point(scroll_state->position_x(),
2674 scroll_state->position_y()); 2710 scroll_state->position_y());
2675 2711
2676 gfx::PointF device_viewport_point = gfx::ScalePoint( 2712 gfx::PointF device_viewport_point = gfx::ScalePoint(
2677 gfx::PointF(viewport_point), active_tree_->device_scale_factor()); 2713 gfx::PointF(viewport_point), active_tree_->device_scale_factor());
2678 LayerImpl* layer_impl = 2714 LayerImpl* layer_impl =
2679 active_tree_->FindLayerThatIsHitByPoint(device_viewport_point); 2715 active_tree_->FindLayerThatIsHitByPoint(device_viewport_point);
2680 2716
2681 if (layer_impl) { 2717 if (layer_impl) {
2682 LayerImpl* scroll_layer_impl = 2718 LayerImpl* scroll_layer_impl =
(...skipping 860 matching lines...) Expand 10 before | Expand all | Expand 10 after
3543 int scroll_layer_id) const { 3579 int scroll_layer_id) const {
3544 if (InnerViewportScrollLayer() && OuterViewportScrollLayer() && 3580 if (InnerViewportScrollLayer() && OuterViewportScrollLayer() &&
3545 scroll_layer_id == InnerViewportScrollLayer()->id()) 3581 scroll_layer_id == InnerViewportScrollLayer()->id())
3546 scroll_layer_id = OuterViewportScrollLayer()->id(); 3582 scroll_layer_id = OuterViewportScrollLayer()->id();
3547 auto i = scrollbar_animation_controllers_.find(scroll_layer_id); 3583 auto i = scrollbar_animation_controllers_.find(scroll_layer_id);
3548 if (i == scrollbar_animation_controllers_.end()) 3584 if (i == scrollbar_animation_controllers_.end())
3549 return nullptr; 3585 return nullptr;
3550 return i->second.get(); 3586 return i->second.get();
3551 } 3587 }
3552 3588
3589 void LayerTreeHostImpl::RegisterScrollElasticityHelper(int scroll_layer_id) {
3590 DCHECK(!InnerViewportScrollLayer() ||
3591 scroll_layer_id != InnerViewportScrollLayer()->id());
3592 DCHECK(!OuterViewportScrollLayer() ||
3593 scroll_layer_id != OuterViewportScrollLayer()->id());
3594 DCHECK(settings().enable_elastic_overscroll);
3595
3596 auto& helper = scroll_elasticity_helpers_[scroll_layer_id];
3597 if (!helper)
3598 helper = active_tree_->CreateScrollElasticityHelper(scroll_layer_id);
3599 }
3600
3601 void LayerTreeHostImpl::UnregisterScrollElasticityHelper(int scroll_layer_id) {
3602 scroll_elasticity_helpers_.erase(scroll_layer_id);
3603 }
3604
3605 ScrollElasticityHelper* LayerTreeHostImpl::ScrollElasticityHelperForId(
3606 int scroll_layer_id) {
3607 if (!settings().enable_elastic_overscroll)
3608 return nullptr;
3609
3610 auto i = scroll_elasticity_helpers_.find(scroll_layer_id);
3611 if (i != scroll_elasticity_helpers_.end())
3612 return i->second.get();
3613
3614 if (!root_scroll_elasticity_helper_) {
3615 root_scroll_elasticity_helper_.reset(
3616 ScrollElasticityHelper::CreateForLayerTreeHostImpl(this));
3617 }
3618 return root_scroll_elasticity_helper_.get();
3619 }
3620
3553 void LayerTreeHostImpl::PostDelayedScrollbarAnimationTask( 3621 void LayerTreeHostImpl::PostDelayedScrollbarAnimationTask(
3554 const base::Closure& task, 3622 const base::Closure& task,
3555 base::TimeDelta delay) { 3623 base::TimeDelta delay) {
3556 client_->PostDelayedAnimationTaskOnImplThread(task, delay); 3624 client_->PostDelayedAnimationTaskOnImplThread(task, delay);
3557 } 3625 }
3558 3626
3559 // TODO(danakj): Make this a return value from the Animate() call instead of an 3627 // TODO(danakj): Make this a return value from the Animate() call instead of an
3560 // interface on LTHI. (Also, crbug.com/551138.) 3628 // interface on LTHI. (Also, crbug.com/551138.)
3561 void LayerTreeHostImpl::SetNeedsAnimateForScrollbarAnimation() { 3629 void LayerTreeHostImpl::SetNeedsAnimateForScrollbarAnimation() {
3562 TRACE_EVENT0("cc", "LayerTreeHostImpl::SetNeedsAnimateForScrollbarAnimation"); 3630 TRACE_EVENT0("cc", "LayerTreeHostImpl::SetNeedsAnimateForScrollbarAnimation");
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
4052 return task_runner_provider_->HasImplThread(); 4120 return task_runner_provider_->HasImplThread();
4053 } 4121 }
4054 4122
4055 bool LayerTreeHostImpl::CommitToActiveTree() const { 4123 bool LayerTreeHostImpl::CommitToActiveTree() const {
4056 // In single threaded mode we skip the pending tree and commit directly to the 4124 // In single threaded mode we skip the pending tree and commit directly to the
4057 // active tree. 4125 // active tree.
4058 return !task_runner_provider_->HasImplThread(); 4126 return !task_runner_provider_->HasImplThread();
4059 } 4127 }
4060 4128
4061 } // namespace cc 4129 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698