| 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 target_space_transform.matrix().postScale( | 610 if (target_id != kRootNodeId) { |
| 611 target_node->surface_contents_scale.x(), | 611 target_space_transform.matrix().postScale( |
| 612 target_node->surface_contents_scale.y(), 1.f); | 612 target_node->surface_contents_scale.x(), |
| 613 target_node->surface_contents_scale.y(), 1.f); |
| 614 } |
| 613 } | 615 } |
| 614 | 616 |
| 615 gfx::Transform from_target; | 617 gfx::Transform from_target; |
| 616 if (!target_space_transform.GetInverse(&from_target)) | 618 if (!target_space_transform.GetInverse(&from_target)) |
| 617 node->ancestors_are_invertible = false; | 619 node->ancestors_are_invertible = false; |
| 618 SetToTarget(node->id, target_space_transform); | 620 SetToTarget(node->id, target_space_transform); |
| 619 SetFromTarget(node->id, from_target); | 621 SetFromTarget(node->id, from_target); |
| 620 } | 622 } |
| 621 | 623 |
| 622 void TransformTree::UpdateAnimationProperties(TransformNode* node, | 624 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; | 698 bool is_invertible = node->is_invertible; |
| 697 // Even when the current node's transform and the parent's screen space | 699 // 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 | 700 // transform are invertible, the current node's screen space transform can |
| 699 // become uninvertible due to floating-point arithmetic. | 701 // become uninvertible due to floating-point arithmetic. |
| 700 if (!node->ancestors_are_invertible && parent_node->ancestors_are_invertible) | 702 if (!node->ancestors_are_invertible && parent_node->ancestors_are_invertible) |
| 701 is_invertible = false; | 703 is_invertible = false; |
| 702 node->node_and_ancestors_are_animated_or_invertible = | 704 node->node_and_ancestors_are_animated_or_invertible = |
| 703 node->has_potential_animation || is_invertible; | 705 node->has_potential_animation || is_invertible; |
| 704 } | 706 } |
| 705 | 707 |
| 706 void TransformTree::SetContentsRootPostLocalTransform( | 708 void TransformTree::SetDeviceTransform(const gfx::Transform& transform, |
| 707 const gfx::Transform& transform, | 709 gfx::PointF root_position) { |
| 708 gfx::PointF root_position) { | 710 gfx::Transform root_post_local = transform; |
| 709 // The post local transform of the contents root node is set to the device | 711 TransformNode* node = Node(1); |
| 710 // transform with scale removed and is also offset by the root layer's | 712 root_post_local.Scale(node->post_local_scale_factor, |
| 711 // position. The scale part of the device transform goes into the screen space | 713 node->post_local_scale_factor); |
| 712 // scale stored on the root node. | 714 root_post_local.Translate(root_position.x(), root_position.y()); |
| 713 gfx::Transform post_local = transform; | 715 if (node->post_local == root_post_local) |
| 714 post_local.Translate(root_position.x(), root_position.y()); | 716 return; |
| 715 | 717 |
| 716 TransformNode* node = Node(kContentsRootNodeId); | 718 node->post_local = root_post_local; |
| 717 if (node->post_local == post_local) | |
| 718 return; | |
| 719 node->post_local = post_local; | |
| 720 node->needs_local_transform_update = true; | 719 node->needs_local_transform_update = true; |
| 721 set_needs_update(true); | 720 set_needs_update(true); |
| 722 } | 721 } |
| 723 | 722 |
| 724 void TransformTree::SetScreenSpaceScaleOnRootNode( | 723 void TransformTree::SetDeviceTransformScaleFactor( |
| 725 gfx::Vector2dF screen_space_scale_components) { | 724 const gfx::Transform& transform) { |
| 726 TransformNode* node = Node(kRootNodeId); | |
| 727 if (node->surface_contents_scale == screen_space_scale_components) | |
| 728 return; | |
| 729 node->needs_surface_contents_scale = true; | |
| 730 node->surface_contents_scale = screen_space_scale_components; | |
| 731 gfx::Transform to_screen; | |
| 732 to_screen.Scale(node->surface_contents_scale.x(), | |
| 733 node->surface_contents_scale.y()); | |
| 734 SetToScreen(node->id, to_screen); | |
| 735 gfx::Transform from_screen; | |
| 736 if (!ToScreen(node->id).GetInverse(&from_screen)) | |
| 737 node->ancestors_are_invertible = false; | |
| 738 SetFromScreen(node->id, from_screen); | |
| 739 set_needs_update(true); | |
| 740 } | |
| 741 | |
| 742 void TransformTree::SetRootTransformsAndScales( | |
| 743 float device_scale_factor, | |
| 744 float page_scale_factor_for_root, | |
| 745 const gfx::Transform& device_transform, | |
| 746 gfx::PointF root_position) { | |
| 747 gfx::Vector2dF device_transform_scale_components = | 725 gfx::Vector2dF device_transform_scale_components = |
| 748 MathUtil::ComputeTransform2dScaleComponents(device_transform, 1.f); | 726 MathUtil::ComputeTransform2dScaleComponents(transform, 1.f); |
| 749 | 727 |
| 750 // Not handling the rare case of different x and y device scale. | 728 // Not handling the rare case of different x and y device scale. |
| 751 device_transform_scale_factor_ = | 729 device_transform_scale_factor_ = |
| 752 std::max(device_transform_scale_components.x(), | 730 std::max(device_transform_scale_components.x(), |
| 753 device_transform_scale_components.y()); | 731 device_transform_scale_components.y()); |
| 754 gfx::Transform device_transform_without_scale = device_transform; | |
| 755 device_transform_without_scale.matrix().postScale( | |
| 756 1.f / device_transform_scale_components.x(), | |
| 757 1.f / device_transform_scale_components.y(), 1.f); | |
| 758 SetContentsRootPostLocalTransform(device_transform_without_scale, | |
| 759 root_position); | |
| 760 | |
| 761 gfx::Vector2dF screen_space_scale_components( | |
| 762 device_transform_scale_components.x() * device_scale_factor * | |
| 763 page_scale_factor_for_root, | |
| 764 device_transform_scale_components.y() * device_scale_factor * | |
| 765 page_scale_factor_for_root); | |
| 766 SetScreenSpaceScaleOnRootNode(screen_space_scale_components); | |
| 767 } | 732 } |
| 768 | 733 |
| 769 void TransformTree::UpdateInnerViewportContainerBoundsDelta() { | 734 void TransformTree::UpdateInnerViewportContainerBoundsDelta() { |
| 770 if (nodes_affected_by_inner_viewport_bounds_delta_.empty()) | 735 if (nodes_affected_by_inner_viewport_bounds_delta_.empty()) |
| 771 return; | 736 return; |
| 772 | 737 |
| 773 set_needs_update(true); | 738 set_needs_update(true); |
| 774 for (int i : nodes_affected_by_inner_viewport_bounds_delta_) | 739 for (int i : nodes_affected_by_inner_viewport_bounds_delta_) |
| 775 Node(i)->needs_local_transform_update = true; | 740 Node(i)->needs_local_transform_update = true; |
| 776 } | 741 } |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1055 transform_node->local.IsBackFaceVisible(); | 1020 transform_node->local.IsBackFaceVisible(); |
| 1056 } | 1021 } |
| 1057 return; | 1022 return; |
| 1058 } | 1023 } |
| 1059 } | 1024 } |
| 1060 } | 1025 } |
| 1061 node->hidden_by_backface_visibility = false; | 1026 node->hidden_by_backface_visibility = false; |
| 1062 } | 1027 } |
| 1063 | 1028 |
| 1064 void EffectTree::UpdateSurfaceContentsScale(EffectNode* effect_node) { | 1029 void EffectTree::UpdateSurfaceContentsScale(EffectNode* effect_node) { |
| 1065 if (!effect_node->has_render_surface) { | 1030 if (!effect_node->has_render_surface || |
| 1031 effect_node->transform_id == kRootNodeId) { |
| 1066 effect_node->surface_contents_scale = gfx::Vector2dF(1.0f, 1.0f); | 1032 effect_node->surface_contents_scale = gfx::Vector2dF(1.0f, 1.0f); |
| 1067 return; | 1033 return; |
| 1068 } | 1034 } |
| 1069 | 1035 |
| 1070 TransformTree& transform_tree = property_trees()->transform_tree; | 1036 TransformTree& transform_tree = property_trees()->transform_tree; |
| 1071 float layer_scale_factor = transform_tree.device_scale_factor() * | 1037 float layer_scale_factor = transform_tree.device_scale_factor() * |
| 1072 transform_tree.device_transform_scale_factor(); | 1038 transform_tree.device_transform_scale_factor(); |
| 1073 TransformNode* transform_node = | 1039 TransformNode* transform_node = |
| 1074 transform_tree.Node(effect_node->transform_id); | 1040 transform_tree.Node(effect_node->transform_id); |
| 1075 if (transform_node->in_subtree_of_page_scale_layer) | 1041 if (transform_node->in_subtree_of_page_scale_layer) |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1175 } else { | 1141 } else { |
| 1176 // The root surface doesn't have the notion of sub-layer scale, but | 1142 // The root surface doesn't have the notion of sub-layer scale, but |
| 1177 // instead has a similar notion of transforming from the space of the root | 1143 // instead has a similar notion of transforming from the space of the root |
| 1178 // layer to the space of the screen. | 1144 // layer to the space of the screen. |
| 1179 DCHECK_EQ(kRootNodeId, destination_id); | 1145 DCHECK_EQ(kRootNodeId, destination_id); |
| 1180 source_id = TransformTree::kContentsRootNodeId; | 1146 source_id = TransformTree::kContentsRootNodeId; |
| 1181 } | 1147 } |
| 1182 gfx::Transform transform; | 1148 gfx::Transform transform; |
| 1183 property_trees()->transform_tree.ComputeTransform(source_id, destination_id, | 1149 property_trees()->transform_tree.ComputeTransform(source_id, destination_id, |
| 1184 &transform); | 1150 &transform); |
| 1185 transform.matrix().postScale(effect_node->surface_contents_scale.x(), | 1151 if (effect_node->id != kContentsRootNodeId) { |
| 1186 effect_node->surface_contents_scale.y(), 1.f); | 1152 transform.matrix().postScale(effect_node->surface_contents_scale.x(), |
| 1153 effect_node->surface_contents_scale.y(), |
| 1154 1.f); |
| 1155 } |
| 1187 it->set_area(MathUtil::MapEnclosingClippedRect(transform, it->area())); | 1156 it->set_area(MathUtil::MapEnclosingClippedRect(transform, it->area())); |
| 1188 } | 1157 } |
| 1189 } | 1158 } |
| 1190 | 1159 |
| 1191 bool EffectTree::HasCopyRequests() const { | 1160 bool EffectTree::HasCopyRequests() const { |
| 1192 return !copy_requests_.empty(); | 1161 return !copy_requests_.empty(); |
| 1193 } | 1162 } |
| 1194 | 1163 |
| 1195 void EffectTree::ClearCopyRequests() { | 1164 void EffectTree::ClearCopyRequests() { |
| 1196 for (auto& node : nodes()) { | 1165 for (auto& node : nodes()) { |
| (...skipping 1199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2396 from_target.ConcatTransform(draw_transforms.from_target); | 2365 from_target.ConcatTransform(draw_transforms.from_target); |
| 2397 from_target.Scale(effect_node->surface_contents_scale.x(), | 2366 from_target.Scale(effect_node->surface_contents_scale.x(), |
| 2398 effect_node->surface_contents_scale.y()); | 2367 effect_node->surface_contents_scale.y()); |
| 2399 DCHECK(from_target.ApproximatelyEqual(*transform) || | 2368 DCHECK(from_target.ApproximatelyEqual(*transform) || |
| 2400 !draw_transforms.invertible); | 2369 !draw_transforms.invertible); |
| 2401 } | 2370 } |
| 2402 return success; | 2371 return success; |
| 2403 } | 2372 } |
| 2404 | 2373 |
| 2405 } // namespace cc | 2374 } // namespace cc |
| OLD | NEW |