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

Unified Diff: cc/trees/layer_tree_host_impl.cc

Issue 2720183003: Track the currently scrolling ScrollNode instead of the scrolling layer (Closed)
Patch Set: Rebase Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: cc/trees/layer_tree_host_impl.cc
diff --git a/cc/trees/layer_tree_host_impl.cc b/cc/trees/layer_tree_host_impl.cc
index f99af61cec2f13da73bae0bf17244f7fe536c3cf..ff729139078af44f91438d20ccebefdad183f67f 100644
--- a/cc/trees/layer_tree_host_impl.cc
+++ b/cc/trees/layer_tree_host_impl.cc
@@ -154,23 +154,6 @@ void RecordCompositorSlowScrollMetric(InputHandler::ScrollInputType type,
}
}
-// Return true if scrollable node for 'ancestor' is the same as 'child' or an
-// ancestor along the scroll tree.
-bool IsScrolledBy(LayerImpl* child, LayerImpl* ancestor) {
- DCHECK(ancestor && ancestor->scrollable());
- if (!child)
- return false;
-
- auto* property_trees = child->layer_tree_impl()->property_trees();
- ScrollTree& scroll_tree = property_trees->scroll_tree;
- for (ScrollNode* scroll_node = scroll_tree.Node(child->scroll_tree_index());
- scroll_node; scroll_node = scroll_tree.parent(scroll_node)) {
- if (scroll_node->id == ancestor->scroll_tree_index())
- return true;
- }
- return false;
-}
-
} // namespace
DEFINE_SCOPED_UMA_HISTOGRAM_TIMER(PendingTreeDurationHistogramTimer,
@@ -239,7 +222,7 @@ LayerTreeHostImpl::LayerTreeHostImpl(
: settings.scheduled_raster_task_limit,
settings.ToTileManagerSettings()),
pinch_gesture_active_(false),
- pinch_gesture_end_should_clear_scrolling_layer_(false),
+ pinch_gesture_end_should_clear_scrolling_node_(false),
fps_counter_(
FrameRateCounter::Create(task_runner_provider_->HasImplThread())),
memory_history_(MemoryHistory::Create()),
@@ -565,18 +548,18 @@ void LayerTreeHostImpl::SetNeedsAnimateInput() {
}
bool LayerTreeHostImpl::IsCurrentlyScrollingViewport() const {
- LayerImpl* scrolling_layer = CurrentlyScrollingLayer();
- if (!scrolling_layer)
+ auto* node = CurrentlyScrollingNode();
+ if (!node)
return false;
DCHECK(viewport());
- return scrolling_layer == viewport()->MainScrollLayer();
+ return node->id == viewport()->MainScrollLayer()->scroll_tree_index();
}
bool LayerTreeHostImpl::IsCurrentlyScrollingLayerAt(
const gfx::Point& viewport_point,
InputHandler::ScrollInputType type) const {
- LayerImpl* scrolling_layer_impl = CurrentlyScrollingLayer();
- if (!scrolling_layer_impl)
+ auto* scrolling_node = CurrentlyScrollingNode();
+ if (!scrolling_node)
return false;
gfx::PointF device_viewport_point = gfx::ScalePoint(
@@ -594,12 +577,13 @@ bool LayerTreeHostImpl::IsCurrentlyScrollingLayerAt(
if (scroll_on_main_thread)
return false;
- if (scrolling_layer_impl == test_layer_impl)
+ int test_scroll_tree_index = test_layer_impl->scroll_tree_index();
+ if (scrolling_node->id == test_scroll_tree_index)
return true;
// For active scrolling state treat the inner/outer viewports interchangeably.
- if (scrolling_layer_impl == InnerViewportScrollLayer() ||
- scrolling_layer_impl == OuterViewportScrollLayer()) {
+ if (scrolling_node->scrolls_inner_viewport ||
+ scrolling_node->scrolls_outer_viewport) {
return test_layer_impl == viewport()->MainScrollLayer();
}
@@ -611,6 +595,23 @@ EventListenerProperties LayerTreeHostImpl::GetEventListenerProperties(
return active_tree_->event_listener_properties(event_class);
}
+// Return true if scrollable node for 'ancestor' is the same as 'child' or an
+// ancestor along the scroll tree.
+bool IsScrolledBy(LayerImpl* child, ScrollNode* ancestor) {
+ DCHECK(ancestor && ancestor->scrollable);
+ if (!child)
+ return false;
+
+ auto* property_trees = child->layer_tree_impl()->property_trees();
+ ScrollTree& scroll_tree = property_trees->scroll_tree;
+ for (ScrollNode* scroll_node = scroll_tree.Node(child->scroll_tree_index());
+ scroll_node; scroll_node = scroll_tree.parent(scroll_node)) {
+ if (scroll_node->id == ancestor->id)
+ return true;
+ }
+ return false;
+}
+
InputHandler::TouchStartEventListenerType
LayerTreeHostImpl::EventListenerTypeForTouchStartAt(
const gfx::Point& viewport_point) {
@@ -625,11 +626,10 @@ LayerTreeHostImpl::EventListenerTypeForTouchStartAt(
if (layer_impl == NULL)
return InputHandler::TouchStartEventListenerType::NO_HANDLER;
- if (!CurrentlyScrollingLayer())
+ if (!CurrentlyScrollingNode())
return InputHandler::TouchStartEventListenerType::HANDLER;
- bool is_ancestor =
- IsScrolledBy(layer_impl, active_tree_->CurrentlyScrollingLayer());
+ bool is_ancestor = IsScrolledBy(layer_impl, CurrentlyScrollingNode());
return is_ancestor ? InputHandler::TouchStartEventListenerType::
HANDLER_ON_SCROLLING_LAYER
: InputHandler::TouchStartEventListenerType::HANDLER;
@@ -1961,12 +1961,16 @@ LayerImpl* LayerTreeHostImpl::OuterViewportScrollLayer() const {
return active_tree_->OuterViewportScrollLayer();
}
-LayerImpl* LayerTreeHostImpl::CurrentlyScrollingLayer() const {
- return active_tree_->CurrentlyScrollingLayer();
+ScrollNode* LayerTreeHostImpl::CurrentlyScrollingNode() {
+ return active_tree()->CurrentlyScrollingNode();
+}
+
+const ScrollNode* LayerTreeHostImpl::CurrentlyScrollingNode() const {
+ return active_tree()->CurrentlyScrollingNode();
}
bool LayerTreeHostImpl::IsActivelyScrolling() const {
- if (!CurrentlyScrollingLayer())
+ if (!CurrentlyScrollingNode())
return false;
// On Android WebView root flings are controlled by the application,
// so the compositor does not animate them and can't tell if they
@@ -2626,7 +2630,7 @@ LayerImpl* LayerTreeHostImpl::FindScrollLayerForDeviceViewportPoint(
InputHandler::ScrollStatus LayerTreeHostImpl::ScrollBeginImpl(
ScrollState* scroll_state,
- LayerImpl* scrolling_layer_impl,
+ ScrollNode* scrolling_node,
InputHandler::ScrollInputType type) {
DCHECK(scroll_state);
DCHECK(scroll_state->delta_x() == 0 && scroll_state->delta_y() == 0);
@@ -2634,7 +2638,7 @@ InputHandler::ScrollStatus LayerTreeHostImpl::ScrollBeginImpl(
InputHandler::ScrollStatus scroll_status;
scroll_status.main_thread_scrolling_reasons =
MainThreadScrollingReason::kNotScrollingOnMain;
- if (!scrolling_layer_impl) {
+ if (!scrolling_node) {
scroll_status.thread = SCROLL_IGNORED;
scroll_status.main_thread_scrolling_reasons =
MainThreadScrollingReason::kNoScrollingLayer;
@@ -2645,7 +2649,7 @@ InputHandler::ScrollStatus LayerTreeHostImpl::ScrollBeginImpl(
browser_controls_offset_manager_->ScrollBegin();
- active_tree_->SetCurrentlyScrollingLayer(scrolling_layer_impl);
+ active_tree_->SetCurrentlyScrollingNode(scrolling_node);
// TODO(majidvp): get rid of wheel_scrolling_ and set is_direct_manipulation
// in input_handler_proxy instead.
wheel_scrolling_ = IsWheelBasedScroll(type);
@@ -2665,10 +2669,15 @@ InputHandler::ScrollStatus LayerTreeHostImpl::RootScrollBegin(
InputHandler::ScrollInputType type) {
TRACE_EVENT0("cc", "LayerTreeHostImpl::RootScrollBegin");
- ClearCurrentlyScrollingLayer();
+ ClearCurrentlyScrollingNode();
DCHECK(viewport());
- return ScrollBeginImpl(scroll_state, viewport()->MainScrollLayer(), type);
+ ScrollTree& scroll_tree = active_tree_->property_trees()->scroll_tree;
+ ScrollNode* viewport_scroll_node =
+ viewport()->MainScrollLayer()
ajuma 2017/02/28 22:59:37 Can MainScrollLayer() be null here? The code added
pdr. 2017/03/01 07:21:03 I confirmed that MainScrollLayer can be null in te
+ ? scroll_tree.Node(viewport()->MainScrollLayer()->scroll_tree_index())
+ : nullptr;
+ return ScrollBeginImpl(scroll_state, viewport_scroll_node, type);
}
InputHandler::ScrollStatus LayerTreeHostImpl::ScrollBegin(
@@ -2679,14 +2688,14 @@ InputHandler::ScrollStatus LayerTreeHostImpl::ScrollBegin(
MainThreadScrollingReason::kNotScrollingOnMain;
TRACE_EVENT0("cc", "LayerTreeHostImpl::ScrollBegin");
- LayerImpl* scrolling_layer_impl = nullptr;
+ ScrollNode* scrolling_node = nullptr;
bool scroll_on_main_thread = false;
if (scroll_state->is_in_inertial_phase())
- scrolling_layer_impl = CurrentlyScrollingLayer();
+ scrolling_node = CurrentlyScrollingNode();
- if (!scrolling_layer_impl) {
- ClearCurrentlyScrollingLayer();
+ if (!scrolling_node) {
+ ClearCurrentlyScrollingNode();
gfx::Point viewport_point(scroll_state->position_x(),
scroll_state->position_y());
@@ -2705,9 +2714,13 @@ InputHandler::ScrollStatus LayerTreeHostImpl::ScrollBegin(
}
}
- scrolling_layer_impl = FindScrollLayerForDeviceViewportPoint(
+ auto* scrolling_layer = FindScrollLayerForDeviceViewportPoint(
device_viewport_point, type, layer_impl, &scroll_on_main_thread,
&scroll_status.main_thread_scrolling_reasons);
+ ScrollTree& scroll_tree = active_tree_->property_trees()->scroll_tree;
+ scrolling_node =
+ scrolling_layer ? scroll_tree.Node(scrolling_layer->scroll_tree_index())
+ : nullptr;
}
if (scroll_on_main_thread) {
@@ -2715,12 +2728,11 @@ InputHandler::ScrollStatus LayerTreeHostImpl::ScrollBegin(
scroll_status.thread = SCROLL_ON_MAIN_THREAD;
return scroll_status;
- } else if (scrolling_layer_impl) {
- scroll_affects_scroll_handler_ =
- scrolling_layer_impl->layer_tree_impl()->have_scroll_event_handlers();
+ } else if (scrolling_node) {
+ scroll_affects_scroll_handler_ = active_tree_->have_scroll_event_handlers();
}
- return ScrollBeginImpl(scroll_state, scrolling_layer_impl, type);
+ return ScrollBeginImpl(scroll_state, scrolling_node, type);
}
// Some initial scroll tests are known to be unreliable and require falling
@@ -3151,7 +3163,7 @@ InputHandlerScrollResult LayerTreeHostImpl::ScrollBy(
DCHECK(scroll_state);
TRACE_EVENT0("cc", "LayerTreeHostImpl::ScrollBy");
- if (!CurrentlyScrollingLayer())
+ if (!CurrentlyScrollingNode())
return InputHandlerScrollResult();
float initial_top_controls_offset =
@@ -3165,8 +3177,8 @@ InputHandlerScrollResult LayerTreeHostImpl::ScrollBy(
DistributeScrollDelta(scroll_state);
- active_tree_->SetCurrentlyScrollingLayer(active_tree_->LayerById(
- scroll_state->current_native_scrolling_node()->owning_layer_id));
+ active_tree_->SetCurrentlyScrollingNode(
+ scroll_state->current_native_scrolling_node());
did_lock_scrolling_layer_ =
scroll_state->delta_consumed_for_scroll_sequence();
@@ -3242,8 +3254,8 @@ void LayerTreeHostImpl::SetSynchronousInputHandlerRootScrollOffset(
SetNeedsRedraw();
}
-void LayerTreeHostImpl::ClearCurrentlyScrollingLayer() {
- active_tree_->ClearCurrentlyScrollingLayer();
+void LayerTreeHostImpl::ClearCurrentlyScrollingNode() {
+ active_tree_->ClearCurrentlyScrollingNode();
did_lock_scrolling_layer_ = false;
scroll_affects_scroll_handler_ = false;
accumulated_root_overscroll_ = gfx::Vector2dF();
@@ -3255,14 +3267,14 @@ void LayerTreeHostImpl::ScrollEnd(ScrollState* scroll_state) {
DistributeScrollDelta(scroll_state);
browser_controls_offset_manager_->ScrollEnd();
- ClearCurrentlyScrollingLayer();
+ ClearCurrentlyScrollingNode();
}
InputHandler::ScrollStatus LayerTreeHostImpl::FlingScrollBegin() {
InputHandler::ScrollStatus scroll_status;
scroll_status.main_thread_scrolling_reasons =
MainThreadScrollingReason::kNotScrollingOnMain;
- if (!CurrentlyScrollingLayer()) {
+ if (!CurrentlyScrollingNode()) {
scroll_status.thread = SCROLL_IGNORED;
scroll_status.main_thread_scrolling_reasons =
MainThreadScrollingReason::kNoScrollingLayer;
@@ -3369,8 +3381,15 @@ void LayerTreeHostImpl::MouseLeave() {
void LayerTreeHostImpl::PinchGestureBegin() {
pinch_gesture_active_ = true;
client_->RenewTreePriority();
- pinch_gesture_end_should_clear_scrolling_layer_ = !CurrentlyScrollingLayer();
- active_tree_->SetCurrentlyScrollingLayer(viewport()->MainScrollLayer());
+ pinch_gesture_end_should_clear_scrolling_node_ = !CurrentlyScrollingNode();
+
+ DCHECK(viewport());
+ ScrollTree& scroll_tree = active_tree_->property_trees()->scroll_tree;
+ ScrollNode* viewport_scroll_node =
+ viewport()->MainScrollLayer()
+ ? scroll_tree.Node(viewport()->MainScrollLayer()->scroll_tree_index())
+ : nullptr;
+ active_tree_->SetCurrentlyScrollingNode(viewport_scroll_node);
browser_controls_offset_manager_->PinchBegin();
}
@@ -3390,9 +3409,9 @@ void LayerTreeHostImpl::PinchGestureUpdate(float magnify_delta,
void LayerTreeHostImpl::PinchGestureEnd() {
pinch_gesture_active_ = false;
- if (pinch_gesture_end_should_clear_scrolling_layer_) {
- pinch_gesture_end_should_clear_scrolling_layer_ = false;
- ClearCurrentlyScrollingLayer();
+ if (pinch_gesture_end_should_clear_scrolling_node_) {
+ pinch_gesture_end_should_clear_scrolling_node_ = false;
+ ClearCurrentlyScrollingNode();
}
viewport()->PinchEnd();
browser_controls_offset_manager_->PinchEnd();

Powered by Google App Engine
This is Rietveld 408576698