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

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

Issue 19106007: cc: Allow the main thread to cancel commits (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: New test for texture state Created 7 years, 5 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
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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 case 1: 65 case 1:
66 EXPECT_VECTOR_EQ(root->scroll_offset(), second_scroll_); 66 EXPECT_VECTOR_EQ(root->scroll_offset(), second_scroll_);
67 EXPECT_VECTOR_EQ(root->ScrollDelta(), scroll_amount_); 67 EXPECT_VECTOR_EQ(root->ScrollDelta(), scroll_amount_);
68 EndTest(); 68 EndTest();
69 break; 69 break;
70 } 70 }
71 } 71 }
72 72
73 virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta, float scale) 73 virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta, float scale)
74 OVERRIDE { 74 OVERRIDE {
75 gfx::Vector2d offset = layer_tree_host()->root_layer()->scroll_offset();
76 layer_tree_host()->root_layer()->SetScrollOffset(offset + scroll_delta);
77 num_scrolls_++; 75 num_scrolls_++;
78 } 76 }
79 77
80 virtual void AfterTest() OVERRIDE { EXPECT_EQ(1, num_scrolls_); } 78 virtual void AfterTest() OVERRIDE { EXPECT_EQ(1, num_scrolls_); }
81 79
82 private: 80 private:
83 gfx::Vector2d initial_scroll_; 81 gfx::Vector2d initial_scroll_;
84 gfx::Vector2d second_scroll_; 82 gfx::Vector2d second_scroll_;
85 gfx::Vector2d scroll_amount_; 83 gfx::Vector2d scroll_amount_;
86 int num_scrolls_; 84 int num_scrolls_;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 EXPECT_GE(impl->SourceAnimationFrameNumber(), 3); 143 EXPECT_GE(impl->SourceAnimationFrameNumber(), 3);
146 EXPECT_VECTOR_EQ(root->ScrollDelta(), gfx::Vector2d()); 144 EXPECT_VECTOR_EQ(root->ScrollDelta(), gfx::Vector2d());
147 EXPECT_VECTOR_EQ(root->scroll_offset(), 145 EXPECT_VECTOR_EQ(root->scroll_offset(),
148 initial_scroll_ + scroll_amount_ + scroll_amount_); 146 initial_scroll_ + scroll_amount_ + scroll_amount_);
149 EndTest(); 147 EndTest();
150 } 148 }
151 } 149 }
152 150
153 virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta, float scale) 151 virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta, float scale)
154 OVERRIDE { 152 OVERRIDE {
155 gfx::Vector2d offset = layer_tree_host()->root_layer()->scroll_offset();
156 layer_tree_host()->root_layer()->SetScrollOffset(offset + scroll_delta);
157 num_scrolls_++; 153 num_scrolls_++;
158 } 154 }
159 155
160 virtual void AfterTest() OVERRIDE { EXPECT_EQ(1, num_scrolls_); } 156 virtual void AfterTest() OVERRIDE { EXPECT_EQ(1, num_scrolls_); }
161 157
162 private: 158 private:
163 gfx::Vector2d initial_scroll_; 159 gfx::Vector2d initial_scroll_;
164 gfx::Vector2d scroll_amount_; 160 gfx::Vector2d scroll_amount_;
165 int num_scrolls_; 161 int num_scrolls_;
166 }; 162 };
167 163
168 MULTI_THREAD_TEST_F(LayerTreeHostScrollTestScrollMultipleRedraw); 164 MULTI_THREAD_TEST_F(LayerTreeHostScrollTestScrollMultipleRedraw);
169 165
166 class LayerTreeHostScrollTestScrollAbortedCommit
167 : public LayerTreeHostScrollTest {
168 public:
169 LayerTreeHostScrollTestScrollAbortedCommit()
170 : initial_scroll_(50, 60),
171 impl_scroll_(-3, 2),
172 second_main_scroll_(14, -3),
173 impl_scale_(2.f),
174 num_will_begin_frames_(0),
175 num_did_begin_frames_(0),
176 num_will_commits_(0),
177 num_did_commits_(0),
178 num_impl_commits_(0),
179 num_impl_scrolls_(0) {}
180
181 virtual void BeginTest() OVERRIDE {
182 PostSetNeedsCommitToMainThread();
183 }
184
185 virtual void SetupTree() OVERRIDE {
186 LayerTreeHostScrollTest::SetupTree();
187 scoped_refptr<Layer> root_scroll_layer = Layer::Create();
188 root_scroll_layer->SetScrollable(true);
189 root_scroll_layer->SetScrollOffset(initial_scroll_);
190 root_scroll_layer->SetBounds(gfx::Size(200, 200));
191 root_scroll_layer->SetMaxScrollOffset(gfx::Vector2d(100, 100));
192 root_scroll_layer->SetIsDrawable(true);
193 layer_tree_host()->root_layer()->AddChild(root_scroll_layer);
194
195 layer_tree_host()->SetPageScaleFactorAndLimits(1.f, 0.01f, 100.f);
196 }
197
198 virtual void WillBeginFrame() OVERRIDE {
199 num_will_begin_frames_++;
200 Layer* root_scroll_layer = layer_tree_host()->root_layer()->children()[0];
201 switch (num_will_begin_frames_) {
202 case 1:
203 // This will not be aborted because of the initial prop changes.
204 EXPECT_EQ(0, num_impl_scrolls_);
205 EXPECT_EQ(0, layer_tree_host()->commit_number());
206 EXPECT_VECTOR_EQ(root_scroll_layer->scroll_offset(), initial_scroll_);
207 EXPECT_EQ(1.f, layer_tree_host()->page_scale_factor());
208 break;
209 case 2:
210 // This commit will be aborted, and another commit will be
211 // initiated from the redraw.
212 EXPECT_EQ(1, num_impl_scrolls_);
213 EXPECT_EQ(1, layer_tree_host()->commit_number());
214 EXPECT_VECTOR_EQ(root_scroll_layer->scroll_offset(),
215 initial_scroll_ + impl_scroll_);
216 EXPECT_EQ(impl_scale_, layer_tree_host()->page_scale_factor());
217 PostSetNeedsRedrawToMainThread();
218 break;
219 case 3:
220 // This commit will not be aborted because of the scroll change.
221 EXPECT_EQ(2, num_impl_scrolls_);
222 EXPECT_EQ(1, layer_tree_host()->commit_number());
223 EXPECT_VECTOR_EQ(root_scroll_layer->scroll_offset(),
224 initial_scroll_ + impl_scroll_ + impl_scroll_);
225 EXPECT_EQ(impl_scale_ * impl_scale_,
226 layer_tree_host()->page_scale_factor());
227 root_scroll_layer->SetScrollOffset(root_scroll_layer->scroll_offset() +
228 second_main_scroll_);
229 break;
230 case 4:
231 // This commit will also be aborted.
232 EXPECT_EQ(3, num_impl_scrolls_);
233 EXPECT_EQ(2, layer_tree_host()->commit_number());
234 EXPECT_VECTOR_EQ(root_scroll_layer->scroll_offset(),
235 initial_scroll_ + impl_scroll_ + impl_scroll_ +
236 impl_scroll_ + second_main_scroll_);
237 // End the test by drawing to verify this commit is also aborted.
238 PostSetNeedsRedrawToMainThread();
239 break;
240 }
241 }
242
243 virtual void DidBeginFrame() OVERRIDE {
244 num_did_begin_frames_++;
245 }
246
247 virtual void WillCommit() OVERRIDE {
248 num_will_commits_++;
249 }
250
251 virtual void DidCommit() OVERRIDE {
252 num_did_commits_++;
253 }
254
255 virtual void BeginCommitOnThread(LayerTreeHostImpl* impl) OVERRIDE {
256 num_impl_commits_++;
257 }
258
259 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE {
260 LayerImpl* root_scroll_layer =
261 impl->active_tree()->root_layer()->children()[0];
262
263 if (impl->active_tree()->source_frame_number() == 0 &&
264 impl->SourceAnimationFrameNumber() == 1) {
265 // First draw
266 EXPECT_VECTOR_EQ(root_scroll_layer->ScrollDelta(), gfx::Vector2d());
267 root_scroll_layer->ScrollBy(impl_scroll_);
268 EXPECT_VECTOR_EQ(root_scroll_layer->ScrollDelta(), impl_scroll_);
269 EXPECT_VECTOR_EQ(root_scroll_layer->scroll_offset(), initial_scroll_);
270
271 EXPECT_EQ(1.f, impl->active_tree()->page_scale_delta());
272 EXPECT_EQ(1.f, impl->active_tree()->total_page_scale_factor());
273 impl->active_tree()->SetPageScaleDelta(impl_scale_);
274 EXPECT_EQ(impl_scale_, impl->active_tree()->page_scale_delta());
275 EXPECT_EQ(impl_scale_, impl->active_tree()->total_page_scale_factor());
276
277 // To simplify the testing flow, don't redraw here, just commit.
278 impl->SetNeedsCommit();
279 } else if (impl->active_tree()->source_frame_number() == 0 &&
280 impl->SourceAnimationFrameNumber() == 2) {
281 // Test a second draw after an aborted commit.
282 // The scroll/scale values should be baked into the offset/scale factor
283 // since the main thread consumed but aborted the begin frame.
284 EXPECT_VECTOR_EQ(root_scroll_layer->ScrollDelta(), gfx::Vector2d());
285 root_scroll_layer->ScrollBy(impl_scroll_);
286 EXPECT_VECTOR_EQ(root_scroll_layer->ScrollDelta(), impl_scroll_);
287 EXPECT_VECTOR_EQ(root_scroll_layer->scroll_offset(),
288 initial_scroll_ + impl_scroll_);
289
290 EXPECT_EQ(1.f, impl->active_tree()->page_scale_delta());
291 EXPECT_EQ(impl_scale_, impl->active_tree()->total_page_scale_factor());
292 impl->active_tree()->SetPageScaleDelta(impl_scale_);
293 EXPECT_EQ(impl_scale_, impl->active_tree()->page_scale_delta());
294 EXPECT_EQ(impl_scale_ * impl_scale_,
295 impl->active_tree()->total_page_scale_factor());
296
297 impl->SetNeedsCommit();
298 } else if (impl->active_tree()->source_frame_number() == 1 &&
299 impl->SourceAnimationFrameNumber() == 3) {
300 // Third draw after the second full commit.
301 EXPECT_EQ(root_scroll_layer->ScrollDelta(), gfx::Vector2d());
302 root_scroll_layer->ScrollBy(impl_scroll_);
303 impl->SetNeedsCommit();
304 EXPECT_VECTOR_EQ(root_scroll_layer->ScrollDelta(), impl_scroll_);
305 EXPECT_VECTOR_EQ(
306 root_scroll_layer->scroll_offset(),
307 initial_scroll_ + impl_scroll_ + impl_scroll_ + second_main_scroll_);
308 } else if (impl->active_tree()->source_frame_number() == 1 &&
309 impl->SourceAnimationFrameNumber() == 4) {
310 // Final draw after the second aborted commit.
311 EXPECT_VECTOR_EQ(root_scroll_layer->ScrollDelta(), gfx::Vector2d());
312 EXPECT_VECTOR_EQ(root_scroll_layer->scroll_offset(),
313 initial_scroll_ + impl_scroll_ + impl_scroll_ +
314 impl_scroll_ + second_main_scroll_);
315 EndTest();
316 }
317 }
318
319 virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta, float scale)
320 OVERRIDE {
321 num_impl_scrolls_++;
322 }
323
324 virtual void AfterTest() OVERRIDE {
325 EXPECT_EQ(3, num_impl_scrolls_);
326 // Verify that the embedder sees aborted commits as real commits.
327 EXPECT_EQ(4, num_will_begin_frames_);
328 EXPECT_EQ(4, num_did_begin_frames_);
329 EXPECT_EQ(4, num_will_commits_);
330 EXPECT_EQ(4, num_did_commits_);
331 // ...but the compositor thread only sees two real ones.
332 EXPECT_EQ(2, num_impl_commits_);
333 }
334
335 private:
336 gfx::Vector2d initial_scroll_;
337 gfx::Vector2d impl_scroll_;
338 gfx::Vector2d second_main_scroll_;
339 float impl_scale_;
340 int num_will_begin_frames_;
341 int num_did_begin_frames_;
342 int num_will_commits_;
343 int num_did_commits_;
344 int num_impl_commits_;
345 int num_impl_scrolls_;
346 };
347
348 MULTI_THREAD_TEST_F(LayerTreeHostScrollTestScrollAbortedCommit);
349
170 class LayerTreeHostScrollTestFractionalScroll : public LayerTreeHostScrollTest { 350 class LayerTreeHostScrollTestFractionalScroll : public LayerTreeHostScrollTest {
171 public: 351 public:
172 LayerTreeHostScrollTestFractionalScroll() : scroll_amount_(1.75, 0) {} 352 LayerTreeHostScrollTestFractionalScroll() : scroll_amount_(1.75, 0) {}
173 353
174 virtual void BeginTest() OVERRIDE { 354 virtual void BeginTest() OVERRIDE {
175 layer_tree_host()->root_layer()->SetScrollable(true); 355 layer_tree_host()->root_layer()->SetScrollable(true);
176 PostSetNeedsCommitToMainThread(); 356 PostSetNeedsCommitToMainThread();
177 } 357 }
178 358
179 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { 359 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE {
(...skipping 21 matching lines...) Expand all
201 gfx::ToFlooredVector2d(scroll_amount_ + scroll_amount_)); 381 gfx::ToFlooredVector2d(scroll_amount_ + scroll_amount_));
202 EXPECT_VECTOR_EQ( 382 EXPECT_VECTOR_EQ(
203 root->ScrollDelta(), 383 root->ScrollDelta(),
204 gfx::Vector2dF(fmod(2.0f * scroll_amount_.x(), 1.0f), 0.0f)); 384 gfx::Vector2dF(fmod(2.0f * scroll_amount_.x(), 1.0f), 0.0f));
205 EndTest(); 385 EndTest();
206 break; 386 break;
207 } 387 }
208 root->ScrollBy(scroll_amount_); 388 root->ScrollBy(scroll_amount_);
209 } 389 }
210 390
211 virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta, float scale)
212 OVERRIDE {
213 gfx::Vector2d offset = layer_tree_host()->root_layer()->scroll_offset();
214 layer_tree_host()->root_layer()->SetScrollOffset(offset + scroll_delta);
215 }
216
217 virtual void AfterTest() OVERRIDE {} 391 virtual void AfterTest() OVERRIDE {}
218 392
219 private: 393 private:
220 gfx::Vector2dF scroll_amount_; 394 gfx::Vector2dF scroll_amount_;
221 }; 395 };
222 396
223 MULTI_THREAD_TEST_F(LayerTreeHostScrollTestFractionalScroll); 397 MULTI_THREAD_TEST_F(LayerTreeHostScrollTestFractionalScroll);
224 398
225 class LayerTreeHostScrollTestCaseWithChild : public LayerTreeHostScrollTest { 399 class LayerTreeHostScrollTestCaseWithChild : public LayerTreeHostScrollTest {
226 public: 400 public:
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 } 452 }
279 453
280 expected_scroll_layer_->SetScrollOffset(initial_offset_); 454 expected_scroll_layer_->SetScrollOffset(initial_offset_);
281 455
282 layer_tree_host()->SetRootLayer(root_layer); 456 layer_tree_host()->SetRootLayer(root_layer);
283 LayerTreeHostScrollTest::SetupTree(); 457 LayerTreeHostScrollTest::SetupTree();
284 } 458 }
285 459
286 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } 460 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); }
287 461
462 virtual void WillCommit() OVERRIDE {
463 // Keep the test committing (otherwise the early out for no update
464 // will stall the test).
465 layer_tree_host()->SetNeedsCommit();
466 }
467
288 void DidScroll() { 468 void DidScroll() {
289 final_scroll_offset_ = expected_scroll_layer_->scroll_offset(); 469 final_scroll_offset_ = expected_scroll_layer_->scroll_offset();
290 } 470 }
291 471
292 virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta, float scale) 472 virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta, float scale)
293 OVERRIDE { 473 OVERRIDE {
294 gfx::Vector2d offset = root_scroll_layer_->scroll_offset();
295 root_scroll_layer_->SetScrollOffset(offset + scroll_delta);
296 num_scrolls_++; 474 num_scrolls_++;
297 } 475 }
298 476
299 virtual void Layout() OVERRIDE { 477 virtual void Layout() OVERRIDE {
300 EXPECT_VECTOR_EQ(gfx::Vector2d(), 478 EXPECT_VECTOR_EQ(gfx::Vector2d(),
301 expected_no_scroll_layer_->scroll_offset()); 479 expected_no_scroll_layer_->scroll_offset());
302 480
303 switch (layer_tree_host()->commit_number()) { 481 switch (layer_tree_host()->commit_number()) {
304 case 0: 482 case 0:
305 EXPECT_VECTOR_EQ(initial_offset_, 483 EXPECT_VECTOR_EQ(initial_offset_,
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
637 initial_scroll_ + main_thread_scroll_ + impl_thread_scroll1_); 815 initial_scroll_ + main_thread_scroll_ + impl_thread_scroll1_);
638 EXPECT_VECTOR_EQ(root->ScrollDelta(), impl_thread_scroll2_); 816 EXPECT_VECTOR_EQ(root->ScrollDelta(), impl_thread_scroll2_);
639 EXPECT_VECTOR_EQ(root->sent_scroll_delta(), gfx::Vector2d()); 817 EXPECT_VECTOR_EQ(root->sent_scroll_delta(), gfx::Vector2d());
640 EndTest(); 818 EndTest();
641 break; 819 break;
642 } 820 }
643 } 821 }
644 822
645 virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta, float scale) 823 virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta, float scale)
646 OVERRIDE { 824 OVERRIDE {
647 gfx::Vector2d offset = layer_tree_host()->root_layer()->scroll_offset();
648 layer_tree_host()->root_layer()->SetScrollOffset(offset + scroll_delta);
649 num_scrolls_++; 825 num_scrolls_++;
650 } 826 }
651 827
652 virtual void AfterTest() OVERRIDE { EXPECT_EQ(1, num_scrolls_); } 828 virtual void AfterTest() OVERRIDE { EXPECT_EQ(1, num_scrolls_); }
653 829
654 private: 830 private:
655 gfx::Vector2d initial_scroll_; 831 gfx::Vector2d initial_scroll_;
656 gfx::Vector2d main_thread_scroll_; 832 gfx::Vector2d main_thread_scroll_;
657 gfx::Vector2d impl_thread_scroll1_; 833 gfx::Vector2d impl_thread_scroll1_;
658 gfx::Vector2d impl_thread_scroll2_; 834 gfx::Vector2d impl_thread_scroll2_;
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
848 RunTest(true, false, false); 1024 RunTest(true, false, false);
849 } 1025 }
850 1026
851 TEST_F(LayerTreeHostScrollTestLayerStructureChange, ScrollDestroyWholeTree) { 1027 TEST_F(LayerTreeHostScrollTestLayerStructureChange, ScrollDestroyWholeTree) {
852 scroll_destroy_whole_tree_ = true; 1028 scroll_destroy_whole_tree_ = true;
853 RunTest(true, false, false); 1029 RunTest(true, false, false);
854 } 1030 }
855 1031
856 } // namespace 1032 } // namespace
857 } // namespace cc 1033 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698