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

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

Issue 2423143002: Scrollbar fade animation broken on Android regression resolved. (Closed)
Patch Set: scrolling_layer_id cached. 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 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 animation_host_(std::move(animation_host)), 234 animation_host_(std::move(animation_host)),
235 rendering_stats_instrumentation_(rendering_stats_instrumentation), 235 rendering_stats_instrumentation_(rendering_stats_instrumentation),
236 micro_benchmark_controller_(this), 236 micro_benchmark_controller_(this),
237 shared_bitmap_manager_(shared_bitmap_manager), 237 shared_bitmap_manager_(shared_bitmap_manager),
238 gpu_memory_buffer_manager_(gpu_memory_buffer_manager), 238 gpu_memory_buffer_manager_(gpu_memory_buffer_manager),
239 task_graph_runner_(task_graph_runner), 239 task_graph_runner_(task_graph_runner),
240 id_(id), 240 id_(id),
241 requires_high_res_to_draw_(false), 241 requires_high_res_to_draw_(false),
242 is_likely_to_require_a_draw_(false), 242 is_likely_to_require_a_draw_(false),
243 has_valid_compositor_frame_sink_(false), 243 has_valid_compositor_frame_sink_(false),
244 mutator_(nullptr) { 244 mutator_(nullptr),
245 cached_scroll_state_for_fling_(Layer::INVALID_ID,
246 did_lock_scrolling_layer_,
247 scroll_affects_scroll_handler_,
248 accumulated_root_overscroll_) {
245 DCHECK(animation_host_); 249 DCHECK(animation_host_);
246 animation_host_->SetMutatorHostClient(this); 250 animation_host_->SetMutatorHostClient(this);
247 251
248 DCHECK(task_runner_provider_->IsImplThread()); 252 DCHECK(task_runner_provider_->IsImplThread());
249 DidVisibilityChange(this, visible_); 253 DidVisibilityChange(this, visible_);
250 254
251 SetDebugState(settings.initial_debug_state); 255 SetDebugState(settings.initial_debug_state);
252 256
253 // LTHI always has an active tree. 257 // LTHI always has an active tree.
254 active_tree_ = base::MakeUnique<LayerTreeImpl>( 258 active_tree_ = base::MakeUnique<LayerTreeImpl>(
(...skipping 2381 matching lines...) Expand 10 before | Expand all | Expand 10 after
2636 return ScrollBeginImpl(scroll_state, viewport()->MainScrollLayer(), type); 2640 return ScrollBeginImpl(scroll_state, viewport()->MainScrollLayer(), type);
2637 } 2641 }
2638 2642
2639 InputHandler::ScrollStatus LayerTreeHostImpl::ScrollBegin( 2643 InputHandler::ScrollStatus LayerTreeHostImpl::ScrollBegin(
2640 ScrollState* scroll_state, 2644 ScrollState* scroll_state,
2641 InputHandler::ScrollInputType type) { 2645 InputHandler::ScrollInputType type) {
2642 ScrollStatus scroll_status; 2646 ScrollStatus scroll_status;
2643 scroll_status.main_thread_scrolling_reasons = 2647 scroll_status.main_thread_scrolling_reasons =
2644 MainThreadScrollingReason::kNotScrollingOnMain; 2648 MainThreadScrollingReason::kNotScrollingOnMain;
2645 TRACE_EVENT0("cc", "LayerTreeHostImpl::ScrollBegin"); 2649 TRACE_EVENT0("cc", "LayerTreeHostImpl::ScrollBegin");
2650 LayerImpl* scrolling_layer_impl = nullptr;
2651 // On Mac a scroll begin with |inertial_phase| = true happens to handle a
2652 // fling. Also, touchpad fling starts are handled by calling ScrollBegin
2653 // instead of FlingScrollBegin.
2654 if (scroll_state->is_in_inertial_phase())
2655 scrolling_layer_impl = RestoreScrollStateForFling();
2646 2656
2647 // On Mac a scroll begin with |inertial_phase| = true happens to handle a 2657 if (!scrolling_layer_impl) {
2648 // fling. 2658 ClearCurrentlyScrollingLayer();
2649 if (scroll_state->is_in_inertial_phase())
2650 return FlingScrollBegin();
2651 2659
2652 ClearCurrentlyScrollingLayer(); 2660 gfx::Point viewport_point(scroll_state->position_x(),
2661 scroll_state->position_y());
2653 2662
2654 gfx::Point viewport_point(scroll_state->position_x(), 2663 gfx::PointF device_viewport_point = gfx::ScalePoint(
2655 scroll_state->position_y()); 2664 gfx::PointF(viewport_point), active_tree_->device_scale_factor());
2665 LayerImpl* layer_impl =
2666 active_tree_->FindLayerThatIsHitByPoint(device_viewport_point);
2656 2667
2657 gfx::PointF device_viewport_point = gfx::ScalePoint( 2668 if (layer_impl) {
2658 gfx::PointF(viewport_point), active_tree_->device_scale_factor()); 2669 LayerImpl* scroll_layer_impl =
2659 LayerImpl* layer_impl = 2670 active_tree_->FindFirstScrollingLayerOrScrollbarLayerThatIsHitByPoint(
2660 active_tree_->FindLayerThatIsHitByPoint(device_viewport_point); 2671 device_viewport_point);
2672 if (scroll_layer_impl &&
2673 !HasScrollAncestor(layer_impl, scroll_layer_impl)) {
2674 scroll_status.thread = SCROLL_UNKNOWN;
2675 scroll_status.main_thread_scrolling_reasons =
2676 MainThreadScrollingReason::kFailedHitTest;
2677 return scroll_status;
2678 }
2679 }
2661 2680
2662 if (layer_impl) { 2681 bool scroll_on_main_thread = false;
2663 LayerImpl* scroll_layer_impl = 2682 scrolling_layer_impl = FindScrollLayerForDeviceViewportPoint(
2664 active_tree_->FindFirstScrollingLayerOrScrollbarLayerThatIsHitByPoint( 2683 device_viewport_point, type, layer_impl, &scroll_on_main_thread,
2665 device_viewport_point); 2684 &scroll_status.main_thread_scrolling_reasons);
2666 if (scroll_layer_impl && 2685
2667 !HasScrollAncestor(layer_impl, scroll_layer_impl)) { 2686 if (scrolling_layer_impl)
tdresser 2016/10/26 15:38:18 Use {}
sahel 2016/10/26 18:47:45 Done.
2668 scroll_status.thread = SCROLL_UNKNOWN; 2687 scroll_affects_scroll_handler_ =
2669 scroll_status.main_thread_scrolling_reasons = 2688 scrolling_layer_impl->layer_tree_impl()->have_scroll_event_handlers();
2670 MainThreadScrollingReason::kFailedHitTest; 2689
2690 if (scroll_on_main_thread) {
2691 RecordCompositorSlowScrollMetric(type, MAIN_THREAD);
2692
2693 scroll_status.thread = SCROLL_ON_MAIN_THREAD;
2671 return scroll_status; 2694 return scroll_status;
2672 } 2695 }
2673 } 2696 }
2674 2697
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); 2698 return ScrollBeginImpl(scroll_state, scrolling_layer_impl, type);
2692 } 2699 }
2693 2700
2694 InputHandler::ScrollStatus LayerTreeHostImpl::ScrollAnimatedBegin( 2701 InputHandler::ScrollStatus LayerTreeHostImpl::ScrollAnimatedBegin(
2695 const gfx::Point& viewport_point) { 2702 const gfx::Point& viewport_point) {
2696 InputHandler::ScrollStatus scroll_status; 2703 InputHandler::ScrollStatus scroll_status;
2697 scroll_status.main_thread_scrolling_reasons = 2704 scroll_status.main_thread_scrolling_reasons =
2698 MainThreadScrollingReason::kNotScrollingOnMain; 2705 MainThreadScrollingReason::kNotScrollingOnMain;
2699 ScrollTree& scroll_tree = active_tree_->property_trees()->scroll_tree; 2706 ScrollTree& scroll_tree = active_tree_->property_trees()->scroll_tree;
2700 ScrollNode* scroll_node = scroll_tree.CurrentlyScrollingNode(); 2707 ScrollNode* scroll_node = scroll_tree.CurrentlyScrollingNode();
(...skipping 17 matching lines...) Expand all
2718 // ScrollAnimated is used for animated wheel scrolls. We find the first layer 2725 // 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 2726 // 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 2727 // this does not currently go through the scroll customization machinery
2721 // that ScrollBy uses for non-animated wheel scrolls. 2728 // that ScrollBy uses for non-animated wheel scrolls.
2722 scroll_status = ScrollBegin(&scroll_state, WHEEL); 2729 scroll_status = ScrollBegin(&scroll_state, WHEEL);
2723 scroll_node = scroll_tree.CurrentlyScrollingNode(); 2730 scroll_node = scroll_tree.CurrentlyScrollingNode();
2724 if (scroll_status.thread == SCROLL_ON_IMPL_THREAD) { 2731 if (scroll_status.thread == SCROLL_ON_IMPL_THREAD) {
2725 ScrollStateData scroll_state_end_data; 2732 ScrollStateData scroll_state_end_data;
2726 scroll_state_end_data.is_ending = true; 2733 scroll_state_end_data.is_ending = true;
2727 ScrollState scroll_state_end(scroll_state_end_data); 2734 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); 2735 ScrollEnd(&scroll_state_end);
2732 ClearCurrentlyScrollingLayer();
2733 } 2736 }
2734 return scroll_status; 2737 return scroll_status;
2735 } 2738 }
2736 2739
2737 gfx::Vector2dF LayerTreeHostImpl::ComputeScrollDelta( 2740 gfx::Vector2dF LayerTreeHostImpl::ComputeScrollDelta(
2738 ScrollNode* scroll_node, 2741 ScrollNode* scroll_node,
2739 const gfx::Vector2dF& delta) { 2742 const gfx::Vector2dF& delta) {
2740 ScrollTree& scroll_tree = active_tree()->property_trees()->scroll_tree; 2743 ScrollTree& scroll_tree = active_tree()->property_trees()->scroll_tree;
2741 float scale_factor = active_tree()->current_page_scale_factor(); 2744 float scale_factor = active_tree()->current_page_scale_factor();
2742 2745
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
2846 gfx::Vector2dF scroll_delta = 2849 gfx::Vector2dF scroll_delta =
2847 ComputeScrollDelta(scroll_node, pending_delta); 2850 ComputeScrollDelta(scroll_node, pending_delta);
2848 if (ScrollAnimationCreate(scroll_node, scroll_delta, delayed_by)) 2851 if (ScrollAnimationCreate(scroll_node, scroll_delta, delayed_by))
2849 return scroll_status; 2852 return scroll_status;
2850 2853
2851 pending_delta -= scroll_delta; 2854 pending_delta -= scroll_delta;
2852 } 2855 }
2853 } 2856 }
2854 } 2857 }
2855 scroll_state.set_is_ending(true); 2858 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); 2859 ScrollEnd(&scroll_state);
2860 ClearCurrentlyScrollingLayer();
2861 2860
2862 return scroll_status; 2861 return scroll_status;
2863 } 2862 }
2864 2863
2865 gfx::Vector2dF LayerTreeHostImpl::ScrollNodeWithViewportSpaceDelta( 2864 gfx::Vector2dF LayerTreeHostImpl::ScrollNodeWithViewportSpaceDelta(
2866 ScrollNode* scroll_node, 2865 ScrollNode* scroll_node,
2867 const gfx::PointF& viewport_point, 2866 const gfx::PointF& viewport_point,
2868 const gfx::Vector2dF& viewport_delta, 2867 const gfx::Vector2dF& viewport_delta,
2869 ScrollTree* scroll_tree) { 2868 ScrollTree* scroll_tree) {
2870 // Layers with non-invertible screen space transforms should not have passed 2869 // Layers with non-invertible screen space transforms should not have passed
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
3158 3157
3159 client_->SetNeedsCommitOnImplThread(); 3158 client_->SetNeedsCommitOnImplThread();
3160 // After applying the synchronous input handler's scroll offset, tell it what 3159 // After applying the synchronous input handler's scroll offset, tell it what
3161 // we ended up with. 3160 // we ended up with.
3162 UpdateRootLayerStateForSynchronousInputHandler(); 3161 UpdateRootLayerStateForSynchronousInputHandler();
3163 SetFullViewportDamage(); 3162 SetFullViewportDamage();
3164 SetNeedsRedraw(); 3163 SetNeedsRedraw();
3165 } 3164 }
3166 3165
3167 void LayerTreeHostImpl::ClearCurrentlyScrollingLayer() { 3166 void LayerTreeHostImpl::ClearCurrentlyScrollingLayer() {
3167 // Cached scrolling variables state is restored in a ScrollBegin with
3168 // inertial phase (fling) to latch it to its corresponding scroll. When
3169 // reseting a variable here, update ScrollStateForFling class as well
3170 // to maintain the proper caching.
3171 CacheScrollStateForFling();
3168 active_tree_->ClearCurrentlyScrollingLayer(); 3172 active_tree_->ClearCurrentlyScrollingLayer();
3169 did_lock_scrolling_layer_ = false; 3173 did_lock_scrolling_layer_ = false;
3170 scroll_affects_scroll_handler_ = false; 3174 scroll_affects_scroll_handler_ = false;
3171 accumulated_root_overscroll_ = gfx::Vector2dF(); 3175 accumulated_root_overscroll_ = gfx::Vector2dF();
3172 } 3176 }
3173 3177
3174 void LayerTreeHostImpl::ScrollEnd(ScrollState* scroll_state) { 3178 void LayerTreeHostImpl::ScrollEnd(ScrollState* scroll_state) {
3175 DCHECK(scroll_state); 3179 DCHECK(scroll_state);
3176 DCHECK(scroll_state->delta_x() == 0 && scroll_state->delta_y() == 0); 3180 DCHECK(scroll_state->delta_x() == 0 && scroll_state->delta_y() == 0);
3177 3181
3178 DistributeScrollDelta(scroll_state); 3182 DistributeScrollDelta(scroll_state);
3179 top_controls_manager_->ScrollEnd(); 3183 top_controls_manager_->ScrollEnd();
3180 3184
3181 if (scroll_state->is_in_inertial_phase()) { 3185 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 } 3186 }
3187 3187
3188 InputHandler::ScrollStatus LayerTreeHostImpl::FlingScrollBegin() { 3188 InputHandler::ScrollStatus LayerTreeHostImpl::FlingScrollBegin() {
3189 InputHandler::ScrollStatus scroll_status; 3189 InputHandler::ScrollStatus scroll_status;
3190 scroll_status.main_thread_scrolling_reasons = 3190 scroll_status.main_thread_scrolling_reasons =
3191 MainThreadScrollingReason::kNotScrollingOnMain; 3191 MainThreadScrollingReason::kNotScrollingOnMain;
3192 if (!CurrentlyScrollingLayer()) { 3192 if (!CurrentlyScrollingLayer()) {
3193 scroll_status.thread = SCROLL_IGNORED; 3193 scroll_status.thread = SCROLL_IGNORED;
3194 scroll_status.main_thread_scrolling_reasons = 3194 scroll_status.main_thread_scrolling_reasons =
3195 MainThreadScrollingReason::kNoScrollingLayer; 3195 MainThreadScrollingReason::kNoScrollingLayer;
(...skipping 832 matching lines...) Expand 10 before | Expand all | Expand 10 after
4028 return; 4028 return;
4029 LayerImpl* layer = tree->LayerByElementId(element_id); 4029 LayerImpl* layer = tree->LayerByElementId(element_id);
4030 if (layer) 4030 if (layer)
4031 layer->OnIsAnimatingChanged(mask, state); 4031 layer->OnIsAnimatingChanged(mask, state);
4032 } 4032 }
4033 4033
4034 void LayerTreeHostImpl::ScrollOffsetAnimationFinished() { 4034 void LayerTreeHostImpl::ScrollOffsetAnimationFinished() {
4035 // TODO(majidvp): We should pass in the original starting scroll position here 4035 // TODO(majidvp): We should pass in the original starting scroll position here
4036 ScrollStateData scroll_state_data; 4036 ScrollStateData scroll_state_data;
4037 ScrollState scroll_state(scroll_state_data); 4037 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); 4038 ScrollEnd(&scroll_state);
4042 ClearCurrentlyScrollingLayer();
4043 } 4039 }
4044 4040
4045 gfx::ScrollOffset LayerTreeHostImpl::GetScrollOffsetForAnimation( 4041 gfx::ScrollOffset LayerTreeHostImpl::GetScrollOffsetForAnimation(
4046 ElementId element_id) const { 4042 ElementId element_id) const {
4047 if (active_tree()) { 4043 if (active_tree()) {
4048 LayerImpl* layer = active_tree()->LayerByElementId(element_id); 4044 LayerImpl* layer = active_tree()->LayerByElementId(element_id);
4049 if (layer) 4045 if (layer)
4050 return layer->ScrollOffsetForAnimation(); 4046 return layer->ScrollOffsetForAnimation();
4051 } 4047 }
4052 4048
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
4100 ContextProvider::ScopedContextLock hold(worker_context); 4096 ContextProvider::ScopedContextLock hold(worker_context);
4101 if (is_visible) { 4097 if (is_visible) {
4102 worker_context_visibility_ = 4098 worker_context_visibility_ =
4103 worker_context->CacheController()->ClientBecameVisible(); 4099 worker_context->CacheController()->ClientBecameVisible();
4104 } else { 4100 } else {
4105 worker_context->CacheController()->ClientBecameNotVisible( 4101 worker_context->CacheController()->ClientBecameNotVisible(
4106 std::move(worker_context_visibility_)); 4102 std::move(worker_context_visibility_));
4107 } 4103 }
4108 } 4104 }
4109 4105
4106 void LayerTreeHostImpl::CacheScrollStateForFling() {
4107 int scrolling_layer_id = active_tree_->CurrentlyScrollingLayer()
4108 ? active_tree_->CurrentlyScrollingLayer()->id()
4109 : Layer::INVALID_ID;
4110 cached_scroll_state_for_fling_ = ScrollStateForFling(
4111 scrolling_layer_id, did_lock_scrolling_layer_,
4112 scroll_affects_scroll_handler_, accumulated_root_overscroll_);
4113 }
4114 LayerImpl* LayerTreeHostImpl::RestoreScrollStateForFling() {
tdresser 2016/10/26 15:38:18 It seems a bit weird to me that this returns the c
bokan 2016/10/26 16:01:53 +1
sahel 2016/10/26 18:47:45 Done.
4115 active_tree_->SetCurrentlyScrollingLayer(active_tree_->LayerById(
4116 cached_scroll_state_for_fling_.scrollingLayerId()));
4117 did_lock_scrolling_layer_ =
4118 cached_scroll_state_for_fling_.didLockScrollingLayer();
4119 scroll_affects_scroll_handler_ =
4120 cached_scroll_state_for_fling_.scrollAffectsScrollHandler();
4121 accumulated_root_overscroll_ =
4122 cached_scroll_state_for_fling_.accumulatedRootOverscroll();
4123 return active_tree_->CurrentlyScrollingLayer();
4124 }
4125
4110 } // namespace cc 4126 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698