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

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

Issue 2408243002: cc : Move screen space scale factor to root transform node (Closed)
Patch Set: comments 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 587 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
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::SetDeviceTransform(const gfx::Transform& transform,
707 gfx::PointF root_position) { 705 gfx::PointF root_position) {
708 gfx::Transform root_post_local = transform; 706 gfx::Vector2dF device_transform_scale_components =
709 TransformNode* node = Node(1); 707 MathUtil::ComputeTransform2dScaleComponents(transform, 1.f);
710 root_post_local.Scale(node->post_local_scale_factor, 708 gfx::Transform post_local = transform;
711 node->post_local_scale_factor); 709 post_local.matrix().postScale(1.f / device_transform_scale_components.x(),
weiliangc 2016/10/24 21:29:36 This assumes device transform's scale components i
jaydasika 2016/10/25 01:20:59 Done.
712 root_post_local.Translate(root_position.x(), root_position.y()); 710 1.f / device_transform_scale_components.y(),
713 if (node->post_local == root_post_local) 711 1.f);
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::SetDeviceTransformScaleFactor(
722 const gfx::Transform& transform) { 723 const gfx::Transform& transform) {
723 gfx::Vector2dF device_transform_scale_components = 724 gfx::Vector2dF device_transform_scale_components =
724 MathUtil::ComputeTransform2dScaleComponents(transform, 1.f); 725 MathUtil::ComputeTransform2dScaleComponents(transform, 1.f);
725 726
726 // Not handling the rare case of different x and y device scale. 727 // Not handling the rare case of different x and y device scale.
727 device_transform_scale_factor_ = 728 device_transform_scale_factor_ =
728 std::max(device_transform_scale_components.x(), 729 std::max(device_transform_scale_components.x(),
729 device_transform_scale_components.y()); 730 device_transform_scale_components.y());
730 } 731 }
731 732
733 void TransformTree::SetScreenSpaceScale(float device_scale_factor,
734 float page_scale_factor_for_root,
735 gfx::Transform device_transform) {
736 gfx::Vector2dF device_transform_scale_components =
737 MathUtil::ComputeTransform2dScaleComponents(device_transform, 1.f);
738 gfx::Vector2dF screen_space_scale_components(
739 device_transform_scale_components.x() * device_scale_factor *
740 page_scale_factor_for_root,
741 device_transform_scale_components.y() * device_scale_factor *
742 page_scale_factor_for_root);
743 TransformNode* node = Node(kRootNodeId);
744 if (node->surface_contents_scale == screen_space_scale_components)
745 return;
746 node->needs_surface_contents_scale = true;
747 node->surface_contents_scale = screen_space_scale_components;
748 gfx::Transform to_screen;
749 to_screen.Scale(node->surface_contents_scale.x(),
750 node->surface_contents_scale.y());
751 SetToScreen(node->id, to_screen);
752 gfx::Transform from_screen;
753 if (!ToScreen(node->id).GetInverse(&from_screen))
754 node->ancestors_are_invertible = false;
755 SetFromScreen(node->id, from_screen);
756 set_needs_update(true);
757 }
758
732 void TransformTree::UpdateInnerViewportContainerBoundsDelta() { 759 void TransformTree::UpdateInnerViewportContainerBoundsDelta() {
733 if (nodes_affected_by_inner_viewport_bounds_delta_.empty()) 760 if (nodes_affected_by_inner_viewport_bounds_delta_.empty())
734 return; 761 return;
735 762
736 set_needs_update(true); 763 set_needs_update(true);
737 for (int i : nodes_affected_by_inner_viewport_bounds_delta_) 764 for (int i : nodes_affected_by_inner_viewport_bounds_delta_)
738 Node(i)->needs_local_transform_update = true; 765 Node(i)->needs_local_transform_update = true;
739 } 766 }
740 767
741 void TransformTree::UpdateOuterViewportContainerBoundsDelta() { 768 void TransformTree::UpdateOuterViewportContainerBoundsDelta() {
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
1003 transform_node->local.IsBackFaceVisible(); 1030 transform_node->local.IsBackFaceVisible();
1004 } 1031 }
1005 return; 1032 return;
1006 } 1033 }
1007 } 1034 }
1008 } 1035 }
1009 node->hidden_by_backface_visibility = false; 1036 node->hidden_by_backface_visibility = false;
1010 } 1037 }
1011 1038
1012 void EffectTree::UpdateSurfaceContentsScale(EffectNode* effect_node) { 1039 void EffectTree::UpdateSurfaceContentsScale(EffectNode* effect_node) {
1013 if (!effect_node->has_render_surface || 1040 if (!effect_node->has_render_surface) {
1014 effect_node->transform_id == kRootNodeId) {
1015 effect_node->surface_contents_scale = gfx::Vector2dF(1.0f, 1.0f); 1041 effect_node->surface_contents_scale = gfx::Vector2dF(1.0f, 1.0f);
1016 return; 1042 return;
1017 } 1043 }
1018 1044
1019 TransformTree& transform_tree = property_trees()->transform_tree; 1045 TransformTree& transform_tree = property_trees()->transform_tree;
1020 float layer_scale_factor = transform_tree.device_scale_factor() * 1046 float layer_scale_factor = transform_tree.device_scale_factor() *
1021 transform_tree.device_transform_scale_factor(); 1047 transform_tree.device_transform_scale_factor();
1022 TransformNode* transform_node = 1048 TransformNode* transform_node =
1023 transform_tree.Node(effect_node->transform_id); 1049 transform_tree.Node(effect_node->transform_id);
1024 if (transform_node->in_subtree_of_page_scale_layer) 1050 if (transform_node->in_subtree_of_page_scale_layer)
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1124 } else { 1150 } else {
1125 // The root surface doesn't have the notion of sub-layer scale, but 1151 // 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 1152 // instead has a similar notion of transforming from the space of the root
1127 // layer to the space of the screen. 1153 // layer to the space of the screen.
1128 DCHECK_EQ(kRootNodeId, destination_id); 1154 DCHECK_EQ(kRootNodeId, destination_id);
1129 source_id = TransformTree::kContentsRootNodeId; 1155 source_id = TransformTree::kContentsRootNodeId;
1130 } 1156 }
1131 gfx::Transform transform; 1157 gfx::Transform transform;
1132 property_trees()->transform_tree.ComputeTransform(source_id, destination_id, 1158 property_trees()->transform_tree.ComputeTransform(source_id, destination_id,
1133 &transform); 1159 &transform);
1134 if (effect_node->id != kContentsRootNodeId) { 1160 transform.matrix().postScale(effect_node->surface_contents_scale.x(),
1135 transform.matrix().postScale(effect_node->surface_contents_scale.x(), 1161 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())); 1162 it->set_area(MathUtil::MapEnclosingClippedRect(transform, it->area()));
1140 } 1163 }
1141 } 1164 }
1142 1165
1143 bool EffectTree::HasCopyRequests() const { 1166 bool EffectTree::HasCopyRequests() const {
1144 return !copy_requests_.empty(); 1167 return !copy_requests_.empty();
1145 } 1168 }
1146 1169
1147 void EffectTree::ClearCopyRequests() { 1170 void EffectTree::ClearCopyRequests() {
1148 for (auto& node : nodes()) { 1171 for (auto& node : nodes()) {
(...skipping 1086 matching lines...) Expand 10 before | Expand all | Expand 10 after
2235 gfx::Transform from_target; 2258 gfx::Transform from_target;
2236 bool already_computed_inverse = false; 2259 bool already_computed_inverse = false;
2237 if (transform_id == dest_id) { 2260 if (transform_id == dest_id) {
2238 target_space_transform.Scale(effect_node->surface_contents_scale.x(), 2261 target_space_transform.Scale(effect_node->surface_contents_scale.x(),
2239 effect_node->surface_contents_scale.y()); 2262 effect_node->surface_contents_scale.y());
2240 data.transforms.to_valid = true; 2263 data.transforms.to_valid = true;
2241 data.transforms.from_valid = false; 2264 data.transforms.from_valid = false;
2242 } else if (transform_id > dest_id) { 2265 } else if (transform_id > dest_id) {
2243 transform_tree.CombineTransformsBetween(transform_id, dest_id, 2266 transform_tree.CombineTransformsBetween(transform_id, dest_id,
2244 &target_space_transform); 2267 &target_space_transform);
2245 if (dest_id != TransformTree::kRootNodeId) 2268 target_space_transform.matrix().postScale(
2246 target_space_transform.matrix().postScale( 2269 effect_node->surface_contents_scale.x(),
2247 effect_node->surface_contents_scale.x(), 2270 effect_node->surface_contents_scale.y(), 1.f);
2248 effect_node->surface_contents_scale.y(), 1.f);
2249 data.transforms.to_valid = true; 2271 data.transforms.to_valid = true;
2250 data.transforms.from_valid = false; 2272 data.transforms.from_valid = false;
2251 data.transforms.might_be_invertible = true; 2273 data.transforms.might_be_invertible = true;
2252 } else { 2274 } else {
2253 gfx::Transform combined_transform; 2275 gfx::Transform combined_transform;
2254 transform_tree.CombineTransformsBetween(dest_id, transform_id, 2276 transform_tree.CombineTransformsBetween(dest_id, transform_id,
2255 &combined_transform); 2277 &combined_transform);
2256 if (effect_node->surface_contents_scale.x() != 0.f && 2278 if (effect_node->surface_contents_scale.x() != 0.f &&
2257 effect_node->surface_contents_scale.y() != 0.f) 2279 effect_node->surface_contents_scale.y() != 0.f)
2258 combined_transform.Scale(1.0f / effect_node->surface_contents_scale.x(), 2280 combined_transform.Scale(1.0f / effect_node->surface_contents_scale.x(),
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
2332 2354
2333 const EffectNode* effect_node = effect_tree.Node(effect_id); 2355 const EffectNode* effect_node = effect_tree.Node(effect_id);
2334 2356
2335 bool success = GetFromTarget(transform_id, effect_id, transform); 2357 bool success = GetFromTarget(transform_id, effect_id, transform);
2336 transform->Scale(effect_node->surface_contents_scale.x(), 2358 transform->Scale(effect_node->surface_contents_scale.x(),
2337 effect_node->surface_contents_scale.y()); 2359 effect_node->surface_contents_scale.y());
2338 return success; 2360 return success;
2339 } 2361 }
2340 2362
2341 } // namespace cc 2363 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698