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

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

Issue 2423143002: Scrollbar fade animation broken on Android regression resolved. (Closed)
Patch Set: unittest added. Created 4 years, 1 month 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 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 active_tree_->property_trees()->is_active = true; 257 active_tree_->property_trees()->is_active = true;
258 258
259 viewport_ = Viewport::Create(this); 259 viewport_ = Viewport::Create(this);
260 260
261 TRACE_EVENT_OBJECT_CREATED_WITH_ID(TRACE_DISABLED_BY_DEFAULT("cc.debug"), 261 TRACE_EVENT_OBJECT_CREATED_WITH_ID(TRACE_DISABLED_BY_DEFAULT("cc.debug"),
262 "cc::LayerTreeHostImpl", id_); 262 "cc::LayerTreeHostImpl", id_);
263 263
264 top_controls_manager_ = 264 top_controls_manager_ =
265 TopControlsManager::Create(this, settings.top_controls_show_threshold, 265 TopControlsManager::Create(this, settings.top_controls_show_threshold,
266 settings.top_controls_hide_threshold); 266 settings.top_controls_hide_threshold);
267 cached_scrolling_variables_state_ = ScrollingVariablesState(
bokan 2016/10/25 17:29:22 These should all be at their default values anyway
sahel 2016/10/25 17:53:41 I thought it's better for maintainability of the c
bokan 2016/10/25 19:19:22 Ah, that's unfortunate. Ok then, initializing is f
sahel 2016/10/26 14:11:43 Done.
268 did_lock_scrolling_layer_, scroll_affects_scroll_handler_,
269 accumulated_root_overscroll_);
267 } 270 }
268 271
269 LayerTreeHostImpl::~LayerTreeHostImpl() { 272 LayerTreeHostImpl::~LayerTreeHostImpl() {
270 DCHECK(task_runner_provider_->IsImplThread()); 273 DCHECK(task_runner_provider_->IsImplThread());
271 TRACE_EVENT0("cc", "LayerTreeHostImpl::~LayerTreeHostImpl()"); 274 TRACE_EVENT0("cc", "LayerTreeHostImpl::~LayerTreeHostImpl()");
272 TRACE_EVENT_OBJECT_DELETED_WITH_ID(TRACE_DISABLED_BY_DEFAULT("cc.debug"), 275 TRACE_EVENT_OBJECT_DELETED_WITH_ID(TRACE_DISABLED_BY_DEFAULT("cc.debug"),
273 "cc::LayerTreeHostImpl", id_); 276 "cc::LayerTreeHostImpl", id_);
274 277
275 // It is released before shutdown. 278 // It is released before shutdown.
276 DCHECK(!compositor_frame_sink_); 279 DCHECK(!compositor_frame_sink_);
(...skipping 2359 matching lines...) Expand 10 before | Expand all | Expand 10 after
2636 return ScrollBeginImpl(scroll_state, viewport()->MainScrollLayer(), type); 2639 return ScrollBeginImpl(scroll_state, viewport()->MainScrollLayer(), type);
2637 } 2640 }
2638 2641
2639 InputHandler::ScrollStatus LayerTreeHostImpl::ScrollBegin( 2642 InputHandler::ScrollStatus LayerTreeHostImpl::ScrollBegin(
2640 ScrollState* scroll_state, 2643 ScrollState* scroll_state,
2641 InputHandler::ScrollInputType type) { 2644 InputHandler::ScrollInputType type) {
2642 ScrollStatus scroll_status; 2645 ScrollStatus scroll_status;
2643 scroll_status.main_thread_scrolling_reasons = 2646 scroll_status.main_thread_scrolling_reasons =
2644 MainThreadScrollingReason::kNotScrollingOnMain; 2647 MainThreadScrollingReason::kNotScrollingOnMain;
2645 TRACE_EVENT0("cc", "LayerTreeHostImpl::ScrollBegin"); 2648 TRACE_EVENT0("cc", "LayerTreeHostImpl::ScrollBegin");
2649 LayerImpl* scrolling_layer_impl = nullptr;
2650 // On Mac a scroll begin with |inertial_phase| = true happens to handle a
2651 // fling. Also, touchpad fling starts are handled by calling ScrollBegin
2652 // instead of FlingScrollBegin.
2653 if (scroll_state->is_in_inertial_phase()) {
2654 scrolling_layer_impl =
2655 active_tree_->LayerById(active_tree_->LastScrolledLayerId());
bokan 2016/10/25 17:29:22 I'd prefer if we just store the CurrentlyScrolling
sahel 2016/10/25 17:53:41 I preferred to use the one that is already cached.
bokan 2016/10/25 19:19:22 Please do. In general, unless something is known t
sahel 2016/10/26 14:11:44 Done.
2656 RestoreCachedScrollingVariablesState();
2657 }
2646 2658
2647 // On Mac a scroll begin with |inertial_phase| = true happens to handle a 2659 if (!scrolling_layer_impl) {
2648 // fling. 2660 ClearCurrentlyScrollingLayer();
2649 if (scroll_state->is_in_inertial_phase())
2650 return FlingScrollBegin();
2651 2661
2652 ClearCurrentlyScrollingLayer(); 2662 gfx::Point viewport_point(scroll_state->position_x(),
2663 scroll_state->position_y());
2653 2664
2654 gfx::Point viewport_point(scroll_state->position_x(), 2665 gfx::PointF device_viewport_point = gfx::ScalePoint(
2655 scroll_state->position_y()); 2666 gfx::PointF(viewport_point), active_tree_->device_scale_factor());
2667 LayerImpl* layer_impl =
2668 active_tree_->FindLayerThatIsHitByPoint(device_viewport_point);
2656 2669
2657 gfx::PointF device_viewport_point = gfx::ScalePoint( 2670 if (layer_impl) {
2658 gfx::PointF(viewport_point), active_tree_->device_scale_factor()); 2671 LayerImpl* scroll_layer_impl =
2659 LayerImpl* layer_impl = 2672 active_tree_->FindFirstScrollingLayerOrScrollbarLayerThatIsHitByPoint(
2660 active_tree_->FindLayerThatIsHitByPoint(device_viewport_point); 2673 device_viewport_point);
2674 if (scroll_layer_impl &&
2675 !HasScrollAncestor(layer_impl, scroll_layer_impl)) {
2676 scroll_status.thread = SCROLL_UNKNOWN;
2677 scroll_status.main_thread_scrolling_reasons =
2678 MainThreadScrollingReason::kFailedHitTest;
2679 return scroll_status;
2680 }
2681 }
2661 2682
2662 if (layer_impl) { 2683 bool scroll_on_main_thread = false;
2663 LayerImpl* scroll_layer_impl = 2684 scrolling_layer_impl = FindScrollLayerForDeviceViewportPoint(
2664 active_tree_->FindFirstScrollingLayerOrScrollbarLayerThatIsHitByPoint( 2685 device_viewport_point, type, layer_impl, &scroll_on_main_thread,
2665 device_viewport_point); 2686 &scroll_status.main_thread_scrolling_reasons);
2666 if (scroll_layer_impl && 2687
2667 !HasScrollAncestor(layer_impl, scroll_layer_impl)) { 2688 if (scrolling_layer_impl)
2668 scroll_status.thread = SCROLL_UNKNOWN; 2689 scroll_affects_scroll_handler_ =
2669 scroll_status.main_thread_scrolling_reasons = 2690 scrolling_layer_impl->layer_tree_impl()->have_scroll_event_handlers();
2670 MainThreadScrollingReason::kFailedHitTest; 2691
2692 if (scroll_on_main_thread) {
2693 RecordCompositorSlowScrollMetric(type, MAIN_THREAD);
2694
2695 scroll_status.thread = SCROLL_ON_MAIN_THREAD;
2671 return scroll_status; 2696 return scroll_status;
2672 } 2697 }
2673 } 2698 }
2674 2699
2675 bool scroll_on_main_thread = false;
2676 LayerImpl* scrolling_layer_impl = FindScrollLayerForDeviceViewportPoint(
2677 device_viewport_point, type, layer_impl, &scroll_on_main_thread,
2678 &scroll_status.main_thread_scrolling_reasons);
2679
2680 if (scrolling_layer_impl)
2681 scroll_affects_scroll_handler_ =
2682 scrolling_layer_impl->layer_tree_impl()->have_scroll_event_handlers();
2683
2684 if (scroll_on_main_thread) {
2685 RecordCompositorSlowScrollMetric(type, MAIN_THREAD);
2686
2687 scroll_status.thread = SCROLL_ON_MAIN_THREAD;
2688 return scroll_status;
2689 }
2690
2691 return ScrollBeginImpl(scroll_state, scrolling_layer_impl, type); 2700 return ScrollBeginImpl(scroll_state, scrolling_layer_impl, type);
bokan 2016/10/25 17:29:22 Is it intentional that we're now calling ScrollBeg
sahel 2016/10/25 17:53:41 On Mac we don't get a fling start and that's why o
bokan 2016/10/25 19:19:22 Ok, sgtm, thanks.
2692 } 2701 }
2693 2702
2694 InputHandler::ScrollStatus LayerTreeHostImpl::ScrollAnimatedBegin( 2703 InputHandler::ScrollStatus LayerTreeHostImpl::ScrollAnimatedBegin(
2695 const gfx::Point& viewport_point) { 2704 const gfx::Point& viewport_point) {
2696 InputHandler::ScrollStatus scroll_status; 2705 InputHandler::ScrollStatus scroll_status;
2697 scroll_status.main_thread_scrolling_reasons = 2706 scroll_status.main_thread_scrolling_reasons =
2698 MainThreadScrollingReason::kNotScrollingOnMain; 2707 MainThreadScrollingReason::kNotScrollingOnMain;
2699 ScrollTree& scroll_tree = active_tree_->property_trees()->scroll_tree; 2708 ScrollTree& scroll_tree = active_tree_->property_trees()->scroll_tree;
2700 ScrollNode* scroll_node = scroll_tree.CurrentlyScrollingNode(); 2709 ScrollNode* scroll_node = scroll_tree.CurrentlyScrollingNode();
2701 if (scroll_node) { 2710 if (scroll_node) {
(...skipping 16 matching lines...) Expand all
2718 // ScrollAnimated is used for animated wheel scrolls. We find the first layer 2727 // ScrollAnimated is used for animated wheel scrolls. We find the first layer
2719 // that can scroll and set up an animation of its scroll offset. Note that 2728 // that can scroll and set up an animation of its scroll offset. Note that
2720 // this does not currently go through the scroll customization machinery 2729 // this does not currently go through the scroll customization machinery
2721 // that ScrollBy uses for non-animated wheel scrolls. 2730 // that ScrollBy uses for non-animated wheel scrolls.
2722 scroll_status = ScrollBegin(&scroll_state, WHEEL); 2731 scroll_status = ScrollBegin(&scroll_state, WHEEL);
2723 scroll_node = scroll_tree.CurrentlyScrollingNode(); 2732 scroll_node = scroll_tree.CurrentlyScrollingNode();
2724 if (scroll_status.thread == SCROLL_ON_IMPL_THREAD) { 2733 if (scroll_status.thread == SCROLL_ON_IMPL_THREAD) {
2725 ScrollStateData scroll_state_end_data; 2734 ScrollStateData scroll_state_end_data;
2726 scroll_state_end_data.is_ending = true; 2735 scroll_state_end_data.is_ending = true;
2727 ScrollState scroll_state_end(scroll_state_end_data); 2736 ScrollState scroll_state_end(scroll_state_end_data);
2728 // TODO(Sahel): Once the touchpad scroll latching for Non-mac devices is
2729 // implemented, the current scrolling layer should not get cleared after
2730 // each animation (crbug.com/526463).
2731 ScrollEnd(&scroll_state_end); 2737 ScrollEnd(&scroll_state_end);
2732 ClearCurrentlyScrollingLayer();
2733 } 2738 }
2734 return scroll_status; 2739 return scroll_status;
2735 } 2740 }
2736 2741
2737 gfx::Vector2dF LayerTreeHostImpl::ComputeScrollDelta( 2742 gfx::Vector2dF LayerTreeHostImpl::ComputeScrollDelta(
2738 ScrollNode* scroll_node, 2743 ScrollNode* scroll_node,
2739 const gfx::Vector2dF& delta) { 2744 const gfx::Vector2dF& delta) {
2740 ScrollTree& scroll_tree = active_tree()->property_trees()->scroll_tree; 2745 ScrollTree& scroll_tree = active_tree()->property_trees()->scroll_tree;
2741 float scale_factor = active_tree()->current_page_scale_factor(); 2746 float scale_factor = active_tree()->current_page_scale_factor();
2742 2747
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
2846 gfx::Vector2dF scroll_delta = 2851 gfx::Vector2dF scroll_delta =
2847 ComputeScrollDelta(scroll_node, pending_delta); 2852 ComputeScrollDelta(scroll_node, pending_delta);
2848 if (ScrollAnimationCreate(scroll_node, scroll_delta, delayed_by)) 2853 if (ScrollAnimationCreate(scroll_node, scroll_delta, delayed_by))
2849 return scroll_status; 2854 return scroll_status;
2850 2855
2851 pending_delta -= scroll_delta; 2856 pending_delta -= scroll_delta;
2852 } 2857 }
2853 } 2858 }
2854 } 2859 }
2855 scroll_state.set_is_ending(true); 2860 scroll_state.set_is_ending(true);
2856 // TODO(Sahel): Once the touchpad scroll latching for Non-mac devices is
2857 // implemented, the current scrolling layer should not get cleared after
2858 // each animation (crbug.com/526463).
2859 ScrollEnd(&scroll_state); 2861 ScrollEnd(&scroll_state);
2860 ClearCurrentlyScrollingLayer();
2861 2862
2862 return scroll_status; 2863 return scroll_status;
2863 } 2864 }
2864 2865
2865 gfx::Vector2dF LayerTreeHostImpl::ScrollNodeWithViewportSpaceDelta( 2866 gfx::Vector2dF LayerTreeHostImpl::ScrollNodeWithViewportSpaceDelta(
2866 ScrollNode* scroll_node, 2867 ScrollNode* scroll_node,
2867 const gfx::PointF& viewport_point, 2868 const gfx::PointF& viewport_point,
2868 const gfx::Vector2dF& viewport_delta, 2869 const gfx::Vector2dF& viewport_delta,
2869 ScrollTree* scroll_tree) { 2870 ScrollTree* scroll_tree) {
2870 // Layers with non-invertible screen space transforms should not have passed 2871 // Layers with non-invertible screen space transforms should not have passed
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
3159 client_->SetNeedsCommitOnImplThread(); 3160 client_->SetNeedsCommitOnImplThread();
3160 // After applying the synchronous input handler's scroll offset, tell it what 3161 // After applying the synchronous input handler's scroll offset, tell it what
3161 // we ended up with. 3162 // we ended up with.
3162 UpdateRootLayerStateForSynchronousInputHandler(); 3163 UpdateRootLayerStateForSynchronousInputHandler();
3163 SetFullViewportDamage(); 3164 SetFullViewportDamage();
3164 SetNeedsRedraw(); 3165 SetNeedsRedraw();
3165 } 3166 }
3166 3167
3167 void LayerTreeHostImpl::ClearCurrentlyScrollingLayer() { 3168 void LayerTreeHostImpl::ClearCurrentlyScrollingLayer() {
3168 active_tree_->ClearCurrentlyScrollingLayer(); 3169 active_tree_->ClearCurrentlyScrollingLayer();
3170 // Cached scrolling variables state is restored in a ScrollBegin with
3171 // inertial phase (fling) to latch it to its corresponding scroll. When
3172 // reseting a variable here, update ScrollingVariablesState struct as well
3173 // to maintain the proper caching.
3174 CacheScrollingVariablesState();
3169 did_lock_scrolling_layer_ = false; 3175 did_lock_scrolling_layer_ = false;
3170 scroll_affects_scroll_handler_ = false; 3176 scroll_affects_scroll_handler_ = false;
3171 accumulated_root_overscroll_ = gfx::Vector2dF(); 3177 accumulated_root_overscroll_ = gfx::Vector2dF();
3172 } 3178 }
3173 3179
3174 void LayerTreeHostImpl::ScrollEnd(ScrollState* scroll_state) { 3180 void LayerTreeHostImpl::ScrollEnd(ScrollState* scroll_state) {
3175 DCHECK(scroll_state); 3181 DCHECK(scroll_state);
3176 DCHECK(scroll_state->delta_x() == 0 && scroll_state->delta_y() == 0); 3182 DCHECK(scroll_state->delta_x() == 0 && scroll_state->delta_y() == 0);
3177 3183
3178 DistributeScrollDelta(scroll_state); 3184 DistributeScrollDelta(scroll_state);
3179 top_controls_manager_->ScrollEnd(); 3185 top_controls_manager_->ScrollEnd();
3180 3186
3181 if (scroll_state->is_in_inertial_phase()) { 3187 ClearCurrentlyScrollingLayer();
3182 // Only clear the currently scrolling layer if we know the scroll is done.
3183 // A non-inertial scroll end could be followed by an inertial scroll.
3184 ClearCurrentlyScrollingLayer();
3185 }
3186 } 3188 }
3187 3189
3188 InputHandler::ScrollStatus LayerTreeHostImpl::FlingScrollBegin() { 3190 InputHandler::ScrollStatus LayerTreeHostImpl::FlingScrollBegin() {
3189 InputHandler::ScrollStatus scroll_status; 3191 InputHandler::ScrollStatus scroll_status;
3190 scroll_status.main_thread_scrolling_reasons = 3192 scroll_status.main_thread_scrolling_reasons =
3191 MainThreadScrollingReason::kNotScrollingOnMain; 3193 MainThreadScrollingReason::kNotScrollingOnMain;
3192 if (!CurrentlyScrollingLayer()) { 3194 if (!CurrentlyScrollingLayer()) {
3193 scroll_status.thread = SCROLL_IGNORED; 3195 scroll_status.thread = SCROLL_IGNORED;
3194 scroll_status.main_thread_scrolling_reasons = 3196 scroll_status.main_thread_scrolling_reasons =
3195 MainThreadScrollingReason::kNoScrollingLayer; 3197 MainThreadScrollingReason::kNoScrollingLayer;
(...skipping 832 matching lines...) Expand 10 before | Expand all | Expand 10 after
4028 return; 4030 return;
4029 LayerImpl* layer = tree->LayerByElementId(element_id); 4031 LayerImpl* layer = tree->LayerByElementId(element_id);
4030 if (layer) 4032 if (layer)
4031 layer->OnIsAnimatingChanged(mask, state); 4033 layer->OnIsAnimatingChanged(mask, state);
4032 } 4034 }
4033 4035
4034 void LayerTreeHostImpl::ScrollOffsetAnimationFinished() { 4036 void LayerTreeHostImpl::ScrollOffsetAnimationFinished() {
4035 // TODO(majidvp): We should pass in the original starting scroll position here 4037 // TODO(majidvp): We should pass in the original starting scroll position here
4036 ScrollStateData scroll_state_data; 4038 ScrollStateData scroll_state_data;
4037 ScrollState scroll_state(scroll_state_data); 4039 ScrollState scroll_state(scroll_state_data);
4038 // TODO(Sahel): Once the touchpad scroll latching for Non-mac devices is
4039 // implemented, the current scrolling layer should not get cleared after
4040 // each animation (crbug.com/526463).
4041 ScrollEnd(&scroll_state); 4040 ScrollEnd(&scroll_state);
4042 ClearCurrentlyScrollingLayer();
4043 } 4041 }
4044 4042
4045 gfx::ScrollOffset LayerTreeHostImpl::GetScrollOffsetForAnimation( 4043 gfx::ScrollOffset LayerTreeHostImpl::GetScrollOffsetForAnimation(
4046 ElementId element_id) const { 4044 ElementId element_id) const {
4047 if (active_tree()) { 4045 if (active_tree()) {
4048 LayerImpl* layer = active_tree()->LayerByElementId(element_id); 4046 LayerImpl* layer = active_tree()->LayerByElementId(element_id);
4049 if (layer) 4047 if (layer)
4050 return layer->ScrollOffsetForAnimation(); 4048 return layer->ScrollOffsetForAnimation();
4051 } 4049 }
4052 4050
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
4100 ContextProvider::ScopedContextLock hold(worker_context); 4098 ContextProvider::ScopedContextLock hold(worker_context);
4101 if (is_visible) { 4099 if (is_visible) {
4102 worker_context_visibility_ = 4100 worker_context_visibility_ =
4103 worker_context->CacheController()->ClientBecameVisible(); 4101 worker_context->CacheController()->ClientBecameVisible();
4104 } else { 4102 } else {
4105 worker_context->CacheController()->ClientBecameNotVisible( 4103 worker_context->CacheController()->ClientBecameNotVisible(
4106 std::move(worker_context_visibility_)); 4104 std::move(worker_context_visibility_));
4107 } 4105 }
4108 } 4106 }
4109 4107
4108 void LayerTreeHostImpl::CacheScrollingVariablesState() {
4109 cached_scrolling_variables_state_ = ScrollingVariablesState(
4110 did_lock_scrolling_layer_, scroll_affects_scroll_handler_,
4111 accumulated_root_overscroll_);
4112 }
4113 void LayerTreeHostImpl::RestoreCachedScrollingVariablesState() {
4114 did_lock_scrolling_layer_ =
4115 cached_scrolling_variables_state_.didLockScrollingLayer();
4116 scroll_affects_scroll_handler_ =
4117 cached_scrolling_variables_state_.scrollAffectsScrollHandler();
4118 accumulated_root_overscroll_ =
4119 cached_scrolling_variables_state_.accumulatedRootOverscroll();
4120 }
4121
4110 } // namespace cc 4122 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698