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

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

Issue 2473453002: cc : Reland move screen space scale factor to root transform node (Closed)
Patch Set: . Created 4 years, 1 month 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
« no previous file with comments | « cc/trees/property_tree.h ('k') | cc/trees/property_tree_builder.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 650 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 bool is_invertible = node->is_invertible; 661 bool is_invertible = node->is_invertible;
662 // Even when the current node's transform and the parent's screen space 662 // Even when the current node's transform and the parent's screen space
663 // transform are invertible, the current node's screen space transform can 663 // transform are invertible, the current node's screen space transform can
664 // become uninvertible due to floating-point arithmetic. 664 // become uninvertible due to floating-point arithmetic.
665 if (!node->ancestors_are_invertible && parent_node->ancestors_are_invertible) 665 if (!node->ancestors_are_invertible && parent_node->ancestors_are_invertible)
666 is_invertible = false; 666 is_invertible = false;
667 node->node_and_ancestors_are_animated_or_invertible = 667 node->node_and_ancestors_are_animated_or_invertible =
668 node->has_potential_animation || is_invertible; 668 node->has_potential_animation || is_invertible;
669 } 669 }
670 670
671 void TransformTree::SetDeviceTransform(const gfx::Transform& transform, 671 void TransformTree::SetRootTransformsAndScales(
672 gfx::PointF root_position) { 672 float device_scale_factor,
673 gfx::Transform root_post_local = transform; 673 float page_scale_factor_for_root,
674 TransformNode* node = Node(1); 674 const gfx::Transform& device_transform,
675 root_post_local.Scale(node->post_local_scale_factor, 675 gfx::PointF root_position) {
676 node->post_local_scale_factor); 676 // If DT is the device transform, DSF is the matrix scaled by (device scale
677 root_post_local.Translate(root_position.x(), root_position.y()); 677 // factor * page scale factor for root), RP is the matrix translated by root's
678 if (node->post_local == root_post_local) 678 // position,
679 return; 679 // Let Screen Space Scale(SSS) = scale component of DT*DSF*RP,
680 // then the screen space transform of the root transform node is set to SSS
681 // and the post local transform of the contents root node is set to
682 // SSS^-1*DT*DSF*RP.
683 gfx::Transform transform = device_transform;
684 transform.Scale(device_scale_factor * page_scale_factor_for_root,
685 device_scale_factor * page_scale_factor_for_root);
686 transform.Translate(root_position.x(), root_position.y());
687 float fallback_value = device_scale_factor * page_scale_factor_for_root;
688 gfx::Vector2dF screen_space_scale =
689 MathUtil::ComputeTransform2dScaleComponents(transform, fallback_value);
690 DCHECK_NE(screen_space_scale.x(), 0.f);
691 DCHECK_NE(screen_space_scale.y(), 0.f);
680 692
681 node->post_local = root_post_local; 693 gfx::Transform root_to_screen;
682 node->needs_local_transform_update = true; 694 root_to_screen.Scale(screen_space_scale.x(), screen_space_scale.y());
695 gfx::Transform root_from_screen;
696 bool invertible = root_to_screen.GetInverse(&root_from_screen);
697 DCHECK(invertible);
698 SetToScreen(kRootNodeId, root_to_screen);
699 SetFromScreen(kRootNodeId, root_from_screen);
683 set_needs_update(true); 700 set_needs_update(true);
701
702 transform.ConcatTransform(root_from_screen);
703 TransformNode* contents_root_node = Node(kContentsRootNodeId);
704 if (contents_root_node->post_local != transform) {
705 contents_root_node->post_local = transform;
706 contents_root_node->needs_local_transform_update = true;
707 }
684 } 708 }
685 709
686 void TransformTree::SetDeviceTransformScaleFactor( 710 void TransformTree::SetDeviceTransformScaleFactor(
weiliangc 2016/11/02 15:38:21 Could this function be folded into above function?
jaydasika 2016/11/02 17:36:55 Done.
687 const gfx::Transform& transform) { 711 const gfx::Transform& transform) {
688 gfx::Vector2dF device_transform_scale_components = 712 gfx::Vector2dF device_transform_scale_components =
689 MathUtil::ComputeTransform2dScaleComponents(transform, 1.f); 713 MathUtil::ComputeTransform2dScaleComponents(transform, 1.f);
690 714
691 // Not handling the rare case of different x and y device scale. 715 // Not handling the rare case of different x and y device scale.
692 device_transform_scale_factor_ = 716 device_transform_scale_factor_ =
693 std::max(device_transform_scale_components.x(), 717 std::max(device_transform_scale_components.x(),
694 device_transform_scale_components.y()); 718 device_transform_scale_components.y());
695 } 719 }
696 720
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
945 transform_node->local.IsBackFaceVisible(); 969 transform_node->local.IsBackFaceVisible();
946 } 970 }
947 return; 971 return;
948 } 972 }
949 } 973 }
950 } 974 }
951 node->hidden_by_backface_visibility = false; 975 node->hidden_by_backface_visibility = false;
952 } 976 }
953 977
954 void EffectTree::UpdateSurfaceContentsScale(EffectNode* effect_node) { 978 void EffectTree::UpdateSurfaceContentsScale(EffectNode* effect_node) {
955 if (!effect_node->has_render_surface || 979 if (!effect_node->has_render_surface) {
956 effect_node->transform_id == kRootNodeId) {
957 effect_node->surface_contents_scale = gfx::Vector2dF(1.0f, 1.0f); 980 effect_node->surface_contents_scale = gfx::Vector2dF(1.0f, 1.0f);
958 return; 981 return;
959 } 982 }
960 983
961 TransformTree& transform_tree = property_trees()->transform_tree; 984 TransformTree& transform_tree = property_trees()->transform_tree;
962 float layer_scale_factor = transform_tree.device_scale_factor() * 985 float layer_scale_factor = transform_tree.device_scale_factor() *
963 transform_tree.device_transform_scale_factor(); 986 transform_tree.device_transform_scale_factor();
964 TransformNode* transform_node = 987 TransformNode* transform_node =
965 transform_tree.Node(effect_node->transform_id); 988 transform_tree.Node(effect_node->transform_id);
966 if (transform_node->in_subtree_of_page_scale_layer) 989 if (transform_node->in_subtree_of_page_scale_layer)
(...skipping 1204 matching lines...) Expand 10 before | Expand all | Expand 10 after
2171 gfx::Transform from_target; 2194 gfx::Transform from_target;
2172 bool already_computed_inverse = false; 2195 bool already_computed_inverse = false;
2173 if (transform_id == dest_id) { 2196 if (transform_id == dest_id) {
2174 target_space_transform.Scale(effect_node->surface_contents_scale.x(), 2197 target_space_transform.Scale(effect_node->surface_contents_scale.x(),
2175 effect_node->surface_contents_scale.y()); 2198 effect_node->surface_contents_scale.y());
2176 data.transforms.to_valid = true; 2199 data.transforms.to_valid = true;
2177 data.transforms.from_valid = false; 2200 data.transforms.from_valid = false;
2178 } else if (transform_id > dest_id) { 2201 } else if (transform_id > dest_id) {
2179 transform_tree.CombineTransformsBetween(transform_id, dest_id, 2202 transform_tree.CombineTransformsBetween(transform_id, dest_id,
2180 &target_space_transform); 2203 &target_space_transform);
2181 if (dest_id != TransformTree::kRootNodeId) 2204 target_space_transform.matrix().postScale(
2182 target_space_transform.matrix().postScale( 2205 effect_node->surface_contents_scale.x(),
2183 effect_node->surface_contents_scale.x(), 2206 effect_node->surface_contents_scale.y(), 1.f);
2184 effect_node->surface_contents_scale.y(), 1.f);
2185 data.transforms.to_valid = true; 2207 data.transforms.to_valid = true;
2186 data.transforms.from_valid = false; 2208 data.transforms.from_valid = false;
2187 data.transforms.might_be_invertible = true; 2209 data.transforms.might_be_invertible = true;
2188 } else { 2210 } else {
2189 gfx::Transform combined_transform; 2211 gfx::Transform combined_transform;
2190 transform_tree.CombineTransformsBetween(dest_id, transform_id, 2212 transform_tree.CombineTransformsBetween(dest_id, transform_id,
2191 &combined_transform); 2213 &combined_transform);
2192 if (effect_node->surface_contents_scale.x() != 0.f && 2214 if (effect_node->surface_contents_scale.x() != 0.f &&
2193 effect_node->surface_contents_scale.y() != 0.f) 2215 effect_node->surface_contents_scale.y() != 0.f)
2194 combined_transform.Scale(1.0f / effect_node->surface_contents_scale.x(), 2216 combined_transform.Scale(1.0f / effect_node->surface_contents_scale.x(),
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
2249 2271
2250 const EffectNode* effect_node = effect_tree.Node(effect_id); 2272 const EffectNode* effect_node = effect_tree.Node(effect_id);
2251 2273
2252 bool success = GetFromTarget(transform_id, effect_id, transform); 2274 bool success = GetFromTarget(transform_id, effect_id, transform);
2253 transform->Scale(effect_node->surface_contents_scale.x(), 2275 transform->Scale(effect_node->surface_contents_scale.x(),
2254 effect_node->surface_contents_scale.y()); 2276 effect_node->surface_contents_scale.y());
2255 return success; 2277 return success;
2256 } 2278 }
2257 2279
2258 } // namespace cc 2280 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/property_tree.h ('k') | cc/trees/property_tree_builder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698