| 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_for_testing_(false), | 80 force_render_surface_for_testing_(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 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 586 } | 585 } |
| 587 | 586 |
| 588 bool Layer::IsContainerForFixedPositionLayers() const { | 587 bool Layer::IsContainerForFixedPositionLayers() const { |
| 589 if (!transform_.IsIdentityOrTranslation()) | 588 if (!transform_.IsIdentityOrTranslation()) |
| 590 return true; | 589 return true; |
| 591 if (parent_ && !parent_->transform_.IsIdentityOrTranslation()) | 590 if (parent_ && !parent_->transform_.IsIdentityOrTranslation()) |
| 592 return true; | 591 return true; |
| 593 return is_container_for_fixed_position_layers_; | 592 return is_container_for_fixed_position_layers_; |
| 594 } | 593 } |
| 595 | 594 |
| 596 bool Are2dAxisAligned(const gfx::Transform& a, | 595 bool Are2dAxisAligned(const gfx::Transform& a, const gfx::Transform& b) { |
| 597 const gfx::Transform& b, | |
| 598 bool* is_invertible) { | |
| 599 if (a.IsScaleOrTranslation() && b.IsScaleOrTranslation()) { | 596 if (a.IsScaleOrTranslation() && b.IsScaleOrTranslation()) { |
| 600 *is_invertible = b.IsInvertible(); | |
| 601 return true; | 597 return true; |
| 602 } | 598 } |
| 603 | 599 |
| 604 gfx::Transform inverse(gfx::Transform::kSkipInitialization); | 600 gfx::Transform inverse(gfx::Transform::kSkipInitialization); |
| 605 *is_invertible = b.GetInverse(&inverse); | 601 if (b.GetInverse(&inverse)) { |
| 606 | 602 inverse *= a; |
| 607 inverse *= a; | 603 return inverse.Preserves2dAxisAlignment(); |
| 608 return inverse.Preserves2dAxisAlignment(); | 604 } else { |
| 605 // TODO(weiliangc): Should return false because b is not invertible. |
| 606 return a.Preserves2dAxisAlignment(); |
| 607 } |
| 609 } | 608 } |
| 610 | 609 |
| 611 void Layer::SetTransform(const gfx::Transform& transform) { | 610 void Layer::SetTransform(const gfx::Transform& transform) { |
| 612 DCHECK(IsPropertyChangeAllowed()); | 611 DCHECK(IsPropertyChangeAllowed()); |
| 613 if (transform_ == transform) | 612 if (transform_ == transform) |
| 614 return; | 613 return; |
| 615 | 614 |
| 616 SetSubtreePropertyChanged(); | 615 SetSubtreePropertyChanged(); |
| 617 if (layer_tree_host_) { | 616 if (layer_tree_host_) { |
| 618 if (TransformNode* transform_node = | 617 if (TransformNode* transform_node = |
| 619 layer_tree_host_->property_trees()->transform_tree.Node( | 618 layer_tree_host_->property_trees()->transform_tree.Node( |
| 620 transform_tree_index())) { | 619 transform_tree_index())) { |
| 621 if (transform_node->owner_id == id()) { | 620 if (transform_node->owner_id == id()) { |
| 622 // 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 |
| 623 // 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 |
| 624 // align with respect to one another. | 623 // align with respect to one another. |
| 625 bool invertible = false; | |
| 626 bool preserves_2d_axis_alignment = | 624 bool preserves_2d_axis_alignment = |
| 627 Are2dAxisAligned(transform_, transform, &invertible); | 625 Are2dAxisAligned(transform_, transform); |
| 628 transform_node->data.local = transform; | 626 transform_node->data.local = transform; |
| 629 transform_node->data.needs_local_transform_update = true; | 627 transform_node->data.needs_local_transform_update = true; |
| 630 transform_node->data.transform_changed = true; | 628 transform_node->data.transform_changed = true; |
| 631 layer_tree_host_->property_trees()->transform_tree.set_needs_update( | 629 layer_tree_host_->property_trees()->transform_tree.set_needs_update( |
| 632 true); | 630 true); |
| 633 if (preserves_2d_axis_alignment) | 631 if (preserves_2d_axis_alignment) |
| 634 SetNeedsCommitNoRebuild(); | 632 SetNeedsCommitNoRebuild(); |
| 635 else | 633 else |
| 636 SetNeedsCommit(); | 634 SetNeedsCommit(); |
| 637 transform_ = transform; | 635 transform_ = transform; |
| 638 transform_is_invertible_ = invertible; | |
| 639 return; | 636 return; |
| 640 } | 637 } |
| 641 } | 638 } |
| 642 } | 639 } |
| 643 | 640 |
| 644 transform_ = transform; | 641 transform_ = transform; |
| 645 transform_is_invertible_ = transform.IsInvertible(); | |
| 646 | 642 |
| 647 SetNeedsCommit(); | 643 SetNeedsCommit(); |
| 648 } | 644 } |
| 649 | 645 |
| 650 void Layer::SetTransformOrigin(const gfx::Point3F& transform_origin) { | 646 void Layer::SetTransformOrigin(const gfx::Point3F& transform_origin) { |
| 651 DCHECK(IsPropertyChangeAllowed()); | 647 DCHECK(IsPropertyChangeAllowed()); |
| 652 if (transform_origin_ == transform_origin) | 648 if (transform_origin_ == transform_origin) |
| 653 return; | 649 return; |
| 654 transform_origin_ = transform_origin; | 650 transform_origin_ = transform_origin; |
| 655 | 651 |
| (...skipping 718 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1374 PointFToProto(position_, base->mutable_position()); | 1370 PointFToProto(position_, base->mutable_position()); |
| 1375 base->set_is_container_for_fixed_position_layers( | 1371 base->set_is_container_for_fixed_position_layers( |
| 1376 is_container_for_fixed_position_layers_); | 1372 is_container_for_fixed_position_layers_); |
| 1377 position_constraint_.ToProtobuf(base->mutable_position_constraint()); | 1373 position_constraint_.ToProtobuf(base->mutable_position_constraint()); |
| 1378 base->set_should_flatten_transform(should_flatten_transform_); | 1374 base->set_should_flatten_transform(should_flatten_transform_); |
| 1379 base->set_should_flatten_transform_from_property_tree( | 1375 base->set_should_flatten_transform_from_property_tree( |
| 1380 should_flatten_transform_from_property_tree_); | 1376 should_flatten_transform_from_property_tree_); |
| 1381 base->set_draw_blend_mode(SkXfermodeModeToProto(draw_blend_mode_)); | 1377 base->set_draw_blend_mode(SkXfermodeModeToProto(draw_blend_mode_)); |
| 1382 base->set_use_parent_backface_visibility(use_parent_backface_visibility_); | 1378 base->set_use_parent_backface_visibility(use_parent_backface_visibility_); |
| 1383 TransformToProto(transform_, base->mutable_transform()); | 1379 TransformToProto(transform_, base->mutable_transform()); |
| 1384 base->set_transform_is_invertible(transform_is_invertible_); | |
| 1385 base->set_sorting_context_id(sorting_context_id_); | 1380 base->set_sorting_context_id(sorting_context_id_); |
| 1386 base->set_num_descendants_that_draw_content( | 1381 base->set_num_descendants_that_draw_content( |
| 1387 num_descendants_that_draw_content_); | 1382 num_descendants_that_draw_content_); |
| 1388 | 1383 |
| 1389 base->set_scroll_clip_layer_id(scroll_clip_layer_id_); | 1384 base->set_scroll_clip_layer_id(scroll_clip_layer_id_); |
| 1390 base->set_user_scrollable_horizontal(user_scrollable_horizontal_); | 1385 base->set_user_scrollable_horizontal(user_scrollable_horizontal_); |
| 1391 base->set_user_scrollable_vertical(user_scrollable_vertical_); | 1386 base->set_user_scrollable_vertical(user_scrollable_vertical_); |
| 1392 | 1387 |
| 1393 int scroll_parent_id = scroll_parent_ ? scroll_parent_->id() : INVALID_ID; | 1388 int scroll_parent_id = scroll_parent_ ? scroll_parent_->id() : INVALID_ID; |
| 1394 base->set_scroll_parent_id(scroll_parent_id); | 1389 base->set_scroll_parent_id(scroll_parent_id); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1454 position_ = ProtoToPointF(base.position()); | 1449 position_ = ProtoToPointF(base.position()); |
| 1455 is_container_for_fixed_position_layers_ = | 1450 is_container_for_fixed_position_layers_ = |
| 1456 base.is_container_for_fixed_position_layers(); | 1451 base.is_container_for_fixed_position_layers(); |
| 1457 position_constraint_.FromProtobuf(base.position_constraint()); | 1452 position_constraint_.FromProtobuf(base.position_constraint()); |
| 1458 should_flatten_transform_ = base.should_flatten_transform(); | 1453 should_flatten_transform_ = base.should_flatten_transform(); |
| 1459 should_flatten_transform_from_property_tree_ = | 1454 should_flatten_transform_from_property_tree_ = |
| 1460 base.should_flatten_transform_from_property_tree(); | 1455 base.should_flatten_transform_from_property_tree(); |
| 1461 draw_blend_mode_ = SkXfermodeModeFromProto(base.draw_blend_mode()); | 1456 draw_blend_mode_ = SkXfermodeModeFromProto(base.draw_blend_mode()); |
| 1462 use_parent_backface_visibility_ = base.use_parent_backface_visibility(); | 1457 use_parent_backface_visibility_ = base.use_parent_backface_visibility(); |
| 1463 transform_ = ProtoToTransform(base.transform()); | 1458 transform_ = ProtoToTransform(base.transform()); |
| 1464 transform_is_invertible_ = base.transform_is_invertible(); | |
| 1465 sorting_context_id_ = base.sorting_context_id(); | 1459 sorting_context_id_ = base.sorting_context_id(); |
| 1466 num_descendants_that_draw_content_ = base.num_descendants_that_draw_content(); | 1460 num_descendants_that_draw_content_ = base.num_descendants_that_draw_content(); |
| 1467 | 1461 |
| 1468 scroll_clip_layer_id_ = base.scroll_clip_layer_id(); | 1462 scroll_clip_layer_id_ = base.scroll_clip_layer_id(); |
| 1469 user_scrollable_horizontal_ = base.user_scrollable_horizontal(); | 1463 user_scrollable_horizontal_ = base.user_scrollable_horizontal(); |
| 1470 user_scrollable_vertical_ = base.user_scrollable_vertical(); | 1464 user_scrollable_vertical_ = base.user_scrollable_vertical(); |
| 1471 | 1465 |
| 1472 scroll_parent_ = base.scroll_parent_id() == INVALID_ID | 1466 scroll_parent_ = base.scroll_parent_id() == INVALID_ID |
| 1473 ? nullptr | 1467 ? nullptr |
| 1474 : layer_tree_host_->LayerById(base.scroll_parent_id()); | 1468 : layer_tree_host_->LayerById(base.scroll_parent_id()); |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1609 layer_tree_host_->property_trees()->effect_tree.set_needs_update(true); | 1603 layer_tree_host_->property_trees()->effect_tree.set_needs_update(true); |
| 1610 } | 1604 } |
| 1611 } | 1605 } |
| 1612 } | 1606 } |
| 1613 } | 1607 } |
| 1614 | 1608 |
| 1615 void Layer::OnTransformAnimated(const gfx::Transform& transform) { | 1609 void Layer::OnTransformAnimated(const gfx::Transform& transform) { |
| 1616 if (transform_ == transform) | 1610 if (transform_ == transform) |
| 1617 return; | 1611 return; |
| 1618 transform_ = transform; | 1612 transform_ = transform; |
| 1619 transform_is_invertible_ = transform.IsInvertible(); | |
| 1620 // Changing the transform may change the visible part of this layer, so a new | 1613 // Changing the transform may change the visible part of this layer, so a new |
| 1621 // recording may be needed. | 1614 // recording may be needed. |
| 1622 SetNeedsUpdate(); | 1615 SetNeedsUpdate(); |
| 1623 if (layer_tree_host_) { | 1616 if (layer_tree_host_) { |
| 1624 if (TransformNode* node = | 1617 if (TransformNode* node = |
| 1625 layer_tree_host_->property_trees()->transform_tree.Node( | 1618 layer_tree_host_->property_trees()->transform_tree.Node( |
| 1626 transform_tree_index())) { | 1619 transform_tree_index())) { |
| 1627 if (node->owner_id == id()) { | 1620 if (node->owner_id == id()) { |
| 1628 node->data.local = transform; | 1621 node->data.local = transform; |
| 1629 node->data.needs_local_transform_update = true; | 1622 node->data.needs_local_transform_update = true; |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1760 ->data.num_copy_requests_in_subtree; | 1753 ->data.num_copy_requests_in_subtree; |
| 1761 } | 1754 } |
| 1762 | 1755 |
| 1763 gfx::Transform Layer::screen_space_transform() const { | 1756 gfx::Transform Layer::screen_space_transform() const { |
| 1764 DCHECK_NE(transform_tree_index_, -1); | 1757 DCHECK_NE(transform_tree_index_, -1); |
| 1765 return draw_property_utils::ScreenSpaceTransform( | 1758 return draw_property_utils::ScreenSpaceTransform( |
| 1766 this, layer_tree_host_->property_trees()->transform_tree); | 1759 this, layer_tree_host_->property_trees()->transform_tree); |
| 1767 } | 1760 } |
| 1768 | 1761 |
| 1769 } // namespace cc | 1762 } // namespace cc |
| OLD | NEW |