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

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

Issue 146713002: Revert of Pinch/Zoom Infrastructure & Plumbing CL (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « cc/trees/layer_tree_host_unittest_damage.cc ('k') | cc/trees/layer_tree_impl.h » ('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 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/memory/weak_ptr.h" 7 #include "base/memory/weak_ptr.h"
8 #include "cc/layers/content_layer.h" 8 #include "cc/layers/content_layer.h"
9 #include "cc/layers/layer.h" 9 #include "cc/layers/layer.h"
10 #include "cc/layers/layer_impl.h" 10 #include "cc/layers/layer_impl.h"
(...skipping 13 matching lines...) Expand all
24 24
25 class LayerTreeHostScrollTestScrollSimple : public LayerTreeHostScrollTest { 25 class LayerTreeHostScrollTestScrollSimple : public LayerTreeHostScrollTest {
26 public: 26 public:
27 LayerTreeHostScrollTestScrollSimple() 27 LayerTreeHostScrollTestScrollSimple()
28 : initial_scroll_(10, 20), 28 : initial_scroll_(10, 20),
29 second_scroll_(40, 5), 29 second_scroll_(40, 5),
30 scroll_amount_(2, -1), 30 scroll_amount_(2, -1),
31 num_scrolls_(0) {} 31 num_scrolls_(0) {}
32 32
33 virtual void BeginTest() OVERRIDE { 33 virtual void BeginTest() OVERRIDE {
34 Layer* root_layer = layer_tree_host()->root_layer(); 34 layer_tree_host()->root_layer()->SetScrollable(true);
35 scoped_refptr<Layer> scroll_layer = Layer::Create(); 35 layer_tree_host()->root_layer()
36 root_layer->AddChild(scroll_layer); 36 ->SetMaxScrollOffset(gfx::Vector2d(100, 100));
37 // Create an effective max_scroll_offset of (100, 100). 37 layer_tree_host()->root_layer()->SetScrollOffset(initial_scroll_);
38 scroll_layer->SetBounds(gfx::Size(root_layer->bounds().width() + 100,
39 root_layer->bounds().height() + 100));
40 scroll_layer->SetIsDrawable(true);
41 scroll_layer->SetIsContainerForFixedPositionLayers(true);
42 scroll_layer->SetScrollClipLayer(root_layer);
43 scroll_layer->SetScrollOffset(initial_scroll_);
44 layer_tree_host()->RegisterViewportLayers(root_layer, scroll_layer, NULL);
45 PostSetNeedsCommitToMainThread(); 38 PostSetNeedsCommitToMainThread();
46 } 39 }
47 40
48 virtual void Layout() OVERRIDE { 41 virtual void Layout() OVERRIDE {
49 Layer* root = layer_tree_host()->root_layer(); 42 Layer* root = layer_tree_host()->root_layer();
50 Layer* scroll_layer = root->children()[0];
51 if (!layer_tree_host()->source_frame_number()) { 43 if (!layer_tree_host()->source_frame_number()) {
52 EXPECT_VECTOR_EQ(initial_scroll_, scroll_layer->scroll_offset()); 44 EXPECT_VECTOR_EQ(initial_scroll_, root->scroll_offset());
53 } else { 45 } else {
54 EXPECT_VECTOR_EQ(initial_scroll_ + scroll_amount_, 46 EXPECT_VECTOR_EQ(initial_scroll_ + scroll_amount_, root->scroll_offset());
55 scroll_layer->scroll_offset());
56 47
57 // Pretend like Javascript updated the scroll position itself. 48 // Pretend like Javascript updated the scroll position itself.
58 scroll_layer->SetScrollOffset(second_scroll_); 49 root->SetScrollOffset(second_scroll_);
59 } 50 }
60 } 51 }
61 52
62 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { 53 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE {
63 LayerImpl* root = impl->active_tree()->root_layer(); 54 LayerImpl* root = impl->active_tree()->root_layer();
64 LayerImpl* scroll_layer = root->children()[0]; 55 EXPECT_VECTOR_EQ(gfx::Vector2d(), root->ScrollDelta());
65 EXPECT_VECTOR_EQ(gfx::Vector2d(), scroll_layer->ScrollDelta());
66 56
67 scroll_layer->SetScrollClipLayer(root->id()); 57 root->SetScrollable(true);
68 scroll_layer->SetBounds( 58 root->SetMaxScrollOffset(gfx::Vector2d(100, 100));
69 gfx::Size(root->bounds().width() + 100, root->bounds().height() + 100)); 59 root->ScrollBy(scroll_amount_);
70 scroll_layer->ScrollBy(scroll_amount_);
71 60
72 switch (impl->active_tree()->source_frame_number()) { 61 switch (impl->active_tree()->source_frame_number()) {
73 case 0: 62 case 0:
74 EXPECT_VECTOR_EQ(initial_scroll_, scroll_layer->scroll_offset()); 63 EXPECT_VECTOR_EQ(initial_scroll_, root->scroll_offset());
75 EXPECT_VECTOR_EQ(scroll_amount_, scroll_layer->ScrollDelta()); 64 EXPECT_VECTOR_EQ(scroll_amount_, root->ScrollDelta());
76 PostSetNeedsCommitToMainThread(); 65 PostSetNeedsCommitToMainThread();
77 break; 66 break;
78 case 1: 67 case 1:
79 EXPECT_VECTOR_EQ(scroll_layer->scroll_offset(), second_scroll_); 68 EXPECT_VECTOR_EQ(root->scroll_offset(), second_scroll_);
80 EXPECT_VECTOR_EQ(scroll_layer->ScrollDelta(), scroll_amount_); 69 EXPECT_VECTOR_EQ(root->ScrollDelta(), scroll_amount_);
81 EndTest(); 70 EndTest();
82 break; 71 break;
83 } 72 }
84 } 73 }
85 74
86 virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta, 75 virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta,
87 float scale) OVERRIDE { 76 float scale) OVERRIDE {
88 num_scrolls_++; 77 num_scrolls_++;
89 } 78 }
90 79
91 virtual void AfterTest() OVERRIDE { EXPECT_EQ(1, num_scrolls_); } 80 virtual void AfterTest() OVERRIDE { EXPECT_EQ(1, num_scrolls_); }
92 81
93 private: 82 private:
94 gfx::Vector2d initial_scroll_; 83 gfx::Vector2d initial_scroll_;
95 gfx::Vector2d second_scroll_; 84 gfx::Vector2d second_scroll_;
96 gfx::Vector2d scroll_amount_; 85 gfx::Vector2d scroll_amount_;
97 int num_scrolls_; 86 int num_scrolls_;
98 }; 87 };
99 88
100 MULTI_THREAD_TEST_F(LayerTreeHostScrollTestScrollSimple); 89 MULTI_THREAD_TEST_F(LayerTreeHostScrollTestScrollSimple);
101 90
102 class LayerTreeHostScrollTestScrollMultipleRedraw 91 class LayerTreeHostScrollTestScrollMultipleRedraw
103 : public LayerTreeHostScrollTest { 92 : public LayerTreeHostScrollTest {
104 public: 93 public:
105 LayerTreeHostScrollTestScrollMultipleRedraw() 94 LayerTreeHostScrollTestScrollMultipleRedraw()
106 : initial_scroll_(40, 10), scroll_amount_(-3, 17), num_scrolls_(0) {} 95 : initial_scroll_(40, 10), scroll_amount_(-3, 17), num_scrolls_(0) {}
107 96
108 virtual void BeginTest() OVERRIDE { 97 virtual void BeginTest() OVERRIDE {
109 Layer* root_layer = layer_tree_host()->root_layer(); 98 layer_tree_host()->root_layer()->SetScrollable(true);
110 scroll_layer_ = Layer::Create(); 99 layer_tree_host()->root_layer()->SetScrollOffset(initial_scroll_);
111 root_layer->AddChild(scroll_layer_); 100 layer_tree_host()->root_layer()->SetBounds(gfx::Size(200, 200));
112 // Create an effective max_scroll_offset of (100, 100). 101 layer_tree_host()->root_layer()
113 scroll_layer_->SetBounds(gfx::Size(root_layer->bounds().width() + 100, 102 ->SetMaxScrollOffset(gfx::Vector2d(100, 100));
114 root_layer->bounds().height() + 100));
115 scroll_layer_->SetIsDrawable(true);
116 scroll_layer_->SetIsContainerForFixedPositionLayers(true);
117 scroll_layer_->SetScrollClipLayer(root_layer);
118 scroll_layer_->SetScrollOffset(initial_scroll_);
119 layer_tree_host()->RegisterViewportLayers(root_layer, scroll_layer_, NULL);
120 PostSetNeedsCommitToMainThread(); 103 PostSetNeedsCommitToMainThread();
121 } 104 }
122 105
123 virtual void BeginCommitOnThread(LayerTreeHostImpl* impl) OVERRIDE { 106 virtual void BeginCommitOnThread(LayerTreeHostImpl* impl) OVERRIDE {
107 Layer* root = layer_tree_host()->root_layer();
124 switch (layer_tree_host()->source_frame_number()) { 108 switch (layer_tree_host()->source_frame_number()) {
125 case 0: 109 case 0:
126 EXPECT_VECTOR_EQ(scroll_layer_->scroll_offset(), initial_scroll_); 110 EXPECT_VECTOR_EQ(root->scroll_offset(), initial_scroll_);
127 break; 111 break;
128 case 1: 112 case 1:
129 EXPECT_VECTOR_EQ(scroll_layer_->scroll_offset(), 113 EXPECT_VECTOR_EQ(root->scroll_offset(),
130 initial_scroll_ + scroll_amount_ + scroll_amount_); 114 initial_scroll_ + scroll_amount_ + scroll_amount_);
131 case 2: 115 case 2:
132 EXPECT_VECTOR_EQ(scroll_layer_->scroll_offset(), 116 EXPECT_VECTOR_EQ(root->scroll_offset(),
133 initial_scroll_ + scroll_amount_ + scroll_amount_); 117 initial_scroll_ + scroll_amount_ + scroll_amount_);
134 break; 118 break;
135 } 119 }
136 } 120 }
137 121
138 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { 122 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE {
139 LayerImpl* scroll_layer = 123 LayerImpl* root = impl->active_tree()->root_layer();
140 impl->active_tree()->LayerById(scroll_layer_->id());
141 if (impl->active_tree()->source_frame_number() == 0 && 124 if (impl->active_tree()->source_frame_number() == 0 &&
142 impl->SourceAnimationFrameNumber() == 1) { 125 impl->SourceAnimationFrameNumber() == 1) {
143 // First draw after first commit. 126 // First draw after first commit.
144 EXPECT_VECTOR_EQ(scroll_layer->ScrollDelta(), gfx::Vector2d()); 127 EXPECT_VECTOR_EQ(root->ScrollDelta(), gfx::Vector2d());
145 scroll_layer->ScrollBy(scroll_amount_); 128 root->ScrollBy(scroll_amount_);
146 EXPECT_VECTOR_EQ(scroll_layer->ScrollDelta(), scroll_amount_); 129 EXPECT_VECTOR_EQ(root->ScrollDelta(), scroll_amount_);
147 130
148 EXPECT_VECTOR_EQ(scroll_layer->scroll_offset(), initial_scroll_); 131 EXPECT_VECTOR_EQ(root->scroll_offset(), initial_scroll_);
149 PostSetNeedsRedrawToMainThread(); 132 PostSetNeedsRedrawToMainThread();
150 } else if (impl->active_tree()->source_frame_number() == 0 && 133 } else if (impl->active_tree()->source_frame_number() == 0 &&
151 impl->SourceAnimationFrameNumber() == 2) { 134 impl->SourceAnimationFrameNumber() == 2) {
152 // Second draw after first commit. 135 // Second draw after first commit.
153 EXPECT_EQ(scroll_layer->ScrollDelta(), scroll_amount_); 136 EXPECT_EQ(root->ScrollDelta(), scroll_amount_);
154 scroll_layer->ScrollBy(scroll_amount_); 137 root->ScrollBy(scroll_amount_);
155 EXPECT_VECTOR_EQ(scroll_layer->ScrollDelta(), 138 EXPECT_VECTOR_EQ(root->ScrollDelta(), scroll_amount_ + scroll_amount_);
156 scroll_amount_ + scroll_amount_);
157 139
158 EXPECT_VECTOR_EQ(scroll_layer_->scroll_offset(), initial_scroll_); 140 EXPECT_VECTOR_EQ(root->scroll_offset(), initial_scroll_);
159 PostSetNeedsCommitToMainThread(); 141 PostSetNeedsCommitToMainThread();
160 } else if (impl->active_tree()->source_frame_number() == 1) { 142 } else if (impl->active_tree()->source_frame_number() == 1) {
161 // Third or later draw after second commit. 143 // Third or later draw after second commit.
162 EXPECT_GE(impl->SourceAnimationFrameNumber(), 3); 144 EXPECT_GE(impl->SourceAnimationFrameNumber(), 3);
163 EXPECT_VECTOR_EQ(scroll_layer_->ScrollDelta(), gfx::Vector2d()); 145 EXPECT_VECTOR_EQ(root->ScrollDelta(), gfx::Vector2d());
164 EXPECT_VECTOR_EQ(scroll_layer_->scroll_offset(), 146 EXPECT_VECTOR_EQ(root->scroll_offset(),
165 initial_scroll_ + scroll_amount_ + scroll_amount_); 147 initial_scroll_ + scroll_amount_ + scroll_amount_);
166 EndTest(); 148 EndTest();
167 } 149 }
168 } 150 }
169 151
170 virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta, 152 virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta,
171 float scale) OVERRIDE { 153 float scale) OVERRIDE {
172 num_scrolls_++; 154 num_scrolls_++;
173 } 155 }
174 156
175 virtual void AfterTest() OVERRIDE { EXPECT_EQ(1, num_scrolls_); } 157 virtual void AfterTest() OVERRIDE { EXPECT_EQ(1, num_scrolls_); }
176 158
177 private: 159 private:
178 gfx::Vector2d initial_scroll_; 160 gfx::Vector2d initial_scroll_;
179 gfx::Vector2d scroll_amount_; 161 gfx::Vector2d scroll_amount_;
180 int num_scrolls_; 162 int num_scrolls_;
181 scoped_refptr<Layer> scroll_layer_;
182 }; 163 };
183 164
184 MULTI_THREAD_TEST_F(LayerTreeHostScrollTestScrollMultipleRedraw); 165 MULTI_THREAD_TEST_F(LayerTreeHostScrollTestScrollMultipleRedraw);
185 166
186 class LayerTreeHostScrollTestScrollAbortedCommit 167 class LayerTreeHostScrollTestScrollAbortedCommit
187 : public LayerTreeHostScrollTest { 168 : public LayerTreeHostScrollTest {
188 public: 169 public:
189 LayerTreeHostScrollTestScrollAbortedCommit() 170 LayerTreeHostScrollTestScrollAbortedCommit()
190 : initial_scroll_(50, 60), 171 : initial_scroll_(50, 60),
191 impl_scroll_(-3, 2), 172 impl_scroll_(-3, 2),
192 second_main_scroll_(14, -3), 173 second_main_scroll_(14, -3),
193 impl_scale_(2.f), 174 impl_scale_(2.f),
194 num_will_begin_main_frames_(0), 175 num_will_begin_main_frames_(0),
195 num_did_begin_main_frames_(0), 176 num_did_begin_main_frames_(0),
196 num_will_commits_(0), 177 num_will_commits_(0),
197 num_did_commits_(0), 178 num_did_commits_(0),
198 num_impl_commits_(0), 179 num_impl_commits_(0),
199 num_impl_scrolls_(0) {} 180 num_impl_scrolls_(0) {}
200 181
201 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } 182 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); }
202 183
203 virtual void SetupTree() OVERRIDE { 184 virtual void SetupTree() OVERRIDE {
204 LayerTreeHostScrollTest::SetupTree(); 185 LayerTreeHostScrollTest::SetupTree();
205 Layer* root_layer = layer_tree_host()->root_layer();
206 scoped_refptr<Layer> root_scroll_layer = Layer::Create(); 186 scoped_refptr<Layer> root_scroll_layer = Layer::Create();
207 root_scroll_layer->SetScrollClipLayer(root_layer); 187 root_scroll_layer->SetScrollable(true);
208 root_scroll_layer->SetScrollOffset(initial_scroll_); 188 root_scroll_layer->SetScrollOffset(initial_scroll_);
209 root_scroll_layer->SetBounds(gfx::Size(200, 200)); 189 root_scroll_layer->SetBounds(gfx::Size(200, 200));
190 root_scroll_layer->SetMaxScrollOffset(gfx::Vector2d(100, 100));
210 root_scroll_layer->SetIsDrawable(true); 191 root_scroll_layer->SetIsDrawable(true);
211 root_scroll_layer->SetIsContainerForFixedPositionLayers(true); 192 layer_tree_host()->root_layer()->AddChild(root_scroll_layer);
212 root_layer->AddChild(root_scroll_layer);
213 193
214 layer_tree_host()->RegisterViewportLayers(
215 root_layer, root_scroll_layer, NULL);
216 layer_tree_host()->SetPageScaleFactorAndLimits(1.f, 0.01f, 100.f); 194 layer_tree_host()->SetPageScaleFactorAndLimits(1.f, 0.01f, 100.f);
217 } 195 }
218 196
219 virtual void WillBeginMainFrame() OVERRIDE { 197 virtual void WillBeginMainFrame() OVERRIDE {
220 num_will_begin_main_frames_++; 198 num_will_begin_main_frames_++;
221 Layer* root_scroll_layer = layer_tree_host()->root_layer()->children()[0]; 199 Layer* root_scroll_layer = layer_tree_host()->root_layer()->children()[0];
222 switch (num_will_begin_main_frames_) { 200 switch (num_will_begin_main_frames_) {
223 case 1: 201 case 1:
224 // This will not be aborted because of the initial prop changes. 202 // This will not be aborted because of the initial prop changes.
225 EXPECT_EQ(0, num_impl_scrolls_); 203 EXPECT_EQ(0, num_impl_scrolls_);
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 int num_impl_commits_; 337 int num_impl_commits_;
360 int num_impl_scrolls_; 338 int num_impl_scrolls_;
361 }; 339 };
362 340
363 MULTI_THREAD_TEST_F(LayerTreeHostScrollTestScrollAbortedCommit); 341 MULTI_THREAD_TEST_F(LayerTreeHostScrollTestScrollAbortedCommit);
364 342
365 class LayerTreeHostScrollTestFractionalScroll : public LayerTreeHostScrollTest { 343 class LayerTreeHostScrollTestFractionalScroll : public LayerTreeHostScrollTest {
366 public: 344 public:
367 LayerTreeHostScrollTestFractionalScroll() : scroll_amount_(1.75, 0) {} 345 LayerTreeHostScrollTestFractionalScroll() : scroll_amount_(1.75, 0) {}
368 346
369 virtual void SetupTree() OVERRIDE {
370 LayerTreeHostScrollTest::SetupTree();
371 Layer* root_layer = layer_tree_host()->root_layer();
372 scoped_refptr<Layer> root_scroll_layer = Layer::Create();
373 root_scroll_layer->SetScrollClipLayer(root_layer);
374 root_scroll_layer->SetBounds(
375 gfx::Size(root_layer->bounds().width() + 100,
376 root_layer->bounds().height() + 100));
377 root_scroll_layer->SetIsDrawable(true);
378 root_scroll_layer->SetIsContainerForFixedPositionLayers(true);
379 root_layer->AddChild(root_scroll_layer);
380
381 layer_tree_host()->RegisterViewportLayers(
382 root_layer, root_scroll_layer, NULL);
383 layer_tree_host()->SetPageScaleFactorAndLimits(1.f, 0.01f, 100.f);
384 }
385
386 virtual void BeginTest() OVERRIDE { 347 virtual void BeginTest() OVERRIDE {
348 layer_tree_host()->root_layer()->SetScrollable(true);
349 layer_tree_host()->root_layer()
350 ->SetMaxScrollOffset(gfx::Vector2d(100, 100));
387 PostSetNeedsCommitToMainThread(); 351 PostSetNeedsCommitToMainThread();
388 } 352 }
389 353
390 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { 354 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE {
391 LayerImpl* root = impl->active_tree()->root_layer(); 355 LayerImpl* root = impl->active_tree()->root_layer();
392 LayerImpl* scroll_layer = root->children()[0];
393 356
394 // Check that a fractional scroll delta is correctly accumulated over 357 // Check that a fractional scroll delta is correctly accumulated over
395 // multiple commits. 358 // multiple commits.
396 switch (impl->active_tree()->source_frame_number()) { 359 switch (impl->active_tree()->source_frame_number()) {
397 case 0: 360 case 0:
398 EXPECT_VECTOR_EQ(scroll_layer->scroll_offset(), gfx::Vector2d(0, 0)); 361 EXPECT_VECTOR_EQ(root->scroll_offset(), gfx::Vector2d(0, 0));
399 EXPECT_VECTOR_EQ(scroll_layer->ScrollDelta(), gfx::Vector2d(0, 0)); 362 EXPECT_VECTOR_EQ(root->ScrollDelta(), gfx::Vector2d(0, 0));
400 PostSetNeedsCommitToMainThread(); 363 PostSetNeedsCommitToMainThread();
401 break; 364 break;
402 case 1: 365 case 1:
403 EXPECT_VECTOR_EQ(scroll_layer->scroll_offset(), 366 EXPECT_VECTOR_EQ(root->scroll_offset(),
404 gfx::ToFlooredVector2d(scroll_amount_)); 367 gfx::ToFlooredVector2d(scroll_amount_));
405 EXPECT_VECTOR_EQ(scroll_layer->ScrollDelta(), 368 EXPECT_VECTOR_EQ(root->ScrollDelta(),
406 gfx::Vector2dF(fmod(scroll_amount_.x(), 1.0f), 0.0f)); 369 gfx::Vector2dF(fmod(scroll_amount_.x(), 1.0f), 0.0f));
407 PostSetNeedsCommitToMainThread(); 370 PostSetNeedsCommitToMainThread();
408 break; 371 break;
409 case 2: 372 case 2:
410 EXPECT_VECTOR_EQ( 373 EXPECT_VECTOR_EQ(
411 scroll_layer->scroll_offset(), 374 root->scroll_offset(),
412 gfx::ToFlooredVector2d(scroll_amount_ + scroll_amount_)); 375 gfx::ToFlooredVector2d(scroll_amount_ + scroll_amount_));
413 EXPECT_VECTOR_EQ( 376 EXPECT_VECTOR_EQ(
414 scroll_layer->ScrollDelta(), 377 root->ScrollDelta(),
415 gfx::Vector2dF(fmod(2.0f * scroll_amount_.x(), 1.0f), 0.0f)); 378 gfx::Vector2dF(fmod(2.0f * scroll_amount_.x(), 1.0f), 0.0f));
416 EndTest(); 379 EndTest();
417 break; 380 break;
418 } 381 }
419 scroll_layer->ScrollBy(scroll_amount_); 382 root->ScrollBy(scroll_amount_);
420 } 383 }
421 384
422 virtual void AfterTest() OVERRIDE {} 385 virtual void AfterTest() OVERRIDE {}
423 386
424 private: 387 private:
425 gfx::Vector2dF scroll_amount_; 388 gfx::Vector2dF scroll_amount_;
426 }; 389 };
427 390
428 MULTI_THREAD_TEST_F(LayerTreeHostScrollTestFractionalScroll); 391 MULTI_THREAD_TEST_F(LayerTreeHostScrollTestFractionalScroll);
429 392
(...skipping 11 matching lines...) Expand all
441 scoped_refptr<Layer> root_layer = Layer::Create(); 404 scoped_refptr<Layer> root_layer = Layer::Create();
442 root_layer->SetBounds(gfx::Size(10, 10)); 405 root_layer->SetBounds(gfx::Size(10, 10));
443 406
444 root_scroll_layer_ = ContentLayer::Create(&fake_content_layer_client_); 407 root_scroll_layer_ = ContentLayer::Create(&fake_content_layer_client_);
445 root_scroll_layer_->SetBounds(gfx::Size(110, 110)); 408 root_scroll_layer_->SetBounds(gfx::Size(110, 110));
446 409
447 root_scroll_layer_->SetPosition(gfx::Point()); 410 root_scroll_layer_->SetPosition(gfx::Point());
448 root_scroll_layer_->SetAnchorPoint(gfx::PointF()); 411 root_scroll_layer_->SetAnchorPoint(gfx::PointF());
449 412
450 root_scroll_layer_->SetIsDrawable(true); 413 root_scroll_layer_->SetIsDrawable(true);
451 root_scroll_layer_->SetScrollClipLayer(root_layer); 414 root_scroll_layer_->SetScrollable(true);
452 root_scroll_layer_->SetIsContainerForFixedPositionLayers(true); 415 root_scroll_layer_->SetMaxScrollOffset(gfx::Vector2d(100, 100));
453 root_layer->AddChild(root_scroll_layer_); 416 root_layer->AddChild(root_scroll_layer_);
454 417
455 child_layer_ = ContentLayer::Create(&fake_content_layer_client_); 418 child_layer_ = ContentLayer::Create(&fake_content_layer_client_);
456 child_layer_->set_did_scroll_callback( 419 child_layer_->set_did_scroll_callback(
457 base::Bind(&LayerTreeHostScrollTestCaseWithChild::DidScroll, 420 base::Bind(&LayerTreeHostScrollTestCaseWithChild::DidScroll,
458 base::Unretained(this))); 421 base::Unretained(this)));
459 child_layer_->SetBounds(gfx::Size(110, 110)); 422 child_layer_->SetBounds(gfx::Size(110, 110));
460 423
461 if (scroll_child_layer_) { 424 if (scroll_child_layer_) {
462 // Scrolls on the child layer will happen at 5, 5. If they are treated 425 // Scrolls on the child layer will happen at 5, 5. If they are treated
463 // like device pixels, and device scale factor is 2, then they will 426 // like device pixels, and device scale factor is 2, then they will
464 // be considered at 2.5, 2.5 in logical pixels, and will miss this layer. 427 // be considered at 2.5, 2.5 in logical pixels, and will miss this layer.
465 child_layer_->SetPosition(gfx::Point(5, 5)); 428 child_layer_->SetPosition(gfx::Point(5, 5));
466 } else { 429 } else {
467 // Adjust the child layer horizontally so that scrolls will never hit it. 430 // Adjust the child layer horizontally so that scrolls will never hit it.
468 child_layer_->SetPosition(gfx::Point(60, 5)); 431 child_layer_->SetPosition(gfx::Point(60, 5));
469 } 432 }
470 child_layer_->SetAnchorPoint(gfx::PointF()); 433 child_layer_->SetAnchorPoint(gfx::PointF());
471 434
472 child_layer_->SetIsDrawable(true); 435 child_layer_->SetIsDrawable(true);
473 child_layer_->SetScrollClipLayer(root_layer); 436 child_layer_->SetScrollable(true);
474 child_layer_->SetBounds(root_scroll_layer_->bounds()); 437 child_layer_->SetMaxScrollOffset(gfx::Vector2d(100, 100));
475 root_scroll_layer_->AddChild(child_layer_); 438 root_scroll_layer_->AddChild(child_layer_);
476 439
477 if (scroll_child_layer_) { 440 if (scroll_child_layer_) {
478 expected_scroll_layer_ = child_layer_; 441 expected_scroll_layer_ = child_layer_;
479 expected_no_scroll_layer_ = root_scroll_layer_; 442 expected_no_scroll_layer_ = root_scroll_layer_;
480 } else { 443 } else {
481 expected_scroll_layer_ = root_scroll_layer_; 444 expected_scroll_layer_ = root_scroll_layer_;
482 expected_no_scroll_layer_ = child_layer_; 445 expected_no_scroll_layer_ = child_layer_;
483 } 446 }
484 447
485 expected_scroll_layer_->SetScrollOffset(initial_offset_); 448 expected_scroll_layer_->SetScrollOffset(initial_offset_);
486 449
487 layer_tree_host()->SetRootLayer(root_layer); 450 layer_tree_host()->SetRootLayer(root_layer);
488 layer_tree_host()->RegisterViewportLayers(
489 root_layer, root_scroll_layer_, NULL);
490 LayerTreeHostScrollTest::SetupTree(); 451 LayerTreeHostScrollTest::SetupTree();
491 } 452 }
492 453
493 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } 454 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); }
494 455
495 virtual void WillCommit() OVERRIDE { 456 virtual void WillCommit() OVERRIDE {
496 // Keep the test committing (otherwise the early out for no update 457 // Keep the test committing (otherwise the early out for no update
497 // will stall the test). 458 // will stall the test).
498 if (layer_tree_host()->source_frame_number() < 2) { 459 if (layer_tree_host()->source_frame_number() < 2) {
499 layer_tree_host()->SetNeedsCommit(); 460 layer_tree_host()->SetNeedsCommit();
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
756 717
757 class ImplSidePaintingScrollTestSimple : public ImplSidePaintingScrollTest { 718 class ImplSidePaintingScrollTestSimple : public ImplSidePaintingScrollTest {
758 public: 719 public:
759 ImplSidePaintingScrollTestSimple() 720 ImplSidePaintingScrollTestSimple()
760 : initial_scroll_(10, 20), 721 : initial_scroll_(10, 20),
761 main_thread_scroll_(40, 5), 722 main_thread_scroll_(40, 5),
762 impl_thread_scroll1_(2, -1), 723 impl_thread_scroll1_(2, -1),
763 impl_thread_scroll2_(-3, 10), 724 impl_thread_scroll2_(-3, 10),
764 num_scrolls_(0) {} 725 num_scrolls_(0) {}
765 726
766 virtual void SetupTree() OVERRIDE {
767 LayerTreeHostScrollTest::SetupTree();
768 Layer* root_layer = layer_tree_host()->root_layer();
769 scoped_refptr<Layer> root_scroll_layer = Layer::Create();
770 root_scroll_layer->SetScrollClipLayer(root_layer);
771 root_scroll_layer->SetScrollOffset(initial_scroll_);
772 root_scroll_layer->SetBounds(
773 gfx::Size(root_layer->bounds().width() + 100,
774 root_layer->bounds().height() + 100));
775 root_scroll_layer->SetIsDrawable(true);
776 root_scroll_layer->SetIsContainerForFixedPositionLayers(true);
777 root_layer->AddChild(root_scroll_layer);
778
779 layer_tree_host()->RegisterViewportLayers(
780 root_layer, root_scroll_layer, NULL);
781 layer_tree_host()->SetPageScaleFactorAndLimits(1.f, 0.01f, 100.f);
782 }
783
784 virtual void BeginTest() OVERRIDE { 727 virtual void BeginTest() OVERRIDE {
728 layer_tree_host()->root_layer()->SetScrollable(true);
729 layer_tree_host()->root_layer()
730 ->SetMaxScrollOffset(gfx::Vector2d(100, 100));
731 layer_tree_host()->root_layer()->SetScrollOffset(initial_scroll_);
785 PostSetNeedsCommitToMainThread(); 732 PostSetNeedsCommitToMainThread();
786 } 733 }
787 734
788 virtual void Layout() OVERRIDE { 735 virtual void Layout() OVERRIDE {
789 Layer* root = layer_tree_host()->root_layer(); 736 Layer* root = layer_tree_host()->root_layer();
790 Layer* scroll_layer = root->children()[0];
791 if (!layer_tree_host()->source_frame_number()) { 737 if (!layer_tree_host()->source_frame_number()) {
792 EXPECT_VECTOR_EQ(scroll_layer->scroll_offset(), initial_scroll_); 738 EXPECT_VECTOR_EQ(root->scroll_offset(), initial_scroll_);
793 } else { 739 } else {
794 EXPECT_VECTOR_EQ(scroll_layer->scroll_offset(), 740 EXPECT_VECTOR_EQ(root->scroll_offset(),
795 initial_scroll_ + impl_thread_scroll1_); 741 initial_scroll_ + impl_thread_scroll1_);
796 742
797 // Pretend like Javascript updated the scroll position itself with a 743 // Pretend like Javascript updated the scroll position itself with a
798 // change of main_thread_scroll. 744 // change of main_thread_scroll.
799 scroll_layer->SetScrollOffset(initial_scroll_ + main_thread_scroll_ + 745 root->SetScrollOffset(initial_scroll_ + main_thread_scroll_ +
800 impl_thread_scroll1_); 746 impl_thread_scroll1_);
801 } 747 }
802 } 748 }
803 749
804 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { 750 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE {
805 // We force a second draw here of the first commit before activating 751 // We force a second draw here of the first commit before activating
806 // the second commit. 752 // the second commit.
807 if (impl->active_tree()->source_frame_number() == 0) 753 if (impl->active_tree()->source_frame_number() == 0)
808 impl->SetNeedsRedraw(); 754 impl->SetNeedsRedraw();
809 } 755 }
810 756
811 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { 757 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE {
812 ImplSidePaintingScrollTest::DrawLayersOnThread(impl); 758 ImplSidePaintingScrollTest::DrawLayersOnThread(impl);
813 759
814 LayerImpl* root = impl->active_tree()->root_layer(); 760 LayerImpl* root = impl->active_tree()->root_layer();
815 LayerImpl* scroll_layer = root->children()[0];
816 LayerImpl* pending_root = 761 LayerImpl* pending_root =
817 impl->active_tree()->FindPendingTreeLayerById(root->id()); 762 impl->active_tree()->FindPendingTreeLayerById(root->id());
818 763
819 switch (impl->active_tree()->source_frame_number()) { 764 switch (impl->active_tree()->source_frame_number()) {
820 case 0: 765 case 0:
821 if (!impl->pending_tree()) { 766 if (!impl->pending_tree()) {
822 impl->BlockNotifyReadyToActivateForTesting(true); 767 impl->BlockNotifyReadyToActivateForTesting(true);
823 EXPECT_VECTOR_EQ(scroll_layer->ScrollDelta(), gfx::Vector2d()); 768 EXPECT_VECTOR_EQ(root->ScrollDelta(), gfx::Vector2d());
824 scroll_layer->ScrollBy(impl_thread_scroll1_); 769 root->ScrollBy(impl_thread_scroll1_);
825 770
826 EXPECT_VECTOR_EQ(scroll_layer->scroll_offset(), initial_scroll_); 771 EXPECT_VECTOR_EQ(root->scroll_offset(), initial_scroll_);
827 EXPECT_VECTOR_EQ(scroll_layer->ScrollDelta(), impl_thread_scroll1_); 772 EXPECT_VECTOR_EQ(root->ScrollDelta(), impl_thread_scroll1_);
828 EXPECT_VECTOR_EQ(scroll_layer->sent_scroll_delta(), gfx::Vector2d()); 773 EXPECT_VECTOR_EQ(root->sent_scroll_delta(), gfx::Vector2d());
829 PostSetNeedsCommitToMainThread(); 774 PostSetNeedsCommitToMainThread();
830 775
831 // CommitCompleteOnThread will trigger this function again 776 // CommitCompleteOnThread will trigger this function again
832 // and cause us to take the else clause. 777 // and cause us to take the else clause.
833 } else { 778 } else {
834 impl->BlockNotifyReadyToActivateForTesting(false); 779 impl->BlockNotifyReadyToActivateForTesting(false);
835 ASSERT_TRUE(pending_root); 780 ASSERT_TRUE(pending_root);
836 EXPECT_EQ(impl->pending_tree()->source_frame_number(), 1); 781 EXPECT_EQ(impl->pending_tree()->source_frame_number(), 1);
837 782
838 scroll_layer->ScrollBy(impl_thread_scroll2_); 783 root->ScrollBy(impl_thread_scroll2_);
839 EXPECT_VECTOR_EQ(scroll_layer->scroll_offset(), initial_scroll_); 784 EXPECT_VECTOR_EQ(root->scroll_offset(), initial_scroll_);
840 EXPECT_VECTOR_EQ(scroll_layer->ScrollDelta(), 785 EXPECT_VECTOR_EQ(root->ScrollDelta(),
841 impl_thread_scroll1_ + impl_thread_scroll2_); 786 impl_thread_scroll1_ + impl_thread_scroll2_);
842 EXPECT_VECTOR_EQ(scroll_layer->sent_scroll_delta(), 787 EXPECT_VECTOR_EQ(root->sent_scroll_delta(), impl_thread_scroll1_);
843 impl_thread_scroll1_);
844 788
845 LayerImpl* pending_scroll_layer = pending_root->children()[0];
846 EXPECT_VECTOR_EQ( 789 EXPECT_VECTOR_EQ(
847 pending_scroll_layer->scroll_offset(), 790 pending_root->scroll_offset(),
848 initial_scroll_ + main_thread_scroll_ + impl_thread_scroll1_); 791 initial_scroll_ + main_thread_scroll_ + impl_thread_scroll1_);
849 EXPECT_VECTOR_EQ(pending_scroll_layer->ScrollDelta(), 792 EXPECT_VECTOR_EQ(pending_root->ScrollDelta(), impl_thread_scroll2_);
850 impl_thread_scroll2_); 793 EXPECT_VECTOR_EQ(pending_root->sent_scroll_delta(), gfx::Vector2d());
851 EXPECT_VECTOR_EQ(pending_scroll_layer->sent_scroll_delta(),
852 gfx::Vector2d());
853 } 794 }
854 break; 795 break;
855 case 1: 796 case 1:
856 EXPECT_FALSE(impl->pending_tree()); 797 EXPECT_FALSE(impl->pending_tree());
857 EXPECT_VECTOR_EQ( 798 EXPECT_VECTOR_EQ(
858 scroll_layer->scroll_offset(), 799 root->scroll_offset(),
859 initial_scroll_ + main_thread_scroll_ + impl_thread_scroll1_); 800 initial_scroll_ + main_thread_scroll_ + impl_thread_scroll1_);
860 EXPECT_VECTOR_EQ(scroll_layer->ScrollDelta(), impl_thread_scroll2_); 801 EXPECT_VECTOR_EQ(root->ScrollDelta(), impl_thread_scroll2_);
861 EXPECT_VECTOR_EQ(scroll_layer->sent_scroll_delta(), gfx::Vector2d()); 802 EXPECT_VECTOR_EQ(root->sent_scroll_delta(), gfx::Vector2d());
862 EndTest(); 803 EndTest();
863 break; 804 break;
864 } 805 }
865 } 806 }
866 807
867 virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta, 808 virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta,
868 float scale) OVERRIDE { 809 float scale) OVERRIDE {
869 num_scrolls_++; 810 num_scrolls_++;
870 } 811 }
871 812
(...skipping 12 matching lines...) Expand all
884 // This test makes sure that layers pick up scrolls that occur between 825 // This test makes sure that layers pick up scrolls that occur between
885 // beginning a commit and finishing a commit (aka scroll deltas not 826 // beginning a commit and finishing a commit (aka scroll deltas not
886 // included in sent scroll delta) still apply to layers that don't 827 // included in sent scroll delta) still apply to layers that don't
887 // push properties. 828 // push properties.
888 class ImplSidePaintingScrollTestImplOnlyScroll 829 class ImplSidePaintingScrollTestImplOnlyScroll
889 : public ImplSidePaintingScrollTest { 830 : public ImplSidePaintingScrollTest {
890 public: 831 public:
891 ImplSidePaintingScrollTestImplOnlyScroll() 832 ImplSidePaintingScrollTestImplOnlyScroll()
892 : initial_scroll_(20, 10), impl_thread_scroll_(-2, 3) {} 833 : initial_scroll_(20, 10), impl_thread_scroll_(-2, 3) {}
893 834
894 virtual void SetupTree() OVERRIDE {
895 LayerTreeHostScrollTest::SetupTree();
896 Layer* root_layer = layer_tree_host()->root_layer();
897 scoped_refptr<Layer> root_scroll_layer = Layer::Create();
898 root_scroll_layer->SetScrollClipLayer(root_layer);
899 root_scroll_layer->SetScrollOffset(initial_scroll_);
900 root_scroll_layer->SetBounds(
901 gfx::Size(root_layer->bounds().width() + 100,
902 root_layer->bounds().height() + 100));
903 root_scroll_layer->SetIsDrawable(true);
904 root_scroll_layer->SetIsContainerForFixedPositionLayers(true);
905 root_layer->AddChild(root_scroll_layer);
906
907 layer_tree_host()->RegisterViewportLayers(
908 root_layer, root_scroll_layer, NULL);
909 layer_tree_host()->SetPageScaleFactorAndLimits(1.f, 0.01f, 100.f);
910 }
911
912 virtual void BeginTest() OVERRIDE { 835 virtual void BeginTest() OVERRIDE {
836 layer_tree_host()->root_layer()->SetScrollable(true);
837 layer_tree_host()->root_layer()->SetMaxScrollOffset(
838 gfx::Vector2d(100, 100));
839 layer_tree_host()->root_layer()->SetScrollOffset(initial_scroll_);
913 PostSetNeedsCommitToMainThread(); 840 PostSetNeedsCommitToMainThread();
914 } 841 }
915 842
916 virtual void WillCommit() OVERRIDE { 843 virtual void WillCommit() OVERRIDE {
917 Layer* root = layer_tree_host()->root_layer(); 844 Layer* root = layer_tree_host()->root_layer();
918 Layer* scroll_layer = root->children()[0];
919 switch (layer_tree_host()->source_frame_number()) { 845 switch (layer_tree_host()->source_frame_number()) {
920 case 0: 846 case 0:
921 EXPECT_TRUE(scroll_layer->needs_push_properties()); 847 EXPECT_TRUE(root->needs_push_properties());
922 break; 848 break;
923 case 1: 849 case 1:
924 // Even if this layer doesn't need push properties, it should 850 // Even if this layer doesn't need push properties, it should
925 // still pick up scrolls that happen on the active layer during 851 // still pick up scrolls that happen on the active layer during
926 // commit. 852 // commit.
927 EXPECT_FALSE(scroll_layer->needs_push_properties()); 853 EXPECT_FALSE(root->needs_push_properties());
928 break; 854 break;
929 } 855 }
930 } 856 }
931 857
932 virtual void BeginCommitOnThread(LayerTreeHostImpl* impl) OVERRIDE { 858 virtual void BeginCommitOnThread(LayerTreeHostImpl* impl) OVERRIDE {
933 // Scroll after the 2nd commit has started. 859 // Scroll after the 2nd commit has started.
934 if (impl->active_tree()->source_frame_number() == 0) { 860 if (impl->active_tree()->source_frame_number() == 0) {
935 LayerImpl* active_root = impl->active_tree()->root_layer(); 861 LayerImpl* active_root = impl->active_tree()->root_layer();
936 LayerImpl* active_scroll_layer = active_root->children()[0];
937 ASSERT_TRUE(active_root); 862 ASSERT_TRUE(active_root);
938 ASSERT_TRUE(active_scroll_layer); 863 active_root->ScrollBy(impl_thread_scroll_);
939 active_scroll_layer->ScrollBy(impl_thread_scroll_);
940 } 864 }
941 } 865 }
942 866
943 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { 867 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE {
944 // We force a second draw here of the first commit before activating 868 // We force a second draw here of the first commit before activating
945 // the second commit. 869 // the second commit.
946 LayerImpl* active_root = impl->active_tree()->root_layer(); 870 LayerImpl* active_root = impl->active_tree()->root_layer();
947 LayerImpl* active_scroll_layer =
948 active_root ? active_root->children()[0] : NULL;
949 LayerImpl* pending_root = impl->pending_tree()->root_layer(); 871 LayerImpl* pending_root = impl->pending_tree()->root_layer();
950 LayerImpl* pending_scroll_layer = pending_root->children()[0];
951 872
952 ASSERT_TRUE(pending_root); 873 ASSERT_TRUE(pending_root);
953 ASSERT_TRUE(pending_scroll_layer);
954 switch (impl->pending_tree()->source_frame_number()) { 874 switch (impl->pending_tree()->source_frame_number()) {
955 case 0: 875 case 0:
956 EXPECT_VECTOR_EQ(pending_scroll_layer->scroll_offset(), 876 EXPECT_VECTOR_EQ(pending_root->scroll_offset(), initial_scroll_);
957 initial_scroll_); 877 EXPECT_VECTOR_EQ(pending_root->ScrollDelta(), gfx::Vector2d());
958 EXPECT_VECTOR_EQ(pending_scroll_layer->ScrollDelta(), gfx::Vector2d()); 878 EXPECT_VECTOR_EQ(pending_root->sent_scroll_delta(), gfx::Vector2d());
959 EXPECT_VECTOR_EQ(pending_scroll_layer->sent_scroll_delta(),
960 gfx::Vector2d());
961 EXPECT_FALSE(active_root); 879 EXPECT_FALSE(active_root);
962 break; 880 break;
963 case 1: 881 case 1:
964 // Even though the scroll happened during the commit, both layers 882 // Even though the scroll happened during the commit, both layers
965 // should have the appropriate scroll delta. 883 // should have the appropriate scroll delta.
966 EXPECT_VECTOR_EQ(pending_scroll_layer->scroll_offset(), 884 EXPECT_VECTOR_EQ(pending_root->scroll_offset(), initial_scroll_);
967 initial_scroll_); 885 EXPECT_VECTOR_EQ(pending_root->ScrollDelta(), impl_thread_scroll_);
968 EXPECT_VECTOR_EQ(pending_scroll_layer->ScrollDelta(), 886 EXPECT_VECTOR_EQ(pending_root->sent_scroll_delta(), gfx::Vector2d());
969 impl_thread_scroll_);
970 EXPECT_VECTOR_EQ(pending_scroll_layer->sent_scroll_delta(),
971 gfx::Vector2d());
972 ASSERT_TRUE(active_root); 887 ASSERT_TRUE(active_root);
973 EXPECT_VECTOR_EQ(active_scroll_layer->scroll_offset(), initial_scroll_); 888 EXPECT_VECTOR_EQ(active_root->scroll_offset(), initial_scroll_);
974 EXPECT_VECTOR_EQ(active_scroll_layer->ScrollDelta(), 889 EXPECT_VECTOR_EQ(active_root->ScrollDelta(), impl_thread_scroll_);
975 impl_thread_scroll_); 890 EXPECT_VECTOR_EQ(active_root->sent_scroll_delta(), gfx::Vector2d());
976 EXPECT_VECTOR_EQ(active_scroll_layer->sent_scroll_delta(),
977 gfx::Vector2d());
978 break; 891 break;
979 case 2: 892 case 2:
980 // On the next commit, this delta should have been sent and applied. 893 // On the next commit, this delta should have been sent and applied.
981 EXPECT_VECTOR_EQ(pending_scroll_layer->scroll_offset(), 894 EXPECT_VECTOR_EQ(pending_root->scroll_offset(),
982 initial_scroll_ + impl_thread_scroll_); 895 initial_scroll_ + impl_thread_scroll_);
983 EXPECT_VECTOR_EQ(pending_scroll_layer->ScrollDelta(), gfx::Vector2d()); 896 EXPECT_VECTOR_EQ(pending_root->ScrollDelta(), gfx::Vector2d());
984 EXPECT_VECTOR_EQ(pending_scroll_layer->sent_scroll_delta(), 897 EXPECT_VECTOR_EQ(pending_root->sent_scroll_delta(), gfx::Vector2d());
985 gfx::Vector2d());
986 EndTest(); 898 EndTest();
987 break; 899 break;
988 } 900 }
989 } 901 }
990 902
991 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { 903 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE {
992 ImplSidePaintingScrollTest::DrawLayersOnThread(impl); 904 ImplSidePaintingScrollTest::DrawLayersOnThread(impl);
993 905
994 LayerImpl* root = impl->active_tree()->root_layer(); 906 LayerImpl* root = impl->active_tree()->root_layer();
995 LayerImpl* scroll_layer = root->children()[0];
996 907
997 switch (impl->active_tree()->source_frame_number()) { 908 switch (impl->active_tree()->source_frame_number()) {
998 case 0: 909 case 0:
999 EXPECT_VECTOR_EQ(scroll_layer->scroll_offset(), initial_scroll_); 910 EXPECT_VECTOR_EQ(root->scroll_offset(), initial_scroll_);
1000 EXPECT_VECTOR_EQ(scroll_layer->ScrollDelta(), gfx::Vector2d()); 911 EXPECT_VECTOR_EQ(root->ScrollDelta(), gfx::Vector2d());
1001 EXPECT_VECTOR_EQ(scroll_layer->sent_scroll_delta(), gfx::Vector2d()); 912 EXPECT_VECTOR_EQ(root->sent_scroll_delta(), gfx::Vector2d());
1002 PostSetNeedsCommitToMainThread(); 913 PostSetNeedsCommitToMainThread();
1003 break; 914 break;
1004 case 1: 915 case 1:
1005 EXPECT_VECTOR_EQ(scroll_layer->scroll_offset(), initial_scroll_); 916 EXPECT_VECTOR_EQ(root->scroll_offset(), initial_scroll_);
1006 EXPECT_VECTOR_EQ(scroll_layer->ScrollDelta(), impl_thread_scroll_); 917 EXPECT_VECTOR_EQ(root->ScrollDelta(), impl_thread_scroll_);
1007 EXPECT_VECTOR_EQ(scroll_layer->sent_scroll_delta(), gfx::Vector2d()); 918 EXPECT_VECTOR_EQ(root->sent_scroll_delta(), gfx::Vector2d());
1008 PostSetNeedsCommitToMainThread(); 919 PostSetNeedsCommitToMainThread();
1009 break; 920 break;
1010 } 921 }
1011 } 922 }
1012 923
1013 virtual void AfterTest() OVERRIDE {} 924 virtual void AfterTest() OVERRIDE {}
1014 925
1015 private: 926 private:
1016 gfx::Vector2d initial_scroll_; 927 gfx::Vector2d initial_scroll_;
1017 gfx::Vector2d impl_thread_scroll_; 928 gfx::Vector2d impl_thread_scroll_;
1018 }; 929 };
1019 930
1020 MULTI_THREAD_TEST_F(ImplSidePaintingScrollTestImplOnlyScroll); 931 MULTI_THREAD_TEST_F(ImplSidePaintingScrollTestImplOnlyScroll);
1021 932
1022 class LayerTreeHostScrollTestScrollZeroMaxScrollOffset 933 class LayerTreeHostScrollTestScrollZeroMaxScrollOffset
1023 : public LayerTreeHostScrollTest { 934 : public LayerTreeHostScrollTest {
1024 public: 935 public:
1025 LayerTreeHostScrollTestScrollZeroMaxScrollOffset() {} 936 LayerTreeHostScrollTestScrollZeroMaxScrollOffset() {}
1026 937
1027 virtual void SetupTree() OVERRIDE {
1028 LayerTreeTest::SetupTree();
1029 scoped_refptr<Layer> scroll_layer = Layer::Create();
1030 layer_tree_host()->root_layer()->AddChild(scroll_layer);
1031 }
1032
1033 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } 938 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); }
1034 939
1035 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { 940 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE {
1036 LayerImpl* root = impl->active_tree()->root_layer(); 941 LayerImpl* root = impl->active_tree()->root_layer();
1037 LayerImpl* scroll_layer = root->children()[0]; 942 root->SetScrollable(true);
1038 scroll_layer->SetScrollClipLayer(root->id());
1039 943
1040 // Set max_scroll_offset = (100, 100). 944 root->SetMaxScrollOffset(gfx::Vector2d(100, 100));
1041 scroll_layer->SetBounds(
1042 gfx::Size(root->bounds().width() + 100, root->bounds().height() + 100));
1043 EXPECT_EQ(InputHandler::ScrollStarted, 945 EXPECT_EQ(InputHandler::ScrollStarted,
1044 scroll_layer->TryScroll(gfx::PointF(0.0f, 1.0f), 946 root->TryScroll(gfx::PointF(0.0f, 1.0f), InputHandler::Gesture));
1045 InputHandler::Gesture));
1046 947
1047 // Set max_scroll_offset = (0, 0). 948 root->SetMaxScrollOffset(gfx::Vector2d(0, 0));
1048 scroll_layer->SetBounds(root->bounds());
1049 EXPECT_EQ(InputHandler::ScrollIgnored, 949 EXPECT_EQ(InputHandler::ScrollIgnored,
1050 scroll_layer->TryScroll(gfx::PointF(0.0f, 1.0f), 950 root->TryScroll(gfx::PointF(0.0f, 1.0f), InputHandler::Gesture));
1051 InputHandler::Gesture));
1052 951
1053 // Set max_scroll_offset = (-100, -100). 952 root->SetMaxScrollOffset(gfx::Vector2d(-100, -100));
1054 scroll_layer->SetBounds(gfx::Size());
1055 EXPECT_EQ(InputHandler::ScrollIgnored, 953 EXPECT_EQ(InputHandler::ScrollIgnored,
1056 scroll_layer->TryScroll(gfx::PointF(0.0f, 1.0f), 954 root->TryScroll(gfx::PointF(0.0f, 1.0f), InputHandler::Gesture));
1057 InputHandler::Gesture));
1058 955
1059 EndTest(); 956 EndTest();
1060 } 957 }
1061 958
1062 virtual void AfterTest() OVERRIDE {} 959 virtual void AfterTest() OVERRIDE {}
1063 }; 960 };
1064 961
1065 SINGLE_AND_MULTI_THREAD_TEST_F( 962 SINGLE_AND_MULTI_THREAD_TEST_F(
1066 LayerTreeHostScrollTestScrollZeroMaxScrollOffset); 963 LayerTreeHostScrollTestScrollZeroMaxScrollOffset);
1067 964
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
1189 Layer* layer_; 1086 Layer* layer_;
1190 }; 1087 };
1191 1088
1192 Layer* CreateScrollLayer(Layer* parent, FakeLayerScrollClient* client) { 1089 Layer* CreateScrollLayer(Layer* parent, FakeLayerScrollClient* client) {
1193 scoped_refptr<Layer> scroll_layer = 1090 scoped_refptr<Layer> scroll_layer =
1194 ContentLayer::Create(&fake_content_layer_client_); 1091 ContentLayer::Create(&fake_content_layer_client_);
1195 scroll_layer->SetBounds(gfx::Size(110, 110)); 1092 scroll_layer->SetBounds(gfx::Size(110, 110));
1196 scroll_layer->SetPosition(gfx::Point(0, 0)); 1093 scroll_layer->SetPosition(gfx::Point(0, 0));
1197 scroll_layer->SetAnchorPoint(gfx::PointF()); 1094 scroll_layer->SetAnchorPoint(gfx::PointF());
1198 scroll_layer->SetIsDrawable(true); 1095 scroll_layer->SetIsDrawable(true);
1199 scroll_layer->SetScrollClipLayer(parent); 1096 scroll_layer->SetScrollable(true);
1200 scroll_layer->SetBounds(gfx::Size(parent->bounds().width() + 100, 1097 scroll_layer->SetMaxScrollOffset(gfx::Vector2d(100, 100));
1201 parent->bounds().height() + 100));
1202 scroll_layer->set_did_scroll_callback(base::Bind( 1098 scroll_layer->set_did_scroll_callback(base::Bind(
1203 &FakeLayerScrollClient::DidScroll, base::Unretained(client))); 1099 &FakeLayerScrollClient::DidScroll, base::Unretained(client)));
1204 client->owner_ = this; 1100 client->owner_ = this;
1205 client->layer_ = scroll_layer.get(); 1101 client->layer_ = scroll_layer.get();
1206 parent->AddChild(scroll_layer); 1102 parent->AddChild(scroll_layer);
1207 return scroll_layer.get(); 1103 return scroll_layer.get();
1208 } 1104 }
1209 1105
1210 FakeLayerScrollClient root_scroll_layer_client_; 1106 FakeLayerScrollClient root_scroll_layer_client_;
1211 FakeLayerScrollClient sibling_scroll_layer_client_; 1107 FakeLayerScrollClient sibling_scroll_layer_client_;
1212 FakeLayerScrollClient child_scroll_layer_client_; 1108 FakeLayerScrollClient child_scroll_layer_client_;
1213 1109
1214 FakeContentLayerClient fake_content_layer_client_; 1110 FakeContentLayerClient fake_content_layer_client_;
1215 1111
1216 bool scroll_destroy_whole_tree_; 1112 bool scroll_destroy_whole_tree_;
1217 }; 1113 };
1218 1114
1219 TEST_F(LayerTreeHostScrollTestLayerStructureChange, ScrollDestroyLayer) { 1115 TEST_F(LayerTreeHostScrollTestLayerStructureChange, ScrollDestroyLayer) {
1220 RunTest(true, false, false); 1116 RunTest(true, false, false);
1221 } 1117 }
1222 1118
1223 TEST_F(LayerTreeHostScrollTestLayerStructureChange, ScrollDestroyWholeTree) { 1119 TEST_F(LayerTreeHostScrollTestLayerStructureChange, ScrollDestroyWholeTree) {
1224 scroll_destroy_whole_tree_ = true; 1120 scroll_destroy_whole_tree_ = true;
1225 RunTest(true, false, false); 1121 RunTest(true, false, false);
1226 } 1122 }
1227 1123
1228 } // namespace 1124 } // namespace
1229 } // namespace cc 1125 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_unittest_damage.cc ('k') | cc/trees/layer_tree_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698