| 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 589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 600 gfx::Transform target_space_transform; | 600 gfx::Transform target_space_transform; |
| 601 if (node->needs_surface_contents_scale) { | 601 if (node->needs_surface_contents_scale) { |
| 602 target_space_transform.MakeIdentity(); | 602 target_space_transform.MakeIdentity(); |
| 603 target_space_transform.Scale(node->surface_contents_scale.x(), | 603 target_space_transform.Scale(node->surface_contents_scale.x(), |
| 604 node->surface_contents_scale.y()); | 604 node->surface_contents_scale.y()); |
| 605 } else { | 605 } else { |
| 606 // In order to include the root transform for the root surface, we walk up | 606 // In order to include the root transform for the root surface, we walk up |
| 607 // to the root of the transform tree in ComputeTransform. | 607 // to the root of the transform tree in ComputeTransform. |
| 608 int target_id = target_node->id; | 608 int target_id = target_node->id; |
| 609 ComputeTransform(node->id, target_id, &target_space_transform); | 609 ComputeTransform(node->id, target_id, &target_space_transform); |
| 610 if (target_id != kRootNodeId) { | 610 target_space_transform.matrix().postScale( |
| 611 target_space_transform.matrix().postScale( | 611 target_node->surface_contents_scale.x(), |
| 612 target_node->surface_contents_scale.x(), | 612 target_node->surface_contents_scale.y(), 1.f); |
| 613 target_node->surface_contents_scale.y(), 1.f); | |
| 614 } | |
| 615 } | 613 } |
| 616 | 614 |
| 617 gfx::Transform from_target; | 615 gfx::Transform from_target; |
| 618 if (!target_space_transform.GetInverse(&from_target)) | 616 if (!target_space_transform.GetInverse(&from_target)) |
| 619 node->ancestors_are_invertible = false; | 617 node->ancestors_are_invertible = false; |
| 620 SetToTarget(node->id, target_space_transform); | 618 SetToTarget(node->id, target_space_transform); |
| 621 SetFromTarget(node->id, from_target); | 619 SetFromTarget(node->id, from_target); |
| 622 } | 620 } |
| 623 | 621 |
| 624 void TransformTree::UpdateAnimationProperties(TransformNode* node, | 622 void TransformTree::UpdateAnimationProperties(TransformNode* node, |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 698 bool is_invertible = node->is_invertible; | 696 bool is_invertible = node->is_invertible; |
| 699 // Even when the current node's transform and the parent's screen space | 697 // Even when the current node's transform and the parent's screen space |
| 700 // transform are invertible, the current node's screen space transform can | 698 // transform are invertible, the current node's screen space transform can |
| 701 // become uninvertible due to floating-point arithmetic. | 699 // become uninvertible due to floating-point arithmetic. |
| 702 if (!node->ancestors_are_invertible && parent_node->ancestors_are_invertible) | 700 if (!node->ancestors_are_invertible && parent_node->ancestors_are_invertible) |
| 703 is_invertible = false; | 701 is_invertible = false; |
| 704 node->node_and_ancestors_are_animated_or_invertible = | 702 node->node_and_ancestors_are_animated_or_invertible = |
| 705 node->has_potential_animation || is_invertible; | 703 node->has_potential_animation || is_invertible; |
| 706 } | 704 } |
| 707 | 705 |
| 708 void TransformTree::SetDeviceTransform(const gfx::Transform& transform, | 706 void TransformTree::SetRootTransformsAndScales( |
| 709 gfx::PointF root_position) { | 707 float device_scale_factor, |
| 710 gfx::Transform root_post_local = transform; | 708 float page_scale_factor_for_root, |
| 711 TransformNode* node = Node(1); | 709 const gfx::Transform& device_transform, |
| 712 root_post_local.Scale(node->post_local_scale_factor, | 710 gfx::PointF root_position) { |
| 713 node->post_local_scale_factor); | |
| 714 root_post_local.Translate(root_position.x(), root_position.y()); | |
| 715 if (node->post_local == root_post_local) | |
| 716 return; | |
| 717 | |
| 718 node->post_local = root_post_local; | |
| 719 node->needs_local_transform_update = true; | |
| 720 set_needs_update(true); | |
| 721 } | |
| 722 | |
| 723 void TransformTree::SetDeviceTransformScaleFactor( | |
| 724 const gfx::Transform& transform) { | |
| 725 gfx::Vector2dF device_transform_scale_components = | 711 gfx::Vector2dF device_transform_scale_components = |
| 726 MathUtil::ComputeTransform2dScaleComponents(transform, 1.f); | 712 MathUtil::ComputeTransform2dScaleComponents(device_transform, 1.f); |
| 727 | 713 |
| 728 // Not handling the rare case of different x and y device scale. | 714 // Not handling the rare case of different x and y device scale. |
| 729 device_transform_scale_factor_ = | 715 device_transform_scale_factor_ = |
| 730 std::max(device_transform_scale_components.x(), | 716 std::max(device_transform_scale_components.x(), |
| 731 device_transform_scale_components.y()); | 717 device_transform_scale_components.y()); |
| 718 |
| 719 // If DT is the device transform, DSF is the matrix scaled by (device scale |
| 720 // factor * page scale factor for root), RP is the matrix translated by root's |
| 721 // position, |
| 722 // Let Screen Space Scale(SSS) = scale component of DT*DSF*RP, |
| 723 // then the screen space transform of the root transform node is set to SSS |
| 724 // and the post local transform of the contents root node is set to |
| 725 // SSS^-1*DT*DSF*RP. |
| 726 gfx::Transform transform = device_transform; |
| 727 transform.Scale(device_scale_factor * page_scale_factor_for_root, |
| 728 device_scale_factor * page_scale_factor_for_root); |
| 729 transform.Translate(root_position.x(), root_position.y()); |
| 730 float fallback_value = device_scale_factor * page_scale_factor_for_root; |
| 731 gfx::Vector2dF screen_space_scale = |
| 732 MathUtil::ComputeTransform2dScaleComponents(transform, fallback_value); |
| 733 DCHECK_NE(screen_space_scale.x(), 0.f); |
| 734 DCHECK_NE(screen_space_scale.y(), 0.f); |
| 735 |
| 736 gfx::Transform root_to_screen; |
| 737 root_to_screen.Scale(screen_space_scale.x(), screen_space_scale.y()); |
| 738 gfx::Transform root_from_screen; |
| 739 bool invertible = root_to_screen.GetInverse(&root_from_screen); |
| 740 DCHECK(invertible); |
| 741 TransformNode* root_node = Node(kRootNodeId); |
| 742 root_node->needs_surface_contents_scale = true; |
| 743 root_node->surface_contents_scale = screen_space_scale; |
| 744 SetToScreen(kRootNodeId, root_to_screen); |
| 745 SetFromScreen(kRootNodeId, root_from_screen); |
| 746 set_needs_update(true); |
| 747 |
| 748 transform.ConcatTransform(root_from_screen); |
| 749 TransformNode* contents_root_node = Node(kContentsRootNodeId); |
| 750 if (contents_root_node->post_local != transform) { |
| 751 contents_root_node->post_local = transform; |
| 752 contents_root_node->needs_local_transform_update = true; |
| 753 } |
| 732 } | 754 } |
| 733 | 755 |
| 734 void TransformTree::UpdateInnerViewportContainerBoundsDelta() { | 756 void TransformTree::UpdateInnerViewportContainerBoundsDelta() { |
| 735 if (nodes_affected_by_inner_viewport_bounds_delta_.empty()) | 757 if (nodes_affected_by_inner_viewport_bounds_delta_.empty()) |
| 736 return; | 758 return; |
| 737 | 759 |
| 738 set_needs_update(true); | 760 set_needs_update(true); |
| 739 for (int i : nodes_affected_by_inner_viewport_bounds_delta_) | 761 for (int i : nodes_affected_by_inner_viewport_bounds_delta_) |
| 740 Node(i)->needs_local_transform_update = true; | 762 Node(i)->needs_local_transform_update = true; |
| 741 } | 763 } |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1020 transform_node->local.IsBackFaceVisible(); | 1042 transform_node->local.IsBackFaceVisible(); |
| 1021 } | 1043 } |
| 1022 return; | 1044 return; |
| 1023 } | 1045 } |
| 1024 } | 1046 } |
| 1025 } | 1047 } |
| 1026 node->hidden_by_backface_visibility = false; | 1048 node->hidden_by_backface_visibility = false; |
| 1027 } | 1049 } |
| 1028 | 1050 |
| 1029 void EffectTree::UpdateSurfaceContentsScale(EffectNode* effect_node) { | 1051 void EffectTree::UpdateSurfaceContentsScale(EffectNode* effect_node) { |
| 1030 if (!effect_node->has_render_surface || | 1052 if (!effect_node->has_render_surface) { |
| 1031 effect_node->transform_id == kRootNodeId) { | |
| 1032 effect_node->surface_contents_scale = gfx::Vector2dF(1.0f, 1.0f); | 1053 effect_node->surface_contents_scale = gfx::Vector2dF(1.0f, 1.0f); |
| 1033 return; | 1054 return; |
| 1034 } | 1055 } |
| 1035 | 1056 |
| 1036 TransformTree& transform_tree = property_trees()->transform_tree; | 1057 TransformTree& transform_tree = property_trees()->transform_tree; |
| 1037 float layer_scale_factor = transform_tree.device_scale_factor() * | 1058 float layer_scale_factor = transform_tree.device_scale_factor() * |
| 1038 transform_tree.device_transform_scale_factor(); | 1059 transform_tree.device_transform_scale_factor(); |
| 1039 TransformNode* transform_node = | 1060 TransformNode* transform_node = |
| 1040 transform_tree.Node(effect_node->transform_id); | 1061 transform_tree.Node(effect_node->transform_id); |
| 1041 if (transform_node->in_subtree_of_page_scale_layer) | 1062 if (transform_node->in_subtree_of_page_scale_layer) |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1141 } else { | 1162 } else { |
| 1142 // The root surface doesn't have the notion of sub-layer scale, but | 1163 // The root surface doesn't have the notion of sub-layer scale, but |
| 1143 // instead has a similar notion of transforming from the space of the root | 1164 // instead has a similar notion of transforming from the space of the root |
| 1144 // layer to the space of the screen. | 1165 // layer to the space of the screen. |
| 1145 DCHECK_EQ(kRootNodeId, destination_id); | 1166 DCHECK_EQ(kRootNodeId, destination_id); |
| 1146 source_id = TransformTree::kContentsRootNodeId; | 1167 source_id = TransformTree::kContentsRootNodeId; |
| 1147 } | 1168 } |
| 1148 gfx::Transform transform; | 1169 gfx::Transform transform; |
| 1149 property_trees()->transform_tree.ComputeTransform(source_id, destination_id, | 1170 property_trees()->transform_tree.ComputeTransform(source_id, destination_id, |
| 1150 &transform); | 1171 &transform); |
| 1151 if (effect_node->id != kContentsRootNodeId) { | 1172 transform.matrix().postScale(effect_node->surface_contents_scale.x(), |
| 1152 transform.matrix().postScale(effect_node->surface_contents_scale.x(), | 1173 effect_node->surface_contents_scale.y(), 1.f); |
| 1153 effect_node->surface_contents_scale.y(), | |
| 1154 1.f); | |
| 1155 } | |
| 1156 it->set_area(MathUtil::MapEnclosingClippedRect(transform, it->area())); | 1174 it->set_area(MathUtil::MapEnclosingClippedRect(transform, it->area())); |
| 1157 } | 1175 } |
| 1158 } | 1176 } |
| 1159 | 1177 |
| 1160 bool EffectTree::HasCopyRequests() const { | 1178 bool EffectTree::HasCopyRequests() const { |
| 1161 return !copy_requests_.empty(); | 1179 return !copy_requests_.empty(); |
| 1162 } | 1180 } |
| 1163 | 1181 |
| 1164 void EffectTree::ClearCopyRequests() { | 1182 void EffectTree::ClearCopyRequests() { |
| 1165 for (auto& node : nodes()) { | 1183 for (auto& node : nodes()) { |
| (...skipping 1199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2365 from_target.ConcatTransform(draw_transforms.from_target); | 2383 from_target.ConcatTransform(draw_transforms.from_target); |
| 2366 from_target.Scale(effect_node->surface_contents_scale.x(), | 2384 from_target.Scale(effect_node->surface_contents_scale.x(), |
| 2367 effect_node->surface_contents_scale.y()); | 2385 effect_node->surface_contents_scale.y()); |
| 2368 DCHECK(from_target.ApproximatelyEqual(*transform) || | 2386 DCHECK(from_target.ApproximatelyEqual(*transform) || |
| 2369 !draw_transforms.invertible); | 2387 !draw_transforms.invertible); |
| 2370 } | 2388 } |
| 2371 return success; | 2389 return success; |
| 2372 } | 2390 } |
| 2373 | 2391 |
| 2374 } // namespace cc | 2392 } // namespace cc |
| OLD | NEW |