| 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_impl.h" | 5 #include "cc/trees/layer_tree_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> |
| 11 #include <iterator> | 11 #include <iterator> |
| 12 #include <limits> | 12 #include <limits> |
| 13 #include <set> | 13 #include <set> |
| 14 | 14 |
| 15 #include "base/containers/adapters.h" | 15 #include "base/containers/adapters.h" |
| 16 #include "base/metrics/histogram_macros.h" | 16 #include "base/metrics/histogram_macros.h" |
| 17 #include "base/timer/elapsed_timer.h" | 17 #include "base/timer/elapsed_timer.h" |
| 18 #include "base/trace_event/trace_event.h" | 18 #include "base/trace_event/trace_event.h" |
| 19 #include "base/trace_event/trace_event_argument.h" | 19 #include "base/trace_event/trace_event_argument.h" |
| 20 #include "cc/animation/animation_host.h" | 20 #include "cc/animation/animation_host.h" |
| 21 #include "cc/base/histograms.h" | 21 #include "cc/base/histograms.h" |
| 22 #include "cc/base/math_util.h" | 22 #include "cc/base/math_util.h" |
| 23 #include "cc/base/synced_property.h" | 23 #include "cc/base/synced_property.h" |
| 24 #include "cc/debug/devtools_instrumentation.h" | 24 #include "cc/debug/devtools_instrumentation.h" |
| 25 #include "cc/debug/traced_value.h" | 25 #include "cc/debug/traced_value.h" |
| 26 #include "cc/input/page_scale_animation.h" | 26 #include "cc/input/page_scale_animation.h" |
| 27 #include "cc/input/scroll_elasticity_helper.h" |
| 27 #include "cc/input/scrollbar_animation_controller.h" | 28 #include "cc/input/scrollbar_animation_controller.h" |
| 28 #include "cc/input/scrollbar_animation_controller_linear_fade.h" | 29 #include "cc/input/scrollbar_animation_controller_linear_fade.h" |
| 29 #include "cc/input/scrollbar_animation_controller_thinning.h" | 30 #include "cc/input/scrollbar_animation_controller_thinning.h" |
| 30 #include "cc/layers/heads_up_display_layer_impl.h" | 31 #include "cc/layers/heads_up_display_layer_impl.h" |
| 31 #include "cc/layers/layer.h" | 32 #include "cc/layers/layer.h" |
| 32 #include "cc/layers/layer_iterator.h" | 33 #include "cc/layers/layer_iterator.h" |
| 33 #include "cc/layers/layer_list_iterator.h" | 34 #include "cc/layers/layer_list_iterator.h" |
| 34 #include "cc/layers/render_surface_impl.h" | 35 #include "cc/layers/render_surface_impl.h" |
| 35 #include "cc/layers/scrollbar_layer_impl_base.h" | 36 #include "cc/layers/scrollbar_layer_impl_base.h" |
| 36 #include "cc/output/compositor_frame_sink.h" | 37 #include "cc/output/compositor_frame_sink.h" |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 | 148 |
| 148 void LayerTreeImpl::DidUpdateScrollOffset(int layer_id) { | 149 void LayerTreeImpl::DidUpdateScrollOffset(int layer_id) { |
| 149 DidUpdateScrollState(layer_id); | 150 DidUpdateScrollState(layer_id); |
| 150 TransformTree& transform_tree = property_trees()->transform_tree; | 151 TransformTree& transform_tree = property_trees()->transform_tree; |
| 151 ScrollTree& scroll_tree = property_trees()->scroll_tree; | 152 ScrollTree& scroll_tree = property_trees()->scroll_tree; |
| 152 int transform_id = -1; | 153 int transform_id = -1; |
| 153 | 154 |
| 154 // If pending tree topology changed and we still want to notify the pending | 155 // If pending tree topology changed and we still want to notify the pending |
| 155 // tree about scroll offset in the active tree, we may not find the | 156 // tree about scroll offset in the active tree, we may not find the |
| 156 // corresponding pending layer. | 157 // corresponding pending layer. |
| 157 if (LayerById(layer_id)) { | 158 if (LayerImpl* layer = LayerById(layer_id)) { |
| 158 // TODO(sunxd): when we have a layer_id to property_tree index map in | 159 // TODO(sunxd): when we have a layer_id to property_tree index map in |
| 159 // property trees, use the transform_id parameter instead of looking for | 160 // property trees, use the transform_id parameter instead of looking for |
| 160 // indices from LayerImpls. | 161 // indices from LayerImpls. |
| 161 transform_id = LayerById(layer_id)->transform_tree_index(); | 162 transform_id = layer->transform_tree_index(); |
| 162 } else { | 163 } else { |
| 163 DCHECK(!IsActiveTree()); | 164 DCHECK(!IsActiveTree()); |
| 164 return; | 165 return; |
| 165 } | 166 } |
| 166 | 167 |
| 167 if (transform_id != -1) { | 168 if (transform_id != -1) { |
| 168 TransformNode* node = transform_tree.Node(transform_id); | 169 TransformNode* node = transform_tree.Node(transform_id); |
| 169 if (node->scroll_offset != scroll_tree.current_scroll_offset(layer_id)) { | 170 gfx::ScrollOffset scroll_offset_with_overscroll = |
| 170 node->scroll_offset = scroll_tree.current_scroll_offset(layer_id); | 171 scroll_tree.current_scroll_offset(layer_id) + |
| 172 scroll_tree.current_overscroll(layer_id); |
| 173 if (node->scroll_offset_with_overscroll != scroll_offset_with_overscroll) { |
| 174 node->scroll_offset_with_overscroll = scroll_offset_with_overscroll; |
| 171 node->needs_local_transform_update = true; | 175 node->needs_local_transform_update = true; |
| 172 transform_tree.set_needs_update(true); | 176 transform_tree.set_needs_update(true); |
| 173 } | 177 } |
| 174 node->transform_changed = true; | 178 node->transform_changed = true; |
| 175 property_trees()->changed = true; | 179 property_trees()->changed = true; |
| 176 set_needs_update_draw_properties(); | 180 set_needs_update_draw_properties(); |
| 177 } | 181 } |
| 178 | 182 |
| 179 if (IsActiveTree() && layer_tree_host_impl_->pending_tree()) | 183 if (IsActiveTree() && layer_tree_host_impl_->pending_tree()) |
| 180 layer_tree_host_impl_->pending_tree()->DidUpdateScrollOffset(layer_id); | 184 layer_tree_host_impl_->pending_tree()->DidUpdateScrollOffset(layer_id); |
| (...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 606 int new_id = layer ? layer->id() : Layer::INVALID_ID; | 610 int new_id = layer ? layer->id() : Layer::INVALID_ID; |
| 607 int new_scroll_node_id = layer ? layer->scroll_tree_index() : -1; | 611 int new_scroll_node_id = layer ? layer->scroll_tree_index() : -1; |
| 608 if (layer) | 612 if (layer) |
| 609 last_scrolled_layer_id_ = new_id; | 613 last_scrolled_layer_id_ = new_id; |
| 610 | 614 |
| 611 if (old_id == new_id) | 615 if (old_id == new_id) |
| 612 return; | 616 return; |
| 613 | 617 |
| 614 ScrollbarAnimationController* old_animation_controller = | 618 ScrollbarAnimationController* old_animation_controller = |
| 615 layer_tree_host_impl_->ScrollbarAnimationControllerForId(old_id); | 619 layer_tree_host_impl_->ScrollbarAnimationControllerForId(old_id); |
| 620 ScrollElasticityHelper* old_elasticity_helper = |
| 621 layer_tree_host_impl_->ScrollElasticityHelperForId(old_id); |
| 616 ScrollbarAnimationController* new_animation_controller = | 622 ScrollbarAnimationController* new_animation_controller = |
| 617 layer_tree_host_impl_->ScrollbarAnimationControllerForId(new_id); | 623 layer_tree_host_impl_->ScrollbarAnimationControllerForId(new_id); |
| 624 ScrollElasticityHelper* new_elasticity_helper = |
| 625 layer_tree_host_impl_->ScrollElasticityHelperForId(new_id); |
| 626 if (old_elasticity_helper == new_elasticity_helper) |
| 627 old_elasticity_helper = new_elasticity_helper = nullptr; |
| 618 | 628 |
| 619 if (old_animation_controller) | 629 if (old_animation_controller) |
| 620 old_animation_controller->DidScrollEnd(); | 630 old_animation_controller->DidScrollEnd(); |
| 631 |
| 621 scroll_tree.set_currently_scrolling_node(new_scroll_node_id); | 632 scroll_tree.set_currently_scrolling_node(new_scroll_node_id); |
| 633 |
| 622 if (new_animation_controller) | 634 if (new_animation_controller) |
| 623 new_animation_controller->DidScrollBegin(); | 635 new_animation_controller->DidScrollBegin(); |
| 624 } | 636 } |
| 625 | 637 |
| 626 void LayerTreeImpl::ClearCurrentlyScrollingLayer() { | 638 void LayerTreeImpl::ClearCurrentlyScrollingLayer() { |
| 627 SetCurrentlyScrollingLayer(NULL); | 639 SetCurrentlyScrollingLayer(NULL); |
| 628 } | 640 } |
| 629 | 641 |
| 630 float LayerTreeImpl::ClampPageScaleFactorToLimits( | 642 float LayerTreeImpl::ClampPageScaleFactorToLimits( |
| 631 float page_scale_factor) const { | 643 float page_scale_factor) const { |
| (...skipping 736 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1368 scroll_layer_id, layer_tree_host_impl_, delay, resize_delay, | 1380 scroll_layer_id, layer_tree_host_impl_, delay, resize_delay, |
| 1369 fade_duration, thinning_duration); | 1381 fade_duration, thinning_duration); |
| 1370 } | 1382 } |
| 1371 case LayerTreeSettings::NO_ANIMATOR: | 1383 case LayerTreeSettings::NO_ANIMATOR: |
| 1372 NOTREACHED(); | 1384 NOTREACHED(); |
| 1373 break; | 1385 break; |
| 1374 } | 1386 } |
| 1375 return nullptr; | 1387 return nullptr; |
| 1376 } | 1388 } |
| 1377 | 1389 |
| 1390 std::unique_ptr<ScrollElasticityHelper> |
| 1391 LayerTreeImpl::CreateScrollElasticityHelper(int scroll_layer_id) { |
| 1392 DCHECK(settings().enable_elastic_overscroll); |
| 1393 return ScrollElasticityHelper::CreateForLayer(scroll_layer_id, |
| 1394 layer_tree_host_impl_); |
| 1395 } |
| 1396 |
| 1378 void LayerTreeImpl::DidAnimateScrollOffset() { | 1397 void LayerTreeImpl::DidAnimateScrollOffset() { |
| 1379 layer_tree_host_impl_->DidAnimateScrollOffset(); | 1398 layer_tree_host_impl_->DidAnimateScrollOffset(); |
| 1380 } | 1399 } |
| 1381 | 1400 |
| 1382 bool LayerTreeImpl::use_gpu_rasterization() const { | 1401 bool LayerTreeImpl::use_gpu_rasterization() const { |
| 1383 return layer_tree_host_impl_->use_gpu_rasterization(); | 1402 return layer_tree_host_impl_->use_gpu_rasterization(); |
| 1384 } | 1403 } |
| 1385 | 1404 |
| 1386 GpuRasterizationStatus LayerTreeImpl::GetGpuRasterizationStatus() const { | 1405 GpuRasterizationStatus LayerTreeImpl::GetGpuRasterizationStatus() const { |
| 1387 return layer_tree_host_impl_->gpu_rasterization_status(); | 1406 return layer_tree_host_impl_->gpu_rasterization_status(); |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1633 return scrollbars; | 1652 return scrollbars; |
| 1634 } | 1653 } |
| 1635 | 1654 |
| 1636 void LayerTreeImpl::RegisterScrollLayer(LayerImpl* layer) { | 1655 void LayerTreeImpl::RegisterScrollLayer(LayerImpl* layer) { |
| 1637 if (layer->scroll_clip_layer_id() == Layer::INVALID_ID) | 1656 if (layer->scroll_clip_layer_id() == Layer::INVALID_ID) |
| 1638 return; | 1657 return; |
| 1639 | 1658 |
| 1640 clip_scroll_map_.insert( | 1659 clip_scroll_map_.insert( |
| 1641 std::pair<int, int>(layer->scroll_clip_layer_id(), layer->id())); | 1660 std::pair<int, int>(layer->scroll_clip_layer_id(), layer->id())); |
| 1642 | 1661 |
| 1662 bool can_overscroll = layer->can_overscroll(); |
| 1663 if (can_overscroll && settings().enable_elastic_overscroll && |
| 1664 (layer->user_scrollable_horizontal() || |
| 1665 layer->user_scrollable_vertical())) { |
| 1666 layer_tree_host_impl_->RegisterScrollElasticityHelper(layer->id()); |
| 1667 } |
| 1668 |
| 1643 DidUpdateScrollState(layer->id()); | 1669 DidUpdateScrollState(layer->id()); |
| 1644 } | 1670 } |
| 1645 | 1671 |
| 1646 void LayerTreeImpl::UnregisterScrollLayer(LayerImpl* layer) { | 1672 void LayerTreeImpl::UnregisterScrollLayer(LayerImpl* layer) { |
| 1647 if (layer->scroll_clip_layer_id() == Layer::INVALID_ID) | 1673 if (layer->scroll_clip_layer_id() == Layer::INVALID_ID) |
| 1648 return; | 1674 return; |
| 1649 | 1675 |
| 1676 layer_tree_host_impl_->UnregisterScrollElasticityHelper(layer->id()); |
| 1650 clip_scroll_map_.erase(layer->scroll_clip_layer_id()); | 1677 clip_scroll_map_.erase(layer->scroll_clip_layer_id()); |
| 1651 } | 1678 } |
| 1652 | 1679 |
| 1653 void LayerTreeImpl::AddSurfaceLayer(LayerImpl* layer) { | 1680 void LayerTreeImpl::AddSurfaceLayer(LayerImpl* layer) { |
| 1654 DCHECK(std::find(surface_layers_.begin(), surface_layers_.end(), layer) == | 1681 DCHECK(std::find(surface_layers_.begin(), surface_layers_.end(), layer) == |
| 1655 surface_layers_.end()); | 1682 surface_layers_.end()); |
| 1656 surface_layers_.push_back(layer); | 1683 surface_layers_.push_back(layer); |
| 1657 } | 1684 } |
| 1658 | 1685 |
| 1659 void LayerTreeImpl::RemoveSurfaceLayer(LayerImpl* layer) { | 1686 void LayerTreeImpl::RemoveSurfaceLayer(LayerImpl* layer) { |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2067 | 2094 |
| 2068 void LayerTreeImpl::ResetAllChangeTracking() { | 2095 void LayerTreeImpl::ResetAllChangeTracking() { |
| 2069 layers_that_should_push_properties_.clear(); | 2096 layers_that_should_push_properties_.clear(); |
| 2070 // Iterate over all layers, including masks. | 2097 // Iterate over all layers, including masks. |
| 2071 for (auto& layer : *layers_) | 2098 for (auto& layer : *layers_) |
| 2072 layer->ResetChangeTracking(); | 2099 layer->ResetChangeTracking(); |
| 2073 property_trees_.ResetAllChangeTracking(); | 2100 property_trees_.ResetAllChangeTracking(); |
| 2074 } | 2101 } |
| 2075 | 2102 |
| 2076 } // namespace cc | 2103 } // namespace cc |
| OLD | NEW |