Chromium Code Reviews| 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 72 } | 72 } |
| 73 | 73 |
| 74 template <typename T> | 74 template <typename T> |
| 75 PropertyTree<T>::~PropertyTree() { | 75 PropertyTree<T>::~PropertyTree() { |
| 76 } | 76 } |
| 77 | 77 |
| 78 TransformTree::TransformTree() | 78 TransformTree::TransformTree() |
| 79 : source_to_parent_updates_allowed_(true), | 79 : source_to_parent_updates_allowed_(true), |
| 80 page_scale_factor_(1.f), | 80 page_scale_factor_(1.f), |
| 81 device_scale_factor_(1.f), | 81 device_scale_factor_(1.f), |
| 82 device_transform_scale_factor_(1.f) {} | 82 device_transform_scale_factor_(1.f) { |
| 83 cached_data_.push_back(TransformCachedNodeData()); | |
| 84 } | |
| 83 | 85 |
| 84 TransformTree::~TransformTree() { | 86 TransformTree::~TransformTree() { |
| 85 } | 87 } |
| 86 | 88 |
| 87 template <typename T> | 89 template <typename T> |
| 88 int PropertyTree<T>::Insert(const T& tree_node, int parent_id) { | 90 int PropertyTree<T>::Insert(const T& tree_node, int parent_id) { |
| 89 DCHECK_GT(nodes_.size(), 0u); | 91 DCHECK_GT(nodes_.size(), 0u); |
| 90 nodes_.push_back(tree_node); | 92 nodes_.push_back(tree_node); |
| 91 T& node = nodes_.back(); | 93 T& node = nodes_.back(); |
| 92 node.parent_id = parent_id; | 94 node.parent_id = parent_id; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 148 } | 150 } |
| 149 value->EndArray(); | 151 value->EndArray(); |
| 150 } | 152 } |
| 151 | 153 |
| 152 template class PropertyTree<TransformNode>; | 154 template class PropertyTree<TransformNode>; |
| 153 template class PropertyTree<ClipNode>; | 155 template class PropertyTree<ClipNode>; |
| 154 template class PropertyTree<EffectNode>; | 156 template class PropertyTree<EffectNode>; |
| 155 template class PropertyTree<ScrollNode>; | 157 template class PropertyTree<ScrollNode>; |
| 156 | 158 |
| 157 TransformNodeData::TransformNodeData() | 159 TransformNodeData::TransformNodeData() |
| 158 : target_id(-1), | 160 : source_node_id(-1), |
| 159 content_target_id(-1), | |
| 160 source_node_id(-1), | |
| 161 sorting_context_id(0), | 161 sorting_context_id(0), |
| 162 needs_local_transform_update(true), | 162 needs_local_transform_update(true), |
| 163 node_and_ancestors_are_animated_or_invertible(true), | 163 node_and_ancestors_are_animated_or_invertible(true), |
| 164 is_invertible(true), | 164 is_invertible(true), |
| 165 ancestors_are_invertible(true), | 165 ancestors_are_invertible(true), |
| 166 has_potential_animation(false), | 166 has_potential_animation(false), |
| 167 is_currently_animating(false), | 167 is_currently_animating(false), |
| 168 to_screen_is_potentially_animated(false), | 168 to_screen_is_potentially_animated(false), |
| 169 has_only_translation_animations(true), | 169 has_only_translation_animations(true), |
| 170 to_screen_has_scale_animation(false), | 170 to_screen_has_scale_animation(false), |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 186 combined_starting_animation_scale(0.f) {} | 186 combined_starting_animation_scale(0.f) {} |
| 187 | 187 |
| 188 TransformNodeData::TransformNodeData(const TransformNodeData& other) = default; | 188 TransformNodeData::TransformNodeData(const TransformNodeData& other) = default; |
| 189 | 189 |
| 190 TransformNodeData::~TransformNodeData() { | 190 TransformNodeData::~TransformNodeData() { |
| 191 } | 191 } |
| 192 | 192 |
| 193 bool TransformNodeData::operator==(const TransformNodeData& other) const { | 193 bool TransformNodeData::operator==(const TransformNodeData& other) const { |
| 194 return pre_local == other.pre_local && local == other.local && | 194 return pre_local == other.pre_local && local == other.local && |
| 195 post_local == other.post_local && to_parent == other.to_parent && | 195 post_local == other.post_local && to_parent == other.to_parent && |
| 196 to_target == other.to_target && from_target == other.from_target && | |
| 197 to_screen == other.to_screen && from_screen == other.from_screen && | |
| 198 target_id == other.target_id && | |
| 199 content_target_id == other.content_target_id && | |
| 200 source_node_id == other.source_node_id && | 196 source_node_id == other.source_node_id && |
| 201 sorting_context_id == other.sorting_context_id && | 197 sorting_context_id == other.sorting_context_id && |
| 202 needs_local_transform_update == other.needs_local_transform_update && | 198 needs_local_transform_update == other.needs_local_transform_update && |
| 203 node_and_ancestors_are_animated_or_invertible == | 199 node_and_ancestors_are_animated_or_invertible == |
| 204 other.node_and_ancestors_are_animated_or_invertible && | 200 other.node_and_ancestors_are_animated_or_invertible && |
| 205 is_invertible == other.is_invertible && | 201 is_invertible == other.is_invertible && |
| 206 ancestors_are_invertible == other.ancestors_are_invertible && | 202 ancestors_are_invertible == other.ancestors_are_invertible && |
| 207 has_potential_animation == other.has_potential_animation && | 203 has_potential_animation == other.has_potential_animation && |
| 208 is_currently_animating == other.is_currently_animating && | 204 is_currently_animating == other.is_currently_animating && |
| 209 to_screen_is_potentially_animated == | 205 to_screen_is_potentially_animated == |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 265 void TransformNodeData::ToProtobuf(proto::TreeNode* proto) const { | 261 void TransformNodeData::ToProtobuf(proto::TreeNode* proto) const { |
| 266 DCHECK(!proto->has_transform_node_data()); | 262 DCHECK(!proto->has_transform_node_data()); |
| 267 proto::TranformNodeData* data = proto->mutable_transform_node_data(); | 263 proto::TranformNodeData* data = proto->mutable_transform_node_data(); |
| 268 | 264 |
| 269 TransformToProto(pre_local, data->mutable_pre_local()); | 265 TransformToProto(pre_local, data->mutable_pre_local()); |
| 270 TransformToProto(local, data->mutable_local()); | 266 TransformToProto(local, data->mutable_local()); |
| 271 TransformToProto(post_local, data->mutable_post_local()); | 267 TransformToProto(post_local, data->mutable_post_local()); |
| 272 | 268 |
| 273 TransformToProto(to_parent, data->mutable_to_parent()); | 269 TransformToProto(to_parent, data->mutable_to_parent()); |
| 274 | 270 |
| 275 TransformToProto(to_target, data->mutable_to_target()); | |
| 276 TransformToProto(from_target, data->mutable_from_target()); | |
| 277 | |
| 278 TransformToProto(to_screen, data->mutable_to_screen()); | |
| 279 TransformToProto(from_screen, data->mutable_from_screen()); | |
| 280 | |
| 281 data->set_target_id(target_id); | |
| 282 data->set_content_target_id(content_target_id); | |
| 283 data->set_source_node_id(source_node_id); | 271 data->set_source_node_id(source_node_id); |
| 284 data->set_sorting_context_id(sorting_context_id); | 272 data->set_sorting_context_id(sorting_context_id); |
| 285 | 273 |
| 286 data->set_needs_local_transform_update(needs_local_transform_update); | 274 data->set_needs_local_transform_update(needs_local_transform_update); |
| 287 | 275 |
| 288 data->set_node_and_ancestors_are_animated_or_invertible( | 276 data->set_node_and_ancestors_are_animated_or_invertible( |
| 289 node_and_ancestors_are_animated_or_invertible); | 277 node_and_ancestors_are_animated_or_invertible); |
| 290 | 278 |
| 291 data->set_is_invertible(is_invertible); | 279 data->set_is_invertible(is_invertible); |
| 292 data->set_ancestors_are_invertible(ancestors_are_invertible); | 280 data->set_ancestors_are_invertible(ancestors_are_invertible); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 336 void TransformNodeData::FromProtobuf(const proto::TreeNode& proto) { | 324 void TransformNodeData::FromProtobuf(const proto::TreeNode& proto) { |
| 337 DCHECK(proto.has_transform_node_data()); | 325 DCHECK(proto.has_transform_node_data()); |
| 338 const proto::TranformNodeData& data = proto.transform_node_data(); | 326 const proto::TranformNodeData& data = proto.transform_node_data(); |
| 339 | 327 |
| 340 pre_local = ProtoToTransform(data.pre_local()); | 328 pre_local = ProtoToTransform(data.pre_local()); |
| 341 local = ProtoToTransform(data.local()); | 329 local = ProtoToTransform(data.local()); |
| 342 post_local = ProtoToTransform(data.post_local()); | 330 post_local = ProtoToTransform(data.post_local()); |
| 343 | 331 |
| 344 to_parent = ProtoToTransform(data.to_parent()); | 332 to_parent = ProtoToTransform(data.to_parent()); |
| 345 | 333 |
| 346 to_target = ProtoToTransform(data.to_target()); | |
| 347 from_target = ProtoToTransform(data.from_target()); | |
| 348 | |
| 349 to_screen = ProtoToTransform(data.to_screen()); | |
| 350 from_screen = ProtoToTransform(data.from_screen()); | |
| 351 | |
| 352 target_id = data.target_id(); | |
| 353 content_target_id = data.content_target_id(); | |
| 354 source_node_id = data.source_node_id(); | 334 source_node_id = data.source_node_id(); |
| 355 sorting_context_id = data.sorting_context_id(); | 335 sorting_context_id = data.sorting_context_id(); |
| 356 | 336 |
| 357 needs_local_transform_update = data.needs_local_transform_update(); | 337 needs_local_transform_update = data.needs_local_transform_update(); |
| 358 | 338 |
| 359 node_and_ancestors_are_animated_or_invertible = | 339 node_and_ancestors_are_animated_or_invertible = |
| 360 data.node_and_ancestors_are_animated_or_invertible(); | 340 data.node_and_ancestors_are_animated_or_invertible(); |
| 361 | 341 |
| 362 is_invertible = data.is_invertible(); | 342 is_invertible = data.is_invertible(); |
| 363 ancestors_are_invertible = data.ancestors_are_invertible(); | 343 ancestors_are_invertible = data.ancestors_are_invertible(); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 400 scroll_snap = ProtoToVector2dF(data.scroll_snap()); | 380 scroll_snap = ProtoToVector2dF(data.scroll_snap()); |
| 401 source_offset = ProtoToVector2dF(data.source_offset()); | 381 source_offset = ProtoToVector2dF(data.source_offset()); |
| 402 source_to_parent = ProtoToVector2dF(data.source_to_parent()); | 382 source_to_parent = ProtoToVector2dF(data.source_to_parent()); |
| 403 } | 383 } |
| 404 | 384 |
| 405 void TransformNodeData::AsValueInto( | 385 void TransformNodeData::AsValueInto( |
| 406 base::trace_event::TracedValue* value) const { | 386 base::trace_event::TracedValue* value) const { |
| 407 MathUtil::AddToTracedValue("pre_local", pre_local, value); | 387 MathUtil::AddToTracedValue("pre_local", pre_local, value); |
| 408 MathUtil::AddToTracedValue("local", local, value); | 388 MathUtil::AddToTracedValue("local", local, value); |
| 409 MathUtil::AddToTracedValue("post_local", post_local, value); | 389 MathUtil::AddToTracedValue("post_local", post_local, value); |
| 410 value->SetInteger("target_id", target_id); | 390 // TODO(sunxd): make frameviewer work without target_id |
| 411 value->SetInteger("content_target_id", content_target_id); | 391 value->SetInteger("target_id", 0); |
| 392 value->SetInteger("content_target_id", 0); | |
| 412 value->SetInteger("source_node_id", source_node_id); | 393 value->SetInteger("source_node_id", source_node_id); |
| 413 value->SetInteger("sorting_context_id", sorting_context_id); | 394 value->SetInteger("sorting_context_id", sorting_context_id); |
| 414 } | 395 } |
| 415 | 396 |
| 397 TransformCachedNodeData::TransformCachedNodeData() | |
| 398 : target_id(-1), content_target_id(-1) {} | |
| 399 | |
| 400 TransformCachedNodeData::TransformCachedNodeData( | |
| 401 const TransformCachedNodeData& other) = default; | |
| 402 | |
| 403 TransformCachedNodeData::~TransformCachedNodeData() {} | |
| 404 | |
| 405 bool TransformCachedNodeData::operator==( | |
| 406 const TransformCachedNodeData& other) const { | |
| 407 return from_target == other.from_target && to_target == other.to_target && | |
| 408 from_screen == other.from_screen && to_screen == other.to_screen && | |
| 409 target_id == other.target_id && | |
| 410 content_target_id == other.content_target_id; | |
| 411 } | |
| 412 | |
| 413 void TransformCachedNodeData::ToProtobuf( | |
| 414 proto::TransformCachedNodeData* proto) const { | |
| 415 TransformToProto(from_target, proto->mutable_from_target()); | |
| 416 TransformToProto(to_target, proto->mutable_to_target()); | |
| 417 TransformToProto(from_screen, proto->mutable_from_screen()); | |
| 418 TransformToProto(to_screen, proto->mutable_to_screen()); | |
| 419 proto->set_target_id(target_id); | |
| 420 proto->set_content_target_id(content_target_id); | |
| 421 } | |
| 422 | |
| 423 void TransformCachedNodeData::FromProtobuf( | |
| 424 const proto::TransformCachedNodeData& proto) { | |
| 425 from_target = ProtoToTransform(proto.from_target()); | |
| 426 to_target = ProtoToTransform(proto.to_target()); | |
| 427 from_screen = ProtoToTransform(proto.from_screen()); | |
| 428 to_screen = ProtoToTransform(proto.to_screen()); | |
| 429 target_id = proto.target_id(); | |
| 430 content_target_id = proto.content_target_id(); | |
| 431 } | |
| 432 | |
| 416 ClipNodeData::ClipNodeData() | 433 ClipNodeData::ClipNodeData() |
| 417 : transform_id(-1), | 434 : transform_id(-1), |
| 418 target_id(-1), | 435 target_id(-1), |
| 419 applies_local_clip(true), | 436 applies_local_clip(true), |
| 420 layer_clipping_uses_only_local_clip(false), | 437 layer_clipping_uses_only_local_clip(false), |
| 421 target_is_clipped(false), | 438 target_is_clipped(false), |
| 422 layers_are_clipped(false), | 439 layers_are_clipped(false), |
| 423 layers_are_clipped_when_surfaces_disabled(false), | 440 layers_are_clipped_when_surfaces_disabled(false), |
| 424 resets_clip(false) {} | 441 resets_clip(false) {} |
| 425 | 442 |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 687 MathUtil::AddToTracedValue("bounds", bounds, value); | 704 MathUtil::AddToTracedValue("bounds", bounds, value); |
| 688 MathUtil::AddToTracedValue("offset_to_transform_parent", | 705 MathUtil::AddToTracedValue("offset_to_transform_parent", |
| 689 offset_to_transform_parent, value); | 706 offset_to_transform_parent, value); |
| 690 value->SetBoolean("should_flatten", should_flatten); | 707 value->SetBoolean("should_flatten", should_flatten); |
| 691 value->SetBoolean("user_scrollable_horizontal", user_scrollable_horizontal); | 708 value->SetBoolean("user_scrollable_horizontal", user_scrollable_horizontal); |
| 692 value->SetBoolean("user_scrollable_vertical", user_scrollable_vertical); | 709 value->SetBoolean("user_scrollable_vertical", user_scrollable_vertical); |
| 693 value->SetInteger("element_id", element_id); | 710 value->SetInteger("element_id", element_id); |
| 694 value->SetInteger("transform_id", transform_id); | 711 value->SetInteger("transform_id", transform_id); |
| 695 } | 712 } |
| 696 | 713 |
| 714 int TransformTree::Insert(const TransformNode& tree_node, int parent_id) { | |
| 715 int node_id = PropertyTree<TransformNode>::Insert(tree_node, parent_id); | |
| 716 DCHECK_EQ(node_id, static_cast<int>(cached_data_.size())); | |
| 717 | |
| 718 cached_data_.push_back(TransformCachedNodeData()); | |
| 719 return node_id; | |
| 720 } | |
| 721 | |
| 697 void TransformTree::clear() { | 722 void TransformTree::clear() { |
| 698 PropertyTree<TransformNode>::clear(); | 723 PropertyTree<TransformNode>::clear(); |
| 699 | 724 |
| 700 nodes_affected_by_inner_viewport_bounds_delta_.clear(); | 725 nodes_affected_by_inner_viewport_bounds_delta_.clear(); |
| 701 nodes_affected_by_outer_viewport_bounds_delta_.clear(); | 726 nodes_affected_by_outer_viewport_bounds_delta_.clear(); |
| 727 cached_data_.clear(); | |
| 728 cached_data_.push_back(TransformCachedNodeData()); | |
| 702 } | 729 } |
| 703 | 730 |
| 704 bool TransformTree::ComputeTransform(int source_id, | 731 bool TransformTree::ComputeTransform(int source_id, |
| 705 int dest_id, | 732 int dest_id, |
| 706 gfx::Transform* transform) const { | 733 gfx::Transform* transform) const { |
| 707 transform->MakeIdentity(); | 734 transform->MakeIdentity(); |
| 708 | 735 |
| 709 if (source_id == dest_id) | 736 if (source_id == dest_id) |
| 710 return true; | 737 return true; |
| 711 | 738 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 764 void TransformTree::ResetChangeTracking() { | 791 void TransformTree::ResetChangeTracking() { |
| 765 for (int id = 1; id < static_cast<int>(size()); ++id) { | 792 for (int id = 1; id < static_cast<int>(size()); ++id) { |
| 766 TransformNode* node = Node(id); | 793 TransformNode* node = Node(id); |
| 767 node->data.transform_changed = false; | 794 node->data.transform_changed = false; |
| 768 } | 795 } |
| 769 } | 796 } |
| 770 | 797 |
| 771 void TransformTree::UpdateTransforms(int id) { | 798 void TransformTree::UpdateTransforms(int id) { |
| 772 TransformNode* node = Node(id); | 799 TransformNode* node = Node(id); |
| 773 TransformNode* parent_node = parent(node); | 800 TransformNode* parent_node = parent(node); |
| 774 TransformNode* target_node = Node(node->data.target_id); | 801 TransformNode* target_node = Node(TargetId(id)); |
| 775 TransformNode* source_node = Node(node->data.source_node_id); | 802 TransformNode* source_node = Node(node->data.source_node_id); |
| 776 if (node->data.needs_local_transform_update || | 803 if (node->data.needs_local_transform_update || |
| 777 NeedsSourceToParentUpdate(node)) | 804 NeedsSourceToParentUpdate(node)) |
| 778 UpdateLocalTransform(node); | 805 UpdateLocalTransform(node); |
| 779 else | 806 else |
| 780 UndoSnapping(node); | 807 UndoSnapping(node); |
| 781 UpdateScreenSpaceTransform(node, parent_node, target_node); | 808 UpdateScreenSpaceTransform(node, parent_node, target_node); |
| 782 UpdateSublayerScale(node); | 809 UpdateSublayerScale(node); |
| 783 UpdateTargetSpaceTransform(node, target_node); | 810 UpdateTargetSpaceTransform(node, target_node); |
| 784 UpdateAnimationProperties(node, parent_node); | 811 UpdateAnimationProperties(node, parent_node); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 808 // non-trivial flattening between the source and destination nodes. For | 835 // non-trivial flattening between the source and destination nodes. For |
| 809 // example, consider the tree R->A->B->C, where B flattens its inherited | 836 // example, consider the tree R->A->B->C, where B flattens its inherited |
| 810 // transform, and A has a non-flat transform. Suppose C is the source and A is | 837 // transform, and A has a non-flat transform. Suppose C is the source and A is |
| 811 // the destination. The expected result is C * B. But C's to_screen | 838 // the destination. The expected result is C * B. But C's to_screen |
| 812 // transform is C * B * flattened(A * R), and A's from_screen transform is | 839 // transform is C * B * flattened(A * R), and A's from_screen transform is |
| 813 // R^{-1} * A^{-1}. If at least one of A and R isn't flat, the inverse of | 840 // R^{-1} * A^{-1}. If at least one of A and R isn't flat, the inverse of |
| 814 // flattened(A * R) won't be R^{-1} * A{-1}, so multiplying C's to_screen and | 841 // flattened(A * R) won't be R^{-1} * A{-1}, so multiplying C's to_screen and |
| 815 // A's from_screen will not produce the correct result. | 842 // A's from_screen will not produce the correct result. |
| 816 if (!dest || (dest->data.ancestors_are_invertible && | 843 if (!dest || (dest->data.ancestors_are_invertible && |
| 817 dest->data.node_and_ancestors_are_flat)) { | 844 dest->data.node_and_ancestors_are_flat)) { |
| 818 transform->ConcatTransform(current->data.to_screen); | 845 transform->ConcatTransform(ToScreen(current->id)); |
| 819 if (dest) | 846 if (dest) |
| 820 transform->ConcatTransform(dest->data.from_screen); | 847 transform->ConcatTransform(FromScreen(dest->id)); |
| 821 return true; | 848 return true; |
| 822 } | 849 } |
| 823 | 850 |
| 824 // Flattening is defined in a way that requires it to be applied while | 851 // Flattening is defined in a way that requires it to be applied while |
| 825 // traversing downward in the tree. We first identify nodes that are on the | 852 // traversing downward in the tree. We first identify nodes that are on the |
| 826 // path from the source to the destination (this is traversing upward), and | 853 // path from the source to the destination (this is traversing upward), and |
| 827 // then we visit these nodes in reverse order, flattening as needed. We | 854 // then we visit these nodes in reverse order, flattening as needed. We |
| 828 // early-out if we get to a node whose target node is the destination, since | 855 // early-out if we get to a node whose target node is the destination, since |
| 829 // we can then re-use the target space transform stored at that node. However, | 856 // we can then re-use the target space transform stored at that node. However, |
| 830 // we cannot re-use a stored target space transform if the destination has a | 857 // we cannot re-use a stored target space transform if the destination has a |
| 831 // zero sublayer scale, since stored target space transforms have sublayer | 858 // zero sublayer scale, since stored target space transforms have sublayer |
| 832 // scale baked in, but we need to compute an unscaled transform. | 859 // scale baked in, but we need to compute an unscaled transform. |
| 833 std::vector<int> source_to_destination; | 860 std::vector<int> source_to_destination; |
| 834 source_to_destination.push_back(current->id); | 861 source_to_destination.push_back(current->id); |
| 835 current = parent(current); | 862 current = parent(current); |
| 836 bool destination_has_non_zero_sublayer_scale = | 863 bool destination_has_non_zero_sublayer_scale = |
| 837 dest->data.sublayer_scale.x() != 0.f && | 864 dest->data.sublayer_scale.x() != 0.f && |
| 838 dest->data.sublayer_scale.y() != 0.f; | 865 dest->data.sublayer_scale.y() != 0.f; |
| 839 DCHECK(destination_has_non_zero_sublayer_scale || | 866 DCHECK(destination_has_non_zero_sublayer_scale || |
| 840 !dest->data.ancestors_are_invertible); | 867 !dest->data.ancestors_are_invertible); |
| 841 for (; current && current->id > dest_id; current = parent(current)) { | 868 for (; current && current->id > dest_id; current = parent(current)) { |
| 842 if (destination_has_non_zero_sublayer_scale && | 869 if (destination_has_non_zero_sublayer_scale && |
| 843 current->data.target_id == dest_id && | 870 TargetId(current->id) == dest_id && |
| 844 current->data.content_target_id == dest_id) | 871 ContentTargetId(current->id) == dest_id) |
| 845 break; | 872 break; |
| 846 source_to_destination.push_back(current->id); | 873 source_to_destination.push_back(current->id); |
| 847 } | 874 } |
| 848 | 875 |
| 849 gfx::Transform combined_transform; | 876 gfx::Transform combined_transform; |
| 850 if (current->id > dest_id) { | 877 if (current->id > dest_id) { |
| 851 combined_transform = current->data.to_target; | 878 combined_transform = ToTarget(current->id); |
| 852 // The stored target space transform has sublayer scale baked in, but we | 879 // The stored target space transform has sublayer scale baked in, but we |
| 853 // need the unscaled transform. | 880 // need the unscaled transform. |
| 854 combined_transform.matrix().postScale(1.0f / dest->data.sublayer_scale.x(), | 881 combined_transform.matrix().postScale(1.0f / dest->data.sublayer_scale.x(), |
| 855 1.0f / dest->data.sublayer_scale.y(), | 882 1.0f / dest->data.sublayer_scale.y(), |
| 856 1.0f); | 883 1.0f); |
| 857 } else if (current->id < dest_id) { | 884 } else if (current->id < dest_id) { |
| 858 // We have reached the lowest common ancestor of the source and destination | 885 // We have reached the lowest common ancestor of the source and destination |
| 859 // nodes. This case can occur when we are transforming between a node | 886 // nodes. This case can occur when we are transforming between a node |
| 860 // corresponding to a fixed-position layer (or its descendant) and the node | 887 // corresponding to a fixed-position layer (or its descendant) and the node |
| 861 // corresponding to the layer's render target. For example, consider the | 888 // corresponding to the layer's render target. For example, consider the |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 895 int dest_id, | 922 int dest_id, |
| 896 gfx::Transform* transform) const { | 923 gfx::Transform* transform) const { |
| 897 DCHECK(source_id < dest_id); | 924 DCHECK(source_id < dest_id); |
| 898 const TransformNode* current = Node(dest_id); | 925 const TransformNode* current = Node(dest_id); |
| 899 const TransformNode* dest = Node(source_id); | 926 const TransformNode* dest = Node(source_id); |
| 900 // Just as in CombineTransformsBetween, we can use screen space transforms in | 927 // Just as in CombineTransformsBetween, we can use screen space transforms in |
| 901 // this computation only when there isn't any non-trivial flattening | 928 // this computation only when there isn't any non-trivial flattening |
| 902 // involved. | 929 // involved. |
| 903 if (current->data.ancestors_are_invertible && | 930 if (current->data.ancestors_are_invertible && |
| 904 current->data.node_and_ancestors_are_flat) { | 931 current->data.node_and_ancestors_are_flat) { |
| 905 transform->PreconcatTransform(current->data.from_screen); | 932 transform->PreconcatTransform(FromScreen(current->id)); |
| 906 if (dest) | 933 if (dest) |
| 907 transform->PreconcatTransform(dest->data.to_screen); | 934 transform->PreconcatTransform(ToScreen(dest->id)); |
| 908 return true; | 935 return true; |
| 909 } | 936 } |
| 910 | 937 |
| 911 // Inverting a flattening is not equivalent to flattening an inverse. This | 938 // Inverting a flattening is not equivalent to flattening an inverse. This |
| 912 // means we cannot, for example, use the inverse of each node's to_parent | 939 // means we cannot, for example, use the inverse of each node's to_parent |
| 913 // transform, flattening where needed. Instead, we must compute the transform | 940 // transform, flattening where needed. Instead, we must compute the transform |
| 914 // from the destination to the source, with flattening, and then invert the | 941 // from the destination to the source, with flattening, and then invert the |
| 915 // result. | 942 // result. |
| 916 gfx::Transform dest_to_source; | 943 gfx::Transform dest_to_source; |
| 917 CombineTransformsBetween(dest_id, source_id, &dest_to_source); | 944 CombineTransformsBetween(dest_id, source_id, &dest_to_source); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 952 transform.PreconcatTransform(node->data.local); | 979 transform.PreconcatTransform(node->data.local); |
| 953 transform.PreconcatTransform(node->data.pre_local); | 980 transform.PreconcatTransform(node->data.pre_local); |
| 954 node->data.set_to_parent(transform); | 981 node->data.set_to_parent(transform); |
| 955 node->data.needs_local_transform_update = false; | 982 node->data.needs_local_transform_update = false; |
| 956 } | 983 } |
| 957 | 984 |
| 958 void TransformTree::UpdateScreenSpaceTransform(TransformNode* node, | 985 void TransformTree::UpdateScreenSpaceTransform(TransformNode* node, |
| 959 TransformNode* parent_node, | 986 TransformNode* parent_node, |
| 960 TransformNode* target_node) { | 987 TransformNode* target_node) { |
| 961 if (!parent_node) { | 988 if (!parent_node) { |
| 962 node->data.to_screen = node->data.to_parent; | 989 SetToScreen(node->id, node->data.to_parent); |
| 963 node->data.ancestors_are_invertible = true; | 990 node->data.ancestors_are_invertible = true; |
| 964 node->data.to_screen_is_potentially_animated = false; | 991 node->data.to_screen_is_potentially_animated = false; |
| 965 node->data.node_and_ancestors_are_flat = node->data.to_parent.IsFlat(); | 992 node->data.node_and_ancestors_are_flat = node->data.to_parent.IsFlat(); |
| 966 } else { | 993 } else { |
| 967 node->data.to_screen = parent_node->data.to_screen; | 994 gfx::Transform to_screen_space_transform = ToScreen(parent_node->id); |
| 968 if (node->data.flattens_inherited_transform) | 995 if (node->data.flattens_inherited_transform) |
| 969 node->data.to_screen.FlattenTo2d(); | 996 to_screen_space_transform.FlattenTo2d(); |
| 970 node->data.to_screen.PreconcatTransform(node->data.to_parent); | 997 to_screen_space_transform.PreconcatTransform(node->data.to_parent); |
| 971 node->data.ancestors_are_invertible = | 998 node->data.ancestors_are_invertible = |
| 972 parent_node->data.ancestors_are_invertible; | 999 parent_node->data.ancestors_are_invertible; |
| 973 node->data.node_and_ancestors_are_flat = | 1000 node->data.node_and_ancestors_are_flat = |
| 974 parent_node->data.node_and_ancestors_are_flat && | 1001 parent_node->data.node_and_ancestors_are_flat && |
| 975 node->data.to_parent.IsFlat(); | 1002 node->data.to_parent.IsFlat(); |
| 1003 SetToScreen(node->id, to_screen_space_transform); | |
| 976 } | 1004 } |
| 977 | 1005 |
| 978 if (!node->data.to_screen.GetInverse(&node->data.from_screen)) | 1006 gfx::Transform from_screen; |
| 1007 if (!ToScreen(node->id).GetInverse(&from_screen)) | |
| 979 node->data.ancestors_are_invertible = false; | 1008 node->data.ancestors_are_invertible = false; |
| 1009 SetFromScreen(node->id, from_screen); | |
| 980 } | 1010 } |
| 981 | 1011 |
| 982 void TransformTree::UpdateSublayerScale(TransformNode* node) { | 1012 void TransformTree::UpdateSublayerScale(TransformNode* node) { |
| 983 // The sublayer scale depends on the screen space transform, so update it too. | 1013 // The sublayer scale depends on the screen space transform, so update it too. |
| 984 if (!node->data.needs_sublayer_scale) { | 1014 if (!node->data.needs_sublayer_scale) { |
| 985 node->data.sublayer_scale = gfx::Vector2dF(1.0f, 1.0f); | 1015 node->data.sublayer_scale = gfx::Vector2dF(1.0f, 1.0f); |
| 986 return; | 1016 return; |
| 987 } | 1017 } |
| 988 | 1018 |
| 989 float layer_scale_factor = | 1019 float layer_scale_factor = |
| 990 device_scale_factor_ * device_transform_scale_factor_; | 1020 device_scale_factor_ * device_transform_scale_factor_; |
| 991 if (node->data.in_subtree_of_page_scale_layer) | 1021 if (node->data.in_subtree_of_page_scale_layer) |
| 992 layer_scale_factor *= page_scale_factor_; | 1022 layer_scale_factor *= page_scale_factor_; |
| 993 node->data.sublayer_scale = MathUtil::ComputeTransform2dScaleComponents( | 1023 node->data.sublayer_scale = MathUtil::ComputeTransform2dScaleComponents( |
| 994 node->data.to_screen, layer_scale_factor); | 1024 ToScreen(node->id), layer_scale_factor); |
| 995 } | 1025 } |
| 996 | 1026 |
| 997 void TransformTree::UpdateTargetSpaceTransform(TransformNode* node, | 1027 void TransformTree::UpdateTargetSpaceTransform(TransformNode* node, |
| 998 TransformNode* target_node) { | 1028 TransformNode* target_node) { |
| 1029 gfx::Transform target_space_transform; | |
| 999 if (node->data.needs_sublayer_scale) { | 1030 if (node->data.needs_sublayer_scale) { |
| 1000 node->data.to_target.MakeIdentity(); | 1031 target_space_transform.MakeIdentity(); |
| 1001 node->data.to_target.Scale(node->data.sublayer_scale.x(), | 1032 target_space_transform.Scale(node->data.sublayer_scale.x(), |
| 1002 node->data.sublayer_scale.y()); | 1033 node->data.sublayer_scale.y()); |
| 1003 } else { | 1034 } else { |
| 1004 // In order to include the root transform for the root surface, we walk up | 1035 // In order to include the root transform for the root surface, we walk up |
| 1005 // to the root of the transform tree in ComputeTransform. | 1036 // to the root of the transform tree in ComputeTransform. |
| 1006 int target_id = target_node->id; | 1037 int target_id = target_node->id; |
| 1007 ComputeTransformWithDestinationSublayerScale(node->id, target_id, | 1038 ComputeTransformWithDestinationSublayerScale(node->id, target_id, |
| 1008 &node->data.to_target); | 1039 &target_space_transform); |
| 1009 } | 1040 } |
| 1010 | 1041 |
| 1011 if (!node->data.to_target.GetInverse(&node->data.from_target)) | 1042 gfx::Transform from_target; |
| 1043 if (!target_space_transform.GetInverse(&from_target)) | |
| 1012 node->data.ancestors_are_invertible = false; | 1044 node->data.ancestors_are_invertible = false; |
| 1045 SetToTarget(node->id, target_space_transform); | |
| 1046 SetFromTarget(node->id, from_target); | |
| 1013 } | 1047 } |
| 1014 | 1048 |
| 1015 void TransformTree::UpdateAnimationProperties(TransformNode* node, | 1049 void TransformTree::UpdateAnimationProperties(TransformNode* node, |
| 1016 TransformNode* parent_node) { | 1050 TransformNode* parent_node) { |
| 1017 bool ancestor_is_animating = false; | 1051 bool ancestor_is_animating = false; |
| 1018 bool ancestor_is_animating_scale = false; | 1052 bool ancestor_is_animating_scale = false; |
| 1019 float ancestor_maximum_target_scale = 0.f; | 1053 float ancestor_maximum_target_scale = 0.f; |
| 1020 float ancestor_starting_animation_scale = 0.f; | 1054 float ancestor_starting_animation_scale = 0.f; |
| 1021 if (parent_node) { | 1055 if (parent_node) { |
| 1022 ancestor_is_animating = parent_node->data.to_screen_is_potentially_animated; | 1056 ancestor_is_animating = parent_node->data.to_screen_is_potentially_animated; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 1034 ancestor_is_animating_scale; | 1068 ancestor_is_animating_scale; |
| 1035 | 1069 |
| 1036 // Once we've failed to compute a maximum animated scale at an ancestor, we | 1070 // Once we've failed to compute a maximum animated scale at an ancestor, we |
| 1037 // continue to fail. | 1071 // continue to fail. |
| 1038 bool failed_at_ancestor = | 1072 bool failed_at_ancestor = |
| 1039 ancestor_is_animating_scale && ancestor_maximum_target_scale == 0.f; | 1073 ancestor_is_animating_scale && ancestor_maximum_target_scale == 0.f; |
| 1040 | 1074 |
| 1041 // Computing maximum animated scale in the presence of non-scale/translation | 1075 // Computing maximum animated scale in the presence of non-scale/translation |
| 1042 // transforms isn't supported. | 1076 // transforms isn't supported. |
| 1043 bool failed_for_non_scale_or_translation = | 1077 bool failed_for_non_scale_or_translation = |
| 1044 !node->data.to_target.IsScaleOrTranslation(); | 1078 !ToTarget(node->id).IsScaleOrTranslation(); |
| 1045 | 1079 |
| 1046 // We don't attempt to accumulate animation scale from multiple nodes with | 1080 // We don't attempt to accumulate animation scale from multiple nodes with |
| 1047 // scale animations, because of the risk of significant overestimation. For | 1081 // scale animations, because of the risk of significant overestimation. For |
| 1048 // example, one node might be increasing scale from 1 to 10 at the same time | 1082 // example, one node might be increasing scale from 1 to 10 at the same time |
| 1049 // as another node is decreasing scale from 10 to 1. Naively combining these | 1083 // as another node is decreasing scale from 10 to 1. Naively combining these |
| 1050 // scales would produce a scale of 100. | 1084 // scales would produce a scale of 100. |
| 1051 bool failed_for_multiple_scale_animations = | 1085 bool failed_for_multiple_scale_animations = |
| 1052 ancestor_is_animating_scale && | 1086 ancestor_is_animating_scale && |
| 1053 !node->data.has_only_translation_animations; | 1087 !node->data.has_only_translation_animations; |
| 1054 | 1088 |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 1085 | 1119 |
| 1086 if (node->data.local_starting_animation_scale == 0.f || | 1120 if (node->data.local_starting_animation_scale == 0.f || |
| 1087 node->data.local_maximum_animation_target_scale == 0.f) { | 1121 node->data.local_maximum_animation_target_scale == 0.f) { |
| 1088 node->data.combined_maximum_animation_target_scale = 0.f; | 1122 node->data.combined_maximum_animation_target_scale = 0.f; |
| 1089 node->data.combined_starting_animation_scale = 0.f; | 1123 node->data.combined_starting_animation_scale = 0.f; |
| 1090 return; | 1124 return; |
| 1091 } | 1125 } |
| 1092 | 1126 |
| 1093 gfx::Vector2dF ancestor_scales = | 1127 gfx::Vector2dF ancestor_scales = |
| 1094 parent_node ? MathUtil::ComputeTransform2dScaleComponents( | 1128 parent_node ? MathUtil::ComputeTransform2dScaleComponents( |
| 1095 parent_node->data.to_target, 0.f) | 1129 ToTarget(parent_node->id), 0.f) |
| 1096 : gfx::Vector2dF(1.f, 1.f); | 1130 : gfx::Vector2dF(1.f, 1.f); |
| 1097 float max_ancestor_scale = std::max(ancestor_scales.x(), ancestor_scales.y()); | 1131 float max_ancestor_scale = std::max(ancestor_scales.x(), ancestor_scales.y()); |
| 1098 node->data.combined_maximum_animation_target_scale = | 1132 node->data.combined_maximum_animation_target_scale = |
| 1099 max_ancestor_scale * node->data.local_maximum_animation_target_scale; | 1133 max_ancestor_scale * node->data.local_maximum_animation_target_scale; |
| 1100 node->data.combined_starting_animation_scale = | 1134 node->data.combined_starting_animation_scale = |
| 1101 max_ancestor_scale * node->data.local_starting_animation_scale; | 1135 max_ancestor_scale * node->data.local_starting_animation_scale; |
| 1102 } | 1136 } |
| 1103 | 1137 |
| 1104 void TransformTree::UndoSnapping(TransformNode* node) { | 1138 void TransformTree::UndoSnapping(TransformNode* node) { |
| 1105 // to_parent transform has the scroll snap from previous frame baked in. | 1139 // to_parent transform has the scroll snap from previous frame baked in. |
| 1106 // We need to undo it and use the un-snapped transform to compute current | 1140 // We need to undo it and use the un-snapped transform to compute current |
| 1107 // target and screen space transforms. | 1141 // target and screen space transforms. |
| 1108 node->data.to_parent.Translate(-node->data.scroll_snap.x(), | 1142 node->data.to_parent.Translate(-node->data.scroll_snap.x(), |
| 1109 -node->data.scroll_snap.y()); | 1143 -node->data.scroll_snap.y()); |
| 1110 } | 1144 } |
| 1111 | 1145 |
| 1112 void TransformTree::UpdateSnapping(TransformNode* node) { | 1146 void TransformTree::UpdateSnapping(TransformNode* node) { |
| 1113 if (!node->data.scrolls || node->data.to_screen_is_potentially_animated || | 1147 if (!node->data.scrolls || node->data.to_screen_is_potentially_animated || |
| 1114 !node->data.to_screen.IsScaleOrTranslation() || | 1148 !ToScreen(node->id).IsScaleOrTranslation() || |
| 1115 !node->data.ancestors_are_invertible) { | 1149 !node->data.ancestors_are_invertible) { |
| 1116 return; | 1150 return; |
| 1117 } | 1151 } |
| 1118 | 1152 |
| 1119 // Scroll snapping must be done in screen space (the pixels we care about). | 1153 // Scroll snapping must be done in screen space (the pixels we care about). |
| 1120 // This means we effectively snap the screen space transform. If ST is the | 1154 // This means we effectively snap the screen space transform. If ST is the |
| 1121 // screen space transform and ST' is ST with its translation components | 1155 // screen space transform and ST' is ST with its translation components |
| 1122 // rounded, then what we're after is the scroll delta X, where ST * X = ST'. | 1156 // rounded, then what we're after is the scroll delta X, where ST * X = ST'. |
| 1123 // I.e., we want a transform that will realize our scroll snap. It follows | 1157 // I.e., we want a transform that will realize our scroll snap. It follows |
| 1124 // that X = ST^-1 * ST'. We cache ST and ST^-1 to make this more efficient. | 1158 // that X = ST^-1 * ST'. We cache ST and ST^-1 to make this more efficient. |
| 1125 gfx::Transform rounded = node->data.to_screen; | 1159 gfx::Transform rounded = ToScreen(node->id); |
| 1126 rounded.RoundTranslationComponents(); | 1160 rounded.RoundTranslationComponents(); |
| 1127 gfx::Transform delta = node->data.from_screen; | 1161 gfx::Transform delta = FromScreen(node->id); |
| 1128 delta *= rounded; | 1162 delta *= rounded; |
| 1129 | 1163 |
| 1130 DCHECK(delta.IsApproximatelyIdentityOrTranslation(SkDoubleToMScalar(1e-4))) | 1164 DCHECK(delta.IsApproximatelyIdentityOrTranslation(SkDoubleToMScalar(1e-4))) |
| 1131 << delta.ToString(); | 1165 << delta.ToString(); |
| 1132 | 1166 |
| 1133 gfx::Vector2dF translation = delta.To2dTranslation(); | 1167 gfx::Vector2dF translation = delta.To2dTranslation(); |
| 1134 | 1168 |
| 1135 // Now that we have our scroll delta, we must apply it to each of our | 1169 // Now that we have our scroll delta, we must apply it to each of our |
| 1136 // combined, to/from matrices. | 1170 // combined, to/from matrices. |
| 1137 node->data.to_screen = rounded; | 1171 SetToScreen(node->id, rounded); |
| 1138 node->data.to_parent.Translate(translation.x(), translation.y()); | 1172 node->data.to_parent.Translate(translation.x(), translation.y()); |
| 1139 node->data.from_screen.matrix().postTranslate(-translation.x(), | 1173 gfx::Transform from_screen = FromScreen(node->id); |
| 1140 -translation.y(), 0); | 1174 from_screen.matrix().postTranslate(-translation.x(), -translation.y(), 0); |
| 1141 node->data.to_target.Translate(translation.x(), translation.y()); | 1175 SetFromScreen(node->id, from_screen); |
| 1142 node->data.from_target.matrix().postTranslate(-translation.x(), | 1176 gfx::Transform to_target = ToTarget(node->id); |
| 1143 -translation.y(), 0); | 1177 to_target.Translate(translation.x(), translation.y()); |
| 1144 | 1178 SetToTarget(node->id, to_target); |
| 1179 gfx::Transform from_target = FromTarget(node->id); | |
| 1180 from_target.matrix().postTranslate(-translation.x(), -translation.y(), 0); | |
| 1181 SetFromTarget(node->id, from_target); | |
| 1145 node->data.scroll_snap = translation; | 1182 node->data.scroll_snap = translation; |
| 1146 } | 1183 } |
| 1147 | 1184 |
| 1148 void TransformTree::UpdateTransformChanged(TransformNode* node, | 1185 void TransformTree::UpdateTransformChanged(TransformNode* node, |
| 1149 TransformNode* parent_node, | 1186 TransformNode* parent_node, |
| 1150 TransformNode* source_node) { | 1187 TransformNode* source_node) { |
| 1151 if (parent_node && parent_node->data.transform_changed) { | 1188 if (parent_node && parent_node->data.transform_changed) { |
| 1152 node->data.transform_changed = true; | 1189 node->data.transform_changed = true; |
| 1153 return; | 1190 return; |
| 1154 } | 1191 } |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1234 } | 1271 } |
| 1235 | 1272 |
| 1236 bool TransformTree::HasNodesAffectedByInnerViewportBoundsDelta() const { | 1273 bool TransformTree::HasNodesAffectedByInnerViewportBoundsDelta() const { |
| 1237 return !nodes_affected_by_inner_viewport_bounds_delta_.empty(); | 1274 return !nodes_affected_by_inner_viewport_bounds_delta_.empty(); |
| 1238 } | 1275 } |
| 1239 | 1276 |
| 1240 bool TransformTree::HasNodesAffectedByOuterViewportBoundsDelta() const { | 1277 bool TransformTree::HasNodesAffectedByOuterViewportBoundsDelta() const { |
| 1241 return !nodes_affected_by_outer_viewport_bounds_delta_.empty(); | 1278 return !nodes_affected_by_outer_viewport_bounds_delta_.empty(); |
| 1242 } | 1279 } |
| 1243 | 1280 |
| 1281 const gfx::Transform& TransformTree::FromTarget(int node_id) const { | |
| 1282 DCHECK(static_cast<int>(cached_data_.size()) > node_id); | |
| 1283 return cached_data_[node_id].from_target; | |
| 1284 } | |
| 1285 | |
| 1286 void TransformTree::SetFromTarget(int node_id, | |
| 1287 const gfx::Transform& transform) { | |
| 1288 DCHECK(static_cast<int>(cached_data_.size()) > node_id); | |
| 1289 cached_data_[node_id].from_target = transform; | |
| 1290 } | |
| 1291 | |
| 1292 const gfx::Transform& TransformTree::ToTarget(int node_id) const { | |
| 1293 DCHECK(static_cast<int>(cached_data_.size()) > node_id); | |
| 1294 return cached_data_[node_id].to_target; | |
| 1295 } | |
| 1296 | |
| 1297 void TransformTree::SetToTarget(int node_id, const gfx::Transform& transform) { | |
| 1298 DCHECK(static_cast<int>(cached_data_.size()) > node_id); | |
| 1299 cached_data_[node_id].to_target = transform; | |
| 1300 } | |
| 1301 | |
| 1302 const gfx::Transform& TransformTree::FromScreen(int node_id) const { | |
| 1303 DCHECK(static_cast<int>(cached_data_.size()) > node_id); | |
| 1304 return cached_data_[node_id].from_screen; | |
| 1305 } | |
| 1306 | |
| 1307 void TransformTree::SetFromScreen(int node_id, | |
| 1308 const gfx::Transform& transform) { | |
| 1309 DCHECK(static_cast<int>(cached_data_.size()) > node_id); | |
| 1310 cached_data_[node_id].from_screen = transform; | |
| 1311 } | |
| 1312 | |
| 1313 const gfx::Transform& TransformTree::ToScreen(int node_id) const { | |
| 1314 DCHECK(static_cast<int>(cached_data_.size()) > node_id); | |
| 1315 return cached_data_[node_id].to_screen; | |
| 1316 } | |
| 1317 | |
| 1318 void TransformTree::SetToScreen(int node_id, const gfx::Transform& transform) { | |
| 1319 DCHECK(static_cast<int>(cached_data_.size()) > node_id); | |
| 1320 cached_data_[node_id].to_screen = transform; | |
| 1321 } | |
| 1322 | |
| 1323 int TransformTree::TargetId(int node_id) const { | |
| 1324 DCHECK(static_cast<int>(cached_data_.size()) > node_id); | |
| 1325 return cached_data_[node_id].target_id; | |
| 1326 } | |
| 1327 | |
| 1328 void TransformTree::SetTargetId(int node_id, int target_id) { | |
| 1329 DCHECK(static_cast<int>(cached_data_.size()) > node_id); | |
| 1330 cached_data_[node_id].target_id = target_id; | |
| 1331 } | |
| 1332 | |
| 1333 int TransformTree::ContentTargetId(int node_id) const { | |
| 1334 DCHECK(static_cast<int>(cached_data_.size()) > node_id); | |
| 1335 return cached_data_[node_id].content_target_id; | |
| 1336 } | |
| 1337 | |
| 1338 void TransformTree::SetContentTargetId(int node_id, int content_target_id) { | |
| 1339 DCHECK(static_cast<int>(cached_data_.size()) > node_id); | |
| 1340 cached_data_[node_id].content_target_id = content_target_id; | |
| 1341 } | |
| 1342 | |
| 1244 gfx::Transform TransformTree::ToScreenSpaceTransformWithoutSublayerScale( | 1343 gfx::Transform TransformTree::ToScreenSpaceTransformWithoutSublayerScale( |
| 1245 int id) const { | 1344 int id) const { |
| 1246 DCHECK_GT(id, 0); | 1345 DCHECK_GT(id, 0); |
| 1247 if (id == 1) { | 1346 if (id == 1) { |
| 1248 return gfx::Transform(); | 1347 return gfx::Transform(); |
| 1249 } | 1348 } |
| 1250 const TransformNode* node = Node(id); | 1349 const TransformNode* node = Node(id); |
| 1251 gfx::Transform screen_space_transform = node->data.to_screen; | 1350 gfx::Transform screen_space_transform = ToScreen(id); |
| 1252 if (node->data.sublayer_scale.x() != 0.0 && | 1351 if (node->data.sublayer_scale.x() != 0.0 && |
| 1253 node->data.sublayer_scale.y() != 0.0) | 1352 node->data.sublayer_scale.y() != 0.0) |
| 1254 screen_space_transform.Scale(1.0 / node->data.sublayer_scale.x(), | 1353 screen_space_transform.Scale(1.0 / node->data.sublayer_scale.x(), |
| 1255 1.0 / node->data.sublayer_scale.y()); | 1354 1.0 / node->data.sublayer_scale.y()); |
| 1256 return screen_space_transform; | 1355 return screen_space_transform; |
| 1257 } | 1356 } |
| 1258 | 1357 |
| 1259 bool TransformTree::operator==(const TransformTree& other) const { | 1358 bool TransformTree::operator==(const TransformTree& other) const { |
| 1260 return PropertyTree::operator==(other) && | 1359 return PropertyTree::operator==(other) && |
| 1261 source_to_parent_updates_allowed_ == | 1360 source_to_parent_updates_allowed_ == |
| 1262 other.source_to_parent_updates_allowed() && | 1361 other.source_to_parent_updates_allowed() && |
| 1263 page_scale_factor_ == other.page_scale_factor() && | 1362 page_scale_factor_ == other.page_scale_factor() && |
| 1264 device_scale_factor_ == other.device_scale_factor() && | 1363 device_scale_factor_ == other.device_scale_factor() && |
| 1265 device_transform_scale_factor_ == | 1364 device_transform_scale_factor_ == |
| 1266 other.device_transform_scale_factor() && | 1365 other.device_transform_scale_factor() && |
| 1267 nodes_affected_by_inner_viewport_bounds_delta_ == | 1366 nodes_affected_by_inner_viewport_bounds_delta_ == |
| 1268 other.nodes_affected_by_inner_viewport_bounds_delta() && | 1367 other.nodes_affected_by_inner_viewport_bounds_delta() && |
| 1269 nodes_affected_by_outer_viewport_bounds_delta_ == | 1368 nodes_affected_by_outer_viewport_bounds_delta_ == |
| 1270 other.nodes_affected_by_outer_viewport_bounds_delta(); | 1369 other.nodes_affected_by_outer_viewport_bounds_delta() && |
| 1370 cached_data_ == other.cached_data(); | |
| 1271 } | 1371 } |
| 1272 | 1372 |
| 1273 void TransformTree::ToProtobuf(proto::PropertyTree* proto) const { | 1373 void TransformTree::ToProtobuf(proto::PropertyTree* proto) const { |
| 1274 DCHECK(!proto->has_property_type()); | 1374 DCHECK(!proto->has_property_type()); |
| 1275 proto->set_property_type(proto::PropertyTree::Transform); | 1375 proto->set_property_type(proto::PropertyTree::Transform); |
| 1276 | 1376 |
| 1277 PropertyTree::ToProtobuf(proto); | 1377 PropertyTree::ToProtobuf(proto); |
| 1278 proto::TransformTreeData* data = proto->mutable_transform_tree_data(); | 1378 proto::TransformTreeData* data = proto->mutable_transform_tree_data(); |
| 1279 | 1379 |
| 1280 data->set_source_to_parent_updates_allowed(source_to_parent_updates_allowed_); | 1380 data->set_source_to_parent_updates_allowed(source_to_parent_updates_allowed_); |
| 1281 data->set_page_scale_factor(page_scale_factor_); | 1381 data->set_page_scale_factor(page_scale_factor_); |
| 1282 data->set_device_scale_factor(device_scale_factor_); | 1382 data->set_device_scale_factor(device_scale_factor_); |
| 1283 data->set_device_transform_scale_factor(device_transform_scale_factor_); | 1383 data->set_device_transform_scale_factor(device_transform_scale_factor_); |
| 1284 | 1384 |
| 1285 for (auto i : nodes_affected_by_inner_viewport_bounds_delta_) | 1385 for (auto i : nodes_affected_by_inner_viewport_bounds_delta_) |
| 1286 data->add_nodes_affected_by_inner_viewport_bounds_delta(i); | 1386 data->add_nodes_affected_by_inner_viewport_bounds_delta(i); |
| 1287 | 1387 |
| 1288 for (auto i : nodes_affected_by_outer_viewport_bounds_delta_) | 1388 for (auto i : nodes_affected_by_outer_viewport_bounds_delta_) |
| 1289 data->add_nodes_affected_by_outer_viewport_bounds_delta(i); | 1389 data->add_nodes_affected_by_outer_viewport_bounds_delta(i); |
| 1390 | |
| 1391 for (int i = 0; i < static_cast<int>(cached_data_.size()); ++i) | |
| 1392 cached_data_[i].ToProtobuf(data->add_cached_data()); | |
| 1290 } | 1393 } |
| 1291 | 1394 |
| 1292 void TransformTree::FromProtobuf( | 1395 void TransformTree::FromProtobuf( |
| 1293 const proto::PropertyTree& proto, | 1396 const proto::PropertyTree& proto, |
| 1294 std::unordered_map<int, int>* node_id_to_index_map) { | 1397 std::unordered_map<int, int>* node_id_to_index_map) { |
| 1295 DCHECK(proto.has_property_type()); | 1398 DCHECK(proto.has_property_type()); |
| 1296 DCHECK_EQ(proto.property_type(), proto::PropertyTree::Transform); | 1399 DCHECK_EQ(proto.property_type(), proto::PropertyTree::Transform); |
| 1297 | 1400 |
| 1298 PropertyTree::FromProtobuf(proto, node_id_to_index_map); | 1401 PropertyTree::FromProtobuf(proto, node_id_to_index_map); |
| 1299 const proto::TransformTreeData& data = proto.transform_tree_data(); | 1402 const proto::TransformTreeData& data = proto.transform_tree_data(); |
| 1300 | 1403 |
| 1301 source_to_parent_updates_allowed_ = data.source_to_parent_updates_allowed(); | 1404 source_to_parent_updates_allowed_ = data.source_to_parent_updates_allowed(); |
| 1302 page_scale_factor_ = data.page_scale_factor(); | 1405 page_scale_factor_ = data.page_scale_factor(); |
| 1303 device_scale_factor_ = data.device_scale_factor(); | 1406 device_scale_factor_ = data.device_scale_factor(); |
| 1304 device_transform_scale_factor_ = data.device_transform_scale_factor(); | 1407 device_transform_scale_factor_ = data.device_transform_scale_factor(); |
| 1305 | 1408 |
| 1306 DCHECK(nodes_affected_by_inner_viewport_bounds_delta_.empty()); | 1409 DCHECK(nodes_affected_by_inner_viewport_bounds_delta_.empty()); |
| 1307 for (int i = 0; i < data.nodes_affected_by_inner_viewport_bounds_delta_size(); | 1410 for (int i = 0; i < data.nodes_affected_by_inner_viewport_bounds_delta_size(); |
| 1308 ++i) { | 1411 ++i) { |
| 1309 nodes_affected_by_inner_viewport_bounds_delta_.push_back( | 1412 nodes_affected_by_inner_viewport_bounds_delta_.push_back( |
| 1310 data.nodes_affected_by_inner_viewport_bounds_delta(i)); | 1413 data.nodes_affected_by_inner_viewport_bounds_delta(i)); |
| 1311 } | 1414 } |
| 1312 | 1415 |
| 1313 DCHECK(nodes_affected_by_outer_viewport_bounds_delta_.empty()); | 1416 DCHECK(nodes_affected_by_outer_viewport_bounds_delta_.empty()); |
| 1314 for (int i = 0; i < data.nodes_affected_by_outer_viewport_bounds_delta_size(); | 1417 for (int i = 0; i < data.nodes_affected_by_outer_viewport_bounds_delta_size(); |
| 1315 ++i) { | 1418 ++i) { |
| 1316 nodes_affected_by_outer_viewport_bounds_delta_.push_back( | 1419 nodes_affected_by_outer_viewport_bounds_delta_.push_back( |
| 1317 data.nodes_affected_by_outer_viewport_bounds_delta(i)); | 1420 data.nodes_affected_by_outer_viewport_bounds_delta(i)); |
| 1318 } | 1421 } |
| 1422 | |
| 1423 // delete the node created when initializing transform tree | |
|
ajuma
2016/06/07 20:39:19
This comment is now obsolete.
| |
| 1424 DCHECK_EQ(static_cast<int>(cached_data_.size()), 1); | |
| 1425 cached_data_.back().FromProtobuf(data.cached_data(0)); | |
| 1426 for (int i = 1; i < data.cached_data_size(); ++i) { | |
| 1427 cached_data_.push_back(TransformCachedNodeData()); | |
| 1428 cached_data_.back().FromProtobuf(data.cached_data(i)); | |
| 1429 } | |
| 1319 } | 1430 } |
| 1320 | 1431 |
| 1321 EffectTree::EffectTree() {} | 1432 EffectTree::EffectTree() {} |
| 1322 | 1433 |
| 1323 EffectTree::~EffectTree() {} | 1434 EffectTree::~EffectTree() {} |
| 1324 | 1435 |
| 1325 float EffectTree::EffectiveOpacity(const EffectNode* node) const { | 1436 float EffectTree::EffectiveOpacity(const EffectNode* node) const { |
| 1326 return node->data.subtree_hidden ? 0.f : node->data.opacity; | 1437 return node->data.subtree_hidden ? 0.f : node->data.opacity; |
| 1327 } | 1438 } |
| 1328 | 1439 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1378 transform_tree.Node(node->data.transform_id); | 1489 transform_tree.Node(node->data.transform_id); |
| 1379 if (transform_node->data.is_invertible && | 1490 if (transform_node->data.is_invertible && |
| 1380 transform_node->data.ancestors_are_invertible) { | 1491 transform_node->data.ancestors_are_invertible) { |
| 1381 if (transform_node->data.sorting_context_id) { | 1492 if (transform_node->data.sorting_context_id) { |
| 1382 const TransformNode* parent_transform_node = | 1493 const TransformNode* parent_transform_node = |
| 1383 transform_tree.parent(transform_node); | 1494 transform_tree.parent(transform_node); |
| 1384 if (parent_transform_node && | 1495 if (parent_transform_node && |
| 1385 parent_transform_node->data.sorting_context_id == | 1496 parent_transform_node->data.sorting_context_id == |
| 1386 transform_node->data.sorting_context_id) { | 1497 transform_node->data.sorting_context_id) { |
| 1387 gfx::Transform surface_draw_transform; | 1498 gfx::Transform surface_draw_transform; |
| 1388 transform_tree.ComputeTransform(transform_node->id, | 1499 transform_tree.ComputeTransform( |
| 1389 transform_node->data.target_id, | 1500 transform_node->id, transform_tree.TargetId(transform_node->id), |
| 1390 &surface_draw_transform); | 1501 &surface_draw_transform); |
| 1391 node->data.hidden_by_backface_visibility = | 1502 node->data.hidden_by_backface_visibility = |
| 1392 surface_draw_transform.IsBackFaceVisible(); | 1503 surface_draw_transform.IsBackFaceVisible(); |
| 1393 } else { | 1504 } else { |
| 1394 node->data.hidden_by_backface_visibility = | 1505 node->data.hidden_by_backface_visibility = |
| 1395 transform_node->data.local.IsBackFaceVisible(); | 1506 transform_node->data.local.IsBackFaceVisible(); |
| 1396 } | 1507 } |
| 1397 return; | 1508 return; |
| 1398 } | 1509 } |
| 1399 } | 1510 } |
| 1400 } | 1511 } |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1744 const ScrollNode* scroll_node = Node(currently_scrolling_node_id_); | 1855 const ScrollNode* scroll_node = Node(currently_scrolling_node_id_); |
| 1745 return scroll_node; | 1856 return scroll_node; |
| 1746 } | 1857 } |
| 1747 | 1858 |
| 1748 void ScrollTree::set_currently_scrolling_node(int scroll_node_id) { | 1859 void ScrollTree::set_currently_scrolling_node(int scroll_node_id) { |
| 1749 currently_scrolling_node_id_ = scroll_node_id; | 1860 currently_scrolling_node_id_ = scroll_node_id; |
| 1750 } | 1861 } |
| 1751 | 1862 |
| 1752 gfx::Transform ScrollTree::ScreenSpaceTransform(int scroll_node_id) const { | 1863 gfx::Transform ScrollTree::ScreenSpaceTransform(int scroll_node_id) const { |
| 1753 const ScrollNode* scroll_node = Node(scroll_node_id); | 1864 const ScrollNode* scroll_node = Node(scroll_node_id); |
| 1865 const TransformTree& transform_tree = property_trees()->transform_tree; | |
| 1754 const TransformNode* transform_node = | 1866 const TransformNode* transform_node = |
| 1755 property_trees()->transform_tree.Node(scroll_node->data.transform_id); | 1867 transform_tree.Node(scroll_node->data.transform_id); |
| 1756 gfx::Transform screen_space_transform( | 1868 gfx::Transform screen_space_transform( |
| 1757 1, 0, 0, 1, scroll_node->data.offset_to_transform_parent.x(), | 1869 1, 0, 0, 1, scroll_node->data.offset_to_transform_parent.x(), |
| 1758 scroll_node->data.offset_to_transform_parent.y()); | 1870 scroll_node->data.offset_to_transform_parent.y()); |
| 1759 screen_space_transform.ConcatTransform(transform_node->data.to_screen); | 1871 screen_space_transform.ConcatTransform( |
| 1872 transform_tree.ToScreen(transform_node->id)); | |
| 1760 if (scroll_node->data.should_flatten) | 1873 if (scroll_node->data.should_flatten) |
| 1761 screen_space_transform.FlattenTo2d(); | 1874 screen_space_transform.FlattenTo2d(); |
| 1762 return screen_space_transform; | 1875 return screen_space_transform; |
| 1763 } | 1876 } |
| 1764 | 1877 |
| 1765 SyncedScrollOffset* ScrollTree::synced_scroll_offset(int layer_id) { | 1878 SyncedScrollOffset* ScrollTree::synced_scroll_offset(int layer_id) { |
| 1766 if (layer_id_to_scroll_offset_map_.find(layer_id) == | 1879 if (layer_id_to_scroll_offset_map_.find(layer_id) == |
| 1767 layer_id_to_scroll_offset_map_.end()) { | 1880 layer_id_to_scroll_offset_map_.end()) { |
| 1768 layer_id_to_scroll_offset_map_[layer_id] = new SyncedScrollOffset; | 1881 layer_id_to_scroll_offset_map_[layer_id] = new SyncedScrollOffset; |
| 1769 } | 1882 } |
| (...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2228 value->EndDictionary(); | 2341 value->EndDictionary(); |
| 2229 | 2342 |
| 2230 value->BeginDictionary("scroll_tree"); | 2343 value->BeginDictionary("scroll_tree"); |
| 2231 scroll_tree.AsValueInto(value.get()); | 2344 scroll_tree.AsValueInto(value.get()); |
| 2232 value->EndDictionary(); | 2345 value->EndDictionary(); |
| 2233 | 2346 |
| 2234 return value; | 2347 return value; |
| 2235 } | 2348 } |
| 2236 | 2349 |
| 2237 } // namespace cc | 2350 } // namespace cc |
| OLD | NEW |