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 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
598 gfx::Transform target_space_transform; | 598 gfx::Transform target_space_transform; |
599 if (node->needs_surface_contents_scale) { | 599 if (node->needs_surface_contents_scale) { |
600 target_space_transform.MakeIdentity(); | 600 target_space_transform.MakeIdentity(); |
601 target_space_transform.Scale(node->surface_contents_scale.x(), | 601 target_space_transform.Scale(node->surface_contents_scale.x(), |
602 node->surface_contents_scale.y()); | 602 node->surface_contents_scale.y()); |
603 } else { | 603 } else { |
604 // In order to include the root transform for the root surface, we walk up | 604 // In order to include the root transform for the root surface, we walk up |
605 // to the root of the transform tree in ComputeTransform. | 605 // to the root of the transform tree in ComputeTransform. |
606 int target_id = target_node->id; | 606 int target_id = target_node->id; |
607 ComputeTransform(node->id, target_id, &target_space_transform); | 607 ComputeTransform(node->id, target_id, &target_space_transform); |
608 if (target_id != kRootNodeId) { | 608 target_space_transform.matrix().postScale( |
609 target_space_transform.matrix().postScale( | 609 target_node->surface_contents_scale.x(), |
610 target_node->surface_contents_scale.x(), | 610 target_node->surface_contents_scale.y(), 1.f); |
611 target_node->surface_contents_scale.y(), 1.f); | |
612 } | |
613 } | 611 } |
614 | 612 |
615 gfx::Transform from_target; | 613 gfx::Transform from_target; |
616 if (!target_space_transform.GetInverse(&from_target)) | 614 if (!target_space_transform.GetInverse(&from_target)) |
617 node->ancestors_are_invertible = false; | 615 node->ancestors_are_invertible = false; |
618 SetToTarget(node->id, target_space_transform); | 616 SetToTarget(node->id, target_space_transform); |
619 SetFromTarget(node->id, from_target); | 617 SetFromTarget(node->id, from_target); |
620 } | 618 } |
621 | 619 |
622 void TransformTree::UpdateAnimationProperties(TransformNode* node, | 620 void TransformTree::UpdateAnimationProperties(TransformNode* node, |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
696 bool is_invertible = node->is_invertible; | 694 bool is_invertible = node->is_invertible; |
697 // Even when the current node's transform and the parent's screen space | 695 // Even when the current node's transform and the parent's screen space |
698 // transform are invertible, the current node's screen space transform can | 696 // transform are invertible, the current node's screen space transform can |
699 // become uninvertible due to floating-point arithmetic. | 697 // become uninvertible due to floating-point arithmetic. |
700 if (!node->ancestors_are_invertible && parent_node->ancestors_are_invertible) | 698 if (!node->ancestors_are_invertible && parent_node->ancestors_are_invertible) |
701 is_invertible = false; | 699 is_invertible = false; |
702 node->node_and_ancestors_are_animated_or_invertible = | 700 node->node_and_ancestors_are_animated_or_invertible = |
703 node->has_potential_animation || is_invertible; | 701 node->has_potential_animation || is_invertible; |
704 } | 702 } |
705 | 703 |
706 void TransformTree::SetDeviceTransform(const gfx::Transform& transform, | 704 void TransformTree::SetContentsRootPostLocalTransform( |
707 gfx::PointF root_position) { | 705 const gfx::Transform& transform, |
708 gfx::Transform root_post_local = transform; | 706 gfx::PointF root_position) { |
709 TransformNode* node = Node(1); | 707 // The post local transform of the contents root node is set to the device |
710 root_post_local.Scale(node->post_local_scale_factor, | 708 // transform with scale removed and is also offset by the root layer's |
711 node->post_local_scale_factor); | 709 // position. The scale part of the device transform goes into the screen space |
712 root_post_local.Translate(root_position.x(), root_position.y()); | 710 // scale stored on the root node. |
713 if (node->post_local == root_post_local) | 711 gfx::Transform post_local = transform; |
| 712 post_local.Translate(root_position.x(), root_position.y()); |
| 713 |
| 714 TransformNode* node = Node(kContentsRootNodeId); |
| 715 if (node->post_local == post_local) |
714 return; | 716 return; |
715 | 717 node->post_local = post_local; |
716 node->post_local = root_post_local; | |
717 node->needs_local_transform_update = true; | 718 node->needs_local_transform_update = true; |
718 set_needs_update(true); | 719 set_needs_update(true); |
719 } | 720 } |
720 | 721 |
721 void TransformTree::SetDeviceTransformScaleFactor( | 722 void TransformTree::SetScreenSpaceScaleOnRootNode( |
722 const gfx::Transform& transform) { | 723 gfx::Vector2dF screen_space_scale_components) { |
| 724 TransformNode* node = Node(kRootNodeId); |
| 725 if (node->surface_contents_scale == screen_space_scale_components) |
| 726 return; |
| 727 node->needs_surface_contents_scale = true; |
| 728 node->surface_contents_scale = screen_space_scale_components; |
| 729 gfx::Transform to_screen; |
| 730 to_screen.Scale(node->surface_contents_scale.x(), |
| 731 node->surface_contents_scale.y()); |
| 732 SetToScreen(node->id, to_screen); |
| 733 gfx::Transform from_screen; |
| 734 if (!ToScreen(node->id).GetInverse(&from_screen)) |
| 735 node->ancestors_are_invertible = false; |
| 736 SetFromScreen(node->id, from_screen); |
| 737 set_needs_update(true); |
| 738 } |
| 739 |
| 740 void TransformTree::SetRootTransformsAndScales( |
| 741 float device_scale_factor, |
| 742 float page_scale_factor_for_root, |
| 743 const gfx::Transform& device_transform, |
| 744 gfx::PointF root_position) { |
723 gfx::Vector2dF device_transform_scale_components = | 745 gfx::Vector2dF device_transform_scale_components = |
724 MathUtil::ComputeTransform2dScaleComponents(transform, 1.f); | 746 MathUtil::ComputeTransform2dScaleComponents(device_transform, 1.f); |
725 | 747 |
726 // Not handling the rare case of different x and y device scale. | 748 // Not handling the rare case of different x and y device scale. |
727 device_transform_scale_factor_ = | 749 device_transform_scale_factor_ = |
728 std::max(device_transform_scale_components.x(), | 750 std::max(device_transform_scale_components.x(), |
729 device_transform_scale_components.y()); | 751 device_transform_scale_components.y()); |
| 752 gfx::Transform device_transform_without_scale = device_transform; |
| 753 device_transform_without_scale.matrix().postScale( |
| 754 1.f / device_transform_scale_components.x(), |
| 755 1.f / device_transform_scale_components.y(), 1.f); |
| 756 SetContentsRootPostLocalTransform(device_transform_without_scale, |
| 757 root_position); |
| 758 |
| 759 gfx::Vector2dF screen_space_scale_components( |
| 760 device_transform_scale_components.x() * device_scale_factor * |
| 761 page_scale_factor_for_root, |
| 762 device_transform_scale_components.y() * device_scale_factor * |
| 763 page_scale_factor_for_root); |
| 764 SetScreenSpaceScaleOnRootNode(screen_space_scale_components); |
730 } | 765 } |
731 | 766 |
732 void TransformTree::UpdateInnerViewportContainerBoundsDelta() { | 767 void TransformTree::UpdateInnerViewportContainerBoundsDelta() { |
733 if (nodes_affected_by_inner_viewport_bounds_delta_.empty()) | 768 if (nodes_affected_by_inner_viewport_bounds_delta_.empty()) |
734 return; | 769 return; |
735 | 770 |
736 set_needs_update(true); | 771 set_needs_update(true); |
737 for (int i : nodes_affected_by_inner_viewport_bounds_delta_) | 772 for (int i : nodes_affected_by_inner_viewport_bounds_delta_) |
738 Node(i)->needs_local_transform_update = true; | 773 Node(i)->needs_local_transform_update = true; |
739 } | 774 } |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1003 transform_node->local.IsBackFaceVisible(); | 1038 transform_node->local.IsBackFaceVisible(); |
1004 } | 1039 } |
1005 return; | 1040 return; |
1006 } | 1041 } |
1007 } | 1042 } |
1008 } | 1043 } |
1009 node->hidden_by_backface_visibility = false; | 1044 node->hidden_by_backface_visibility = false; |
1010 } | 1045 } |
1011 | 1046 |
1012 void EffectTree::UpdateSurfaceContentsScale(EffectNode* effect_node) { | 1047 void EffectTree::UpdateSurfaceContentsScale(EffectNode* effect_node) { |
1013 if (!effect_node->has_render_surface || | 1048 if (!effect_node->has_render_surface) { |
1014 effect_node->transform_id == kRootNodeId) { | |
1015 effect_node->surface_contents_scale = gfx::Vector2dF(1.0f, 1.0f); | 1049 effect_node->surface_contents_scale = gfx::Vector2dF(1.0f, 1.0f); |
1016 return; | 1050 return; |
1017 } | 1051 } |
1018 | 1052 |
1019 TransformTree& transform_tree = property_trees()->transform_tree; | 1053 TransformTree& transform_tree = property_trees()->transform_tree; |
1020 float layer_scale_factor = transform_tree.device_scale_factor() * | 1054 float layer_scale_factor = transform_tree.device_scale_factor() * |
1021 transform_tree.device_transform_scale_factor(); | 1055 transform_tree.device_transform_scale_factor(); |
1022 TransformNode* transform_node = | 1056 TransformNode* transform_node = |
1023 transform_tree.Node(effect_node->transform_id); | 1057 transform_tree.Node(effect_node->transform_id); |
1024 if (transform_node->in_subtree_of_page_scale_layer) | 1058 if (transform_node->in_subtree_of_page_scale_layer) |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1124 } else { | 1158 } else { |
1125 // The root surface doesn't have the notion of sub-layer scale, but | 1159 // The root surface doesn't have the notion of sub-layer scale, but |
1126 // instead has a similar notion of transforming from the space of the root | 1160 // instead has a similar notion of transforming from the space of the root |
1127 // layer to the space of the screen. | 1161 // layer to the space of the screen. |
1128 DCHECK_EQ(kRootNodeId, destination_id); | 1162 DCHECK_EQ(kRootNodeId, destination_id); |
1129 source_id = TransformTree::kContentsRootNodeId; | 1163 source_id = TransformTree::kContentsRootNodeId; |
1130 } | 1164 } |
1131 gfx::Transform transform; | 1165 gfx::Transform transform; |
1132 property_trees()->transform_tree.ComputeTransform(source_id, destination_id, | 1166 property_trees()->transform_tree.ComputeTransform(source_id, destination_id, |
1133 &transform); | 1167 &transform); |
1134 if (effect_node->id != kContentsRootNodeId) { | 1168 transform.matrix().postScale(effect_node->surface_contents_scale.x(), |
1135 transform.matrix().postScale(effect_node->surface_contents_scale.x(), | 1169 effect_node->surface_contents_scale.y(), 1.f); |
1136 effect_node->surface_contents_scale.y(), | |
1137 1.f); | |
1138 } | |
1139 it->set_area(MathUtil::MapEnclosingClippedRect(transform, it->area())); | 1170 it->set_area(MathUtil::MapEnclosingClippedRect(transform, it->area())); |
1140 } | 1171 } |
1141 } | 1172 } |
1142 | 1173 |
1143 bool EffectTree::HasCopyRequests() const { | 1174 bool EffectTree::HasCopyRequests() const { |
1144 return !copy_requests_.empty(); | 1175 return !copy_requests_.empty(); |
1145 } | 1176 } |
1146 | 1177 |
1147 void EffectTree::ClearCopyRequests() { | 1178 void EffectTree::ClearCopyRequests() { |
1148 for (auto& node : nodes()) { | 1179 for (auto& node : nodes()) { |
(...skipping 1086 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2235 gfx::Transform from_target; | 2266 gfx::Transform from_target; |
2236 bool already_computed_inverse = false; | 2267 bool already_computed_inverse = false; |
2237 if (transform_id == dest_id) { | 2268 if (transform_id == dest_id) { |
2238 target_space_transform.Scale(effect_node->surface_contents_scale.x(), | 2269 target_space_transform.Scale(effect_node->surface_contents_scale.x(), |
2239 effect_node->surface_contents_scale.y()); | 2270 effect_node->surface_contents_scale.y()); |
2240 data.transforms.to_valid = true; | 2271 data.transforms.to_valid = true; |
2241 data.transforms.from_valid = false; | 2272 data.transforms.from_valid = false; |
2242 } else if (transform_id > dest_id) { | 2273 } else if (transform_id > dest_id) { |
2243 transform_tree.CombineTransformsBetween(transform_id, dest_id, | 2274 transform_tree.CombineTransformsBetween(transform_id, dest_id, |
2244 &target_space_transform); | 2275 &target_space_transform); |
2245 if (dest_id != TransformTree::kRootNodeId) | 2276 target_space_transform.matrix().postScale( |
2246 target_space_transform.matrix().postScale( | 2277 effect_node->surface_contents_scale.x(), |
2247 effect_node->surface_contents_scale.x(), | 2278 effect_node->surface_contents_scale.y(), 1.f); |
2248 effect_node->surface_contents_scale.y(), 1.f); | |
2249 data.transforms.to_valid = true; | 2279 data.transforms.to_valid = true; |
2250 data.transforms.from_valid = false; | 2280 data.transforms.from_valid = false; |
2251 data.transforms.might_be_invertible = true; | 2281 data.transforms.might_be_invertible = true; |
2252 } else { | 2282 } else { |
2253 gfx::Transform combined_transform; | 2283 gfx::Transform combined_transform; |
2254 transform_tree.CombineTransformsBetween(dest_id, transform_id, | 2284 transform_tree.CombineTransformsBetween(dest_id, transform_id, |
2255 &combined_transform); | 2285 &combined_transform); |
2256 if (effect_node->surface_contents_scale.x() != 0.f && | 2286 if (effect_node->surface_contents_scale.x() != 0.f && |
2257 effect_node->surface_contents_scale.y() != 0.f) | 2287 effect_node->surface_contents_scale.y() != 0.f) |
2258 combined_transform.Scale(1.0f / effect_node->surface_contents_scale.x(), | 2288 combined_transform.Scale(1.0f / effect_node->surface_contents_scale.x(), |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2332 | 2362 |
2333 const EffectNode* effect_node = effect_tree.Node(effect_id); | 2363 const EffectNode* effect_node = effect_tree.Node(effect_id); |
2334 | 2364 |
2335 bool success = GetFromTarget(transform_id, effect_id, transform); | 2365 bool success = GetFromTarget(transform_id, effect_id, transform); |
2336 transform->Scale(effect_node->surface_contents_scale.x(), | 2366 transform->Scale(effect_node->surface_contents_scale.x(), |
2337 effect_node->surface_contents_scale.y()); | 2367 effect_node->surface_contents_scale.y()); |
2338 return success; | 2368 return success; |
2339 } | 2369 } |
2340 | 2370 |
2341 } // namespace cc | 2371 } // namespace cc |
OLD | NEW |