| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/property_tree_builder.h" | 5 #include "cc/trees/property_tree_builder.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 }; | 73 }; |
| 74 | 74 |
| 75 static LayerPositionConstraint PositionConstraint(Layer* layer) { | 75 static LayerPositionConstraint PositionConstraint(Layer* layer) { |
| 76 return layer->position_constraint(); | 76 return layer->position_constraint(); |
| 77 } | 77 } |
| 78 | 78 |
| 79 static LayerPositionConstraint PositionConstraint(LayerImpl* layer) { | 79 static LayerPositionConstraint PositionConstraint(LayerImpl* layer) { |
| 80 return layer->test_properties()->position_constraint; | 80 return layer->test_properties()->position_constraint; |
| 81 } | 81 } |
| 82 | 82 |
| 83 static Layer* ScrollParent(Layer* layer) { |
| 84 return layer->scroll_parent(); |
| 85 } |
| 86 |
| 87 static LayerImpl* ScrollParent(LayerImpl* layer) { |
| 88 return layer->test_properties()->scroll_parent; |
| 89 } |
| 90 |
| 91 static std::set<Layer*>* ScrollChildren(Layer* layer) { |
| 92 return layer->scroll_children(); |
| 93 } |
| 94 |
| 95 static std::set<LayerImpl*>* ScrollChildren(LayerImpl* layer) { |
| 96 return layer->test_properties()->scroll_children.get(); |
| 97 } |
| 98 |
| 99 static Layer* ClipParent(Layer* layer) { |
| 100 return layer->clip_parent(); |
| 101 } |
| 102 |
| 103 static LayerImpl* ClipParent(LayerImpl* layer) { |
| 104 return layer->test_properties()->clip_parent; |
| 105 } |
| 106 |
| 83 template <typename LayerType> | 107 template <typename LayerType> |
| 84 static LayerType* GetTransformParent(const DataForRecursion<LayerType>& data, | 108 static LayerType* GetTransformParent(const DataForRecursion<LayerType>& data, |
| 85 LayerType* layer) { | 109 LayerType* layer) { |
| 86 return PositionConstraint(layer).is_fixed_position() | 110 return PositionConstraint(layer).is_fixed_position() |
| 87 ? data.transform_fixed_parent | 111 ? data.transform_fixed_parent |
| 88 : data.transform_tree_parent; | 112 : data.transform_tree_parent; |
| 89 } | 113 } |
| 90 | 114 |
| 91 template <typename LayerType> | 115 template <typename LayerType> |
| 92 static ClipNode* GetClipParent(const DataForRecursion<LayerType>& data, | 116 static ClipNode* GetClipParent(const DataForRecursion<LayerType>& data, |
| 93 LayerType* layer) { | 117 LayerType* layer) { |
| 94 const bool inherits_clip = !layer->clip_parent(); | 118 const bool inherits_clip = !ClipParent(layer); |
| 95 const int id = inherits_clip ? data.clip_tree_parent | 119 const int id = inherits_clip ? data.clip_tree_parent |
| 96 : layer->clip_parent()->clip_tree_index(); | 120 : ClipParent(layer)->clip_tree_index(); |
| 97 return data.clip_tree->Node(id); | 121 return data.clip_tree->Node(id); |
| 98 } | 122 } |
| 99 | 123 |
| 100 template <typename LayerType> | 124 template <typename LayerType> |
| 101 static bool LayerClipsSubtree(LayerType* layer) { | 125 static bool LayerClipsSubtree(LayerType* layer) { |
| 102 return layer->masks_to_bounds() || layer->mask_layer(); | 126 return layer->masks_to_bounds() || layer->mask_layer(); |
| 103 } | 127 } |
| 104 | 128 |
| 105 template <typename LayerType> | 129 template <typename LayerType> |
| 106 static int GetScrollParentId(const DataForRecursion<LayerType>& data, | 130 static int GetScrollParentId(const DataForRecursion<LayerType>& data, |
| 107 LayerType* layer) { | 131 LayerType* layer) { |
| 108 const bool inherits_scroll = !layer->scroll_parent(); | 132 const bool inherits_scroll = !ScrollParent(layer); |
| 109 const int id = inherits_scroll ? data.scroll_tree_parent | 133 const int id = inherits_scroll ? data.scroll_tree_parent |
| 110 : layer->scroll_parent()->scroll_tree_index(); | 134 : ScrollParent(layer)->scroll_tree_index(); |
| 111 return id; | 135 return id; |
| 112 } | 136 } |
| 113 | 137 |
| 114 template <typename LayerType> | 138 template <typename LayerType> |
| 115 void AddClipNodeIfNeeded(const DataForRecursion<LayerType>& data_from_ancestor, | 139 void AddClipNodeIfNeeded(const DataForRecursion<LayerType>& data_from_ancestor, |
| 116 LayerType* layer, | 140 LayerType* layer, |
| 117 bool created_render_surface, | 141 bool created_render_surface, |
| 118 bool created_transform_node, | 142 bool created_transform_node, |
| 119 DataForRecursion<LayerType>* data_for_children) { | 143 DataForRecursion<LayerType>* data_for_children) { |
| 120 ClipNode* parent = GetClipParent(data_from_ancestor, layer); | 144 ClipNode* parent = GetClipParent(data_from_ancestor, layer); |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 // the Running state right after commit on the compositor thread. | 301 // the Running state right after commit on the compositor thread. |
| 278 const bool has_any_transform_animation = | 302 const bool has_any_transform_animation = |
| 279 layer->HasAnyAnimationTargetingProperty(TargetProperty::TRANSFORM); | 303 layer->HasAnyAnimationTargetingProperty(TargetProperty::TRANSFORM); |
| 280 | 304 |
| 281 const bool has_surface = created_render_surface; | 305 const bool has_surface = created_render_surface; |
| 282 | 306 |
| 283 // A transform node is needed to change the render target for subtree when | 307 // A transform node is needed to change the render target for subtree when |
| 284 // a scroll child's render target is different from the scroll parent's render | 308 // a scroll child's render target is different from the scroll parent's render |
| 285 // target. | 309 // target. |
| 286 const bool scroll_child_has_different_target = | 310 const bool scroll_child_has_different_target = |
| 287 layer->scroll_parent() && | 311 ScrollParent(layer) && |
| 288 layer->parent()->effect_tree_index() != | 312 layer->parent()->effect_tree_index() != |
| 289 layer->scroll_parent()->effect_tree_index(); | 313 ScrollParent(layer)->effect_tree_index(); |
| 290 | 314 |
| 291 const bool is_at_boundary_of_3d_rendering_context = | 315 const bool is_at_boundary_of_3d_rendering_context = |
| 292 IsAtBoundaryOf3dRenderingContext(layer); | 316 IsAtBoundaryOf3dRenderingContext(layer); |
| 293 | 317 |
| 294 bool requires_node = is_root || is_scrollable || has_significant_transform || | 318 bool requires_node = is_root || is_scrollable || has_significant_transform || |
| 295 has_any_transform_animation || has_surface || is_fixed || | 319 has_any_transform_animation || has_surface || is_fixed || |
| 296 is_page_scale_layer || is_overscroll_elasticity_layer || | 320 is_page_scale_layer || is_overscroll_elasticity_layer || |
| 297 scroll_child_has_different_target || | 321 scroll_child_has_different_target || |
| 298 is_at_boundary_of_3d_rendering_context; | 322 is_at_boundary_of_3d_rendering_context; |
| 299 | 323 |
| 300 LayerType* transform_parent = GetTransformParent(data_from_ancestor, layer); | 324 LayerType* transform_parent = GetTransformParent(data_from_ancestor, layer); |
| 301 DCHECK(is_root || transform_parent); | 325 DCHECK(is_root || transform_parent); |
| 302 | 326 |
| 303 int parent_index = kRootPropertyTreeNodeId; | 327 int parent_index = kRootPropertyTreeNodeId; |
| 304 if (transform_parent) | 328 if (transform_parent) |
| 305 parent_index = transform_parent->transform_tree_index(); | 329 parent_index = transform_parent->transform_tree_index(); |
| 306 | 330 |
| 307 int source_index = parent_index; | 331 int source_index = parent_index; |
| 308 | 332 |
| 309 gfx::Vector2dF source_offset; | 333 gfx::Vector2dF source_offset; |
| 310 if (transform_parent) { | 334 if (transform_parent) { |
| 311 if (layer->scroll_parent()) { | 335 if (ScrollParent(layer)) { |
| 312 LayerType* source = layer->parent(); | 336 LayerType* source = layer->parent(); |
| 313 source_offset += source->offset_to_transform_parent(); | 337 source_offset += source->offset_to_transform_parent(); |
| 314 source_index = source->transform_tree_index(); | 338 source_index = source->transform_tree_index(); |
| 315 } else if (!is_fixed) { | 339 } else if (!is_fixed) { |
| 316 source_offset = transform_parent->offset_to_transform_parent(); | 340 source_offset = transform_parent->offset_to_transform_parent(); |
| 317 } else { | 341 } else { |
| 318 source_offset = data_from_ancestor.transform_tree_parent | 342 source_offset = data_from_ancestor.transform_tree_parent |
| 319 ->offset_to_transform_parent(); | 343 ->offset_to_transform_parent(); |
| 320 source_index = | 344 source_index = |
| 321 data_from_ancestor.transform_tree_parent->transform_tree_index(); | 345 data_from_ancestor.transform_tree_parent->transform_tree_index(); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 } else { | 457 } else { |
| 434 node->data.source_offset = source_offset; | 458 node->data.source_offset = source_offset; |
| 435 node->data.update_post_local_transform(layer->position(), | 459 node->data.update_post_local_transform(layer->position(), |
| 436 TransformOrigin(layer)); | 460 TransformOrigin(layer)); |
| 437 } | 461 } |
| 438 | 462 |
| 439 if (is_overscroll_elasticity_layer) { | 463 if (is_overscroll_elasticity_layer) { |
| 440 DCHECK(!is_scrollable); | 464 DCHECK(!is_scrollable); |
| 441 node->data.scroll_offset = | 465 node->data.scroll_offset = |
| 442 gfx::ScrollOffset(data_from_ancestor.elastic_overscroll); | 466 gfx::ScrollOffset(data_from_ancestor.elastic_overscroll); |
| 443 } else if (!layer->scroll_parent()) { | 467 } else if (!ScrollParent(layer)) { |
| 444 node->data.scroll_offset = layer->CurrentScrollOffset(); | 468 node->data.scroll_offset = layer->CurrentScrollOffset(); |
| 445 } | 469 } |
| 446 | 470 |
| 447 if (is_fixed) { | 471 if (is_fixed) { |
| 448 if (data_from_ancestor.affected_by_inner_viewport_bounds_delta) { | 472 if (data_from_ancestor.affected_by_inner_viewport_bounds_delta) { |
| 449 node->data.affected_by_inner_viewport_bounds_delta_x = | 473 node->data.affected_by_inner_viewport_bounds_delta_x = |
| 450 PositionConstraint(layer).is_fixed_to_right_edge(); | 474 PositionConstraint(layer).is_fixed_to_right_edge(); |
| 451 node->data.affected_by_inner_viewport_bounds_delta_y = | 475 node->data.affected_by_inner_viewport_bounds_delta_y = |
| 452 PositionConstraint(layer).is_fixed_to_bottom_edge(); | 476 PositionConstraint(layer).is_fixed_to_bottom_edge(); |
| 453 if (node->data.affected_by_inner_viewport_bounds_delta_x || | 477 if (node->data.affected_by_inner_viewport_bounds_delta_x || |
| (...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 873 AddClipNodeIfNeeded(data_from_parent, layer, created_render_surface, | 897 AddClipNodeIfNeeded(data_from_parent, layer, created_render_surface, |
| 874 created_transform_node, &data_for_children); | 898 created_transform_node, &data_for_children); |
| 875 | 899 |
| 876 AddScrollNodeIfNeeded(data_from_parent, layer, &data_for_children); | 900 AddScrollNodeIfNeeded(data_from_parent, layer, &data_for_children); |
| 877 | 901 |
| 878 SetBackfaceVisibilityTransform(layer, created_transform_node); | 902 SetBackfaceVisibilityTransform(layer, created_transform_node); |
| 879 SetSafeOpaqueBackgroundColor(data_from_parent, layer, &data_for_children); | 903 SetSafeOpaqueBackgroundColor(data_from_parent, layer, &data_for_children); |
| 880 | 904 |
| 881 for (size_t i = 0; i < layer->children().size(); ++i) { | 905 for (size_t i = 0; i < layer->children().size(); ++i) { |
| 882 SetLayerPropertyChangedForChild(layer, layer->child_at(i)); | 906 SetLayerPropertyChangedForChild(layer, layer->child_at(i)); |
| 883 if (!layer->child_at(i)->scroll_parent()) { | 907 if (!ScrollParent(layer->child_at(i))) { |
| 884 DataForRecursionFromChild<LayerType> data_from_child; | 908 DataForRecursionFromChild<LayerType> data_from_child; |
| 885 BuildPropertyTreesInternal(layer->child_at(i), data_for_children, | 909 BuildPropertyTreesInternal(layer->child_at(i), data_for_children, |
| 886 &data_from_child); | 910 &data_from_child); |
| 887 data_to_parent->Merge(data_from_child); | 911 data_to_parent->Merge(data_from_child); |
| 888 } else { | 912 } else { |
| 889 // The child should be included in its scroll parent's list of scroll | 913 // The child should be included in its scroll parent's list of scroll |
| 890 // children. | 914 // children. |
| 891 DCHECK(layer->child_at(i)->scroll_parent()->scroll_children()->count( | 915 DCHECK(ScrollChildren(ScrollParent(layer->child_at(i))) |
| 892 layer->child_at(i))); | 916 ->count(layer->child_at(i))); |
| 893 } | 917 } |
| 894 } | 918 } |
| 895 | 919 |
| 896 if (layer->scroll_children()) { | 920 if (ScrollChildren(layer)) { |
| 897 for (LayerType* scroll_child : *layer->scroll_children()) { | 921 for (LayerType* scroll_child : *ScrollChildren(layer)) { |
| 898 DCHECK_EQ(scroll_child->scroll_parent(), layer); | 922 DCHECK_EQ(ScrollParent(scroll_child), layer); |
| 899 DataForRecursionFromChild<LayerType> data_from_child; | 923 DataForRecursionFromChild<LayerType> data_from_child; |
| 900 DCHECK(scroll_child->parent()); | 924 DCHECK(scroll_child->parent()); |
| 901 data_for_children.effect_tree_parent = | 925 data_for_children.effect_tree_parent = |
| 902 scroll_child->parent()->effect_tree_index(); | 926 scroll_child->parent()->effect_tree_index(); |
| 903 data_for_children.render_target = | 927 data_for_children.render_target = |
| 904 scroll_child->parent()->effect_tree_index(); | 928 scroll_child->parent()->effect_tree_index(); |
| 905 BuildPropertyTreesInternal(scroll_child, data_for_children, | 929 BuildPropertyTreesInternal(scroll_child, data_for_children, |
| 906 &data_from_child); | 930 &data_from_child); |
| 907 data_to_parent->Merge(data_from_child); | 931 data_to_parent->Merge(data_from_child); |
| 908 } | 932 } |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1058 if (SkColorGetA(color) != 255) | 1082 if (SkColorGetA(color) != 255) |
| 1059 color = SkColorSetA(color, 255); | 1083 color = SkColorSetA(color, 255); |
| 1060 BuildPropertyTreesTopLevelInternal( | 1084 BuildPropertyTreesTopLevelInternal( |
| 1061 root_layer, page_scale_layer, inner_viewport_scroll_layer, | 1085 root_layer, page_scale_layer, inner_viewport_scroll_layer, |
| 1062 outer_viewport_scroll_layer, overscroll_elasticity_layer, | 1086 outer_viewport_scroll_layer, overscroll_elasticity_layer, |
| 1063 elastic_overscroll, page_scale_factor, device_scale_factor, viewport, | 1087 elastic_overscroll, page_scale_factor, device_scale_factor, viewport, |
| 1064 device_transform, property_trees, color); | 1088 device_transform, property_trees, color); |
| 1065 } | 1089 } |
| 1066 | 1090 |
| 1067 } // namespace cc | 1091 } // namespace cc |
| OLD | NEW |