| 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 650 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 661 bool is_invertible = node->is_invertible; | 661 bool is_invertible = node->is_invertible; |
| 662 // Even when the current node's transform and the parent's screen space | 662 // Even when the current node's transform and the parent's screen space |
| 663 // transform are invertible, the current node's screen space transform can | 663 // transform are invertible, the current node's screen space transform can |
| 664 // become uninvertible due to floating-point arithmetic. | 664 // become uninvertible due to floating-point arithmetic. |
| 665 if (!node->ancestors_are_invertible && parent_node->ancestors_are_invertible) | 665 if (!node->ancestors_are_invertible && parent_node->ancestors_are_invertible) |
| 666 is_invertible = false; | 666 is_invertible = false; |
| 667 node->node_and_ancestors_are_animated_or_invertible = | 667 node->node_and_ancestors_are_animated_or_invertible = |
| 668 node->has_potential_animation || is_invertible; | 668 node->has_potential_animation || is_invertible; |
| 669 } | 669 } |
| 670 | 670 |
| 671 void TransformTree::SetDeviceTransform(const gfx::Transform& transform, | 671 void TransformTree::SetRootTransformsAndScales( |
| 672 gfx::PointF root_position) { | 672 float device_scale_factor, |
| 673 gfx::Transform root_post_local = transform; | 673 float page_scale_factor_for_root, |
| 674 TransformNode* node = Node(1); | 674 const gfx::Transform& device_transform, |
| 675 root_post_local.Scale(node->post_local_scale_factor, | 675 gfx::PointF root_position) { |
| 676 node->post_local_scale_factor); | |
| 677 root_post_local.Translate(root_position.x(), root_position.y()); | |
| 678 if (node->post_local == root_post_local) | |
| 679 return; | |
| 680 | |
| 681 node->post_local = root_post_local; | |
| 682 node->needs_local_transform_update = true; | |
| 683 set_needs_update(true); | |
| 684 } | |
| 685 | |
| 686 void TransformTree::SetDeviceTransformScaleFactor( | |
| 687 const gfx::Transform& transform) { | |
| 688 gfx::Vector2dF device_transform_scale_components = | 676 gfx::Vector2dF device_transform_scale_components = |
| 689 MathUtil::ComputeTransform2dScaleComponents(transform, 1.f); | 677 MathUtil::ComputeTransform2dScaleComponents(device_transform, 1.f); |
| 690 | 678 |
| 691 // Not handling the rare case of different x and y device scale. | 679 // Not handling the rare case of different x and y device scale. |
| 692 device_transform_scale_factor_ = | 680 device_transform_scale_factor_ = |
| 693 std::max(device_transform_scale_components.x(), | 681 std::max(device_transform_scale_components.x(), |
| 694 device_transform_scale_components.y()); | 682 device_transform_scale_components.y()); |
| 683 |
| 684 // If DT is the device transform, DSF is the matrix scaled by (device scale |
| 685 // factor * page scale factor for root), RP is the matrix translated by root's |
| 686 // position, |
| 687 // Let Screen Space Scale(SSS) = scale component of DT*DSF*RP, |
| 688 // then the screen space transform of the root transform node is set to SSS |
| 689 // and the post local transform of the contents root node is set to |
| 690 // SSS^-1*DT*DSF*RP. |
| 691 gfx::Transform transform = device_transform; |
| 692 transform.Scale(device_scale_factor * page_scale_factor_for_root, |
| 693 device_scale_factor * page_scale_factor_for_root); |
| 694 transform.Translate(root_position.x(), root_position.y()); |
| 695 float fallback_value = device_scale_factor * page_scale_factor_for_root; |
| 696 gfx::Vector2dF screen_space_scale = |
| 697 MathUtil::ComputeTransform2dScaleComponents(transform, fallback_value); |
| 698 DCHECK_NE(screen_space_scale.x(), 0.f); |
| 699 DCHECK_NE(screen_space_scale.y(), 0.f); |
| 700 |
| 701 gfx::Transform root_to_screen; |
| 702 root_to_screen.Scale(screen_space_scale.x(), screen_space_scale.y()); |
| 703 gfx::Transform root_from_screen; |
| 704 bool invertible = root_to_screen.GetInverse(&root_from_screen); |
| 705 DCHECK(invertible); |
| 706 SetToScreen(kRootNodeId, root_to_screen); |
| 707 SetFromScreen(kRootNodeId, root_from_screen); |
| 708 set_needs_update(true); |
| 709 |
| 710 transform.ConcatTransform(root_from_screen); |
| 711 TransformNode* contents_root_node = Node(kContentsRootNodeId); |
| 712 if (contents_root_node->post_local != transform) { |
| 713 contents_root_node->post_local = transform; |
| 714 contents_root_node->needs_local_transform_update = true; |
| 715 } |
| 695 } | 716 } |
| 696 | 717 |
| 697 void TransformTree::UpdateInnerViewportContainerBoundsDelta() { | 718 void TransformTree::UpdateInnerViewportContainerBoundsDelta() { |
| 698 if (nodes_affected_by_inner_viewport_bounds_delta_.empty()) | 719 if (nodes_affected_by_inner_viewport_bounds_delta_.empty()) |
| 699 return; | 720 return; |
| 700 | 721 |
| 701 set_needs_update(true); | 722 set_needs_update(true); |
| 702 for (int i : nodes_affected_by_inner_viewport_bounds_delta_) | 723 for (int i : nodes_affected_by_inner_viewport_bounds_delta_) |
| 703 Node(i)->needs_local_transform_update = true; | 724 Node(i)->needs_local_transform_update = true; |
| 704 } | 725 } |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 945 transform_node->local.IsBackFaceVisible(); | 966 transform_node->local.IsBackFaceVisible(); |
| 946 } | 967 } |
| 947 return; | 968 return; |
| 948 } | 969 } |
| 949 } | 970 } |
| 950 } | 971 } |
| 951 node->hidden_by_backface_visibility = false; | 972 node->hidden_by_backface_visibility = false; |
| 952 } | 973 } |
| 953 | 974 |
| 954 void EffectTree::UpdateSurfaceContentsScale(EffectNode* effect_node) { | 975 void EffectTree::UpdateSurfaceContentsScale(EffectNode* effect_node) { |
| 955 if (!effect_node->has_render_surface || | 976 if (!effect_node->has_render_surface) { |
| 956 effect_node->transform_id == kRootNodeId) { | |
| 957 effect_node->surface_contents_scale = gfx::Vector2dF(1.0f, 1.0f); | 977 effect_node->surface_contents_scale = gfx::Vector2dF(1.0f, 1.0f); |
| 958 return; | 978 return; |
| 959 } | 979 } |
| 960 | 980 |
| 961 TransformTree& transform_tree = property_trees()->transform_tree; | 981 TransformTree& transform_tree = property_trees()->transform_tree; |
| 962 float layer_scale_factor = transform_tree.device_scale_factor() * | 982 float layer_scale_factor = transform_tree.device_scale_factor() * |
| 963 transform_tree.device_transform_scale_factor(); | 983 transform_tree.device_transform_scale_factor(); |
| 964 TransformNode* transform_node = | 984 TransformNode* transform_node = |
| 965 transform_tree.Node(effect_node->transform_id); | 985 transform_tree.Node(effect_node->transform_id); |
| 966 if (transform_node->in_subtree_of_page_scale_layer) | 986 if (transform_node->in_subtree_of_page_scale_layer) |
| (...skipping 1204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2171 gfx::Transform from_target; | 2191 gfx::Transform from_target; |
| 2172 bool already_computed_inverse = false; | 2192 bool already_computed_inverse = false; |
| 2173 if (transform_id == dest_id) { | 2193 if (transform_id == dest_id) { |
| 2174 target_space_transform.Scale(effect_node->surface_contents_scale.x(), | 2194 target_space_transform.Scale(effect_node->surface_contents_scale.x(), |
| 2175 effect_node->surface_contents_scale.y()); | 2195 effect_node->surface_contents_scale.y()); |
| 2176 data.transforms.to_valid = true; | 2196 data.transforms.to_valid = true; |
| 2177 data.transforms.from_valid = false; | 2197 data.transforms.from_valid = false; |
| 2178 } else if (transform_id > dest_id) { | 2198 } else if (transform_id > dest_id) { |
| 2179 transform_tree.CombineTransformsBetween(transform_id, dest_id, | 2199 transform_tree.CombineTransformsBetween(transform_id, dest_id, |
| 2180 &target_space_transform); | 2200 &target_space_transform); |
| 2181 if (dest_id != TransformTree::kRootNodeId) | 2201 target_space_transform.matrix().postScale( |
| 2182 target_space_transform.matrix().postScale( | 2202 effect_node->surface_contents_scale.x(), |
| 2183 effect_node->surface_contents_scale.x(), | 2203 effect_node->surface_contents_scale.y(), 1.f); |
| 2184 effect_node->surface_contents_scale.y(), 1.f); | |
| 2185 data.transforms.to_valid = true; | 2204 data.transforms.to_valid = true; |
| 2186 data.transforms.from_valid = false; | 2205 data.transforms.from_valid = false; |
| 2187 data.transforms.might_be_invertible = true; | 2206 data.transforms.might_be_invertible = true; |
| 2188 } else { | 2207 } else { |
| 2189 gfx::Transform combined_transform; | 2208 gfx::Transform combined_transform; |
| 2190 transform_tree.CombineTransformsBetween(dest_id, transform_id, | 2209 transform_tree.CombineTransformsBetween(dest_id, transform_id, |
| 2191 &combined_transform); | 2210 &combined_transform); |
| 2192 if (effect_node->surface_contents_scale.x() != 0.f && | 2211 if (effect_node->surface_contents_scale.x() != 0.f && |
| 2193 effect_node->surface_contents_scale.y() != 0.f) | 2212 effect_node->surface_contents_scale.y() != 0.f) |
| 2194 combined_transform.Scale(1.0f / effect_node->surface_contents_scale.x(), | 2213 combined_transform.Scale(1.0f / effect_node->surface_contents_scale.x(), |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2249 | 2268 |
| 2250 const EffectNode* effect_node = effect_tree.Node(effect_id); | 2269 const EffectNode* effect_node = effect_tree.Node(effect_id); |
| 2251 | 2270 |
| 2252 bool success = GetFromTarget(transform_id, effect_id, transform); | 2271 bool success = GetFromTarget(transform_id, effect_id, transform); |
| 2253 transform->Scale(effect_node->surface_contents_scale.x(), | 2272 transform->Scale(effect_node->surface_contents_scale.x(), |
| 2254 effect_node->surface_contents_scale.y()); | 2273 effect_node->surface_contents_scale.y()); |
| 2255 return success; | 2274 return success; |
| 2256 } | 2275 } |
| 2257 | 2276 |
| 2258 } // namespace cc | 2277 } // namespace cc |
| OLD | NEW |