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 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 418 return gfx::Vector2dF(); | 418 return gfx::Vector2dF(); |
| 419 const StickyPositionNodeData* sticky_data = | 419 const StickyPositionNodeData* sticky_data = |
| 420 tree->StickyPositionData(node->id); | 420 tree->StickyPositionData(node->id); |
| 421 const LayerStickyPositionConstraint& constraint = sticky_data->constraints; | 421 const LayerStickyPositionConstraint& constraint = sticky_data->constraints; |
| 422 ScrollNode* scroll_node = | 422 ScrollNode* scroll_node = |
| 423 tree->property_trees()->scroll_tree.Node(sticky_data->scroll_ancestor); | 423 tree->property_trees()->scroll_tree.Node(sticky_data->scroll_ancestor); |
| 424 gfx::ScrollOffset scroll_offset = | 424 gfx::ScrollOffset scroll_offset = |
| 425 tree->property_trees()->scroll_tree.current_scroll_offset( | 425 tree->property_trees()->scroll_tree.current_scroll_offset( |
| 426 scroll_node->owner_id); | 426 scroll_node->owner_id); |
| 427 gfx::PointF scroll_position(scroll_offset.x(), scroll_offset.y()); | 427 gfx::PointF scroll_position(scroll_offset.x(), scroll_offset.y()); |
| 428 // The scroll position does not include snapping which shifts the scroll | 428 TransformNode* scroll_ancestor_transform_node = |
| 429 // offset to align to a pixel boundary, we need to manually include it here. | 429 tree->Node(scroll_node->transform_id); |
| 430 scroll_position -= tree->property_trees() | 430 if (scroll_ancestor_transform_node->scrolls) { |
| 431 ->transform_tree.Node(scroll_node->transform_id) | 431 // The scroll position does not include snapping which shifts the scroll |
| 432 ->scroll_snap; | 432 // offset to align to a pixel boundary, we need to manually include it here. |
| 433 // In this case, snapping is caused by a scroll. | |
| 434 scroll_position -= scroll_ancestor_transform_node->snap_amount; | |
| 435 } | |
| 433 | 436 |
| 434 gfx::RectF clip( | 437 gfx::RectF clip( |
| 435 scroll_position, | 438 scroll_position, |
| 436 gfx::SizeF(tree->property_trees()->scroll_tree.scroll_clip_layer_bounds( | 439 gfx::SizeF(tree->property_trees()->scroll_tree.scroll_clip_layer_bounds( |
| 437 scroll_node->id))); | 440 scroll_node->id))); |
| 438 gfx::Vector2dF sticky_offset( | 441 gfx::Vector2dF sticky_offset( |
| 439 constraint.scroll_container_relative_sticky_box_rect.OffsetFromOrigin()); | 442 constraint.scroll_container_relative_sticky_box_rect.OffsetFromOrigin()); |
| 440 gfx::Vector2dF layer_offset(sticky_data->main_thread_offset); | 443 gfx::Vector2dF layer_offset(sticky_data->main_thread_offset); |
| 441 | 444 |
| 442 // In each of the following cases, we measure the limit which is the point | 445 // In each of the following cases, we measure the limit which is the point |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 502 } | 505 } |
| 503 | 506 |
| 504 void TransformTree::UpdateLocalTransform(TransformNode* node) { | 507 void TransformTree::UpdateLocalTransform(TransformNode* node) { |
| 505 gfx::Transform transform = node->post_local; | 508 gfx::Transform transform = node->post_local; |
| 506 if (NeedsSourceToParentUpdate(node)) { | 509 if (NeedsSourceToParentUpdate(node)) { |
| 507 gfx::Transform to_parent; | 510 gfx::Transform to_parent; |
| 508 ComputeTranslation(node->source_node_id, node->parent_id, &to_parent); | 511 ComputeTranslation(node->source_node_id, node->parent_id, &to_parent); |
| 509 gfx::Vector2dF unsnapping; | 512 gfx::Vector2dF unsnapping; |
| 510 TransformNode* current; | 513 TransformNode* current; |
| 511 TransformNode* parent_node; | 514 TransformNode* parent_node; |
| 515 // Since we are calculating the adjustment for fixed position node or a | |
| 516 // scroll child, we need to unsnap only if the snap was caused by a scroll. | |
| 512 for (current = Node(node->source_node_id); current->id > node->parent_id; | 517 for (current = Node(node->source_node_id); current->id > node->parent_id; |
| 513 current = parent(current)) { | 518 current = parent(current)) { |
| 514 unsnapping.Subtract(current->scroll_snap); | 519 if (current->scrolls) |
| 520 unsnapping.Subtract(current->snap_amount); | |
|
ajuma
2016/10/26 21:19:39
Could we DCHECK that the snap_amount is non-zero o
jaydasika
2016/10/26 21:49:13
Done.
| |
| 515 } | 521 } |
| 516 for (parent_node = Node(node->parent_id); | 522 for (parent_node = Node(node->parent_id); |
| 517 parent_node->id > node->source_node_id; | 523 parent_node->id > node->source_node_id; |
| 518 parent_node = parent(parent_node)) { | 524 parent_node = parent(parent_node)) { |
| 519 unsnapping.Add(parent_node->scroll_snap); | 525 if (parent_node->scrolls) |
| 526 unsnapping.Add(parent_node->snap_amount); | |
| 520 } | 527 } |
| 521 // If a node NeedsSourceToParentUpdate, the node is either a fixed position | 528 // If a node NeedsSourceToParentUpdate, the node is either a fixed position |
| 522 // node or a scroll child. | 529 // node or a scroll child. |
| 523 // If the node has a fixed position, the parent of the node is an ancestor | 530 // If the node has a fixed position, the parent of the node is an ancestor |
| 524 // of source node, current->id should be equal to node->parent_id. | 531 // of source node, current->id should be equal to node->parent_id. |
| 525 // Otherwise, the node's source node is always an ancestor of the node owned | 532 // Otherwise, the node's source node is always an ancestor of the node owned |
| 526 // by the scroll parent, so parent_node->id should be equal to | 533 // by the scroll parent, so parent_node->id should be equal to |
| 527 // node->source_node_id. | 534 // node->source_node_id. |
| 528 DCHECK(current->id == node->parent_id || | 535 DCHECK(current->id == node->parent_id || |
| 529 parent_node->id == node->source_node_id); | 536 parent_node->id == node->source_node_id); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 626 void TransformTree::UpdateAnimationProperties(TransformNode* node, | 633 void TransformTree::UpdateAnimationProperties(TransformNode* node, |
| 627 TransformNode* parent_node) { | 634 TransformNode* parent_node) { |
| 628 bool ancestor_is_animating = false; | 635 bool ancestor_is_animating = false; |
| 629 if (parent_node) | 636 if (parent_node) |
| 630 ancestor_is_animating = parent_node->to_screen_is_potentially_animated; | 637 ancestor_is_animating = parent_node->to_screen_is_potentially_animated; |
| 631 node->to_screen_is_potentially_animated = | 638 node->to_screen_is_potentially_animated = |
| 632 node->has_potential_animation || ancestor_is_animating; | 639 node->has_potential_animation || ancestor_is_animating; |
| 633 } | 640 } |
| 634 | 641 |
| 635 void TransformTree::UndoSnapping(TransformNode* node) { | 642 void TransformTree::UndoSnapping(TransformNode* node) { |
| 636 // to_parent transform has the scroll snap from previous frame baked in. | 643 // to_parent transform has snapping from previous frame baked in. |
| 637 // We need to undo it and use the un-snapped transform to compute current | 644 // We need to undo it and use the un-snapped transform to compute current |
| 638 // target and screen space transforms. | 645 // target and screen space transforms. |
| 639 node->to_parent.Translate(-node->scroll_snap.x(), -node->scroll_snap.y()); | 646 node->to_parent.Translate(-node->snap_amount.x(), -node->snap_amount.y()); |
| 640 } | 647 } |
| 641 | 648 |
| 642 void TransformTree::UpdateSnapping(TransformNode* node) { | 649 void TransformTree::UpdateSnapping(TransformNode* node) { |
| 643 if (!node->scrolls || node->to_screen_is_potentially_animated || | 650 if (!node->should_be_snapped || node->to_screen_is_potentially_animated || |
| 644 !ToScreen(node->id).IsScaleOrTranslation() || | 651 !ToScreen(node->id).IsScaleOrTranslation() || |
| 645 !node->ancestors_are_invertible) { | 652 !node->ancestors_are_invertible) { |
| 646 return; | 653 return; |
| 647 } | 654 } |
| 648 | 655 |
| 649 // Scroll snapping must be done in screen space (the pixels we care about). | 656 // Snapping must be done in screen space (the pixels we care about). |
|
enne (OOO)
2016/10/26 20:32:33
This comment is not actually true. Snapping reall
jaydasika
2016/10/26 21:49:13
Done.
| |
| 650 // This means we effectively snap the screen space transform. If ST is the | 657 // This means we effectively snap the screen space transform. If ST is the |
| 651 // screen space transform and ST' is ST with its translation components | 658 // screen space transform and ST' is ST with its translation components |
| 652 // rounded, then what we're after is the scroll delta X, where ST * X = ST'. | 659 // rounded, then what we're after is the scroll delta X, where ST * X = ST'. |
| 653 // I.e., we want a transform that will realize our scroll snap. It follows | 660 // I.e., we want a transform that will realize our snap. It follows that |
| 654 // that X = ST^-1 * ST'. We cache ST and ST^-1 to make this more efficient. | 661 // X = ST^-1 * ST'. We cache ST and ST^-1 to make this more efficient. |
| 655 gfx::Transform rounded = ToScreen(node->id); | 662 gfx::Transform rounded = ToScreen(node->id); |
| 656 rounded.RoundTranslationComponents(); | 663 rounded.RoundTranslationComponents(); |
| 657 gfx::Transform delta = FromScreen(node->id); | 664 gfx::Transform delta = FromScreen(node->id); |
| 658 delta *= rounded; | 665 delta *= rounded; |
| 659 | 666 |
| 660 DCHECK(delta.IsApproximatelyIdentityOrTranslation(SkDoubleToMScalar(1e-4))) | 667 DCHECK(delta.IsApproximatelyIdentityOrTranslation(SkDoubleToMScalar(1e-4))) |
| 661 << delta.ToString(); | 668 << delta.ToString(); |
| 662 | 669 |
| 663 gfx::Vector2dF translation = delta.To2dTranslation(); | 670 gfx::Vector2dF translation = delta.To2dTranslation(); |
| 664 | 671 |
| 665 // Now that we have our scroll delta, we must apply it to each of our | 672 // Now that we have our delta, we must apply it to each of our combined, |
| 666 // combined, to/from matrices. | 673 // to/from matrices. |
| 667 SetToScreen(node->id, rounded); | 674 SetToScreen(node->id, rounded); |
| 668 node->to_parent.Translate(translation.x(), translation.y()); | 675 node->to_parent.Translate(translation.x(), translation.y()); |
| 669 gfx::Transform from_screen = FromScreen(node->id); | 676 gfx::Transform from_screen = FromScreen(node->id); |
| 670 from_screen.matrix().postTranslate(-translation.x(), -translation.y(), 0); | 677 from_screen.matrix().postTranslate(-translation.x(), -translation.y(), 0); |
| 671 SetFromScreen(node->id, from_screen); | 678 SetFromScreen(node->id, from_screen); |
| 672 node->scroll_snap = translation; | 679 node->snap_amount = translation; |
| 673 } | 680 } |
| 674 | 681 |
| 675 void TransformTree::UpdateTransformChanged(TransformNode* node, | 682 void TransformTree::UpdateTransformChanged(TransformNode* node, |
| 676 TransformNode* parent_node, | 683 TransformNode* parent_node, |
| 677 TransformNode* source_node) { | 684 TransformNode* source_node) { |
| 678 if (parent_node && parent_node->transform_changed) { | 685 if (parent_node && parent_node->transform_changed) { |
| 679 node->transform_changed = true; | 686 node->transform_changed = true; |
| 680 return; | 687 return; |
| 681 } | 688 } |
| 682 | 689 |
| (...skipping 1685 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2368 | 2375 |
| 2369 const EffectNode* effect_node = effect_tree.Node(effect_id); | 2376 const EffectNode* effect_node = effect_tree.Node(effect_id); |
| 2370 | 2377 |
| 2371 bool success = GetFromTarget(transform_id, effect_id, transform); | 2378 bool success = GetFromTarget(transform_id, effect_id, transform); |
| 2372 transform->Scale(effect_node->surface_contents_scale.x(), | 2379 transform->Scale(effect_node->surface_contents_scale.x(), |
| 2373 effect_node->surface_contents_scale.y()); | 2380 effect_node->surface_contents_scale.y()); |
| 2374 return success; | 2381 return success; |
| 2375 } | 2382 } |
| 2376 | 2383 |
| 2377 } // namespace cc | 2384 } // namespace cc |
| OLD | NEW |