| 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 2759 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2770 InputHandler::ScrollStatus LayerTreeHostImpl::ScrollAnimatedBegin( | 2770 InputHandler::ScrollStatus LayerTreeHostImpl::ScrollAnimatedBegin( |
| 2771 const gfx::Point& viewport_point) { | 2771 const gfx::Point& viewport_point) { |
| 2772 InputHandler::ScrollStatus scroll_status; | 2772 InputHandler::ScrollStatus scroll_status; |
| 2773 scroll_status.main_thread_scrolling_reasons = | 2773 scroll_status.main_thread_scrolling_reasons = |
| 2774 MainThreadScrollingReason::kNotScrollingOnMain; | 2774 MainThreadScrollingReason::kNotScrollingOnMain; |
| 2775 ScrollTree& scroll_tree = active_tree_->property_trees()->scroll_tree; | 2775 ScrollTree& scroll_tree = active_tree_->property_trees()->scroll_tree; |
| 2776 ScrollNode* scroll_node = scroll_tree.CurrentlyScrollingNode(); | 2776 ScrollNode* scroll_node = scroll_tree.CurrentlyScrollingNode(); |
| 2777 if (scroll_node) { | 2777 if (scroll_node) { |
| 2778 gfx::Vector2dF delta; | 2778 gfx::Vector2dF delta; |
| 2779 | 2779 |
| 2780 if (ScrollAnimationUpdateTarget(scroll_node, delta)) { | 2780 if (ScrollAnimationUpdateTarget(scroll_node, delta, base::TimeDelta())) { |
| 2781 scroll_status.thread = SCROLL_ON_IMPL_THREAD; | 2781 scroll_status.thread = SCROLL_ON_IMPL_THREAD; |
| 2782 } else { | 2782 } else { |
| 2783 scroll_status.thread = SCROLL_IGNORED; | 2783 scroll_status.thread = SCROLL_IGNORED; |
| 2784 scroll_status.main_thread_scrolling_reasons = | 2784 scroll_status.main_thread_scrolling_reasons = |
| 2785 MainThreadScrollingReason::kNotScrollable; | 2785 MainThreadScrollingReason::kNotScrollable; |
| 2786 } | 2786 } |
| 2787 return scroll_status; | 2787 return scroll_status; |
| 2788 } | 2788 } |
| 2789 ScrollStateData scroll_state_data; | 2789 ScrollStateData scroll_state_data; |
| 2790 scroll_state_data.position_x = viewport_point.x(); | 2790 scroll_state_data.position_x = viewport_point.x(); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2823 gfx::ScrollOffset old_offset = | 2823 gfx::ScrollOffset old_offset = |
| 2824 scroll_tree.current_scroll_offset(scroll_node->owner_id); | 2824 scroll_tree.current_scroll_offset(scroll_node->owner_id); |
| 2825 gfx::ScrollOffset new_offset = scroll_tree.ClampScrollOffsetToLimits( | 2825 gfx::ScrollOffset new_offset = scroll_tree.ClampScrollOffsetToLimits( |
| 2826 old_offset + gfx::ScrollOffset(adjusted_scroll), scroll_node); | 2826 old_offset + gfx::ScrollOffset(adjusted_scroll), scroll_node); |
| 2827 | 2827 |
| 2828 gfx::ScrollOffset scrolled = new_offset - old_offset; | 2828 gfx::ScrollOffset scrolled = new_offset - old_offset; |
| 2829 return gfx::Vector2dF(scrolled.x(), scrolled.y()); | 2829 return gfx::Vector2dF(scrolled.x(), scrolled.y()); |
| 2830 } | 2830 } |
| 2831 | 2831 |
| 2832 bool LayerTreeHostImpl::ScrollAnimationCreate(ScrollNode* scroll_node, | 2832 bool LayerTreeHostImpl::ScrollAnimationCreate(ScrollNode* scroll_node, |
| 2833 const gfx::Vector2dF& delta) { | 2833 const gfx::Vector2dF& delta, |
| 2834 base::TimeDelta delayed_by) { |
| 2834 ScrollTree& scroll_tree = active_tree_->property_trees()->scroll_tree; | 2835 ScrollTree& scroll_tree = active_tree_->property_trees()->scroll_tree; |
| 2835 | 2836 |
| 2836 const float kEpsilon = 0.1f; | 2837 const float kEpsilon = 0.1f; |
| 2837 bool scroll_animated = | 2838 bool scroll_animated = |
| 2838 (std::abs(delta.x()) > kEpsilon || std::abs(delta.y()) > kEpsilon); | 2839 (std::abs(delta.x()) > kEpsilon || std::abs(delta.y()) > kEpsilon); |
| 2839 if (!scroll_animated) { | 2840 if (!scroll_animated) { |
| 2840 scroll_tree.ScrollBy(scroll_node, delta, active_tree()); | 2841 scroll_tree.ScrollBy(scroll_node, delta, active_tree()); |
| 2841 return false; | 2842 return false; |
| 2842 } | 2843 } |
| 2843 | 2844 |
| 2844 scroll_tree.set_currently_scrolling_node(scroll_node->id); | 2845 scroll_tree.set_currently_scrolling_node(scroll_node->id); |
| 2845 | 2846 |
| 2846 gfx::ScrollOffset current_offset = | 2847 gfx::ScrollOffset current_offset = |
| 2847 scroll_tree.current_scroll_offset(scroll_node->owner_id); | 2848 scroll_tree.current_scroll_offset(scroll_node->owner_id); |
| 2848 gfx::ScrollOffset target_offset = scroll_tree.ClampScrollOffsetToLimits( | 2849 gfx::ScrollOffset target_offset = scroll_tree.ClampScrollOffsetToLimits( |
| 2849 current_offset + gfx::ScrollOffset(delta), scroll_node); | 2850 current_offset + gfx::ScrollOffset(delta), scroll_node); |
| 2850 DCHECK_EQ( | 2851 DCHECK_EQ( |
| 2851 ElementId(active_tree()->LayerById(scroll_node->owner_id)->element_id()), | 2852 ElementId(active_tree()->LayerById(scroll_node->owner_id)->element_id()), |
| 2852 scroll_node->element_id); | 2853 scroll_node->element_id); |
| 2853 | 2854 |
| 2854 animation_host_->ImplOnlyScrollAnimationCreate(scroll_node->element_id, | 2855 animation_host_->ImplOnlyScrollAnimationCreate( |
| 2855 target_offset, current_offset); | 2856 scroll_node->element_id, target_offset, current_offset, delayed_by); |
| 2856 | 2857 |
| 2857 SetNeedsOneBeginImplFrame(); | 2858 SetNeedsOneBeginImplFrame(); |
| 2858 | 2859 |
| 2859 return true; | 2860 return true; |
| 2860 } | 2861 } |
| 2861 | 2862 |
| 2862 InputHandler::ScrollStatus LayerTreeHostImpl::ScrollAnimated( | 2863 InputHandler::ScrollStatus LayerTreeHostImpl::ScrollAnimated( |
| 2863 const gfx::Point& viewport_point, | 2864 const gfx::Point& viewport_point, |
| 2864 const gfx::Vector2dF& scroll_delta) { | 2865 const gfx::Vector2dF& scroll_delta, |
| 2866 base::TimeDelta delayed_by) { |
| 2865 InputHandler::ScrollStatus scroll_status; | 2867 InputHandler::ScrollStatus scroll_status; |
| 2866 scroll_status.main_thread_scrolling_reasons = | 2868 scroll_status.main_thread_scrolling_reasons = |
| 2867 MainThreadScrollingReason::kNotScrollingOnMain; | 2869 MainThreadScrollingReason::kNotScrollingOnMain; |
| 2868 ScrollTree& scroll_tree = active_tree_->property_trees()->scroll_tree; | 2870 ScrollTree& scroll_tree = active_tree_->property_trees()->scroll_tree; |
| 2869 ScrollNode* scroll_node = scroll_tree.CurrentlyScrollingNode(); | 2871 ScrollNode* scroll_node = scroll_tree.CurrentlyScrollingNode(); |
| 2870 if (scroll_node) { | 2872 if (scroll_node) { |
| 2871 gfx::Vector2dF delta = scroll_delta; | 2873 gfx::Vector2dF delta = scroll_delta; |
| 2872 if (!scroll_node->user_scrollable_horizontal) | 2874 if (!scroll_node->user_scrollable_horizontal) |
| 2873 delta.set_x(0); | 2875 delta.set_x(0); |
| 2874 if (!scroll_node->user_scrollable_vertical) | 2876 if (!scroll_node->user_scrollable_vertical) |
| 2875 delta.set_y(0); | 2877 delta.set_y(0); |
| 2876 | 2878 |
| 2877 if (ScrollAnimationUpdateTarget(scroll_node, delta)) { | 2879 if (ScrollAnimationUpdateTarget(scroll_node, delta, delayed_by)) { |
| 2878 scroll_status.thread = SCROLL_ON_IMPL_THREAD; | 2880 scroll_status.thread = SCROLL_ON_IMPL_THREAD; |
| 2879 } else { | 2881 } else { |
| 2880 scroll_status.thread = SCROLL_IGNORED; | 2882 scroll_status.thread = SCROLL_IGNORED; |
| 2881 scroll_status.main_thread_scrolling_reasons = | 2883 scroll_status.main_thread_scrolling_reasons = |
| 2882 MainThreadScrollingReason::kNotScrollable; | 2884 MainThreadScrollingReason::kNotScrollable; |
| 2883 } | 2885 } |
| 2884 return scroll_status; | 2886 return scroll_status; |
| 2885 } | 2887 } |
| 2886 | 2888 |
| 2887 ScrollStateData scroll_state_data; | 2889 ScrollStateData scroll_state_data; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2899 if (scroll_status.thread == SCROLL_ON_IMPL_THREAD) { | 2901 if (scroll_status.thread == SCROLL_ON_IMPL_THREAD) { |
| 2900 gfx::Vector2dF pending_delta = scroll_delta; | 2902 gfx::Vector2dF pending_delta = scroll_delta; |
| 2901 if (scroll_node) { | 2903 if (scroll_node) { |
| 2902 for (; scroll_tree.parent(scroll_node); | 2904 for (; scroll_tree.parent(scroll_node); |
| 2903 scroll_node = scroll_tree.parent(scroll_node)) { | 2905 scroll_node = scroll_tree.parent(scroll_node)) { |
| 2904 if (!scroll_node->scrollable || | 2906 if (!scroll_node->scrollable || |
| 2905 scroll_node->is_outer_viewport_scroll_layer) | 2907 scroll_node->is_outer_viewport_scroll_layer) |
| 2906 continue; | 2908 continue; |
| 2907 | 2909 |
| 2908 if (scroll_node->is_inner_viewport_scroll_layer) { | 2910 if (scroll_node->is_inner_viewport_scroll_layer) { |
| 2909 gfx::Vector2dF scrolled = viewport()->ScrollAnimated(pending_delta); | 2911 gfx::Vector2dF scrolled = |
| 2912 viewport()->ScrollAnimated(pending_delta, delayed_by); |
| 2910 // Viewport::ScrollAnimated returns pending_delta as long as it | 2913 // Viewport::ScrollAnimated returns pending_delta as long as it |
| 2911 // starts an animation. | 2914 // starts an animation. |
| 2912 if (scrolled == pending_delta) | 2915 if (scrolled == pending_delta) |
| 2913 return scroll_status; | 2916 return scroll_status; |
| 2914 pending_delta -= scrolled; | 2917 pending_delta -= scrolled; |
| 2915 continue; | 2918 continue; |
| 2916 } | 2919 } |
| 2917 | 2920 |
| 2918 gfx::Vector2dF scroll_delta = | 2921 gfx::Vector2dF scroll_delta = |
| 2919 ComputeScrollDelta(scroll_node, pending_delta); | 2922 ComputeScrollDelta(scroll_node, pending_delta); |
| 2920 if (ScrollAnimationCreate(scroll_node, scroll_delta)) | 2923 if (ScrollAnimationCreate(scroll_node, scroll_delta, delayed_by)) |
| 2921 return scroll_status; | 2924 return scroll_status; |
| 2922 | 2925 |
| 2923 pending_delta -= scroll_delta; | 2926 pending_delta -= scroll_delta; |
| 2924 } | 2927 } |
| 2925 } | 2928 } |
| 2926 } | 2929 } |
| 2927 scroll_state.set_is_ending(true); | 2930 scroll_state.set_is_ending(true); |
| 2928 ScrollEnd(&scroll_state); | 2931 ScrollEnd(&scroll_state); |
| 2929 return scroll_status; | 2932 return scroll_status; |
| 2930 } | 2933 } |
| (...skipping 938 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3869 active_tree_->min_page_scale_factor(), | 3872 active_tree_->min_page_scale_factor(), |
| 3870 active_tree_->max_page_scale_factor()); | 3873 active_tree_->max_page_scale_factor()); |
| 3871 } | 3874 } |
| 3872 | 3875 |
| 3873 void LayerTreeHostImpl::ScrollAnimationAbort(LayerImpl* layer_impl) { | 3876 void LayerTreeHostImpl::ScrollAnimationAbort(LayerImpl* layer_impl) { |
| 3874 return animation_host_->ScrollAnimationAbort(false /* needs_completion */); | 3877 return animation_host_->ScrollAnimationAbort(false /* needs_completion */); |
| 3875 } | 3878 } |
| 3876 | 3879 |
| 3877 bool LayerTreeHostImpl::ScrollAnimationUpdateTarget( | 3880 bool LayerTreeHostImpl::ScrollAnimationUpdateTarget( |
| 3878 ScrollNode* scroll_node, | 3881 ScrollNode* scroll_node, |
| 3879 const gfx::Vector2dF& scroll_delta) { | 3882 const gfx::Vector2dF& scroll_delta, |
| 3883 base::TimeDelta delayed_by) { |
| 3880 DCHECK_EQ( | 3884 DCHECK_EQ( |
| 3881 ElementId(active_tree()->LayerById(scroll_node->owner_id)->element_id()), | 3885 ElementId(active_tree()->LayerById(scroll_node->owner_id)->element_id()), |
| 3882 scroll_node->element_id); | 3886 scroll_node->element_id); |
| 3883 | 3887 |
| 3884 return animation_host_->ImplOnlyScrollAnimationUpdateTarget( | 3888 return animation_host_->ImplOnlyScrollAnimationUpdateTarget( |
| 3885 scroll_node->element_id, scroll_delta, | 3889 scroll_node->element_id, scroll_delta, |
| 3886 active_tree_->property_trees()->scroll_tree.MaxScrollOffset( | 3890 active_tree_->property_trees()->scroll_tree.MaxScrollOffset( |
| 3887 scroll_node->id), | 3891 scroll_node->id), |
| 3888 CurrentBeginFrameArgs().frame_time); | 3892 CurrentBeginFrameArgs().frame_time, delayed_by); |
| 3889 } | 3893 } |
| 3890 | 3894 |
| 3891 bool LayerTreeHostImpl::IsElementInList(ElementId element_id, | 3895 bool LayerTreeHostImpl::IsElementInList(ElementId element_id, |
| 3892 ElementListType list_type) const { | 3896 ElementListType list_type) const { |
| 3893 if (list_type == ElementListType::ACTIVE) { | 3897 if (list_type == ElementListType::ACTIVE) { |
| 3894 return active_tree() | 3898 return active_tree() |
| 3895 ? active_tree()->LayerByElementId(element_id) != nullptr | 3899 ? active_tree()->LayerByElementId(element_id) != nullptr |
| 3896 : false; | 3900 : false; |
| 3897 } else { | 3901 } else { |
| 3898 if (pending_tree() && pending_tree()->LayerByElementId(element_id)) | 3902 if (pending_tree() && pending_tree()->LayerByElementId(element_id)) |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4112 return task_runner_provider_->HasImplThread(); | 4116 return task_runner_provider_->HasImplThread(); |
| 4113 } | 4117 } |
| 4114 | 4118 |
| 4115 bool LayerTreeHostImpl::CommitToActiveTree() const { | 4119 bool LayerTreeHostImpl::CommitToActiveTree() const { |
| 4116 // In single threaded mode we skip the pending tree and commit directly to the | 4120 // In single threaded mode we skip the pending tree and commit directly to the |
| 4117 // active tree. | 4121 // active tree. |
| 4118 return !task_runner_provider_->HasImplThread(); | 4122 return !task_runner_provider_->HasImplThread(); |
| 4119 } | 4123 } |
| 4120 | 4124 |
| 4121 } // namespace cc | 4125 } // namespace cc |
| OLD | NEW |