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