Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2010 The Chromium Authors. All rights reserved. | 1 // Copyright 2010 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.h" | 5 #include "cc/layers/layer.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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 71 draws_content_(false), | 71 draws_content_(false), |
| 72 hide_layer_and_subtree_(false), | 72 hide_layer_and_subtree_(false), |
| 73 masks_to_bounds_(false), | 73 masks_to_bounds_(false), |
| 74 contents_opaque_(false), | 74 contents_opaque_(false), |
| 75 double_sided_(true), | 75 double_sided_(true), |
| 76 should_flatten_transform_(true), | 76 should_flatten_transform_(true), |
| 77 use_parent_backface_visibility_(false), | 77 use_parent_backface_visibility_(false), |
| 78 use_local_transform_for_backface_visibility_(false), | 78 use_local_transform_for_backface_visibility_(false), |
| 79 should_check_backface_visibility_(false), | 79 should_check_backface_visibility_(false), |
| 80 force_render_surface_(false), | 80 force_render_surface_(false), |
| 81 transform_is_invertible_(true), | |
| 82 has_render_surface_(false), | 81 has_render_surface_(false), |
| 83 subtree_property_changed_(false), | 82 subtree_property_changed_(false), |
| 84 background_color_(0), | 83 background_color_(0), |
| 85 safe_opaque_background_color_(0), | 84 safe_opaque_background_color_(0), |
| 86 opacity_(1.f), | 85 opacity_(1.f), |
| 87 blend_mode_(SkXfermode::kSrcOver_Mode), | 86 blend_mode_(SkXfermode::kSrcOver_Mode), |
| 88 draw_blend_mode_(SkXfermode::kSrcOver_Mode), | 87 draw_blend_mode_(SkXfermode::kSrcOver_Mode), |
| 89 scroll_parent_(nullptr), | 88 scroll_parent_(nullptr), |
| 90 clip_parent_(nullptr), | 89 clip_parent_(nullptr), |
| 91 replica_layer_(nullptr), | 90 replica_layer_(nullptr), |
| (...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 587 } | 586 } |
| 588 | 587 |
| 589 bool Layer::IsContainerForFixedPositionLayers() const { | 588 bool Layer::IsContainerForFixedPositionLayers() const { |
| 590 if (!transform_.IsIdentityOrTranslation()) | 589 if (!transform_.IsIdentityOrTranslation()) |
| 591 return true; | 590 return true; |
| 592 if (parent_ && !parent_->transform_.IsIdentityOrTranslation()) | 591 if (parent_ && !parent_->transform_.IsIdentityOrTranslation()) |
| 593 return true; | 592 return true; |
| 594 return is_container_for_fixed_position_layers_; | 593 return is_container_for_fixed_position_layers_; |
| 595 } | 594 } |
| 596 | 595 |
| 597 bool Are2dAxisAligned(const gfx::Transform& a, | 596 bool Are2dAxisAligned(const gfx::Transform& a, const gfx::Transform& b) { |
| 598 const gfx::Transform& b, | |
| 599 bool* is_invertible) { | |
| 600 if (a.IsScaleOrTranslation() && b.IsScaleOrTranslation()) { | 597 if (a.IsScaleOrTranslation() && b.IsScaleOrTranslation()) { |
| 601 *is_invertible = b.IsInvertible(); | |
| 602 return true; | 598 return true; |
| 603 } | 599 } |
| 604 | 600 |
| 605 gfx::Transform inverse(gfx::Transform::kSkipInitialization); | 601 gfx::Transform inverse(gfx::Transform::kSkipInitialization); |
| 606 *is_invertible = b.GetInverse(&inverse); | 602 if (b.GetInverse(&inverse)) { |
| 607 | 603 inverse *= a; |
| 608 inverse *= a; | 604 return inverse.Preserves2dAxisAlignment(); |
| 609 return inverse.Preserves2dAxisAlignment(); | 605 } else { |
| 606 return a.Preserves2dAxisAlignment(); | |
|
ajuma
2016/04/21 17:20:10
It seems like we'd want to return false here, sinc
| |
| 607 } | |
| 610 } | 608 } |
| 611 | 609 |
| 612 void Layer::SetTransform(const gfx::Transform& transform) { | 610 void Layer::SetTransform(const gfx::Transform& transform) { |
| 613 DCHECK(IsPropertyChangeAllowed()); | 611 DCHECK(IsPropertyChangeAllowed()); |
| 614 if (transform_ == transform) | 612 if (transform_ == transform) |
| 615 return; | 613 return; |
| 616 | 614 |
| 617 SetSubtreePropertyChanged(); | 615 SetSubtreePropertyChanged(); |
| 618 if (layer_tree_host_) { | 616 if (layer_tree_host_) { |
| 619 if (TransformNode* transform_node = | 617 if (TransformNode* transform_node = |
| 620 layer_tree_host_->property_trees()->transform_tree.Node( | 618 layer_tree_host_->property_trees()->transform_tree.Node( |
| 621 transform_tree_index())) { | 619 transform_tree_index())) { |
| 622 if (transform_node->owner_id == id()) { | 620 if (transform_node->owner_id == id()) { |
| 623 // We need to trigger a rebuild if we could have affected 2d axis | 621 // We need to trigger a rebuild if we could have affected 2d axis |
| 624 // alignment. We'll check to see if transform and transform_ are axis | 622 // alignment. We'll check to see if transform and transform_ are axis |
| 625 // align with respect to one another. | 623 // align with respect to one another. |
| 626 bool invertible = false; | |
| 627 bool preserves_2d_axis_alignment = | 624 bool preserves_2d_axis_alignment = |
| 628 Are2dAxisAligned(transform_, transform, &invertible); | 625 Are2dAxisAligned(transform_, transform); |
| 629 transform_node->data.local = transform; | 626 transform_node->data.local = transform; |
| 630 transform_node->data.needs_local_transform_update = true; | 627 transform_node->data.needs_local_transform_update = true; |
| 631 transform_node->data.transform_changed = true; | 628 transform_node->data.transform_changed = true; |
| 632 layer_tree_host_->property_trees()->transform_tree.set_needs_update( | 629 layer_tree_host_->property_trees()->transform_tree.set_needs_update( |
| 633 true); | 630 true); |
| 634 if (preserves_2d_axis_alignment) | 631 if (preserves_2d_axis_alignment) |
| 635 SetNeedsCommitNoRebuild(); | 632 SetNeedsCommitNoRebuild(); |
| 636 else | 633 else |
| 637 SetNeedsCommit(); | 634 SetNeedsCommit(); |
| 638 transform_ = transform; | 635 transform_ = transform; |
| 639 transform_is_invertible_ = invertible; | |
| 640 return; | 636 return; |
| 641 } | 637 } |
| 642 } | 638 } |
| 643 } | 639 } |
| 644 | 640 |
| 645 transform_ = transform; | 641 transform_ = transform; |
| 646 transform_is_invertible_ = transform.IsInvertible(); | |
| 647 | 642 |
| 648 SetNeedsCommit(); | 643 SetNeedsCommit(); |
| 649 } | 644 } |
| 650 | 645 |
| 651 void Layer::SetTransformOrigin(const gfx::Point3F& transform_origin) { | 646 void Layer::SetTransformOrigin(const gfx::Point3F& transform_origin) { |
| 652 DCHECK(IsPropertyChangeAllowed()); | 647 DCHECK(IsPropertyChangeAllowed()); |
| 653 if (transform_origin_ == transform_origin) | 648 if (transform_origin_ == transform_origin) |
| 654 return; | 649 return; |
| 655 transform_origin_ = transform_origin; | 650 transform_origin_ = transform_origin; |
| 656 | 651 |
| (...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1168 layer->SetPositionConstraint(position_constraint_); | 1163 layer->SetPositionConstraint(position_constraint_); |
| 1169 layer->SetShouldFlattenTransform(should_flatten_transform_); | 1164 layer->SetShouldFlattenTransform(should_flatten_transform_); |
| 1170 layer->set_should_flatten_transform_from_property_tree( | 1165 layer->set_should_flatten_transform_from_property_tree( |
| 1171 should_flatten_transform_from_property_tree_); | 1166 should_flatten_transform_from_property_tree_); |
| 1172 layer->set_draw_blend_mode(draw_blend_mode_); | 1167 layer->set_draw_blend_mode(draw_blend_mode_); |
| 1173 layer->SetUseParentBackfaceVisibility(use_parent_backface_visibility_); | 1168 layer->SetUseParentBackfaceVisibility(use_parent_backface_visibility_); |
| 1174 layer->SetUseLocalTransformForBackfaceVisibility( | 1169 layer->SetUseLocalTransformForBackfaceVisibility( |
| 1175 use_local_transform_for_backface_visibility_); | 1170 use_local_transform_for_backface_visibility_); |
| 1176 layer->SetShouldCheckBackfaceVisibility(should_check_backface_visibility_); | 1171 layer->SetShouldCheckBackfaceVisibility(should_check_backface_visibility_); |
| 1177 if (!layer->TransformIsAnimatingOnImplOnly() && !TransformIsAnimating()) | 1172 if (!layer->TransformIsAnimatingOnImplOnly() && !TransformIsAnimating()) |
| 1178 layer->SetTransformAndInvertibility(transform_, transform_is_invertible_); | 1173 layer->SetTransform(transform_); |
| 1179 DCHECK(!(TransformIsAnimating() && layer->TransformIsAnimatingOnImplOnly())); | 1174 DCHECK(!(TransformIsAnimating() && layer->TransformIsAnimatingOnImplOnly())); |
| 1180 layer->Set3dSortingContextId(sorting_context_id_); | 1175 layer->Set3dSortingContextId(sorting_context_id_); |
| 1181 layer->SetNumDescendantsThatDrawContent(num_descendants_that_draw_content_); | 1176 layer->SetNumDescendantsThatDrawContent(num_descendants_that_draw_content_); |
| 1182 | 1177 |
| 1183 layer->SetScrollClipLayer(scroll_clip_layer_id_); | 1178 layer->SetScrollClipLayer(scroll_clip_layer_id_); |
| 1184 layer->set_user_scrollable_horizontal(user_scrollable_horizontal_); | 1179 layer->set_user_scrollable_horizontal(user_scrollable_horizontal_); |
| 1185 layer->set_user_scrollable_vertical(user_scrollable_vertical_); | 1180 layer->set_user_scrollable_vertical(user_scrollable_vertical_); |
| 1186 layer->SetElementId(element_id_); | 1181 layer->SetElementId(element_id_); |
| 1187 layer->SetMutableProperties(mutable_properties_); | 1182 layer->SetMutableProperties(mutable_properties_); |
| 1188 | 1183 |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1435 PointFToProto(position_, base->mutable_position()); | 1430 PointFToProto(position_, base->mutable_position()); |
| 1436 base->set_is_container_for_fixed_position_layers( | 1431 base->set_is_container_for_fixed_position_layers( |
| 1437 is_container_for_fixed_position_layers_); | 1432 is_container_for_fixed_position_layers_); |
| 1438 position_constraint_.ToProtobuf(base->mutable_position_constraint()); | 1433 position_constraint_.ToProtobuf(base->mutable_position_constraint()); |
| 1439 base->set_should_flatten_transform(should_flatten_transform_); | 1434 base->set_should_flatten_transform(should_flatten_transform_); |
| 1440 base->set_should_flatten_transform_from_property_tree( | 1435 base->set_should_flatten_transform_from_property_tree( |
| 1441 should_flatten_transform_from_property_tree_); | 1436 should_flatten_transform_from_property_tree_); |
| 1442 base->set_draw_blend_mode(SkXfermodeModeToProto(draw_blend_mode_)); | 1437 base->set_draw_blend_mode(SkXfermodeModeToProto(draw_blend_mode_)); |
| 1443 base->set_use_parent_backface_visibility(use_parent_backface_visibility_); | 1438 base->set_use_parent_backface_visibility(use_parent_backface_visibility_); |
| 1444 TransformToProto(transform_, base->mutable_transform()); | 1439 TransformToProto(transform_, base->mutable_transform()); |
| 1445 base->set_transform_is_invertible(transform_is_invertible_); | |
| 1446 base->set_sorting_context_id(sorting_context_id_); | 1440 base->set_sorting_context_id(sorting_context_id_); |
| 1447 base->set_num_descendants_that_draw_content( | 1441 base->set_num_descendants_that_draw_content( |
| 1448 num_descendants_that_draw_content_); | 1442 num_descendants_that_draw_content_); |
| 1449 | 1443 |
| 1450 base->set_scroll_clip_layer_id(scroll_clip_layer_id_); | 1444 base->set_scroll_clip_layer_id(scroll_clip_layer_id_); |
| 1451 base->set_user_scrollable_horizontal(user_scrollable_horizontal_); | 1445 base->set_user_scrollable_horizontal(user_scrollable_horizontal_); |
| 1452 base->set_user_scrollable_vertical(user_scrollable_vertical_); | 1446 base->set_user_scrollable_vertical(user_scrollable_vertical_); |
| 1453 | 1447 |
| 1454 int scroll_parent_id = scroll_parent_ ? scroll_parent_->id() : INVALID_ID; | 1448 int scroll_parent_id = scroll_parent_ ? scroll_parent_->id() : INVALID_ID; |
| 1455 base->set_scroll_parent_id(scroll_parent_id); | 1449 base->set_scroll_parent_id(scroll_parent_id); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1517 position_ = ProtoToPointF(base.position()); | 1511 position_ = ProtoToPointF(base.position()); |
| 1518 is_container_for_fixed_position_layers_ = | 1512 is_container_for_fixed_position_layers_ = |
| 1519 base.is_container_for_fixed_position_layers(); | 1513 base.is_container_for_fixed_position_layers(); |
| 1520 position_constraint_.FromProtobuf(base.position_constraint()); | 1514 position_constraint_.FromProtobuf(base.position_constraint()); |
| 1521 should_flatten_transform_ = base.should_flatten_transform(); | 1515 should_flatten_transform_ = base.should_flatten_transform(); |
| 1522 should_flatten_transform_from_property_tree_ = | 1516 should_flatten_transform_from_property_tree_ = |
| 1523 base.should_flatten_transform_from_property_tree(); | 1517 base.should_flatten_transform_from_property_tree(); |
| 1524 draw_blend_mode_ = SkXfermodeModeFromProto(base.draw_blend_mode()); | 1518 draw_blend_mode_ = SkXfermodeModeFromProto(base.draw_blend_mode()); |
| 1525 use_parent_backface_visibility_ = base.use_parent_backface_visibility(); | 1519 use_parent_backface_visibility_ = base.use_parent_backface_visibility(); |
| 1526 transform_ = ProtoToTransform(base.transform()); | 1520 transform_ = ProtoToTransform(base.transform()); |
| 1527 transform_is_invertible_ = base.transform_is_invertible(); | |
| 1528 sorting_context_id_ = base.sorting_context_id(); | 1521 sorting_context_id_ = base.sorting_context_id(); |
| 1529 num_descendants_that_draw_content_ = base.num_descendants_that_draw_content(); | 1522 num_descendants_that_draw_content_ = base.num_descendants_that_draw_content(); |
| 1530 | 1523 |
| 1531 scroll_clip_layer_id_ = base.scroll_clip_layer_id(); | 1524 scroll_clip_layer_id_ = base.scroll_clip_layer_id(); |
| 1532 user_scrollable_horizontal_ = base.user_scrollable_horizontal(); | 1525 user_scrollable_horizontal_ = base.user_scrollable_horizontal(); |
| 1533 user_scrollable_vertical_ = base.user_scrollable_vertical(); | 1526 user_scrollable_vertical_ = base.user_scrollable_vertical(); |
| 1534 | 1527 |
| 1535 scroll_parent_ = base.scroll_parent_id() == INVALID_ID | 1528 scroll_parent_ = base.scroll_parent_id() == INVALID_ID |
| 1536 ? nullptr | 1529 ? nullptr |
| 1537 : layer_tree_host_->LayerById(base.scroll_parent_id()); | 1530 : layer_tree_host_->LayerById(base.scroll_parent_id()); |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1677 layer_tree_host_->property_trees()->effect_tree.set_needs_update(true); | 1670 layer_tree_host_->property_trees()->effect_tree.set_needs_update(true); |
| 1678 } | 1671 } |
| 1679 } | 1672 } |
| 1680 } | 1673 } |
| 1681 } | 1674 } |
| 1682 | 1675 |
| 1683 void Layer::OnTransformAnimated(const gfx::Transform& transform) { | 1676 void Layer::OnTransformAnimated(const gfx::Transform& transform) { |
| 1684 if (transform_ == transform) | 1677 if (transform_ == transform) |
| 1685 return; | 1678 return; |
| 1686 transform_ = transform; | 1679 transform_ = transform; |
| 1687 transform_is_invertible_ = transform.IsInvertible(); | |
| 1688 // Changing the transform may change the visible part of this layer, so a new | 1680 // Changing the transform may change the visible part of this layer, so a new |
| 1689 // recording may be needed. | 1681 // recording may be needed. |
| 1690 SetNeedsUpdate(); | 1682 SetNeedsUpdate(); |
| 1691 if (layer_tree_host_) { | 1683 if (layer_tree_host_) { |
| 1692 if (TransformNode* node = | 1684 if (TransformNode* node = |
| 1693 layer_tree_host_->property_trees()->transform_tree.Node( | 1685 layer_tree_host_->property_trees()->transform_tree.Node( |
| 1694 transform_tree_index())) { | 1686 transform_tree_index())) { |
| 1695 if (node->owner_id == id()) { | 1687 if (node->owner_id == id()) { |
| 1696 node->data.local = transform; | 1688 node->data.local = transform; |
| 1697 node->data.needs_local_transform_update = true; | 1689 node->data.needs_local_transform_update = true; |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1838 ->data.num_copy_requests_in_subtree; | 1830 ->data.num_copy_requests_in_subtree; |
| 1839 } | 1831 } |
| 1840 | 1832 |
| 1841 gfx::Transform Layer::screen_space_transform() const { | 1833 gfx::Transform Layer::screen_space_transform() const { |
| 1842 DCHECK_NE(transform_tree_index_, -1); | 1834 DCHECK_NE(transform_tree_index_, -1); |
| 1843 return draw_property_utils::ScreenSpaceTransform( | 1835 return draw_property_utils::ScreenSpaceTransform( |
| 1844 this, layer_tree_host_->property_trees()->transform_tree); | 1836 this, layer_tree_host_->property_trees()->transform_tree); |
| 1845 } | 1837 } |
| 1846 | 1838 |
| 1847 } // namespace cc | 1839 } // namespace cc |
| OLD | NEW |