Chromium Code Reviews| 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> | 
| (...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 617 layer->id()); | 617 layer->id()); | 
| 618 | 618 | 
| 619 layer_tree_host_impl_->mutator_host()->UnregisterElement( | 619 layer_tree_host_impl_->mutator_host()->UnregisterElement( | 
| 620 layer->element_id(), | 620 layer->element_id(), | 
| 621 IsActiveTree() ? ElementListType::ACTIVE : ElementListType::PENDING); | 621 IsActiveTree() ? ElementListType::ACTIVE : ElementListType::PENDING); | 
| 622 | 622 | 
| 623 element_layers_map_.erase(layer->element_id()); | 623 element_layers_map_.erase(layer->element_id()); | 
| 624 } | 624 } | 
| 625 | 625 | 
| 626 void LayerTreeImpl::AddToOpacityAnimationsMap(int id, float opacity) { | 626 void LayerTreeImpl::AddToOpacityAnimationsMap(int id, float opacity) { | 
| 627 opacity_animations_map_[id] = opacity; | 627 if (LayerImpl* layer = LayerById(id)) | 
| 
 
ajuma
2017/03/20 21:40:38
This logic is a bit roundabout in that (looking at
 
weiliangc
2017/03/21 15:18:52
Yeah.
 
 | |
| 628 opacity_animations_map_[layer->element_id()] = opacity; | |
| 628 } | 629 } | 
| 629 | 630 | 
| 630 void LayerTreeImpl::AddToTransformAnimationsMap(int id, | 631 void LayerTreeImpl::AddToTransformAnimationsMap(int id, | 
| 631 gfx::Transform transform) { | 632 gfx::Transform transform) { | 
| 632 transform_animations_map_[id] = transform; | 633 if (LayerImpl* layer = LayerById(id)) | 
| 634 transform_animations_map_[layer->element_id()] = transform; | |
| 633 } | 635 } | 
| 634 | 636 | 
| 635 void LayerTreeImpl::AddToFilterAnimationsMap(int id, | 637 void LayerTreeImpl::AddToFilterAnimationsMap(int id, | 
| 636 const FilterOperations& filters) { | 638 const FilterOperations& filters) { | 
| 637 filter_animations_map_[id] = filters; | 639 if (LayerImpl* layer = LayerById(id)) | 
| 640 filter_animations_map_[layer->element_id()] = filters; | |
| 638 } | 641 } | 
| 639 | 642 | 
| 640 LayerImpl* LayerTreeImpl::InnerViewportContainerLayer() const { | 643 LayerImpl* LayerTreeImpl::InnerViewportContainerLayer() const { | 
| 641 return InnerViewportScrollLayer() | 644 return InnerViewportScrollLayer() | 
| 642 ? InnerViewportScrollLayer()->scroll_clip_layer() | 645 ? InnerViewportScrollLayer()->scroll_clip_layer() | 
| 643 : NULL; | 646 : NULL; | 
| 644 } | 647 } | 
| 645 | 648 | 
| 646 LayerImpl* LayerTreeImpl::OuterViewportContainerLayer() const { | 649 LayerImpl* LayerTreeImpl::OuterViewportContainerLayer() const { | 
| 647 return OuterViewportScrollLayer() | 650 return OuterViewportScrollLayer() | 
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 714 | 717 | 
| 715 void LayerTreeImpl::UpdatePropertyTreeScrollingAndAnimationFromMainThread() { | 718 void LayerTreeImpl::UpdatePropertyTreeScrollingAndAnimationFromMainThread() { | 
| 716 // TODO(enne): This should get replaced by pulling out scrolling and | 719 // TODO(enne): This should get replaced by pulling out scrolling and | 
| 717 // animations into their own trees. Then scrolls and animations would have | 720 // animations into their own trees. Then scrolls and animations would have | 
| 718 // their own ways of synchronizing across commits. This occurs to push | 721 // their own ways of synchronizing across commits. This occurs to push | 
| 719 // updates from scrolling deltas on the compositor thread that have occurred | 722 // updates from scrolling deltas on the compositor thread that have occurred | 
| 720 // after begin frame and updates from animations that have ticked since begin | 723 // after begin frame and updates from animations that have ticked since begin | 
| 721 // frame to a newly-committed property tree. | 724 // frame to a newly-committed property tree. | 
| 722 if (layer_list_.empty()) | 725 if (layer_list_.empty()) | 
| 723 return; | 726 return; | 
| 724 std::vector<int> layer_ids_to_remove; | 727 auto element_id_to_opacity = opacity_animations_map_.begin(); | 
| 725 for (auto& layer_id_to_opacity : opacity_animations_map_) { | 728 for (; element_id_to_opacity != opacity_animations_map_.end();) { | 
| 
 
ajuma
2017/03/20 21:40:38
Since this just has a condition now, it can be tur
 
 | |
| 726 const int id = layer_id_to_opacity.first; | 729 const ElementId id = element_id_to_opacity->first; | 
| 727 if (EffectNode* node = | 730 if (EffectNode* node = | 
| 728 property_trees_.effect_tree.UpdateNodeFromOwningLayerId(id)) { | 731 property_trees_.effect_tree.FindNodeFromElementId(id)) { | 
| 729 if (!node->is_currently_animating_opacity || | 732 if (!node->is_currently_animating_opacity || | 
| 730 node->opacity == layer_id_to_opacity.second) { | 733 node->opacity == element_id_to_opacity->second) { | 
| 731 layer_ids_to_remove.push_back(id); | 734 opacity_animations_map_.erase(element_id_to_opacity++); | 
| 
 
ajuma
2017/03/20 21:40:38
Is the iterator guaranteed to still be valid after
 
weiliangc
2017/03/21 15:18:52
Yes. It's post increment, so the current iterator
 
 | |
| 732 continue; | 735 continue; | 
| 733 } | 736 } | 
| 734 node->opacity = layer_id_to_opacity.second; | 737 node->opacity = element_id_to_opacity->second; | 
| 735 property_trees_.effect_tree.set_needs_update(true); | 738 property_trees_.effect_tree.set_needs_update(true); | 
| 736 } | 739 } | 
| 740 ++element_id_to_opacity; | |
| 737 } | 741 } | 
| 738 for (auto id : layer_ids_to_remove) | |
| 739 opacity_animations_map_.erase(id); | |
| 740 layer_ids_to_remove.clear(); | |
| 741 | 742 | 
| 742 for (auto& layer_id_to_transform : transform_animations_map_) { | 743 auto element_id_to_filter = filter_animations_map_.begin(); | 
| 743 const int id = layer_id_to_transform.first; | 744 for (; element_id_to_filter != filter_animations_map_.end();) { | 
| 744 if (TransformNode* node = | 745 const ElementId id = element_id_to_filter->first; | 
| 745 property_trees_.transform_tree.UpdateNodeFromOwningLayerId(id)) { | 746 if (EffectNode* node = | 
| 746 if (!node->is_currently_animating || | 747 property_trees_.effect_tree.FindNodeFromElementId(id)) { | 
| 747 node->local == layer_id_to_transform.second) { | 748 if (!node->is_currently_animating_filter || | 
| 748 layer_ids_to_remove.push_back(id); | 749 node->filters == element_id_to_filter->second) { | 
| 750 filter_animations_map_.erase(element_id_to_filter++); | |
| 749 continue; | 751 continue; | 
| 750 } | 752 } | 
| 751 node->local = layer_id_to_transform.second; | 753 node->filters = element_id_to_filter->second; | 
| 754 property_trees_.effect_tree.set_needs_update(true); | |
| 755 } | |
| 756 ++element_id_to_filter; | |
| 757 } | |
| 758 | |
| 759 auto element_id_to_transform = transform_animations_map_.begin(); | |
| 760 for (; element_id_to_transform != transform_animations_map_.end();) { | |
| 761 const ElementId id = element_id_to_transform->first; | |
| 762 if (TransformNode* node = | |
| 763 property_trees_.transform_tree.FindNodeFromElementId(id)) { | |
| 764 if (!node->is_currently_animating || | |
| 765 node->local == element_id_to_transform->second) { | |
| 766 transform_animations_map_.erase(element_id_to_transform++); | |
| 767 continue; | |
| 768 } | |
| 769 node->local = element_id_to_transform->second; | |
| 752 node->needs_local_transform_update = true; | 770 node->needs_local_transform_update = true; | 
| 753 property_trees_.transform_tree.set_needs_update(true); | 771 property_trees_.transform_tree.set_needs_update(true); | 
| 754 } | 772 } | 
| 773 ++element_id_to_transform; | |
| 755 } | 774 } | 
| 756 for (auto id : layer_ids_to_remove) | |
| 757 transform_animations_map_.erase(id); | |
| 758 layer_ids_to_remove.clear(); | |
| 759 | |
| 760 for (auto& layer_id_to_filters : filter_animations_map_) { | |
| 761 const int id = layer_id_to_filters.first; | |
| 762 if (EffectNode* node = | |
| 763 property_trees_.effect_tree.UpdateNodeFromOwningLayerId(id)) { | |
| 764 if (!node->is_currently_animating_filter || | |
| 765 node->filters == layer_id_to_filters.second) { | |
| 766 layer_ids_to_remove.push_back(id); | |
| 767 continue; | |
| 768 } | |
| 769 node->filters = layer_id_to_filters.second; | |
| 770 property_trees_.effect_tree.set_needs_update(true); | |
| 771 } | |
| 772 } | |
| 773 for (auto id : layer_ids_to_remove) | |
| 774 filter_animations_map_.erase(id); | |
| 775 | 775 | 
| 776 LayerTreeHostCommon::CallFunctionForEveryLayer(this, [](LayerImpl* layer) { | 776 LayerTreeHostCommon::CallFunctionForEveryLayer(this, [](LayerImpl* layer) { | 
| 777 layer->UpdatePropertyTreeForScrollingAndAnimationIfNeeded(); | 777 layer->UpdatePropertyTreeForScrollingAndAnimationIfNeeded(); | 
| 778 }); | 778 }); | 
| 779 } | 779 } | 
| 780 | 780 | 
| 781 void LayerTreeImpl::SetPageScaleOnActiveTree(float active_page_scale) { | 781 void LayerTreeImpl::SetPageScaleOnActiveTree(float active_page_scale) { | 
| 782 DCHECK(IsActiveTree()); | 782 DCHECK(IsActiveTree()); | 
| 783 if (page_scale_factor()->SetCurrent( | 783 if (page_scale_factor()->SetCurrent( | 
| 784 ClampPageScaleFactorToLimits(active_page_scale))) { | 784 ClampPageScaleFactorToLimits(active_page_scale))) { | 
| (...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1178 << "CalcDrawProperties should not set_needs_update_draw_properties()"; | 1178 << "CalcDrawProperties should not set_needs_update_draw_properties()"; | 
| 1179 return true; | 1179 return true; | 
| 1180 } | 1180 } | 
| 1181 | 1181 | 
| 1182 void LayerTreeImpl::BuildLayerListAndPropertyTreesForTesting() { | 1182 void LayerTreeImpl::BuildLayerListAndPropertyTreesForTesting() { | 
| 1183 BuildLayerListForTesting(); | 1183 BuildLayerListForTesting(); | 
| 1184 BuildPropertyTreesForTesting(); | 1184 BuildPropertyTreesForTesting(); | 
| 1185 } | 1185 } | 
| 1186 | 1186 | 
| 1187 void LayerTreeImpl::BuildPropertyTreesForTesting() { | 1187 void LayerTreeImpl::BuildPropertyTreesForTesting() { | 
| 1188 SetElementIdsForTesting(); | |
| 1188 PropertyTreeBuilder::PreCalculateMetaInformationForTesting(layer_list_[0]); | 1189 PropertyTreeBuilder::PreCalculateMetaInformationForTesting(layer_list_[0]); | 
| 1189 property_trees_.needs_rebuild = true; | 1190 property_trees_.needs_rebuild = true; | 
| 1190 property_trees_.transform_tree.set_source_to_parent_updates_allowed(true); | 1191 property_trees_.transform_tree.set_source_to_parent_updates_allowed(true); | 
| 1191 PropertyTreeBuilder::BuildPropertyTrees( | 1192 PropertyTreeBuilder::BuildPropertyTrees( | 
| 1192 layer_list_[0], PageScaleLayer(), InnerViewportScrollLayer(), | 1193 layer_list_[0], PageScaleLayer(), InnerViewportScrollLayer(), | 
| 1193 OuterViewportScrollLayer(), OverscrollElasticityLayer(), | 1194 OuterViewportScrollLayer(), OverscrollElasticityLayer(), | 
| 1194 elastic_overscroll()->Current(IsActiveTree()), | 1195 elastic_overscroll()->Current(IsActiveTree()), | 
| 1195 current_page_scale_factor(), device_scale_factor(), | 1196 current_page_scale_factor(), device_scale_factor(), | 
| 1196 gfx::Rect(DrawViewportSize()), layer_tree_host_impl_->DrawTransform(), | 1197 gfx::Rect(DrawViewportSize()), layer_tree_host_impl_->DrawTransform(), | 
| 1197 &property_trees_); | 1198 &property_trees_); | 
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1250 } | 1251 } | 
| 1251 | 1252 | 
| 1252 void LayerTreeImpl::RegisterLayer(LayerImpl* layer) { | 1253 void LayerTreeImpl::RegisterLayer(LayerImpl* layer) { | 
| 1253 DCHECK(!LayerById(layer->id())); | 1254 DCHECK(!LayerById(layer->id())); | 
| 1254 layer_id_map_[layer->id()] = layer; | 1255 layer_id_map_[layer->id()] = layer; | 
| 1255 } | 1256 } | 
| 1256 | 1257 | 
| 1257 void LayerTreeImpl::UnregisterLayer(LayerImpl* layer) { | 1258 void LayerTreeImpl::UnregisterLayer(LayerImpl* layer) { | 
| 1258 DCHECK(LayerById(layer->id())); | 1259 DCHECK(LayerById(layer->id())); | 
| 1259 layers_that_should_push_properties_.erase(layer); | 1260 layers_that_should_push_properties_.erase(layer); | 
| 1260 transform_animations_map_.erase(layer->id()); | 1261 transform_animations_map_.erase(layer->element_id()); | 
| 1261 opacity_animations_map_.erase(layer->id()); | 1262 opacity_animations_map_.erase(layer->element_id()); | 
| 1263 filter_animations_map_.erase(layer->element_id()); | |
| 1262 layer_id_map_.erase(layer->id()); | 1264 layer_id_map_.erase(layer->id()); | 
| 1263 } | 1265 } | 
| 1264 | 1266 | 
| 1265 // These manage ownership of the LayerImpl. | 1267 // These manage ownership of the LayerImpl. | 
| 1266 void LayerTreeImpl::AddLayer(std::unique_ptr<LayerImpl> layer) { | 1268 void LayerTreeImpl::AddLayer(std::unique_ptr<LayerImpl> layer) { | 
| 1267 DCHECK(std::find(layers_->begin(), layers_->end(), layer) == layers_->end()); | 1269 DCHECK(std::find(layers_->begin(), layers_->end(), layer) == layers_->end()); | 
| 1268 layers_->push_back(std::move(layer)); | 1270 layers_->push_back(std::move(layer)); | 
| 1269 set_needs_update_draw_properties(); | 1271 set_needs_update_draw_properties(); | 
| 1270 } | 1272 } | 
| 1271 | 1273 | 
| (...skipping 873 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2145 | 2147 | 
| 2146 void LayerTreeImpl::ResetAllChangeTracking() { | 2148 void LayerTreeImpl::ResetAllChangeTracking() { | 
| 2147 layers_that_should_push_properties_.clear(); | 2149 layers_that_should_push_properties_.clear(); | 
| 2148 // Iterate over all layers, including masks. | 2150 // Iterate over all layers, including masks. | 
| 2149 for (auto& layer : *layers_) | 2151 for (auto& layer : *layers_) | 
| 2150 layer->ResetChangeTracking(); | 2152 layer->ResetChangeTracking(); | 
| 2151 property_trees_.ResetAllChangeTracking(); | 2153 property_trees_.ResetAllChangeTracking(); | 
| 2152 } | 2154 } | 
| 2153 | 2155 | 
| 2154 } // namespace cc | 2156 } // namespace cc | 
| OLD | NEW |