OLD | NEW |
---|---|
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 Loading... | |
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 Loading... | |
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 layer_tree_host()->root_layer()->SetScrollable(true); | |
183 layer_tree_host()->root_layer()->SetScrollOffset(initial_scroll_); | |
184 layer_tree_host()->root_layer()->SetBounds(gfx::Size(200, 200)); | |
185 layer_tree_host()->root_layer() | |
186 ->SetMaxScrollOffset(gfx::Vector2d(100, 100)); | |
187 layer_tree_host()->SetPageScaleFactorAndLimits(1.f, 0.01f, 100.f); | |
188 PostSetNeedsCommitToMainThread(); | |
189 } | |
190 | |
191 virtual void WillBeginFrame() OVERRIDE { | |
192 num_will_begin_frames_++; | |
193 Layer* root = layer_tree_host()->root_layer(); | |
194 switch (num_will_begin_frames_) { | |
195 case 1: | |
196 // This will not be aborted because of the initial prop changes. | |
197 EXPECT_EQ(0, num_impl_scrolls_); | |
198 EXPECT_EQ(0, layer_tree_host()->commit_number()); | |
199 EXPECT_VECTOR_EQ(root->scroll_offset(), initial_scroll_); | |
200 EXPECT_EQ(1.f, layer_tree_host()->page_scale_factor()); | |
201 break; | |
202 case 2: | |
203 // This commit will be aborted, and another commit will be | |
204 // initiated from the redraw. | |
205 EXPECT_EQ(1, num_impl_scrolls_); | |
206 EXPECT_EQ(1, layer_tree_host()->commit_number()); | |
207 EXPECT_VECTOR_EQ(root->scroll_offset(), | |
208 initial_scroll_ + impl_scroll_); | |
209 EXPECT_EQ(impl_scale_, layer_tree_host()->page_scale_factor()); | |
210 PostSetNeedsRedrawToMainThread(); | |
211 break; | |
212 case 3: | |
213 // This commit will not be aborted because of the scroll change. | |
214 EXPECT_EQ(2, num_impl_scrolls_); | |
215 EXPECT_EQ(1, layer_tree_host()->commit_number()); | |
216 EXPECT_VECTOR_EQ(root->scroll_offset(), | |
217 initial_scroll_ + impl_scroll_ + impl_scroll_); | |
218 EXPECT_EQ(impl_scale_ * impl_scale_, | |
219 layer_tree_host()->page_scale_factor()); | |
220 root->SetScrollOffset(root->scroll_offset() + second_main_scroll_); | |
221 break; | |
222 case 4: | |
223 // This commit will also be aborted. | |
224 EXPECT_EQ(3, num_impl_scrolls_); | |
225 EXPECT_EQ(2, layer_tree_host()->commit_number()); | |
226 EXPECT_VECTOR_EQ(root->scroll_offset(), | |
227 initial_scroll_ + impl_scroll_ + impl_scroll_ + | |
228 impl_scroll_ + second_main_scroll_); | |
229 // End the test by drawing to verify this commit is also aborted. | |
230 PostSetNeedsRedrawToMainThread(); | |
231 break; | |
232 } | |
233 } | |
234 | |
235 virtual void DidBeginFrame() OVERRIDE { | |
236 num_did_begin_frames_++; | |
237 } | |
238 | |
239 virtual void WillCommit() OVERRIDE { | |
240 num_will_commits_++; | |
241 } | |
242 | |
243 virtual void DidCommit() OVERRIDE { | |
244 num_did_commits_++; | |
245 } | |
246 virtual void BeginCommitOnThread(LayerTreeHostImpl* impl) OVERRIDE { | |
danakj
2013/07/17 20:53:24
nit: blank line above
enne (OOO)
2013/07/18 17:36:37
Done.
| |
247 num_impl_commits_++; | |
248 } | |
249 | |
250 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { | |
251 LayerImpl* root = impl->active_tree()->root_layer(); | |
252 | |
253 if (impl->active_tree()->source_frame_number() == 0 && | |
254 impl->SourceAnimationFrameNumber() == 1) { | |
255 // First draw | |
256 EXPECT_VECTOR_EQ(root->ScrollDelta(), gfx::Vector2d()); | |
257 root->ScrollBy(impl_scroll_); | |
258 EXPECT_VECTOR_EQ(root->ScrollDelta(), impl_scroll_); | |
259 EXPECT_VECTOR_EQ(root->scroll_offset(), initial_scroll_); | |
260 | |
261 EXPECT_EQ(1.f, impl->active_tree()->page_scale_delta()); | |
262 EXPECT_EQ(1.f, impl->active_tree()->total_page_scale_factor()); | |
263 impl->active_tree()->SetPageScaleDelta(impl_scale_); | |
264 EXPECT_EQ(impl_scale_, impl->active_tree()->page_scale_delta()); | |
265 EXPECT_EQ(impl_scale_, impl->active_tree()->total_page_scale_factor()); | |
266 | |
267 // To simplify the testing flow, don't redraw here, just commit. | |
268 impl->SetNeedsCommit(); | |
269 } else if (impl->active_tree()->source_frame_number() == 0 && | |
270 impl->SourceAnimationFrameNumber() == 2) { | |
271 // Test a second draw after an aborted commit. | |
272 // The scroll/scale values should be baked into the offset/scale factor | |
273 // since the main thread consumed but aborted the begin frame. | |
274 EXPECT_VECTOR_EQ(root->ScrollDelta(), gfx::Vector2d()); | |
275 root->ScrollBy(impl_scroll_); | |
276 EXPECT_VECTOR_EQ(root->ScrollDelta(), impl_scroll_); | |
277 EXPECT_VECTOR_EQ(root->scroll_offset(), initial_scroll_ + impl_scroll_); | |
278 | |
279 EXPECT_EQ(1.f, impl->active_tree()->page_scale_delta()); | |
280 EXPECT_EQ(impl_scale_, impl->active_tree()->total_page_scale_factor()); | |
281 impl->active_tree()->SetPageScaleDelta(impl_scale_); | |
282 EXPECT_EQ(impl_scale_, impl->active_tree()->page_scale_delta()); | |
283 EXPECT_EQ(impl_scale_ * impl_scale_, | |
284 impl->active_tree()->total_page_scale_factor()); | |
285 | |
286 impl->SetNeedsCommit(); | |
287 } else if (impl->active_tree()->source_frame_number() == 1 && | |
288 impl->SourceAnimationFrameNumber() == 3) { | |
289 // Third draw after the second full commit. | |
290 EXPECT_EQ(root->ScrollDelta(), gfx::Vector2d()); | |
291 root->ScrollBy(impl_scroll_); | |
292 impl->SetNeedsCommit(); | |
293 EXPECT_VECTOR_EQ(root->ScrollDelta(), impl_scroll_); | |
294 EXPECT_VECTOR_EQ( | |
295 root->scroll_offset(), | |
296 initial_scroll_ + impl_scroll_ + impl_scroll_ + second_main_scroll_); | |
297 } else if (impl->active_tree()->source_frame_number() == 1 && | |
298 impl->SourceAnimationFrameNumber() == 4) { | |
299 // Final draw after the second aborted commit. | |
300 EXPECT_VECTOR_EQ(root->ScrollDelta(), gfx::Vector2d()); | |
301 EXPECT_VECTOR_EQ(root->scroll_offset(), | |
302 initial_scroll_ + impl_scroll_ + impl_scroll_ + | |
303 impl_scroll_ + second_main_scroll_); | |
304 EndTest(); | |
305 } | |
306 } | |
307 | |
308 virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta, float scale) | |
309 OVERRIDE { | |
310 // Emulate Blink: | |
311 layer_tree_host()->SetPageScaleFactorAndLimits( | |
312 layer_tree_host()->page_scale_factor() * scale, 0.01f, 100.f); | |
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); | |
danakj
2013/07/17 20:53:24
Does this fail in single thread?
enne (OOO)
2013/07/18 17:36:37
Yes. You can't get non-zero scroll deltas in the
| |
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 Loading... | |
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 Loading... | |
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 layer_tree_host()->SetNeedsCommit(); | |
458 } | |
459 | |
288 void DidScroll() { | 460 void DidScroll() { |
289 final_scroll_offset_ = expected_scroll_layer_->scroll_offset(); | 461 final_scroll_offset_ = expected_scroll_layer_->scroll_offset(); |
290 } | 462 } |
291 | 463 |
292 virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta, float scale) | 464 virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta, float scale) |
293 OVERRIDE { | 465 OVERRIDE { |
294 gfx::Vector2d offset = root_scroll_layer_->scroll_offset(); | |
295 root_scroll_layer_->SetScrollOffset(offset + scroll_delta); | |
296 num_scrolls_++; | 466 num_scrolls_++; |
297 } | 467 } |
298 | 468 |
299 virtual void Layout() OVERRIDE { | 469 virtual void Layout() OVERRIDE { |
300 EXPECT_VECTOR_EQ(gfx::Vector2d(), | 470 EXPECT_VECTOR_EQ(gfx::Vector2d(), |
301 expected_no_scroll_layer_->scroll_offset()); | 471 expected_no_scroll_layer_->scroll_offset()); |
302 | 472 |
303 switch (layer_tree_host()->commit_number()) { | 473 switch (layer_tree_host()->commit_number()) { |
304 case 0: | 474 case 0: |
305 EXPECT_VECTOR_EQ(initial_offset_, | 475 EXPECT_VECTOR_EQ(initial_offset_, |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
637 initial_scroll_ + main_thread_scroll_ + impl_thread_scroll1_); | 807 initial_scroll_ + main_thread_scroll_ + impl_thread_scroll1_); |
638 EXPECT_VECTOR_EQ(root->ScrollDelta(), impl_thread_scroll2_); | 808 EXPECT_VECTOR_EQ(root->ScrollDelta(), impl_thread_scroll2_); |
639 EXPECT_VECTOR_EQ(root->sent_scroll_delta(), gfx::Vector2d()); | 809 EXPECT_VECTOR_EQ(root->sent_scroll_delta(), gfx::Vector2d()); |
640 EndTest(); | 810 EndTest(); |
641 break; | 811 break; |
642 } | 812 } |
643 } | 813 } |
644 | 814 |
645 virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta, float scale) | 815 virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta, float scale) |
646 OVERRIDE { | 816 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_++; | 817 num_scrolls_++; |
650 } | 818 } |
651 | 819 |
652 virtual void AfterTest() OVERRIDE { EXPECT_EQ(1, num_scrolls_); } | 820 virtual void AfterTest() OVERRIDE { EXPECT_EQ(1, num_scrolls_); } |
653 | 821 |
654 private: | 822 private: |
655 gfx::Vector2d initial_scroll_; | 823 gfx::Vector2d initial_scroll_; |
656 gfx::Vector2d main_thread_scroll_; | 824 gfx::Vector2d main_thread_scroll_; |
657 gfx::Vector2d impl_thread_scroll1_; | 825 gfx::Vector2d impl_thread_scroll1_; |
658 gfx::Vector2d impl_thread_scroll2_; | 826 gfx::Vector2d impl_thread_scroll2_; |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
849 RunTest(true, false, false); | 1017 RunTest(true, false, false); |
850 } | 1018 } |
851 | 1019 |
852 TEST_F(LayerTreeHostScrollTestLayerStructureChange, ScrollDestroyWholeTree) { | 1020 TEST_F(LayerTreeHostScrollTestLayerStructureChange, ScrollDestroyWholeTree) { |
853 scroll_destroy_whole_tree_ = true; | 1021 scroll_destroy_whole_tree_ = true; |
854 RunTest(true, false, false); | 1022 RunTest(true, false, false); |
855 } | 1023 } |
856 | 1024 |
857 } // namespace | 1025 } // namespace |
858 } // namespace cc | 1026 } // namespace cc |
OLD | NEW |