| 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 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 return gfx::Vector2dF(); | 408 return gfx::Vector2dF(); |
| 409 const StickyPositionNodeData* sticky_data = | 409 const StickyPositionNodeData* sticky_data = |
| 410 tree->StickyPositionData(node->id); | 410 tree->StickyPositionData(node->id); |
| 411 const LayerStickyPositionConstraint& constraint = sticky_data->constraints; | 411 const LayerStickyPositionConstraint& constraint = sticky_data->constraints; |
| 412 ScrollNode* scroll_node = | 412 ScrollNode* scroll_node = |
| 413 tree->property_trees()->scroll_tree.Node(sticky_data->scroll_ancestor); | 413 tree->property_trees()->scroll_tree.Node(sticky_data->scroll_ancestor); |
| 414 gfx::ScrollOffset scroll_offset = | 414 gfx::ScrollOffset scroll_offset = |
| 415 tree->property_trees()->scroll_tree.current_scroll_offset( | 415 tree->property_trees()->scroll_tree.current_scroll_offset( |
| 416 scroll_node->owner_id); | 416 scroll_node->owner_id); |
| 417 gfx::PointF scroll_position(scroll_offset.x(), scroll_offset.y()); | 417 gfx::PointF scroll_position(scroll_offset.x(), scroll_offset.y()); |
| 418 // The scroll position does not include snapping which shifts the scroll | 418 TransformNode* scroll_ancestor_transform_node = |
| 419 // offset to align to a pixel boundary, we need to manually include it here. | 419 tree->Node(scroll_node->transform_id); |
| 420 scroll_position -= tree->property_trees() | 420 if (scroll_ancestor_transform_node->scrolls) { |
| 421 ->transform_tree.Node(scroll_node->transform_id) | 421 // The scroll position does not include snapping which shifts the scroll |
| 422 ->scroll_snap; | 422 // offset to align to a pixel boundary, we need to manually include it here. |
| 423 // In this case, snapping is caused by a scroll. |
| 424 scroll_position -= scroll_ancestor_transform_node->snap_amount; |
| 425 } |
| 423 | 426 |
| 424 gfx::RectF clip( | 427 gfx::RectF clip( |
| 425 scroll_position, | 428 scroll_position, |
| 426 gfx::SizeF(tree->property_trees()->scroll_tree.scroll_clip_layer_bounds( | 429 gfx::SizeF(tree->property_trees()->scroll_tree.scroll_clip_layer_bounds( |
| 427 scroll_node->id))); | 430 scroll_node->id))); |
| 428 gfx::Vector2dF sticky_offset( | 431 gfx::Vector2dF sticky_offset( |
| 429 constraint.scroll_container_relative_sticky_box_rect.OffsetFromOrigin()); | 432 constraint.scroll_container_relative_sticky_box_rect.OffsetFromOrigin()); |
| 430 gfx::Vector2dF layer_offset(sticky_data->main_thread_offset); | 433 gfx::Vector2dF layer_offset(sticky_data->main_thread_offset); |
| 431 | 434 |
| 432 // In each of the following cases, we measure the limit which is the point | 435 // 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... |
| 492 } | 495 } |
| 493 | 496 |
| 494 void TransformTree::UpdateLocalTransform(TransformNode* node) { | 497 void TransformTree::UpdateLocalTransform(TransformNode* node) { |
| 495 gfx::Transform transform = node->post_local; | 498 gfx::Transform transform = node->post_local; |
| 496 if (NeedsSourceToParentUpdate(node)) { | 499 if (NeedsSourceToParentUpdate(node)) { |
| 497 gfx::Transform to_parent; | 500 gfx::Transform to_parent; |
| 498 ComputeTranslation(node->source_node_id, node->parent_id, &to_parent); | 501 ComputeTranslation(node->source_node_id, node->parent_id, &to_parent); |
| 499 gfx::Vector2dF unsnapping; | 502 gfx::Vector2dF unsnapping; |
| 500 TransformNode* current; | 503 TransformNode* current; |
| 501 TransformNode* parent_node; | 504 TransformNode* parent_node; |
| 505 // Since we are calculating the adjustment for fixed position node or a |
| 506 // scroll child, we need to unsnap only if the snap was caused by a scroll. |
| 502 for (current = Node(node->source_node_id); current->id > node->parent_id; | 507 for (current = Node(node->source_node_id); current->id > node->parent_id; |
| 503 current = parent(current)) { | 508 current = parent(current)) { |
| 504 unsnapping.Subtract(current->scroll_snap); | 509 DCHECK(current->scrolls || current->snap_amount.IsZero()); |
| 510 if (current->scrolls) |
| 511 unsnapping.Subtract(current->snap_amount); |
| 505 } | 512 } |
| 506 for (parent_node = Node(node->parent_id); | 513 for (parent_node = Node(node->parent_id); |
| 507 parent_node->id > node->source_node_id; | 514 parent_node->id > node->source_node_id; |
| 508 parent_node = parent(parent_node)) { | 515 parent_node = parent(parent_node)) { |
| 509 unsnapping.Add(parent_node->scroll_snap); | 516 DCHECK(parent_node->scrolls || parent_node->snap_amount.IsZero()); |
| 517 if (parent_node->scrolls) |
| 518 unsnapping.Add(parent_node->snap_amount); |
| 510 } | 519 } |
| 511 // If a node NeedsSourceToParentUpdate, the node is either a fixed position | 520 // If a node NeedsSourceToParentUpdate, the node is either a fixed position |
| 512 // node or a scroll child. | 521 // node or a scroll child. |
| 513 // If the node has a fixed position, the parent of the node is an ancestor | 522 // If the node has a fixed position, the parent of the node is an ancestor |
| 514 // of source node, current->id should be equal to node->parent_id. | 523 // of source node, current->id should be equal to node->parent_id. |
| 515 // Otherwise, the node's source node is always an ancestor of the node owned | 524 // Otherwise, the node's source node is always an ancestor of the node owned |
| 516 // by the scroll parent, so parent_node->id should be equal to | 525 // by the scroll parent, so parent_node->id should be equal to |
| 517 // node->source_node_id. | 526 // node->source_node_id. |
| 518 DCHECK(current->id == node->parent_id || | 527 DCHECK(current->id == node->parent_id || |
| 519 parent_node->id == node->source_node_id); | 528 parent_node->id == node->source_node_id); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 576 void TransformTree::UpdateAnimationProperties(TransformNode* node, | 585 void TransformTree::UpdateAnimationProperties(TransformNode* node, |
| 577 TransformNode* parent_node) { | 586 TransformNode* parent_node) { |
| 578 bool ancestor_is_animating = false; | 587 bool ancestor_is_animating = false; |
| 579 if (parent_node) | 588 if (parent_node) |
| 580 ancestor_is_animating = parent_node->to_screen_is_potentially_animated; | 589 ancestor_is_animating = parent_node->to_screen_is_potentially_animated; |
| 581 node->to_screen_is_potentially_animated = | 590 node->to_screen_is_potentially_animated = |
| 582 node->has_potential_animation || ancestor_is_animating; | 591 node->has_potential_animation || ancestor_is_animating; |
| 583 } | 592 } |
| 584 | 593 |
| 585 void TransformTree::UndoSnapping(TransformNode* node) { | 594 void TransformTree::UndoSnapping(TransformNode* node) { |
| 586 // to_parent transform has the scroll snap from previous frame baked in. | 595 // to_parent transform has snapping from previous frame baked in. |
| 587 // We need to undo it and use the un-snapped transform to compute current | 596 // We need to undo it and use the un-snapped transform to compute current |
| 588 // target and screen space transforms. | 597 // target and screen space transforms. |
| 589 node->to_parent.Translate(-node->scroll_snap.x(), -node->scroll_snap.y()); | 598 node->to_parent.Translate(-node->snap_amount.x(), -node->snap_amount.y()); |
| 590 } | 599 } |
| 591 | 600 |
| 592 void TransformTree::UpdateSnapping(TransformNode* node) { | 601 void TransformTree::UpdateSnapping(TransformNode* node) { |
| 593 if (!node->scrolls || node->to_screen_is_potentially_animated || | 602 if (!node->should_be_snapped || node->to_screen_is_potentially_animated || |
| 594 !ToScreen(node->id).IsScaleOrTranslation() || | 603 !ToScreen(node->id).IsScaleOrTranslation() || |
| 595 !node->ancestors_are_invertible) { | 604 !node->ancestors_are_invertible) { |
| 596 return; | 605 return; |
| 597 } | 606 } |
| 598 | 607 |
| 599 // Scroll snapping must be done in screen space (the pixels we care about). | 608 // Snapping must be done in target space (the pixels we care about) and then |
| 600 // This means we effectively snap the screen space transform. If ST is the | 609 // the render pass should also be snapped if necessary. But, we do it in |
| 610 // screen space because it is easier and works most of the time if there is |
| 611 // no intermediate render pass with a snap-destrying transform. If ST is the |
| 601 // screen space transform and ST' is ST with its translation components | 612 // screen space transform and ST' is ST with its translation components |
| 602 // rounded, then what we're after is the scroll delta X, where ST * X = ST'. | 613 // rounded, then what we're after is the scroll delta X, where ST * X = ST'. |
| 603 // I.e., we want a transform that will realize our scroll snap. It follows | 614 // I.e., we want a transform that will realize our snap. It follows that |
| 604 // that X = ST^-1 * ST'. We cache ST and ST^-1 to make this more efficient. | 615 // X = ST^-1 * ST'. We cache ST and ST^-1 to make this more efficient. |
| 605 gfx::Transform rounded = ToScreen(node->id); | 616 gfx::Transform rounded = ToScreen(node->id); |
| 606 rounded.RoundTranslationComponents(); | 617 rounded.RoundTranslationComponents(); |
| 607 gfx::Transform delta = FromScreen(node->id); | 618 gfx::Transform delta = FromScreen(node->id); |
| 608 delta *= rounded; | 619 delta *= rounded; |
| 609 | 620 |
| 610 DCHECK(delta.IsApproximatelyIdentityOrTranslation(SkDoubleToMScalar(1e-4))) | 621 DCHECK(delta.IsApproximatelyIdentityOrTranslation(SkDoubleToMScalar(1e-4))) |
| 611 << delta.ToString(); | 622 << delta.ToString(); |
| 612 | 623 |
| 613 gfx::Vector2dF translation = delta.To2dTranslation(); | 624 gfx::Vector2dF translation = delta.To2dTranslation(); |
| 614 | 625 |
| 615 // Now that we have our scroll delta, we must apply it to each of our | 626 // Now that we have our delta, we must apply it to each of our combined, |
| 616 // combined, to/from matrices. | 627 // to/from matrices. |
| 617 SetToScreen(node->id, rounded); | 628 SetToScreen(node->id, rounded); |
| 618 node->to_parent.Translate(translation.x(), translation.y()); | 629 node->to_parent.Translate(translation.x(), translation.y()); |
| 619 gfx::Transform from_screen = FromScreen(node->id); | 630 gfx::Transform from_screen = FromScreen(node->id); |
| 620 from_screen.matrix().postTranslate(-translation.x(), -translation.y(), 0); | 631 from_screen.matrix().postTranslate(-translation.x(), -translation.y(), 0); |
| 621 SetFromScreen(node->id, from_screen); | 632 SetFromScreen(node->id, from_screen); |
| 622 node->scroll_snap = translation; | 633 node->snap_amount = translation; |
| 623 } | 634 } |
| 624 | 635 |
| 625 void TransformTree::UpdateTransformChanged(TransformNode* node, | 636 void TransformTree::UpdateTransformChanged(TransformNode* node, |
| 626 TransformNode* parent_node, | 637 TransformNode* parent_node, |
| 627 TransformNode* source_node) { | 638 TransformNode* source_node) { |
| 628 if (parent_node && parent_node->transform_changed) { | 639 if (parent_node && parent_node->transform_changed) { |
| 629 node->transform_changed = true; | 640 node->transform_changed = true; |
| 630 return; | 641 return; |
| 631 } | 642 } |
| 632 | 643 |
| (...skipping 1638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2271 | 2282 |
| 2272 const EffectNode* effect_node = effect_tree.Node(effect_id); | 2283 const EffectNode* effect_node = effect_tree.Node(effect_id); |
| 2273 | 2284 |
| 2274 bool success = GetFromTarget(transform_id, effect_id, transform); | 2285 bool success = GetFromTarget(transform_id, effect_id, transform); |
| 2275 transform->Scale(effect_node->surface_contents_scale.x(), | 2286 transform->Scale(effect_node->surface_contents_scale.x(), |
| 2276 effect_node->surface_contents_scale.y()); | 2287 effect_node->surface_contents_scale.y()); |
| 2277 return success; | 2288 return success; |
| 2278 } | 2289 } |
| 2279 | 2290 |
| 2280 } // namespace cc | 2291 } // namespace cc |
| OLD | NEW |