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

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

Issue 2621133002: Return main thread scroll layer in FindScrollLayerForDeviceViewportPoint (Closed)
Patch Set: add test Created 3 years, 11 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 558 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 569
570 LayerImpl* layer_impl = 570 LayerImpl* layer_impl =
571 active_tree_->FindLayerThatIsHitByPoint(device_viewport_point); 571 active_tree_->FindLayerThatIsHitByPoint(device_viewport_point);
572 572
573 bool scroll_on_main_thread = false; 573 bool scroll_on_main_thread = false;
574 uint32_t main_thread_scrolling_reasons; 574 uint32_t main_thread_scrolling_reasons;
575 LayerImpl* test_layer_impl = FindScrollLayerForDeviceViewportPoint( 575 LayerImpl* test_layer_impl = FindScrollLayerForDeviceViewportPoint(
576 device_viewport_point, type, layer_impl, &scroll_on_main_thread, 576 device_viewport_point, type, layer_impl, &scroll_on_main_thread,
577 &main_thread_scrolling_reasons); 577 &main_thread_scrolling_reasons);
578 578
579 if (!test_layer_impl) 579 if (scroll_on_main_thread)
580 return false; 580 return false;
581 581
582 if (scrolling_layer_impl == test_layer_impl) 582 if (scrolling_layer_impl == test_layer_impl)
583 return true; 583 return true;
584 584
585 // For active scrolling state treat the inner/outer viewports interchangeably. 585 // For active scrolling state treat the inner/outer viewports interchangeably.
586 if (scrolling_layer_impl == InnerViewportScrollLayer() || 586 if (scrolling_layer_impl == InnerViewportScrollLayer() ||
587 scrolling_layer_impl == OuterViewportScrollLayer()) { 587 scrolling_layer_impl == OuterViewportScrollLayer()) {
588 return test_layer_impl == viewport()->MainScrollLayer(); 588 return test_layer_impl == viewport()->MainScrollLayer();
589 } 589 }
(...skipping 1058 matching lines...) Expand 10 before | Expand all | Expand 10 after
1648 1648
1649 // Collect all resource ids in the render passes into a single array. 1649 // Collect all resource ids in the render passes into a single array.
1650 ResourceProvider::ResourceIdArray resources; 1650 ResourceProvider::ResourceIdArray resources;
1651 for (const auto& render_pass : frame->render_passes) { 1651 for (const auto& render_pass : frame->render_passes) {
1652 for (auto* quad : render_pass->quad_list) { 1652 for (auto* quad : render_pass->quad_list) {
1653 for (ResourceId resource_id : quad->resources) 1653 for (ResourceId resource_id : quad->resources)
1654 resources.push_back(resource_id); 1654 resources.push_back(resource_id);
1655 } 1655 }
1656 } 1656 }
1657 1657
1658
1659 CompositorFrame compositor_frame; 1658 CompositorFrame compositor_frame;
1660 compositor_frame.metadata = std::move(metadata); 1659 compositor_frame.metadata = std::move(metadata);
1661 resource_provider_->PrepareSendToParent(resources, 1660 resource_provider_->PrepareSendToParent(resources,
1662 &compositor_frame.resource_list); 1661 &compositor_frame.resource_list);
1663 compositor_frame.render_pass_list = std::move(frame->render_passes); 1662 compositor_frame.render_pass_list = std::move(frame->render_passes);
1664 compositor_frame_sink_->SubmitCompositorFrame(std::move(compositor_frame)); 1663 compositor_frame_sink_->SubmitCompositorFrame(std::move(compositor_frame));
1665 1664
1666 // Clears the list of swap promises after calling DidSwap on each of them to 1665 // Clears the list of swap promises after calling DidSwap on each of them to
1667 // signal that the swap is over. 1666 // signal that the swap is over.
1668 active_tree()->ClearSwapPromises(); 1667 active_tree()->ClearSwapPromises();
(...skipping 849 matching lines...) Expand 10 before | Expand all | Expand 10 after
2518 LayerImpl* layer_impl, 2517 LayerImpl* layer_impl,
2519 bool* scroll_on_main_thread, 2518 bool* scroll_on_main_thread,
2520 uint32_t* main_thread_scrolling_reasons) const { 2519 uint32_t* main_thread_scrolling_reasons) const {
2521 DCHECK(scroll_on_main_thread); 2520 DCHECK(scroll_on_main_thread);
2522 DCHECK(main_thread_scrolling_reasons); 2521 DCHECK(main_thread_scrolling_reasons);
2523 *main_thread_scrolling_reasons = 2522 *main_thread_scrolling_reasons =
2524 MainThreadScrollingReason::kNotScrollingOnMain; 2523 MainThreadScrollingReason::kNotScrollingOnMain;
2525 2524
2526 // Walk up the hierarchy and look for a scrollable layer. 2525 // Walk up the hierarchy and look for a scrollable layer.
2527 ScrollTree& scroll_tree = active_tree_->property_trees()->scroll_tree; 2526 ScrollTree& scroll_tree = active_tree_->property_trees()->scroll_tree;
2528 LayerImpl* potentially_scrolling_layer_impl = NULL; 2527 LayerImpl* potentially_scrolling_layer_impl = nullptr;
2529 if (layer_impl) { 2528 if (layer_impl) {
2530 ScrollNode* scroll_node = scroll_tree.Node(layer_impl->scroll_tree_index()); 2529 ScrollNode* scroll_node = scroll_tree.Node(layer_impl->scroll_tree_index());
2531 for (; scroll_tree.parent(scroll_node); 2530 for (; scroll_tree.parent(scroll_node);
2532 scroll_node = scroll_tree.parent(scroll_node)) { 2531 scroll_node = scroll_tree.parent(scroll_node)) {
2533 // The content layer can also block attempts to scroll outside the main 2532 // The content layer can also block attempts to scroll outside the main
2534 // thread. 2533 // thread.
2535 ScrollStatus status = 2534 ScrollStatus status =
2536 TryScroll(device_viewport_point, type, scroll_tree, scroll_node); 2535 TryScroll(device_viewport_point, type, scroll_tree, scroll_node);
2537 if (IsMainThreadScrolling(status, scroll_node)) { 2536 if (IsMainThreadScrolling(status, scroll_node)) {
2538 *scroll_on_main_thread = true; 2537 *scroll_on_main_thread = true;
2539 *main_thread_scrolling_reasons = status.main_thread_scrolling_reasons; 2538 *main_thread_scrolling_reasons = status.main_thread_scrolling_reasons;
2540 return NULL; 2539 return potentially_scrolling_layer_impl
2540 ? potentially_scrolling_layer_impl
2541 : active_tree_->LayerById(scroll_node->owning_layer_id);
2541 } 2542 }
2542 2543
2543 if (status.thread == InputHandler::SCROLL_ON_IMPL_THREAD && 2544 if (status.thread == InputHandler::SCROLL_ON_IMPL_THREAD &&
2544 !potentially_scrolling_layer_impl) { 2545 !potentially_scrolling_layer_impl) {
2545 potentially_scrolling_layer_impl = 2546 potentially_scrolling_layer_impl =
2546 active_tree_->LayerById(scroll_node->owning_layer_id); 2547 active_tree_->LayerById(scroll_node->owning_layer_id);
2547 } 2548 }
2548 } 2549 }
2549 } 2550 }
2550 2551
2551 // Falling back to the viewport layer ensures generation of root overscroll 2552 // Falling back to the viewport layer ensures generation of root overscroll
2552 // notifications. We use the viewport's main scroll layer to represent the 2553 // notifications. We use the viewport's main scroll layer to represent the
2553 // viewport in scrolling code. 2554 // viewport in scrolling code.
2554 if (!potentially_scrolling_layer_impl || 2555 if (!potentially_scrolling_layer_impl ||
2555 potentially_scrolling_layer_impl == OuterViewportScrollLayer() || 2556 potentially_scrolling_layer_impl == OuterViewportScrollLayer() ||
2556 potentially_scrolling_layer_impl == InnerViewportScrollLayer()) { 2557 potentially_scrolling_layer_impl == InnerViewportScrollLayer()) {
2557 potentially_scrolling_layer_impl = viewport()->MainScrollLayer(); 2558 potentially_scrolling_layer_impl = viewport()->MainScrollLayer();
2558 } 2559 }
2559 2560
2560 if (potentially_scrolling_layer_impl) { 2561 if (potentially_scrolling_layer_impl) {
2561 // Ensure that final layer scrolls on impl thread (crbug.com/625100) 2562 // Ensure that final layer scrolls on impl thread (crbug.com/625100)
2562 ScrollNode* scroll_node = 2563 ScrollNode* scroll_node =
2563 scroll_tree.Node(potentially_scrolling_layer_impl->scroll_tree_index()); 2564 scroll_tree.Node(potentially_scrolling_layer_impl->scroll_tree_index());
2564 ScrollStatus status = 2565 ScrollStatus status =
2565 TryScroll(device_viewport_point, type, scroll_tree, scroll_node); 2566 TryScroll(device_viewport_point, type, scroll_tree, scroll_node);
2566 if (IsMainThreadScrolling(status, scroll_node)) { 2567 if (IsMainThreadScrolling(status, scroll_node)) {
2567 *scroll_on_main_thread = true; 2568 *scroll_on_main_thread = true;
2568 *main_thread_scrolling_reasons = status.main_thread_scrolling_reasons; 2569 *main_thread_scrolling_reasons = status.main_thread_scrolling_reasons;
2569 return NULL;
2570 } 2570 }
2571 } 2571 }
2572 2572
2573 return potentially_scrolling_layer_impl; 2573 return potentially_scrolling_layer_impl;
2574 } 2574 }
2575 2575
2576 static bool IsClosestScrollAncestor(LayerImpl* child, 2576 static bool IsClosestScrollAncestor(LayerImpl* child,
2577 LayerImpl* scroll_ancestor) { 2577 LayerImpl* scroll_ancestor) {
2578 DCHECK(scroll_ancestor); 2578 DCHECK(scroll_ancestor);
2579 if (!child) 2579 if (!child)
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
2671 scroll_status.main_thread_scrolling_reasons = 2671 scroll_status.main_thread_scrolling_reasons =
2672 MainThreadScrollingReason::kFailedHitTest; 2672 MainThreadScrollingReason::kFailedHitTest;
2673 return scroll_status; 2673 return scroll_status;
2674 } 2674 }
2675 } 2675 }
2676 2676
2677 scrolling_layer_impl = FindScrollLayerForDeviceViewportPoint( 2677 scrolling_layer_impl = FindScrollLayerForDeviceViewportPoint(
2678 device_viewport_point, type, layer_impl, &scroll_on_main_thread, 2678 device_viewport_point, type, layer_impl, &scroll_on_main_thread,
2679 &scroll_status.main_thread_scrolling_reasons); 2679 &scroll_status.main_thread_scrolling_reasons);
2680 } 2680 }
2681 if (scrolling_layer_impl)
2682 scroll_affects_scroll_handler_ =
2683 scrolling_layer_impl->layer_tree_impl()->have_scroll_event_handlers();
2684 2681
2685 if (scroll_on_main_thread) { 2682 if (scroll_on_main_thread) {
2686 RecordCompositorSlowScrollMetric(type, MAIN_THREAD); 2683 RecordCompositorSlowScrollMetric(type, MAIN_THREAD);
2687 2684
2688 scroll_status.thread = SCROLL_ON_MAIN_THREAD; 2685 scroll_status.thread = SCROLL_ON_MAIN_THREAD;
2689 return scroll_status; 2686 return scroll_status;
2687 } else if (scrolling_layer_impl) {
2688 scroll_affects_scroll_handler_ =
2689 scrolling_layer_impl->layer_tree_impl()->have_scroll_event_handlers();
2690 } 2690 }
2691 2691
2692 return ScrollBeginImpl(scroll_state, scrolling_layer_impl, type); 2692 return ScrollBeginImpl(scroll_state, scrolling_layer_impl, type);
2693 } 2693 }
2694 2694
2695 InputHandler::ScrollStatus LayerTreeHostImpl::ScrollAnimatedBegin( 2695 InputHandler::ScrollStatus LayerTreeHostImpl::ScrollAnimatedBegin(
2696 const gfx::Point& viewport_point) { 2696 const gfx::Point& viewport_point) {
2697 InputHandler::ScrollStatus scroll_status; 2697 InputHandler::ScrollStatus scroll_status;
2698 scroll_status.main_thread_scrolling_reasons = 2698 scroll_status.main_thread_scrolling_reasons =
2699 MainThreadScrollingReason::kNotScrollingOnMain; 2699 MainThreadScrollingReason::kNotScrollingOnMain;
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after
3235 void LayerTreeHostImpl::MouseMoveAt(const gfx::Point& viewport_point) { 3235 void LayerTreeHostImpl::MouseMoveAt(const gfx::Point& viewport_point) {
3236 float distance_to_scrollbar = std::numeric_limits<float>::max(); 3236 float distance_to_scrollbar = std::numeric_limits<float>::max();
3237 gfx::PointF device_viewport_point = gfx::ScalePoint( 3237 gfx::PointF device_viewport_point = gfx::ScalePoint(
3238 gfx::PointF(viewport_point), active_tree_->device_scale_factor()); 3238 gfx::PointF(viewport_point), active_tree_->device_scale_factor());
3239 LayerImpl* layer_impl = 3239 LayerImpl* layer_impl =
3240 active_tree_->FindLayerThatIsHitByPoint(device_viewport_point); 3240 active_tree_->FindLayerThatIsHitByPoint(device_viewport_point);
3241 3241
3242 // Check if mouse is over a scrollbar or not. 3242 // Check if mouse is over a scrollbar or not.
3243 // TODO(sahel): get rid of this extera checking when 3243 // TODO(sahel): get rid of this extera checking when
3244 // FindScrollLayerForDeviceViewportPoint finds the proper layer for 3244 // FindScrollLayerForDeviceViewportPoint finds the proper layer for
3245 // scrolling on main thread, as well. 3245 // scrolling on main thread when mouse over scrollbar as well.
bokan 2017/01/13 19:23:38 nit: when mouse *is* over scrollbar.
3246 int new_id = Layer::INVALID_ID; 3246 int new_id = Layer::INVALID_ID;
3247 if (layer_impl && layer_impl->ToScrollbarLayer()) 3247 if (layer_impl && layer_impl->ToScrollbarLayer())
3248 new_id = layer_impl->ToScrollbarLayer()->ScrollLayerId(); 3248 new_id = layer_impl->ToScrollbarLayer()->ScrollLayerId();
3249 if (new_id != Layer::INVALID_ID) { 3249 if (new_id != Layer::INVALID_ID) {
3250 // Mouse over a scrollbar. 3250 // Mouse over a scrollbar.
3251 distance_to_scrollbar = 0; 3251 distance_to_scrollbar = 0;
3252 } else { 3252 } else {
3253 bool scroll_on_main_thread = false; 3253 bool scroll_on_main_thread = false;
3254 uint32_t main_thread_scrolling_reasons; 3254 uint32_t main_thread_scrolling_reasons;
3255 LayerImpl* scroll_layer_impl = FindScrollLayerForDeviceViewportPoint( 3255 LayerImpl* scroll_layer_impl = FindScrollLayerForDeviceViewportPoint(
(...skipping 829 matching lines...) Expand 10 before | Expand all | Expand 10 after
4085 worker_context_visibility_ = 4085 worker_context_visibility_ =
4086 worker_context->CacheController()->ClientBecameVisible(); 4086 worker_context->CacheController()->ClientBecameVisible();
4087 } else { 4087 } else {
4088 worker_context->CacheController()->ClientBecameNotVisible( 4088 worker_context->CacheController()->ClientBecameNotVisible(
4089 std::move(worker_context_visibility_)); 4089 std::move(worker_context_visibility_));
4090 } 4090 }
4091 } 4091 }
4092 } 4092 }
4093 4093
4094 } // namespace cc 4094 } // namespace cc
OLDNEW
« no previous file with comments | « no previous file | cc/trees/layer_tree_host_impl_unittest.cc » ('j') | cc/trees/layer_tree_host_impl_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698