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 758 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
769 void Layer::SetScrollOffset(const gfx::ScrollOffset& scroll_offset) { | 769 void Layer::SetScrollOffset(const gfx::ScrollOffset& scroll_offset) { |
770 DCHECK(IsPropertyChangeAllowed()); | 770 DCHECK(IsPropertyChangeAllowed()); |
771 | 771 |
772 if (inputs_.scroll_offset == scroll_offset) | 772 if (inputs_.scroll_offset == scroll_offset) |
773 return; | 773 return; |
774 inputs_.scroll_offset = scroll_offset; | 774 inputs_.scroll_offset = scroll_offset; |
775 | 775 |
776 if (!layer_tree_host_) | 776 if (!layer_tree_host_) |
777 return; | 777 return; |
778 | 778 |
779 PropertyTrees* property_trees = layer_tree_host_->property_trees(); | 779 DCHECK(scrollable()); |
780 if (scroll_tree_index() != ScrollTree::kInvalidNodeId && scrollable()) | |
781 property_trees->scroll_tree.SetScrollOffset(id(), scroll_offset); | |
782 | 780 |
783 if (TransformNode* transform_node = | 781 if (!UpdateExistingScrollOffsetPropertyTreeNodes(scroll_offset)) { |
784 property_trees->transform_tree.UpdateNodeFromOwningLayerId(id())) { | 782 // Ensure property trees will be updated which will set the scroll offset. |
785 DCHECK_EQ(transform_tree_index(), transform_node->id); | 783 DCHECK(layer_tree_host_->property_trees()->needs_rebuild); |
786 transform_node->scroll_offset = CurrentScrollOffset(); | |
787 transform_node->needs_local_transform_update = true; | |
788 property_trees->transform_tree.set_needs_update(true); | |
789 } | 784 } |
790 | 785 |
791 SetNeedsCommit(); | 786 SetNeedsCommit(); |
792 } | 787 } |
793 | 788 |
794 void Layer::SetScrollOffsetFromImplSide( | 789 void Layer::SetScrollOffsetFromImplSide( |
795 const gfx::ScrollOffset& scroll_offset) { | 790 const gfx::ScrollOffset& scroll_offset) { |
796 DCHECK(IsPropertyChangeAllowed()); | 791 DCHECK(IsPropertyChangeAllowed()); |
797 // This function only gets called during a BeginMainFrame, so there | 792 // This function only gets called during a BeginMainFrame, so there |
798 // is no need to call SetNeedsUpdate here. | 793 // is no need to call SetNeedsUpdate here. |
799 DCHECK(layer_tree_host_ && layer_tree_host_->CommitRequested()); | 794 DCHECK(layer_tree_host_ && layer_tree_host_->CommitRequested()); |
800 if (inputs_.scroll_offset == scroll_offset) | 795 if (inputs_.scroll_offset == scroll_offset) |
801 return; | 796 return; |
802 inputs_.scroll_offset = scroll_offset; | 797 inputs_.scroll_offset = scroll_offset; |
803 SetNeedsPushProperties(); | 798 SetNeedsPushProperties(); |
804 | 799 |
805 PropertyTrees* property_trees = layer_tree_host_->property_trees(); | 800 DCHECK(scrollable()); |
806 if (scroll_tree_index() != ScrollTree::kInvalidNodeId && scrollable()) | |
807 property_trees->scroll_tree.SetScrollOffset(id(), scroll_offset); | |
808 | 801 |
809 if (TransformNode* transform_node = | 802 if (!UpdateExistingScrollOffsetPropertyTreeNodes(scroll_offset)) { |
810 property_trees->transform_tree.UpdateNodeFromOwningLayerId(id())) { | 803 // Ensure property trees will be updated which will set the scroll offset. |
811 DCHECK_EQ(transform_tree_index(), transform_node->id); | 804 DCHECK(layer_tree_host_->property_trees()->needs_rebuild); |
812 transform_node->scroll_offset = CurrentScrollOffset(); | |
813 transform_node->needs_local_transform_update = true; | |
814 property_trees->transform_tree.set_needs_update(true); | |
815 } | 805 } |
816 | 806 |
817 if (!inputs_.did_scroll_callback.is_null()) | 807 if (!inputs_.did_scroll_callback.is_null()) |
818 inputs_.did_scroll_callback.Run(scroll_offset); | 808 inputs_.did_scroll_callback.Run(scroll_offset); |
819 | 809 |
820 // The callback could potentially change the layer structure: | 810 // The callback could potentially change the layer structure: |
821 // "this" may have been destroyed during the process. | 811 // "this" may have been destroyed during the process. |
822 } | 812 } |
823 | 813 |
814 bool Layer::UpdateExistingScrollOffsetPropertyTreeNodes( | |
wkorman
2017/05/11 17:42:13
Add unit test for this?
pdr.
2017/05/11 18:03:37
This function is really just a refactoring of the
wkorman
2017/05/11 18:21:37
It looks like a public method on layer, so I would
| |
815 const gfx::ScrollOffset& scroll_offset) { | |
816 if (scroll_tree_index() == ScrollTree::kInvalidNodeId) | |
817 return false; | |
wkorman
2017/05/11 17:42:13
Why not put DCHECK in two places above in here, an
pdr.
2017/05/11 18:03:37
Done.
| |
818 | |
819 // If a scroll node exists, it should have an associated transform node. | |
820 DCHECK(transform_tree_index() != TransformTree::kInvalidNodeId); | |
821 | |
822 PropertyTrees* property_trees = layer_tree_host_->property_trees(); | |
wkorman
2017/05/11 17:42:13
Use auto& like you did in other patch?
pdr.
2017/05/11 18:03:37
Done
| |
823 property_trees->scroll_tree.SetScrollOffset(id(), scroll_offset); | |
824 TransformNode* transform_node = | |
825 property_trees->transform_tree.Node(transform_tree_index()); | |
826 DCHECK_EQ(transform_tree_index(), transform_node->id); | |
827 transform_node->scroll_offset = CurrentScrollOffset(); | |
828 transform_node->needs_local_transform_update = true; | |
829 property_trees->transform_tree.set_needs_update(true); | |
830 return true; | |
831 } | |
832 | |
824 void Layer::SetScrollClipLayerId(int clip_layer_id) { | 833 void Layer::SetScrollClipLayerId(int clip_layer_id) { |
825 DCHECK(IsPropertyChangeAllowed()); | 834 DCHECK(IsPropertyChangeAllowed()); |
826 if (inputs_.scroll_clip_layer_id == clip_layer_id) | 835 if (inputs_.scroll_clip_layer_id == clip_layer_id) |
827 return; | 836 return; |
828 inputs_.scroll_clip_layer_id = clip_layer_id; | 837 inputs_.scroll_clip_layer_id = clip_layer_id; |
829 SetPropertyTreesNeedRebuild(); | 838 SetPropertyTreesNeedRebuild(); |
830 SetNeedsCommit(); | 839 SetNeedsCommit(); |
831 } | 840 } |
832 | 841 |
833 Layer* Layer::scroll_clip_layer() const { | 842 Layer* Layer::scroll_clip_layer() const { |
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1441 ->subtree_has_copy_request; | 1450 ->subtree_has_copy_request; |
1442 } | 1451 } |
1443 | 1452 |
1444 gfx::Transform Layer::ScreenSpaceTransform() const { | 1453 gfx::Transform Layer::ScreenSpaceTransform() const { |
1445 DCHECK_NE(transform_tree_index_, TransformTree::kInvalidNodeId); | 1454 DCHECK_NE(transform_tree_index_, TransformTree::kInvalidNodeId); |
1446 return draw_property_utils::ScreenSpaceTransform( | 1455 return draw_property_utils::ScreenSpaceTransform( |
1447 this, layer_tree_host_->property_trees()->transform_tree); | 1456 this, layer_tree_host_->property_trees()->transform_tree); |
1448 } | 1457 } |
1449 | 1458 |
1450 } // namespace cc | 1459 } // namespace cc |
OLD | NEW |