| 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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 return CombineInversesBetween(source_id, dest_id, transform); | 157 return CombineInversesBetween(source_id, dest_id, transform); |
| 158 } | 158 } |
| 159 | 159 |
| 160 bool TransformTree::ComputeTransformWithDestinationSublayerScale( | 160 bool TransformTree::ComputeTransformWithDestinationSublayerScale( |
| 161 int source_id, | 161 int source_id, |
| 162 int dest_id, | 162 int dest_id, |
| 163 gfx::Transform* transform) const { | 163 gfx::Transform* transform) const { |
| 164 bool success = ComputeTransform(source_id, dest_id, transform); | 164 bool success = ComputeTransform(source_id, dest_id, transform); |
| 165 | 165 |
| 166 const TransformNode* dest_node = Node(dest_id); | 166 const TransformNode* dest_node = Node(dest_id); |
| 167 if (!dest_node->needs_sublayer_scale) | 167 if (!dest_node->needs_surface_contents_scale) |
| 168 return success; | 168 return success; |
| 169 | 169 |
| 170 transform->matrix().postScale(dest_node->sublayer_scale.x(), | 170 transform->matrix().postScale(dest_node->surface_contents_scale.x(), |
| 171 dest_node->sublayer_scale.y(), 1.f); | 171 dest_node->surface_contents_scale.y(), 1.f); |
| 172 return success; | 172 return success; |
| 173 } | 173 } |
| 174 | 174 |
| 175 bool TransformTree::ComputeTransformWithSourceSublayerScale( | |
| 176 int source_id, | |
| 177 int dest_id, | |
| 178 gfx::Transform* transform) const { | |
| 179 bool success = ComputeTransform(source_id, dest_id, transform); | |
| 180 | |
| 181 const TransformNode* source_node = Node(source_id); | |
| 182 if (!source_node->needs_sublayer_scale) | |
| 183 return success; | |
| 184 | |
| 185 if (source_node->sublayer_scale.x() == 0 || | |
| 186 source_node->sublayer_scale.y() == 0) | |
| 187 return false; | |
| 188 | |
| 189 transform->Scale(1.f / source_node->sublayer_scale.x(), | |
| 190 1.f / source_node->sublayer_scale.y()); | |
| 191 return success; | |
| 192 } | |
| 193 | |
| 194 bool TransformTree::Are2DAxisAligned(int source_id, int dest_id) const { | 175 bool TransformTree::Are2DAxisAligned(int source_id, int dest_id) const { |
| 195 gfx::Transform transform; | 176 gfx::Transform transform; |
| 196 return ComputeTransform(source_id, dest_id, &transform) && | 177 return ComputeTransform(source_id, dest_id, &transform) && |
| 197 transform.Preserves2dAxisAlignment(); | 178 transform.Preserves2dAxisAlignment(); |
| 198 } | 179 } |
| 199 | 180 |
| 200 bool TransformTree::NeedsSourceToParentUpdate(TransformNode* node) { | 181 bool TransformTree::NeedsSourceToParentUpdate(TransformNode* node) { |
| 201 return (source_to_parent_updates_allowed() && | 182 return (source_to_parent_updates_allowed() && |
| 202 node->parent_id != node->source_node_id); | 183 node->parent_id != node->source_node_id); |
| 203 } | 184 } |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 // path from the source to the destination (this is traversing upward), and | 248 // path from the source to the destination (this is traversing upward), and |
| 268 // then we visit these nodes in reverse order, flattening as needed. We | 249 // then we visit these nodes in reverse order, flattening as needed. We |
| 269 // early-out if we get to a node whose target node is the destination, since | 250 // early-out if we get to a node whose target node is the destination, since |
| 270 // we can then re-use the target space transform stored at that node. However, | 251 // we can then re-use the target space transform stored at that node. However, |
| 271 // we cannot re-use a stored target space transform if the destination has a | 252 // we cannot re-use a stored target space transform if the destination has a |
| 272 // zero sublayer scale, since stored target space transforms have sublayer | 253 // zero sublayer scale, since stored target space transforms have sublayer |
| 273 // scale baked in, but we need to compute an unscaled transform. | 254 // scale baked in, but we need to compute an unscaled transform. |
| 274 std::vector<int> source_to_destination; | 255 std::vector<int> source_to_destination; |
| 275 source_to_destination.push_back(current->id); | 256 source_to_destination.push_back(current->id); |
| 276 current = parent(current); | 257 current = parent(current); |
| 277 bool destination_has_non_zero_sublayer_scale = | 258 bool destination_has_non_zero_surface_contents_scale = |
| 278 dest->sublayer_scale.x() != 0.f && dest->sublayer_scale.y() != 0.f; | 259 dest->surface_contents_scale.x() != 0.f && |
| 279 DCHECK(destination_has_non_zero_sublayer_scale || | 260 dest->surface_contents_scale.y() != 0.f; |
| 261 DCHECK(destination_has_non_zero_surface_contents_scale || |
| 280 !dest->ancestors_are_invertible); | 262 !dest->ancestors_are_invertible); |
| 281 for (; current && current->id > dest_id; current = parent(current)) { | 263 for (; current && current->id > dest_id; current = parent(current)) { |
| 282 if (destination_has_non_zero_sublayer_scale && | 264 if (destination_has_non_zero_surface_contents_scale && |
| 283 TargetId(current->id) == dest_id && | 265 TargetId(current->id) == dest_id && |
| 284 ContentTargetId(current->id) == dest_id) | 266 ContentTargetId(current->id) == dest_id) |
| 285 break; | 267 break; |
| 286 source_to_destination.push_back(current->id); | 268 source_to_destination.push_back(current->id); |
| 287 } | 269 } |
| 288 | 270 |
| 289 gfx::Transform combined_transform; | 271 gfx::Transform combined_transform; |
| 290 if (current->id > dest_id) { | 272 if (current->id > dest_id) { |
| 291 combined_transform = ToTarget(current->id); | 273 combined_transform = ToTarget(current->id); |
| 292 // The stored target space transform has sublayer scale baked in, but we | 274 // The stored target space transform has sublayer scale baked in, but we |
| 293 // need the unscaled transform. | 275 // need the unscaled transform. |
| 294 combined_transform.matrix().postScale( | 276 combined_transform.matrix().postScale( |
| 295 1.0f / dest->sublayer_scale.x(), 1.0f / dest->sublayer_scale.y(), 1.0f); | 277 1.0f / dest->surface_contents_scale.x(), |
| 278 1.0f / dest->surface_contents_scale.y(), 1.0f); |
| 296 } else if (current->id < dest_id) { | 279 } else if (current->id < dest_id) { |
| 297 // We have reached the lowest common ancestor of the source and destination | 280 // We have reached the lowest common ancestor of the source and destination |
| 298 // nodes. This case can occur when we are transforming between a node | 281 // nodes. This case can occur when we are transforming between a node |
| 299 // corresponding to a fixed-position layer (or its descendant) and the node | 282 // corresponding to a fixed-position layer (or its descendant) and the node |
| 300 // corresponding to the layer's render target. For example, consider the | 283 // corresponding to the layer's render target. For example, consider the |
| 301 // layer tree R->T->S->F where F is fixed-position, S owns a render surface, | 284 // layer tree R->T->S->F where F is fixed-position, S owns a render surface, |
| 302 // and T has a significant transform. This will yield the following | 285 // and T has a significant transform. This will yield the following |
| 303 // transform tree: | 286 // transform tree: |
| 304 // R | 287 // R |
| 305 // | | 288 // | |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 } | 396 } |
| 414 | 397 |
| 415 gfx::Transform from_screen; | 398 gfx::Transform from_screen; |
| 416 if (!ToScreen(node->id).GetInverse(&from_screen)) | 399 if (!ToScreen(node->id).GetInverse(&from_screen)) |
| 417 node->ancestors_are_invertible = false; | 400 node->ancestors_are_invertible = false; |
| 418 SetFromScreen(node->id, from_screen); | 401 SetFromScreen(node->id, from_screen); |
| 419 } | 402 } |
| 420 | 403 |
| 421 void TransformTree::UpdateSublayerScale(TransformNode* node) { | 404 void TransformTree::UpdateSublayerScale(TransformNode* node) { |
| 422 // The sublayer scale depends on the screen space transform, so update it too. | 405 // The sublayer scale depends on the screen space transform, so update it too. |
| 423 if (!node->needs_sublayer_scale) { | 406 if (!node->needs_surface_contents_scale) { |
| 424 node->sublayer_scale = gfx::Vector2dF(1.0f, 1.0f); | 407 node->surface_contents_scale = gfx::Vector2dF(1.0f, 1.0f); |
| 425 return; | 408 return; |
| 426 } | 409 } |
| 427 | 410 |
| 428 float layer_scale_factor = | 411 float layer_scale_factor = |
| 429 device_scale_factor_ * device_transform_scale_factor_; | 412 device_scale_factor_ * device_transform_scale_factor_; |
| 430 if (node->in_subtree_of_page_scale_layer) | 413 if (node->in_subtree_of_page_scale_layer) |
| 431 layer_scale_factor *= page_scale_factor_; | 414 layer_scale_factor *= page_scale_factor_; |
| 432 node->sublayer_scale = MathUtil::ComputeTransform2dScaleComponents( | 415 node->surface_contents_scale = MathUtil::ComputeTransform2dScaleComponents( |
| 433 ToScreen(node->id), layer_scale_factor); | 416 ToScreen(node->id), layer_scale_factor); |
| 434 } | 417 } |
| 435 | 418 |
| 436 void TransformTree::UpdateTargetSpaceTransform(TransformNode* node, | 419 void TransformTree::UpdateTargetSpaceTransform(TransformNode* node, |
| 437 TransformNode* target_node) { | 420 TransformNode* target_node) { |
| 438 gfx::Transform target_space_transform; | 421 gfx::Transform target_space_transform; |
| 439 if (node->needs_sublayer_scale) { | 422 if (node->needs_surface_contents_scale) { |
| 440 target_space_transform.MakeIdentity(); | 423 target_space_transform.MakeIdentity(); |
| 441 target_space_transform.Scale(node->sublayer_scale.x(), | 424 target_space_transform.Scale(node->surface_contents_scale.x(), |
| 442 node->sublayer_scale.y()); | 425 node->surface_contents_scale.y()); |
| 443 } else { | 426 } else { |
| 444 // In order to include the root transform for the root surface, we walk up | 427 // In order to include the root transform for the root surface, we walk up |
| 445 // to the root of the transform tree in ComputeTransform. | 428 // to the root of the transform tree in ComputeTransform. |
| 446 int target_id = target_node->id; | 429 int target_id = target_node->id; |
| 447 ComputeTransformWithDestinationSublayerScale(node->id, target_id, | 430 ComputeTransformWithDestinationSublayerScale(node->id, target_id, |
| 448 &target_space_transform); | 431 &target_space_transform); |
| 449 } | 432 } |
| 450 | 433 |
| 451 gfx::Transform from_target; | 434 gfx::Transform from_target; |
| 452 if (!target_space_transform.GetInverse(&from_target)) | 435 if (!target_space_transform.GetInverse(&from_target)) |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 662 } | 645 } |
| 663 | 646 |
| 664 gfx::Transform TransformTree::ToScreenSpaceTransformWithoutSublayerScale( | 647 gfx::Transform TransformTree::ToScreenSpaceTransformWithoutSublayerScale( |
| 665 int id) const { | 648 int id) const { |
| 666 DCHECK_GT(id, 0); | 649 DCHECK_GT(id, 0); |
| 667 if (id == 1) { | 650 if (id == 1) { |
| 668 return gfx::Transform(); | 651 return gfx::Transform(); |
| 669 } | 652 } |
| 670 const TransformNode* node = Node(id); | 653 const TransformNode* node = Node(id); |
| 671 gfx::Transform screen_space_transform = ToScreen(id); | 654 gfx::Transform screen_space_transform = ToScreen(id); |
| 672 if (node->sublayer_scale.x() != 0.0 && node->sublayer_scale.y() != 0.0) | 655 if (node->surface_contents_scale.x() != 0.0 && |
| 673 screen_space_transform.Scale(1.0 / node->sublayer_scale.x(), | 656 node->surface_contents_scale.y() != 0.0) |
| 674 1.0 / node->sublayer_scale.y()); | 657 screen_space_transform.Scale(1.0 / node->surface_contents_scale.x(), |
| 658 1.0 / node->surface_contents_scale.y()); |
| 675 return screen_space_transform; | 659 return screen_space_transform; |
| 676 } | 660 } |
| 677 | 661 |
| 678 bool TransformTree::operator==(const TransformTree& other) const { | 662 bool TransformTree::operator==(const TransformTree& other) const { |
| 679 return PropertyTree::operator==(other) && | 663 return PropertyTree::operator==(other) && |
| 680 source_to_parent_updates_allowed_ == | 664 source_to_parent_updates_allowed_ == |
| 681 other.source_to_parent_updates_allowed() && | 665 other.source_to_parent_updates_allowed() && |
| 682 page_scale_factor_ == other.page_scale_factor() && | 666 page_scale_factor_ == other.page_scale_factor() && |
| 683 device_scale_factor_ == other.device_scale_factor() && | 667 device_scale_factor_ == other.device_scale_factor() && |
| 684 device_transform_scale_factor_ == | 668 device_transform_scale_factor_ == |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 830 } | 814 } |
| 831 return; | 815 return; |
| 832 } | 816 } |
| 833 } | 817 } |
| 834 } | 818 } |
| 835 node->hidden_by_backface_visibility = false; | 819 node->hidden_by_backface_visibility = false; |
| 836 } | 820 } |
| 837 | 821 |
| 838 void EffectTree::UpdateSublayerScale(EffectNode* effect_node) { | 822 void EffectTree::UpdateSublayerScale(EffectNode* effect_node) { |
| 839 if (!effect_node->has_render_surface || effect_node->transform_id == 0) { | 823 if (!effect_node->has_render_surface || effect_node->transform_id == 0) { |
| 840 effect_node->sublayer_scale = gfx::Vector2dF(1.0f, 1.0f); | 824 effect_node->surface_contents_scale = gfx::Vector2dF(1.0f, 1.0f); |
| 841 return; | 825 return; |
| 842 } | 826 } |
| 843 | 827 |
| 844 TransformTree& transform_tree = property_trees()->transform_tree; | 828 TransformTree& transform_tree = property_trees()->transform_tree; |
| 845 float layer_scale_factor = transform_tree.device_scale_factor() * | 829 float layer_scale_factor = transform_tree.device_scale_factor() * |
| 846 transform_tree.device_transform_scale_factor(); | 830 transform_tree.device_transform_scale_factor(); |
| 847 TransformNode* transform_node = | 831 TransformNode* transform_node = |
| 848 transform_tree.Node(effect_node->transform_id); | 832 transform_tree.Node(effect_node->transform_id); |
| 849 if (transform_node->in_subtree_of_page_scale_layer) | 833 if (transform_node->in_subtree_of_page_scale_layer) |
| 850 layer_scale_factor *= transform_tree.page_scale_factor(); | 834 layer_scale_factor *= transform_tree.page_scale_factor(); |
| 851 effect_node->sublayer_scale = MathUtil::ComputeTransform2dScaleComponents( | 835 effect_node->surface_contents_scale = |
| 852 transform_tree.ToScreen(transform_node->id), layer_scale_factor); | 836 MathUtil::ComputeTransform2dScaleComponents( |
| 837 transform_tree.ToScreen(transform_node->id), layer_scale_factor); |
| 853 } | 838 } |
| 854 | 839 |
| 855 void EffectTree::UpdateEffects(int id) { | 840 void EffectTree::UpdateEffects(int id) { |
| 856 EffectNode* node = Node(id); | 841 EffectNode* node = Node(id); |
| 857 EffectNode* parent_node = parent(node); | 842 EffectNode* parent_node = parent(node); |
| 858 | 843 |
| 859 UpdateOpacities(node, parent_node); | 844 UpdateOpacities(node, parent_node); |
| 860 UpdateIsDrawn(node, parent_node); | 845 UpdateIsDrawn(node, parent_node); |
| 861 UpdateEffectChanged(node, parent_node); | 846 UpdateEffectChanged(node, parent_node); |
| 862 UpdateBackfaceVisibility(node, parent_node); | 847 UpdateBackfaceVisibility(node, parent_node); |
| (...skipping 1021 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1884 cached_data_.property_tree_update_number = 0; | 1869 cached_data_.property_tree_update_number = 0; |
| 1885 cached_data_.animation_scales = std::vector<AnimationScaleData>( | 1870 cached_data_.animation_scales = std::vector<AnimationScaleData>( |
| 1886 transform_tree.nodes().size(), AnimationScaleData()); | 1871 transform_tree.nodes().size(), AnimationScaleData()); |
| 1887 } | 1872 } |
| 1888 | 1873 |
| 1889 void PropertyTrees::UpdateCachedNumber() { | 1874 void PropertyTrees::UpdateCachedNumber() { |
| 1890 cached_data_.property_tree_update_number++; | 1875 cached_data_.property_tree_update_number++; |
| 1891 } | 1876 } |
| 1892 | 1877 |
| 1893 } // namespace cc | 1878 } // namespace cc |
| OLD | NEW |