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/layer_tree_host_impl.h" | 5 #include "cc/layer_tree_host_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
(...skipping 1369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1380 // When hiding top controls is enabled and the controls are hidden or | 1380 // When hiding top controls is enabled and the controls are hidden or |
1381 // overlaying the content, force scrolls to be enabled on the root layer to | 1381 // overlaying the content, force scrolls to be enabled on the root layer to |
1382 // allow bringing the top controls back into view. | 1382 // allow bringing the top controls back into view. |
1383 if (!potentially_scrolling_layer_impl && top_controls_manager_ && | 1383 if (!potentially_scrolling_layer_impl && top_controls_manager_ && |
1384 top_controls_manager_->content_top_offset() != | 1384 top_controls_manager_->content_top_offset() != |
1385 settings_.topControlsHeight) { | 1385 settings_.topControlsHeight) { |
1386 potentially_scrolling_layer_impl = RootScrollLayer(); | 1386 potentially_scrolling_layer_impl = RootScrollLayer(); |
1387 } | 1387 } |
1388 | 1388 |
1389 if (potentially_scrolling_layer_impl) { | 1389 if (potentially_scrolling_layer_impl) { |
1390 active_tree_->set_currently_scrolling_layer( | 1390 active_tree_->SetCurrentlyScrollingLayer( |
1391 potentially_scrolling_layer_impl); | 1391 potentially_scrolling_layer_impl); |
1392 should_bubble_scrolls_ = (type != NonBubblingGesture); | 1392 should_bubble_scrolls_ = (type != NonBubblingGesture); |
1393 wheel_scrolling_ = (type == Wheel); | 1393 wheel_scrolling_ = (type == Wheel); |
1394 num_impl_thread_scrolls_++; | 1394 num_impl_thread_scrolls_++; |
1395 client_->RenewTreePriority(); | 1395 client_->RenewTreePriority(); |
1396 UMA_HISTOGRAM_BOOLEAN("TryScroll.SlowScroll", false); | 1396 UMA_HISTOGRAM_BOOLEAN("TryScroll.SlowScroll", false); |
1397 return ScrollStarted; | 1397 return ScrollStarted; |
1398 } | 1398 } |
1399 return ScrollIgnored; | 1399 return ScrollIgnored; |
1400 } | 1400 } |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1521 float move_threshold_squared = 0.1f * 0.1f; | 1521 float move_threshold_squared = 0.1f * 0.1f; |
1522 if (applied_delta.LengthSquared() < move_threshold_squared) { | 1522 if (applied_delta.LengthSquared() < move_threshold_squared) { |
1523 if (should_bubble_scrolls_ || !did_lock_scrolling_layer_) | 1523 if (should_bubble_scrolls_ || !did_lock_scrolling_layer_) |
1524 continue; | 1524 continue; |
1525 else | 1525 else |
1526 break; | 1526 break; |
1527 } | 1527 } |
1528 did_scroll = true; | 1528 did_scroll = true; |
1529 did_lock_scrolling_layer_ = true; | 1529 did_lock_scrolling_layer_ = true; |
1530 if (!should_bubble_scrolls_) { | 1530 if (!should_bubble_scrolls_) { |
1531 active_tree_->set_currently_scrolling_layer(layer_impl); | 1531 active_tree_->SetCurrentlyScrollingLayer(layer_impl); |
1532 break; | 1532 break; |
1533 } | 1533 } |
1534 | 1534 |
1535 // If the applied delta is within 45 degrees of the input delta, bail out to | 1535 // If the applied delta is within 45 degrees of the input delta, bail out to |
1536 // make it easier to scroll just one layer in one direction without | 1536 // make it easier to scroll just one layer in one direction without |
1537 // affecting any of its parents. | 1537 // affecting any of its parents. |
1538 float angle_threshold = 45; | 1538 float angle_threshold = 45; |
1539 if (MathUtil::smallestAngleBetweenVectors( | 1539 if (MathUtil::smallestAngleBetweenVectors( |
1540 applied_delta, pending_delta) < angle_threshold) { | 1540 applied_delta, pending_delta) < angle_threshold) { |
1541 pending_delta = gfx::Vector2d(); | 1541 pending_delta = gfx::Vector2d(); |
(...skipping 19 matching lines...) Expand all Loading... |
1561 | 1561 |
1562 void LayerTreeHostImpl::ClearCurrentlyScrollingLayer() { | 1562 void LayerTreeHostImpl::ClearCurrentlyScrollingLayer() { |
1563 active_tree_->ClearCurrentlyScrollingLayer(); | 1563 active_tree_->ClearCurrentlyScrollingLayer(); |
1564 did_lock_scrolling_layer_ = false; | 1564 did_lock_scrolling_layer_ = false; |
1565 } | 1565 } |
1566 | 1566 |
1567 void LayerTreeHostImpl::ScrollEnd() { | 1567 void LayerTreeHostImpl::ScrollEnd() { |
1568 if (top_controls_manager_) | 1568 if (top_controls_manager_) |
1569 top_controls_manager_->ScrollEnd(); | 1569 top_controls_manager_->ScrollEnd(); |
1570 ClearCurrentlyScrollingLayer(); | 1570 ClearCurrentlyScrollingLayer(); |
| 1571 StartScrollbarAnimation(base::TimeTicks::Now()); |
1571 } | 1572 } |
1572 | 1573 |
1573 void LayerTreeHostImpl::PinchGestureBegin() { | 1574 void LayerTreeHostImpl::PinchGestureBegin() { |
1574 pinch_gesture_active_ = true; | 1575 pinch_gesture_active_ = true; |
1575 previous_pinch_anchor_ = gfx::Point(); | 1576 previous_pinch_anchor_ = gfx::Point(); |
1576 client_->RenewTreePriority(); | 1577 client_->RenewTreePriority(); |
1577 } | 1578 } |
1578 | 1579 |
1579 void LayerTreeHostImpl::PinchGestureUpdate(float magnify_delta, | 1580 void LayerTreeHostImpl::PinchGestureUpdate(float magnify_delta, |
1580 gfx::Point anchor) { | 1581 gfx::Point anchor) { |
(...skipping 12 matching lines...) Expand all Loading... |
1593 gfx::PointF new_scale_anchor = | 1594 gfx::PointF new_scale_anchor = |
1594 gfx::ScalePoint(anchor, 1.f / page_scale_delta); | 1595 gfx::ScalePoint(anchor, 1.f / page_scale_delta); |
1595 gfx::Vector2dF move = previous_scale_anchor - new_scale_anchor; | 1596 gfx::Vector2dF move = previous_scale_anchor - new_scale_anchor; |
1596 | 1597 |
1597 previous_pinch_anchor_ = anchor; | 1598 previous_pinch_anchor_ = anchor; |
1598 | 1599 |
1599 move.Scale(1 / active_tree_->page_scale_factor()); | 1600 move.Scale(1 / active_tree_->page_scale_factor()); |
1600 | 1601 |
1601 RootScrollLayer()->ScrollBy(move); | 1602 RootScrollLayer()->ScrollBy(move); |
1602 | 1603 |
1603 if (RootScrollLayer()->scrollbar_animation_controller()) { | |
1604 RootScrollLayer()->scrollbar_animation_controller()-> | |
1605 didPinchGestureUpdate(base::TimeTicks::Now()); | |
1606 } | |
1607 | |
1608 client_->SetNeedsCommitOnImplThread(); | 1604 client_->SetNeedsCommitOnImplThread(); |
1609 client_->SetNeedsRedrawOnImplThread(); | 1605 client_->SetNeedsRedrawOnImplThread(); |
1610 client_->RenewTreePriority(); | 1606 client_->RenewTreePriority(); |
1611 } | 1607 } |
1612 | 1608 |
1613 void LayerTreeHostImpl::PinchGestureEnd() { | 1609 void LayerTreeHostImpl::PinchGestureEnd() { |
1614 pinch_gesture_active_ = false; | 1610 pinch_gesture_active_ = false; |
1615 | |
1616 if (RootScrollLayer() && | |
1617 RootScrollLayer()->scrollbar_animation_controller()) { | |
1618 RootScrollLayer()->scrollbar_animation_controller()-> | |
1619 didPinchGestureEnd(base::TimeTicks::Now()); | |
1620 } | |
1621 | |
1622 client_->SetNeedsCommitOnImplThread(); | 1611 client_->SetNeedsCommitOnImplThread(); |
1623 } | 1612 } |
1624 | 1613 |
1625 static void CollectScrollDeltas(ScrollAndScaleSet* scroll_info, | 1614 static void CollectScrollDeltas(ScrollAndScaleSet* scroll_info, |
1626 LayerImpl* layer_impl) { | 1615 LayerImpl* layer_impl) { |
1627 if (!layer_impl) | 1616 if (!layer_impl) |
1628 return; | 1617 return; |
1629 | 1618 |
1630 gfx::Vector2d scroll_delta = | 1619 gfx::Vector2d scroll_delta = |
1631 gfx::ToFlooredVector2d(layer_impl->scroll_delta()); | 1620 gfx::ToFlooredVector2d(layer_impl->scroll_delta()); |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1840 AnimateScrollbarsRecursive(active_tree_->root_layer(), time); | 1829 AnimateScrollbarsRecursive(active_tree_->root_layer(), time); |
1841 } | 1830 } |
1842 | 1831 |
1843 void LayerTreeHostImpl::AnimateScrollbarsRecursive(LayerImpl* layer, | 1832 void LayerTreeHostImpl::AnimateScrollbarsRecursive(LayerImpl* layer, |
1844 base::TimeTicks time) { | 1833 base::TimeTicks time) { |
1845 if (!layer) | 1834 if (!layer) |
1846 return; | 1835 return; |
1847 | 1836 |
1848 ScrollbarAnimationController* scrollbar_controller = | 1837 ScrollbarAnimationController* scrollbar_controller = |
1849 layer->scrollbar_animation_controller(); | 1838 layer->scrollbar_animation_controller(); |
1850 if (scrollbar_controller && scrollbar_controller->animate(time)) | 1839 if (scrollbar_controller && scrollbar_controller->animate(time)) { |
| 1840 TRACE_EVENT_INSTANT0( |
| 1841 "cc", "LayerTreeHostImpl::setNeedsRedraw due to AnimateScrollbars"); |
1851 client_->SetNeedsRedrawOnImplThread(); | 1842 client_->SetNeedsRedrawOnImplThread(); |
| 1843 } |
1852 | 1844 |
1853 for (size_t i = 0; i < layer->children().size(); ++i) | 1845 for (size_t i = 0; i < layer->children().size(); ++i) |
1854 AnimateScrollbarsRecursive(layer->children()[i], time); | 1846 AnimateScrollbarsRecursive(layer->children()[i], time); |
1855 } | 1847 } |
1856 | 1848 |
| 1849 void LayerTreeHostImpl::StartScrollbarAnimation(base::TimeTicks time) { |
| 1850 TRACE_EVENT0("cc", "LayerTreeHostImpl::startScrollbarAnimation"); |
| 1851 StartScrollbarAnimationRecursive(RootLayer(), time); |
| 1852 } |
| 1853 |
| 1854 void LayerTreeHostImpl::StartScrollbarAnimationRecursive(LayerImpl* layer, |
| 1855 base::TimeTicks time) { |
| 1856 if (!layer) |
| 1857 return; |
| 1858 |
| 1859 ScrollbarAnimationController* scrollbar_controller = |
| 1860 layer->scrollbar_animation_controller(); |
| 1861 if (scrollbar_controller && scrollbar_controller->isAnimating()) { |
| 1862 base::TimeDelta delay = scrollbar_controller->delayBeforeStart(time); |
| 1863 if (delay > base::TimeDelta()) |
| 1864 client_->RequestScrollbarAnimationOnImplThread(delay); |
| 1865 else if (scrollbar_controller->animate(time)) |
| 1866 client_->SetNeedsRedrawOnImplThread(); |
| 1867 } |
| 1868 |
| 1869 for (size_t i = 0; i < layer->children().size(); ++i) |
| 1870 StartScrollbarAnimationRecursive(layer->children()[i], time); |
| 1871 } |
| 1872 |
1857 void LayerTreeHostImpl::SetTreePriority(TreePriority priority) { | 1873 void LayerTreeHostImpl::SetTreePriority(TreePriority priority) { |
1858 if (!tile_manager_) | 1874 if (!tile_manager_) |
1859 return; | 1875 return; |
1860 | 1876 |
1861 GlobalStateThatImpactsTilePriority new_state(tile_manager_->GlobalState()); | 1877 GlobalStateThatImpactsTilePriority new_state(tile_manager_->GlobalState()); |
1862 if (new_state.tree_priority == priority) | 1878 if (new_state.tree_priority == priority) |
1863 return; | 1879 return; |
1864 | 1880 |
1865 new_state.tree_priority = priority; | 1881 new_state.tree_priority = priority; |
1866 tile_manager_->SetGlobalState(new_state); | 1882 tile_manager_->SetGlobalState(new_state); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1939 tile_manager_->SetRecordRenderingStats(debug_state_.recordRenderingStats()); | 1955 tile_manager_->SetRecordRenderingStats(debug_state_.recordRenderingStats()); |
1940 } | 1956 } |
1941 | 1957 |
1942 void LayerTreeHostImpl::SavePaintTime(const base::TimeDelta& total_paint_time, | 1958 void LayerTreeHostImpl::SavePaintTime(const base::TimeDelta& total_paint_time, |
1943 int commit_number) { | 1959 int commit_number) { |
1944 DCHECK(debug_state_.continuousPainting); | 1960 DCHECK(debug_state_.continuousPainting); |
1945 paint_time_counter_->SavePaintTime(total_paint_time, commit_number); | 1961 paint_time_counter_->SavePaintTime(total_paint_time, commit_number); |
1946 } | 1962 } |
1947 | 1963 |
1948 } // namespace cc | 1964 } // namespace cc |
OLD | NEW |