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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 | 45 |
46 base::StaticAtomicSequenceNumber g_next_layer_id; | 46 base::StaticAtomicSequenceNumber g_next_layer_id; |
47 | 47 |
48 scoped_refptr<Layer> Layer::Create(const LayerSettings& settings) { | 48 scoped_refptr<Layer> Layer::Create(const LayerSettings& settings) { |
49 return make_scoped_refptr(new Layer(settings)); | 49 return make_scoped_refptr(new Layer(settings)); |
50 } | 50 } |
51 | 51 |
52 Layer::Layer(const LayerSettings& settings) | 52 Layer::Layer(const LayerSettings& settings) |
53 : needs_push_properties_(false), | 53 : needs_push_properties_(false), |
54 num_dependents_need_push_properties_(0), | 54 num_dependents_need_push_properties_(0), |
55 stacking_order_changed_(false), | |
56 // Layer IDs start from 1. | 55 // Layer IDs start from 1. |
57 layer_id_(g_next_layer_id.GetNext() + 1), | 56 layer_id_(g_next_layer_id.GetNext() + 1), |
58 ignore_set_needs_commit_(false), | 57 ignore_set_needs_commit_(false), |
59 sorting_context_id_(0), | 58 sorting_context_id_(0), |
60 parent_(nullptr), | 59 parent_(nullptr), |
61 layer_tree_host_(nullptr), | 60 layer_tree_host_(nullptr), |
62 scroll_clip_layer_id_(INVALID_ID), | 61 scroll_clip_layer_id_(INVALID_ID), |
63 num_descendants_that_draw_content_(0), | 62 num_descendants_that_draw_content_(0), |
64 transform_tree_index_(-1), | 63 transform_tree_index_(-1), |
65 effect_tree_index_(-1), | 64 effect_tree_index_(-1), |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 void Layer::AddChild(scoped_refptr<Layer> child) { | 283 void Layer::AddChild(scoped_refptr<Layer> child) { |
285 InsertChild(child, children_.size()); | 284 InsertChild(child, children_.size()); |
286 } | 285 } |
287 | 286 |
288 void Layer::InsertChild(scoped_refptr<Layer> child, size_t index) { | 287 void Layer::InsertChild(scoped_refptr<Layer> child, size_t index) { |
289 DCHECK(IsPropertyChangeAllowed()); | 288 DCHECK(IsPropertyChangeAllowed()); |
290 child->RemoveFromParent(); | 289 child->RemoveFromParent(); |
291 AddDrawableDescendants(child->NumDescendantsThatDrawContent() + | 290 AddDrawableDescendants(child->NumDescendantsThatDrawContent() + |
292 (child->DrawsContent() ? 1 : 0)); | 291 (child->DrawsContent() ? 1 : 0)); |
293 child->SetParent(this); | 292 child->SetParent(this); |
294 child->stacking_order_changed_ = true; | 293 child->SetSubtreePropertyChanged(); |
295 | 294 |
296 index = std::min(index, children_.size()); | 295 index = std::min(index, children_.size()); |
297 children_.insert(children_.begin() + index, child); | 296 children_.insert(children_.begin() + index, child); |
298 SetNeedsFullTreeSync(); | 297 SetNeedsFullTreeSync(); |
299 } | 298 } |
300 | 299 |
301 void Layer::RemoveFromParent() { | 300 void Layer::RemoveFromParent() { |
302 DCHECK(IsPropertyChangeAllowed()); | 301 DCHECK(IsPropertyChangeAllowed()); |
303 if (parent_) | 302 if (parent_) |
304 parent_->RemoveChildOrDependent(this); | 303 parent_->RemoveChildOrDependent(this); |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
677 | 676 |
678 inverse *= a; | 677 inverse *= a; |
679 return inverse.Preserves2dAxisAlignment(); | 678 return inverse.Preserves2dAxisAlignment(); |
680 } | 679 } |
681 | 680 |
682 void Layer::SetTransform(const gfx::Transform& transform) { | 681 void Layer::SetTransform(const gfx::Transform& transform) { |
683 DCHECK(IsPropertyChangeAllowed()); | 682 DCHECK(IsPropertyChangeAllowed()); |
684 if (transform_ == transform) | 683 if (transform_ == transform) |
685 return; | 684 return; |
686 | 685 |
| 686 SetSubtreePropertyChanged(); |
687 if (layer_tree_host_) { | 687 if (layer_tree_host_) { |
688 if (TransformNode* transform_node = | 688 if (TransformNode* transform_node = |
689 layer_tree_host_->property_trees()->transform_tree.Node( | 689 layer_tree_host_->property_trees()->transform_tree.Node( |
690 transform_tree_index())) { | 690 transform_tree_index())) { |
691 if (transform_node->owner_id == id()) { | 691 if (transform_node->owner_id == id()) { |
692 // We need to trigger a rebuild if we could have affected 2d axis | 692 // We need to trigger a rebuild if we could have affected 2d axis |
693 // alignment. We'll check to see if transform and transform_ are axis | 693 // alignment. We'll check to see if transform and transform_ are axis |
694 // align with respect to one another. | 694 // align with respect to one another. |
695 bool invertible = false; | 695 bool invertible = false; |
696 bool preserves_2d_axis_alignment = | 696 bool preserves_2d_axis_alignment = |
697 Are2dAxisAligned(transform_, transform, &invertible); | 697 Are2dAxisAligned(transform_, transform, &invertible); |
698 transform_node->data.local = transform; | 698 transform_node->data.local = transform; |
699 transform_node->data.needs_local_transform_update = true; | 699 transform_node->data.needs_local_transform_update = true; |
| 700 transform_node->data.transform_changed = true; |
700 layer_tree_host_->property_trees()->transform_tree.set_needs_update( | 701 layer_tree_host_->property_trees()->transform_tree.set_needs_update( |
701 true); | 702 true); |
702 if (preserves_2d_axis_alignment) | 703 if (preserves_2d_axis_alignment) |
703 SetNeedsCommitNoRebuild(); | 704 SetNeedsCommitNoRebuild(); |
704 else | 705 else |
705 SetNeedsCommit(); | 706 SetNeedsCommit(); |
706 transform_ = transform; | 707 transform_ = transform; |
707 transform_is_invertible_ = invertible; | 708 transform_is_invertible_ = invertible; |
708 return; | 709 return; |
709 } | 710 } |
(...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1356 layer->PassCopyRequests(&main_thread_copy_requests); | 1357 layer->PassCopyRequests(&main_thread_copy_requests); |
1357 } | 1358 } |
1358 | 1359 |
1359 // If the main thread commits multiple times before the impl thread actually | 1360 // If the main thread commits multiple times before the impl thread actually |
1360 // draws, then damage tracking will become incorrect if we simply clobber the | 1361 // draws, then damage tracking will become incorrect if we simply clobber the |
1361 // update_rect here. The LayerImpl's update_rect needs to accumulate (i.e. | 1362 // update_rect here. The LayerImpl's update_rect needs to accumulate (i.e. |
1362 // union) any update changes that have occurred on the main thread. | 1363 // union) any update changes that have occurred on the main thread. |
1363 update_rect_.Union(layer->update_rect()); | 1364 update_rect_.Union(layer->update_rect()); |
1364 layer->SetUpdateRect(update_rect_); | 1365 layer->SetUpdateRect(update_rect_); |
1365 | 1366 |
1366 layer->SetStackingOrderChanged(stacking_order_changed_); | |
1367 | |
1368 if (layer->layer_animation_controller() && layer_animation_controller_) | 1367 if (layer->layer_animation_controller() && layer_animation_controller_) |
1369 layer_animation_controller_->PushAnimationUpdatesTo( | 1368 layer_animation_controller_->PushAnimationUpdatesTo( |
1370 layer->layer_animation_controller()); | 1369 layer->layer_animation_controller()); |
1371 | 1370 |
1372 if (frame_timing_requests_dirty_) { | 1371 if (frame_timing_requests_dirty_) { |
1373 layer->SetFrameTimingRequests(frame_timing_requests_); | 1372 layer->SetFrameTimingRequests(frame_timing_requests_); |
1374 frame_timing_requests_dirty_ = false; | 1373 frame_timing_requests_dirty_ = false; |
1375 } | 1374 } |
1376 | 1375 |
1377 // Reset any state that should be cleared for the next update. | 1376 // Reset any state that should be cleared for the next update. |
1378 stacking_order_changed_ = false; | |
1379 subtree_property_changed_ = false; | 1377 subtree_property_changed_ = false; |
1380 update_rect_ = gfx::Rect(); | 1378 update_rect_ = gfx::Rect(); |
1381 | 1379 |
1382 needs_push_properties_ = false; | 1380 needs_push_properties_ = false; |
1383 num_dependents_need_push_properties_ = 0; | 1381 num_dependents_need_push_properties_ = 0; |
1384 } | 1382 } |
1385 | 1383 |
1386 void Layer::SetTypeForProtoSerialization(proto::LayerNode* proto) const { | 1384 void Layer::SetTypeForProtoSerialization(proto::LayerNode* proto) const { |
1387 proto->set_type(proto::LayerType::LAYER); | 1385 proto->set_type(proto::LayerType::LAYER); |
1388 } | 1386 } |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1579 } | 1577 } |
1580 | 1578 |
1581 ScrollOffsetToProto(scroll_offset_, base->mutable_scroll_offset()); | 1579 ScrollOffsetToProto(scroll_offset_, base->mutable_scroll_offset()); |
1582 Vector2dFToProto(scroll_compensation_adjustment_, | 1580 Vector2dFToProto(scroll_compensation_adjustment_, |
1583 base->mutable_scroll_compensation_adjustment()); | 1581 base->mutable_scroll_compensation_adjustment()); |
1584 | 1582 |
1585 // TODO(nyquist): Figure out what to do with CopyRequests. | 1583 // TODO(nyquist): Figure out what to do with CopyRequests. |
1586 // See crbug.com/570374. | 1584 // See crbug.com/570374. |
1587 | 1585 |
1588 RectToProto(update_rect_, base->mutable_update_rect()); | 1586 RectToProto(update_rect_, base->mutable_update_rect()); |
1589 base->set_stacking_order_changed(stacking_order_changed_); | |
1590 | 1587 |
1591 // TODO(nyquist): Figure out what to do with LayerAnimationController. | 1588 // TODO(nyquist): Figure out what to do with LayerAnimationController. |
1592 // See crbug.com/570376. | 1589 // See crbug.com/570376. |
1593 // TODO(nyquist): Figure out what to do with FrameTimingRequests. See | 1590 // TODO(nyquist): Figure out what to do with FrameTimingRequests. See |
1594 // crbug.com/570377. | 1591 // crbug.com/570377. |
1595 | 1592 |
1596 stacking_order_changed_ = false; | |
1597 update_rect_ = gfx::Rect(); | 1593 update_rect_ = gfx::Rect(); |
1598 } | 1594 } |
1599 | 1595 |
1600 void Layer::FromLayerSpecificPropertiesProto( | 1596 void Layer::FromLayerSpecificPropertiesProto( |
1601 const proto::LayerProperties& proto) { | 1597 const proto::LayerProperties& proto) { |
1602 DCHECK(proto.has_base()); | 1598 DCHECK(proto.has_base()); |
1603 DCHECK(layer_tree_host_); | 1599 DCHECK(layer_tree_host_); |
1604 const proto::BaseLayerProperties& base = proto.base(); | 1600 const proto::BaseLayerProperties& base = proto.base(); |
1605 | 1601 |
1606 transform_origin_ = ProtoToPoint3F(base.transform_origin()); | 1602 transform_origin_ = ProtoToPoint3F(base.transform_origin()); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1682 int child_id = base.clip_children_ids(i); | 1678 int child_id = base.clip_children_ids(i); |
1683 scoped_refptr<Layer> child = layer_tree_host_->LayerById(child_id); | 1679 scoped_refptr<Layer> child = layer_tree_host_->LayerById(child_id); |
1684 clip_children_->insert(child.get()); | 1680 clip_children_->insert(child.get()); |
1685 } | 1681 } |
1686 | 1682 |
1687 scroll_offset_ = ProtoToScrollOffset(base.scroll_offset()); | 1683 scroll_offset_ = ProtoToScrollOffset(base.scroll_offset()); |
1688 scroll_compensation_adjustment_ = | 1684 scroll_compensation_adjustment_ = |
1689 ProtoToVector2dF(base.scroll_compensation_adjustment()); | 1685 ProtoToVector2dF(base.scroll_compensation_adjustment()); |
1690 | 1686 |
1691 update_rect_.Union(ProtoToRect(base.update_rect())); | 1687 update_rect_.Union(ProtoToRect(base.update_rect())); |
1692 stacking_order_changed_ = base.stacking_order_changed(); | |
1693 } | 1688 } |
1694 | 1689 |
1695 scoped_ptr<LayerImpl> Layer::CreateLayerImpl(LayerTreeImpl* tree_impl) { | 1690 scoped_ptr<LayerImpl> Layer::CreateLayerImpl(LayerTreeImpl* tree_impl) { |
1696 return LayerImpl::Create(tree_impl, layer_id_, | 1691 return LayerImpl::Create(tree_impl, layer_id_, |
1697 new LayerImpl::SyncedScrollOffset); | 1692 new LayerImpl::SyncedScrollOffset); |
1698 } | 1693 } |
1699 | 1694 |
1700 bool Layer::DrawsContent() const { | 1695 bool Layer::DrawsContent() const { |
1701 return draws_content_; | 1696 return draws_content_; |
1702 } | 1697 } |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2070 this, layer_tree_host_->property_trees()->transform_tree); | 2065 this, layer_tree_host_->property_trees()->transform_tree); |
2071 } | 2066 } |
2072 | 2067 |
2073 gfx::Transform Layer::screen_space_transform() const { | 2068 gfx::Transform Layer::screen_space_transform() const { |
2074 DCHECK_NE(transform_tree_index_, -1); | 2069 DCHECK_NE(transform_tree_index_, -1); |
2075 return ScreenSpaceTransformFromPropertyTrees( | 2070 return ScreenSpaceTransformFromPropertyTrees( |
2076 this, layer_tree_host_->property_trees()->transform_tree); | 2071 this, layer_tree_host_->property_trees()->transform_tree); |
2077 } | 2072 } |
2078 | 2073 |
2079 } // namespace cc | 2074 } // namespace cc |
OLD | NEW |