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

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

Issue 1689293002: cc: Move TryScroll from LayerImpl to LayerTreeHostImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge with master and fix unit test failures. Created 4 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 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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 #include "cc/trees/damage_tracker.h" 78 #include "cc/trees/damage_tracker.h"
79 #include "cc/trees/draw_property_utils.h" 79 #include "cc/trees/draw_property_utils.h"
80 #include "cc/trees/latency_info_swap_promise_monitor.h" 80 #include "cc/trees/latency_info_swap_promise_monitor.h"
81 #include "cc/trees/layer_tree_host.h" 81 #include "cc/trees/layer_tree_host.h"
82 #include "cc/trees/layer_tree_host_common.h" 82 #include "cc/trees/layer_tree_host_common.h"
83 #include "cc/trees/layer_tree_impl.h" 83 #include "cc/trees/layer_tree_impl.h"
84 #include "cc/trees/single_thread_proxy.h" 84 #include "cc/trees/single_thread_proxy.h"
85 #include "cc/trees/tree_synchronizer.h" 85 #include "cc/trees/tree_synchronizer.h"
86 #include "gpu/GLES2/gl2extchromium.h" 86 #include "gpu/GLES2/gl2extchromium.h"
87 #include "gpu/command_buffer/client/gles2_interface.h" 87 #include "gpu/command_buffer/client/gles2_interface.h"
88 #include "ui/gfx/geometry/point_conversions.h"
88 #include "ui/gfx/geometry/rect_conversions.h" 89 #include "ui/gfx/geometry/rect_conversions.h"
89 #include "ui/gfx/geometry/scroll_offset.h" 90 #include "ui/gfx/geometry/scroll_offset.h"
90 #include "ui/gfx/geometry/size_conversions.h" 91 #include "ui/gfx/geometry/size_conversions.h"
91 #include "ui/gfx/geometry/vector2d_conversions.h" 92 #include "ui/gfx/geometry/vector2d_conversions.h"
92 93
93 namespace cc { 94 namespace cc {
94 namespace { 95 namespace {
95 96
96 // Small helper class that saves the current viewport location as the user sees 97 // Small helper class that saves the current viewport location as the user sees
97 // it and resets to the same location. 98 // it and resets to the same location.
(...skipping 2312 matching lines...) Expand 10 before | Expand all | Expand 10 after
2410 2411
2411 float LayerTreeHostImpl::CurrentTopControlsShownRatio() const { 2412 float LayerTreeHostImpl::CurrentTopControlsShownRatio() const {
2412 return active_tree_->CurrentTopControlsShownRatio(); 2413 return active_tree_->CurrentTopControlsShownRatio();
2413 } 2414 }
2414 2415
2415 void LayerTreeHostImpl::BindToClient(InputHandlerClient* client) { 2416 void LayerTreeHostImpl::BindToClient(InputHandlerClient* client) {
2416 DCHECK(input_handler_client_ == NULL); 2417 DCHECK(input_handler_client_ == NULL);
2417 input_handler_client_ = client; 2418 input_handler_client_ = client;
2418 } 2419 }
2419 2420
2421 InputHandler::ScrollStatus LayerTreeHostImpl::TryScroll(
2422 const gfx::PointF& screen_space_point,
2423 InputHandler::ScrollInputType type,
2424 const ScrollTree& scroll_tree,
2425 ScrollNode* scroll_node) const {
2426 InputHandler::ScrollStatus scroll_status;
2427 scroll_status.main_thread_scrolling_reasons =
2428 MainThreadScrollingReason::kNotScrollingOnMain;
2429 if (!!scroll_node->data.main_thread_scrolling_reasons) {
2430 TRACE_EVENT0("cc", "LayerImpl::TryScroll: Failed ShouldScrollOnMainThread");
2431 scroll_status.thread = InputHandler::SCROLL_ON_MAIN_THREAD;
2432 scroll_status.main_thread_scrolling_reasons =
2433 scroll_node->data.main_thread_scrolling_reasons;
2434 return scroll_status;
2435 }
2436
2437 gfx::Transform screen_space_transform =
2438 scroll_tree.ScreenSpaceTransform(scroll_node->id);
2439 if (!screen_space_transform.IsInvertible()) {
2440 TRACE_EVENT0("cc", "LayerImpl::TryScroll: Ignored NonInvertibleTransform");
2441 scroll_status.thread = InputHandler::SCROLL_IGNORED;
2442 scroll_status.main_thread_scrolling_reasons =
2443 MainThreadScrollingReason::kNonInvertibleTransform;
2444 return scroll_status;
2445 }
2446
2447 if (scroll_node->data.contains_non_fast_scrollable_region) {
2448 bool clipped = false;
2449 gfx::Transform inverse_screen_space_transform(
2450 gfx::Transform::kSkipInitialization);
2451 if (!screen_space_transform.GetInverse(&inverse_screen_space_transform)) {
2452 // TODO(shawnsingh): We shouldn't be applying a projection if screen space
2453 // transform is uninvertible here. Perhaps we should be returning
2454 // SCROLL_ON_MAIN_THREAD in this case?
2455 }
2456
2457 gfx::PointF hit_test_point_in_layer_space = MathUtil::ProjectPoint(
2458 inverse_screen_space_transform, screen_space_point, &clipped);
2459 if (!clipped &&
2460 active_tree()
2461 ->LayerById(scroll_node->owner_id)
2462 ->non_fast_scrollable_region()
2463 .Contains(gfx::ToRoundedPoint(hit_test_point_in_layer_space))) {
2464 TRACE_EVENT0("cc",
2465 "LayerImpl::tryScroll: Failed NonFastScrollableRegion");
2466 scroll_status.thread = InputHandler::SCROLL_ON_MAIN_THREAD;
2467 scroll_status.main_thread_scrolling_reasons =
2468 MainThreadScrollingReason::kNonFastScrollableRegion;
2469 return scroll_status;
2470 }
2471 }
2472
2473 if (type == InputHandler::WHEEL || type == InputHandler::ANIMATED_WHEEL) {
2474 EventListenerProperties event_properties =
2475 active_tree()->event_listener_properties(
2476 EventListenerClass::kMouseWheel);
2477 if (event_properties == EventListenerProperties::kBlocking ||
2478 event_properties == EventListenerProperties::kBlockingAndPassive ||
2479 (!active_tree()->settings().use_mouse_wheel_gestures &&
2480 event_properties == EventListenerProperties::kPassive)) {
2481 TRACE_EVENT0("cc", "LayerImpl::tryScroll: Failed WheelEventHandlers");
2482 scroll_status.thread = InputHandler::SCROLL_ON_MAIN_THREAD;
2483 scroll_status.main_thread_scrolling_reasons =
2484 MainThreadScrollingReason::kEventHandlers;
2485 return scroll_status;
2486 }
2487 }
2488
2489 if (!scroll_node->data.scrollable) {
2490 TRACE_EVENT0("cc", "LayerImpl::tryScroll: Ignored not scrollable");
2491 scroll_status.thread = InputHandler::SCROLL_IGNORED;
2492 scroll_status.main_thread_scrolling_reasons =
2493 MainThreadScrollingReason::kNotScrollable;
2494 return scroll_status;
2495 }
2496
2497 gfx::ScrollOffset max_scroll_offset =
2498 scroll_tree.MaxScrollOffset(scroll_node->id);
2499 if (max_scroll_offset.x() <= 0 && max_scroll_offset.y() <= 0) {
2500 TRACE_EVENT0("cc",
2501 "LayerImpl::tryScroll: Ignored. Technically scrollable,"
2502 " but has no affordance in either direction.");
2503 scroll_status.thread = InputHandler::SCROLL_IGNORED;
2504 scroll_status.main_thread_scrolling_reasons =
2505 MainThreadScrollingReason::kNotScrollable;
2506 return scroll_status;
2507 }
2508
2509 scroll_status.thread = InputHandler::SCROLL_ON_IMPL_THREAD;
2510 return scroll_status;
2511 }
2512
2420 LayerImpl* LayerTreeHostImpl::FindScrollLayerForDeviceViewportPoint( 2513 LayerImpl* LayerTreeHostImpl::FindScrollLayerForDeviceViewportPoint(
2421 const gfx::PointF& device_viewport_point, 2514 const gfx::PointF& device_viewport_point,
2422 InputHandler::ScrollInputType type, 2515 InputHandler::ScrollInputType type,
2423 LayerImpl* layer_impl, 2516 LayerImpl* layer_impl,
2424 bool* scroll_on_main_thread, 2517 bool* scroll_on_main_thread,
2425 uint32_t* main_thread_scrolling_reasons) const { 2518 uint32_t* main_thread_scrolling_reasons) const {
2426 DCHECK(scroll_on_main_thread); 2519 DCHECK(scroll_on_main_thread);
2427 DCHECK(main_thread_scrolling_reasons); 2520 DCHECK(main_thread_scrolling_reasons);
2428 *main_thread_scrolling_reasons = 2521 *main_thread_scrolling_reasons =
2429 MainThreadScrollingReason::kNotScrollingOnMain; 2522 MainThreadScrollingReason::kNotScrollingOnMain;
2430 2523
2431 // Walk up the hierarchy and look for a scrollable layer. 2524 // Walk up the hierarchy and look for a scrollable layer.
2432 LayerImpl* potentially_scrolling_layer_impl = NULL; 2525 LayerImpl* potentially_scrolling_layer_impl = NULL;
2433 if (layer_impl) { 2526 if (layer_impl) {
2434 ScrollTree& scroll_tree = active_tree_->property_trees()->scroll_tree; 2527 ScrollTree& scroll_tree = active_tree_->property_trees()->scroll_tree;
2435 ScrollNode* scroll_node = scroll_tree.Node(layer_impl->scroll_tree_index()); 2528 ScrollNode* scroll_node = scroll_tree.Node(layer_impl->scroll_tree_index());
2436 for (; scroll_tree.parent(scroll_node); 2529 for (; scroll_tree.parent(scroll_node);
2437 scroll_node = scroll_tree.parent(scroll_node)) { 2530 scroll_node = scroll_tree.parent(scroll_node)) {
2438 layer_impl = active_tree_->LayerById(scroll_node->owner_id);
2439 // The content layer can also block attempts to scroll outside the main 2531 // The content layer can also block attempts to scroll outside the main
2440 // thread. 2532 // thread.
2441 ScrollStatus status = layer_impl->TryScroll(device_viewport_point, type); 2533 ScrollStatus status =
2534 TryScroll(device_viewport_point, type, scroll_tree, scroll_node);
2442 if (status.thread == SCROLL_ON_MAIN_THREAD) { 2535 if (status.thread == SCROLL_ON_MAIN_THREAD) {
2443 if (layer_impl->should_scroll_on_main_thread()) { 2536 if (!!scroll_node->data.main_thread_scrolling_reasons) {
2444 DCHECK(MainThreadScrollingReason::MainThreadCanSetScrollReasons( 2537 DCHECK(MainThreadScrollingReason::MainThreadCanSetScrollReasons(
2445 status.main_thread_scrolling_reasons)); 2538 status.main_thread_scrolling_reasons));
2446 } else { 2539 } else {
2447 DCHECK(MainThreadScrollingReason::CompositorCanSetScrollReasons( 2540 DCHECK(MainThreadScrollingReason::CompositorCanSetScrollReasons(
2448 status.main_thread_scrolling_reasons)); 2541 status.main_thread_scrolling_reasons));
2449 } 2542 }
2450 2543
2451 *scroll_on_main_thread = true; 2544 *scroll_on_main_thread = true;
2452 *main_thread_scrolling_reasons = status.main_thread_scrolling_reasons; 2545 *main_thread_scrolling_reasons = status.main_thread_scrolling_reasons;
2453 return NULL; 2546 return NULL;
2454 } 2547 }
2455 2548
2456 if (status.thread == InputHandler::SCROLL_ON_IMPL_THREAD && 2549 if (status.thread == InputHandler::SCROLL_ON_IMPL_THREAD &&
2457 !potentially_scrolling_layer_impl) { 2550 !potentially_scrolling_layer_impl) {
2458 potentially_scrolling_layer_impl = layer_impl; 2551 potentially_scrolling_layer_impl =
2552 active_tree_->LayerById(scroll_node->owner_id);
2459 } 2553 }
2460 } 2554 }
2461 } 2555 }
2462 // Falling back to the root scroll layer ensures generation of root overscroll 2556 // Falling back to the root scroll layer ensures generation of root overscroll
2463 // notifications while preventing scroll updates from being unintentionally 2557 // notifications while preventing scroll updates from being unintentionally
2464 // forwarded to the main thread. The inner viewport layer represents the 2558 // forwarded to the main thread. The inner viewport layer represents the
2465 // viewport during scrolling. 2559 // viewport during scrolling.
2466 if (!potentially_scrolling_layer_impl) 2560 if (!potentially_scrolling_layer_impl)
2467 potentially_scrolling_layer_impl = InnerViewportScrollLayer(); 2561 potentially_scrolling_layer_impl = InnerViewportScrollLayer();
2468 2562
(...skipping 1398 matching lines...) Expand 10 before | Expand all | Expand 10 after
3867 return task_runner_provider_->HasImplThread(); 3961 return task_runner_provider_->HasImplThread();
3868 } 3962 }
3869 3963
3870 bool LayerTreeHostImpl::CommitToActiveTree() const { 3964 bool LayerTreeHostImpl::CommitToActiveTree() const {
3871 // In single threaded mode we skip the pending tree and commit directly to the 3965 // In single threaded mode we skip the pending tree and commit directly to the
3872 // active tree. 3966 // active tree.
3873 return !task_runner_provider_->HasImplThread(); 3967 return !task_runner_provider_->HasImplThread();
3874 } 3968 }
3875 3969
3876 } // namespace cc 3970 } // 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