| 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 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 DCHECK(!resource_provider_); | 279 DCHECK(!resource_provider_); |
| 280 DCHECK(!resource_pool_); | 280 DCHECK(!resource_pool_); |
| 281 DCHECK(!tile_task_manager_); | 281 DCHECK(!tile_task_manager_); |
| 282 DCHECK(!single_thread_synchronous_task_graph_runner_); | 282 DCHECK(!single_thread_synchronous_task_graph_runner_); |
| 283 DCHECK(!image_decode_controller_); | 283 DCHECK(!image_decode_controller_); |
| 284 | 284 |
| 285 if (input_handler_client_) { | 285 if (input_handler_client_) { |
| 286 input_handler_client_->WillShutdown(); | 286 input_handler_client_->WillShutdown(); |
| 287 input_handler_client_ = NULL; | 287 input_handler_client_ = NULL; |
| 288 } | 288 } |
| 289 if (scroll_elasticity_helper_) | 289 root_scroll_elasticity_helper_.reset(); |
| 290 scroll_elasticity_helper_.reset(); | |
| 291 | 290 |
| 292 // The layer trees must be destroyed before the layer tree host. We've | 291 // The layer trees must be destroyed before the layer tree host. We've |
| 293 // made a contract with our animation controllers that the animation_host | 292 // made a contract with our animation controllers that the animation_host |
| 294 // will outlive them, and we must make good. | 293 // will outlive them, and we must make good. |
| 295 if (recycle_tree_) | 294 if (recycle_tree_) |
| 296 recycle_tree_->Shutdown(); | 295 recycle_tree_->Shutdown(); |
| 297 if (pending_tree_) | 296 if (pending_tree_) |
| 298 pending_tree_->Shutdown(); | 297 pending_tree_->Shutdown(); |
| 299 active_tree_->Shutdown(); | 298 active_tree_->Shutdown(); |
| 300 recycle_tree_ = nullptr; | 299 recycle_tree_ = nullptr; |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 607 return layer_impl != NULL; | 606 return layer_impl != NULL; |
| 608 } | 607 } |
| 609 | 608 |
| 610 std::unique_ptr<SwapPromiseMonitor> | 609 std::unique_ptr<SwapPromiseMonitor> |
| 611 LayerTreeHostImpl::CreateLatencyInfoSwapPromiseMonitor( | 610 LayerTreeHostImpl::CreateLatencyInfoSwapPromiseMonitor( |
| 612 ui::LatencyInfo* latency) { | 611 ui::LatencyInfo* latency) { |
| 613 return base::WrapUnique( | 612 return base::WrapUnique( |
| 614 new LatencyInfoSwapPromiseMonitor(latency, NULL, this)); | 613 new LatencyInfoSwapPromiseMonitor(latency, NULL, this)); |
| 615 } | 614 } |
| 616 | 615 |
| 617 ScrollElasticityHelper* LayerTreeHostImpl::CreateScrollElasticityHelper() { | 616 ScrollElasticityHelper* LayerTreeHostImpl::CreateRootScrollElasticityHelper() { |
| 618 DCHECK(!scroll_elasticity_helper_); | 617 DCHECK(!root_scroll_elasticity_helper_); |
| 619 if (settings_.enable_elastic_overscroll) { | 618 if (settings_.enable_elastic_overscroll) { |
| 620 scroll_elasticity_helper_.reset( | 619 root_scroll_elasticity_helper_.reset( |
| 621 ScrollElasticityHelper::CreateForLayerTreeHostImpl(this)); | 620 ScrollElasticityHelper::CreateForLayerTreeHostImpl(this)); |
| 622 } | 621 } |
| 623 return scroll_elasticity_helper_.get(); | 622 return root_scroll_elasticity_helper_.get(); |
| 623 } |
| 624 |
| 625 base::WeakPtr<ScrollElasticityHelper> |
| 626 LayerTreeHostImpl::ScrollElasticityHelperForScrollingLayer() { |
| 627 LayerImpl* scrolling_layer_impl = CurrentlyScrollingLayer(); |
| 628 if (!scrolling_layer_impl) |
| 629 return nullptr; |
| 630 |
| 631 return ScrollElasticityHelperForId(scrolling_layer_impl->id())->GetWeakPtr(); |
| 624 } | 632 } |
| 625 | 633 |
| 626 bool LayerTreeHostImpl::GetScrollOffsetForLayer(int layer_id, | 634 bool LayerTreeHostImpl::GetScrollOffsetForLayer(int layer_id, |
| 627 gfx::ScrollOffset* offset) { | 635 gfx::ScrollOffset* offset) { |
| 628 LayerImpl* layer = active_tree()->FindActiveTreeLayerById(layer_id); | 636 LayerImpl* layer = active_tree()->FindActiveTreeLayerById(layer_id); |
| 629 if (!layer) | 637 if (!layer) |
| 630 return false; | 638 return false; |
| 631 | 639 |
| 632 *offset = layer->CurrentScrollOffset(); | 640 *offset = layer->CurrentScrollOffset(); |
| 633 return true; | 641 return true; |
| (...skipping 1975 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2609 scroll_status.thread = SCROLL_ON_IMPL_THREAD; | 2617 scroll_status.thread = SCROLL_ON_IMPL_THREAD; |
| 2610 ScrollAnimationAbort(scrolling_layer_impl); | 2618 ScrollAnimationAbort(scrolling_layer_impl); |
| 2611 | 2619 |
| 2612 top_controls_manager_->ScrollBegin(); | 2620 top_controls_manager_->ScrollBegin(); |
| 2613 | 2621 |
| 2614 active_tree_->SetCurrentlyScrollingLayer(scrolling_layer_impl); | 2622 active_tree_->SetCurrentlyScrollingLayer(scrolling_layer_impl); |
| 2615 // TODO(majidvp): get rid of wheel_scrolling_ and set is_direct_manipulation | 2623 // TODO(majidvp): get rid of wheel_scrolling_ and set is_direct_manipulation |
| 2616 // in input_handler_proxy instead. | 2624 // in input_handler_proxy instead. |
| 2617 wheel_scrolling_ = IsWheelBasedScroll(type); | 2625 wheel_scrolling_ = IsWheelBasedScroll(type); |
| 2618 scroll_state->set_is_direct_manipulation(!wheel_scrolling_); | 2626 scroll_state->set_is_direct_manipulation(!wheel_scrolling_); |
| 2619 // Invoke |DistributeScrollDelta| even with zero delta and velocity to ensure | 2627 // Invoke |DistributeScrollDelta| even with zero delta and velocity to process |
| 2620 // scroll customization callbacks are invoked. | 2628 // overscroll and ensure scroll customization callbacks are invoked. |
| 2621 DistributeScrollDelta(scroll_state); | 2629 DistributeScrollDelta(scroll_state); |
| 2622 | 2630 |
| 2623 client_->RenewTreePriority(); | 2631 client_->RenewTreePriority(); |
| 2624 RecordCompositorSlowScrollMetric(type, CC_THREAD); | 2632 RecordCompositorSlowScrollMetric(type, CC_THREAD); |
| 2625 | 2633 |
| 2626 return scroll_status; | 2634 return scroll_status; |
| 2627 } | 2635 } |
| 2628 | 2636 |
| 2629 InputHandler::ScrollStatus LayerTreeHostImpl::RootScrollBegin( | 2637 InputHandler::ScrollStatus LayerTreeHostImpl::RootScrollBegin( |
| 2630 ScrollState* scroll_state, | 2638 ScrollState* scroll_state, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 2645 MainThreadScrollingReason::kNotScrollingOnMain; | 2653 MainThreadScrollingReason::kNotScrollingOnMain; |
| 2646 TRACE_EVENT0("cc", "LayerTreeHostImpl::ScrollBegin"); | 2654 TRACE_EVENT0("cc", "LayerTreeHostImpl::ScrollBegin"); |
| 2647 | 2655 |
| 2648 // On Mac a scroll begin with |inertial_phase| = true happens to handle a | 2656 // On Mac a scroll begin with |inertial_phase| = true happens to handle a |
| 2649 // fling. | 2657 // fling. |
| 2650 if (scroll_state->is_in_inertial_phase()) | 2658 if (scroll_state->is_in_inertial_phase()) |
| 2651 return FlingScrollBegin(); | 2659 return FlingScrollBegin(); |
| 2652 | 2660 |
| 2653 ClearCurrentlyScrollingLayer(); | 2661 ClearCurrentlyScrollingLayer(); |
| 2654 | 2662 |
| 2663 if (!scroll_state->is_beginning()) { |
| 2664 DCHECK(scroll_state->is_in_inertial_phase()); |
| 2665 // When transitioning into a "flick", try to find the layer that was |
| 2666 // already scrolling. Without this, a flick may begin after elastic |
| 2667 // overscroll moves the scrolling layer out from beneath the event, causing |
| 2668 // a failed hit test. |
| 2669 LayerImpl* scrolling_layer_impl = |
| 2670 active_tree_->LayerById(active_tree_->LastScrolledLayerId()); |
| 2671 if (scrolling_layer_impl) |
| 2672 return ScrollBeginImpl(scroll_state, scrolling_layer_impl, type); |
| 2673 } |
| 2674 |
| 2655 gfx::Point viewport_point(scroll_state->position_x(), | 2675 gfx::Point viewport_point(scroll_state->position_x(), |
| 2656 scroll_state->position_y()); | 2676 scroll_state->position_y()); |
| 2657 | 2677 |
| 2658 gfx::PointF device_viewport_point = gfx::ScalePoint( | 2678 gfx::PointF device_viewport_point = gfx::ScalePoint( |
| 2659 gfx::PointF(viewport_point), active_tree_->device_scale_factor()); | 2679 gfx::PointF(viewport_point), active_tree_->device_scale_factor()); |
| 2660 LayerImpl* layer_impl = | 2680 LayerImpl* layer_impl = |
| 2661 active_tree_->FindLayerThatIsHitByPoint(device_viewport_point); | 2681 active_tree_->FindLayerThatIsHitByPoint(device_viewport_point); |
| 2662 | 2682 |
| 2663 if (layer_impl) { | 2683 if (layer_impl) { |
| 2664 LayerImpl* scroll_layer_impl = | 2684 LayerImpl* scroll_layer_impl = |
| (...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3068 scroll_state->set_scroll_chain_and_layer_tree(current_scroll_chain, | 3088 scroll_state->set_scroll_chain_and_layer_tree(current_scroll_chain, |
| 3069 active_tree()); | 3089 active_tree()); |
| 3070 scroll_state->DistributeToScrollChainDescendant(); | 3090 scroll_state->DistributeToScrollChainDescendant(); |
| 3071 } | 3091 } |
| 3072 | 3092 |
| 3073 InputHandlerScrollResult LayerTreeHostImpl::ScrollBy( | 3093 InputHandlerScrollResult LayerTreeHostImpl::ScrollBy( |
| 3074 ScrollState* scroll_state) { | 3094 ScrollState* scroll_state) { |
| 3075 DCHECK(scroll_state); | 3095 DCHECK(scroll_state); |
| 3076 | 3096 |
| 3077 TRACE_EVENT0("cc", "LayerTreeHostImpl::ScrollBy"); | 3097 TRACE_EVENT0("cc", "LayerTreeHostImpl::ScrollBy"); |
| 3098 |
| 3099 if (!CurrentlyScrollingLayer()) { |
| 3100 // If the InputHandlerClient didn't call ScrollBegin() to re-perform a |
| 3101 // hit-test but provided an element to scroll instead, scroll that. For now, |
| 3102 // just compare it against the last scrolled layer. |
| 3103 ElementId provided_element = |
| 3104 scroll_state->data()->current_native_scrolling_element(); |
| 3105 int last_scrolled = active_tree()->LastScrolledLayerId(); |
| 3106 if (provided_element && last_scrolled) { |
| 3107 LayerImpl* layer = active_tree()->LayerById(last_scrolled); |
| 3108 if (layer && layer->element_id() == provided_element) |
| 3109 active_tree_->SetCurrentlyScrollingLayer(layer); |
| 3110 } |
| 3111 } |
| 3112 |
| 3078 if (!CurrentlyScrollingLayer()) | 3113 if (!CurrentlyScrollingLayer()) |
| 3079 return InputHandlerScrollResult(); | 3114 return InputHandlerScrollResult(); |
| 3080 | 3115 |
| 3081 float initial_top_controls_offset = | 3116 float initial_top_controls_offset = |
| 3082 top_controls_manager_->ControlsTopOffset(); | 3117 top_controls_manager_->ControlsTopOffset(); |
| 3083 | 3118 |
| 3084 scroll_state->set_delta_consumed_for_scroll_sequence( | 3119 scroll_state->set_delta_consumed_for_scroll_sequence( |
| 3085 did_lock_scrolling_layer_); | 3120 did_lock_scrolling_layer_); |
| 3086 scroll_state->set_is_direct_manipulation(!wheel_scrolling_); | 3121 scroll_state->set_is_direct_manipulation(!wheel_scrolling_); |
| 3087 scroll_state->set_current_native_scrolling_node( | 3122 scroll_state->set_current_native_scrolling_node( |
| (...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3510 // is registered with the outer viewport. | 3545 // is registered with the outer viewport. |
| 3511 if (InnerViewportScrollLayer() && OuterViewportScrollLayer() && | 3546 if (InnerViewportScrollLayer() && OuterViewportScrollLayer() && |
| 3512 scroll_layer_id == InnerViewportScrollLayer()->id()) | 3547 scroll_layer_id == InnerViewportScrollLayer()->id()) |
| 3513 scroll_layer_id = OuterViewportScrollLayer()->id(); | 3548 scroll_layer_id = OuterViewportScrollLayer()->id(); |
| 3514 auto i = scrollbar_animation_controllers_.find(scroll_layer_id); | 3549 auto i = scrollbar_animation_controllers_.find(scroll_layer_id); |
| 3515 if (i == scrollbar_animation_controllers_.end()) | 3550 if (i == scrollbar_animation_controllers_.end()) |
| 3516 return nullptr; | 3551 return nullptr; |
| 3517 return i->second.get(); | 3552 return i->second.get(); |
| 3518 } | 3553 } |
| 3519 | 3554 |
| 3555 void LayerTreeHostImpl::RegisterScrollElasticityHelper(int scroll_layer_id) { |
| 3556 DCHECK(!InnerViewportScrollLayer() || |
| 3557 scroll_layer_id != InnerViewportScrollLayer()->id()); |
| 3558 DCHECK(!OuterViewportScrollLayer() || |
| 3559 scroll_layer_id != OuterViewportScrollLayer()->id()); |
| 3560 DCHECK(settings().enable_elastic_overscroll); |
| 3561 |
| 3562 auto& helper = scroll_elasticity_helpers_[scroll_layer_id]; |
| 3563 if (!helper) |
| 3564 helper = active_tree_->CreateScrollElasticityHelper(scroll_layer_id); |
| 3565 } |
| 3566 |
| 3567 void LayerTreeHostImpl::UnregisterScrollElasticityHelper(int scroll_layer_id) { |
| 3568 scroll_elasticity_helpers_.erase(scroll_layer_id); |
| 3569 } |
| 3570 |
| 3571 ScrollElasticityHelper* LayerTreeHostImpl::ScrollElasticityHelperForId( |
| 3572 int scroll_layer_id) { |
| 3573 if (!settings().enable_elastic_overscroll) |
| 3574 return nullptr; |
| 3575 |
| 3576 auto i = scroll_elasticity_helpers_.find(scroll_layer_id); |
| 3577 if (i != scroll_elasticity_helpers_.end()) |
| 3578 return i->second.get(); |
| 3579 |
| 3580 if (!root_scroll_elasticity_helper_) { |
| 3581 root_scroll_elasticity_helper_.reset( |
| 3582 ScrollElasticityHelper::CreateForLayerTreeHostImpl(this)); |
| 3583 } |
| 3584 return root_scroll_elasticity_helper_.get(); |
| 3585 } |
| 3586 |
| 3520 void LayerTreeHostImpl::PostDelayedScrollbarAnimationTask( | 3587 void LayerTreeHostImpl::PostDelayedScrollbarAnimationTask( |
| 3521 const base::Closure& task, | 3588 const base::Closure& task, |
| 3522 base::TimeDelta delay) { | 3589 base::TimeDelta delay) { |
| 3523 client_->PostDelayedAnimationTaskOnImplThread(task, delay); | 3590 client_->PostDelayedAnimationTaskOnImplThread(task, delay); |
| 3524 } | 3591 } |
| 3525 | 3592 |
| 3526 // TODO(danakj): Make this a return value from the Animate() call instead of an | 3593 // TODO(danakj): Make this a return value from the Animate() call instead of an |
| 3527 // interface on LTHI. (Also, crbug.com/551138.) | 3594 // interface on LTHI. (Also, crbug.com/551138.) |
| 3528 void LayerTreeHostImpl::SetNeedsAnimateForScrollbarAnimation() { | 3595 void LayerTreeHostImpl::SetNeedsAnimateForScrollbarAnimation() { |
| 3529 TRACE_EVENT0("cc", "LayerTreeHostImpl::SetNeedsAnimateForScrollbarAnimation"); | 3596 TRACE_EVENT0("cc", "LayerTreeHostImpl::SetNeedsAnimateForScrollbarAnimation"); |
| (...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4089 if (is_visible) { | 4156 if (is_visible) { |
| 4090 worker_context_visibility_ = | 4157 worker_context_visibility_ = |
| 4091 worker_context->CacheController()->ClientBecameVisible(); | 4158 worker_context->CacheController()->ClientBecameVisible(); |
| 4092 } else { | 4159 } else { |
| 4093 worker_context->CacheController()->ClientBecameNotVisible( | 4160 worker_context->CacheController()->ClientBecameNotVisible( |
| 4094 std::move(worker_context_visibility_)); | 4161 std::move(worker_context_visibility_)); |
| 4095 } | 4162 } |
| 4096 } | 4163 } |
| 4097 | 4164 |
| 4098 } // namespace cc | 4165 } // namespace cc |
| OLD | NEW |