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

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: Add more comments Created 7 years, 4 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 PostSetNeedsCommitToMainThread(); 63 PostSetNeedsCommitToMainThread();
64 break; 64 break;
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,
74 OVERRIDE { 74 float scale) 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 } else if (impl->active_tree()->source_frame_number() == 1) { 141 } else if (impl->active_tree()->source_frame_number() == 1) {
144 // Third or later draw after second commit. 142 // Third or later draw after second commit.
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,
154 OVERRIDE { 152 float scale) 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 { PostSetNeedsCommitToMainThread(); }
182
183 virtual void SetupTree() OVERRIDE {
184 LayerTreeHostScrollTest::SetupTree();
185 scoped_refptr<Layer> root_scroll_layer = Layer::Create();
186 root_scroll_layer->SetScrollable(true);
187 root_scroll_layer->SetScrollOffset(initial_scroll_);
188 root_scroll_layer->SetBounds(gfx::Size(200, 200));
189 root_scroll_layer->SetMaxScrollOffset(gfx::Vector2d(100, 100));
190 root_scroll_layer->SetIsDrawable(true);
191 layer_tree_host()->root_layer()->AddChild(root_scroll_layer);
192
193 layer_tree_host()->SetPageScaleFactorAndLimits(1.f, 0.01f, 100.f);
194 }
195
196 virtual void WillBeginFrame() OVERRIDE {
197 num_will_begin_frames_++;
198 Layer* root_scroll_layer = layer_tree_host()->root_layer()->children()[0];
199 switch (num_will_begin_frames_) {
200 case 1:
201 // This will not be aborted because of the initial prop changes.
202 EXPECT_EQ(0, num_impl_scrolls_);
203 EXPECT_EQ(0, layer_tree_host()->source_frame_number());
204 EXPECT_VECTOR_EQ(root_scroll_layer->scroll_offset(), initial_scroll_);
205 EXPECT_EQ(1.f, layer_tree_host()->page_scale_factor());
206 break;
207 case 2:
208 // This commit will be aborted, and another commit will be
209 // initiated from the redraw.
210 EXPECT_EQ(1, num_impl_scrolls_);
211 EXPECT_EQ(1, layer_tree_host()->source_frame_number());
212 EXPECT_VECTOR_EQ(root_scroll_layer->scroll_offset(),
213 initial_scroll_ + impl_scroll_);
214 EXPECT_EQ(impl_scale_, layer_tree_host()->page_scale_factor());
215 PostSetNeedsRedrawToMainThread();
216 break;
217 case 3:
218 // This commit will not be aborted because of the scroll change.
219 EXPECT_EQ(2, num_impl_scrolls_);
220 EXPECT_EQ(1, layer_tree_host()->source_frame_number());
221 EXPECT_VECTOR_EQ(root_scroll_layer->scroll_offset(),
222 initial_scroll_ + impl_scroll_ + impl_scroll_);
223 EXPECT_EQ(impl_scale_ * impl_scale_,
224 layer_tree_host()->page_scale_factor());
225 root_scroll_layer->SetScrollOffset(root_scroll_layer->scroll_offset() +
226 second_main_scroll_);
227 break;
228 case 4:
229 // This commit will also be aborted.
230 EXPECT_EQ(3, num_impl_scrolls_);
231 EXPECT_EQ(2, layer_tree_host()->source_frame_number());
232 EXPECT_VECTOR_EQ(root_scroll_layer->scroll_offset(),
233 initial_scroll_ + impl_scroll_ + impl_scroll_ +
234 impl_scroll_ + second_main_scroll_);
235 // End the test by drawing to verify this commit is also aborted.
236 PostSetNeedsRedrawToMainThread();
237 break;
238 }
239 }
240
241 virtual void DidBeginFrame() OVERRIDE { num_did_begin_frames_++; }
242
243 virtual void WillCommit() OVERRIDE { num_will_commits_++; }
244
245 virtual void DidCommit() OVERRIDE { num_did_commits_++; }
246
247 virtual void BeginCommitOnThread(LayerTreeHostImpl* impl) OVERRIDE {
248 num_impl_commits_++;
249 }
250
251 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE {
252 LayerImpl* root_scroll_layer =
253 impl->active_tree()->root_layer()->children()[0];
254
255 if (impl->active_tree()->source_frame_number() == 0 &&
256 impl->SourceAnimationFrameNumber() == 1) {
257 // First draw
258 EXPECT_VECTOR_EQ(root_scroll_layer->ScrollDelta(), gfx::Vector2d());
259 root_scroll_layer->ScrollBy(impl_scroll_);
260 EXPECT_VECTOR_EQ(root_scroll_layer->ScrollDelta(), impl_scroll_);
261 EXPECT_VECTOR_EQ(root_scroll_layer->scroll_offset(), initial_scroll_);
262
263 EXPECT_EQ(1.f, impl->active_tree()->page_scale_delta());
264 EXPECT_EQ(1.f, impl->active_tree()->total_page_scale_factor());
265 impl->active_tree()->SetPageScaleDelta(impl_scale_);
266 EXPECT_EQ(impl_scale_, impl->active_tree()->page_scale_delta());
267 EXPECT_EQ(impl_scale_, impl->active_tree()->total_page_scale_factor());
268
269 // To simplify the testing flow, don't redraw here, just commit.
270 impl->SetNeedsCommit();
271 } else if (impl->active_tree()->source_frame_number() == 0 &&
272 impl->SourceAnimationFrameNumber() == 2) {
273 // Test a second draw after an aborted commit.
274 // The scroll/scale values should be baked into the offset/scale factor
275 // since the main thread consumed but aborted the begin frame.
276 EXPECT_VECTOR_EQ(root_scroll_layer->ScrollDelta(), gfx::Vector2d());
277 root_scroll_layer->ScrollBy(impl_scroll_);
278 EXPECT_VECTOR_EQ(root_scroll_layer->ScrollDelta(), impl_scroll_);
279 EXPECT_VECTOR_EQ(root_scroll_layer->scroll_offset(),
280 initial_scroll_ + impl_scroll_);
281
282 EXPECT_EQ(1.f, impl->active_tree()->page_scale_delta());
283 EXPECT_EQ(impl_scale_, impl->active_tree()->total_page_scale_factor());
284 impl->active_tree()->SetPageScaleDelta(impl_scale_);
285 EXPECT_EQ(impl_scale_, impl->active_tree()->page_scale_delta());
286 EXPECT_EQ(impl_scale_ * impl_scale_,
287 impl->active_tree()->total_page_scale_factor());
288
289 impl->SetNeedsCommit();
290 } else if (impl->active_tree()->source_frame_number() == 1 &&
291 impl->SourceAnimationFrameNumber() == 3) {
292 // Third draw after the second full commit.
293 EXPECT_EQ(root_scroll_layer->ScrollDelta(), gfx::Vector2d());
294 root_scroll_layer->ScrollBy(impl_scroll_);
295 impl->SetNeedsCommit();
296 EXPECT_VECTOR_EQ(root_scroll_layer->ScrollDelta(), impl_scroll_);
297 EXPECT_VECTOR_EQ(
298 root_scroll_layer->scroll_offset(),
299 initial_scroll_ + impl_scroll_ + impl_scroll_ + second_main_scroll_);
300 } else if (impl->active_tree()->source_frame_number() == 1 &&
301 impl->SourceAnimationFrameNumber() == 4) {
302 // Final draw after the second aborted commit.
303 EXPECT_VECTOR_EQ(root_scroll_layer->ScrollDelta(), gfx::Vector2d());
304 EXPECT_VECTOR_EQ(root_scroll_layer->scroll_offset(),
305 initial_scroll_ + impl_scroll_ + impl_scroll_ +
306 impl_scroll_ + second_main_scroll_);
307 EndTest();
308 }
309 }
310
311 virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta,
312 float scale) OVERRIDE {
313 num_impl_scrolls_++;
314 }
315
316 virtual void AfterTest() OVERRIDE {
317 EXPECT_EQ(3, num_impl_scrolls_);
318 // Verify that the embedder sees aborted commits as real commits.
319 EXPECT_EQ(4, num_will_begin_frames_);
320 EXPECT_EQ(4, num_did_begin_frames_);
321 EXPECT_EQ(4, num_will_commits_);
322 EXPECT_EQ(4, num_did_commits_);
323 // ...but the compositor thread only sees two real ones.
324 EXPECT_EQ(2, num_impl_commits_);
325 }
326
327 private:
328 gfx::Vector2d initial_scroll_;
329 gfx::Vector2d impl_scroll_;
330 gfx::Vector2d second_main_scroll_;
331 float impl_scale_;
332 int num_will_begin_frames_;
333 int num_did_begin_frames_;
334 int num_will_commits_;
335 int num_did_commits_;
336 int num_impl_commits_;
337 int num_impl_scrolls_;
338 };
339
340 MULTI_THREAD_TEST_F(LayerTreeHostScrollTestScrollAbortedCommit);
341
170 class LayerTreeHostScrollTestFractionalScroll : public LayerTreeHostScrollTest { 342 class LayerTreeHostScrollTestFractionalScroll : public LayerTreeHostScrollTest {
171 public: 343 public:
172 LayerTreeHostScrollTestFractionalScroll() : scroll_amount_(1.75, 0) {} 344 LayerTreeHostScrollTestFractionalScroll() : scroll_amount_(1.75, 0) {}
173 345
174 virtual void BeginTest() OVERRIDE { 346 virtual void BeginTest() OVERRIDE {
175 layer_tree_host()->root_layer()->SetScrollable(true); 347 layer_tree_host()->root_layer()->SetScrollable(true);
176 PostSetNeedsCommitToMainThread(); 348 PostSetNeedsCommitToMainThread();
177 } 349 }
178 350
179 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { 351 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE {
(...skipping 21 matching lines...) Expand all
201 gfx::ToFlooredVector2d(scroll_amount_ + scroll_amount_)); 373 gfx::ToFlooredVector2d(scroll_amount_ + scroll_amount_));
202 EXPECT_VECTOR_EQ( 374 EXPECT_VECTOR_EQ(
203 root->ScrollDelta(), 375 root->ScrollDelta(),
204 gfx::Vector2dF(fmod(2.0f * scroll_amount_.x(), 1.0f), 0.0f)); 376 gfx::Vector2dF(fmod(2.0f * scroll_amount_.x(), 1.0f), 0.0f));
205 EndTest(); 377 EndTest();
206 break; 378 break;
207 } 379 }
208 root->ScrollBy(scroll_amount_); 380 root->ScrollBy(scroll_amount_);
209 } 381 }
210 382
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 {} 383 virtual void AfterTest() OVERRIDE {}
218 384
219 private: 385 private:
220 gfx::Vector2dF scroll_amount_; 386 gfx::Vector2dF scroll_amount_;
221 }; 387 };
222 388
223 MULTI_THREAD_TEST_F(LayerTreeHostScrollTestFractionalScroll); 389 MULTI_THREAD_TEST_F(LayerTreeHostScrollTestFractionalScroll);
224 390
225 class LayerTreeHostScrollTestCaseWithChild : public LayerTreeHostScrollTest { 391 class LayerTreeHostScrollTestCaseWithChild : public LayerTreeHostScrollTest {
226 public: 392 public:
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 } 444 }
279 445
280 expected_scroll_layer_->SetScrollOffset(initial_offset_); 446 expected_scroll_layer_->SetScrollOffset(initial_offset_);
281 447
282 layer_tree_host()->SetRootLayer(root_layer); 448 layer_tree_host()->SetRootLayer(root_layer);
283 LayerTreeHostScrollTest::SetupTree(); 449 LayerTreeHostScrollTest::SetupTree();
284 } 450 }
285 451
286 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } 452 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); }
287 453
454 virtual void WillCommit() OVERRIDE {
455 // Keep the test committing (otherwise the early out for no update
456 // will stall the test).
457 if (layer_tree_host()->source_frame_number() < 2) {
458 layer_tree_host()->SetNeedsCommit();
459 }
460 }
461
288 void DidScroll() { 462 void DidScroll() {
289 final_scroll_offset_ = expected_scroll_layer_->scroll_offset(); 463 final_scroll_offset_ = expected_scroll_layer_->scroll_offset();
290 } 464 }
291 465
292 virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta, float scale) 466 virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta,
293 OVERRIDE { 467 float scale) OVERRIDE {
294 gfx::Vector2d offset = root_scroll_layer_->scroll_offset();
295 root_scroll_layer_->SetScrollOffset(offset + scroll_delta);
296 num_scrolls_++; 468 num_scrolls_++;
297 } 469 }
298 470
299 virtual void Layout() OVERRIDE { 471 virtual void Layout() OVERRIDE {
300 EXPECT_VECTOR_EQ(gfx::Vector2d(), 472 EXPECT_VECTOR_EQ(gfx::Vector2d(),
301 expected_no_scroll_layer_->scroll_offset()); 473 expected_no_scroll_layer_->scroll_offset());
302 474
303 switch (layer_tree_host()->source_frame_number()) { 475 switch (layer_tree_host()->source_frame_number()) {
304 case 0: 476 case 0:
305 EXPECT_VECTOR_EQ(initial_offset_, 477 EXPECT_VECTOR_EQ(initial_offset_,
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 EXPECT_VECTOR_EQ( 807 EXPECT_VECTOR_EQ(
636 root->scroll_offset(), 808 root->scroll_offset(),
637 initial_scroll_ + main_thread_scroll_ + impl_thread_scroll1_); 809 initial_scroll_ + main_thread_scroll_ + impl_thread_scroll1_);
638 EXPECT_VECTOR_EQ(root->ScrollDelta(), impl_thread_scroll2_); 810 EXPECT_VECTOR_EQ(root->ScrollDelta(), impl_thread_scroll2_);
639 EXPECT_VECTOR_EQ(root->sent_scroll_delta(), gfx::Vector2d()); 811 EXPECT_VECTOR_EQ(root->sent_scroll_delta(), gfx::Vector2d());
640 EndTest(); 812 EndTest();
641 break; 813 break;
642 } 814 }
643 } 815 }
644 816
645 virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta, float scale) 817 virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta,
646 OVERRIDE { 818 float scale) 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_++; 819 num_scrolls_++;
650 } 820 }
651 821
652 virtual void AfterTest() OVERRIDE { EXPECT_EQ(1, num_scrolls_); } 822 virtual void AfterTest() OVERRIDE { EXPECT_EQ(1, num_scrolls_); }
653 823
654 private: 824 private:
655 gfx::Vector2d initial_scroll_; 825 gfx::Vector2d initial_scroll_;
656 gfx::Vector2d main_thread_scroll_; 826 gfx::Vector2d main_thread_scroll_;
657 gfx::Vector2d impl_thread_scroll1_; 827 gfx::Vector2d impl_thread_scroll1_;
658 gfx::Vector2d impl_thread_scroll2_; 828 gfx::Vector2d impl_thread_scroll2_;
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
848 RunTest(true, false, false); 1018 RunTest(true, false, false);
849 } 1019 }
850 1020
851 TEST_F(LayerTreeHostScrollTestLayerStructureChange, ScrollDestroyWholeTree) { 1021 TEST_F(LayerTreeHostScrollTestLayerStructureChange, ScrollDestroyWholeTree) {
852 scroll_destroy_whole_tree_ = true; 1022 scroll_destroy_whole_tree_ = true;
853 RunTest(true, false, false); 1023 RunTest(true, false, false);
854 } 1024 }
855 1025
856 } // namespace 1026 } // namespace
857 } // namespace cc 1027 } // 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