| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 bool LayerTreeHostImpl::ScrollLayerTo(int layer_id, |
| 634 const gfx::ScrollOffset& offset) { |
| 635 LayerImpl* layer = active_tree()->FindActiveTreeLayerById(layer_id); |
| 636 if (!layer) |
| 637 return false; |
| 638 |
| 639 layer->ScrollBy( |
| 640 ScrollOffsetToVector2dF(offset - layer->CurrentScrollOffset())); |
| 641 return true; |
| 623 } | 642 } |
| 624 | 643 |
| 625 void LayerTreeHostImpl::QueueSwapPromiseForMainThreadScrollUpdate( | 644 void LayerTreeHostImpl::QueueSwapPromiseForMainThreadScrollUpdate( |
| 626 std::unique_ptr<SwapPromise> swap_promise) { | 645 std::unique_ptr<SwapPromise> swap_promise) { |
| 627 swap_promises_for_main_thread_scroll_update_.push_back( | 646 swap_promises_for_main_thread_scroll_update_.push_back( |
| 628 std::move(swap_promise)); | 647 std::move(swap_promise)); |
| 629 } | 648 } |
| 630 | 649 |
| 631 void LayerTreeHostImpl::TrackDamageForAllSurfaces( | 650 void LayerTreeHostImpl::TrackDamageForAllSurfaces( |
| 632 const LayerImplList& render_surface_layer_list) { | 651 const LayerImplList& render_surface_layer_list) { |
| (...skipping 1998 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2631 scroll_status.thread = SCROLL_ON_IMPL_THREAD; | 2650 scroll_status.thread = SCROLL_ON_IMPL_THREAD; |
| 2632 ScrollAnimationAbort(scrolling_layer_impl); | 2651 ScrollAnimationAbort(scrolling_layer_impl); |
| 2633 | 2652 |
| 2634 top_controls_manager_->ScrollBegin(); | 2653 top_controls_manager_->ScrollBegin(); |
| 2635 | 2654 |
| 2636 active_tree_->SetCurrentlyScrollingLayer(scrolling_layer_impl); | 2655 active_tree_->SetCurrentlyScrollingLayer(scrolling_layer_impl); |
| 2637 // TODO(majidvp): get rid of wheel_scrolling_ and set is_direct_manipulation | 2656 // TODO(majidvp): get rid of wheel_scrolling_ and set is_direct_manipulation |
| 2638 // in input_handler_proxy instead. | 2657 // in input_handler_proxy instead. |
| 2639 wheel_scrolling_ = IsWheelBasedScroll(type); | 2658 wheel_scrolling_ = IsWheelBasedScroll(type); |
| 2640 scroll_state->set_is_direct_manipulation(!wheel_scrolling_); | 2659 scroll_state->set_is_direct_manipulation(!wheel_scrolling_); |
| 2641 // Invoke |DistributeScrollDelta| even with zero delta and velocity to ensure | 2660 // Invoke |DistributeScrollDelta| even with zero delta and velocity to process |
| 2642 // scroll customization callbacks are invoked. | 2661 // overscroll and ensure scroll customization callbacks are invoked. |
| 2643 DistributeScrollDelta(scroll_state); | 2662 DistributeScrollDelta(scroll_state); |
| 2644 | 2663 |
| 2645 client_->RenewTreePriority(); | 2664 client_->RenewTreePriority(); |
| 2646 RecordCompositorSlowScrollMetric(type, CC_THREAD); | 2665 RecordCompositorSlowScrollMetric(type, CC_THREAD); |
| 2647 | 2666 |
| 2648 return scroll_status; | 2667 return scroll_status; |
| 2649 } | 2668 } |
| 2650 | 2669 |
| 2651 InputHandler::ScrollStatus LayerTreeHostImpl::RootScrollBegin( | 2670 InputHandler::ScrollStatus LayerTreeHostImpl::RootScrollBegin( |
| 2652 ScrollState* scroll_state, | 2671 ScrollState* scroll_state, |
| 2653 InputHandler::ScrollInputType type) { | 2672 InputHandler::ScrollInputType type) { |
| 2654 TRACE_EVENT0("cc", "LayerTreeHostImpl::RootScrollBegin"); | 2673 TRACE_EVENT0("cc", "LayerTreeHostImpl::RootScrollBegin"); |
| 2655 | 2674 |
| 2656 ClearCurrentlyScrollingLayer(); | 2675 ClearCurrentlyScrollingLayer(); |
| 2657 | 2676 |
| 2658 return ScrollBeginImpl(scroll_state, InnerViewportScrollLayer(), type); | 2677 return ScrollBeginImpl(scroll_state, InnerViewportScrollLayer(), type); |
| 2659 } | 2678 } |
| 2660 | 2679 |
| 2661 InputHandler::ScrollStatus LayerTreeHostImpl::ScrollBegin( | 2680 InputHandler::ScrollStatus LayerTreeHostImpl::ScrollBegin( |
| 2662 ScrollState* scroll_state, | 2681 ScrollState* scroll_state, |
| 2663 InputHandler::ScrollInputType type) { | 2682 InputHandler::ScrollInputType type) { |
| 2664 ScrollStatus scroll_status; | 2683 ScrollStatus scroll_status; |
| 2665 scroll_status.main_thread_scrolling_reasons = | 2684 scroll_status.main_thread_scrolling_reasons = |
| 2666 MainThreadScrollingReason::kNotScrollingOnMain; | 2685 MainThreadScrollingReason::kNotScrollingOnMain; |
| 2667 TRACE_EVENT0("cc", "LayerTreeHostImpl::ScrollBegin"); | 2686 TRACE_EVENT0("cc", "LayerTreeHostImpl::ScrollBegin"); |
| 2668 | 2687 |
| 2669 ClearCurrentlyScrollingLayer(); | 2688 ClearCurrentlyScrollingLayer(); |
| 2670 | 2689 |
| 2690 if (!scroll_state->is_beginning()) { |
| 2691 DCHECK(scroll_state->is_in_inertial_phase()); |
| 2692 // When transitioning into a "flick", try to find the layer that was |
| 2693 // already scrolling. Without this, a flick may begin after elastic |
| 2694 // overscroll moves the scrolling layer out from beneath the event, causing |
| 2695 // a failed hit test. |
| 2696 LayerImpl* scrolling_layer_impl = |
| 2697 active_tree_->LayerById(active_tree_->LastScrolledLayerId()); |
| 2698 if (scrolling_layer_impl) |
| 2699 return ScrollBeginImpl(scroll_state, scrolling_layer_impl, type); |
| 2700 } |
| 2701 |
| 2671 gfx::Point viewport_point(scroll_state->position_x(), | 2702 gfx::Point viewport_point(scroll_state->position_x(), |
| 2672 scroll_state->position_y()); | 2703 scroll_state->position_y()); |
| 2673 | 2704 |
| 2674 gfx::PointF device_viewport_point = gfx::ScalePoint( | 2705 gfx::PointF device_viewport_point = gfx::ScalePoint( |
| 2675 gfx::PointF(viewport_point), active_tree_->device_scale_factor()); | 2706 gfx::PointF(viewport_point), active_tree_->device_scale_factor()); |
| 2676 LayerImpl* layer_impl = | 2707 LayerImpl* layer_impl = |
| 2677 active_tree_->FindLayerThatIsHitByPoint(device_viewport_point); | 2708 active_tree_->FindLayerThatIsHitByPoint(device_viewport_point); |
| 2678 | 2709 |
| 2679 if (layer_impl) { | 2710 if (layer_impl) { |
| 2680 LayerImpl* scroll_layer_impl = | 2711 LayerImpl* scroll_layer_impl = |
| (...skipping 860 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3541 int scroll_layer_id) const { | 3572 int scroll_layer_id) const { |
| 3542 if (InnerViewportScrollLayer() && OuterViewportScrollLayer() && | 3573 if (InnerViewportScrollLayer() && OuterViewportScrollLayer() && |
| 3543 scroll_layer_id == InnerViewportScrollLayer()->id()) | 3574 scroll_layer_id == InnerViewportScrollLayer()->id()) |
| 3544 scroll_layer_id = OuterViewportScrollLayer()->id(); | 3575 scroll_layer_id = OuterViewportScrollLayer()->id(); |
| 3545 auto i = scrollbar_animation_controllers_.find(scroll_layer_id); | 3576 auto i = scrollbar_animation_controllers_.find(scroll_layer_id); |
| 3546 if (i == scrollbar_animation_controllers_.end()) | 3577 if (i == scrollbar_animation_controllers_.end()) |
| 3547 return nullptr; | 3578 return nullptr; |
| 3548 return i->second.get(); | 3579 return i->second.get(); |
| 3549 } | 3580 } |
| 3550 | 3581 |
| 3582 void LayerTreeHostImpl::RegisterScrollElasticityHelper(int scroll_layer_id) { |
| 3583 DCHECK(!InnerViewportScrollLayer() || |
| 3584 scroll_layer_id != InnerViewportScrollLayer()->id()); |
| 3585 DCHECK(!OuterViewportScrollLayer() || |
| 3586 scroll_layer_id != OuterViewportScrollLayer()->id()); |
| 3587 DCHECK(settings().enable_elastic_overscroll); |
| 3588 |
| 3589 auto& helper = scroll_elasticity_helpers_[scroll_layer_id]; |
| 3590 if (!helper) |
| 3591 helper = active_tree_->CreateScrollElasticityHelper(scroll_layer_id); |
| 3592 } |
| 3593 |
| 3594 void LayerTreeHostImpl::UnregisterScrollElasticityHelper(int scroll_layer_id) { |
| 3595 scroll_elasticity_helpers_.erase(scroll_layer_id); |
| 3596 } |
| 3597 |
| 3598 ScrollElasticityHelper* LayerTreeHostImpl::ScrollElasticityHelperForId( |
| 3599 int scroll_layer_id) { |
| 3600 if (!settings().enable_elastic_overscroll) |
| 3601 return nullptr; |
| 3602 |
| 3603 auto i = scroll_elasticity_helpers_.find(scroll_layer_id); |
| 3604 if (i != scroll_elasticity_helpers_.end()) |
| 3605 return i->second.get(); |
| 3606 |
| 3607 if (!root_scroll_elasticity_helper_) { |
| 3608 root_scroll_elasticity_helper_.reset( |
| 3609 ScrollElasticityHelper::CreateForLayerTreeHostImpl(this)); |
| 3610 } |
| 3611 return root_scroll_elasticity_helper_.get(); |
| 3612 } |
| 3613 |
| 3551 void LayerTreeHostImpl::PostDelayedScrollbarAnimationTask( | 3614 void LayerTreeHostImpl::PostDelayedScrollbarAnimationTask( |
| 3552 const base::Closure& task, | 3615 const base::Closure& task, |
| 3553 base::TimeDelta delay) { | 3616 base::TimeDelta delay) { |
| 3554 client_->PostDelayedAnimationTaskOnImplThread(task, delay); | 3617 client_->PostDelayedAnimationTaskOnImplThread(task, delay); |
| 3555 } | 3618 } |
| 3556 | 3619 |
| 3557 // TODO(danakj): Make this a return value from the Animate() call instead of an | 3620 // TODO(danakj): Make this a return value from the Animate() call instead of an |
| 3558 // interface on LTHI. (Also, crbug.com/551138.) | 3621 // interface on LTHI. (Also, crbug.com/551138.) |
| 3559 void LayerTreeHostImpl::SetNeedsAnimateForScrollbarAnimation() { | 3622 void LayerTreeHostImpl::SetNeedsAnimateForScrollbarAnimation() { |
| 3560 TRACE_EVENT0("cc", "LayerTreeHostImpl::SetNeedsAnimateForScrollbarAnimation"); | 3623 TRACE_EVENT0("cc", "LayerTreeHostImpl::SetNeedsAnimateForScrollbarAnimation"); |
| (...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4050 return task_runner_provider_->HasImplThread(); | 4113 return task_runner_provider_->HasImplThread(); |
| 4051 } | 4114 } |
| 4052 | 4115 |
| 4053 bool LayerTreeHostImpl::CommitToActiveTree() const { | 4116 bool LayerTreeHostImpl::CommitToActiveTree() const { |
| 4054 // In single threaded mode we skip the pending tree and commit directly to the | 4117 // In single threaded mode we skip the pending tree and commit directly to the |
| 4055 // active tree. | 4118 // active tree. |
| 4056 return !task_runner_provider_->HasImplThread(); | 4119 return !task_runner_provider_->HasImplThread(); |
| 4057 } | 4120 } |
| 4058 | 4121 |
| 4059 } // namespace cc | 4122 } // namespace cc |
| OLD | NEW |