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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
764 void TransformTree::ResetChangeTracking() { | 764 void TransformTree::ResetChangeTracking() { |
765 for (int id = 1; id < static_cast<int>(size()); ++id) { | 765 for (int id = 1; id < static_cast<int>(size()); ++id) { |
766 TransformNode* node = Node(id); | 766 TransformNode* node = Node(id); |
767 node->data.transform_changed = false; | 767 node->data.transform_changed = false; |
768 } | 768 } |
769 } | 769 } |
770 | 770 |
771 void TransformTree::UpdateTransforms(int id) { | 771 void TransformTree::UpdateTransforms(int id) { |
772 TransformNode* node = Node(id); | 772 TransformNode* node = Node(id); |
773 TransformNode* parent_node = parent(node); | 773 TransformNode* parent_node = parent(node); |
774 TransformNode* target_node = Node(node->data.target_id); | 774 TransformNode* target_node = Node(TargetId(id)); |
775 TransformNode* source_node = Node(node->data.source_node_id); | 775 TransformNode* source_node = Node(node->data.source_node_id); |
776 if (node->data.needs_local_transform_update || | 776 if (node->data.needs_local_transform_update || |
777 NeedsSourceToParentUpdate(node)) | 777 NeedsSourceToParentUpdate(node)) |
778 UpdateLocalTransform(node); | 778 UpdateLocalTransform(node); |
779 else | 779 else |
780 UndoSnapping(node); | 780 UndoSnapping(node); |
781 UpdateScreenSpaceTransform(node, parent_node, target_node); | 781 UpdateScreenSpaceTransform(node, parent_node, target_node); |
782 UpdateSublayerScale(node); | 782 UpdateSublayerScale(node); |
783 UpdateTargetSpaceTransform(node, target_node); | 783 UpdateTargetSpaceTransform(node, target_node); |
784 UpdateAnimationProperties(node, parent_node); | 784 UpdateAnimationProperties(node, parent_node); |
(...skipping 23 matching lines...) Expand all Loading... |
808 // non-trivial flattening between the source and destination nodes. For | 808 // non-trivial flattening between the source and destination nodes. For |
809 // example, consider the tree R->A->B->C, where B flattens its inherited | 809 // example, consider the tree R->A->B->C, where B flattens its inherited |
810 // transform, and A has a non-flat transform. Suppose C is the source and A is | 810 // transform, and A has a non-flat transform. Suppose C is the source and A is |
811 // the destination. The expected result is C * B. But C's to_screen | 811 // the destination. The expected result is C * B. But C's to_screen |
812 // transform is C * B * flattened(A * R), and A's from_screen transform is | 812 // transform is C * B * flattened(A * R), and A's from_screen transform is |
813 // R^{-1} * A^{-1}. If at least one of A and R isn't flat, the inverse of | 813 // R^{-1} * A^{-1}. If at least one of A and R isn't flat, the inverse of |
814 // flattened(A * R) won't be R^{-1} * A{-1}, so multiplying C's to_screen and | 814 // flattened(A * R) won't be R^{-1} * A{-1}, so multiplying C's to_screen and |
815 // A's from_screen will not produce the correct result. | 815 // A's from_screen will not produce the correct result. |
816 if (!dest || (dest->data.ancestors_are_invertible && | 816 if (!dest || (dest->data.ancestors_are_invertible && |
817 dest->data.node_and_ancestors_are_flat)) { | 817 dest->data.node_and_ancestors_are_flat)) { |
818 transform->ConcatTransform(current->data.to_screen); | 818 transform->ConcatTransform(ToScreen(current->id)); |
819 if (dest) | 819 if (dest) |
820 transform->ConcatTransform(dest->data.from_screen); | 820 transform->ConcatTransform(dest->data.from_screen); |
821 return true; | 821 return true; |
822 } | 822 } |
823 | 823 |
824 // Flattening is defined in a way that requires it to be applied while | 824 // Flattening is defined in a way that requires it to be applied while |
825 // traversing downward in the tree. We first identify nodes that are on the | 825 // traversing downward in the tree. We first identify nodes that are on the |
826 // path from the source to the destination (this is traversing upward), and | 826 // path from the source to the destination (this is traversing upward), and |
827 // then we visit these nodes in reverse order, flattening as needed. We | 827 // then we visit these nodes in reverse order, flattening as needed. We |
828 // early-out if we get to a node whose target node is the destination, since | 828 // early-out if we get to a node whose target node is the destination, since |
829 // we can then re-use the target space transform stored at that node. However, | 829 // we can then re-use the target space transform stored at that node. However, |
830 // we cannot re-use a stored target space transform if the destination has a | 830 // we cannot re-use a stored target space transform if the destination has a |
831 // zero sublayer scale, since stored target space transforms have sublayer | 831 // zero sublayer scale, since stored target space transforms have sublayer |
832 // scale baked in, but we need to compute an unscaled transform. | 832 // scale baked in, but we need to compute an unscaled transform. |
833 std::vector<int> source_to_destination; | 833 std::vector<int> source_to_destination; |
834 source_to_destination.push_back(current->id); | 834 source_to_destination.push_back(current->id); |
835 current = parent(current); | 835 current = parent(current); |
836 bool destination_has_non_zero_sublayer_scale = | 836 bool destination_has_non_zero_sublayer_scale = |
837 dest->data.sublayer_scale.x() != 0.f && | 837 dest->data.sublayer_scale.x() != 0.f && |
838 dest->data.sublayer_scale.y() != 0.f; | 838 dest->data.sublayer_scale.y() != 0.f; |
839 DCHECK(destination_has_non_zero_sublayer_scale || | 839 DCHECK(destination_has_non_zero_sublayer_scale || |
840 !dest->data.ancestors_are_invertible); | 840 !dest->data.ancestors_are_invertible); |
841 for (; current && current->id > dest_id; current = parent(current)) { | 841 for (; current && current->id > dest_id; current = parent(current)) { |
842 if (destination_has_non_zero_sublayer_scale && | 842 if (destination_has_non_zero_sublayer_scale && |
843 current->data.target_id == dest_id && | 843 TargetId(current->id) == dest_id && |
844 current->data.content_target_id == dest_id) | 844 ContentTargetId(current->id) == dest_id) |
845 break; | 845 break; |
846 source_to_destination.push_back(current->id); | 846 source_to_destination.push_back(current->id); |
847 } | 847 } |
848 | 848 |
849 gfx::Transform combined_transform; | 849 gfx::Transform combined_transform; |
850 if (current->id > dest_id) { | 850 if (current->id > dest_id) { |
851 combined_transform = current->data.to_target; | 851 combined_transform = ToTarget(current->id); |
852 // The stored target space transform has sublayer scale baked in, but we | 852 // The stored target space transform has sublayer scale baked in, but we |
853 // need the unscaled transform. | 853 // need the unscaled transform. |
854 combined_transform.matrix().postScale(1.0f / dest->data.sublayer_scale.x(), | 854 combined_transform.matrix().postScale(1.0f / dest->data.sublayer_scale.x(), |
855 1.0f / dest->data.sublayer_scale.y(), | 855 1.0f / dest->data.sublayer_scale.y(), |
856 1.0f); | 856 1.0f); |
857 } else if (current->id < dest_id) { | 857 } else if (current->id < dest_id) { |
858 // We have reached the lowest common ancestor of the source and destination | 858 // We have reached the lowest common ancestor of the source and destination |
859 // nodes. This case can occur when we are transforming between a node | 859 // nodes. This case can occur when we are transforming between a node |
860 // corresponding to a fixed-position layer (or its descendant) and the node | 860 // corresponding to a fixed-position layer (or its descendant) and the node |
861 // corresponding to the layer's render target. For example, consider the | 861 // corresponding to the layer's render target. For example, consider the |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
897 DCHECK(source_id < dest_id); | 897 DCHECK(source_id < dest_id); |
898 const TransformNode* current = Node(dest_id); | 898 const TransformNode* current = Node(dest_id); |
899 const TransformNode* dest = Node(source_id); | 899 const TransformNode* dest = Node(source_id); |
900 // Just as in CombineTransformsBetween, we can use screen space transforms in | 900 // Just as in CombineTransformsBetween, we can use screen space transforms in |
901 // this computation only when there isn't any non-trivial flattening | 901 // this computation only when there isn't any non-trivial flattening |
902 // involved. | 902 // involved. |
903 if (current->data.ancestors_are_invertible && | 903 if (current->data.ancestors_are_invertible && |
904 current->data.node_and_ancestors_are_flat) { | 904 current->data.node_and_ancestors_are_flat) { |
905 transform->PreconcatTransform(current->data.from_screen); | 905 transform->PreconcatTransform(current->data.from_screen); |
906 if (dest) | 906 if (dest) |
907 transform->PreconcatTransform(dest->data.to_screen); | 907 transform->PreconcatTransform(ToScreen(dest->id)); |
908 return true; | 908 return true; |
909 } | 909 } |
910 | 910 |
911 // Inverting a flattening is not equivalent to flattening an inverse. This | 911 // Inverting a flattening is not equivalent to flattening an inverse. This |
912 // means we cannot, for example, use the inverse of each node's to_parent | 912 // means we cannot, for example, use the inverse of each node's to_parent |
913 // transform, flattening where needed. Instead, we must compute the transform | 913 // transform, flattening where needed. Instead, we must compute the transform |
914 // from the destination to the source, with flattening, and then invert the | 914 // from the destination to the source, with flattening, and then invert the |
915 // result. | 915 // result. |
916 gfx::Transform dest_to_source; | 916 gfx::Transform dest_to_source; |
917 CombineTransformsBetween(dest_id, source_id, &dest_to_source); | 917 CombineTransformsBetween(dest_id, source_id, &dest_to_source); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
952 transform.PreconcatTransform(node->data.local); | 952 transform.PreconcatTransform(node->data.local); |
953 transform.PreconcatTransform(node->data.pre_local); | 953 transform.PreconcatTransform(node->data.pre_local); |
954 node->data.set_to_parent(transform); | 954 node->data.set_to_parent(transform); |
955 node->data.needs_local_transform_update = false; | 955 node->data.needs_local_transform_update = false; |
956 } | 956 } |
957 | 957 |
958 void TransformTree::UpdateScreenSpaceTransform(TransformNode* node, | 958 void TransformTree::UpdateScreenSpaceTransform(TransformNode* node, |
959 TransformNode* parent_node, | 959 TransformNode* parent_node, |
960 TransformNode* target_node) { | 960 TransformNode* target_node) { |
961 if (!parent_node) { | 961 if (!parent_node) { |
962 node->data.to_screen = node->data.to_parent; | 962 SetToScreen(node->id, node->data.to_parent); |
963 node->data.ancestors_are_invertible = true; | 963 node->data.ancestors_are_invertible = true; |
964 node->data.to_screen_is_potentially_animated = false; | 964 node->data.to_screen_is_potentially_animated = false; |
965 node->data.node_and_ancestors_are_flat = node->data.to_parent.IsFlat(); | 965 node->data.node_and_ancestors_are_flat = node->data.to_parent.IsFlat(); |
966 } else { | 966 } else { |
967 node->data.to_screen = parent_node->data.to_screen; | 967 gfx::Transform to_screen_space_transform = parent_node->data.to_screen; |
968 if (node->data.flattens_inherited_transform) | 968 if (node->data.flattens_inherited_transform) |
969 node->data.to_screen.FlattenTo2d(); | 969 to_screen_space_transform.FlattenTo2d(); |
970 node->data.to_screen.PreconcatTransform(node->data.to_parent); | 970 to_screen_space_transform.PreconcatTransform(node->data.to_parent); |
971 node->data.ancestors_are_invertible = | 971 node->data.ancestors_are_invertible = |
972 parent_node->data.ancestors_are_invertible; | 972 parent_node->data.ancestors_are_invertible; |
973 node->data.node_and_ancestors_are_flat = | 973 node->data.node_and_ancestors_are_flat = |
974 parent_node->data.node_and_ancestors_are_flat && | 974 parent_node->data.node_and_ancestors_are_flat && |
975 node->data.to_parent.IsFlat(); | 975 node->data.to_parent.IsFlat(); |
| 976 SetToScreen(node->id, to_screen_space_transform); |
976 } | 977 } |
977 | 978 |
978 if (!node->data.to_screen.GetInverse(&node->data.from_screen)) | 979 if (!ToScreen(node->id).GetInverse(&node->data.from_screen)) |
979 node->data.ancestors_are_invertible = false; | 980 node->data.ancestors_are_invertible = false; |
980 } | 981 } |
981 | 982 |
982 void TransformTree::UpdateSublayerScale(TransformNode* node) { | 983 void TransformTree::UpdateSublayerScale(TransformNode* node) { |
983 // The sublayer scale depends on the screen space transform, so update it too. | 984 // The sublayer scale depends on the screen space transform, so update it too. |
984 if (!node->data.needs_sublayer_scale) { | 985 if (!node->data.needs_sublayer_scale) { |
985 node->data.sublayer_scale = gfx::Vector2dF(1.0f, 1.0f); | 986 node->data.sublayer_scale = gfx::Vector2dF(1.0f, 1.0f); |
986 return; | 987 return; |
987 } | 988 } |
988 | 989 |
989 float layer_scale_factor = | 990 float layer_scale_factor = |
990 device_scale_factor_ * device_transform_scale_factor_; | 991 device_scale_factor_ * device_transform_scale_factor_; |
991 if (node->data.in_subtree_of_page_scale_layer) | 992 if (node->data.in_subtree_of_page_scale_layer) |
992 layer_scale_factor *= page_scale_factor_; | 993 layer_scale_factor *= page_scale_factor_; |
993 node->data.sublayer_scale = MathUtil::ComputeTransform2dScaleComponents( | 994 node->data.sublayer_scale = MathUtil::ComputeTransform2dScaleComponents( |
994 node->data.to_screen, layer_scale_factor); | 995 ToScreen(node->id), layer_scale_factor); |
995 } | 996 } |
996 | 997 |
997 void TransformTree::UpdateTargetSpaceTransform(TransformNode* node, | 998 void TransformTree::UpdateTargetSpaceTransform(TransformNode* node, |
998 TransformNode* target_node) { | 999 TransformNode* target_node) { |
| 1000 gfx::Transform target_space_transform; |
999 if (node->data.needs_sublayer_scale) { | 1001 if (node->data.needs_sublayer_scale) { |
1000 node->data.to_target.MakeIdentity(); | 1002 target_space_transform.MakeIdentity(); |
1001 node->data.to_target.Scale(node->data.sublayer_scale.x(), | 1003 target_space_transform.Scale(node->data.sublayer_scale.x(), |
1002 node->data.sublayer_scale.y()); | 1004 node->data.sublayer_scale.y()); |
1003 } else { | 1005 } else { |
1004 // In order to include the root transform for the root surface, we walk up | 1006 // In order to include the root transform for the root surface, we walk up |
1005 // to the root of the transform tree in ComputeTransform. | 1007 // to the root of the transform tree in ComputeTransform. |
1006 int target_id = target_node->id; | 1008 int target_id = target_node->id; |
1007 ComputeTransformWithDestinationSublayerScale(node->id, target_id, | 1009 ComputeTransformWithDestinationSublayerScale(node->id, target_id, |
1008 &node->data.to_target); | 1010 &target_space_transform); |
1009 } | 1011 } |
1010 | 1012 |
1011 if (!node->data.to_target.GetInverse(&node->data.from_target)) | 1013 if (!target_space_transform.GetInverse(&node->data.from_target)) |
1012 node->data.ancestors_are_invertible = false; | 1014 node->data.ancestors_are_invertible = false; |
| 1015 SetToTarget(node->id, target_space_transform); |
1013 } | 1016 } |
1014 | 1017 |
1015 void TransformTree::UpdateAnimationProperties(TransformNode* node, | 1018 void TransformTree::UpdateAnimationProperties(TransformNode* node, |
1016 TransformNode* parent_node) { | 1019 TransformNode* parent_node) { |
1017 bool ancestor_is_animating = false; | 1020 bool ancestor_is_animating = false; |
1018 bool ancestor_is_animating_scale = false; | 1021 bool ancestor_is_animating_scale = false; |
1019 float ancestor_maximum_target_scale = 0.f; | 1022 float ancestor_maximum_target_scale = 0.f; |
1020 float ancestor_starting_animation_scale = 0.f; | 1023 float ancestor_starting_animation_scale = 0.f; |
1021 if (parent_node) { | 1024 if (parent_node) { |
1022 ancestor_is_animating = parent_node->data.to_screen_is_potentially_animated; | 1025 ancestor_is_animating = parent_node->data.to_screen_is_potentially_animated; |
(...skipping 11 matching lines...) Expand all Loading... |
1034 ancestor_is_animating_scale; | 1037 ancestor_is_animating_scale; |
1035 | 1038 |
1036 // Once we've failed to compute a maximum animated scale at an ancestor, we | 1039 // Once we've failed to compute a maximum animated scale at an ancestor, we |
1037 // continue to fail. | 1040 // continue to fail. |
1038 bool failed_at_ancestor = | 1041 bool failed_at_ancestor = |
1039 ancestor_is_animating_scale && ancestor_maximum_target_scale == 0.f; | 1042 ancestor_is_animating_scale && ancestor_maximum_target_scale == 0.f; |
1040 | 1043 |
1041 // Computing maximum animated scale in the presence of non-scale/translation | 1044 // Computing maximum animated scale in the presence of non-scale/translation |
1042 // transforms isn't supported. | 1045 // transforms isn't supported. |
1043 bool failed_for_non_scale_or_translation = | 1046 bool failed_for_non_scale_or_translation = |
1044 !node->data.to_target.IsScaleOrTranslation(); | 1047 !ToTarget(node->id).IsScaleOrTranslation(); |
1045 | 1048 |
1046 // We don't attempt to accumulate animation scale from multiple nodes with | 1049 // We don't attempt to accumulate animation scale from multiple nodes with |
1047 // scale animations, because of the risk of significant overestimation. For | 1050 // scale animations, because of the risk of significant overestimation. For |
1048 // example, one node might be increasing scale from 1 to 10 at the same time | 1051 // example, one node might be increasing scale from 1 to 10 at the same time |
1049 // as another node is decreasing scale from 10 to 1. Naively combining these | 1052 // as another node is decreasing scale from 10 to 1. Naively combining these |
1050 // scales would produce a scale of 100. | 1053 // scales would produce a scale of 100. |
1051 bool failed_for_multiple_scale_animations = | 1054 bool failed_for_multiple_scale_animations = |
1052 ancestor_is_animating_scale && | 1055 ancestor_is_animating_scale && |
1053 !node->data.has_only_translation_animations; | 1056 !node->data.has_only_translation_animations; |
1054 | 1057 |
(...skipping 30 matching lines...) Expand all Loading... |
1085 | 1088 |
1086 if (node->data.local_starting_animation_scale == 0.f || | 1089 if (node->data.local_starting_animation_scale == 0.f || |
1087 node->data.local_maximum_animation_target_scale == 0.f) { | 1090 node->data.local_maximum_animation_target_scale == 0.f) { |
1088 node->data.combined_maximum_animation_target_scale = 0.f; | 1091 node->data.combined_maximum_animation_target_scale = 0.f; |
1089 node->data.combined_starting_animation_scale = 0.f; | 1092 node->data.combined_starting_animation_scale = 0.f; |
1090 return; | 1093 return; |
1091 } | 1094 } |
1092 | 1095 |
1093 gfx::Vector2dF ancestor_scales = | 1096 gfx::Vector2dF ancestor_scales = |
1094 parent_node ? MathUtil::ComputeTransform2dScaleComponents( | 1097 parent_node ? MathUtil::ComputeTransform2dScaleComponents( |
1095 parent_node->data.to_target, 0.f) | 1098 ToTarget(parent_node->id), 0.f) |
1096 : gfx::Vector2dF(1.f, 1.f); | 1099 : gfx::Vector2dF(1.f, 1.f); |
1097 float max_ancestor_scale = std::max(ancestor_scales.x(), ancestor_scales.y()); | 1100 float max_ancestor_scale = std::max(ancestor_scales.x(), ancestor_scales.y()); |
1098 node->data.combined_maximum_animation_target_scale = | 1101 node->data.combined_maximum_animation_target_scale = |
1099 max_ancestor_scale * node->data.local_maximum_animation_target_scale; | 1102 max_ancestor_scale * node->data.local_maximum_animation_target_scale; |
1100 node->data.combined_starting_animation_scale = | 1103 node->data.combined_starting_animation_scale = |
1101 max_ancestor_scale * node->data.local_starting_animation_scale; | 1104 max_ancestor_scale * node->data.local_starting_animation_scale; |
1102 } | 1105 } |
1103 | 1106 |
1104 void TransformTree::UndoSnapping(TransformNode* node) { | 1107 void TransformTree::UndoSnapping(TransformNode* node) { |
1105 // to_parent transform has the scroll snap from previous frame baked in. | 1108 // to_parent transform has the scroll snap from previous frame baked in. |
1106 // We need to undo it and use the un-snapped transform to compute current | 1109 // We need to undo it and use the un-snapped transform to compute current |
1107 // target and screen space transforms. | 1110 // target and screen space transforms. |
1108 node->data.to_parent.Translate(-node->data.scroll_snap.x(), | 1111 node->data.to_parent.Translate(-node->data.scroll_snap.x(), |
1109 -node->data.scroll_snap.y()); | 1112 -node->data.scroll_snap.y()); |
1110 } | 1113 } |
1111 | 1114 |
1112 void TransformTree::UpdateSnapping(TransformNode* node) { | 1115 void TransformTree::UpdateSnapping(TransformNode* node) { |
1113 if (!node->data.scrolls || node->data.to_screen_is_potentially_animated || | 1116 if (!node->data.scrolls || node->data.to_screen_is_potentially_animated || |
1114 !node->data.to_screen.IsScaleOrTranslation() || | 1117 !ToScreen(node->id).IsScaleOrTranslation() || |
1115 !node->data.ancestors_are_invertible) { | 1118 !node->data.ancestors_are_invertible) { |
1116 return; | 1119 return; |
1117 } | 1120 } |
1118 | 1121 |
1119 // Scroll snapping must be done in screen space (the pixels we care about). | 1122 // Scroll snapping must be done in screen space (the pixels we care about). |
1120 // This means we effectively snap the screen space transform. If ST is the | 1123 // This means we effectively snap the screen space transform. If ST is the |
1121 // screen space transform and ST' is ST with its translation components | 1124 // screen space transform and ST' is ST with its translation components |
1122 // rounded, then what we're after is the scroll delta X, where ST * X = ST'. | 1125 // rounded, then what we're after is the scroll delta X, where ST * X = ST'. |
1123 // I.e., we want a transform that will realize our scroll snap. It follows | 1126 // I.e., we want a transform that will realize our scroll snap. It follows |
1124 // that X = ST^-1 * ST'. We cache ST and ST^-1 to make this more efficient. | 1127 // that X = ST^-1 * ST'. We cache ST and ST^-1 to make this more efficient. |
1125 gfx::Transform rounded = node->data.to_screen; | 1128 gfx::Transform rounded = ToScreen(node->id); |
1126 rounded.RoundTranslationComponents(); | 1129 rounded.RoundTranslationComponents(); |
1127 gfx::Transform delta = node->data.from_screen; | 1130 gfx::Transform delta = node->data.from_screen; |
1128 delta *= rounded; | 1131 delta *= rounded; |
1129 | 1132 |
1130 DCHECK(delta.IsApproximatelyIdentityOrTranslation(SkDoubleToMScalar(1e-4))) | 1133 DCHECK(delta.IsApproximatelyIdentityOrTranslation(SkDoubleToMScalar(1e-4))) |
1131 << delta.ToString(); | 1134 << delta.ToString(); |
1132 | 1135 |
1133 gfx::Vector2dF translation = delta.To2dTranslation(); | 1136 gfx::Vector2dF translation = delta.To2dTranslation(); |
1134 | 1137 |
1135 // Now that we have our scroll delta, we must apply it to each of our | 1138 // Now that we have our scroll delta, we must apply it to each of our |
1136 // combined, to/from matrices. | 1139 // combined, to/from matrices. |
1137 node->data.to_screen = rounded; | 1140 SetToScreen(node->id, rounded); |
1138 node->data.to_parent.Translate(translation.x(), translation.y()); | 1141 node->data.to_parent.Translate(translation.x(), translation.y()); |
1139 node->data.from_screen.matrix().postTranslate(-translation.x(), | 1142 node->data.from_screen.matrix().postTranslate(-translation.x(), |
1140 -translation.y(), 0); | 1143 -translation.y(), 0); |
1141 node->data.to_target.Translate(translation.x(), translation.y()); | 1144 gfx::Transform to_target = ToTarget(node->id); |
| 1145 to_target.Translate(translation.x(), translation.y()); |
| 1146 SetToTarget(node->id, to_target); |
1142 node->data.from_target.matrix().postTranslate(-translation.x(), | 1147 node->data.from_target.matrix().postTranslate(-translation.x(), |
1143 -translation.y(), 0); | 1148 -translation.y(), 0); |
1144 | 1149 |
1145 node->data.scroll_snap = translation; | 1150 node->data.scroll_snap = translation; |
1146 } | 1151 } |
1147 | 1152 |
1148 void TransformTree::UpdateTransformChanged(TransformNode* node, | 1153 void TransformTree::UpdateTransformChanged(TransformNode* node, |
1149 TransformNode* parent_node, | 1154 TransformNode* parent_node, |
1150 TransformNode* source_node) { | 1155 TransformNode* source_node) { |
1151 if (parent_node && parent_node->data.transform_changed) { | 1156 if (parent_node && parent_node->data.transform_changed) { |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1234 } | 1239 } |
1235 | 1240 |
1236 bool TransformTree::HasNodesAffectedByInnerViewportBoundsDelta() const { | 1241 bool TransformTree::HasNodesAffectedByInnerViewportBoundsDelta() const { |
1237 return !nodes_affected_by_inner_viewport_bounds_delta_.empty(); | 1242 return !nodes_affected_by_inner_viewport_bounds_delta_.empty(); |
1238 } | 1243 } |
1239 | 1244 |
1240 bool TransformTree::HasNodesAffectedByOuterViewportBoundsDelta() const { | 1245 bool TransformTree::HasNodesAffectedByOuterViewportBoundsDelta() const { |
1241 return !nodes_affected_by_outer_viewport_bounds_delta_.empty(); | 1246 return !nodes_affected_by_outer_viewport_bounds_delta_.empty(); |
1242 } | 1247 } |
1243 | 1248 |
| 1249 gfx::Transform TransformTree::ToTarget(int id) const { |
| 1250 return Node(id)->data.to_target; |
| 1251 } |
| 1252 |
| 1253 void TransformTree::SetToTarget(int id, const gfx::Transform& transform) { |
| 1254 Node(id)->data.to_target = transform; |
| 1255 } |
| 1256 |
| 1257 gfx::Transform TransformTree::ToScreen(int id) const { |
| 1258 return Node(id)->data.to_screen; |
| 1259 } |
| 1260 |
| 1261 void TransformTree::SetToScreen(int id, const gfx::Transform& transform) { |
| 1262 Node(id)->data.to_screen = transform; |
| 1263 } |
| 1264 |
| 1265 int TransformTree::TargetId(int id) const { |
| 1266 return Node(id)->data.target_id; |
| 1267 } |
| 1268 |
| 1269 void TransformTree::SetTargetId(int id, int target_id) { |
| 1270 Node(id)->data.target_id = target_id; |
| 1271 } |
| 1272 |
| 1273 int TransformTree::ContentTargetId(int id) const { |
| 1274 return Node(id)->data.content_target_id; |
| 1275 } |
| 1276 |
| 1277 void TransformTree::SetContentTargetId(int id, int content_target_id) { |
| 1278 Node(id)->data.content_target_id = content_target_id; |
| 1279 } |
| 1280 |
1244 gfx::Transform TransformTree::ToScreenSpaceTransformWithoutSublayerScale( | 1281 gfx::Transform TransformTree::ToScreenSpaceTransformWithoutSublayerScale( |
1245 int id) const { | 1282 int id) const { |
1246 DCHECK_GT(id, 0); | 1283 DCHECK_GT(id, 0); |
1247 if (id == 1) { | 1284 if (id == 1) { |
1248 return gfx::Transform(); | 1285 return gfx::Transform(); |
1249 } | 1286 } |
1250 const TransformNode* node = Node(id); | 1287 const TransformNode* node = Node(id); |
1251 gfx::Transform screen_space_transform = node->data.to_screen; | 1288 gfx::Transform screen_space_transform = ToScreen(id); |
1252 if (node->data.sublayer_scale.x() != 0.0 && | 1289 if (node->data.sublayer_scale.x() != 0.0 && |
1253 node->data.sublayer_scale.y() != 0.0) | 1290 node->data.sublayer_scale.y() != 0.0) |
1254 screen_space_transform.Scale(1.0 / node->data.sublayer_scale.x(), | 1291 screen_space_transform.Scale(1.0 / node->data.sublayer_scale.x(), |
1255 1.0 / node->data.sublayer_scale.y()); | 1292 1.0 / node->data.sublayer_scale.y()); |
1256 return screen_space_transform; | 1293 return screen_space_transform; |
1257 } | 1294 } |
1258 | 1295 |
1259 bool TransformTree::operator==(const TransformTree& other) const { | 1296 bool TransformTree::operator==(const TransformTree& other) const { |
1260 return PropertyTree::operator==(other) && | 1297 return PropertyTree::operator==(other) && |
1261 source_to_parent_updates_allowed_ == | 1298 source_to_parent_updates_allowed_ == |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1378 transform_tree.Node(node->data.transform_id); | 1415 transform_tree.Node(node->data.transform_id); |
1379 if (transform_node->data.is_invertible && | 1416 if (transform_node->data.is_invertible && |
1380 transform_node->data.ancestors_are_invertible) { | 1417 transform_node->data.ancestors_are_invertible) { |
1381 if (transform_node->data.sorting_context_id) { | 1418 if (transform_node->data.sorting_context_id) { |
1382 const TransformNode* parent_transform_node = | 1419 const TransformNode* parent_transform_node = |
1383 transform_tree.parent(transform_node); | 1420 transform_tree.parent(transform_node); |
1384 if (parent_transform_node && | 1421 if (parent_transform_node && |
1385 parent_transform_node->data.sorting_context_id == | 1422 parent_transform_node->data.sorting_context_id == |
1386 transform_node->data.sorting_context_id) { | 1423 transform_node->data.sorting_context_id) { |
1387 gfx::Transform surface_draw_transform; | 1424 gfx::Transform surface_draw_transform; |
1388 transform_tree.ComputeTransform(transform_node->id, | 1425 transform_tree.ComputeTransform( |
1389 transform_node->data.target_id, | 1426 transform_node->id, transform_tree.TargetId(transform_node->id), |
1390 &surface_draw_transform); | 1427 &surface_draw_transform); |
1391 node->data.hidden_by_backface_visibility = | 1428 node->data.hidden_by_backface_visibility = |
1392 surface_draw_transform.IsBackFaceVisible(); | 1429 surface_draw_transform.IsBackFaceVisible(); |
1393 } else { | 1430 } else { |
1394 node->data.hidden_by_backface_visibility = | 1431 node->data.hidden_by_backface_visibility = |
1395 transform_node->data.local.IsBackFaceVisible(); | 1432 transform_node->data.local.IsBackFaceVisible(); |
1396 } | 1433 } |
1397 return; | 1434 return; |
1398 } | 1435 } |
1399 } | 1436 } |
1400 } | 1437 } |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1744 const ScrollNode* scroll_node = Node(currently_scrolling_node_id_); | 1781 const ScrollNode* scroll_node = Node(currently_scrolling_node_id_); |
1745 return scroll_node; | 1782 return scroll_node; |
1746 } | 1783 } |
1747 | 1784 |
1748 void ScrollTree::set_currently_scrolling_node(int scroll_node_id) { | 1785 void ScrollTree::set_currently_scrolling_node(int scroll_node_id) { |
1749 currently_scrolling_node_id_ = scroll_node_id; | 1786 currently_scrolling_node_id_ = scroll_node_id; |
1750 } | 1787 } |
1751 | 1788 |
1752 gfx::Transform ScrollTree::ScreenSpaceTransform(int scroll_node_id) const { | 1789 gfx::Transform ScrollTree::ScreenSpaceTransform(int scroll_node_id) const { |
1753 const ScrollNode* scroll_node = Node(scroll_node_id); | 1790 const ScrollNode* scroll_node = Node(scroll_node_id); |
| 1791 const TransformTree& transform_tree = property_trees()->transform_tree; |
1754 const TransformNode* transform_node = | 1792 const TransformNode* transform_node = |
1755 property_trees()->transform_tree.Node(scroll_node->data.transform_id); | 1793 transform_tree.Node(scroll_node->data.transform_id); |
1756 gfx::Transform screen_space_transform( | 1794 gfx::Transform screen_space_transform( |
1757 1, 0, 0, 1, scroll_node->data.offset_to_transform_parent.x(), | 1795 1, 0, 0, 1, scroll_node->data.offset_to_transform_parent.x(), |
1758 scroll_node->data.offset_to_transform_parent.y()); | 1796 scroll_node->data.offset_to_transform_parent.y()); |
1759 screen_space_transform.ConcatTransform(transform_node->data.to_screen); | 1797 screen_space_transform.ConcatTransform( |
| 1798 transform_tree.ToScreen(transform_node->id)); |
1760 if (scroll_node->data.should_flatten) | 1799 if (scroll_node->data.should_flatten) |
1761 screen_space_transform.FlattenTo2d(); | 1800 screen_space_transform.FlattenTo2d(); |
1762 return screen_space_transform; | 1801 return screen_space_transform; |
1763 } | 1802 } |
1764 | 1803 |
1765 SyncedScrollOffset* ScrollTree::synced_scroll_offset(int layer_id) { | 1804 SyncedScrollOffset* ScrollTree::synced_scroll_offset(int layer_id) { |
1766 if (layer_id_to_scroll_offset_map_.find(layer_id) == | 1805 if (layer_id_to_scroll_offset_map_.find(layer_id) == |
1767 layer_id_to_scroll_offset_map_.end()) { | 1806 layer_id_to_scroll_offset_map_.end()) { |
1768 layer_id_to_scroll_offset_map_[layer_id] = new SyncedScrollOffset; | 1807 layer_id_to_scroll_offset_map_[layer_id] = new SyncedScrollOffset; |
1769 } | 1808 } |
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2228 value->EndDictionary(); | 2267 value->EndDictionary(); |
2229 | 2268 |
2230 value->BeginDictionary("scroll_tree"); | 2269 value->BeginDictionary("scroll_tree"); |
2231 scroll_tree.AsValueInto(value.get()); | 2270 scroll_tree.AsValueInto(value.get()); |
2232 value->EndDictionary(); | 2271 value->EndDictionary(); |
2233 | 2272 |
2234 return value; | 2273 return value; |
2235 } | 2274 } |
2236 | 2275 |
2237 } // namespace cc | 2276 } // namespace cc |
OLD | NEW |