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

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

Issue 2877673002: Rewrite Layer::SetScrollOffset{FromImplSide} property tree fast-path (Closed)
Patch Set: Address reviewer comments with simpler "UpdateScrollOffset" fn Created 3 years, 7 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
« no previous file with comments | « cc/layers/layer.h ('k') | cc/layers/scrollbar_layer_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <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
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 UpdateScrollOffset(scroll_offset);
780 if (scroll_tree_index() != ScrollTree::kInvalidNodeId && scrollable())
781 property_trees->scroll_tree.SetScrollOffset(id(), scroll_offset);
782
783 if (TransformNode* transform_node =
784 property_trees->transform_tree.UpdateNodeFromOwningLayerId(id())) {
785 DCHECK_EQ(transform_tree_index(), transform_node->id);
786 transform_node->scroll_offset = CurrentScrollOffset();
787 transform_node->needs_local_transform_update = true;
788 property_trees->transform_tree.set_needs_update(true);
789 }
790 780
791 SetNeedsCommit(); 781 SetNeedsCommit();
792 } 782 }
793 783
794 void Layer::SetScrollOffsetFromImplSide( 784 void Layer::SetScrollOffsetFromImplSide(
795 const gfx::ScrollOffset& scroll_offset) { 785 const gfx::ScrollOffset& scroll_offset) {
796 DCHECK(IsPropertyChangeAllowed()); 786 DCHECK(IsPropertyChangeAllowed());
797 // This function only gets called during a BeginMainFrame, so there 787 // This function only gets called during a BeginMainFrame, so there
798 // is no need to call SetNeedsUpdate here. 788 // is no need to call SetNeedsUpdate here.
799 DCHECK(layer_tree_host_ && layer_tree_host_->CommitRequested()); 789 DCHECK(layer_tree_host_ && layer_tree_host_->CommitRequested());
800 if (inputs_.scroll_offset == scroll_offset) 790 if (inputs_.scroll_offset == scroll_offset)
801 return; 791 return;
802 inputs_.scroll_offset = scroll_offset; 792 inputs_.scroll_offset = scroll_offset;
803 SetNeedsPushProperties(); 793 SetNeedsPushProperties();
804 794
805 PropertyTrees* property_trees = layer_tree_host_->property_trees(); 795 UpdateScrollOffset(scroll_offset);
806 if (scroll_tree_index() != ScrollTree::kInvalidNodeId && scrollable())
807 property_trees->scroll_tree.SetScrollOffset(id(), scroll_offset);
808
809 if (TransformNode* transform_node =
810 property_trees->transform_tree.UpdateNodeFromOwningLayerId(id())) {
811 DCHECK_EQ(transform_tree_index(), transform_node->id);
812 transform_node->scroll_offset = CurrentScrollOffset();
813 transform_node->needs_local_transform_update = true;
814 property_trees->transform_tree.set_needs_update(true);
815 }
816 796
817 if (!inputs_.did_scroll_callback.is_null()) 797 if (!inputs_.did_scroll_callback.is_null())
818 inputs_.did_scroll_callback.Run(scroll_offset); 798 inputs_.did_scroll_callback.Run(scroll_offset);
819 799
820 // The callback could potentially change the layer structure: 800 // The callback could potentially change the layer structure:
821 // "this" may have been destroyed during the process. 801 // "this" may have been destroyed during the process.
822 } 802 }
823 803
804 void Layer::UpdateScrollOffset(const gfx::ScrollOffset& scroll_offset) {
805 DCHECK(scrollable());
806 if (scroll_tree_index() == ScrollTree::kInvalidNodeId) {
807 // Ensure the property trees just have not been built yet but are marked for
808 // being built which will set the correct scroll offset values.
809 DCHECK(layer_tree_host_->property_trees()->needs_rebuild);
810 return;
811 }
812
813 // If a scroll node exists, it should have an associated transform node.
814 DCHECK(transform_tree_index() != TransformTree::kInvalidNodeId);
815
816 auto& property_trees = *layer_tree_host_->property_trees();
817 property_trees.scroll_tree.SetScrollOffset(id(), scroll_offset);
818 auto* transform_node =
819 property_trees.transform_tree.Node(transform_tree_index());
820 DCHECK_EQ(transform_tree_index(), transform_node->id);
821 transform_node->scroll_offset = CurrentScrollOffset();
822 transform_node->needs_local_transform_update = true;
823 property_trees.transform_tree.set_needs_update(true);
824 }
825
824 void Layer::SetScrollClipLayerId(int clip_layer_id) { 826 void Layer::SetScrollClipLayerId(int clip_layer_id) {
825 DCHECK(IsPropertyChangeAllowed()); 827 DCHECK(IsPropertyChangeAllowed());
826 if (inputs_.scroll_clip_layer_id == clip_layer_id) 828 if (inputs_.scroll_clip_layer_id == clip_layer_id)
827 return; 829 return;
828 inputs_.scroll_clip_layer_id = clip_layer_id; 830 inputs_.scroll_clip_layer_id = clip_layer_id;
829 SetPropertyTreesNeedRebuild(); 831 SetPropertyTreesNeedRebuild();
830 SetNeedsCommit(); 832 SetNeedsCommit();
831 } 833 }
832 834
833 Layer* Layer::scroll_clip_layer() const { 835 Layer* Layer::scroll_clip_layer() const {
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after
1441 ->subtree_has_copy_request; 1443 ->subtree_has_copy_request;
1442 } 1444 }
1443 1445
1444 gfx::Transform Layer::ScreenSpaceTransform() const { 1446 gfx::Transform Layer::ScreenSpaceTransform() const {
1445 DCHECK_NE(transform_tree_index_, TransformTree::kInvalidNodeId); 1447 DCHECK_NE(transform_tree_index_, TransformTree::kInvalidNodeId);
1446 return draw_property_utils::ScreenSpaceTransform( 1448 return draw_property_utils::ScreenSpaceTransform(
1447 this, layer_tree_host_->property_trees()->transform_tree); 1449 this, layer_tree_host_->property_trees()->transform_tree);
1448 } 1450 }
1449 1451
1450 } // namespace cc 1452 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/layer.h ('k') | cc/layers/scrollbar_layer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698