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

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

Issue 2907053004: GSB uses delta_hints to calculate scrolling chain. (Closed)
Patch Set: debug version Created 3 years, 6 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 2732 matching lines...) Expand 10 before | Expand all | Expand 10 after
2743 InputHandler::ScrollStatus LayerTreeHostImpl::ScrollBeginImpl( 2743 InputHandler::ScrollStatus LayerTreeHostImpl::ScrollBeginImpl(
2744 ScrollState* scroll_state, 2744 ScrollState* scroll_state,
2745 ScrollNode* scrolling_node, 2745 ScrollNode* scrolling_node,
2746 InputHandler::ScrollInputType type) { 2746 InputHandler::ScrollInputType type) {
2747 DCHECK(scroll_state); 2747 DCHECK(scroll_state);
2748 DCHECK(scroll_state->delta_x() == 0 && scroll_state->delta_y() == 0); 2748 DCHECK(scroll_state->delta_x() == 0 && scroll_state->delta_y() == 0);
2749 2749
2750 InputHandler::ScrollStatus scroll_status; 2750 InputHandler::ScrollStatus scroll_status;
2751 scroll_status.main_thread_scrolling_reasons = 2751 scroll_status.main_thread_scrolling_reasons =
2752 MainThreadScrollingReason::kNotScrollingOnMain; 2752 MainThreadScrollingReason::kNotScrollingOnMain;
2753 if (!scrolling_node) { 2753 if (!scrolling_node) {
sahel 2017/05/30 15:36:14 Early return happens here too when scrolling is ig
2754 scroll_status.thread = SCROLL_IGNORED; 2754 scroll_status.thread = SCROLL_IGNORED;
2755 scroll_status.main_thread_scrolling_reasons = 2755 scroll_status.main_thread_scrolling_reasons =
2756 MainThreadScrollingReason::kNoScrollingLayer; 2756 MainThreadScrollingReason::kNoScrollingLayer;
2757 return scroll_status; 2757 return scroll_status;
2758 } 2758 }
2759 scroll_status.thread = SCROLL_ON_IMPL_THREAD; 2759 scroll_status.thread = SCROLL_ON_IMPL_THREAD;
2760 mutator_host_->ScrollAnimationAbort(); 2760 mutator_host_->ScrollAnimationAbort();
2761 2761
2762 browser_controls_offset_manager_->ScrollBegin(); 2762 browser_controls_offset_manager_->ScrollBegin();
2763 2763
2764 active_tree_->SetCurrentlyScrollingNode(scrolling_node); 2764 active_tree_->SetCurrentlyScrollingNode(scrolling_node);
2765 // TODO(majidvp): get rid of wheel_scrolling_ and set is_direct_manipulation 2765 // TODO(majidvp): get rid of wheel_scrolling_ and set is_direct_manipulation
2766 // in input_handler_proxy instead. 2766 // in input_handler_proxy instead.
2767 wheel_scrolling_ = IsWheelBasedScroll(type); 2767 wheel_scrolling_ = IsWheelBasedScroll(type);
2768 scroll_state->set_is_direct_manipulation(!wheel_scrolling_); 2768 scroll_state->set_is_direct_manipulation(!wheel_scrolling_);
2769 // Invoke |DistributeScrollDelta| even with zero delta and velocity to ensure 2769 // Invoke |DistributeScrollDelta| even with zero delta and velocity to ensure
2770 // scroll customization callbacks are invoked. 2770 // scroll customization callbacks are invoked.
2771 DistributeScrollDelta(scroll_state); 2771 DistributeScrollDelta(scroll_state);
2772 2772
2773 // If the CurrentlyScrollingNode doesn't exist after distributing scroll
2774 // delta, no scroller can scroll in the given delta hint direction(s).
2775 if (!active_tree_->CurrentlyScrollingNode()) {
2776 scroll_status.thread = InputHandler::SCROLL_IGNORED;
2777 scroll_status.main_thread_scrolling_reasons =
2778 MainThreadScrollingReason::kNotScrollingOnMain;
2779 return scroll_status;
dtapuska 2017/05/30 15:20:38 Why is this an early return? It avoids the uma met
sahel 2017/05/30 15:36:14 I want GSB handling to return ignored when there i
2780 }
2781
2773 client_->RenewTreePriority(); 2782 client_->RenewTreePriority();
2774 RecordCompositorSlowScrollMetric(type, CC_THREAD); 2783 RecordCompositorSlowScrollMetric(type, CC_THREAD);
2775 2784
2776 UpdateScrollSourceInfo(wheel_scrolling_); 2785 UpdateScrollSourceInfo(wheel_scrolling_);
2777 2786
2778 return scroll_status; 2787 return scroll_status;
2779 } 2788 }
2780 2789
2781 InputHandler::ScrollStatus LayerTreeHostImpl::RootScrollBegin( 2790 InputHandler::ScrollStatus LayerTreeHostImpl::RootScrollBegin(
2782 ScrollState* scroll_state, 2791 ScrollState* scroll_state,
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
2889 } 2898 }
2890 2899
2891 // If |first_scrolling_layer_or_drawn_scrollbar| is not scrollable, it must 2900 // If |first_scrolling_layer_or_drawn_scrollbar| is not scrollable, it must
2892 // be a drawn scrollbar. These hit tests require falling back to main-thread 2901 // be a drawn scrollbar. These hit tests require falling back to main-thread
2893 // scrolling. 2902 // scrolling.
2894 DCHECK(first_scrolling_layer_or_drawn_scrollbar->IsDrawnScrollbar()); 2903 DCHECK(first_scrolling_layer_or_drawn_scrollbar->IsDrawnScrollbar());
2895 return false; 2904 return false;
2896 } 2905 }
2897 2906
2898 InputHandler::ScrollStatus LayerTreeHostImpl::ScrollAnimatedBegin( 2907 InputHandler::ScrollStatus LayerTreeHostImpl::ScrollAnimatedBegin(
2899 const gfx::Point& viewport_point) { 2908 ScrollState* scroll_state) {
2900 InputHandler::ScrollStatus scroll_status; 2909 InputHandler::ScrollStatus scroll_status;
2901 scroll_status.main_thread_scrolling_reasons = 2910 scroll_status.main_thread_scrolling_reasons =
2902 MainThreadScrollingReason::kNotScrollingOnMain; 2911 MainThreadScrollingReason::kNotScrollingOnMain;
2903 ScrollTree& scroll_tree = active_tree_->property_trees()->scroll_tree; 2912 ScrollTree& scroll_tree = active_tree_->property_trees()->scroll_tree;
2904 ScrollNode* scroll_node = scroll_tree.CurrentlyScrollingNode(); 2913 ScrollNode* scroll_node = scroll_tree.CurrentlyScrollingNode();
2905 if (scroll_node) { 2914 if (scroll_node) {
2906 gfx::Vector2dF delta; 2915 gfx::Vector2dF delta;
2907 2916
2908 if (ScrollAnimationUpdateTarget(scroll_node, delta, base::TimeDelta())) { 2917 if (ScrollAnimationUpdateTarget(scroll_node, delta, base::TimeDelta())) {
2909 scroll_status.thread = SCROLL_ON_IMPL_THREAD; 2918 scroll_status.thread = SCROLL_ON_IMPL_THREAD;
2910 } else { 2919 } else {
2911 scroll_status.thread = SCROLL_IGNORED; 2920 scroll_status.thread = SCROLL_IGNORED;
2912 scroll_status.main_thread_scrolling_reasons = 2921 scroll_status.main_thread_scrolling_reasons =
2913 MainThreadScrollingReason::kNotScrollable; 2922 MainThreadScrollingReason::kNotScrollable;
2914 } 2923 }
2915 return scroll_status; 2924 return scroll_status;
2916 } 2925 }
2917 ScrollStateData scroll_state_data;
2918 scroll_state_data.position_x = viewport_point.x();
2919 scroll_state_data.position_y = viewport_point.y();
2920 ScrollState scroll_state(scroll_state_data);
2921 2926
2922 // ScrollAnimated is used for animated wheel scrolls. We find the first layer 2927 // ScrollAnimated is used for animated wheel scrolls. We find the first layer
2923 // that can scroll and set up an animation of its scroll offset. Note that 2928 // that can scroll and set up an animation of its scroll offset. Note that
2924 // this does not currently go through the scroll customization machinery 2929 // this does not currently go through the scroll customization machinery
2925 // that ScrollBy uses for non-animated wheel scrolls. 2930 // that ScrollBy uses for non-animated wheel scrolls.
2926 scroll_status = ScrollBegin(&scroll_state, WHEEL); 2931 scroll_status = ScrollBegin(scroll_state, WHEEL);
2927 if (scroll_status.thread == SCROLL_ON_IMPL_THREAD) { 2932 if (scroll_status.thread == SCROLL_ON_IMPL_THREAD) {
2928 scroll_animating_latched_node_id_ = ScrollTree::kInvalidNodeId; 2933 scroll_animating_latched_node_id_ = ScrollTree::kInvalidNodeId;
2929 ScrollStateData scroll_state_end_data; 2934 ScrollStateData scroll_state_end_data;
2930 scroll_state_end_data.is_ending = true; 2935 scroll_state_end_data.is_ending = true;
2931 ScrollState scroll_state_end(scroll_state_end_data); 2936 ScrollState scroll_state_end(scroll_state_end_data);
2932 ScrollEnd(&scroll_state_end); 2937 ScrollEnd(&scroll_state_end);
2933 } 2938 }
2934 return scroll_status; 2939 return scroll_status;
2935 } 2940 }
2936 2941
2937 gfx::Vector2dF LayerTreeHostImpl::ComputeScrollDelta( 2942 gfx::Vector2dF LayerTreeHostImpl::ComputeScrollDelta(
2938 ScrollNode* scroll_node, 2943 ScrollNode* scroll_node,
2939 const gfx::Vector2dF& delta) { 2944 const gfx::Vector2dF& delta) {
2940 ScrollTree& scroll_tree = active_tree()->property_trees()->scroll_tree; 2945 ScrollTree& scroll_tree = active_tree()->property_trees()->scroll_tree;
2941 float scale_factor = active_tree()->current_page_scale_factor(); 2946 float scale_factor = active_tree()->current_page_scale_factor();
2942 2947
2943 gfx::Vector2dF adjusted_scroll(delta); 2948 gfx::Vector2dF adjusted_scroll(delta);
2944 adjusted_scroll.Scale(1.f / scale_factor); 2949 adjusted_scroll.Scale(1.f / scale_factor);
2945 if (!scroll_node->user_scrollable_horizontal) 2950 if (!scroll_node->user_scrollable_horizontal)
2946 adjusted_scroll.set_x(0); 2951 adjusted_scroll.set_x(0);
2947 if (!scroll_node->user_scrollable_vertical) 2952 if (!scroll_node->user_scrollable_vertical)
2948 adjusted_scroll.set_y(0); 2953 adjusted_scroll.set_y(0);
2949 2954
2950 gfx::ScrollOffset old_offset = 2955 gfx::ScrollOffset old_offset =
2951 scroll_tree.current_scroll_offset(scroll_node->owning_layer_id); 2956 scroll_tree.current_scroll_offset(scroll_node->owning_layer_id);
2952 gfx::ScrollOffset new_offset = scroll_tree.ClampScrollOffsetToLimits( 2957 gfx::ScrollOffset new_offset = scroll_tree.ClampScrollOffsetToLimits(
2953 old_offset + gfx::ScrollOffset(adjusted_scroll), scroll_node); 2958 old_offset + gfx::ScrollOffset(adjusted_scroll), scroll_node);
2954
2955 gfx::ScrollOffset scrolled = new_offset - old_offset; 2959 gfx::ScrollOffset scrolled = new_offset - old_offset;
2956 return gfx::Vector2dF(scrolled.x(), scrolled.y()); 2960 return gfx::Vector2dF(scrolled.x(), scrolled.y());
2957 } 2961 }
2958 2962
2959 bool LayerTreeHostImpl::ScrollAnimationCreate(ScrollNode* scroll_node, 2963 bool LayerTreeHostImpl::ScrollAnimationCreate(ScrollNode* scroll_node,
2960 const gfx::Vector2dF& delta, 2964 const gfx::Vector2dF& delta,
2961 base::TimeDelta delayed_by) { 2965 base::TimeDelta delayed_by) {
2962 ScrollTree& scroll_tree = active_tree_->property_trees()->scroll_tree; 2966 ScrollTree& scroll_tree = active_tree_->property_trees()->scroll_tree;
2963 2967
2964 const float kEpsilon = 0.1f; 2968 const float kEpsilon = 0.1f;
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
3282 3286
3283 void LayerTreeHostImpl::DistributeScrollDelta(ScrollState* scroll_state) { 3287 void LayerTreeHostImpl::DistributeScrollDelta(ScrollState* scroll_state) {
3284 // TODO(majidvp): in Blink we compute scroll chain only at scroll begin which 3288 // TODO(majidvp): in Blink we compute scroll chain only at scroll begin which
3285 // is not the case here. We eventually want to have the same behaviour on both 3289 // is not the case here. We eventually want to have the same behaviour on both
3286 // sides but it may become a non issue if we get rid of scroll chaining (see 3290 // sides but it may become a non issue if we get rid of scroll chaining (see
3287 // crbug.com/526462) 3291 // crbug.com/526462)
3288 std::list<ScrollNode*> current_scroll_chain; 3292 std::list<ScrollNode*> current_scroll_chain;
3289 ScrollTree& scroll_tree = active_tree_->property_trees()->scroll_tree; 3293 ScrollTree& scroll_tree = active_tree_->property_trees()->scroll_tree;
3290 ScrollNode* scroll_node = scroll_tree.CurrentlyScrollingNode(); 3294 ScrollNode* scroll_node = scroll_tree.CurrentlyScrollingNode();
3291 ScrollNode* viewport_scroll_node = OuterViewportScrollNode(); 3295 ScrollNode* viewport_scroll_node = OuterViewportScrollNode();
3296 LOG(ERROR) << "in distribute scroll delta before for loop";
dtapuska 2017/05/30 15:20:38 Why log errors?
sahel 2017/05/30 15:36:14 This is a debug version I was trying to figure out
3292 if (scroll_node) { 3297 if (scroll_node) {
3293 // TODO(bokan): The loop checks for a null parent but don't we still want to 3298 // TODO(bokan): The loop checks for a null parent but don't we still want to
3294 // distribute to the root scroll node? 3299 // distribute to the root scroll node?
3295 for (; scroll_tree.parent(scroll_node); 3300 for (; scroll_tree.parent(scroll_node);
3296 scroll_node = scroll_tree.parent(scroll_node)) { 3301 scroll_node = scroll_tree.parent(scroll_node)) {
3302 LOG(ERROR) << "scroll node id ib DistributeScrollDelta:\t"
3303 << scroll_node->id;
3297 if (scroll_node == viewport_scroll_node) { 3304 if (scroll_node == viewport_scroll_node) {
3298 // Don't chain scrolls past the outer viewport scroll layer. Once we 3305 // Don't chain scrolls past the outer viewport scroll layer. Once we
3299 // reach that, we should scroll the viewport which is represented by the 3306 // reach that, we should scroll the viewport which is represented by the
3300 // main viewport scroll layer. 3307 // main viewport scroll layer.
3301 DCHECK(viewport_scroll_node); 3308 DCHECK(viewport_scroll_node);
3302 current_scroll_chain.push_front(viewport_scroll_node); 3309 if (CanConsumeDelta(viewport_scroll_node, *scroll_state))
3310 current_scroll_chain.push_front(viewport_scroll_node);
3303 break; 3311 break;
3304 } 3312 }
3305 3313
3306 if (!scroll_node->scrollable) 3314 if (!scroll_node->scrollable)
3307 continue; 3315 continue;
3308 3316
3309 current_scroll_chain.push_front(scroll_node); 3317 if (CanConsumeDelta(scroll_node, *scroll_state))
3318 current_scroll_chain.push_front(scroll_node);
3310 } 3319 }
3311 } 3320 }
3321 // active_tree_->SetCurrentlyScrollingNode(
3322 // current_scroll_chain.empty() ? nullptr : current_scroll_chain.back());
3312 scroll_state->set_scroll_chain_and_layer_tree(current_scroll_chain, 3323 scroll_state->set_scroll_chain_and_layer_tree(current_scroll_chain,
3313 active_tree()); 3324 active_tree());
3314 scroll_state->DistributeToScrollChainDescendant(); 3325 scroll_state->DistributeToScrollChainDescendant();
3315 } 3326 }
3316 3327
3328 bool LayerTreeHostImpl::CanConsumeDelta(ScrollNode* scroll_node,
3329 const ScrollState& scroll_state) {
3330 LOG(ERROR) << "node id in can consume:\t" << scroll_node->id;
3331 gfx::Vector2dF delta_to_scroll;
3332 if (scroll_state.is_beginning()) {
3333 if (scroll_state.ignore_delta_hints())
3334 return true;
3335
3336 delta_to_scroll = gfx::Vector2dF(scroll_state.delta_x_hint(),
3337 scroll_state.delta_y_hint());
3338 } else {
3339 delta_to_scroll =
3340 gfx::Vector2dF(scroll_state.delta_x(), scroll_state.delta_y());
3341 }
3342
3343 if (delta_to_scroll == gfx::Vector2dF()) {
3344 LOG(ERROR) << "true because scroll delta is zero";
3345 return true;
3346 }
3347
3348 if (ComputeScrollDelta(scroll_node, delta_to_scroll) != gfx::Vector2dF())
3349 return true;
3350
3351 if ((OuterViewportScrollNode() &&
3352 OuterViewportScrollNode()->id == scroll_node->id &&
3353 active_tree_->InnerViewportScrollLayer()) ||
3354 scroll_node->scrolls_inner_viewport) {
3355 ScrollTree& scroll_tree = active_tree_->property_trees()->scroll_tree;
3356 ScrollNode* inner_viewport_scroll_node = scroll_tree.Node(
3357 active_tree_->InnerViewportScrollLayer()->scroll_tree_index());
3358 if (!inner_viewport_scroll_node)
3359 return false;
3360 LOG(ERROR) << "return value in newly added code:\t"
3361 << (ComputeScrollDelta(inner_viewport_scroll_node,
3362 delta_to_scroll) != gfx::Vector2dF());
3363
3364 return ComputeScrollDelta(inner_viewport_scroll_node, delta_to_scroll) !=
3365 gfx::Vector2dF();
3366 }
3367
3368 return false;
3369 }
3370
3317 InputHandlerScrollResult LayerTreeHostImpl::ScrollBy( 3371 InputHandlerScrollResult LayerTreeHostImpl::ScrollBy(
3318 ScrollState* scroll_state) { 3372 ScrollState* scroll_state) {
3319 DCHECK(scroll_state); 3373 DCHECK(scroll_state);
3320 3374
3321 TRACE_EVENT0("cc", "LayerTreeHostImpl::ScrollBy"); 3375 TRACE_EVENT0("cc", "LayerTreeHostImpl::ScrollBy");
3322 ScrollTree& scroll_tree = active_tree_->property_trees()->scroll_tree; 3376 ScrollTree& scroll_tree = active_tree_->property_trees()->scroll_tree;
3323 ScrollNode* scroll_node = scroll_tree.CurrentlyScrollingNode(); 3377 ScrollNode* scroll_node = scroll_tree.CurrentlyScrollingNode();
3324 3378
3325 if (!scroll_node) 3379 if (!scroll_node)
3326 return InputHandlerScrollResult(); 3380 return InputHandlerScrollResult();
(...skipping 10 matching lines...) Expand all
3337 scroll_state->set_delta_consumed_for_scroll_sequence( 3391 scroll_state->set_delta_consumed_for_scroll_sequence(
3338 did_lock_scrolling_layer_); 3392 did_lock_scrolling_layer_);
3339 scroll_state->set_is_direct_manipulation(!wheel_scrolling_); 3393 scroll_state->set_is_direct_manipulation(!wheel_scrolling_);
3340 scroll_state->set_current_native_scrolling_node( 3394 scroll_state->set_current_native_scrolling_node(
3341 active_tree()->property_trees()->scroll_tree.CurrentlyScrollingNode()); 3395 active_tree()->property_trees()->scroll_tree.CurrentlyScrollingNode());
3342 3396
3343 DistributeScrollDelta(scroll_state); 3397 DistributeScrollDelta(scroll_state);
3344 3398
3345 ScrollNode* current_scrolling_node = 3399 ScrollNode* current_scrolling_node =
3346 scroll_state->current_native_scrolling_node(); 3400 scroll_state->current_native_scrolling_node();
3401 LOG(ERROR) << "currently scrolling node id:\t" << current_scrolling_node->id;
3347 active_tree_->SetCurrentlyScrollingNode(current_scrolling_node); 3402 active_tree_->SetCurrentlyScrollingNode(current_scrolling_node);
3348 did_lock_scrolling_layer_ = 3403 did_lock_scrolling_layer_ =
3349 scroll_state->delta_consumed_for_scroll_sequence(); 3404 scroll_state->delta_consumed_for_scroll_sequence();
3350 3405
3351 bool did_scroll_x = scroll_state->caused_scroll_x(); 3406 bool did_scroll_x = scroll_state->caused_scroll_x();
3352 bool did_scroll_y = scroll_state->caused_scroll_y(); 3407 bool did_scroll_y = scroll_state->caused_scroll_y();
3353 bool did_scroll_content = did_scroll_x || did_scroll_y; 3408 bool did_scroll_content = did_scroll_x || did_scroll_y;
3354 if (did_scroll_content) { 3409 if (did_scroll_content) {
3355 ShowScrollbarsForImplScroll(current_scrolling_node->element_id); 3410 ShowScrollbarsForImplScroll(current_scrolling_node->element_id);
3356 3411
(...skipping 990 matching lines...) Expand 10 before | Expand all | Expand 10 after
4347 4402
4348 void LayerTreeHostImpl::ShowScrollbarsForImplScroll(ElementId element_id) { 4403 void LayerTreeHostImpl::ShowScrollbarsForImplScroll(ElementId element_id) {
4349 if (!element_id) 4404 if (!element_id)
4350 return; 4405 return;
4351 if (ScrollbarAnimationController* animation_controller = 4406 if (ScrollbarAnimationController* animation_controller =
4352 ScrollbarAnimationControllerForElementId(element_id)) 4407 ScrollbarAnimationControllerForElementId(element_id))
4353 animation_controller->DidScrollUpdate(); 4408 animation_controller->DidScrollUpdate();
4354 } 4409 }
4355 4410
4356 } // namespace cc 4411 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698