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> |
11 | 11 |
| 12 #include "cc/animation/animation_host.h" |
12 #include "cc/base/math_util.h" | 13 #include "cc/base/math_util.h" |
13 #include "cc/layers/layer.h" | 14 #include "cc/layers/layer.h" |
14 #include "cc/layers/layer_impl.h" | 15 #include "cc/layers/layer_impl.h" |
15 #include "cc/output/copy_output_request.h" | 16 #include "cc/output/copy_output_request.h" |
16 #include "cc/trees/clip_node.h" | 17 #include "cc/trees/clip_node.h" |
17 #include "cc/trees/draw_property_utils.h" | 18 #include "cc/trees/draw_property_utils.h" |
18 #include "cc/trees/effect_node.h" | 19 #include "cc/trees/effect_node.h" |
19 #include "cc/trees/layer_tree_host.h" | 20 #include "cc/trees/layer_tree_host.h" |
20 #include "cc/trees/layer_tree_impl.h" | 21 #include "cc/trees/layer_tree_impl.h" |
21 #include "cc/trees/scroll_node.h" | 22 #include "cc/trees/scroll_node.h" |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 } | 227 } |
227 | 228 |
228 static Layer* ReplicaLayer(Layer* layer) { | 229 static Layer* ReplicaLayer(Layer* layer) { |
229 return layer->replica_layer(); | 230 return layer->replica_layer(); |
230 } | 231 } |
231 | 232 |
232 static LayerImpl* ReplicaLayer(LayerImpl* layer) { | 233 static LayerImpl* ReplicaLayer(LayerImpl* layer) { |
233 return layer->test_properties()->replica_layer; | 234 return layer->test_properties()->replica_layer; |
234 } | 235 } |
235 | 236 |
| 237 // Methods to query state from the AnimationHost ---------------------- |
| 238 template <typename LayerType> |
| 239 bool OpacityIsAnimating(LayerType* layer) { |
| 240 return layer->GetAnimationHost()->IsAnimatingOpacityProperty( |
| 241 layer->element_id(), layer->GetElementTypeForAnimation()); |
| 242 } |
| 243 |
| 244 template <typename LayerType> |
| 245 bool HasPotentiallyRunningOpacityAnimation(LayerType* layer) { |
| 246 return layer->GetAnimationHost()->HasPotentiallyRunningOpacityAnimation( |
| 247 layer->element_id(), layer->GetElementTypeForAnimation()); |
| 248 } |
| 249 |
| 250 template <typename LayerType> |
| 251 bool FilterIsAnimating(LayerType* layer) { |
| 252 return layer->GetAnimationHost()->IsAnimatingFilterProperty( |
| 253 layer->element_id(), layer->GetElementTypeForAnimation()); |
| 254 } |
| 255 |
| 256 template <typename LayerType> |
| 257 bool HasPotentiallyRunningFilterAnimation(LayerType* layer) { |
| 258 return layer->GetAnimationHost()->HasPotentiallyRunningFilterAnimation( |
| 259 layer->element_id(), layer->GetElementTypeForAnimation()); |
| 260 } |
| 261 |
| 262 template <typename LayerType> |
| 263 bool TransformIsAnimating(LayerType* layer) { |
| 264 return layer->GetAnimationHost()->IsAnimatingTransformProperty( |
| 265 layer->element_id(), layer->GetElementTypeForAnimation()); |
| 266 } |
| 267 |
| 268 template <typename LayerType> |
| 269 bool HasPotentiallyRunningTransformAnimation(LayerType* layer) { |
| 270 return layer->GetAnimationHost()->HasPotentiallyRunningTransformAnimation( |
| 271 layer->element_id(), layer->GetElementTypeForAnimation()); |
| 272 } |
| 273 |
| 274 template <typename LayerType> |
| 275 bool HasOnlyTranslationTransforms(LayerType* layer) { |
| 276 return layer->GetAnimationHost()->HasOnlyTranslationTransforms( |
| 277 layer->element_id(), layer->GetElementTypeForAnimation()); |
| 278 } |
| 279 |
| 280 template <typename LayerType> |
| 281 bool AnimationsPreserveAxisAlignment(LayerType* layer) { |
| 282 return layer->GetAnimationHost()->AnimationsPreserveAxisAlignment( |
| 283 layer->element_id()); |
| 284 } |
| 285 |
| 286 template <typename LayerType> |
| 287 bool HasAnyAnimationTargetingProperty(LayerType* layer, |
| 288 TargetProperty::Type property) { |
| 289 return layer->GetAnimationHost()->HasAnyAnimationTargetingProperty( |
| 290 layer->element_id(), property); |
| 291 } |
| 292 |
| 293 // ------------------------------------------------------------------- |
| 294 |
236 template <typename LayerType> | 295 template <typename LayerType> |
237 static LayerType* GetTransformParent(const DataForRecursion<LayerType>& data, | 296 static LayerType* GetTransformParent(const DataForRecursion<LayerType>& data, |
238 LayerType* layer) { | 297 LayerType* layer) { |
239 return PositionConstraint(layer).is_fixed_position() | 298 return PositionConstraint(layer).is_fixed_position() |
240 ? data.transform_fixed_parent | 299 ? data.transform_fixed_parent |
241 : data.transform_tree_parent; | 300 : data.transform_tree_parent; |
242 } | 301 } |
243 | 302 |
244 template <typename LayerType> | 303 template <typename LayerType> |
245 static ClipNode* GetClipParent(const DataForRecursion<LayerType>& data, | 304 static ClipNode* GetClipParent(const DataForRecursion<LayerType>& data, |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 const bool is_page_scale_layer = layer == data_from_ancestor.page_scale_layer; | 482 const bool is_page_scale_layer = layer == data_from_ancestor.page_scale_layer; |
424 const bool is_overscroll_elasticity_layer = | 483 const bool is_overscroll_elasticity_layer = |
425 layer == data_from_ancestor.overscroll_elasticity_layer; | 484 layer == data_from_ancestor.overscroll_elasticity_layer; |
426 const bool is_scrollable = layer->scrollable(); | 485 const bool is_scrollable = layer->scrollable(); |
427 const bool is_fixed = PositionConstraint(layer).is_fixed_position(); | 486 const bool is_fixed = PositionConstraint(layer).is_fixed_position(); |
428 | 487 |
429 const bool has_significant_transform = | 488 const bool has_significant_transform = |
430 !layer->transform().IsIdentityOr2DTranslation(); | 489 !layer->transform().IsIdentityOr2DTranslation(); |
431 | 490 |
432 const bool has_potentially_animated_transform = | 491 const bool has_potentially_animated_transform = |
433 layer->HasPotentiallyRunningTransformAnimation(); | 492 HasPotentiallyRunningTransformAnimation(layer); |
434 | 493 |
435 // A transform node is needed even for a finished animation, since differences | 494 // A transform node is needed even for a finished animation, since differences |
436 // in the timing of animation state updates can mean that an animation that's | 495 // in the timing of animation state updates can mean that an animation that's |
437 // in the Finished state at tree-building time on the main thread is still in | 496 // in the Finished state at tree-building time on the main thread is still in |
438 // the Running state right after commit on the compositor thread. | 497 // the Running state right after commit on the compositor thread. |
439 const bool has_any_transform_animation = | 498 const bool has_any_transform_animation = |
440 layer->HasAnyAnimationTargetingProperty(TargetProperty::TRANSFORM); | 499 HasAnyAnimationTargetingProperty(layer, TargetProperty::TRANSFORM); |
441 | 500 |
442 const bool has_surface = created_render_surface; | 501 const bool has_surface = created_render_surface; |
443 | 502 |
444 // A transform node is needed to change the render target for subtree when | 503 // A transform node is needed to change the render target for subtree when |
445 // a scroll child's render target is different from the scroll parent's render | 504 // a scroll child's render target is different from the scroll parent's render |
446 // target. | 505 // target. |
447 const bool scroll_child_has_different_target = | 506 const bool scroll_child_has_different_target = |
448 ScrollParent(layer) && | 507 ScrollParent(layer) && |
449 Parent(layer)->effect_tree_index() != | 508 Parent(layer)->effect_tree_index() != |
450 ScrollParent(layer)->effect_tree_index(); | 509 ScrollParent(layer)->effect_tree_index(); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 ->transform_id); | 610 ->transform_id); |
552 data_for_children->property_trees->transform_tree.SetContentTargetId( | 611 data_for_children->property_trees->transform_tree.SetContentTargetId( |
553 node->id, data_for_children->property_trees->effect_tree | 612 node->id, data_for_children->property_trees->effect_tree |
554 .Node(data_for_children->render_target) | 613 .Node(data_for_children->render_target) |
555 ->transform_id); | 614 ->transform_id); |
556 DCHECK_NE( | 615 DCHECK_NE( |
557 data_for_children->property_trees->transform_tree.TargetId(node->id), | 616 data_for_children->property_trees->transform_tree.TargetId(node->id), |
558 kInvalidPropertyTreeNodeId); | 617 kInvalidPropertyTreeNodeId); |
559 | 618 |
560 node->has_potential_animation = has_potentially_animated_transform; | 619 node->has_potential_animation = has_potentially_animated_transform; |
561 node->is_currently_animating = layer->TransformIsAnimating(); | 620 node->is_currently_animating = TransformIsAnimating(layer); |
562 if (has_potentially_animated_transform) { | 621 if (has_potentially_animated_transform) { |
563 node->has_only_translation_animations = | 622 node->has_only_translation_animations = |
564 layer->HasOnlyTranslationTransforms(); | 623 HasOnlyTranslationTransforms(layer); |
565 } | 624 } |
566 | 625 |
567 float post_local_scale_factor = 1.0f; | 626 float post_local_scale_factor = 1.0f; |
568 if (is_root) | 627 if (is_root) |
569 post_local_scale_factor = | 628 post_local_scale_factor = |
570 data_for_children->property_trees->transform_tree.device_scale_factor(); | 629 data_for_children->property_trees->transform_tree.device_scale_factor(); |
571 | 630 |
572 if (is_page_scale_layer) { | 631 if (is_page_scale_layer) { |
573 post_local_scale_factor *= data_from_ancestor.page_scale_factor; | 632 post_local_scale_factor *= data_from_ancestor.page_scale_factor; |
574 data_for_children->property_trees->transform_tree.set_page_scale_factor( | 633 data_for_children->property_trees->transform_tree.set_page_scale_factor( |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
635 layer->set_should_flatten_transform_from_property_tree(false); | 694 layer->set_should_flatten_transform_from_property_tree(false); |
636 | 695 |
637 data_for_children->scroll_snap += node->scroll_snap; | 696 data_for_children->scroll_snap += node->scroll_snap; |
638 | 697 |
639 node->owner_id = layer->id(); | 698 node->owner_id = layer->id(); |
640 | 699 |
641 return true; | 700 return true; |
642 } | 701 } |
643 | 702 |
644 static inline bool HasPotentialOpacityAnimation(Layer* layer) { | 703 static inline bool HasPotentialOpacityAnimation(Layer* layer) { |
645 return layer->HasPotentiallyRunningOpacityAnimation() || | 704 return HasPotentiallyRunningOpacityAnimation(layer) || |
646 layer->OpacityCanAnimateOnImplThread(); | 705 layer->OpacityCanAnimateOnImplThread(); |
647 } | 706 } |
648 | 707 |
649 static inline bool HasPotentialOpacityAnimation(LayerImpl* layer) { | 708 static inline bool HasPotentialOpacityAnimation(LayerImpl* layer) { |
650 return layer->HasPotentiallyRunningOpacityAnimation() || | 709 return HasPotentiallyRunningOpacityAnimation(layer) || |
651 layer->test_properties()->opacity_can_animate; | 710 layer->test_properties()->opacity_can_animate; |
652 } | 711 } |
653 | 712 |
654 static inline bool DoubleSided(Layer* layer) { | 713 static inline bool DoubleSided(Layer* layer) { |
655 return layer->double_sided(); | 714 return layer->double_sided(); |
656 } | 715 } |
657 | 716 |
658 static inline bool DoubleSided(LayerImpl* layer) { | 717 static inline bool DoubleSided(LayerImpl* layer) { |
659 return layer->test_properties()->double_sided; | 718 return layer->test_properties()->double_sided; |
660 } | 719 } |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
738 static inline bool HasCopyRequest(LayerImpl* layer) { | 797 static inline bool HasCopyRequest(LayerImpl* layer) { |
739 return !layer->test_properties()->copy_requests.empty(); | 798 return !layer->test_properties()->copy_requests.empty(); |
740 } | 799 } |
741 | 800 |
742 template <typename LayerType> | 801 template <typename LayerType> |
743 bool ShouldCreateRenderSurface(LayerType* layer, | 802 bool ShouldCreateRenderSurface(LayerType* layer, |
744 gfx::Transform current_transform, | 803 gfx::Transform current_transform, |
745 bool axis_aligned) { | 804 bool axis_aligned) { |
746 const bool preserves_2d_axis_alignment = | 805 const bool preserves_2d_axis_alignment = |
747 (current_transform * layer->transform()).Preserves2dAxisAlignment() && | 806 (current_transform * layer->transform()).Preserves2dAxisAlignment() && |
748 axis_aligned && layer->AnimationsPreserveAxisAlignment(); | 807 axis_aligned && AnimationsPreserveAxisAlignment(layer); |
749 const bool is_root = !Parent(layer); | 808 const bool is_root = !Parent(layer); |
750 if (is_root) | 809 if (is_root) |
751 return true; | 810 return true; |
752 | 811 |
753 // If the layer uses a mask and the layer is not a replica layer. | 812 // If the layer uses a mask and the layer is not a replica layer. |
754 // TODO(weiliangc): After slimming paint there won't be replica layers. | 813 // TODO(weiliangc): After slimming paint there won't be replica layers. |
755 if (MaskLayer(layer) && ReplicaLayer(Parent(layer)) != layer) { | 814 if (MaskLayer(layer) && ReplicaLayer(Parent(layer)) != layer) { |
756 return true; | 815 return true; |
757 } | 816 } |
758 | 817 |
759 // If the layer has a reflection. | 818 // If the layer has a reflection. |
760 if (ReplicaLayer(layer)) { | 819 if (ReplicaLayer(layer)) { |
761 return true; | 820 return true; |
762 } | 821 } |
763 | 822 |
764 // If the layer uses a CSS filter. | 823 // If the layer uses a CSS filter. |
765 if (!layer->filters().IsEmpty() || !BackgroundFilters(layer).IsEmpty()) { | 824 if (!layer->filters().IsEmpty() || !BackgroundFilters(layer).IsEmpty()) { |
766 return true; | 825 return true; |
767 } | 826 } |
768 | 827 |
769 // If the layer will use a CSS filter. In this case, the animation | 828 // If the layer will use a CSS filter. In this case, the animation |
770 // will start and add a filter to this layer, so it needs a surface. | 829 // will start and add a filter to this layer, so it needs a surface. |
771 if (layer->HasPotentiallyRunningFilterAnimation()) { | 830 if (HasPotentiallyRunningFilterAnimation(layer)) { |
772 return true; | 831 return true; |
773 } | 832 } |
774 | 833 |
775 int num_descendants_that_draw_content = NumDescendantsThatDrawContent(layer); | 834 int num_descendants_that_draw_content = NumDescendantsThatDrawContent(layer); |
776 | 835 |
777 // If the layer flattens its subtree, but it is treated as a 3D object by its | 836 // If the layer flattens its subtree, but it is treated as a 3D object by its |
778 // parent (i.e. parent participates in a 3D rendering context). | 837 // parent (i.e. parent participates in a 3D rendering context). |
779 if (LayerIsInExisting3DRenderingContext(layer) && | 838 if (LayerIsInExisting3DRenderingContext(layer) && |
780 ShouldFlattenTransform(layer) && num_descendants_that_draw_content > 0) { | 839 ShouldFlattenTransform(layer) && num_descendants_that_draw_content > 0) { |
781 TRACE_EVENT_INSTANT0( | 840 TRACE_EVENT_INSTANT0( |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
865 LayerType* layer, | 924 LayerType* layer, |
866 DataForRecursion<LayerType>* data_for_children) { | 925 DataForRecursion<LayerType>* data_for_children) { |
867 const bool is_root = !Parent(layer); | 926 const bool is_root = !Parent(layer); |
868 const bool has_transparency = EffectiveOpacity(layer) != 1.f; | 927 const bool has_transparency = EffectiveOpacity(layer) != 1.f; |
869 const bool has_potential_opacity_animation = | 928 const bool has_potential_opacity_animation = |
870 HasPotentialOpacityAnimation(layer); | 929 HasPotentialOpacityAnimation(layer); |
871 const bool should_create_render_surface = ShouldCreateRenderSurface( | 930 const bool should_create_render_surface = ShouldCreateRenderSurface( |
872 layer, data_from_ancestor.compound_transform_since_render_target, | 931 layer, data_from_ancestor.compound_transform_since_render_target, |
873 data_from_ancestor.axis_align_since_render_target); | 932 data_from_ancestor.axis_align_since_render_target); |
874 data_for_children->axis_align_since_render_target &= | 933 data_for_children->axis_align_since_render_target &= |
875 layer->AnimationsPreserveAxisAlignment(); | 934 AnimationsPreserveAxisAlignment(layer); |
876 | 935 |
877 bool requires_node = is_root || has_transparency || | 936 bool requires_node = is_root || has_transparency || |
878 has_potential_opacity_animation || | 937 has_potential_opacity_animation || |
879 should_create_render_surface; | 938 should_create_render_surface; |
880 | 939 |
881 int parent_id = data_from_ancestor.effect_tree_parent; | 940 int parent_id = data_from_ancestor.effect_tree_parent; |
882 | 941 |
883 if (!requires_node) { | 942 if (!requires_node) { |
884 layer->SetEffectTreeIndex(parent_id); | 943 layer->SetEffectTreeIndex(parent_id); |
885 data_for_children->effect_tree_parent = parent_id; | 944 data_for_children->effect_tree_parent = parent_id; |
886 data_for_children->compound_transform_since_render_target *= | 945 data_for_children->compound_transform_since_render_target *= |
887 layer->transform(); | 946 layer->transform(); |
888 return false; | 947 return false; |
889 } | 948 } |
890 | 949 |
891 EffectNode node; | 950 EffectNode node; |
892 node.owner_id = layer->id(); | 951 node.owner_id = layer->id(); |
893 if (AlwaysUseActiveTreeOpacity(layer)) { | 952 if (AlwaysUseActiveTreeOpacity(layer)) { |
894 data_for_children->property_trees->always_use_active_tree_opacity_effect_ids | 953 data_for_children->property_trees->always_use_active_tree_opacity_effect_ids |
895 .push_back(node.owner_id); | 954 .push_back(node.owner_id); |
896 } | 955 } |
897 | 956 |
898 node.opacity = Opacity(layer); | 957 node.opacity = Opacity(layer); |
899 node.has_render_surface = should_create_render_surface; | 958 node.has_render_surface = should_create_render_surface; |
900 node.has_copy_request = HasCopyRequest(layer); | 959 node.has_copy_request = HasCopyRequest(layer); |
901 node.background_filters = BackgroundFilters(layer); | 960 node.background_filters = BackgroundFilters(layer); |
902 node.has_potential_opacity_animation = has_potential_opacity_animation; | 961 node.has_potential_opacity_animation = has_potential_opacity_animation; |
903 node.double_sided = DoubleSided(layer); | 962 node.double_sided = DoubleSided(layer); |
904 node.subtree_hidden = HideLayerAndSubtree(layer); | 963 node.subtree_hidden = HideLayerAndSubtree(layer); |
905 node.is_currently_animating_opacity = layer->OpacityIsAnimating(); | 964 node.is_currently_animating_opacity = OpacityIsAnimating(layer); |
906 | 965 |
907 EffectTree& effect_tree = data_for_children->property_trees->effect_tree; | 966 EffectTree& effect_tree = data_for_children->property_trees->effect_tree; |
908 if (MaskLayer(layer)) { | 967 if (MaskLayer(layer)) { |
909 node.mask_layer_id = MaskLayer(layer)->id(); | 968 node.mask_layer_id = MaskLayer(layer)->id(); |
910 effect_tree.AddMaskOrReplicaLayerId(node.mask_layer_id); | 969 effect_tree.AddMaskOrReplicaLayerId(node.mask_layer_id); |
911 } | 970 } |
912 if (ReplicaLayer(layer)) { | 971 if (ReplicaLayer(layer)) { |
913 node.replica_layer_id = ReplicaLayer(layer)->id(); | 972 node.replica_layer_id = ReplicaLayer(layer)->id(); |
914 effect_tree.AddMaskOrReplicaLayerId(node.replica_layer_id); | 973 effect_tree.AddMaskOrReplicaLayerId(node.replica_layer_id); |
915 if (MaskLayer(ReplicaLayer(layer))) { | 974 if (MaskLayer(ReplicaLayer(layer))) { |
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1379 color = SkColorSetA(color, 255); | 1438 color = SkColorSetA(color, 255); |
1380 BuildPropertyTreesTopLevelInternal( | 1439 BuildPropertyTreesTopLevelInternal( |
1381 root_layer, page_scale_layer, inner_viewport_scroll_layer, | 1440 root_layer, page_scale_layer, inner_viewport_scroll_layer, |
1382 outer_viewport_scroll_layer, overscroll_elasticity_layer, | 1441 outer_viewport_scroll_layer, overscroll_elasticity_layer, |
1383 elastic_overscroll, page_scale_factor, device_scale_factor, viewport, | 1442 elastic_overscroll, page_scale_factor, device_scale_factor, viewport, |
1384 device_transform, property_trees, color); | 1443 device_transform, property_trees, color); |
1385 property_trees->ResetCachedData(); | 1444 property_trees->ResetCachedData(); |
1386 } | 1445 } |
1387 | 1446 |
1388 } // namespace cc | 1447 } // namespace cc |
OLD | NEW |