| 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/base/math_util.h" | 12 #include "cc/base/math_util.h" |
| 13 #include "cc/layers/layer.h" | 13 #include "cc/layers/layer.h" |
| 14 #include "cc/layers/layer_impl.h" | 14 #include "cc/layers/layer_impl.h" |
| 15 #include "cc/output/copy_output_request.h" |
| 15 #include "cc/trees/draw_property_utils.h" | 16 #include "cc/trees/draw_property_utils.h" |
| 16 #include "cc/trees/layer_tree_host.h" | 17 #include "cc/trees/layer_tree_host.h" |
| 17 #include "cc/trees/layer_tree_impl.h" | 18 #include "cc/trees/layer_tree_impl.h" |
| 18 #include "ui/gfx/geometry/point_f.h" | 19 #include "ui/gfx/geometry/point_f.h" |
| 19 #include "ui/gfx/geometry/vector2d_conversions.h" | 20 #include "ui/gfx/geometry/vector2d_conversions.h" |
| 20 | 21 |
| 21 namespace cc { | 22 namespace cc { |
| 22 | 23 |
| 23 class LayerTreeHost; | 24 class LayerTreeHost; |
| 24 | 25 |
| (...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 674 } | 675 } |
| 675 | 676 |
| 676 static inline bool AlwaysUseActiveTreeOpacity(Layer* layer) { | 677 static inline bool AlwaysUseActiveTreeOpacity(Layer* layer) { |
| 677 return layer->AlwaysUseActiveTreeOpacity(); | 678 return layer->AlwaysUseActiveTreeOpacity(); |
| 678 } | 679 } |
| 679 | 680 |
| 680 static inline bool AlwaysUseActiveTreeOpacity(LayerImpl* layer) { | 681 static inline bool AlwaysUseActiveTreeOpacity(LayerImpl* layer) { |
| 681 return false; | 682 return false; |
| 682 } | 683 } |
| 683 | 684 |
| 685 static inline bool HasCopyRequest(Layer* layer) { |
| 686 return layer->HasCopyRequest(); |
| 687 } |
| 688 |
| 689 static inline bool HasCopyRequest(LayerImpl* layer) { |
| 690 return !layer->test_properties()->copy_requests.empty(); |
| 691 } |
| 692 |
| 684 template <typename LayerType> | 693 template <typename LayerType> |
| 685 bool ShouldCreateRenderSurface(LayerType* layer, | 694 bool ShouldCreateRenderSurface(LayerType* layer, |
| 686 gfx::Transform current_transform, | 695 gfx::Transform current_transform, |
| 687 bool axis_aligned) { | 696 bool axis_aligned) { |
| 688 const bool preserves_2d_axis_alignment = | 697 const bool preserves_2d_axis_alignment = |
| 689 (current_transform * layer->transform()).Preserves2dAxisAlignment() && | 698 (current_transform * layer->transform()).Preserves2dAxisAlignment() && |
| 690 axis_aligned && layer->AnimationsPreserveAxisAlignment(); | 699 axis_aligned && layer->AnimationsPreserveAxisAlignment(); |
| 691 const bool is_root = !layer->parent(); | 700 const bool is_root = !layer->parent(); |
| 692 if (is_root) | 701 if (is_root) |
| 693 return true; | 702 return true; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 774 "cc", "PropertyTreeBuilder::ShouldCreateRenderSurface isolation", | 783 "cc", "PropertyTreeBuilder::ShouldCreateRenderSurface isolation", |
| 775 TRACE_EVENT_SCOPE_THREAD); | 784 TRACE_EVENT_SCOPE_THREAD); |
| 776 return true; | 785 return true; |
| 777 } | 786 } |
| 778 | 787 |
| 779 // If we force it. | 788 // If we force it. |
| 780 if (ForceRenderSurface(layer)) | 789 if (ForceRenderSurface(layer)) |
| 781 return true; | 790 return true; |
| 782 | 791 |
| 783 // If we'll make a copy of the layer's contents. | 792 // If we'll make a copy of the layer's contents. |
| 784 if (layer->HasCopyRequest()) | 793 if (HasCopyRequest(layer)) |
| 785 return true; | 794 return true; |
| 786 | 795 |
| 787 return false; | 796 return false; |
| 788 } | 797 } |
| 789 | 798 |
| 799 static void TakeCopyRequests( |
| 800 Layer* layer, |
| 801 std::vector<std::unique_ptr<CopyOutputRequest>>* copy_requests) { |
| 802 layer->TakeCopyRequests(copy_requests); |
| 803 } |
| 804 |
| 805 static void TakeCopyRequests( |
| 806 LayerImpl* layer, |
| 807 std::vector<std::unique_ptr<CopyOutputRequest>>* copy_requests) { |
| 808 for (auto& request : layer->test_properties()->copy_requests) |
| 809 copy_requests->push_back(std::move(request)); |
| 810 layer->test_properties()->copy_requests.clear(); |
| 811 } |
| 812 |
| 790 template <typename LayerType> | 813 template <typename LayerType> |
| 791 bool AddEffectNodeIfNeeded( | 814 bool AddEffectNodeIfNeeded( |
| 792 const DataForRecursion<LayerType>& data_from_ancestor, | 815 const DataForRecursion<LayerType>& data_from_ancestor, |
| 793 LayerType* layer, | 816 LayerType* layer, |
| 794 DataForRecursion<LayerType>* data_for_children) { | 817 DataForRecursion<LayerType>* data_for_children) { |
| 795 const bool is_root = !layer->parent(); | 818 const bool is_root = !layer->parent(); |
| 796 const bool has_transparency = EffectiveOpacity(layer) != 1.f; | 819 const bool has_transparency = EffectiveOpacity(layer) != 1.f; |
| 797 const bool has_potential_opacity_animation = | 820 const bool has_potential_opacity_animation = |
| 798 HasPotentialOpacityAnimation(layer); | 821 HasPotentialOpacityAnimation(layer); |
| 799 const bool should_create_render_surface = ShouldCreateRenderSurface( | 822 const bool should_create_render_surface = ShouldCreateRenderSurface( |
| (...skipping 18 matching lines...) Expand all Loading... |
| 818 | 841 |
| 819 EffectNode node; | 842 EffectNode node; |
| 820 node.owner_id = layer->id(); | 843 node.owner_id = layer->id(); |
| 821 if (AlwaysUseActiveTreeOpacity(layer)) { | 844 if (AlwaysUseActiveTreeOpacity(layer)) { |
| 822 data_for_children->property_trees->always_use_active_tree_opacity_effect_ids | 845 data_for_children->property_trees->always_use_active_tree_opacity_effect_ids |
| 823 .push_back(node.owner_id); | 846 .push_back(node.owner_id); |
| 824 } | 847 } |
| 825 | 848 |
| 826 node.data.opacity = layer->opacity(); | 849 node.data.opacity = layer->opacity(); |
| 827 node.data.has_render_surface = should_create_render_surface; | 850 node.data.has_render_surface = should_create_render_surface; |
| 828 node.data.has_copy_request = layer->HasCopyRequest(); | 851 node.data.has_copy_request = HasCopyRequest(layer); |
| 829 node.data.has_background_filters = !layer->background_filters().IsEmpty(); | 852 node.data.has_background_filters = !layer->background_filters().IsEmpty(); |
| 830 node.data.has_potential_opacity_animation = has_potential_opacity_animation; | 853 node.data.has_potential_opacity_animation = has_potential_opacity_animation; |
| 831 node.data.double_sided = DoubleSided(layer); | 854 node.data.double_sided = DoubleSided(layer); |
| 832 node.data.subtree_hidden = HideLayerAndSubtree(layer); | 855 node.data.subtree_hidden = HideLayerAndSubtree(layer); |
| 833 node.data.is_currently_animating_opacity = layer->OpacityIsAnimating(); | 856 node.data.is_currently_animating_opacity = layer->OpacityIsAnimating(); |
| 834 | 857 |
| 835 if (!is_root) { | 858 if (!is_root) { |
| 836 // The effect node's transform id is used only when we create a render | 859 // The effect node's transform id is used only when we create a render |
| 837 // surface. So, we can leave the default value when we don't create a render | 860 // surface. So, we can leave the default value when we don't create a render |
| 838 // surface. | 861 // surface. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 849 } else { | 872 } else { |
| 850 // Root render surface acts the unbounded and untransformed to draw content | 873 // Root render surface acts the unbounded and untransformed to draw content |
| 851 // into. Transform node created from root layer (includes device scale | 874 // into. Transform node created from root layer (includes device scale |
| 852 // factor) and clip node created from root layer (include viewports) applies | 875 // factor) and clip node created from root layer (include viewports) applies |
| 853 // to root render surface's content, but not root render surface itself. | 876 // to root render surface's content, but not root render surface itself. |
| 854 node.data.transform_id = kRootPropertyTreeNodeId; | 877 node.data.transform_id = kRootPropertyTreeNodeId; |
| 855 node.data.clip_id = kViewportClipTreeNodeId; | 878 node.data.clip_id = kViewportClipTreeNodeId; |
| 856 } | 879 } |
| 857 data_for_children->effect_tree_parent = | 880 data_for_children->effect_tree_parent = |
| 858 data_for_children->property_trees->effect_tree.Insert(node, parent_id); | 881 data_for_children->property_trees->effect_tree.Insert(node, parent_id); |
| 859 layer->SetEffectTreeIndex(data_for_children->effect_tree_parent); | 882 int node_id = data_for_children->effect_tree_parent; |
| 883 layer->SetEffectTreeIndex(node_id); |
| 860 data_for_children->property_trees->effect_id_to_index_map[layer->id()] = | 884 data_for_children->property_trees->effect_id_to_index_map[layer->id()] = |
| 861 data_for_children->effect_tree_parent; | 885 data_for_children->effect_tree_parent; |
| 886 |
| 887 std::vector<std::unique_ptr<CopyOutputRequest>> layer_copy_requests; |
| 888 TakeCopyRequests(layer, &layer_copy_requests); |
| 889 for (auto& it : layer_copy_requests) { |
| 890 data_for_children->property_trees->effect_tree.AddCopyRequest( |
| 891 node_id, std::move(it)); |
| 892 } |
| 893 layer_copy_requests.clear(); |
| 894 |
| 862 if (should_create_render_surface) { | 895 if (should_create_render_surface) { |
| 863 data_for_children->compound_transform_since_render_target = | 896 data_for_children->compound_transform_since_render_target = |
| 864 gfx::Transform(); | 897 gfx::Transform(); |
| 865 data_for_children->axis_align_since_render_target = true; | 898 data_for_children->axis_align_since_render_target = true; |
| 866 } | 899 } |
| 867 return should_create_render_surface; | 900 return should_create_render_surface; |
| 868 } | 901 } |
| 869 | 902 |
| 870 template <typename LayerType> | 903 template <typename LayerType> |
| 871 void AddScrollNodeIfNeeded( | 904 void AddScrollNodeIfNeeded( |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1071 } | 1104 } |
| 1072 } | 1105 } |
| 1073 | 1106 |
| 1074 if (layer->has_replica()) { | 1107 if (layer->has_replica()) { |
| 1075 DataForRecursionFromChild<LayerType> data_from_child; | 1108 DataForRecursionFromChild<LayerType> data_from_child; |
| 1076 BuildPropertyTreesInternal(layer->replica_layer(), data_for_children, | 1109 BuildPropertyTreesInternal(layer->replica_layer(), data_for_children, |
| 1077 &data_from_child); | 1110 &data_from_child); |
| 1078 data_to_parent->Merge(data_from_child); | 1111 data_to_parent->Merge(data_from_child); |
| 1079 } | 1112 } |
| 1080 | 1113 |
| 1081 if (layer->HasCopyRequest()) | 1114 EffectNode* effect_node = data_for_children.property_trees->effect_tree.Node( |
| 1082 data_to_parent->num_copy_requests_in_subtree++; | 1115 data_for_children.effect_tree_parent); |
| 1083 | 1116 |
| 1084 if (data_for_children.property_trees->effect_tree | 1117 if (effect_node->owner_id == layer->id()) { |
| 1085 .Node(data_for_children.effect_tree_parent) | 1118 if (effect_node->data.has_copy_request) |
| 1086 ->owner_id == layer->id()) | 1119 data_to_parent->num_copy_requests_in_subtree++; |
| 1087 data_for_children.property_trees->effect_tree | 1120 effect_node->data.num_copy_requests_in_subtree = |
| 1088 .Node(data_for_children.effect_tree_parent) | |
| 1089 ->data.num_copy_requests_in_subtree = | |
| 1090 data_to_parent->num_copy_requests_in_subtree; | 1121 data_to_parent->num_copy_requests_in_subtree; |
| 1122 } |
| 1091 } | 1123 } |
| 1092 | 1124 |
| 1093 } // namespace | 1125 } // namespace |
| 1094 | 1126 |
| 1095 void CC_EXPORT | 1127 void CC_EXPORT |
| 1096 PropertyTreeBuilder::PreCalculateMetaInformation(Layer* root_layer) { | 1128 PropertyTreeBuilder::PreCalculateMetaInformation(Layer* root_layer) { |
| 1097 PreCalculateMetaInformationRecursiveData recursive_data; | 1129 PreCalculateMetaInformationRecursiveData recursive_data; |
| 1098 PreCalculateMetaInformationInternal(root_layer, &recursive_data); | 1130 PreCalculateMetaInformationInternal(root_layer, &recursive_data); |
| 1099 } | 1131 } |
| 1100 | 1132 |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1277 if (SkColorGetA(color) != 255) | 1309 if (SkColorGetA(color) != 255) |
| 1278 color = SkColorSetA(color, 255); | 1310 color = SkColorSetA(color, 255); |
| 1279 BuildPropertyTreesTopLevelInternal( | 1311 BuildPropertyTreesTopLevelInternal( |
| 1280 root_layer, page_scale_layer, inner_viewport_scroll_layer, | 1312 root_layer, page_scale_layer, inner_viewport_scroll_layer, |
| 1281 outer_viewport_scroll_layer, overscroll_elasticity_layer, | 1313 outer_viewport_scroll_layer, overscroll_elasticity_layer, |
| 1282 elastic_overscroll, page_scale_factor, device_scale_factor, viewport, | 1314 elastic_overscroll, page_scale_factor, device_scale_factor, viewport, |
| 1283 device_transform, property_trees, color); | 1315 device_transform, property_trees, color); |
| 1284 } | 1316 } |
| 1285 | 1317 |
| 1286 } // namespace cc | 1318 } // namespace cc |
| OLD | NEW |