| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 "cc/layers/layer_impl.h" | 5 #include "cc/layers/layer_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 damage_rect_.SetRect(0, 0, 0, 0); | 477 damage_rect_.SetRect(0, 0, 0, 0); |
| 478 } | 478 } |
| 479 | 479 |
| 480 int LayerImpl::num_copy_requests_in_target_subtree() { | 480 int LayerImpl::num_copy_requests_in_target_subtree() { |
| 481 return GetEffectTree() | 481 return GetEffectTree() |
| 482 .Node(effect_tree_index()) | 482 .Node(effect_tree_index()) |
| 483 ->num_copy_requests_in_subtree; | 483 ->num_copy_requests_in_subtree; |
| 484 } | 484 } |
| 485 | 485 |
| 486 void LayerImpl::UpdatePropertyTreeTransformIsAnimated(bool is_animated) { | 486 void LayerImpl::UpdatePropertyTreeTransformIsAnimated(bool is_animated) { |
| 487 PropertyTrees* property_trees = GetPropertyTrees(); | 487 if (TransformNode* node = |
| 488 if (property_trees->IsInIdToIndexMap(PropertyTrees::TreeType::TRANSFORM, | 488 GetTransformTree().FindNodeFromOwningLayerId(id())) { |
| 489 id())) { | |
| 490 TransformTree& transform_tree = GetTransformTree(); | |
| 491 TransformNode* node = transform_tree.Node( | |
| 492 property_trees->layer_id_to_transform_node_index[id()]); | |
| 493 // A LayerImpl's own current state is insufficient for determining whether | 489 // A LayerImpl's own current state is insufficient for determining whether |
| 494 // it owns a TransformNode, since this depends on the state of the | 490 // it owns a TransformNode, since this depends on the state of the |
| 495 // corresponding Layer at the time of the last commit. For example, if | 491 // corresponding Layer at the time of the last commit. For example, if |
| 496 // |is_animated| is false, this might mean a transform animation just ticked | 492 // |is_animated| is false, this might mean a transform animation just ticked |
| 497 // past its finish point (so the LayerImpl still owns a TransformNode) or it | 493 // past its finish point (so the LayerImpl still owns a TransformNode) or it |
| 498 // might mean that a transform animation was removed during commit or | 494 // might mean that a transform animation was removed during commit or |
| 499 // activation (and, in that case, the LayerImpl will no longer own a | 495 // activation (and, in that case, the LayerImpl will no longer own a |
| 500 // TransformNode, unless it has non-animation-related reasons for owning a | 496 // TransformNode, unless it has non-animation-related reasons for owning a |
| 501 // node). | 497 // node). |
| 502 if (node->has_potential_animation != is_animated) { | 498 if (node->has_potential_animation != is_animated) { |
| 503 node->has_potential_animation = is_animated; | 499 node->has_potential_animation = is_animated; |
| 504 if (is_animated) { | 500 if (is_animated) { |
| 505 node->has_only_translation_animations = HasOnlyTranslationTransforms(); | 501 node->has_only_translation_animations = HasOnlyTranslationTransforms(); |
| 506 } else { | 502 } else { |
| 507 node->has_only_translation_animations = true; | 503 node->has_only_translation_animations = true; |
| 508 } | 504 } |
| 509 | 505 |
| 510 transform_tree.set_needs_update(true); | 506 GetTransformTree().set_needs_update(true); |
| 511 layer_tree_impl()->set_needs_update_draw_properties(); | 507 layer_tree_impl()->set_needs_update_draw_properties(); |
| 512 } | 508 } |
| 513 } | 509 } |
| 514 } | 510 } |
| 515 | 511 |
| 516 void LayerImpl::UpdatePropertyTreeForScrollingAndAnimationIfNeeded() { | 512 void LayerImpl::UpdatePropertyTreeForScrollingAndAnimationIfNeeded() { |
| 517 if (scrollable()) | 513 if (scrollable()) |
| 518 UpdatePropertyTreeScrollOffset(); | 514 UpdatePropertyTreeScrollOffset(); |
| 519 | 515 |
| 520 if (HasAnyAnimationTargetingProperty(TargetProperty::TRANSFORM)) { | 516 if (HasAnyAnimationTargetingProperty(TargetProperty::TRANSFORM)) { |
| 521 UpdatePropertyTreeTransformIsAnimated( | 517 UpdatePropertyTreeTransformIsAnimated( |
| 522 HasPotentiallyRunningTransformAnimation()); | 518 HasPotentiallyRunningTransformAnimation()); |
| 523 } | 519 } |
| 524 } | 520 } |
| 525 | 521 |
| 526 gfx::ScrollOffset LayerImpl::ScrollOffsetForAnimation() const { | 522 gfx::ScrollOffset LayerImpl::ScrollOffsetForAnimation() const { |
| 527 return CurrentScrollOffset(); | 523 return CurrentScrollOffset(); |
| 528 } | 524 } |
| 529 | 525 |
| 530 void LayerImpl::OnIsAnimatingChanged(const PropertyAnimationState& mask, | 526 void LayerImpl::OnIsAnimatingChanged(const PropertyAnimationState& mask, |
| 531 const PropertyAnimationState& state) { | 527 const PropertyAnimationState& state) { |
| 532 DCHECK(layer_tree_impl_); | 528 DCHECK(layer_tree_impl_); |
| 533 PropertyTrees* property_trees = GetPropertyTrees(); | |
| 534 | 529 |
| 535 TransformNode* transform_node = nullptr; | 530 TransformNode* transform_node = |
| 536 if (property_trees->IsInIdToIndexMap(PropertyTrees::TreeType::TRANSFORM, | 531 GetTransformTree().FindNodeFromOwningLayerId(id()); |
| 537 id())) { | 532 EffectNode* effect_node = GetEffectTree().FindNodeFromOwningLayerId(id()); |
| 538 transform_node = GetTransformTree().Node( | |
| 539 property_trees->layer_id_to_transform_node_index[id()]); | |
| 540 } | |
| 541 | |
| 542 EffectNode* effect_node = nullptr; | |
| 543 if (property_trees->IsInIdToIndexMap(PropertyTrees::TreeType::EFFECT, id())) { | |
| 544 effect_node = GetEffectTree().Node( | |
| 545 property_trees->layer_id_to_effect_node_index[id()]); | |
| 546 } | |
| 547 | |
| 548 for (int property = TargetProperty::FIRST_TARGET_PROPERTY; | 533 for (int property = TargetProperty::FIRST_TARGET_PROPERTY; |
| 549 property <= TargetProperty::LAST_TARGET_PROPERTY; ++property) { | 534 property <= TargetProperty::LAST_TARGET_PROPERTY; ++property) { |
| 550 switch (property) { | 535 switch (property) { |
| 551 case TargetProperty::TRANSFORM: | 536 case TargetProperty::TRANSFORM: |
| 552 if (transform_node) { | 537 if (transform_node) { |
| 553 if (mask.currently_running[property]) | 538 if (mask.currently_running[property]) |
| 554 transform_node->is_currently_animating = | 539 transform_node->is_currently_animating = |
| 555 state.currently_running[property]; | 540 state.currently_running[property]; |
| 556 if (mask.potentially_animating[property]) { | 541 if (mask.potentially_animating[property]) { |
| 557 UpdatePropertyTreeTransformIsAnimated( | 542 UpdatePropertyTreeTransformIsAnimated( |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 628 property_trees->SetOuterViewportContainerBoundsDelta(bounds_delta); | 613 property_trees->SetOuterViewportContainerBoundsDelta(bounds_delta); |
| 629 else if (this == layer_tree_impl()->InnerViewportScrollLayer()) | 614 else if (this == layer_tree_impl()->InnerViewportScrollLayer()) |
| 630 property_trees->SetInnerViewportScrollBoundsDelta(bounds_delta); | 615 property_trees->SetInnerViewportScrollBoundsDelta(bounds_delta); |
| 631 | 616 |
| 632 layer_tree_impl()->DidUpdateScrollState(id()); | 617 layer_tree_impl()->DidUpdateScrollState(id()); |
| 633 | 618 |
| 634 if (masks_to_bounds()) { | 619 if (masks_to_bounds()) { |
| 635 // If layer is clipping, then update the clip node using the new bounds. | 620 // If layer is clipping, then update the clip node using the new bounds. |
| 636 ClipNode* clip_node = property_trees->clip_tree.Node(clip_tree_index()); | 621 ClipNode* clip_node = property_trees->clip_tree.Node(clip_tree_index()); |
| 637 if (clip_node) { | 622 if (clip_node) { |
| 638 DCHECK(property_trees->IsInIdToIndexMap(PropertyTrees::TreeType::CLIP, | 623 DCHECK_EQ(clip_node, GetClipTree().FindNodeFromOwningLayerId(id())); |
| 639 id())); | |
| 640 clip_node->clip = gfx::RectF(gfx::PointF() + offset_to_transform_parent(), | 624 clip_node->clip = gfx::RectF(gfx::PointF() + offset_to_transform_parent(), |
| 641 gfx::SizeF(bounds())); | 625 gfx::SizeF(bounds())); |
| 642 property_trees->clip_tree.set_needs_update(true); | 626 property_trees->clip_tree.set_needs_update(true); |
| 643 } | 627 } |
| 644 property_trees->full_tree_damaged = true; | 628 property_trees->full_tree_damaged = true; |
| 645 layer_tree_impl()->set_needs_update_draw_properties(); | 629 layer_tree_impl()->set_needs_update_draw_properties(); |
| 646 } else { | 630 } else { |
| 647 NoteLayerPropertyChanged(); | 631 NoteLayerPropertyChanged(); |
| 648 } | 632 } |
| 649 } | 633 } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 693 | 677 |
| 694 void LayerImpl::SetMasksToBounds(bool masks_to_bounds) { | 678 void LayerImpl::SetMasksToBounds(bool masks_to_bounds) { |
| 695 masks_to_bounds_ = masks_to_bounds; | 679 masks_to_bounds_ = masks_to_bounds; |
| 696 } | 680 } |
| 697 | 681 |
| 698 void LayerImpl::SetContentsOpaque(bool opaque) { | 682 void LayerImpl::SetContentsOpaque(bool opaque) { |
| 699 contents_opaque_ = opaque; | 683 contents_opaque_ = opaque; |
| 700 } | 684 } |
| 701 | 685 |
| 702 float LayerImpl::Opacity() const { | 686 float LayerImpl::Opacity() const { |
| 703 PropertyTrees* property_trees = GetPropertyTrees(); | 687 if (EffectNode* node = GetEffectTree().FindNodeFromOwningLayerId(id())) |
| 704 if (!property_trees->IsInIdToIndexMap(PropertyTrees::TreeType::EFFECT, id())) | 688 return node->opacity; |
| 689 else |
| 705 return 1.f; | 690 return 1.f; |
| 706 EffectNode* node = | |
| 707 GetEffectTree().Node(property_trees->layer_id_to_effect_node_index[id()]); | |
| 708 return node->opacity; | |
| 709 } | 691 } |
| 710 | 692 |
| 711 const gfx::Transform& LayerImpl::Transform() const { | 693 const gfx::Transform& LayerImpl::Transform() const { |
| 712 PropertyTrees* property_trees = GetPropertyTrees(); | 694 DCHECK_NE(GetTransformTree().FindNodeFromOwningLayerId(id()), nullptr); |
| 713 DCHECK(property_trees->IsInIdToIndexMap(PropertyTrees::TreeType::TRANSFORM, | 695 return GetTransformTree().FindNodeFromOwningLayerId(id())->local; |
| 714 id())); | |
| 715 TransformNode* node = GetTransformTree().Node( | |
| 716 property_trees->layer_id_to_transform_node_index[id()]); | |
| 717 return node->local; | |
| 718 } | 696 } |
| 719 | 697 |
| 720 void LayerImpl::SetElementId(ElementId element_id) { | 698 void LayerImpl::SetElementId(ElementId element_id) { |
| 721 if (element_id == element_id_) | 699 if (element_id == element_id_) |
| 722 return; | 700 return; |
| 723 | 701 |
| 724 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("compositor-worker"), | 702 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("compositor-worker"), |
| 725 "LayerImpl::SetElementId", "element", | 703 "LayerImpl::SetElementId", "element", |
| 726 element_id.AsValue().release()); | 704 element_id.AsValue().release()); |
| 727 | 705 |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1059 | 1037 |
| 1060 gfx::Vector2dF transform_scales = MathUtil::ComputeTransform2dScaleComponents( | 1038 gfx::Vector2dF transform_scales = MathUtil::ComputeTransform2dScaleComponents( |
| 1061 ScreenSpaceTransform(), default_scale); | 1039 ScreenSpaceTransform(), default_scale); |
| 1062 return std::max(transform_scales.x(), transform_scales.y()); | 1040 return std::max(transform_scales.x(), transform_scales.y()); |
| 1063 } | 1041 } |
| 1064 | 1042 |
| 1065 PropertyTrees* LayerImpl::GetPropertyTrees() const { | 1043 PropertyTrees* LayerImpl::GetPropertyTrees() const { |
| 1066 return layer_tree_impl_->property_trees(); | 1044 return layer_tree_impl_->property_trees(); |
| 1067 } | 1045 } |
| 1068 | 1046 |
| 1047 ClipTree& LayerImpl::GetClipTree() const { |
| 1048 return GetPropertyTrees()->clip_tree; |
| 1049 } |
| 1050 |
| 1069 EffectTree& LayerImpl::GetEffectTree() const { | 1051 EffectTree& LayerImpl::GetEffectTree() const { |
| 1070 return GetPropertyTrees()->effect_tree; | 1052 return GetPropertyTrees()->effect_tree; |
| 1071 } | 1053 } |
| 1072 | 1054 |
| 1073 ScrollTree& LayerImpl::GetScrollTree() const { | 1055 ScrollTree& LayerImpl::GetScrollTree() const { |
| 1074 return GetPropertyTrees()->scroll_tree; | 1056 return GetPropertyTrees()->scroll_tree; |
| 1075 } | 1057 } |
| 1076 | 1058 |
| 1077 TransformTree& LayerImpl::GetTransformTree() const { | 1059 TransformTree& LayerImpl::GetTransformTree() const { |
| 1078 return GetPropertyTrees()->transform_tree; | 1060 return GetPropertyTrees()->transform_tree; |
| 1079 } | 1061 } |
| 1080 | 1062 |
| 1081 } // namespace cc | 1063 } // namespace cc |
| OLD | NEW |