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 <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 #include "gpu/command_buffer/client/gles2_interface.h" | 71 #include "gpu/command_buffer/client/gles2_interface.h" |
72 #include "gpu/GLES2/gl2extchromium.h" | 72 #include "gpu/GLES2/gl2extchromium.h" |
73 #include "ui/gfx/frame_time.h" | 73 #include "ui/gfx/frame_time.h" |
74 #include "ui/gfx/geometry/rect_conversions.h" | 74 #include "ui/gfx/geometry/rect_conversions.h" |
75 #include "ui/gfx/size_conversions.h" | 75 #include "ui/gfx/size_conversions.h" |
76 #include "ui/gfx/vector2d_conversions.h" | 76 #include "ui/gfx/vector2d_conversions.h" |
77 | 77 |
78 namespace cc { | 78 namespace cc { |
79 namespace { | 79 namespace { |
80 | 80 |
| 81 // Small helper class that saves the current viewport location as the user sees |
| 82 // it and resets to the same location. |
| 83 class ViewportAnchor { |
| 84 public: |
| 85 ViewportAnchor(LayerImpl* inner_scroll, LayerImpl* outer_scroll) |
| 86 : inner_(inner_scroll), |
| 87 outer_(outer_scroll) { |
| 88 viewport_in_content_coordinates_ = inner_->TotalScrollOffset(); |
| 89 |
| 90 if (outer_) |
| 91 viewport_in_content_coordinates_ += outer_->TotalScrollOffset(); |
| 92 } |
| 93 |
| 94 void ResetViewportToAnchoredPosition() { |
| 95 DCHECK(outer_); |
| 96 |
| 97 inner_->ClampScrollToMaxScrollOffset(); |
| 98 outer_->ClampScrollToMaxScrollOffset(); |
| 99 |
| 100 gfx::ScrollOffset viewport_location = inner_->TotalScrollOffset() + |
| 101 outer_->TotalScrollOffset(); |
| 102 |
| 103 gfx::Vector2dF delta = |
| 104 viewport_in_content_coordinates_.DeltaFrom(viewport_location); |
| 105 |
| 106 delta = outer_->ScrollBy(delta); |
| 107 inner_->ScrollBy(delta); |
| 108 } |
| 109 |
| 110 private: |
| 111 LayerImpl* inner_; |
| 112 LayerImpl* outer_; |
| 113 gfx::ScrollOffset viewport_in_content_coordinates_; |
| 114 }; |
| 115 |
| 116 |
81 void DidVisibilityChange(LayerTreeHostImpl* id, bool visible) { | 117 void DidVisibilityChange(LayerTreeHostImpl* id, bool visible) { |
82 if (visible) { | 118 if (visible) { |
83 TRACE_EVENT_ASYNC_BEGIN1("webkit", | 119 TRACE_EVENT_ASYNC_BEGIN1("webkit", |
84 "LayerTreeHostImpl::SetVisible", | 120 "LayerTreeHostImpl::SetVisible", |
85 id, | 121 id, |
86 "LayerTreeHostImpl", | 122 "LayerTreeHostImpl", |
87 id); | 123 id); |
88 return; | 124 return; |
89 } | 125 } |
90 | 126 |
(...skipping 1556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1647 } | 1683 } |
1648 | 1684 |
1649 void LayerTreeHostImpl::WillBeginImplFrame(const BeginFrameArgs& args) { | 1685 void LayerTreeHostImpl::WillBeginImplFrame(const BeginFrameArgs& args) { |
1650 // Sample the frame time now. This time will be used for updating animations | 1686 // Sample the frame time now. This time will be used for updating animations |
1651 // when we draw. | 1687 // when we draw. |
1652 UpdateCurrentBeginFrameArgs(args); | 1688 UpdateCurrentBeginFrameArgs(args); |
1653 // Cache the begin impl frame interval | 1689 // Cache the begin impl frame interval |
1654 begin_impl_frame_interval_ = args.interval; | 1690 begin_impl_frame_interval_ = args.interval; |
1655 } | 1691 } |
1656 | 1692 |
1657 void LayerTreeHostImpl::UpdateInnerViewportContainerSize() { | 1693 void LayerTreeHostImpl::UpdateViewportContainerSizes() { |
1658 LayerImpl* container_layer = active_tree_->InnerViewportContainerLayer(); | 1694 LayerImpl* inner_container = active_tree_->InnerViewportContainerLayer(); |
1659 if (!container_layer) | 1695 LayerImpl* outer_container = active_tree_->OuterViewportContainerLayer(); |
| 1696 |
| 1697 if (!inner_container || !top_controls_manager_) |
1660 return; | 1698 return; |
1661 | 1699 |
1662 if (top_controls_manager_) { | 1700 ViewportAnchor anchor(InnerViewportScrollLayer(), |
1663 container_layer->SetBoundsDelta( | 1701 OuterViewportScrollLayer()); |
1664 gfx::Vector2dF(0, active_tree_->top_controls_layout_height() - | 1702 |
1665 active_tree_->total_top_controls_content_offset())); | 1703 // Adjust the inner viewport by shrinking/expanding the container to account |
1666 } | 1704 // for the change in top controls height since the last Resize from Blink. |
| 1705 inner_container->SetBoundsDelta( |
| 1706 gfx::Vector2dF(0, active_tree_->top_controls_layout_height() - |
| 1707 active_tree_->total_top_controls_content_offset())); |
| 1708 |
| 1709 if (!outer_container || outer_container->BoundsForScrolling().IsEmpty()) |
| 1710 return; |
| 1711 |
| 1712 // Adjust the outer viewport container as well, since adjusting only the |
| 1713 // inner may cause its bounds to exceed those of the outer, causing scroll |
| 1714 // clamping. We adjust it so it maintains the same aspect ratio as the |
| 1715 // inner viewport. |
| 1716 float aspect_ratio = inner_container->BoundsForScrolling().width() / |
| 1717 inner_container->BoundsForScrolling().height(); |
| 1718 float target_height = outer_container->BoundsForScrolling().width() / |
| 1719 aspect_ratio; |
| 1720 float current_outer_height = outer_container->BoundsForScrolling().height() - |
| 1721 outer_container->bounds_delta().y(); |
| 1722 gfx::Vector2dF delta(0, target_height - current_outer_height); |
| 1723 |
| 1724 outer_container->SetBoundsDelta(delta); |
| 1725 active_tree_->InnerViewportScrollLayer()->SetBoundsDelta(delta); |
| 1726 |
| 1727 anchor.ResetViewportToAnchoredPosition(); |
1667 } | 1728 } |
1668 | 1729 |
1669 void LayerTreeHostImpl::SetTopControlsLayoutHeight(float height) { | 1730 void LayerTreeHostImpl::SetTopControlsLayoutHeight(float height) { |
1670 if (active_tree_->top_controls_layout_height() == height) | 1731 if (active_tree_->top_controls_layout_height() == height) |
1671 return; | 1732 return; |
1672 | 1733 |
1673 active_tree_->set_top_controls_layout_height(height); | 1734 active_tree_->set_top_controls_layout_height(height); |
1674 UpdateInnerViewportContainerSize(); | 1735 UpdateViewportContainerSizes(); |
1675 SetFullRootLayerDamage(); | 1736 SetFullRootLayerDamage(); |
1676 } | 1737 } |
1677 | 1738 |
1678 void LayerTreeHostImpl::DidLoseOutputSurface() { | 1739 void LayerTreeHostImpl::DidLoseOutputSurface() { |
1679 if (resource_provider_) | 1740 if (resource_provider_) |
1680 resource_provider_->DidLoseOutputSurface(); | 1741 resource_provider_->DidLoseOutputSurface(); |
1681 client_->DidLoseOutputSurfaceOnImplThread(); | 1742 client_->DidLoseOutputSurfaceOnImplThread(); |
1682 } | 1743 } |
1683 | 1744 |
1684 bool LayerTreeHostImpl::HaveRootScrollLayer() const { | 1745 bool LayerTreeHostImpl::HaveRootScrollLayer() const { |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1785 | 1846 |
1786 active_tree_->SetRootLayerScrollOffsetDelegate( | 1847 active_tree_->SetRootLayerScrollOffsetDelegate( |
1787 root_layer_scroll_offset_delegate_); | 1848 root_layer_scroll_offset_delegate_); |
1788 | 1849 |
1789 if (top_controls_manager_) { | 1850 if (top_controls_manager_) { |
1790 top_controls_manager_->SetControlsTopOffset( | 1851 top_controls_manager_->SetControlsTopOffset( |
1791 active_tree_->total_top_controls_content_offset() - | 1852 active_tree_->total_top_controls_content_offset() - |
1792 top_controls_manager_->top_controls_height()); | 1853 top_controls_manager_->top_controls_height()); |
1793 } | 1854 } |
1794 | 1855 |
1795 UpdateInnerViewportContainerSize(); | 1856 UpdateViewportContainerSizes(); |
1796 } else { | 1857 } else { |
1797 active_tree_->ProcessUIResourceRequestQueue(); | 1858 active_tree_->ProcessUIResourceRequestQueue(); |
1798 } | 1859 } |
1799 | 1860 |
1800 active_tree_->DidBecomeActive(); | 1861 active_tree_->DidBecomeActive(); |
1801 ActivateAnimations(); | 1862 ActivateAnimations(); |
1802 if (settings_.impl_side_painting) | 1863 if (settings_.impl_side_painting) |
1803 client_->RenewTreePriority(); | 1864 client_->RenewTreePriority(); |
1804 | 1865 |
1805 client_->OnCanDrawStateChanged(CanDraw()); | 1866 client_->OnCanDrawStateChanged(CanDraw()); |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2148 | 2209 |
2149 void LayerTreeHostImpl::SetViewportSize(const gfx::Size& device_viewport_size) { | 2210 void LayerTreeHostImpl::SetViewportSize(const gfx::Size& device_viewport_size) { |
2150 if (device_viewport_size == device_viewport_size_) | 2211 if (device_viewport_size == device_viewport_size_) |
2151 return; | 2212 return; |
2152 | 2213 |
2153 if (pending_tree_) | 2214 if (pending_tree_) |
2154 active_tree_->SetViewportSizeInvalid(); | 2215 active_tree_->SetViewportSizeInvalid(); |
2155 | 2216 |
2156 device_viewport_size_ = device_viewport_size; | 2217 device_viewport_size_ = device_viewport_size; |
2157 | 2218 |
2158 UpdateInnerViewportContainerSize(); | 2219 UpdateViewportContainerSizes(); |
2159 client_->OnCanDrawStateChanged(CanDraw()); | 2220 client_->OnCanDrawStateChanged(CanDraw()); |
2160 SetFullRootLayerDamage(); | 2221 SetFullRootLayerDamage(); |
2161 active_tree_->set_needs_update_draw_properties(); | 2222 active_tree_->set_needs_update_draw_properties(); |
2162 } | 2223 } |
2163 | 2224 |
2164 void LayerTreeHostImpl::SetOverhangUIResource( | 2225 void LayerTreeHostImpl::SetOverhangUIResource( |
2165 UIResourceId overhang_ui_resource_id, | 2226 UIResourceId overhang_ui_resource_id, |
2166 const gfx::Size& overhang_ui_resource_size) { | 2227 const gfx::Size& overhang_ui_resource_size) { |
2167 overhang_ui_resource_id_ = overhang_ui_resource_id; | 2228 overhang_ui_resource_id_ = overhang_ui_resource_id; |
2168 overhang_ui_resource_size_ = overhang_ui_resource_size; | 2229 overhang_ui_resource_size_ = overhang_ui_resource_size; |
(...skipping 30 matching lines...) Expand all Loading... |
2199 return DeviceViewport(); | 2260 return DeviceViewport(); |
2200 | 2261 |
2201 return external_clip_; | 2262 return external_clip_; |
2202 } | 2263 } |
2203 | 2264 |
2204 const gfx::Transform& LayerTreeHostImpl::DrawTransform() const { | 2265 const gfx::Transform& LayerTreeHostImpl::DrawTransform() const { |
2205 return external_transform_; | 2266 return external_transform_; |
2206 } | 2267 } |
2207 | 2268 |
2208 void LayerTreeHostImpl::DidChangeTopControlsPosition() { | 2269 void LayerTreeHostImpl::DidChangeTopControlsPosition() { |
2209 UpdateInnerViewportContainerSize(); | 2270 UpdateViewportContainerSizes(); |
2210 SetNeedsRedraw(); | 2271 SetNeedsRedraw(); |
2211 SetNeedsAnimate(); | 2272 SetNeedsAnimate(); |
2212 active_tree_->set_needs_update_draw_properties(); | 2273 active_tree_->set_needs_update_draw_properties(); |
2213 SetFullRootLayerDamage(); | 2274 SetFullRootLayerDamage(); |
2214 } | 2275 } |
2215 | 2276 |
2216 void LayerTreeHostImpl::SetControlsTopOffset(float offset) { | 2277 void LayerTreeHostImpl::SetControlsTopOffset(float offset) { |
2217 float current_top_offset = active_tree_->top_controls_content_offset() - | 2278 float current_top_offset = active_tree_->top_controls_content_offset() - |
2218 top_controls_manager_->top_controls_height(); | 2279 top_controls_manager_->top_controls_height(); |
2219 active_tree_->set_top_controls_delta(offset - current_top_offset); | 2280 active_tree_->set_top_controls_delta(offset - current_top_offset); |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2495 return actual_viewport_end_point - viewport_point; | 2556 return actual_viewport_end_point - viewport_point; |
2496 } | 2557 } |
2497 | 2558 |
2498 static gfx::Vector2dF ScrollLayerWithLocalDelta(LayerImpl* layer_impl, | 2559 static gfx::Vector2dF ScrollLayerWithLocalDelta(LayerImpl* layer_impl, |
2499 const gfx::Vector2dF& local_delta) { | 2560 const gfx::Vector2dF& local_delta) { |
2500 gfx::Vector2dF previous_delta(layer_impl->ScrollDelta()); | 2561 gfx::Vector2dF previous_delta(layer_impl->ScrollDelta()); |
2501 layer_impl->ScrollBy(local_delta); | 2562 layer_impl->ScrollBy(local_delta); |
2502 return layer_impl->ScrollDelta() - previous_delta; | 2563 return layer_impl->ScrollDelta() - previous_delta; |
2503 } | 2564 } |
2504 | 2565 |
| 2566 bool LayerTreeHostImpl::ShouldTopControlsConsumeScroll( |
| 2567 const gfx::Vector2dF& scroll_delta) const { |
| 2568 DCHECK(CurrentlyScrollingLayer()); |
| 2569 |
| 2570 if (!top_controls_manager_) |
| 2571 return false; |
| 2572 |
| 2573 // Always consume if it's in the direction to show the top controls. |
| 2574 if (scroll_delta.y() < 0) |
| 2575 return true; |
| 2576 |
| 2577 if (CurrentlyScrollingLayer() != InnerViewportScrollLayer() && |
| 2578 CurrentlyScrollingLayer() != OuterViewportScrollLayer()) |
| 2579 return false; |
| 2580 |
| 2581 if (InnerViewportScrollLayer()->MaxScrollOffset().y() > 0) |
| 2582 return true; |
| 2583 |
| 2584 if (OuterViewportScrollLayer() && |
| 2585 OuterViewportScrollLayer()->MaxScrollOffset().y() > 0) |
| 2586 return true; |
| 2587 |
| 2588 return false; |
| 2589 } |
| 2590 |
2505 bool LayerTreeHostImpl::ScrollBy(const gfx::Point& viewport_point, | 2591 bool LayerTreeHostImpl::ScrollBy(const gfx::Point& viewport_point, |
2506 const gfx::Vector2dF& scroll_delta) { | 2592 const gfx::Vector2dF& scroll_delta) { |
2507 TRACE_EVENT0("cc", "LayerTreeHostImpl::ScrollBy"); | 2593 TRACE_EVENT0("cc", "LayerTreeHostImpl::ScrollBy"); |
2508 if (!CurrentlyScrollingLayer()) | 2594 if (!CurrentlyScrollingLayer()) |
2509 return false; | 2595 return false; |
2510 | 2596 |
2511 gfx::Vector2dF pending_delta = scroll_delta; | 2597 gfx::Vector2dF pending_delta = scroll_delta; |
2512 gfx::Vector2dF unused_root_delta; | 2598 gfx::Vector2dF unused_root_delta; |
2513 bool did_scroll_x = false; | 2599 bool did_scroll_x = false; |
2514 bool did_scroll_y = false; | 2600 bool did_scroll_y = false; |
2515 bool did_scroll_top_controls = false; | 2601 bool did_scroll_top_controls = false; |
2516 // TODO(wjmaclean) Should we guard against CurrentlyScrollingLayer() == 0 | 2602 |
2517 // here? | 2603 bool consume_by_top_controls = ShouldTopControlsConsumeScroll(scroll_delta); |
2518 bool consume_by_top_controls = | |
2519 top_controls_manager_ && | |
2520 (((CurrentlyScrollingLayer() == InnerViewportScrollLayer() || | |
2521 CurrentlyScrollingLayer() == OuterViewportScrollLayer()) && | |
2522 InnerViewportScrollLayer()->MaxScrollOffset().y() > 0) || | |
2523 scroll_delta.y() < 0); | |
2524 | 2604 |
2525 for (LayerImpl* layer_impl = CurrentlyScrollingLayer(); | 2605 for (LayerImpl* layer_impl = CurrentlyScrollingLayer(); |
2526 layer_impl; | 2606 layer_impl; |
2527 layer_impl = layer_impl->parent()) { | 2607 layer_impl = layer_impl->parent()) { |
2528 if (!layer_impl->scrollable()) | 2608 if (!layer_impl->scrollable()) |
2529 continue; | 2609 continue; |
2530 | 2610 |
2531 if (layer_impl == InnerViewportScrollLayer()) { | 2611 if (layer_impl == InnerViewportScrollLayer() || |
2532 // Only allow bubble scrolling when the scroll is in the direction to make | 2612 layer_impl == OuterViewportScrollLayer()) { |
2533 // the top controls visible. | |
2534 gfx::Vector2dF applied_delta; | |
2535 gfx::Vector2dF excess_delta; | |
2536 if (consume_by_top_controls) { | 2613 if (consume_by_top_controls) { |
2537 excess_delta = top_controls_manager_->ScrollBy(pending_delta); | 2614 gfx::Vector2dF excess_delta = |
2538 applied_delta = pending_delta - excess_delta; | 2615 top_controls_manager_->ScrollBy(pending_delta); |
| 2616 gfx::Vector2dF applied_delta = pending_delta - excess_delta; |
2539 pending_delta = excess_delta; | 2617 pending_delta = excess_delta; |
2540 // Force updating of vertical adjust values if needed. | 2618 // Force updating of vertical adjust values if needed. |
2541 if (applied_delta.y() != 0) { | 2619 if (applied_delta.y() != 0) |
2542 did_scroll_top_controls = true; | 2620 did_scroll_top_controls = true; |
2543 layer_impl->ScrollbarParametersDidChange(false); | |
2544 } | |
2545 } | 2621 } |
2546 // Track root layer deltas for reporting overscroll. | 2622 // Track root layer deltas for reporting overscroll. |
2547 unused_root_delta = pending_delta; | 2623 if (layer_impl == InnerViewportScrollLayer()) |
| 2624 unused_root_delta = pending_delta; |
2548 } | 2625 } |
2549 | 2626 |
2550 gfx::Vector2dF applied_delta; | 2627 gfx::Vector2dF applied_delta; |
2551 // Gesture events need to be transformed from viewport coordinates to local | 2628 // Gesture events need to be transformed from viewport coordinates to local |
2552 // layer coordinates so that the scrolling contents exactly follow the | 2629 // layer coordinates so that the scrolling contents exactly follow the |
2553 // user's finger. In contrast, wheel events represent a fixed amount of | 2630 // user's finger. In contrast, wheel events represent a fixed amount of |
2554 // scrolling so we can just apply them directly. | 2631 // scrolling so we can just apply them directly. |
2555 if (!wheel_scrolling_) { | 2632 if (!wheel_scrolling_) { |
2556 float scale_from_viewport_to_screen_space = device_scale_factor_; | 2633 float scale_from_viewport_to_screen_space = device_scale_factor_; |
2557 applied_delta = | 2634 applied_delta = |
(...skipping 825 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3383 } | 3460 } |
3384 | 3461 |
3385 void LayerTreeHostImpl::UnregisterPictureLayerImpl(PictureLayerImpl* layer) { | 3462 void LayerTreeHostImpl::UnregisterPictureLayerImpl(PictureLayerImpl* layer) { |
3386 std::vector<PictureLayerImpl*>::iterator it = | 3463 std::vector<PictureLayerImpl*>::iterator it = |
3387 std::find(picture_layers_.begin(), picture_layers_.end(), layer); | 3464 std::find(picture_layers_.begin(), picture_layers_.end(), layer); |
3388 DCHECK(it != picture_layers_.end()); | 3465 DCHECK(it != picture_layers_.end()); |
3389 picture_layers_.erase(it); | 3466 picture_layers_.erase(it); |
3390 } | 3467 } |
3391 | 3468 |
3392 } // namespace cc | 3469 } // namespace cc |
OLD | NEW |