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

Side by Side Diff: cc/trees/layer_tree_host_unittest_scroll.cc

Issue 1905713002: cc: Remove LayerImpl::children() calls from descendants of LayerTreeTest (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Resolve comments Created 4 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
« no previous file with comments | « cc/trees/layer_tree_host_unittest_picture.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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/trees/layer_tree_host.h" 5 #include "cc/trees/layer_tree_host.h"
6 6
7 #include "base/location.h" 7 #include "base/location.h"
8 #include "base/memory/weak_ptr.h" 8 #include "base/memory/weak_ptr.h"
9 #include "base/single_thread_task_runner.h" 9 #include "base/single_thread_task_runner.h"
10 #include "base/thread_task_runner_handle.h" 10 #include "base/thread_task_runner_handle.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 78
79 class LayerTreeHostScrollTestScrollSimple : public LayerTreeHostScrollTest { 79 class LayerTreeHostScrollTestScrollSimple : public LayerTreeHostScrollTest {
80 public: 80 public:
81 LayerTreeHostScrollTestScrollSimple() 81 LayerTreeHostScrollTestScrollSimple()
82 : initial_scroll_(10, 20), 82 : initial_scroll_(10, 20),
83 second_scroll_(40, 5), 83 second_scroll_(40, 5),
84 scroll_amount_(2, -1), 84 scroll_amount_(2, -1),
85 num_scrolls_(0) {} 85 num_scrolls_(0) {}
86 86
87 void BeginTest() override { 87 void BeginTest() override {
88 outer_viewport_container_layer_id_ = layer_tree_host()
89 ->outer_viewport_scroll_layer()
90 ->scroll_clip_layer()
91 ->id();
88 layer_tree_host()->outer_viewport_scroll_layer()->SetScrollOffset( 92 layer_tree_host()->outer_viewport_scroll_layer()->SetScrollOffset(
89 initial_scroll_); 93 initial_scroll_);
90 PostSetNeedsCommitToMainThread(); 94 PostSetNeedsCommitToMainThread();
91 } 95 }
92 96
93 void UpdateLayerTreeHost() override { 97 void UpdateLayerTreeHost() override {
94 Layer* scroll_layer = layer_tree_host()->outer_viewport_scroll_layer(); 98 Layer* scroll_layer = layer_tree_host()->outer_viewport_scroll_layer();
95 if (!layer_tree_host()->source_frame_number()) { 99 if (!layer_tree_host()->source_frame_number()) {
96 EXPECT_VECTOR_EQ(initial_scroll_, scroll_layer->scroll_offset()); 100 EXPECT_VECTOR_EQ(initial_scroll_, scroll_layer->scroll_offset());
97 } else { 101 } else {
98 EXPECT_VECTOR_EQ(gfx::ScrollOffsetWithDelta(initial_scroll_, 102 EXPECT_VECTOR_EQ(gfx::ScrollOffsetWithDelta(initial_scroll_,
99 scroll_amount_), 103 scroll_amount_),
100 scroll_layer->scroll_offset()); 104 scroll_layer->scroll_offset());
101 105
102 // Pretend like Javascript updated the scroll position itself. 106 // Pretend like Javascript updated the scroll position itself.
103 scroll_layer->SetScrollOffset(second_scroll_); 107 scroll_layer->SetScrollOffset(second_scroll_);
104 } 108 }
105 } 109 }
106 110
107 void DrawLayersOnThread(LayerTreeHostImpl* impl) override { 111 void DrawLayersOnThread(LayerTreeHostImpl* impl) override {
108 LayerImpl* root = impl->active_tree()->root_layer(); 112 LayerImpl* root = impl->active_tree()->root_layer();
109 LayerImpl* scroll_layer = impl->OuterViewportScrollLayer(); 113 LayerImpl* scroll_layer = impl->OuterViewportScrollLayer();
110 EXPECT_VECTOR_EQ(gfx::Vector2d(), ScrollDelta(scroll_layer)); 114 EXPECT_VECTOR_EQ(gfx::Vector2d(), ScrollDelta(scroll_layer));
111 115
112 scroll_layer->SetScrollClipLayer(root->children()[0]->id()); 116 scroll_layer->SetScrollClipLayer(outer_viewport_container_layer_id_);
113 scroll_layer->SetBounds( 117 scroll_layer->SetBounds(
114 gfx::Size(root->bounds().width() + 100, root->bounds().height() + 100)); 118 gfx::Size(root->bounds().width() + 100, root->bounds().height() + 100));
115 scroll_layer->ScrollBy(scroll_amount_); 119 scroll_layer->ScrollBy(scroll_amount_);
116 120
117 switch (impl->active_tree()->source_frame_number()) { 121 switch (impl->active_tree()->source_frame_number()) {
118 case 0: 122 case 0:
119 EXPECT_VECTOR_EQ(initial_scroll_, ScrollTreeForLayer(scroll_layer) 123 EXPECT_VECTOR_EQ(initial_scroll_, ScrollTreeForLayer(scroll_layer)
120 ->GetScrollOffsetBaseForTesting( 124 ->GetScrollOffsetBaseForTesting(
121 scroll_layer->id())); 125 scroll_layer->id()));
122 EXPECT_VECTOR_EQ(scroll_amount_, ScrollDelta(scroll_layer)); 126 EXPECT_VECTOR_EQ(scroll_amount_, ScrollDelta(scroll_layer));
(...skipping 17 matching lines...) Expand all
140 num_scrolls_++; 144 num_scrolls_++;
141 } 145 }
142 146
143 void AfterTest() override { EXPECT_EQ(1, num_scrolls_); } 147 void AfterTest() override { EXPECT_EQ(1, num_scrolls_); }
144 148
145 private: 149 private:
146 gfx::ScrollOffset initial_scroll_; 150 gfx::ScrollOffset initial_scroll_;
147 gfx::ScrollOffset second_scroll_; 151 gfx::ScrollOffset second_scroll_;
148 gfx::Vector2dF scroll_amount_; 152 gfx::Vector2dF scroll_amount_;
149 int num_scrolls_; 153 int num_scrolls_;
154 int outer_viewport_container_layer_id_;
150 }; 155 };
151 156
152 MULTI_THREAD_TEST_F(LayerTreeHostScrollTestScrollSimple); 157 MULTI_THREAD_TEST_F(LayerTreeHostScrollTestScrollSimple);
153 158
154 class LayerTreeHostScrollTestScrollMultipleRedraw 159 class LayerTreeHostScrollTestScrollMultipleRedraw
155 : public LayerTreeHostScrollTest { 160 : public LayerTreeHostScrollTest {
156 public: 161 public:
157 LayerTreeHostScrollTestScrollMultipleRedraw() 162 LayerTreeHostScrollTestScrollMultipleRedraw()
158 : initial_scroll_(40, 10), scroll_amount_(-3, 17), num_scrolls_(0) {} 163 : initial_scroll_(40, 10), scroll_amount_(-3, 17), num_scrolls_(0) {}
159 164
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 expected_scroll_layer_->scroll_offset()); 604 expected_scroll_layer_->scroll_offset());
600 break; 605 break;
601 } 606 }
602 } 607 }
603 608
604 void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override { 609 void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override {
605 LayerImpl* inner_scroll = impl->InnerViewportScrollLayer(); 610 LayerImpl* inner_scroll = impl->InnerViewportScrollLayer();
606 FakePictureLayerImpl* root_scroll_layer_impl = 611 FakePictureLayerImpl* root_scroll_layer_impl =
607 static_cast<FakePictureLayerImpl*>(impl->OuterViewportScrollLayer()); 612 static_cast<FakePictureLayerImpl*>(impl->OuterViewportScrollLayer());
608 FakePictureLayerImpl* child_layer_impl = static_cast<FakePictureLayerImpl*>( 613 FakePictureLayerImpl* child_layer_impl = static_cast<FakePictureLayerImpl*>(
609 root_scroll_layer_impl->children()[0]); 614 root_scroll_layer_impl->layer_tree_impl()->LayerById(
615 child_layer_->id()));
610 616
611 LayerImpl* expected_scroll_layer_impl = NULL; 617 LayerImpl* expected_scroll_layer_impl = NULL;
612 LayerImpl* expected_no_scroll_layer_impl = NULL; 618 LayerImpl* expected_no_scroll_layer_impl = NULL;
613 if (scroll_child_layer_) { 619 if (scroll_child_layer_) {
614 expected_scroll_layer_impl = child_layer_impl; 620 expected_scroll_layer_impl = child_layer_impl;
615 expected_no_scroll_layer_impl = root_scroll_layer_impl; 621 expected_no_scroll_layer_impl = root_scroll_layer_impl;
616 } else { 622 } else {
617 expected_scroll_layer_impl = root_scroll_layer_impl; 623 expected_scroll_layer_impl = root_scroll_layer_impl;
618 expected_no_scroll_layer_impl = child_layer_impl; 624 expected_no_scroll_layer_impl = child_layer_impl;
619 } 625 }
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
1068 }; 1074 };
1069 1075
1070 // This tests scrolling on the impl side which is only possible with a thread. 1076 // This tests scrolling on the impl side which is only possible with a thread.
1071 MULTI_THREAD_TEST_F(LayerTreeHostScrollTestImplOnlyScroll); 1077 MULTI_THREAD_TEST_F(LayerTreeHostScrollTestImplOnlyScroll);
1072 1078
1073 class LayerTreeHostScrollTestScrollZeroMaxScrollOffset 1079 class LayerTreeHostScrollTestScrollZeroMaxScrollOffset
1074 : public LayerTreeHostScrollTest { 1080 : public LayerTreeHostScrollTest {
1075 public: 1081 public:
1076 LayerTreeHostScrollTestScrollZeroMaxScrollOffset() {} 1082 LayerTreeHostScrollTestScrollZeroMaxScrollOffset() {}
1077 1083
1078 void BeginTest() override { PostSetNeedsCommitToMainThread(); } 1084 void BeginTest() override {
1085 outer_viewport_container_layer_id_ = layer_tree_host()
1086 ->outer_viewport_scroll_layer()
1087 ->scroll_clip_layer()
1088 ->id();
1089 PostSetNeedsCommitToMainThread();
1090 }
1079 1091
1080 void DrawLayersOnThread(LayerTreeHostImpl* impl) override { 1092 void DrawLayersOnThread(LayerTreeHostImpl* impl) override {
1081 LayerImpl* root = impl->active_tree()->root_layer(); 1093 LayerImpl* root = impl->active_tree()->root_layer();
1082 LayerImpl* scroll_layer = impl->OuterViewportScrollLayer(); 1094 LayerImpl* scroll_layer = impl->OuterViewportScrollLayer();
1083 scroll_layer->SetScrollClipLayer(root->children()[0]->id()); 1095 scroll_layer->SetScrollClipLayer(outer_viewport_container_layer_id_);
1084 1096
1085 // Set max_scroll_offset = (100, 100). 1097 // Set max_scroll_offset = (100, 100).
1086 scroll_layer->SetBounds( 1098 scroll_layer->SetBounds(
1087 gfx::Size(root->bounds().width() + 100, root->bounds().height() + 100)); 1099 gfx::Size(root->bounds().width() + 100, root->bounds().height() + 100));
1088 impl->active_tree()->property_trees()->needs_rebuild = true; 1100 impl->active_tree()->property_trees()->needs_rebuild = true;
1089 impl->active_tree()->BuildPropertyTreesForTesting(); 1101 impl->active_tree()->BuildPropertyTreesForTesting();
1090 1102
1091 ScrollTree& scroll_tree = 1103 ScrollTree& scroll_tree =
1092 impl->active_tree()->property_trees()->scroll_tree; 1104 impl->active_tree()->property_trees()->scroll_tree;
1093 ScrollNode* scroll_node = 1105 ScrollNode* scroll_node =
(...skipping 28 matching lines...) Expand all
1122 status = impl->TryScroll(gfx::PointF(0.0f, 1.0f), InputHandler::TOUCHSCREEN, 1134 status = impl->TryScroll(gfx::PointF(0.0f, 1.0f), InputHandler::TOUCHSCREEN,
1123 scroll_tree, scroll_node); 1135 scroll_tree, scroll_node);
1124 EXPECT_EQ(InputHandler::SCROLL_IGNORED, status.thread); 1136 EXPECT_EQ(InputHandler::SCROLL_IGNORED, status.thread);
1125 EXPECT_EQ(MainThreadScrollingReason::kNotScrollable, 1137 EXPECT_EQ(MainThreadScrollingReason::kNotScrollable,
1126 status.main_thread_scrolling_reasons); 1138 status.main_thread_scrolling_reasons);
1127 1139
1128 EndTest(); 1140 EndTest();
1129 } 1141 }
1130 1142
1131 void AfterTest() override {} 1143 void AfterTest() override {}
1144
1145 private:
1146 int outer_viewport_container_layer_id_;
1132 }; 1147 };
1133 1148
1134 SINGLE_AND_MULTI_THREAD_TEST_F( 1149 SINGLE_AND_MULTI_THREAD_TEST_F(
1135 LayerTreeHostScrollTestScrollZeroMaxScrollOffset); 1150 LayerTreeHostScrollTestScrollZeroMaxScrollOffset);
1136 1151
1137 class LayerTreeHostScrollTestScrollNonDrawnLayer 1152 class LayerTreeHostScrollTestScrollNonDrawnLayer
1138 : public LayerTreeHostScrollTest { 1153 : public LayerTreeHostScrollTest {
1139 public: 1154 public:
1140 LayerTreeHostScrollTestScrollNonDrawnLayer() {} 1155 LayerTreeHostScrollTestScrollNonDrawnLayer() {}
1141 1156
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
1424 RunTest(CompositorMode::THREADED, false); 1439 RunTest(CompositorMode::THREADED, false);
1425 } 1440 }
1426 1441
1427 TEST_F(LayerTreeHostScrollTestLayerStructureChange, ScrollDestroyWholeTree) { 1442 TEST_F(LayerTreeHostScrollTestLayerStructureChange, ScrollDestroyWholeTree) {
1428 scroll_destroy_whole_tree_ = true; 1443 scroll_destroy_whole_tree_ = true;
1429 RunTest(CompositorMode::THREADED, false); 1444 RunTest(CompositorMode::THREADED, false);
1430 } 1445 }
1431 1446
1432 } // namespace 1447 } // namespace
1433 } // namespace cc 1448 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_unittest_picture.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698