Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(47)

Side by Side Diff: cc/layers/layer.cc

Issue 1088773003: Reuse property trees (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove unrelated change Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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;
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 if (children_[i].get() == reference) 344 if (children_[i].get() == reference)
329 return i; 345 return i;
330 } 346 }
331 return -1; 347 return -1;
332 } 348 }
333 349
334 void Layer::SetBounds(const gfx::Size& size) { 350 void Layer::SetBounds(const gfx::Size& size) {
335 DCHECK(IsPropertyChangeAllowed()); 351 DCHECK(IsPropertyChangeAllowed());
336 if (bounds() == size) 352 if (bounds() == size)
337 return; 353 return;
354 bounds_ = size;
338 355
339 bounds_ = size; 356 if (!layer_tree_host_)
340 SetNeedsCommit(); 357 return;
358
359 if (ClipNode* clip_node = layer_tree_host_->property_trees()->clip_tree.Node(
360 clip_tree_index())) {
361 if (clip_node->owner_id == id()) {
362 clip_node->data.clip.set_size(size);
363 }
364 }
365
366 SetNeedsCommitNoRebuild();
341 } 367 }
342 368
343 Layer* Layer::RootLayer() { 369 Layer* Layer::RootLayer() {
344 Layer* layer = this; 370 Layer* layer = this;
345 while (layer->parent()) 371 while (layer->parent())
346 layer = layer->parent(); 372 layer = layer->parent();
347 return layer; 373 return layer;
348 } 374 }
349 375
350 void Layer::RemoveAllChildren() { 376 void Layer::RemoveAllChildren() {
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 return; 596 return;
571 contents_opaque_ = opaque; 597 contents_opaque_ = opaque;
572 SetNeedsCommit(); 598 SetNeedsCommit();
573 } 599 }
574 600
575 void Layer::SetPosition(const gfx::PointF& position) { 601 void Layer::SetPosition(const gfx::PointF& position) {
576 DCHECK(IsPropertyChangeAllowed()); 602 DCHECK(IsPropertyChangeAllowed());
577 if (position_ == position) 603 if (position_ == position)
578 return; 604 return;
579 position_ = position; 605 position_ = position;
606
607 if (!layer_tree_host_)
608 return;
609
610 if (TransformNode* transform_node =
611 layer_tree_host_->property_trees()->transform_tree.Node(
612 transform_tree_index())) {
613 if (transform_node->owner_id == id()) {
614 transform_node->data.update_post_local_transform(position,
615 transform_origin());
616 transform_node->data.needs_local_transform_update = true;
617 SetNeedsCommitNoRebuild();
618 return;
619 }
620 }
621
580 SetNeedsCommit(); 622 SetNeedsCommit();
581 } 623 }
582 624
583 bool Layer::IsContainerForFixedPositionLayers() const { 625 bool Layer::IsContainerForFixedPositionLayers() const {
584 if (!transform_.IsIdentityOrTranslation()) 626 if (!transform_.IsIdentityOrTranslation())
585 return true; 627 return true;
586 if (parent_ && !parent_->transform_.IsIdentityOrTranslation()) 628 if (parent_ && !parent_->transform_.IsIdentityOrTranslation())
587 return true; 629 return true;
588 return is_container_for_fixed_position_layers_; 630 return is_container_for_fixed_position_layers_;
589 } 631 }
590 632
633 bool Are2dAxisAligned(const gfx::Transform& a,
634 const gfx::Transform& b,
635 bool* is_invertible) {
636 if (a.IsScaleOrTranslation() && b.IsScaleOrTranslation()) {
637 *is_invertible = b.IsInvertible();
638 return true;
639 }
640
641 gfx::Transform inverse(gfx::Transform::kSkipInitialization);
642 *is_invertible = b.GetInverse(&inverse);
643
644 inverse *= a;
645 return inverse.Preserves2dAxisAlignment();
646 }
647
591 void Layer::SetTransform(const gfx::Transform& transform) { 648 void Layer::SetTransform(const gfx::Transform& transform) {
592 DCHECK(IsPropertyChangeAllowed()); 649 DCHECK(IsPropertyChangeAllowed());
593 if (transform_ == transform) 650 if (transform_ == transform)
594 return; 651 return;
652
653 if (layer_tree_host_) {
654 if (TransformNode* transform_node =
655 layer_tree_host_->property_trees()->transform_tree.Node(
656 transform_tree_index())) {
657 if (transform_node->owner_id == id()) {
658 // We need to trigger a rebuild if we could have affected 2d axis
659 // alignment. We'll check to see if transform and transform_ are axis
660 // align with respect to one another.
661 bool invertible = false;
662 bool preserves_2d_axis_alignment =
663 Are2dAxisAligned(transform_, transform, &invertible);
664 transform_node->data.local = transform;
665 transform_node->data.needs_local_transform_update = true;
666 if (preserves_2d_axis_alignment)
667 SetNeedsCommitNoRebuild();
668 else
669 SetNeedsCommit();
670 transform_ = transform;
671 transform_is_invertible_ = invertible;
672 return;
673 }
674 }
675 }
676
595 transform_ = transform; 677 transform_ = transform;
596 transform_is_invertible_ = transform.IsInvertible(); 678 transform_is_invertible_ = transform.IsInvertible();
679
597 SetNeedsCommit(); 680 SetNeedsCommit();
598 } 681 }
599 682
600 void Layer::SetTransformOrigin(const gfx::Point3F& transform_origin) { 683 void Layer::SetTransformOrigin(const gfx::Point3F& transform_origin) {
601 DCHECK(IsPropertyChangeAllowed()); 684 DCHECK(IsPropertyChangeAllowed());
602 if (transform_origin_ == transform_origin) 685 if (transform_origin_ == transform_origin)
603 return; 686 return;
604 transform_origin_ = transform_origin; 687 transform_origin_ = transform_origin;
688
689 if (!layer_tree_host_)
690 return;
691
692 if (TransformNode* transform_node =
693 layer_tree_host_->property_trees()->transform_tree.Node(
694 transform_tree_index())) {
695 if (transform_node->owner_id == id()) {
696 transform_node->data.update_post_local_transform(position(),
697 transform_origin);
698 transform_node->data.needs_local_transform_update = true;
699 SetNeedsCommitNoRebuild();
700 return;
701 }
702 }
703
605 SetNeedsCommit(); 704 SetNeedsCommit();
606 } 705 }
607 706
608 bool Layer::AnimationsPreserveAxisAlignment() const { 707 bool Layer::AnimationsPreserveAxisAlignment() const {
609 return layer_animation_controller_->AnimationsPreserveAxisAlignment(); 708 return layer_animation_controller_->AnimationsPreserveAxisAlignment();
610 } 709 }
611 710
612 bool Layer::TransformIsAnimating() const { 711 bool Layer::TransformIsAnimating() const {
613 return layer_animation_controller_->IsAnimatingProperty(Animation::TRANSFORM); 712 return layer_animation_controller_->IsAnimatingProperty(Animation::TRANSFORM);
614 } 713 }
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
672 clip_children_ = nullptr; 771 clip_children_ = nullptr;
673 SetNeedsCommit(); 772 SetNeedsCommit();
674 } 773 }
675 774
676 void Layer::SetScrollOffset(const gfx::ScrollOffset& scroll_offset) { 775 void Layer::SetScrollOffset(const gfx::ScrollOffset& scroll_offset) {
677 DCHECK(IsPropertyChangeAllowed()); 776 DCHECK(IsPropertyChangeAllowed());
678 777
679 if (scroll_offset_ == scroll_offset) 778 if (scroll_offset_ == scroll_offset)
680 return; 779 return;
681 scroll_offset_ = scroll_offset; 780 scroll_offset_ = scroll_offset;
781
782 if (!layer_tree_host_)
783 return;
784
785 if (TransformNode* transform_node =
786 layer_tree_host_->property_trees()->transform_tree.Node(
787 transform_tree_index())) {
788 if (transform_node->owner_id == id()) {
789 transform_node->data.scroll_offset =
790 gfx::ScrollOffsetToVector2dF(CurrentScrollOffset());
791 transform_node->data.needs_local_transform_update = true;
792 SetNeedsCommitNoRebuild();
793 return;
794 }
795 }
796
682 SetNeedsCommit(); 797 SetNeedsCommit();
683 } 798 }
684 799
685 void Layer::SetScrollCompensationAdjustment( 800 void Layer::SetScrollCompensationAdjustment(
686 const gfx::Vector2dF& scroll_compensation_adjustment) { 801 const gfx::Vector2dF& scroll_compensation_adjustment) {
687 if (scroll_compensation_adjustment_ == scroll_compensation_adjustment) 802 if (scroll_compensation_adjustment_ == scroll_compensation_adjustment)
688 return; 803 return;
689 scroll_compensation_adjustment_ = scroll_compensation_adjustment; 804 scroll_compensation_adjustment_ = scroll_compensation_adjustment;
690 SetNeedsCommit(); 805 SetNeedsCommit();
691 } 806 }
692 807
693 gfx::Vector2dF Layer::ScrollCompensationAdjustment() const { 808 gfx::Vector2dF Layer::ScrollCompensationAdjustment() const {
694 return scroll_compensation_adjustment_; 809 return scroll_compensation_adjustment_;
695 } 810 }
696 811
697 void Layer::SetScrollOffsetFromImplSide( 812 void Layer::SetScrollOffsetFromImplSide(
698 const gfx::ScrollOffset& scroll_offset) { 813 const gfx::ScrollOffset& scroll_offset) {
699 DCHECK(IsPropertyChangeAllowed()); 814 DCHECK(IsPropertyChangeAllowed());
700 // This function only gets called during a BeginMainFrame, so there 815 // This function only gets called during a BeginMainFrame, so there
701 // is no need to call SetNeedsUpdate here. 816 // is no need to call SetNeedsUpdate here.
702 DCHECK(layer_tree_host_ && layer_tree_host_->CommitRequested()); 817 DCHECK(layer_tree_host_ && layer_tree_host_->CommitRequested());
703 if (scroll_offset_ == scroll_offset) 818 if (scroll_offset_ == scroll_offset)
704 return; 819 return;
705 scroll_offset_ = scroll_offset; 820 scroll_offset_ = scroll_offset;
706 SetNeedsPushProperties(); 821 SetNeedsPushProperties();
822
823 bool needs_rebuild = true;
824 if (TransformNode* transform_node =
825 layer_tree_host_->property_trees()->transform_tree.Node(
826 transform_tree_index())) {
827 if (transform_node->owner_id == id()) {
828 transform_node->data.scroll_offset =
829 gfx::ScrollOffsetToVector2dF(CurrentScrollOffset());
830 transform_node->data.needs_local_transform_update = true;
831 needs_rebuild = false;
832 }
833 }
834
835 if (needs_rebuild)
836 layer_tree_host_->property_trees()->needs_rebuild = true;
837
707 if (!did_scroll_callback_.is_null()) 838 if (!did_scroll_callback_.is_null())
708 did_scroll_callback_.Run(); 839 did_scroll_callback_.Run();
709 // The callback could potentially change the layer structure: 840 // The callback could potentially change the layer structure:
710 // "this" may have been destroyed during the process. 841 // "this" may have been destroyed during the process.
711 } 842 }
712 843
713 void Layer::SetScrollClipLayerId(int clip_layer_id) { 844 void Layer::SetScrollClipLayerId(int clip_layer_id) {
714 DCHECK(IsPropertyChangeAllowed()); 845 DCHECK(IsPropertyChangeAllowed());
715 if (scroll_clip_layer_id_ == clip_layer_id) 846 if (scroll_clip_layer_id_ == clip_layer_id)
716 return; 847 return;
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
1012 scoped_ptr<CopyOutputRequest> original_request = copy_requests_.take(it); 1143 scoped_ptr<CopyOutputRequest> original_request = copy_requests_.take(it);
1013 const CopyOutputRequest& original_request_ref = *original_request; 1144 const CopyOutputRequest& original_request_ref = *original_request;
1014 scoped_ptr<CopyOutputRequest> main_thread_request = 1145 scoped_ptr<CopyOutputRequest> main_thread_request =
1015 CopyOutputRequest::CreateRelayRequest( 1146 CopyOutputRequest::CreateRelayRequest(
1016 original_request_ref, 1147 original_request_ref,
1017 base::Bind(&PostCopyCallbackToMainThread, 1148 base::Bind(&PostCopyCallbackToMainThread,
1018 main_thread_task_runner, 1149 main_thread_task_runner,
1019 base::Passed(&original_request))); 1150 base::Passed(&original_request)));
1020 main_thread_copy_requests.push_back(main_thread_request.Pass()); 1151 main_thread_copy_requests.push_back(main_thread_request.Pass());
1021 } 1152 }
1153 if (!copy_requests_.empty() && layer_tree_host_)
1154 layer_tree_host_->property_trees()->needs_rebuild = true;
1022 copy_requests_.clear(); 1155 copy_requests_.clear();
1023 layer->PassCopyRequests(&main_thread_copy_requests); 1156 layer->PassCopyRequests(&main_thread_copy_requests);
1024 1157
1025 // If the main thread commits multiple times before the impl thread actually 1158 // 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 1159 // 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. 1160 // 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. 1161 // union) any update changes that have occurred on the main thread.
1029 update_rect_.Union(layer->update_rect()); 1162 update_rect_.Union(layer->update_rect());
1030 layer->SetUpdateRect(update_rect_); 1163 layer->SetUpdateRect(update_rect_);
1031 1164
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
1150 // On<Property>Animated is called due to an ongoing accelerated animation. 1283 // On<Property>Animated is called due to an ongoing accelerated animation.
1151 // Since this animation is also being run on the compositor thread, there 1284 // 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 1285 // 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>. 1286 // set directly rather than by calling Set<Property>.
1154 void Layer::OnFilterAnimated(const FilterOperations& filters) { 1287 void Layer::OnFilterAnimated(const FilterOperations& filters) {
1155 filters_ = filters; 1288 filters_ = filters;
1156 } 1289 }
1157 1290
1158 void Layer::OnOpacityAnimated(float opacity) { 1291 void Layer::OnOpacityAnimated(float opacity) {
1159 opacity_ = opacity; 1292 opacity_ = opacity;
1293 if (layer_tree_host_) {
1294 if (OpacityNode* node =
1295 layer_tree_host_->property_trees()->opacity_tree.Node(
1296 opacity_tree_index_)) {
1297 if (node->owner_id == id())
1298 node->data = opacity;
1299 }
1300 }
1160 } 1301 }
1161 1302
1162 void Layer::OnTransformAnimated(const gfx::Transform& transform) { 1303 void Layer::OnTransformAnimated(const gfx::Transform& transform) {
1163 if (transform_ == transform) 1304 if (transform_ == transform)
1164 return; 1305 return;
1165 transform_ = transform; 1306 transform_ = transform;
1166 transform_is_invertible_ = transform.IsInvertible(); 1307 transform_is_invertible_ = transform.IsInvertible();
1308 if (layer_tree_host_) {
1309 if (TransformNode* node =
1310 layer_tree_host_->property_trees()->transform_tree.Node(
1311 transform_tree_index_)) {
1312 if (node->owner_id == id()) {
1313 node->data.local = transform;
1314 node->data.needs_local_transform_update = true;
1315 node->data.is_animated = true;
1316 }
1317 }
1318 }
1167 } 1319 }
1168 1320
1169 void Layer::OnScrollOffsetAnimated(const gfx::ScrollOffset& scroll_offset) { 1321 void Layer::OnScrollOffsetAnimated(const gfx::ScrollOffset& scroll_offset) {
1170 // Do nothing. Scroll deltas will be sent from the compositor thread back 1322 // 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 1323 // to the main thread in the same manner as during non-animated
1172 // compositor-driven scrolling. 1324 // compositor-driven scrolling.
1173 } 1325 }
1174 1326
1175 void Layer::OnAnimationWaitingForDeletion() { 1327 void Layer::OnAnimationWaitingForDeletion() {
1176 // Animations are only deleted during PushProperties. 1328 // Animations are only deleted during PushProperties.
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
1375 1527
1376 void Layer::DidBeginTracing() { 1528 void Layer::DidBeginTracing() {
1377 // We'll be dumping layer trees as part of trace, so make sure 1529 // We'll be dumping layer trees as part of trace, so make sure
1378 // PushPropertiesTo() propagates layer debug info to the impl 1530 // PushPropertiesTo() propagates layer debug info to the impl
1379 // side -- otherwise this won't happen for the the layers that 1531 // side -- otherwise this won't happen for the the layers that
1380 // remain unchanged since tracing started. 1532 // remain unchanged since tracing started.
1381 SetNeedsPushProperties(); 1533 SetNeedsPushProperties();
1382 } 1534 }
1383 1535
1384 } // namespace cc 1536 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698