Skip to content

Commit 64b691c

Browse files
progersCommit bot
authored and
Commit bot
committed
Cleanup the Layer::SetScrollOffset{FromImplSide} property tree fast-path
This patch updates Layer::SetScrollOffset{FromImplSide} to clarify how the scroll offset fast-path works: 1) Existing property nodes are updated if they exist without invalidating the property trees. 2) If no existing property nodes exist, the property trees should already be marked as needig a full rebuild which will update the scroll offset. DCHECKs have been added to clarify: * SetScrollOffset should not be called for non-scrollable Layers. * The scroll transform node does not need to be looked up using layer ids because it is available via the Layer's transform_node_index(). This patch removes two users of transform node's owning layer id. BUG=693740 CQ_INCLUDE_TRYBOTS=master.tryserver.blink:linux_trusty_blink_rel;master.tryserver.chromium.linux:linux_layout_tests_slimming_paint_v2 Review-Url: https://codereview.chromium.org/2877673002 Cr-Commit-Position: refs/heads/master@{#471490}
1 parent 5cd5e67 commit 64b691c

File tree

4 files changed

+36
-22
lines changed

4 files changed

+36
-22
lines changed

cc/layers/layer.cc

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -771,17 +771,7 @@ void Layer::SetScrollOffset(const gfx::ScrollOffset& scroll_offset) {
771771
if (!layer_tree_host_)
772772
return;
773773

774-
PropertyTrees* property_trees = layer_tree_host_->property_trees();
775-
if (scroll_tree_index() != ScrollTree::kInvalidNodeId && scrollable())
776-
property_trees->scroll_tree.SetScrollOffset(id(), scroll_offset);
777-
778-
if (TransformNode* transform_node =
779-
property_trees->transform_tree.UpdateNodeFromOwningLayerId(id())) {
780-
DCHECK_EQ(transform_tree_index(), transform_node->id);
781-
transform_node->scroll_offset = CurrentScrollOffset();
782-
transform_node->needs_local_transform_update = true;
783-
property_trees->transform_tree.set_needs_update(true);
784-
}
774+
UpdateScrollOffset(scroll_offset);
785775

786776
SetNeedsCommit();
787777
}
@@ -797,17 +787,7 @@ void Layer::SetScrollOffsetFromImplSide(
797787
inputs_.scroll_offset = scroll_offset;
798788
SetNeedsPushProperties();
799789

800-
PropertyTrees* property_trees = layer_tree_host_->property_trees();
801-
if (scroll_tree_index() != ScrollTree::kInvalidNodeId && scrollable())
802-
property_trees->scroll_tree.SetScrollOffset(id(), scroll_offset);
803-
804-
if (TransformNode* transform_node =
805-
property_trees->transform_tree.UpdateNodeFromOwningLayerId(id())) {
806-
DCHECK_EQ(transform_tree_index(), transform_node->id);
807-
transform_node->scroll_offset = CurrentScrollOffset();
808-
transform_node->needs_local_transform_update = true;
809-
property_trees->transform_tree.set_needs_update(true);
810-
}
790+
UpdateScrollOffset(scroll_offset);
811791

812792
if (!inputs_.did_scroll_callback.is_null())
813793
inputs_.did_scroll_callback.Run(scroll_offset);
@@ -816,6 +796,28 @@ void Layer::SetScrollOffsetFromImplSide(
816796
// "this" may have been destroyed during the process.
817797
}
818798

799+
void Layer::UpdateScrollOffset(const gfx::ScrollOffset& scroll_offset) {
800+
DCHECK(scrollable());
801+
if (scroll_tree_index() == ScrollTree::kInvalidNodeId) {
802+
// Ensure the property trees just have not been built yet but are marked for
803+
// being built which will set the correct scroll offset values.
804+
DCHECK(layer_tree_host_->property_trees()->needs_rebuild);
805+
return;
806+
}
807+
808+
// If a scroll node exists, it should have an associated transform node.
809+
DCHECK(transform_tree_index() != TransformTree::kInvalidNodeId);
810+
811+
auto& property_trees = *layer_tree_host_->property_trees();
812+
property_trees.scroll_tree.SetScrollOffset(id(), scroll_offset);
813+
auto* transform_node =
814+
property_trees.transform_tree.Node(transform_tree_index());
815+
DCHECK_EQ(transform_tree_index(), transform_node->id);
816+
transform_node->scroll_offset = CurrentScrollOffset();
817+
transform_node->needs_local_transform_update = true;
818+
property_trees.transform_tree.set_needs_update(true);
819+
}
820+
819821
void Layer::SetScrollClipLayerId(int clip_layer_id) {
820822
DCHECK(IsPropertyChangeAllowed());
821823
if (inputs_.scroll_clip_layer_id == clip_layer_id)

cc/layers/layer.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,12 @@ class CC_EXPORT Layer : public base::RefCounted<Layer> {
502502
// layer should own a property tree node or not.
503503
void SetPropertyTreesNeedRebuild();
504504

505+
// Fast-path for |SetScrollOffset| and |SetScrollOffsetFromImplSide| to
506+
// directly update scroll offset values in the property tree without needing a
507+
// full property tree update. If property trees do not exist yet, ensures
508+
// they are marked as needing to be rebuilt.
509+
void UpdateScrollOffset(const gfx::ScrollOffset&);
510+
505511
// Encapsulates all data, callbacks or interfaces received from the embedder.
506512
// TODO(khushalsagar): This is only valid when PropertyTrees are built
507513
// internally in cc. Update this for the SPv2 path where blink generates

cc/layers/scrollbar_layer_unittest.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,7 @@ TEST_F(ScrollbarLayerTest, ThumbRect) {
437437

438438
// Over-scroll (thumb position should clamp on the far side).
439439
root_layer->SetScrollOffset(gfx::ScrollOffset(85, 0));
440+
layer_tree_host_->UpdateLayers();
440441

441442
UPDATE_AND_EXTRACT_LAYER_POINTERS();
442443
EXPECT_EQ(gfx::Rect(56, 0, 4, 10).ToString(),
@@ -909,6 +910,7 @@ class ScrollbarLayerTestResourceCreationAndRelease : public ScrollbarLayerTest {
909910
int expected_deleted,
910911
bool use_solid_color_scrollbar) {
911912
std::unique_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, false));
913+
scoped_refptr<Layer> root_clip_layer = Layer::Create();
912914
scoped_refptr<Layer> layer_tree_root = Layer::Create();
913915
scoped_refptr<Layer> content_layer = Layer::Create();
914916
scoped_refptr<Layer> scrollbar_layer;
@@ -930,6 +932,7 @@ class ScrollbarLayerTestResourceCreationAndRelease : public ScrollbarLayerTest {
930932

931933
scrollbar_layer->SetIsDrawable(true);
932934
scrollbar_layer->SetBounds(gfx::Size(100, 100));
935+
layer_tree_root->SetScrollClipLayerId(root_clip_layer->id());
933936
layer_tree_root->SetScrollOffset(gfx::ScrollOffset(10, 20));
934937
layer_tree_root->SetBounds(gfx::Size(100, 200));
935938
content_layer->SetBounds(gfx::Size(100, 200));

third_party/WebKit/Source/platform/graphics/compositing/PaintArtifactCompositorTest.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,9 @@ TEST_F(PaintArtifactCompositorTestWithPropertyTrees, OneScrollNode) {
770770
EXPECT_EQ(transform_node_index, transform_node.id);
771771

772772
EXPECT_EQ(0u, scroll_client.did_scroll_count);
773+
// TODO(pdr): The PaintArtifactCompositor should set the scroll clip layer id
774+
// so the Layer is scrollable. This call should be removed.
775+
layer->SetScrollClipLayerId(layer->id());
773776
layer->SetScrollOffsetFromImplSide(gfx::ScrollOffset(1, 2));
774777
EXPECT_EQ(1u, scroll_client.did_scroll_count);
775778
EXPECT_EQ(gfx::ScrollOffset(1, 2), scroll_client.last_scroll_offset);

0 commit comments

Comments
 (0)