Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(216)

Side by Side Diff: cc/trees/property_tree.cc

Issue 2408243002: cc : Move screen space scale factor to root transform node (Closed)
Patch Set: test Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
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::SetDeviceTransform(const gfx::Transform& transform,
709 gfx::PointF root_position) { 707 gfx::PointF root_position) {
710 gfx::Transform root_post_local = transform; 708 gfx::Vector2dF device_transform_scale_components =
711 TransformNode* node = Node(1); 709 MathUtil::ComputeTransform2dScaleComponents(transform, 1.f);
712 root_post_local.Scale(node->post_local_scale_factor, 710 gfx::Transform post_local = transform;
713 node->post_local_scale_factor); 711 post_local.matrix().postScale(1.f / device_transform_scale_components.x(),
714 root_post_local.Translate(root_position.x(), root_position.y()); 712 1.f / device_transform_scale_components.y(),
715 if (node->post_local == root_post_local) 713 1.f);
714 post_local.Translate(root_position.x(), root_position.y());
715
716 TransformNode* node = Node(kContentsRootNodeId);
717 if (node->post_local == post_local)
716 return; 718 return;
717 719 node->post_local = post_local;
718 node->post_local = root_post_local;
719 node->needs_local_transform_update = true; 720 node->needs_local_transform_update = true;
720 set_needs_update(true); 721 set_needs_update(true);
721 } 722 }
722 723
723 void TransformTree::SetDeviceTransformScaleFactor( 724 void TransformTree::SetDeviceTransformScaleFactor(
724 const gfx::Transform& transform) { 725 const gfx::Transform& transform) {
725 gfx::Vector2dF device_transform_scale_components = 726 gfx::Vector2dF device_transform_scale_components =
726 MathUtil::ComputeTransform2dScaleComponents(transform, 1.f); 727 MathUtil::ComputeTransform2dScaleComponents(transform, 1.f);
727 728
728 // Not handling the rare case of different x and y device scale. 729 // Not handling the rare case of different x and y device scale.
729 device_transform_scale_factor_ = 730 device_transform_scale_factor_ =
730 std::max(device_transform_scale_components.x(), 731 std::max(device_transform_scale_components.x(),
731 device_transform_scale_components.y()); 732 device_transform_scale_components.y());
732 } 733 }
733 734
735 void TransformTree::SetScreenSpaceScale(float device_scale_factor,
736 float page_scale_factor_for_root,
737 gfx::Transform device_transform) {
738 gfx::Vector2dF device_transform_scale_components =
739 MathUtil::ComputeTransform2dScaleComponents(device_transform, 1.f);
740 gfx::Vector2dF screen_space_scale_components(
741 device_transform_scale_components.x() * device_scale_factor *
742 page_scale_factor_for_root,
743 device_transform_scale_components.y() * device_scale_factor *
744 page_scale_factor_for_root);
745 TransformNode* node = Node(kRootNodeId);
746 if (node->surface_contents_scale == screen_space_scale_components)
747 return;
748 node->needs_surface_contents_scale = true;
749 node->surface_contents_scale = screen_space_scale_components;
750 gfx::Transform to_screen;
751 to_screen.Scale(node->surface_contents_scale.x(),
752 node->surface_contents_scale.y());
753 SetToScreen(node->id, to_screen);
754 gfx::Transform from_screen;
755 if (!ToScreen(node->id).GetInverse(&from_screen))
756 node->ancestors_are_invertible = false;
757 SetFromScreen(node->id, from_screen);
758 set_needs_update(true);
759 }
760
734 void TransformTree::UpdateInnerViewportContainerBoundsDelta() { 761 void TransformTree::UpdateInnerViewportContainerBoundsDelta() {
735 if (nodes_affected_by_inner_viewport_bounds_delta_.empty()) 762 if (nodes_affected_by_inner_viewport_bounds_delta_.empty())
736 return; 763 return;
737 764
738 set_needs_update(true); 765 set_needs_update(true);
739 for (int i : nodes_affected_by_inner_viewport_bounds_delta_) 766 for (int i : nodes_affected_by_inner_viewport_bounds_delta_)
740 Node(i)->needs_local_transform_update = true; 767 Node(i)->needs_local_transform_update = true;
741 } 768 }
742 769
743 void TransformTree::UpdateOuterViewportContainerBoundsDelta() { 770 void TransformTree::UpdateOuterViewportContainerBoundsDelta() {
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
1020 transform_node->local.IsBackFaceVisible(); 1047 transform_node->local.IsBackFaceVisible();
1021 } 1048 }
1022 return; 1049 return;
1023 } 1050 }
1024 } 1051 }
1025 } 1052 }
1026 node->hidden_by_backface_visibility = false; 1053 node->hidden_by_backface_visibility = false;
1027 } 1054 }
1028 1055
1029 void EffectTree::UpdateSurfaceContentsScale(EffectNode* effect_node) { 1056 void EffectTree::UpdateSurfaceContentsScale(EffectNode* effect_node) {
1030 if (!effect_node->has_render_surface || 1057 if (!effect_node->has_render_surface) {
1031 effect_node->transform_id == kRootNodeId) {
1032 effect_node->surface_contents_scale = gfx::Vector2dF(1.0f, 1.0f); 1058 effect_node->surface_contents_scale = gfx::Vector2dF(1.0f, 1.0f);
1033 return; 1059 return;
1034 } 1060 }
1035 1061
1036 TransformTree& transform_tree = property_trees()->transform_tree; 1062 TransformTree& transform_tree = property_trees()->transform_tree;
1037 float layer_scale_factor = transform_tree.device_scale_factor() * 1063 float layer_scale_factor = transform_tree.device_scale_factor() *
1038 transform_tree.device_transform_scale_factor(); 1064 transform_tree.device_transform_scale_factor();
1039 TransformNode* transform_node = 1065 TransformNode* transform_node =
1040 transform_tree.Node(effect_node->transform_id); 1066 transform_tree.Node(effect_node->transform_id);
1041 if (transform_node->in_subtree_of_page_scale_layer) 1067 if (transform_node->in_subtree_of_page_scale_layer)
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1141 } else { 1167 } else {
1142 // The root surface doesn't have the notion of sub-layer scale, but 1168 // 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 1169 // instead has a similar notion of transforming from the space of the root
1144 // layer to the space of the screen. 1170 // layer to the space of the screen.
1145 DCHECK_EQ(kRootNodeId, destination_id); 1171 DCHECK_EQ(kRootNodeId, destination_id);
1146 source_id = TransformTree::kContentsRootNodeId; 1172 source_id = TransformTree::kContentsRootNodeId;
1147 } 1173 }
1148 gfx::Transform transform; 1174 gfx::Transform transform;
1149 property_trees()->transform_tree.ComputeTransform(source_id, destination_id, 1175 property_trees()->transform_tree.ComputeTransform(source_id, destination_id,
1150 &transform); 1176 &transform);
1151 if (effect_node->id != kContentsRootNodeId) { 1177 transform.matrix().postScale(effect_node->surface_contents_scale.x(),
1152 transform.matrix().postScale(effect_node->surface_contents_scale.x(), 1178 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())); 1179 it->set_area(MathUtil::MapEnclosingClippedRect(transform, it->area()));
1157 } 1180 }
1158 } 1181 }
1159 1182
1160 bool EffectTree::HasCopyRequests() const { 1183 bool EffectTree::HasCopyRequests() const {
1161 return !copy_requests_.empty(); 1184 return !copy_requests_.empty();
1162 } 1185 }
1163 1186
1164 void EffectTree::ClearCopyRequests() { 1187 void EffectTree::ClearCopyRequests() {
1165 for (auto& node : nodes()) { 1188 for (auto& node : nodes()) {
(...skipping 1199 matching lines...) Expand 10 before | Expand all | Expand 10 after
2365 from_target.ConcatTransform(draw_transforms.from_target); 2388 from_target.ConcatTransform(draw_transforms.from_target);
2366 from_target.Scale(effect_node->surface_contents_scale.x(), 2389 from_target.Scale(effect_node->surface_contents_scale.x(),
2367 effect_node->surface_contents_scale.y()); 2390 effect_node->surface_contents_scale.y());
2368 DCHECK(from_target.ApproximatelyEqual(*transform) || 2391 DCHECK(from_target.ApproximatelyEqual(*transform) ||
2369 !draw_transforms.invertible); 2392 !draw_transforms.invertible);
2370 } 2393 }
2371 return success; 2394 return success;
2372 } 2395 }
2373 2396
2374 } // namespace cc 2397 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698