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

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

Issue 2720183003: Track the currently scrolling ScrollNode instead of the scrolling layer (Closed)
Patch Set: Ali did forsee a use-after-free with no stable id Created 3 years, 9 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
« no previous file with comments | « cc/trees/layer_tree_host_impl.h ('k') | cc/trees/layer_tree_host_impl_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 bool scroll_on_main_thread = (scroll_thread == MAIN_THREAD); 147 bool scroll_on_main_thread = (scroll_thread == MAIN_THREAD);
148 if (IsWheelBasedScroll(type)) { 148 if (IsWheelBasedScroll(type)) {
149 UMA_HISTOGRAM_BOOLEAN("Renderer4.CompositorWheelScrollUpdateThread", 149 UMA_HISTOGRAM_BOOLEAN("Renderer4.CompositorWheelScrollUpdateThread",
150 scroll_on_main_thread); 150 scroll_on_main_thread);
151 } else { 151 } else {
152 UMA_HISTOGRAM_BOOLEAN("Renderer4.CompositorTouchScrollUpdateThread", 152 UMA_HISTOGRAM_BOOLEAN("Renderer4.CompositorTouchScrollUpdateThread",
153 scroll_on_main_thread); 153 scroll_on_main_thread);
154 } 154 }
155 } 155 }
156 156
157 // Return true if scrollable node for 'ancestor' is the same as 'child' or an
158 // ancestor along the scroll tree.
159 bool IsScrolledBy(LayerImpl* child, LayerImpl* ancestor) {
160 DCHECK(ancestor && ancestor->scrollable());
161 if (!child)
162 return false;
163
164 auto* property_trees = child->layer_tree_impl()->property_trees();
165 ScrollTree& scroll_tree = property_trees->scroll_tree;
166 for (ScrollNode* scroll_node = scroll_tree.Node(child->scroll_tree_index());
167 scroll_node; scroll_node = scroll_tree.parent(scroll_node)) {
168 if (scroll_node->id == ancestor->scroll_tree_index())
169 return true;
170 }
171 return false;
172 }
173
174 } // namespace 157 } // namespace
175 158
176 DEFINE_SCOPED_UMA_HISTOGRAM_TIMER(PendingTreeDurationHistogramTimer, 159 DEFINE_SCOPED_UMA_HISTOGRAM_TIMER(PendingTreeDurationHistogramTimer,
177 "Scheduling.%s.PendingTreeDuration"); 160 "Scheduling.%s.PendingTreeDuration");
178 161
179 LayerTreeHostImpl::FrameData::FrameData() 162 LayerTreeHostImpl::FrameData::FrameData()
180 : render_surface_layer_list(nullptr), 163 : render_surface_layer_list(nullptr),
181 has_no_damage(false), 164 has_no_damage(false),
182 may_contain_video(false) {} 165 may_contain_video(false) {}
183 166
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 // Must be initialized after is_synchronous_single_threaded_ and 215 // Must be initialized after is_synchronous_single_threaded_ and
233 // task_runner_provider_. 216 // task_runner_provider_.
234 tile_manager_(this, 217 tile_manager_(this,
235 GetTaskRunner(), 218 GetTaskRunner(),
236 std::move(image_worker_task_runner), 219 std::move(image_worker_task_runner),
237 is_synchronous_single_threaded_ 220 is_synchronous_single_threaded_
238 ? std::numeric_limits<size_t>::max() 221 ? std::numeric_limits<size_t>::max()
239 : settings.scheduled_raster_task_limit, 222 : settings.scheduled_raster_task_limit,
240 settings.ToTileManagerSettings()), 223 settings.ToTileManagerSettings()),
241 pinch_gesture_active_(false), 224 pinch_gesture_active_(false),
242 pinch_gesture_end_should_clear_scrolling_layer_(false), 225 pinch_gesture_end_should_clear_scrolling_node_(false),
243 fps_counter_( 226 fps_counter_(
244 FrameRateCounter::Create(task_runner_provider_->HasImplThread())), 227 FrameRateCounter::Create(task_runner_provider_->HasImplThread())),
245 memory_history_(MemoryHistory::Create()), 228 memory_history_(MemoryHistory::Create()),
246 debug_rect_history_(DebugRectHistory::Create()), 229 debug_rect_history_(DebugRectHistory::Create()),
247 max_memory_needed_bytes_(0), 230 max_memory_needed_bytes_(0),
248 resourceless_software_draw_(false), 231 resourceless_software_draw_(false),
249 mutator_host_(std::move(mutator_host)), 232 mutator_host_(std::move(mutator_host)),
250 rendering_stats_instrumentation_(rendering_stats_instrumentation), 233 rendering_stats_instrumentation_(rendering_stats_instrumentation),
251 micro_benchmark_controller_(this), 234 micro_benchmark_controller_(this),
252 task_graph_runner_(task_graph_runner), 235 task_graph_runner_(task_graph_runner),
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 client_->RenewTreePriority(); 541 client_->RenewTreePriority();
559 } 542 }
560 543
561 void LayerTreeHostImpl::SetNeedsAnimateInput() { 544 void LayerTreeHostImpl::SetNeedsAnimateInput() {
562 DCHECK(!IsCurrentlyScrollingViewport() || 545 DCHECK(!IsCurrentlyScrollingViewport() ||
563 !settings_.ignore_root_layer_flings); 546 !settings_.ignore_root_layer_flings);
564 SetNeedsOneBeginImplFrame(); 547 SetNeedsOneBeginImplFrame();
565 } 548 }
566 549
567 bool LayerTreeHostImpl::IsCurrentlyScrollingViewport() const { 550 bool LayerTreeHostImpl::IsCurrentlyScrollingViewport() const {
568 LayerImpl* scrolling_layer = CurrentlyScrollingLayer(); 551 auto* node = CurrentlyScrollingNode();
569 if (!scrolling_layer) 552 if (!node)
570 return false; 553 return false;
571 DCHECK(viewport()); 554 if (!viewport()->MainScrollLayer())
572 return scrolling_layer == viewport()->MainScrollLayer(); 555 return false;
556 return node->id == viewport()->MainScrollLayer()->scroll_tree_index();
ajuma 2017/03/01 15:29:20 I think the logic above is equivalent to just doin
pdr. 2017/03/01 19:31:26 Yeah it's the same (as long as we check that the c
ajuma 2017/03/01 19:34:42 Ah, I missed that difference. Leaving this as-is u
573 } 557 }
574 558
575 bool LayerTreeHostImpl::IsCurrentlyScrollingLayerAt( 559 bool LayerTreeHostImpl::IsCurrentlyScrollingLayerAt(
576 const gfx::Point& viewport_point, 560 const gfx::Point& viewport_point,
577 InputHandler::ScrollInputType type) const { 561 InputHandler::ScrollInputType type) const {
578 LayerImpl* scrolling_layer_impl = CurrentlyScrollingLayer(); 562 auto* scrolling_node = CurrentlyScrollingNode();
579 if (!scrolling_layer_impl) 563 if (!scrolling_node)
580 return false; 564 return false;
581 565
582 gfx::PointF device_viewport_point = gfx::ScalePoint( 566 gfx::PointF device_viewport_point = gfx::ScalePoint(
583 gfx::PointF(viewport_point), active_tree_->device_scale_factor()); 567 gfx::PointF(viewport_point), active_tree_->device_scale_factor());
584 568
585 LayerImpl* layer_impl = 569 LayerImpl* layer_impl =
586 active_tree_->FindLayerThatIsHitByPoint(device_viewport_point); 570 active_tree_->FindLayerThatIsHitByPoint(device_viewport_point);
587 571
588 bool scroll_on_main_thread = false; 572 bool scroll_on_main_thread = false;
589 uint32_t main_thread_scrolling_reasons; 573 uint32_t main_thread_scrolling_reasons;
590 LayerImpl* test_layer_impl = FindScrollLayerForDeviceViewportPoint( 574 LayerImpl* test_layer_impl = FindScrollLayerForDeviceViewportPoint(
591 device_viewport_point, type, layer_impl, &scroll_on_main_thread, 575 device_viewport_point, type, layer_impl, &scroll_on_main_thread,
592 &main_thread_scrolling_reasons); 576 &main_thread_scrolling_reasons);
593 577
594 if (scroll_on_main_thread) 578 if (scroll_on_main_thread)
595 return false; 579 return false;
596 580
597 if (scrolling_layer_impl == test_layer_impl) 581 int test_scroll_tree_index = test_layer_impl->scroll_tree_index();
582 if (scrolling_node->id == test_scroll_tree_index)
598 return true; 583 return true;
599 584
600 // For active scrolling state treat the inner/outer viewports interchangeably. 585 // For active scrolling state treat the inner/outer viewports interchangeably.
601 if (scrolling_layer_impl == InnerViewportScrollLayer() || 586 if (scrolling_node->scrolls_inner_viewport ||
602 scrolling_layer_impl == OuterViewportScrollLayer()) { 587 scrolling_node->scrolls_outer_viewport) {
603 return test_layer_impl == viewport()->MainScrollLayer(); 588 return test_layer_impl == viewport()->MainScrollLayer();
604 } 589 }
605 590
606 return false; 591 return false;
607 } 592 }
608 593
609 EventListenerProperties LayerTreeHostImpl::GetEventListenerProperties( 594 EventListenerProperties LayerTreeHostImpl::GetEventListenerProperties(
610 EventListenerClass event_class) const { 595 EventListenerClass event_class) const {
611 return active_tree_->event_listener_properties(event_class); 596 return active_tree_->event_listener_properties(event_class);
612 } 597 }
613 598
599 // Return true if scrollable node for 'ancestor' is the same as 'child' or an
600 // ancestor along the scroll tree.
601 bool IsScrolledBy(LayerImpl* child, ScrollNode* ancestor) {
602 DCHECK(ancestor && ancestor->scrollable);
603 if (!child)
604 return false;
605
606 auto* property_trees = child->layer_tree_impl()->property_trees();
607 ScrollTree& scroll_tree = property_trees->scroll_tree;
608 for (ScrollNode* scroll_node = scroll_tree.Node(child->scroll_tree_index());
609 scroll_node; scroll_node = scroll_tree.parent(scroll_node)) {
610 if (scroll_node->id == ancestor->id)
611 return true;
612 }
613 return false;
614 }
615
614 InputHandler::TouchStartEventListenerType 616 InputHandler::TouchStartEventListenerType
615 LayerTreeHostImpl::EventListenerTypeForTouchStartAt( 617 LayerTreeHostImpl::EventListenerTypeForTouchStartAt(
616 const gfx::Point& viewport_point) { 618 const gfx::Point& viewport_point) {
617 gfx::PointF device_viewport_point = gfx::ScalePoint( 619 gfx::PointF device_viewport_point = gfx::ScalePoint(
618 gfx::PointF(viewport_point), active_tree_->device_scale_factor()); 620 gfx::PointF(viewport_point), active_tree_->device_scale_factor());
619 621
620 // Now determine if there are actually any handlers at that point. 622 // Now determine if there are actually any handlers at that point.
621 // TODO(rbyers): Consider also honoring touch-action (crbug.com/347272). 623 // TODO(rbyers): Consider also honoring touch-action (crbug.com/347272).
622 LayerImpl* layer_impl = 624 LayerImpl* layer_impl =
623 active_tree_->FindLayerThatIsHitByPointInTouchHandlerRegion( 625 active_tree_->FindLayerThatIsHitByPointInTouchHandlerRegion(
624 device_viewport_point); 626 device_viewport_point);
625 if (layer_impl == NULL) 627 if (layer_impl == NULL)
626 return InputHandler::TouchStartEventListenerType::NO_HANDLER; 628 return InputHandler::TouchStartEventListenerType::NO_HANDLER;
627 629
628 if (!CurrentlyScrollingLayer()) 630 if (!CurrentlyScrollingNode())
629 return InputHandler::TouchStartEventListenerType::HANDLER; 631 return InputHandler::TouchStartEventListenerType::HANDLER;
630 632
631 bool is_ancestor = 633 bool is_ancestor = IsScrolledBy(layer_impl, CurrentlyScrollingNode());
632 IsScrolledBy(layer_impl, active_tree_->CurrentlyScrollingLayer());
633 return is_ancestor ? InputHandler::TouchStartEventListenerType:: 634 return is_ancestor ? InputHandler::TouchStartEventListenerType::
634 HANDLER_ON_SCROLLING_LAYER 635 HANDLER_ON_SCROLLING_LAYER
635 : InputHandler::TouchStartEventListenerType::HANDLER; 636 : InputHandler::TouchStartEventListenerType::HANDLER;
636 } 637 }
637 638
638 std::unique_ptr<SwapPromiseMonitor> 639 std::unique_ptr<SwapPromiseMonitor>
639 LayerTreeHostImpl::CreateLatencyInfoSwapPromiseMonitor( 640 LayerTreeHostImpl::CreateLatencyInfoSwapPromiseMonitor(
640 ui::LatencyInfo* latency) { 641 ui::LatencyInfo* latency) {
641 return base::WrapUnique( 642 return base::WrapUnique(
642 new LatencyInfoSwapPromiseMonitor(latency, NULL, this)); 643 new LatencyInfoSwapPromiseMonitor(latency, NULL, this));
(...skipping 1316 matching lines...) Expand 10 before | Expand all | Expand 10 after
1959 } 1960 }
1960 1961
1961 LayerImpl* LayerTreeHostImpl::InnerViewportScrollLayer() const { 1962 LayerImpl* LayerTreeHostImpl::InnerViewportScrollLayer() const {
1962 return active_tree_->InnerViewportScrollLayer(); 1963 return active_tree_->InnerViewportScrollLayer();
1963 } 1964 }
1964 1965
1965 LayerImpl* LayerTreeHostImpl::OuterViewportScrollLayer() const { 1966 LayerImpl* LayerTreeHostImpl::OuterViewportScrollLayer() const {
1966 return active_tree_->OuterViewportScrollLayer(); 1967 return active_tree_->OuterViewportScrollLayer();
1967 } 1968 }
1968 1969
1969 LayerImpl* LayerTreeHostImpl::CurrentlyScrollingLayer() const { 1970 ScrollNode* LayerTreeHostImpl::OuterViewportScrollNode() const {
1970 return active_tree_->CurrentlyScrollingLayer(); 1971 if (!viewport()->MainScrollLayer())
1972 return nullptr;
1973 ScrollTree& scroll_tree = active_tree_->property_trees()->scroll_tree;
1974 return scroll_tree.Node(viewport()->MainScrollLayer()->scroll_tree_index());
1975 }
1976
1977 ScrollNode* LayerTreeHostImpl::CurrentlyScrollingNode() {
1978 return active_tree()->CurrentlyScrollingNode();
1979 }
1980
1981 const ScrollNode* LayerTreeHostImpl::CurrentlyScrollingNode() const {
1982 return active_tree()->CurrentlyScrollingNode();
1971 } 1983 }
1972 1984
1973 bool LayerTreeHostImpl::IsActivelyScrolling() const { 1985 bool LayerTreeHostImpl::IsActivelyScrolling() const {
1974 if (!CurrentlyScrollingLayer()) 1986 if (!CurrentlyScrollingNode())
1975 return false; 1987 return false;
1976 // On Android WebView root flings are controlled by the application, 1988 // On Android WebView root flings are controlled by the application,
1977 // so the compositor does not animate them and can't tell if they 1989 // so the compositor does not animate them and can't tell if they
1978 // are actually animating. So assume there are none. 1990 // are actually animating. So assume there are none.
1979 if (settings_.ignore_root_layer_flings && IsCurrentlyScrollingViewport()) 1991 if (settings_.ignore_root_layer_flings && IsCurrentlyScrollingViewport())
1980 return false; 1992 return false;
1981 return did_lock_scrolling_layer_; 1993 return did_lock_scrolling_layer_;
1982 } 1994 }
1983 1995
1984 void LayerTreeHostImpl::CreatePendingTree() { 1996 void LayerTreeHostImpl::CreatePendingTree() {
(...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after
2595 } 2607 }
2596 } 2608 }
2597 2609
2598 // Falling back to the viewport layer ensures generation of root overscroll 2610 // Falling back to the viewport layer ensures generation of root overscroll
2599 // notifications. We use the viewport's main scroll layer to represent the 2611 // notifications. We use the viewport's main scroll layer to represent the
2600 // viewport in scrolling code. 2612 // viewport in scrolling code.
2601 bool scrolls_inner_viewport = 2613 bool scrolls_inner_viewport =
2602 impl_scroll_node && impl_scroll_node->scrolls_inner_viewport; 2614 impl_scroll_node && impl_scroll_node->scrolls_inner_viewport;
2603 bool scrolls_outer_viewport = 2615 bool scrolls_outer_viewport =
2604 impl_scroll_node && impl_scroll_node->scrolls_outer_viewport; 2616 impl_scroll_node && impl_scroll_node->scrolls_outer_viewport;
2605 if (!impl_scroll_node || scrolls_inner_viewport || scrolls_outer_viewport) { 2617 if (!impl_scroll_node || scrolls_inner_viewport || scrolls_outer_viewport)
2606 if (auto* mainScrollLayer = viewport()->MainScrollLayer()) 2618 impl_scroll_node = OuterViewportScrollNode();
2607 impl_scroll_node = scroll_tree.Node(mainScrollLayer->scroll_tree_index());
2608 else
2609 impl_scroll_node = nullptr;
2610 }
2611 2619
2612 if (impl_scroll_node) { 2620 if (impl_scroll_node) {
2613 // Ensure that final layer scrolls on impl thread (crbug.com/625100) 2621 // Ensure that final layer scrolls on impl thread (crbug.com/625100)
2614 ScrollStatus status = 2622 ScrollStatus status =
2615 TryScroll(device_viewport_point, type, scroll_tree, impl_scroll_node); 2623 TryScroll(device_viewport_point, type, scroll_tree, impl_scroll_node);
2616 if (IsMainThreadScrolling(status, impl_scroll_node)) { 2624 if (IsMainThreadScrolling(status, impl_scroll_node)) {
2617 *scroll_on_main_thread = true; 2625 *scroll_on_main_thread = true;
2618 *main_thread_scrolling_reasons = status.main_thread_scrolling_reasons; 2626 *main_thread_scrolling_reasons = status.main_thread_scrolling_reasons;
2619 } 2627 }
2620 } 2628 }
2621 2629
2622 // TODO(pdr): Refactor this function to directly return |impl_scroll_node| 2630 // TODO(pdr): Refactor this function to directly return |impl_scroll_node|
2623 // instead of using ScrollNode's owning_layer_id to return a LayerImpl. 2631 // instead of using ScrollNode's owning_layer_id to return a LayerImpl.
2624 if (!impl_scroll_node) 2632 if (!impl_scroll_node)
2625 return nullptr; 2633 return nullptr;
2626 return active_tree_->LayerById(impl_scroll_node->owning_layer_id); 2634 return active_tree_->LayerById(impl_scroll_node->owning_layer_id);
2627 } 2635 }
2628 2636
2629 InputHandler::ScrollStatus LayerTreeHostImpl::ScrollBeginImpl( 2637 InputHandler::ScrollStatus LayerTreeHostImpl::ScrollBeginImpl(
2630 ScrollState* scroll_state, 2638 ScrollState* scroll_state,
2631 LayerImpl* scrolling_layer_impl, 2639 ScrollNode* scrolling_node,
2632 InputHandler::ScrollInputType type) { 2640 InputHandler::ScrollInputType type) {
2633 DCHECK(scroll_state); 2641 DCHECK(scroll_state);
2634 DCHECK(scroll_state->delta_x() == 0 && scroll_state->delta_y() == 0); 2642 DCHECK(scroll_state->delta_x() == 0 && scroll_state->delta_y() == 0);
2635 2643
2636 InputHandler::ScrollStatus scroll_status; 2644 InputHandler::ScrollStatus scroll_status;
2637 scroll_status.main_thread_scrolling_reasons = 2645 scroll_status.main_thread_scrolling_reasons =
2638 MainThreadScrollingReason::kNotScrollingOnMain; 2646 MainThreadScrollingReason::kNotScrollingOnMain;
2639 if (!scrolling_layer_impl) { 2647 if (!scrolling_node) {
2640 scroll_status.thread = SCROLL_IGNORED; 2648 scroll_status.thread = SCROLL_IGNORED;
2641 scroll_status.main_thread_scrolling_reasons = 2649 scroll_status.main_thread_scrolling_reasons =
2642 MainThreadScrollingReason::kNoScrollingLayer; 2650 MainThreadScrollingReason::kNoScrollingLayer;
2643 return scroll_status; 2651 return scroll_status;
2644 } 2652 }
2645 scroll_status.thread = SCROLL_ON_IMPL_THREAD; 2653 scroll_status.thread = SCROLL_ON_IMPL_THREAD;
2646 mutator_host_->ScrollAnimationAbort(); 2654 mutator_host_->ScrollAnimationAbort();
2647 2655
2648 browser_controls_offset_manager_->ScrollBegin(); 2656 browser_controls_offset_manager_->ScrollBegin();
2649 2657
2650 active_tree_->SetCurrentlyScrollingLayer(scrolling_layer_impl); 2658 active_tree_->SetCurrentlyScrollingNode(scrolling_node);
2651 // TODO(majidvp): get rid of wheel_scrolling_ and set is_direct_manipulation 2659 // TODO(majidvp): get rid of wheel_scrolling_ and set is_direct_manipulation
2652 // in input_handler_proxy instead. 2660 // in input_handler_proxy instead.
2653 wheel_scrolling_ = IsWheelBasedScroll(type); 2661 wheel_scrolling_ = IsWheelBasedScroll(type);
2654 scroll_state->set_is_direct_manipulation(!wheel_scrolling_); 2662 scroll_state->set_is_direct_manipulation(!wheel_scrolling_);
2655 // Invoke |DistributeScrollDelta| even with zero delta and velocity to ensure 2663 // Invoke |DistributeScrollDelta| even with zero delta and velocity to ensure
2656 // scroll customization callbacks are invoked. 2664 // scroll customization callbacks are invoked.
2657 DistributeScrollDelta(scroll_state); 2665 DistributeScrollDelta(scroll_state);
2658 2666
2659 client_->RenewTreePriority(); 2667 client_->RenewTreePriority();
2660 RecordCompositorSlowScrollMetric(type, CC_THREAD); 2668 RecordCompositorSlowScrollMetric(type, CC_THREAD);
2661 2669
2662 return scroll_status; 2670 return scroll_status;
2663 } 2671 }
2664 2672
2665 InputHandler::ScrollStatus LayerTreeHostImpl::RootScrollBegin( 2673 InputHandler::ScrollStatus LayerTreeHostImpl::RootScrollBegin(
2666 ScrollState* scroll_state, 2674 ScrollState* scroll_state,
2667 InputHandler::ScrollInputType type) { 2675 InputHandler::ScrollInputType type) {
2668 TRACE_EVENT0("cc", "LayerTreeHostImpl::RootScrollBegin"); 2676 TRACE_EVENT0("cc", "LayerTreeHostImpl::RootScrollBegin");
2669 2677
2670 ClearCurrentlyScrollingLayer(); 2678 ClearCurrentlyScrollingNode();
2671 2679
2672 DCHECK(viewport()); 2680 return ScrollBeginImpl(scroll_state, OuterViewportScrollNode(), type);
2673 return ScrollBeginImpl(scroll_state, viewport()->MainScrollLayer(), type);
2674 } 2681 }
2675 2682
2676 InputHandler::ScrollStatus LayerTreeHostImpl::ScrollBegin( 2683 InputHandler::ScrollStatus LayerTreeHostImpl::ScrollBegin(
2677 ScrollState* scroll_state, 2684 ScrollState* scroll_state,
2678 InputHandler::ScrollInputType type) { 2685 InputHandler::ScrollInputType type) {
2679 ScrollStatus scroll_status; 2686 ScrollStatus scroll_status;
2680 scroll_status.main_thread_scrolling_reasons = 2687 scroll_status.main_thread_scrolling_reasons =
2681 MainThreadScrollingReason::kNotScrollingOnMain; 2688 MainThreadScrollingReason::kNotScrollingOnMain;
2682 TRACE_EVENT0("cc", "LayerTreeHostImpl::ScrollBegin"); 2689 TRACE_EVENT0("cc", "LayerTreeHostImpl::ScrollBegin");
2683 2690
2684 LayerImpl* scrolling_layer_impl = nullptr; 2691 ScrollNode* scrolling_node = nullptr;
2685 bool scroll_on_main_thread = false; 2692 bool scroll_on_main_thread = false;
2686 2693
2687 if (scroll_state->is_in_inertial_phase()) 2694 if (scroll_state->is_in_inertial_phase())
2688 scrolling_layer_impl = CurrentlyScrollingLayer(); 2695 scrolling_node = CurrentlyScrollingNode();
2689 2696
2690 if (!scrolling_layer_impl) { 2697 if (!scrolling_node) {
2691 ClearCurrentlyScrollingLayer(); 2698 ClearCurrentlyScrollingNode();
2692 2699
2693 gfx::Point viewport_point(scroll_state->position_x(), 2700 gfx::Point viewport_point(scroll_state->position_x(),
2694 scroll_state->position_y()); 2701 scroll_state->position_y());
2695 2702
2696 gfx::PointF device_viewport_point = gfx::ScalePoint( 2703 gfx::PointF device_viewport_point = gfx::ScalePoint(
2697 gfx::PointF(viewport_point), active_tree_->device_scale_factor()); 2704 gfx::PointF(viewport_point), active_tree_->device_scale_factor());
2698 LayerImpl* layer_impl = 2705 LayerImpl* layer_impl =
2699 active_tree_->FindLayerThatIsHitByPoint(device_viewport_point); 2706 active_tree_->FindLayerThatIsHitByPoint(device_viewport_point);
2700 2707
2701 if (layer_impl) { 2708 if (layer_impl) {
2702 if (!IsInitialScrollHitTestReliable(layer_impl, device_viewport_point)) { 2709 if (!IsInitialScrollHitTestReliable(layer_impl, device_viewport_point)) {
2703 scroll_status.thread = SCROLL_UNKNOWN; 2710 scroll_status.thread = SCROLL_UNKNOWN;
2704 scroll_status.main_thread_scrolling_reasons = 2711 scroll_status.main_thread_scrolling_reasons =
2705 MainThreadScrollingReason::kFailedHitTest; 2712 MainThreadScrollingReason::kFailedHitTest;
2706 return scroll_status; 2713 return scroll_status;
2707 } 2714 }
2708 } 2715 }
2709 2716
2710 scrolling_layer_impl = FindScrollLayerForDeviceViewportPoint( 2717 auto* scrolling_layer = FindScrollLayerForDeviceViewportPoint(
2711 device_viewport_point, type, layer_impl, &scroll_on_main_thread, 2718 device_viewport_point, type, layer_impl, &scroll_on_main_thread,
2712 &scroll_status.main_thread_scrolling_reasons); 2719 &scroll_status.main_thread_scrolling_reasons);
2720 ScrollTree& scroll_tree = active_tree_->property_trees()->scroll_tree;
2721 scrolling_node =
2722 scrolling_layer ? scroll_tree.Node(scrolling_layer->scroll_tree_index())
2723 : nullptr;
2713 } 2724 }
2714 2725
2715 if (scroll_on_main_thread) { 2726 if (scroll_on_main_thread) {
2716 RecordCompositorSlowScrollMetric(type, MAIN_THREAD); 2727 RecordCompositorSlowScrollMetric(type, MAIN_THREAD);
2717 2728
2718 scroll_status.thread = SCROLL_ON_MAIN_THREAD; 2729 scroll_status.thread = SCROLL_ON_MAIN_THREAD;
2719 return scroll_status; 2730 return scroll_status;
2720 } else if (scrolling_layer_impl) { 2731 } else if (scrolling_node) {
2721 scroll_affects_scroll_handler_ = 2732 scroll_affects_scroll_handler_ = active_tree_->have_scroll_event_handlers();
2722 scrolling_layer_impl->layer_tree_impl()->have_scroll_event_handlers();
2723 } 2733 }
2724 2734
2725 return ScrollBeginImpl(scroll_state, scrolling_layer_impl, type); 2735 return ScrollBeginImpl(scroll_state, scrolling_node, type);
2726 } 2736 }
2727 2737
2728 // Some initial scroll tests are known to be unreliable and require falling 2738 // Some initial scroll tests are known to be unreliable and require falling
2729 // back to main thread scrolling. 2739 // back to main thread scrolling.
2730 bool LayerTreeHostImpl::IsInitialScrollHitTestReliable( 2740 bool LayerTreeHostImpl::IsInitialScrollHitTestReliable(
2731 LayerImpl* layer_impl, 2741 LayerImpl* layer_impl,
2732 const gfx::PointF& device_viewport_point) { 2742 const gfx::PointF& device_viewport_point) {
2733 LayerImpl* first_scrolling_layer_or_drawn_scrollbar = 2743 LayerImpl* first_scrolling_layer_or_drawn_scrollbar =
2734 active_tree_->FindFirstScrollingLayerOrDrawnScrollbarThatIsHitByPoint( 2744 active_tree_->FindFirstScrollingLayerOrDrawnScrollbarThatIsHitByPoint(
2735 device_viewport_point); 2745 device_viewport_point);
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
3112 } 3122 }
3113 3123
3114 void LayerTreeHostImpl::DistributeScrollDelta(ScrollState* scroll_state) { 3124 void LayerTreeHostImpl::DistributeScrollDelta(ScrollState* scroll_state) {
3115 // TODO(majidvp): in Blink we compute scroll chain only at scroll begin which 3125 // TODO(majidvp): in Blink we compute scroll chain only at scroll begin which
3116 // is not the case here. We eventually want to have the same behaviour on both 3126 // is not the case here. We eventually want to have the same behaviour on both
3117 // sides but it may become a non issue if we get rid of scroll chaining (see 3127 // sides but it may become a non issue if we get rid of scroll chaining (see
3118 // crbug.com/526462) 3128 // crbug.com/526462)
3119 std::list<ScrollNode*> current_scroll_chain; 3129 std::list<ScrollNode*> current_scroll_chain;
3120 ScrollTree& scroll_tree = active_tree_->property_trees()->scroll_tree; 3130 ScrollTree& scroll_tree = active_tree_->property_trees()->scroll_tree;
3121 ScrollNode* scroll_node = scroll_tree.CurrentlyScrollingNode(); 3131 ScrollNode* scroll_node = scroll_tree.CurrentlyScrollingNode();
3122 ScrollNode* viewport_scroll_node = 3132 ScrollNode* viewport_scroll_node = OuterViewportScrollNode();
3123 viewport()->MainScrollLayer()
3124 ? scroll_tree.Node(viewport()->MainScrollLayer()->scroll_tree_index())
3125 : nullptr;
3126 if (scroll_node) { 3133 if (scroll_node) {
3127 // TODO(bokan): The loop checks for a null parent but don't we still want to 3134 // TODO(bokan): The loop checks for a null parent but don't we still want to
3128 // distribute to the root scroll node? 3135 // distribute to the root scroll node?
3129 for (; scroll_tree.parent(scroll_node); 3136 for (; scroll_tree.parent(scroll_node);
3130 scroll_node = scroll_tree.parent(scroll_node)) { 3137 scroll_node = scroll_tree.parent(scroll_node)) {
3131 if (scroll_node == viewport_scroll_node) { 3138 if (scroll_node == viewport_scroll_node) {
3132 // Don't chain scrolls past the outer viewport scroll layer. Once we 3139 // Don't chain scrolls past the outer viewport scroll layer. Once we
3133 // reach that, we should scroll the viewport which is represented by the 3140 // reach that, we should scroll the viewport which is represented by the
3134 // main viewport scroll layer. 3141 // main viewport scroll layer.
3135 DCHECK(viewport_scroll_node); 3142 DCHECK(viewport_scroll_node);
(...skipping 10 matching lines...) Expand all
3146 scroll_state->set_scroll_chain_and_layer_tree(current_scroll_chain, 3153 scroll_state->set_scroll_chain_and_layer_tree(current_scroll_chain,
3147 active_tree()); 3154 active_tree());
3148 scroll_state->DistributeToScrollChainDescendant(); 3155 scroll_state->DistributeToScrollChainDescendant();
3149 } 3156 }
3150 3157
3151 InputHandlerScrollResult LayerTreeHostImpl::ScrollBy( 3158 InputHandlerScrollResult LayerTreeHostImpl::ScrollBy(
3152 ScrollState* scroll_state) { 3159 ScrollState* scroll_state) {
3153 DCHECK(scroll_state); 3160 DCHECK(scroll_state);
3154 3161
3155 TRACE_EVENT0("cc", "LayerTreeHostImpl::ScrollBy"); 3162 TRACE_EVENT0("cc", "LayerTreeHostImpl::ScrollBy");
3156 if (!CurrentlyScrollingLayer()) 3163 if (!CurrentlyScrollingNode())
3157 return InputHandlerScrollResult(); 3164 return InputHandlerScrollResult();
3158 3165
3159 float initial_top_controls_offset = 3166 float initial_top_controls_offset =
3160 browser_controls_offset_manager_->ControlsTopOffset(); 3167 browser_controls_offset_manager_->ControlsTopOffset();
3161 3168
3162 scroll_state->set_delta_consumed_for_scroll_sequence( 3169 scroll_state->set_delta_consumed_for_scroll_sequence(
3163 did_lock_scrolling_layer_); 3170 did_lock_scrolling_layer_);
3164 scroll_state->set_is_direct_manipulation(!wheel_scrolling_); 3171 scroll_state->set_is_direct_manipulation(!wheel_scrolling_);
3165 scroll_state->set_current_native_scrolling_node( 3172 scroll_state->set_current_native_scrolling_node(
3166 active_tree()->property_trees()->scroll_tree.CurrentlyScrollingNode()); 3173 active_tree()->property_trees()->scroll_tree.CurrentlyScrollingNode());
3167 3174
3168 DistributeScrollDelta(scroll_state); 3175 DistributeScrollDelta(scroll_state);
3169 3176
3170 active_tree_->SetCurrentlyScrollingLayer(active_tree_->LayerById( 3177 active_tree_->SetCurrentlyScrollingNode(
3171 scroll_state->current_native_scrolling_node()->owning_layer_id)); 3178 scroll_state->current_native_scrolling_node());
3172 did_lock_scrolling_layer_ = 3179 did_lock_scrolling_layer_ =
3173 scroll_state->delta_consumed_for_scroll_sequence(); 3180 scroll_state->delta_consumed_for_scroll_sequence();
3174 3181
3175 bool did_scroll_x = scroll_state->caused_scroll_x(); 3182 bool did_scroll_x = scroll_state->caused_scroll_x();
3176 bool did_scroll_y = scroll_state->caused_scroll_y(); 3183 bool did_scroll_y = scroll_state->caused_scroll_y();
3177 bool did_scroll_content = did_scroll_x || did_scroll_y; 3184 bool did_scroll_content = did_scroll_x || did_scroll_y;
3178 if (did_scroll_content) { 3185 if (did_scroll_content) {
3179 // If we are scrolling with an active scroll handler, forward latency 3186 // If we are scrolling with an active scroll handler, forward latency
3180 // tracking information to the main thread so the delay introduced by the 3187 // tracking information to the main thread so the delay introduced by the
3181 // handler is accounted for. 3188 // handler is accounted for.
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
3237 return; 3244 return;
3238 3245
3239 client_->SetNeedsCommitOnImplThread(); 3246 client_->SetNeedsCommitOnImplThread();
3240 // After applying the synchronous input handler's scroll offset, tell it what 3247 // After applying the synchronous input handler's scroll offset, tell it what
3241 // we ended up with. 3248 // we ended up with.
3242 UpdateRootLayerStateForSynchronousInputHandler(); 3249 UpdateRootLayerStateForSynchronousInputHandler();
3243 SetFullViewportDamage(); 3250 SetFullViewportDamage();
3244 SetNeedsRedraw(); 3251 SetNeedsRedraw();
3245 } 3252 }
3246 3253
3247 void LayerTreeHostImpl::ClearCurrentlyScrollingLayer() { 3254 void LayerTreeHostImpl::ClearCurrentlyScrollingNode() {
3248 active_tree_->ClearCurrentlyScrollingLayer(); 3255 active_tree_->ClearCurrentlyScrollingNode();
3249 did_lock_scrolling_layer_ = false; 3256 did_lock_scrolling_layer_ = false;
3250 scroll_affects_scroll_handler_ = false; 3257 scroll_affects_scroll_handler_ = false;
3251 accumulated_root_overscroll_ = gfx::Vector2dF(); 3258 accumulated_root_overscroll_ = gfx::Vector2dF();
3252 } 3259 }
3253 3260
3254 void LayerTreeHostImpl::ScrollEnd(ScrollState* scroll_state) { 3261 void LayerTreeHostImpl::ScrollEnd(ScrollState* scroll_state) {
3255 DCHECK(scroll_state); 3262 DCHECK(scroll_state);
3256 DCHECK(scroll_state->delta_x() == 0 && scroll_state->delta_y() == 0); 3263 DCHECK(scroll_state->delta_x() == 0 && scroll_state->delta_y() == 0);
3257 3264
3258 DistributeScrollDelta(scroll_state); 3265 DistributeScrollDelta(scroll_state);
3259 browser_controls_offset_manager_->ScrollEnd(); 3266 browser_controls_offset_manager_->ScrollEnd();
3260 ClearCurrentlyScrollingLayer(); 3267 ClearCurrentlyScrollingNode();
3261 } 3268 }
3262 3269
3263 InputHandler::ScrollStatus LayerTreeHostImpl::FlingScrollBegin() { 3270 InputHandler::ScrollStatus LayerTreeHostImpl::FlingScrollBegin() {
3264 InputHandler::ScrollStatus scroll_status; 3271 InputHandler::ScrollStatus scroll_status;
3265 scroll_status.main_thread_scrolling_reasons = 3272 scroll_status.main_thread_scrolling_reasons =
3266 MainThreadScrollingReason::kNotScrollingOnMain; 3273 MainThreadScrollingReason::kNotScrollingOnMain;
3267 if (!CurrentlyScrollingLayer()) { 3274 if (!CurrentlyScrollingNode()) {
3268 scroll_status.thread = SCROLL_IGNORED; 3275 scroll_status.thread = SCROLL_IGNORED;
3269 scroll_status.main_thread_scrolling_reasons = 3276 scroll_status.main_thread_scrolling_reasons =
3270 MainThreadScrollingReason::kNoScrollingLayer; 3277 MainThreadScrollingReason::kNoScrollingLayer;
3271 } else { 3278 } else {
3272 scroll_status.thread = SCROLL_ON_IMPL_THREAD; 3279 scroll_status.thread = SCROLL_ON_IMPL_THREAD;
3273 } 3280 }
3274 return scroll_status; 3281 return scroll_status;
3275 } 3282 }
3276 3283
3277 float LayerTreeHostImpl::DeviceSpaceDistanceToLayer( 3284 float LayerTreeHostImpl::DeviceSpaceDistanceToLayer(
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
3364 3371
3365 void LayerTreeHostImpl::MouseLeave() { 3372 void LayerTreeHostImpl::MouseLeave() {
3366 for (auto& pair : scrollbar_animation_controllers_) 3373 for (auto& pair : scrollbar_animation_controllers_)
3367 pair.second->DidMouseLeave(); 3374 pair.second->DidMouseLeave();
3368 scroll_layer_id_mouse_currently_over_ = Layer::INVALID_ID; 3375 scroll_layer_id_mouse_currently_over_ = Layer::INVALID_ID;
3369 } 3376 }
3370 3377
3371 void LayerTreeHostImpl::PinchGestureBegin() { 3378 void LayerTreeHostImpl::PinchGestureBegin() {
3372 pinch_gesture_active_ = true; 3379 pinch_gesture_active_ = true;
3373 client_->RenewTreePriority(); 3380 client_->RenewTreePriority();
3374 pinch_gesture_end_should_clear_scrolling_layer_ = !CurrentlyScrollingLayer(); 3381 pinch_gesture_end_should_clear_scrolling_node_ = !CurrentlyScrollingNode();
3375 active_tree_->SetCurrentlyScrollingLayer(viewport()->MainScrollLayer()); 3382
3383 active_tree_->SetCurrentlyScrollingNode(OuterViewportScrollNode());
3376 browser_controls_offset_manager_->PinchBegin(); 3384 browser_controls_offset_manager_->PinchBegin();
3377 } 3385 }
3378 3386
3379 void LayerTreeHostImpl::PinchGestureUpdate(float magnify_delta, 3387 void LayerTreeHostImpl::PinchGestureUpdate(float magnify_delta,
3380 const gfx::Point& anchor) { 3388 const gfx::Point& anchor) {
3381 TRACE_EVENT0("cc", "LayerTreeHostImpl::PinchGestureUpdate"); 3389 TRACE_EVENT0("cc", "LayerTreeHostImpl::PinchGestureUpdate");
3382 if (!InnerViewportScrollLayer()) 3390 if (!InnerViewportScrollLayer())
3383 return; 3391 return;
3384 viewport()->PinchUpdate(magnify_delta, anchor); 3392 viewport()->PinchUpdate(magnify_delta, anchor);
3385 client_->SetNeedsCommitOnImplThread(); 3393 client_->SetNeedsCommitOnImplThread();
3386 SetNeedsRedraw(); 3394 SetNeedsRedraw();
3387 client_->RenewTreePriority(); 3395 client_->RenewTreePriority();
3388 // Pinching can change the root scroll offset, so inform the synchronous input 3396 // Pinching can change the root scroll offset, so inform the synchronous input
3389 // handler. 3397 // handler.
3390 UpdateRootLayerStateForSynchronousInputHandler(); 3398 UpdateRootLayerStateForSynchronousInputHandler();
3391 } 3399 }
3392 3400
3393 void LayerTreeHostImpl::PinchGestureEnd() { 3401 void LayerTreeHostImpl::PinchGestureEnd() {
3394 pinch_gesture_active_ = false; 3402 pinch_gesture_active_ = false;
3395 if (pinch_gesture_end_should_clear_scrolling_layer_) { 3403 if (pinch_gesture_end_should_clear_scrolling_node_) {
3396 pinch_gesture_end_should_clear_scrolling_layer_ = false; 3404 pinch_gesture_end_should_clear_scrolling_node_ = false;
3397 ClearCurrentlyScrollingLayer(); 3405 ClearCurrentlyScrollingNode();
3398 } 3406 }
3399 viewport()->PinchEnd(); 3407 viewport()->PinchEnd();
3400 browser_controls_offset_manager_->PinchEnd(); 3408 browser_controls_offset_manager_->PinchEnd();
3401 client_->SetNeedsCommitOnImplThread(); 3409 client_->SetNeedsCommitOnImplThread();
3402 // When a pinch ends, we may be displaying content cached at incorrect scales, 3410 // When a pinch ends, we may be displaying content cached at incorrect scales,
3403 // so updating draw properties and drawing will ensure we are using the right 3411 // so updating draw properties and drawing will ensure we are using the right
3404 // scales that we want when we're not inside a pinch. 3412 // scales that we want when we're not inside a pinch.
3405 active_tree_->set_needs_update_draw_properties(); 3413 active_tree_->set_needs_update_draw_properties();
3406 SetNeedsRedraw(); 3414 SetNeedsRedraw();
3407 } 3415 }
(...skipping 743 matching lines...) Expand 10 before | Expand all | Expand 10 after
4151 worker_context_visibility_ = 4159 worker_context_visibility_ =
4152 worker_context->CacheController()->ClientBecameVisible(); 4160 worker_context->CacheController()->ClientBecameVisible();
4153 } else { 4161 } else {
4154 worker_context->CacheController()->ClientBecameNotVisible( 4162 worker_context->CacheController()->ClientBecameNotVisible(
4155 std::move(worker_context_visibility_)); 4163 std::move(worker_context_visibility_));
4156 } 4164 }
4157 } 4165 }
4158 } 4166 }
4159 4167
4160 } // namespace cc 4168 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_impl.h ('k') | cc/trees/layer_tree_host_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698