OLD | NEW |
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 Loading... |
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 Loading... |
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 (!active_tree()->settings().use_mouse_wheel_gestures && |
| 2479 event_properties == EventListenerProperties::kPassive)) { |
| 2480 TRACE_EVENT0("cc", "LayerImpl::tryScroll: Failed WheelEventHandlers"); |
| 2481 scroll_status.thread = InputHandler::SCROLL_ON_MAIN_THREAD; |
| 2482 scroll_status.main_thread_scrolling_reasons = |
| 2483 MainThreadScrollingReason::kEventHandlers; |
| 2484 return scroll_status; |
| 2485 } |
| 2486 } |
| 2487 |
| 2488 if (!scroll_node->data.scrollable) { |
| 2489 TRACE_EVENT0("cc", "LayerImpl::tryScroll: Ignored not scrollable"); |
| 2490 scroll_status.thread = InputHandler::SCROLL_IGNORED; |
| 2491 scroll_status.main_thread_scrolling_reasons = |
| 2492 MainThreadScrollingReason::kNotScrollable; |
| 2493 return scroll_status; |
| 2494 } |
| 2495 |
| 2496 gfx::ScrollOffset max_scroll_offset = |
| 2497 scroll_tree.MaxScrollOffset(scroll_node->id); |
| 2498 if (max_scroll_offset.x() <= 0 && max_scroll_offset.y() <= 0) { |
| 2499 TRACE_EVENT0("cc", |
| 2500 "LayerImpl::tryScroll: Ignored. Technically scrollable," |
| 2501 " but has no affordance in either direction."); |
| 2502 scroll_status.thread = InputHandler::SCROLL_IGNORED; |
| 2503 scroll_status.main_thread_scrolling_reasons = |
| 2504 MainThreadScrollingReason::kNotScrollable; |
| 2505 return scroll_status; |
| 2506 } |
| 2507 |
| 2508 scroll_status.thread = InputHandler::SCROLL_ON_IMPL_THREAD; |
| 2509 return scroll_status; |
| 2510 } |
| 2511 |
2420 LayerImpl* LayerTreeHostImpl::FindScrollLayerForDeviceViewportPoint( | 2512 LayerImpl* LayerTreeHostImpl::FindScrollLayerForDeviceViewportPoint( |
2421 const gfx::PointF& device_viewport_point, | 2513 const gfx::PointF& device_viewport_point, |
2422 InputHandler::ScrollInputType type, | 2514 InputHandler::ScrollInputType type, |
2423 LayerImpl* layer_impl, | 2515 LayerImpl* layer_impl, |
2424 bool* scroll_on_main_thread, | 2516 bool* scroll_on_main_thread, |
2425 uint32_t* main_thread_scrolling_reasons) const { | 2517 uint32_t* main_thread_scrolling_reasons) const { |
2426 DCHECK(scroll_on_main_thread); | 2518 DCHECK(scroll_on_main_thread); |
2427 DCHECK(main_thread_scrolling_reasons); | 2519 DCHECK(main_thread_scrolling_reasons); |
2428 *main_thread_scrolling_reasons = | 2520 *main_thread_scrolling_reasons = |
2429 MainThreadScrollingReason::kNotScrollingOnMain; | 2521 MainThreadScrollingReason::kNotScrollingOnMain; |
2430 | 2522 |
2431 // Walk up the hierarchy and look for a scrollable layer. | 2523 // Walk up the hierarchy and look for a scrollable layer. |
2432 LayerImpl* potentially_scrolling_layer_impl = NULL; | 2524 LayerImpl* potentially_scrolling_layer_impl = NULL; |
2433 if (layer_impl) { | 2525 if (layer_impl) { |
2434 ScrollTree& scroll_tree = active_tree_->property_trees()->scroll_tree; | 2526 ScrollTree& scroll_tree = active_tree_->property_trees()->scroll_tree; |
2435 ScrollNode* scroll_node = scroll_tree.Node(layer_impl->scroll_tree_index()); | 2527 ScrollNode* scroll_node = scroll_tree.Node(layer_impl->scroll_tree_index()); |
2436 for (; scroll_tree.parent(scroll_node); | 2528 for (; scroll_tree.parent(scroll_node); |
2437 scroll_node = scroll_tree.parent(scroll_node)) { | 2529 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 | 2530 // The content layer can also block attempts to scroll outside the main |
2440 // thread. | 2531 // thread. |
2441 ScrollStatus status = layer_impl->TryScroll(device_viewport_point, type); | 2532 ScrollStatus status = |
| 2533 TryScroll(device_viewport_point, type, scroll_tree, scroll_node); |
2442 if (status.thread == SCROLL_ON_MAIN_THREAD) { | 2534 if (status.thread == SCROLL_ON_MAIN_THREAD) { |
2443 if (layer_impl->should_scroll_on_main_thread()) { | 2535 if (!!scroll_node->data.main_thread_scrolling_reasons) { |
2444 DCHECK(MainThreadScrollingReason::MainThreadCanSetScrollReasons( | 2536 DCHECK(MainThreadScrollingReason::MainThreadCanSetScrollReasons( |
2445 status.main_thread_scrolling_reasons)); | 2537 status.main_thread_scrolling_reasons)); |
2446 } else { | 2538 } else { |
2447 DCHECK(MainThreadScrollingReason::CompositorCanSetScrollReasons( | 2539 DCHECK(MainThreadScrollingReason::CompositorCanSetScrollReasons( |
2448 status.main_thread_scrolling_reasons)); | 2540 status.main_thread_scrolling_reasons)); |
2449 } | 2541 } |
2450 | 2542 |
2451 *scroll_on_main_thread = true; | 2543 *scroll_on_main_thread = true; |
2452 *main_thread_scrolling_reasons = status.main_thread_scrolling_reasons; | 2544 *main_thread_scrolling_reasons = status.main_thread_scrolling_reasons; |
2453 return NULL; | 2545 return NULL; |
2454 } | 2546 } |
2455 | 2547 |
2456 if (status.thread == InputHandler::SCROLL_ON_IMPL_THREAD && | 2548 if (status.thread == InputHandler::SCROLL_ON_IMPL_THREAD && |
2457 !potentially_scrolling_layer_impl) { | 2549 !potentially_scrolling_layer_impl) { |
2458 potentially_scrolling_layer_impl = layer_impl; | 2550 potentially_scrolling_layer_impl = |
| 2551 active_tree_->LayerById(scroll_node->owner_id); |
2459 } | 2552 } |
2460 } | 2553 } |
2461 } | 2554 } |
2462 // Falling back to the root scroll layer ensures generation of root overscroll | 2555 // Falling back to the root scroll layer ensures generation of root overscroll |
2463 // notifications while preventing scroll updates from being unintentionally | 2556 // notifications while preventing scroll updates from being unintentionally |
2464 // forwarded to the main thread. The inner viewport layer represents the | 2557 // forwarded to the main thread. The inner viewport layer represents the |
2465 // viewport during scrolling. | 2558 // viewport during scrolling. |
2466 if (!potentially_scrolling_layer_impl) | 2559 if (!potentially_scrolling_layer_impl) |
2467 potentially_scrolling_layer_impl = InnerViewportScrollLayer(); | 2560 potentially_scrolling_layer_impl = InnerViewportScrollLayer(); |
2468 | 2561 |
(...skipping 1398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3867 return task_runner_provider_->HasImplThread(); | 3960 return task_runner_provider_->HasImplThread(); |
3868 } | 3961 } |
3869 | 3962 |
3870 bool LayerTreeHostImpl::CommitToActiveTree() const { | 3963 bool LayerTreeHostImpl::CommitToActiveTree() const { |
3871 // In single threaded mode we skip the pending tree and commit directly to the | 3964 // In single threaded mode we skip the pending tree and commit directly to the |
3872 // active tree. | 3965 // active tree. |
3873 return !task_runner_provider_->HasImplThread(); | 3966 return !task_runner_provider_->HasImplThread(); |
3874 } | 3967 } |
3875 | 3968 |
3876 } // namespace cc | 3969 } // namespace cc |
OLD | NEW |