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 <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/atomic_sequence_num.h" | 9 #include "base/atomic_sequence_num.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
111 if (replica_layer_.get()) { | 111 if (replica_layer_.get()) { |
112 DCHECK_EQ(this, replica_layer_->parent()); | 112 DCHECK_EQ(this, replica_layer_->parent()); |
113 replica_layer_->RemoveFromParent(); | 113 replica_layer_->RemoveFromParent(); |
114 } | 114 } |
115 } | 115 } |
116 | 116 |
117 void Layer::SetLayerTreeHost(LayerTreeHost* host) { | 117 void Layer::SetLayerTreeHost(LayerTreeHost* host) { |
118 if (layer_tree_host_ == host) | 118 if (layer_tree_host_ == host) |
119 return; | 119 return; |
120 | 120 |
121 if (layer_tree_host_) | |
122 layer_tree_host_->property_trees()->needs_rebuild = true; | |
123 | |
121 layer_tree_host_ = host; | 124 layer_tree_host_ = host; |
122 | 125 |
123 // When changing hosts, the layer needs to commit its properties to the impl | 126 // When changing hosts, the layer needs to commit its properties to the impl |
124 // side for the new host. | 127 // side for the new host. |
125 SetNeedsPushProperties(); | 128 SetNeedsPushProperties(); |
126 | 129 |
127 for (size_t i = 0; i < children_.size(); ++i) | 130 for (size_t i = 0; i < children_.size(); ++i) |
128 children_[i]->SetLayerTreeHost(host); | 131 children_[i]->SetLayerTreeHost(host); |
129 | 132 |
130 if (mask_layer_.get()) | 133 if (mask_layer_.get()) |
(...skipping 16 matching lines...) Expand all Loading... | |
147 void Layer::SetNeedsUpdate() { | 150 void Layer::SetNeedsUpdate() { |
148 if (layer_tree_host_ && !ignore_set_needs_commit_) | 151 if (layer_tree_host_ && !ignore_set_needs_commit_) |
149 layer_tree_host_->SetNeedsUpdateLayers(); | 152 layer_tree_host_->SetNeedsUpdateLayers(); |
150 } | 153 } |
151 | 154 |
152 void Layer::SetNeedsCommit() { | 155 void Layer::SetNeedsCommit() { |
153 if (!layer_tree_host_) | 156 if (!layer_tree_host_) |
154 return; | 157 return; |
155 | 158 |
156 SetNeedsPushProperties(); | 159 SetNeedsPushProperties(); |
160 layer_tree_host_->property_trees()->needs_rebuild = true; | |
161 | |
162 if (ignore_set_needs_commit_) | |
163 return; | |
164 | |
165 layer_tree_host_->SetNeedsCommit(); | |
166 } | |
167 | |
168 void Layer::SetNeedsCommitNoRebuild() { | |
169 if (!layer_tree_host_) | |
170 return; | |
171 | |
172 SetNeedsPushProperties(); | |
157 | 173 |
158 if (ignore_set_needs_commit_) | 174 if (ignore_set_needs_commit_) |
159 return; | 175 return; |
160 | 176 |
161 layer_tree_host_->SetNeedsCommit(); | 177 layer_tree_host_->SetNeedsCommit(); |
162 } | 178 } |
163 | 179 |
164 void Layer::SetNeedsFullTreeSync() { | 180 void Layer::SetNeedsFullTreeSync() { |
165 if (!layer_tree_host_) | 181 if (!layer_tree_host_) |
166 return; | 182 return; |
167 | 183 |
184 layer_tree_host_->property_trees()->needs_rebuild = true; | |
ajuma
2015/04/16 14:52:14
LayerTreeHost::SetNeedsFullTreeSync will trigger a
enne (OOO)
2015/04/16 21:49:33
That's kind of subtle to skip it. I think I'd pre
| |
168 layer_tree_host_->SetNeedsFullTreeSync(); | 185 layer_tree_host_->SetNeedsFullTreeSync(); |
169 } | 186 } |
170 | 187 |
171 void Layer::SetNextCommitWaitsForActivation() { | 188 void Layer::SetNextCommitWaitsForActivation() { |
172 if (!layer_tree_host_) | 189 if (!layer_tree_host_) |
173 return; | 190 return; |
174 | 191 |
175 layer_tree_host_->SetNextCommitWaitsForActivation(); | 192 layer_tree_host_->SetNextCommitWaitsForActivation(); |
176 } | 193 } |
177 | 194 |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
328 if (children_[i].get() == reference) | 345 if (children_[i].get() == reference) |
329 return i; | 346 return i; |
330 } | 347 } |
331 return -1; | 348 return -1; |
332 } | 349 } |
333 | 350 |
334 void Layer::SetBounds(const gfx::Size& size) { | 351 void Layer::SetBounds(const gfx::Size& size) { |
335 DCHECK(IsPropertyChangeAllowed()); | 352 DCHECK(IsPropertyChangeAllowed()); |
336 if (bounds() == size) | 353 if (bounds() == size) |
337 return; | 354 return; |
355 bounds_ = size; | |
338 | 356 |
339 bounds_ = size; | 357 if (!layer_tree_host_) |
358 return; | |
359 | |
360 if (ClipNode* clip_node = layer_tree_host_->property_trees()->clip_tree.Node( | |
361 clip_tree_index())) { | |
362 if (clip_node->owner_id == id()) { | |
363 clip_node->data.clip.set_size(size); | |
364 SetNeedsCommitNoRebuild(); | |
365 return; | |
366 } | |
367 } | |
368 | |
340 SetNeedsCommit(); | 369 SetNeedsCommit(); |
ajuma
2015/04/16 14:52:14
In what situations will changing bounds change whe
Ian Vollick
2015/04/17 14:56:22
None! I've gotten rid of the early out and we now
| |
341 } | 370 } |
342 | 371 |
343 Layer* Layer::RootLayer() { | 372 Layer* Layer::RootLayer() { |
344 Layer* layer = this; | 373 Layer* layer = this; |
345 while (layer->parent()) | 374 while (layer->parent()) |
346 layer = layer->parent(); | 375 layer = layer->parent(); |
347 return layer; | 376 return layer; |
348 } | 377 } |
349 | 378 |
350 void Layer::RemoveAllChildren() { | 379 void Layer::RemoveAllChildren() { |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
570 return; | 599 return; |
571 contents_opaque_ = opaque; | 600 contents_opaque_ = opaque; |
572 SetNeedsCommit(); | 601 SetNeedsCommit(); |
573 } | 602 } |
574 | 603 |
575 void Layer::SetPosition(const gfx::PointF& position) { | 604 void Layer::SetPosition(const gfx::PointF& position) { |
576 DCHECK(IsPropertyChangeAllowed()); | 605 DCHECK(IsPropertyChangeAllowed()); |
577 if (position_ == position) | 606 if (position_ == position) |
578 return; | 607 return; |
579 position_ = position; | 608 position_ = position; |
609 | |
610 if (!layer_tree_host_) | |
611 return; | |
612 | |
613 if (TransformNode* transform_node = | |
614 layer_tree_host_->property_trees()->transform_tree.Node( | |
615 transform_tree_index())) { | |
616 if (transform_node->owner_id == id()) { | |
617 transform_node->data.update_post_local_transform(position, | |
618 transform_origin()); | |
619 transform_node->data.needs_local_transform_update = true; | |
620 SetNeedsCommitNoRebuild(); | |
621 return; | |
622 } | |
623 } | |
624 | |
580 SetNeedsCommit(); | 625 SetNeedsCommit(); |
ajuma
2015/04/16 14:52:13
Can setting position change whether a transform no
Ian Vollick
2015/04/17 14:56:22
The latter, yeah.
| |
581 } | 626 } |
582 | 627 |
583 bool Layer::IsContainerForFixedPositionLayers() const { | 628 bool Layer::IsContainerForFixedPositionLayers() const { |
584 if (!transform_.IsIdentityOrTranslation()) | 629 if (!transform_.IsIdentityOrTranslation()) |
585 return true; | 630 return true; |
586 if (parent_ && !parent_->transform_.IsIdentityOrTranslation()) | 631 if (parent_ && !parent_->transform_.IsIdentityOrTranslation()) |
587 return true; | 632 return true; |
588 return is_container_for_fixed_position_layers_; | 633 return is_container_for_fixed_position_layers_; |
589 } | 634 } |
590 | 635 |
591 void Layer::SetTransform(const gfx::Transform& transform) { | 636 void Layer::SetTransform(const gfx::Transform& transform) { |
592 DCHECK(IsPropertyChangeAllowed()); | 637 DCHECK(IsPropertyChangeAllowed()); |
593 if (transform_ == transform) | 638 if (transform_ == transform) |
594 return; | 639 return; |
595 transform_ = transform; | 640 transform_ = transform; |
596 transform_is_invertible_ = transform.IsInvertible(); | 641 transform_is_invertible_ = transform.IsInvertible(); |
642 | |
643 if (!layer_tree_host_) | |
644 return; | |
645 | |
646 if (TransformNode* transform_node = | |
647 layer_tree_host_->property_trees()->transform_tree.Node( | |
648 transform_tree_index())) { | |
649 if (transform_node->owner_id == id()) { | |
650 transform_node->data.local = transform; | |
651 transform_node->data.needs_local_transform_update = true; | |
ajuma
2015/04/16 14:52:14
Could changing a transform's value affect whether
Ian Vollick
2015/04/17 14:56:22
Yeah, it could. I've updated this code to check fo
| |
652 SetNeedsCommitNoRebuild(); | |
653 return; | |
654 } | |
655 } | |
656 | |
597 SetNeedsCommit(); | 657 SetNeedsCommit(); |
ajuma
2015/04/16 14:52:14
As a future optimization (not in this CL), we coul
ajuma
2015/04/16 14:55:04
Actually, I take this back; a 2d translation would
Ian Vollick
2015/04/17 14:56:22
We've talked about the offset_to_transform_parent
| |
598 } | 658 } |
599 | 659 |
600 void Layer::SetTransformOrigin(const gfx::Point3F& transform_origin) { | 660 void Layer::SetTransformOrigin(const gfx::Point3F& transform_origin) { |
601 DCHECK(IsPropertyChangeAllowed()); | 661 DCHECK(IsPropertyChangeAllowed()); |
602 if (transform_origin_ == transform_origin) | 662 if (transform_origin_ == transform_origin) |
603 return; | 663 return; |
604 transform_origin_ = transform_origin; | 664 transform_origin_ = transform_origin; |
665 | |
666 if (!layer_tree_host_) | |
667 return; | |
668 | |
669 if (TransformNode* transform_node = | |
670 layer_tree_host_->property_trees()->transform_tree.Node( | |
671 transform_tree_index())) { | |
672 if (transform_node->owner_id == id()) { | |
673 transform_node->data.update_post_local_transform(position(), | |
674 transform_origin); | |
675 transform_node->data.needs_local_transform_update = true; | |
676 SetNeedsCommitNoRebuild(); | |
677 return; | |
678 } | |
679 } | |
680 | |
605 SetNeedsCommit(); | 681 SetNeedsCommit(); |
606 } | 682 } |
607 | 683 |
608 bool Layer::AnimationsPreserveAxisAlignment() const { | 684 bool Layer::AnimationsPreserveAxisAlignment() const { |
609 return layer_animation_controller_->AnimationsPreserveAxisAlignment(); | 685 return layer_animation_controller_->AnimationsPreserveAxisAlignment(); |
610 } | 686 } |
611 | 687 |
612 bool Layer::TransformIsAnimating() const { | 688 bool Layer::TransformIsAnimating() const { |
613 return layer_animation_controller_->IsAnimatingProperty(Animation::TRANSFORM); | 689 return layer_animation_controller_->IsAnimatingProperty(Animation::TRANSFORM); |
614 } | 690 } |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
672 clip_children_ = nullptr; | 748 clip_children_ = nullptr; |
673 SetNeedsCommit(); | 749 SetNeedsCommit(); |
674 } | 750 } |
675 | 751 |
676 void Layer::SetScrollOffset(const gfx::ScrollOffset& scroll_offset) { | 752 void Layer::SetScrollOffset(const gfx::ScrollOffset& scroll_offset) { |
677 DCHECK(IsPropertyChangeAllowed()); | 753 DCHECK(IsPropertyChangeAllowed()); |
678 | 754 |
679 if (scroll_offset_ == scroll_offset) | 755 if (scroll_offset_ == scroll_offset) |
680 return; | 756 return; |
681 scroll_offset_ = scroll_offset; | 757 scroll_offset_ = scroll_offset; |
758 | |
759 if (!layer_tree_host_) | |
760 return; | |
761 | |
762 if (TransformNode* transform_node = | |
763 layer_tree_host_->property_trees()->transform_tree.Node( | |
764 transform_tree_index())) { | |
765 if (transform_node->owner_id == id()) { | |
766 transform_node->data.scroll_offset = | |
767 gfx::ScrollOffsetToVector2dF(CurrentScrollOffset()); | |
768 transform_node->data.needs_local_transform_update = true; | |
769 SetNeedsCommitNoRebuild(); | |
770 return; | |
771 } | |
772 } | |
773 | |
682 SetNeedsCommit(); | 774 SetNeedsCommit(); |
683 } | 775 } |
684 | 776 |
685 void Layer::SetScrollCompensationAdjustment( | 777 void Layer::SetScrollCompensationAdjustment( |
686 const gfx::Vector2dF& scroll_compensation_adjustment) { | 778 const gfx::Vector2dF& scroll_compensation_adjustment) { |
687 if (scroll_compensation_adjustment_ == scroll_compensation_adjustment) | 779 if (scroll_compensation_adjustment_ == scroll_compensation_adjustment) |
688 return; | 780 return; |
689 scroll_compensation_adjustment_ = scroll_compensation_adjustment; | 781 scroll_compensation_adjustment_ = scroll_compensation_adjustment; |
690 SetNeedsCommit(); | 782 SetNeedsCommit(); |
691 } | 783 } |
692 | 784 |
693 gfx::Vector2dF Layer::ScrollCompensationAdjustment() const { | 785 gfx::Vector2dF Layer::ScrollCompensationAdjustment() const { |
694 return scroll_compensation_adjustment_; | 786 return scroll_compensation_adjustment_; |
695 } | 787 } |
696 | 788 |
697 void Layer::SetScrollOffsetFromImplSide( | 789 void Layer::SetScrollOffsetFromImplSide(const gfx::ScrollOffset& scroll_offset, |
698 const gfx::ScrollOffset& scroll_offset) { | 790 LayerTreeHost* host) { |
ajuma
2015/04/16 14:52:14
Will this ever get called with a |host| that's not
Ian Vollick
2015/04/17 14:56:22
Nope. Removed.
| |
699 DCHECK(IsPropertyChangeAllowed()); | 791 DCHECK(IsPropertyChangeAllowed()); |
700 // This function only gets called during a BeginMainFrame, so there | 792 // This function only gets called during a BeginMainFrame, so there |
701 // is no need to call SetNeedsUpdate here. | 793 // is no need to call SetNeedsUpdate here. |
702 DCHECK(layer_tree_host_ && layer_tree_host_->CommitRequested()); | 794 DCHECK(layer_tree_host_ && layer_tree_host_->CommitRequested()); |
703 if (scroll_offset_ == scroll_offset) | 795 if (scroll_offset_ == scroll_offset) |
704 return; | 796 return; |
705 scroll_offset_ = scroll_offset; | 797 scroll_offset_ = scroll_offset; |
706 SetNeedsPushProperties(); | 798 SetNeedsPushProperties(); |
799 | |
800 bool needs_rebuild = true; | |
801 if (TransformNode* transform_node = | |
802 host->property_trees()->transform_tree.Node(transform_tree_index())) { | |
803 if (transform_node->owner_id == id()) { | |
804 transform_node->data.scroll_offset = | |
805 gfx::ScrollOffsetToVector2dF(CurrentScrollOffset()); | |
806 transform_node->data.needs_local_transform_update = true; | |
807 needs_rebuild = false; | |
808 } | |
809 } | |
810 | |
811 if (needs_rebuild) | |
812 host->property_trees()->needs_rebuild = true; | |
813 | |
707 if (!did_scroll_callback_.is_null()) | 814 if (!did_scroll_callback_.is_null()) |
708 did_scroll_callback_.Run(); | 815 did_scroll_callback_.Run(); |
709 // The callback could potentially change the layer structure: | 816 // The callback could potentially change the layer structure: |
710 // "this" may have been destroyed during the process. | 817 // "this" may have been destroyed during the process. |
711 } | 818 } |
712 | 819 |
713 void Layer::SetScrollClipLayerId(int clip_layer_id) { | 820 void Layer::SetScrollClipLayerId(int clip_layer_id) { |
714 DCHECK(IsPropertyChangeAllowed()); | 821 DCHECK(IsPropertyChangeAllowed()); |
715 if (scroll_clip_layer_id_ == clip_layer_id) | 822 if (scroll_clip_layer_id_ == clip_layer_id) |
716 return; | 823 return; |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1012 scoped_ptr<CopyOutputRequest> original_request = copy_requests_.take(it); | 1119 scoped_ptr<CopyOutputRequest> original_request = copy_requests_.take(it); |
1013 const CopyOutputRequest& original_request_ref = *original_request; | 1120 const CopyOutputRequest& original_request_ref = *original_request; |
1014 scoped_ptr<CopyOutputRequest> main_thread_request = | 1121 scoped_ptr<CopyOutputRequest> main_thread_request = |
1015 CopyOutputRequest::CreateRelayRequest( | 1122 CopyOutputRequest::CreateRelayRequest( |
1016 original_request_ref, | 1123 original_request_ref, |
1017 base::Bind(&PostCopyCallbackToMainThread, | 1124 base::Bind(&PostCopyCallbackToMainThread, |
1018 main_thread_task_runner, | 1125 main_thread_task_runner, |
1019 base::Passed(&original_request))); | 1126 base::Passed(&original_request))); |
1020 main_thread_copy_requests.push_back(main_thread_request.Pass()); | 1127 main_thread_copy_requests.push_back(main_thread_request.Pass()); |
1021 } | 1128 } |
1129 if (!copy_requests_.empty() && layer_tree_host_) | |
1130 layer_tree_host_->property_trees()->needs_rebuild = true; | |
1022 copy_requests_.clear(); | 1131 copy_requests_.clear(); |
1023 layer->PassCopyRequests(&main_thread_copy_requests); | 1132 layer->PassCopyRequests(&main_thread_copy_requests); |
1024 | 1133 |
1025 // If the main thread commits multiple times before the impl thread actually | 1134 // If the main thread commits multiple times before the impl thread actually |
1026 // draws, then damage tracking will become incorrect if we simply clobber the | 1135 // draws, then damage tracking will become incorrect if we simply clobber the |
1027 // update_rect here. The LayerImpl's update_rect needs to accumulate (i.e. | 1136 // update_rect here. The LayerImpl's update_rect needs to accumulate (i.e. |
1028 // union) any update changes that have occurred on the main thread. | 1137 // union) any update changes that have occurred on the main thread. |
1029 update_rect_.Union(layer->update_rect()); | 1138 update_rect_.Union(layer->update_rect()); |
1030 layer->SetUpdateRect(update_rect_); | 1139 layer->SetUpdateRect(update_rect_); |
1031 | 1140 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1150 // On<Property>Animated is called due to an ongoing accelerated animation. | 1259 // On<Property>Animated is called due to an ongoing accelerated animation. |
1151 // Since this animation is also being run on the compositor thread, there | 1260 // Since this animation is also being run on the compositor thread, there |
1152 // is no need to request a commit to push this value over, so the value is | 1261 // is no need to request a commit to push this value over, so the value is |
1153 // set directly rather than by calling Set<Property>. | 1262 // set directly rather than by calling Set<Property>. |
1154 void Layer::OnFilterAnimated(const FilterOperations& filters) { | 1263 void Layer::OnFilterAnimated(const FilterOperations& filters) { |
1155 filters_ = filters; | 1264 filters_ = filters; |
1156 } | 1265 } |
1157 | 1266 |
1158 void Layer::OnOpacityAnimated(float opacity) { | 1267 void Layer::OnOpacityAnimated(float opacity) { |
1159 opacity_ = opacity; | 1268 opacity_ = opacity; |
1269 if (layer_tree_host_) { | |
1270 if (OpacityNode* node = | |
1271 layer_tree_host_->property_trees()->opacity_tree.Node( | |
1272 opacity_tree_index_)) { | |
1273 if (node->owner_id == id()) | |
1274 node->data = opacity; | |
1275 } | |
1276 } | |
1160 } | 1277 } |
1161 | 1278 |
1162 void Layer::OnTransformAnimated(const gfx::Transform& transform) { | 1279 void Layer::OnTransformAnimated(const gfx::Transform& transform) { |
1163 if (transform_ == transform) | 1280 if (transform_ == transform) |
1164 return; | 1281 return; |
1165 transform_ = transform; | 1282 transform_ = transform; |
1166 transform_is_invertible_ = transform.IsInvertible(); | 1283 transform_is_invertible_ = transform.IsInvertible(); |
1284 if (layer_tree_host_) { | |
1285 if (TransformNode* node = | |
1286 layer_tree_host_->property_trees()->transform_tree.Node( | |
1287 transform_tree_index_)) { | |
1288 if (node->owner_id == id()) { | |
1289 node->data.local = transform; | |
1290 node->data.needs_local_transform_update = true; | |
1291 node->data.is_animated = true; | |
1292 } | |
1293 } | |
1294 } | |
1167 } | 1295 } |
1168 | 1296 |
1169 void Layer::OnScrollOffsetAnimated(const gfx::ScrollOffset& scroll_offset) { | 1297 void Layer::OnScrollOffsetAnimated(const gfx::ScrollOffset& scroll_offset) { |
1170 // Do nothing. Scroll deltas will be sent from the compositor thread back | 1298 // Do nothing. Scroll deltas will be sent from the compositor thread back |
1171 // to the main thread in the same manner as during non-animated | 1299 // to the main thread in the same manner as during non-animated |
1172 // compositor-driven scrolling. | 1300 // compositor-driven scrolling. |
1173 } | 1301 } |
1174 | 1302 |
1175 void Layer::OnAnimationWaitingForDeletion() { | 1303 void Layer::OnAnimationWaitingForDeletion() { |
1176 // Animations are only deleted during PushProperties. | 1304 // Animations are only deleted during PushProperties. |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1375 | 1503 |
1376 void Layer::DidBeginTracing() { | 1504 void Layer::DidBeginTracing() { |
1377 // We'll be dumping layer trees as part of trace, so make sure | 1505 // We'll be dumping layer trees as part of trace, so make sure |
1378 // PushPropertiesTo() propagates layer debug info to the impl | 1506 // PushPropertiesTo() propagates layer debug info to the impl |
1379 // side -- otherwise this won't happen for the the layers that | 1507 // side -- otherwise this won't happen for the the layers that |
1380 // remain unchanged since tracing started. | 1508 // remain unchanged since tracing started. |
1381 SetNeedsPushProperties(); | 1509 SetNeedsPushProperties(); |
1382 } | 1510 } |
1383 | 1511 |
1384 } // namespace cc | 1512 } // namespace cc |
OLD | NEW |