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/location.h" | 7 #include "base/location.h" |
8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
10 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
66 gfx::Size scroll_layer_bounds(root_layer->bounds().width() + 100, | 66 gfx::Size scroll_layer_bounds(root_layer->bounds().width() + 100, |
67 root_layer->bounds().height() + 100); | 67 root_layer->bounds().height() + 100); |
68 | 68 |
69 CreateVirtualViewportLayers(root_layer, | 69 CreateVirtualViewportLayers(root_layer, |
70 root_layer->bounds(), | 70 root_layer->bounds(), |
71 root_layer->bounds(), | 71 root_layer->bounds(), |
72 scroll_layer_bounds, | 72 scroll_layer_bounds, |
73 layer_tree_host(), | 73 layer_tree_host(), |
74 layer_settings()); | 74 layer_settings()); |
75 } | 75 } |
76 | |
77 public: | |
78 ScrollTree* scroll_tree(LayerImpl* layer_impl) { | |
ajuma
2016/03/07 19:10:19
This is probably better off as a helper function d
sunxd
2016/03/09 01:51:21
Done.
| |
79 return &layer_impl->layer_tree_impl()->property_trees()->scroll_tree; | |
80 } | |
76 }; | 81 }; |
77 | 82 |
78 class LayerTreeHostScrollTestScrollSimple : public LayerTreeHostScrollTest { | 83 class LayerTreeHostScrollTestScrollSimple : public LayerTreeHostScrollTest { |
79 public: | 84 public: |
80 LayerTreeHostScrollTestScrollSimple() | 85 LayerTreeHostScrollTestScrollSimple() |
81 : initial_scroll_(10, 20), | 86 : initial_scroll_(10, 20), |
82 second_scroll_(40, 5), | 87 second_scroll_(40, 5), |
83 scroll_amount_(2, -1), | 88 scroll_amount_(2, -1), |
84 num_scrolls_(0) {} | 89 num_scrolls_(0) {} |
85 | 90 |
(...skipping 22 matching lines...) Expand all Loading... | |
108 LayerImpl* scroll_layer = impl->OuterViewportScrollLayer(); | 113 LayerImpl* scroll_layer = impl->OuterViewportScrollLayer(); |
109 EXPECT_VECTOR_EQ(gfx::Vector2d(), scroll_layer->ScrollDelta()); | 114 EXPECT_VECTOR_EQ(gfx::Vector2d(), scroll_layer->ScrollDelta()); |
110 | 115 |
111 scroll_layer->SetScrollClipLayer(root->children()[0]->id()); | 116 scroll_layer->SetScrollClipLayer(root->children()[0]->id()); |
112 scroll_layer->SetBounds( | 117 scroll_layer->SetBounds( |
113 gfx::Size(root->bounds().width() + 100, root->bounds().height() + 100)); | 118 gfx::Size(root->bounds().width() + 100, root->bounds().height() + 100)); |
114 scroll_layer->ScrollBy(scroll_amount_); | 119 scroll_layer->ScrollBy(scroll_amount_); |
115 | 120 |
116 switch (impl->active_tree()->source_frame_number()) { | 121 switch (impl->active_tree()->source_frame_number()) { |
117 case 0: | 122 case 0: |
118 EXPECT_VECTOR_EQ(initial_scroll_, scroll_layer->BaseScrollOffset()); | 123 EXPECT_VECTOR_EQ(initial_scroll_, scroll_tree(scroll_layer) |
124 ->GetScrollOffsetBaseForTesting( | |
125 scroll_layer->id())); | |
119 EXPECT_VECTOR_EQ(scroll_amount_, scroll_layer->ScrollDelta()); | 126 EXPECT_VECTOR_EQ(scroll_amount_, scroll_layer->ScrollDelta()); |
120 PostSetNeedsCommitToMainThread(); | 127 PostSetNeedsCommitToMainThread(); |
121 break; | 128 break; |
122 case 1: | 129 case 1: |
123 EXPECT_VECTOR_EQ(second_scroll_, scroll_layer->BaseScrollOffset()); | 130 EXPECT_VECTOR_EQ(second_scroll_, scroll_tree(scroll_layer) |
131 ->GetScrollOffsetBaseForTesting( | |
132 scroll_layer->id())); | |
124 EXPECT_VECTOR_EQ(scroll_amount_, scroll_layer->ScrollDelta()); | 133 EXPECT_VECTOR_EQ(scroll_amount_, scroll_layer->ScrollDelta()); |
125 EndTest(); | 134 EndTest(); |
126 break; | 135 break; |
127 } | 136 } |
128 } | 137 } |
129 | 138 |
130 void ApplyViewportDeltas(const gfx::Vector2dF& inner_delta, | 139 void ApplyViewportDeltas(const gfx::Vector2dF& inner_delta, |
131 const gfx::Vector2dF& outer_delta, | 140 const gfx::Vector2dF& outer_delta, |
132 const gfx::Vector2dF& elastic_overscroll_delta, | 141 const gfx::Vector2dF& elastic_overscroll_delta, |
133 float scale, | 142 float scale, |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
180 void DrawLayersOnThread(LayerTreeHostImpl* impl) override { | 189 void DrawLayersOnThread(LayerTreeHostImpl* impl) override { |
181 LayerImpl* scroll_layer = | 190 LayerImpl* scroll_layer = |
182 impl->active_tree()->LayerById(scroll_layer_->id()); | 191 impl->active_tree()->LayerById(scroll_layer_->id()); |
183 if (impl->active_tree()->source_frame_number() == 0 && | 192 if (impl->active_tree()->source_frame_number() == 0 && |
184 impl->SourceAnimationFrameNumberForTesting() == 1) { | 193 impl->SourceAnimationFrameNumberForTesting() == 1) { |
185 // First draw after first commit. | 194 // First draw after first commit. |
186 EXPECT_VECTOR_EQ(gfx::Vector2d(), scroll_layer->ScrollDelta()); | 195 EXPECT_VECTOR_EQ(gfx::Vector2d(), scroll_layer->ScrollDelta()); |
187 scroll_layer->ScrollBy(scroll_amount_); | 196 scroll_layer->ScrollBy(scroll_amount_); |
188 EXPECT_VECTOR_EQ(scroll_amount_, scroll_layer->ScrollDelta()); | 197 EXPECT_VECTOR_EQ(scroll_amount_, scroll_layer->ScrollDelta()); |
189 | 198 |
190 EXPECT_VECTOR_EQ(initial_scroll_, scroll_layer->BaseScrollOffset()); | 199 EXPECT_VECTOR_EQ(initial_scroll_, |
200 scroll_tree(scroll_layer) | |
201 ->GetScrollOffsetBaseForTesting(scroll_layer->id())); | |
191 PostSetNeedsRedrawToMainThread(); | 202 PostSetNeedsRedrawToMainThread(); |
192 } else if (impl->active_tree()->source_frame_number() == 0 && | 203 } else if (impl->active_tree()->source_frame_number() == 0 && |
193 impl->SourceAnimationFrameNumberForTesting() == 2) { | 204 impl->SourceAnimationFrameNumberForTesting() == 2) { |
194 // Second draw after first commit. | 205 // Second draw after first commit. |
195 EXPECT_EQ(scroll_layer->ScrollDelta(), scroll_amount_); | 206 EXPECT_EQ(scroll_layer->ScrollDelta(), scroll_amount_); |
196 scroll_layer->ScrollBy(scroll_amount_); | 207 scroll_layer->ScrollBy(scroll_amount_); |
197 EXPECT_VECTOR_EQ(scroll_amount_ + scroll_amount_, | 208 EXPECT_VECTOR_EQ(scroll_amount_ + scroll_amount_, |
198 scroll_layer->ScrollDelta()); | 209 scroll_layer->ScrollDelta()); |
199 | 210 |
200 EXPECT_VECTOR_EQ(initial_scroll_, scroll_layer_->scroll_offset()); | 211 EXPECT_VECTOR_EQ(initial_scroll_, scroll_layer_->scroll_offset()); |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
324 | 335 |
325 void DrawLayersOnThread(LayerTreeHostImpl* impl) override { | 336 void DrawLayersOnThread(LayerTreeHostImpl* impl) override { |
326 LayerImpl* root_scroll_layer = impl->OuterViewportScrollLayer(); | 337 LayerImpl* root_scroll_layer = impl->OuterViewportScrollLayer(); |
327 | 338 |
328 if (impl->active_tree()->source_frame_number() == 0 && | 339 if (impl->active_tree()->source_frame_number() == 0 && |
329 impl->SourceAnimationFrameNumberForTesting() == 1) { | 340 impl->SourceAnimationFrameNumberForTesting() == 1) { |
330 // First draw | 341 // First draw |
331 EXPECT_VECTOR_EQ(gfx::Vector2d(), root_scroll_layer->ScrollDelta()); | 342 EXPECT_VECTOR_EQ(gfx::Vector2d(), root_scroll_layer->ScrollDelta()); |
332 root_scroll_layer->ScrollBy(impl_scroll_); | 343 root_scroll_layer->ScrollBy(impl_scroll_); |
333 EXPECT_VECTOR_EQ(impl_scroll_, root_scroll_layer->ScrollDelta()); | 344 EXPECT_VECTOR_EQ(impl_scroll_, root_scroll_layer->ScrollDelta()); |
334 EXPECT_VECTOR_EQ(initial_scroll_, root_scroll_layer->BaseScrollOffset()); | 345 EXPECT_VECTOR_EQ(initial_scroll_, scroll_tree(root_scroll_layer) |
346 ->GetScrollOffsetBaseForTesting( | |
347 root_scroll_layer->id())); | |
335 | 348 |
336 EXPECT_EQ(1.f, impl->active_tree()->page_scale_delta()); | 349 EXPECT_EQ(1.f, impl->active_tree()->page_scale_delta()); |
337 EXPECT_EQ(1.f, impl->active_tree()->current_page_scale_factor()); | 350 EXPECT_EQ(1.f, impl->active_tree()->current_page_scale_factor()); |
338 impl->active_tree()->SetPageScaleOnActiveTree(impl_scale_); | 351 impl->active_tree()->SetPageScaleOnActiveTree(impl_scale_); |
339 EXPECT_EQ(impl_scale_, impl->active_tree()->page_scale_delta()); | 352 EXPECT_EQ(impl_scale_, impl->active_tree()->page_scale_delta()); |
340 EXPECT_EQ(impl_scale_, impl->active_tree()->current_page_scale_factor()); | 353 EXPECT_EQ(impl_scale_, impl->active_tree()->current_page_scale_factor()); |
341 | 354 |
342 // To simplify the testing flow, don't redraw here, just commit. | 355 // To simplify the testing flow, don't redraw here, just commit. |
343 impl->SetNeedsCommit(); | 356 impl->SetNeedsCommit(); |
344 } else if (impl->active_tree()->source_frame_number() == 0 && | 357 } else if (impl->active_tree()->source_frame_number() == 0 && |
345 impl->SourceAnimationFrameNumberForTesting() == 2) { | 358 impl->SourceAnimationFrameNumberForTesting() == 2) { |
346 // Test a second draw after an aborted commit. | 359 // Test a second draw after an aborted commit. |
347 // The scroll/scale values should be baked into the offset/scale factor | 360 // The scroll/scale values should be baked into the offset/scale factor |
348 // since the main thread consumed but aborted the begin frame. | 361 // since the main thread consumed but aborted the begin frame. |
349 EXPECT_VECTOR_EQ(gfx::Vector2d(), root_scroll_layer->ScrollDelta()); | 362 EXPECT_VECTOR_EQ(gfx::Vector2d(), root_scroll_layer->ScrollDelta()); |
350 root_scroll_layer->ScrollBy(impl_scroll_); | 363 root_scroll_layer->ScrollBy(impl_scroll_); |
351 EXPECT_VECTOR_EQ(impl_scroll_, root_scroll_layer->ScrollDelta()); | 364 EXPECT_VECTOR_EQ(impl_scroll_, root_scroll_layer->ScrollDelta()); |
352 EXPECT_VECTOR_EQ( | 365 EXPECT_VECTOR_EQ( |
353 gfx::ScrollOffsetWithDelta(initial_scroll_, impl_scroll_), | 366 gfx::ScrollOffsetWithDelta(initial_scroll_, impl_scroll_), |
354 root_scroll_layer->BaseScrollOffset()); | 367 scroll_tree(root_scroll_layer) |
368 ->GetScrollOffsetBaseForTesting(root_scroll_layer->id())); | |
355 | 369 |
356 EXPECT_EQ(1.f, impl->active_tree()->page_scale_delta()); | 370 EXPECT_EQ(1.f, impl->active_tree()->page_scale_delta()); |
357 EXPECT_EQ(impl_scale_, impl->active_tree()->current_page_scale_factor()); | 371 EXPECT_EQ(impl_scale_, impl->active_tree()->current_page_scale_factor()); |
358 impl->active_tree()->SetPageScaleOnActiveTree(impl_scale_ * impl_scale_); | 372 impl->active_tree()->SetPageScaleOnActiveTree(impl_scale_ * impl_scale_); |
359 EXPECT_EQ(impl_scale_, impl->active_tree()->page_scale_delta()); | 373 EXPECT_EQ(impl_scale_, impl->active_tree()->page_scale_delta()); |
360 EXPECT_EQ(impl_scale_ * impl_scale_, | 374 EXPECT_EQ(impl_scale_ * impl_scale_, |
361 impl->active_tree()->current_page_scale_factor()); | 375 impl->active_tree()->current_page_scale_factor()); |
362 | 376 |
363 impl->SetNeedsCommit(); | 377 impl->SetNeedsCommit(); |
364 } else if (impl->active_tree()->source_frame_number() == 1) { | 378 } else if (impl->active_tree()->source_frame_number() == 1) { |
365 // Commit for source frame 1 is aborted. | 379 // Commit for source frame 1 is aborted. |
366 NOTREACHED(); | 380 NOTREACHED(); |
367 } else if (impl->active_tree()->source_frame_number() == 2 && | 381 } else if (impl->active_tree()->source_frame_number() == 2 && |
368 impl->SourceAnimationFrameNumberForTesting() == 3) { | 382 impl->SourceAnimationFrameNumberForTesting() == 3) { |
369 // Third draw after the second full commit. | 383 // Third draw after the second full commit. |
370 EXPECT_EQ(root_scroll_layer->ScrollDelta(), gfx::Vector2d()); | 384 EXPECT_EQ(root_scroll_layer->ScrollDelta(), gfx::Vector2d()); |
371 root_scroll_layer->ScrollBy(impl_scroll_); | 385 root_scroll_layer->ScrollBy(impl_scroll_); |
372 impl->SetNeedsCommit(); | 386 impl->SetNeedsCommit(); |
373 EXPECT_VECTOR_EQ(impl_scroll_, root_scroll_layer->ScrollDelta()); | 387 EXPECT_VECTOR_EQ(impl_scroll_, root_scroll_layer->ScrollDelta()); |
374 gfx::Vector2dF delta = impl_scroll_ + impl_scroll_ + second_main_scroll_; | 388 gfx::Vector2dF delta = impl_scroll_ + impl_scroll_ + second_main_scroll_; |
375 EXPECT_VECTOR_EQ(gfx::ScrollOffsetWithDelta(initial_scroll_, delta), | 389 EXPECT_VECTOR_EQ( |
376 root_scroll_layer->BaseScrollOffset()); | 390 gfx::ScrollOffsetWithDelta(initial_scroll_, delta), |
391 scroll_tree(root_scroll_layer) | |
392 ->GetScrollOffsetBaseForTesting(root_scroll_layer->id())); | |
377 } else if (impl->active_tree()->source_frame_number() == 2 && | 393 } else if (impl->active_tree()->source_frame_number() == 2 && |
378 impl->SourceAnimationFrameNumberForTesting() == 4) { | 394 impl->SourceAnimationFrameNumberForTesting() == 4) { |
379 // Final draw after the second aborted commit. | 395 // Final draw after the second aborted commit. |
380 EXPECT_VECTOR_EQ(gfx::Vector2d(), root_scroll_layer->ScrollDelta()); | 396 EXPECT_VECTOR_EQ(gfx::Vector2d(), root_scroll_layer->ScrollDelta()); |
381 gfx::Vector2dF delta = | 397 gfx::Vector2dF delta = |
382 impl_scroll_ + impl_scroll_ + impl_scroll_ + second_main_scroll_; | 398 impl_scroll_ + impl_scroll_ + impl_scroll_ + second_main_scroll_; |
383 EXPECT_VECTOR_EQ(gfx::ScrollOffsetWithDelta(initial_scroll_, delta), | 399 EXPECT_VECTOR_EQ( |
384 root_scroll_layer->BaseScrollOffset()); | 400 gfx::ScrollOffsetWithDelta(initial_scroll_, delta), |
401 scroll_tree(root_scroll_layer) | |
402 ->GetScrollOffsetBaseForTesting(root_scroll_layer->id())); | |
385 EndTest(); | 403 EndTest(); |
386 } else { | 404 } else { |
387 // Commit for source frame 3 is aborted. | 405 // Commit for source frame 3 is aborted. |
388 NOTREACHED(); | 406 NOTREACHED(); |
389 } | 407 } |
390 } | 408 } |
391 | 409 |
392 void ApplyViewportDeltas(const gfx::Vector2dF& inner_delta, | 410 void ApplyViewportDeltas(const gfx::Vector2dF& inner_delta, |
393 const gfx::Vector2dF& outer_delta, | 411 const gfx::Vector2dF& outer_delta, |
394 const gfx::Vector2dF& elastic_overscroll_delta, | 412 const gfx::Vector2dF& elastic_overscroll_delta, |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
434 | 452 |
435 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 453 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
436 | 454 |
437 void DrawLayersOnThread(LayerTreeHostImpl* impl) override { | 455 void DrawLayersOnThread(LayerTreeHostImpl* impl) override { |
438 LayerImpl* scroll_layer = impl->OuterViewportScrollLayer(); | 456 LayerImpl* scroll_layer = impl->OuterViewportScrollLayer(); |
439 | 457 |
440 // Check that a fractional scroll delta is correctly accumulated over | 458 // Check that a fractional scroll delta is correctly accumulated over |
441 // multiple commits. | 459 // multiple commits. |
442 switch (impl->active_tree()->source_frame_number()) { | 460 switch (impl->active_tree()->source_frame_number()) { |
443 case 0: | 461 case 0: |
444 EXPECT_VECTOR_EQ(gfx::Vector2d(0, 0), scroll_layer->BaseScrollOffset()); | 462 EXPECT_VECTOR_EQ( |
463 gfx::Vector2d(0, 0), | |
464 scroll_tree(scroll_layer) | |
465 ->GetScrollOffsetBaseForTesting(scroll_layer->id())); | |
445 EXPECT_VECTOR_EQ(gfx::Vector2d(0, 0), scroll_layer->ScrollDelta()); | 466 EXPECT_VECTOR_EQ(gfx::Vector2d(0, 0), scroll_layer->ScrollDelta()); |
446 PostSetNeedsCommitToMainThread(); | 467 PostSetNeedsCommitToMainThread(); |
447 break; | 468 break; |
448 case 1: | 469 case 1: |
449 EXPECT_VECTOR_EQ(gfx::ToFlooredVector2d(scroll_amount_), | 470 EXPECT_VECTOR_EQ( |
450 scroll_layer->BaseScrollOffset()); | 471 gfx::ToFlooredVector2d(scroll_amount_), |
472 scroll_tree(scroll_layer) | |
473 ->GetScrollOffsetBaseForTesting(scroll_layer->id())); | |
451 EXPECT_VECTOR_EQ(gfx::Vector2dF(fmod(scroll_amount_.x(), 1.0f), 0.0f), | 474 EXPECT_VECTOR_EQ(gfx::Vector2dF(fmod(scroll_amount_.x(), 1.0f), 0.0f), |
452 scroll_layer->ScrollDelta()); | 475 scroll_layer->ScrollDelta()); |
453 PostSetNeedsCommitToMainThread(); | 476 PostSetNeedsCommitToMainThread(); |
454 break; | 477 break; |
455 case 2: | 478 case 2: |
456 EXPECT_VECTOR_EQ( | 479 EXPECT_VECTOR_EQ( |
457 gfx::ToFlooredVector2d(scroll_amount_ + scroll_amount_), | 480 gfx::ToFlooredVector2d(scroll_amount_ + scroll_amount_), |
458 scroll_layer->BaseScrollOffset()); | 481 scroll_tree(scroll_layer) |
482 ->GetScrollOffsetBaseForTesting(scroll_layer->id())); | |
459 EXPECT_VECTOR_EQ( | 483 EXPECT_VECTOR_EQ( |
460 gfx::Vector2dF(fmod(2.0f * scroll_amount_.x(), 1.0f), 0.0f), | 484 gfx::Vector2dF(fmod(2.0f * scroll_amount_.x(), 1.0f), 0.0f), |
461 scroll_layer->ScrollDelta()); | 485 scroll_layer->ScrollDelta()); |
462 EndTest(); | 486 EndTest(); |
463 break; | 487 break; |
464 } | 488 } |
465 scroll_layer->ScrollBy(scroll_amount_); | 489 scroll_layer->ScrollBy(scroll_amount_); |
466 } | 490 } |
467 | 491 |
468 void AfterTest() override {} | 492 void AfterTest() override {} |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
624 impl->ScrollBy(UpdateState(gfx::Point(), scroll_amount_).get()); | 648 impl->ScrollBy(UpdateState(gfx::Point(), scroll_amount_).get()); |
625 LayerImpl* scrolling_layer = impl->CurrentlyScrollingLayer(); | 649 LayerImpl* scrolling_layer = impl->CurrentlyScrollingLayer(); |
626 CHECK(scrolling_layer); | 650 CHECK(scrolling_layer); |
627 impl->ScrollEnd(EndState().get()); | 651 impl->ScrollEnd(EndState().get()); |
628 CHECK(!impl->CurrentlyScrollingLayer()); | 652 CHECK(!impl->CurrentlyScrollingLayer()); |
629 EXPECT_EQ(scrolling_layer->id(), | 653 EXPECT_EQ(scrolling_layer->id(), |
630 impl->active_tree()->LastScrolledLayerId()); | 654 impl->active_tree()->LastScrolledLayerId()); |
631 | 655 |
632 // Check the scroll is applied as a delta. | 656 // Check the scroll is applied as a delta. |
633 EXPECT_VECTOR_EQ(initial_offset_, | 657 EXPECT_VECTOR_EQ(initial_offset_, |
634 expected_scroll_layer_impl->BaseScrollOffset()); | 658 scroll_tree(expected_scroll_layer_impl) |
659 ->GetScrollOffsetBaseForTesting( | |
660 expected_scroll_layer_impl->id())); | |
635 EXPECT_VECTOR_EQ(scroll_amount_, | 661 EXPECT_VECTOR_EQ(scroll_amount_, |
636 expected_scroll_layer_impl->ScrollDelta()); | 662 expected_scroll_layer_impl->ScrollDelta()); |
637 break; | 663 break; |
638 } | 664 } |
639 case 1: { | 665 case 1: { |
640 // WHEEL scroll on impl thread. | 666 // WHEEL scroll on impl thread. |
641 gfx::Point scroll_point = | 667 gfx::Point scroll_point = |
642 gfx::ToCeiledPoint(expected_scroll_layer_impl->position() + | 668 gfx::ToCeiledPoint(expected_scroll_layer_impl->position() + |
643 gfx::Vector2dF(0.5f, 0.5f)); | 669 gfx::Vector2dF(0.5f, 0.5f)); |
644 InputHandler::ScrollStatus status = impl->ScrollBegin( | 670 InputHandler::ScrollStatus status = impl->ScrollBegin( |
645 BeginState(scroll_point).get(), InputHandler::WHEEL); | 671 BeginState(scroll_point).get(), InputHandler::WHEEL); |
646 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, status.thread); | 672 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, status.thread); |
647 impl->ScrollBy(UpdateState(gfx::Point(), scroll_amount_).get()); | 673 impl->ScrollBy(UpdateState(gfx::Point(), scroll_amount_).get()); |
648 impl->ScrollEnd(EndState().get()); | 674 impl->ScrollEnd(EndState().get()); |
649 | 675 |
650 // Check the scroll is applied as a delta. | 676 // Check the scroll is applied as a delta. |
651 EXPECT_VECTOR_EQ(javascript_scroll_, | 677 EXPECT_VECTOR_EQ(javascript_scroll_, |
652 expected_scroll_layer_impl->BaseScrollOffset()); | 678 scroll_tree(expected_scroll_layer_impl) |
679 ->GetScrollOffsetBaseForTesting( | |
680 expected_scroll_layer_impl->id())); | |
653 EXPECT_VECTOR_EQ(scroll_amount_, | 681 EXPECT_VECTOR_EQ(scroll_amount_, |
654 expected_scroll_layer_impl->ScrollDelta()); | 682 expected_scroll_layer_impl->ScrollDelta()); |
655 break; | 683 break; |
656 } | 684 } |
657 case 2: | 685 case 2: |
658 | 686 |
659 EXPECT_VECTOR_EQ( | 687 EXPECT_VECTOR_EQ( |
660 gfx::ScrollOffsetWithDelta(javascript_scroll_, scroll_amount_), | 688 gfx::ScrollOffsetWithDelta(javascript_scroll_, scroll_amount_), |
661 expected_scroll_layer_impl->BaseScrollOffset()); | 689 scroll_tree(expected_scroll_layer_impl) |
690 ->GetScrollOffsetBaseForTesting( | |
691 expected_scroll_layer_impl->id())); | |
662 EXPECT_VECTOR_EQ(gfx::Vector2d(), | 692 EXPECT_VECTOR_EQ(gfx::Vector2d(), |
663 expected_scroll_layer_impl->ScrollDelta()); | 693 expected_scroll_layer_impl->ScrollDelta()); |
664 | 694 |
665 EndTest(); | 695 EndTest(); |
666 break; | 696 break; |
667 } | 697 } |
668 } | 698 } |
669 | 699 |
670 void AfterTest() override { | 700 void AfterTest() override { |
671 if (scroll_child_layer_) { | 701 if (scroll_child_layer_) { |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
834 LayerImpl* pending_root = | 864 LayerImpl* pending_root = |
835 impl->active_tree()->FindPendingTreeLayerById(root->id()); | 865 impl->active_tree()->FindPendingTreeLayerById(root->id()); |
836 | 866 |
837 switch (impl->active_tree()->source_frame_number()) { | 867 switch (impl->active_tree()->source_frame_number()) { |
838 case 0: | 868 case 0: |
839 if (!impl->pending_tree()) { | 869 if (!impl->pending_tree()) { |
840 impl->BlockNotifyReadyToActivateForTesting(true); | 870 impl->BlockNotifyReadyToActivateForTesting(true); |
841 EXPECT_VECTOR_EQ(gfx::Vector2d(), scroll_layer->ScrollDelta()); | 871 EXPECT_VECTOR_EQ(gfx::Vector2d(), scroll_layer->ScrollDelta()); |
842 scroll_layer->ScrollBy(impl_thread_scroll1_); | 872 scroll_layer->ScrollBy(impl_thread_scroll1_); |
843 | 873 |
844 EXPECT_VECTOR_EQ(initial_scroll_, scroll_layer->BaseScrollOffset()); | 874 EXPECT_VECTOR_EQ(initial_scroll_, scroll_tree(scroll_layer) |
875 ->GetScrollOffsetBaseForTesting( | |
876 scroll_layer->id())); | |
845 EXPECT_VECTOR_EQ(impl_thread_scroll1_, scroll_layer->ScrollDelta()); | 877 EXPECT_VECTOR_EQ(impl_thread_scroll1_, scroll_layer->ScrollDelta()); |
846 PostSetNeedsCommitToMainThread(); | 878 PostSetNeedsCommitToMainThread(); |
847 | 879 |
848 // CommitCompleteOnThread will trigger this function again | 880 // CommitCompleteOnThread will trigger this function again |
849 // and cause us to take the else clause. | 881 // and cause us to take the else clause. |
850 } else { | 882 } else { |
851 impl->BlockNotifyReadyToActivateForTesting(false); | 883 impl->BlockNotifyReadyToActivateForTesting(false); |
852 ASSERT_TRUE(pending_root); | 884 ASSERT_TRUE(pending_root); |
853 EXPECT_EQ(impl->pending_tree()->source_frame_number(), 1); | 885 EXPECT_EQ(impl->pending_tree()->source_frame_number(), 1); |
854 | 886 |
855 scroll_layer->ScrollBy(impl_thread_scroll2_); | 887 scroll_layer->ScrollBy(impl_thread_scroll2_); |
856 EXPECT_VECTOR_EQ(initial_scroll_, scroll_layer->BaseScrollOffset()); | 888 EXPECT_VECTOR_EQ(initial_scroll_, scroll_tree(scroll_layer) |
889 ->GetScrollOffsetBaseForTesting( | |
890 scroll_layer->id())); | |
857 EXPECT_VECTOR_EQ(impl_thread_scroll1_ + impl_thread_scroll2_, | 891 EXPECT_VECTOR_EQ(impl_thread_scroll1_ + impl_thread_scroll2_, |
858 scroll_layer->ScrollDelta()); | 892 scroll_layer->ScrollDelta()); |
859 | 893 |
860 LayerImpl* pending_scroll_layer = | 894 LayerImpl* pending_scroll_layer = |
861 impl->pending_tree()->OuterViewportScrollLayer(); | 895 impl->pending_tree()->OuterViewportScrollLayer(); |
862 EXPECT_VECTOR_EQ( | 896 EXPECT_VECTOR_EQ( |
863 gfx::ScrollOffsetWithDelta( | 897 gfx::ScrollOffsetWithDelta( |
864 initial_scroll_, main_thread_scroll_ + impl_thread_scroll1_), | 898 initial_scroll_, main_thread_scroll_ + impl_thread_scroll1_), |
865 pending_scroll_layer->BaseScrollOffset()); | 899 scroll_tree(pending_scroll_layer) |
900 ->GetScrollOffsetBaseForTesting(pending_scroll_layer->id())); | |
866 EXPECT_VECTOR_EQ(impl_thread_scroll2_, | 901 EXPECT_VECTOR_EQ(impl_thread_scroll2_, |
867 pending_scroll_layer->ScrollDelta()); | 902 pending_scroll_layer->ScrollDelta()); |
868 } | 903 } |
869 break; | 904 break; |
870 case 1: | 905 case 1: |
871 EXPECT_FALSE(impl->pending_tree()); | 906 EXPECT_FALSE(impl->pending_tree()); |
872 EXPECT_VECTOR_EQ( | 907 EXPECT_VECTOR_EQ( |
873 gfx::ScrollOffsetWithDelta( | 908 gfx::ScrollOffsetWithDelta( |
874 initial_scroll_, main_thread_scroll_ + impl_thread_scroll1_), | 909 initial_scroll_, main_thread_scroll_ + impl_thread_scroll1_), |
875 scroll_layer->BaseScrollOffset()); | 910 scroll_tree(scroll_layer) |
911 ->GetScrollOffsetBaseForTesting(scroll_layer->id())); | |
876 EXPECT_VECTOR_EQ(impl_thread_scroll2_, scroll_layer->ScrollDelta()); | 912 EXPECT_VECTOR_EQ(impl_thread_scroll2_, scroll_layer->ScrollDelta()); |
877 EndTest(); | 913 EndTest(); |
878 break; | 914 break; |
879 } | 915 } |
880 } | 916 } |
881 | 917 |
882 void ApplyViewportDeltas(const gfx::Vector2dF& inner_delta, | 918 void ApplyViewportDeltas(const gfx::Vector2dF& inner_delta, |
883 const gfx::Vector2dF& outer_delta, | 919 const gfx::Vector2dF& outer_delta, |
884 const gfx::Vector2dF& elastic_overscroll_delta, | 920 const gfx::Vector2dF& elastic_overscroll_delta, |
885 float scale, | 921 float scale, |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
954 LayerImpl* active_scroll_layer = | 990 LayerImpl* active_scroll_layer = |
955 active_root ? impl->OuterViewportScrollLayer() : NULL; | 991 active_root ? impl->OuterViewportScrollLayer() : NULL; |
956 LayerImpl* pending_root = impl->pending_tree()->root_layer(); | 992 LayerImpl* pending_root = impl->pending_tree()->root_layer(); |
957 LayerImpl* pending_scroll_layer = | 993 LayerImpl* pending_scroll_layer = |
958 impl->pending_tree()->OuterViewportScrollLayer(); | 994 impl->pending_tree()->OuterViewportScrollLayer(); |
959 | 995 |
960 ASSERT_TRUE(pending_root); | 996 ASSERT_TRUE(pending_root); |
961 ASSERT_TRUE(pending_scroll_layer); | 997 ASSERT_TRUE(pending_scroll_layer); |
962 switch (impl->pending_tree()->source_frame_number()) { | 998 switch (impl->pending_tree()->source_frame_number()) { |
963 case 0: | 999 case 0: |
964 EXPECT_VECTOR_EQ(initial_scroll_, | 1000 EXPECT_VECTOR_EQ(initial_scroll_, scroll_tree(pending_scroll_layer) |
965 pending_scroll_layer->BaseScrollOffset()); | 1001 ->GetScrollOffsetBaseForTesting( |
1002 pending_scroll_layer->id())); | |
966 EXPECT_VECTOR_EQ(gfx::Vector2d(), pending_scroll_layer->ScrollDelta()); | 1003 EXPECT_VECTOR_EQ(gfx::Vector2d(), pending_scroll_layer->ScrollDelta()); |
967 EXPECT_FALSE(active_root); | 1004 EXPECT_FALSE(active_root); |
968 break; | 1005 break; |
969 case 1: | 1006 case 1: |
970 // Even though the scroll happened during the commit, both layers | 1007 // Even though the scroll happened during the commit, both layers |
971 // should have the appropriate scroll delta. | 1008 // should have the appropriate scroll delta. |
972 EXPECT_VECTOR_EQ(initial_scroll_, | 1009 EXPECT_VECTOR_EQ(initial_scroll_, scroll_tree(pending_scroll_layer) |
973 pending_scroll_layer->BaseScrollOffset()); | 1010 ->GetScrollOffsetBaseForTesting( |
1011 pending_scroll_layer->id())); | |
974 EXPECT_VECTOR_EQ(impl_thread_scroll_, | 1012 EXPECT_VECTOR_EQ(impl_thread_scroll_, |
975 pending_scroll_layer->ScrollDelta()); | 1013 pending_scroll_layer->ScrollDelta()); |
976 ASSERT_TRUE(active_root); | 1014 ASSERT_TRUE(active_root); |
977 EXPECT_VECTOR_EQ(initial_scroll_, | 1015 EXPECT_VECTOR_EQ(initial_scroll_, scroll_tree(active_scroll_layer) |
978 active_scroll_layer->BaseScrollOffset()); | 1016 ->GetScrollOffsetBaseForTesting( |
1017 active_scroll_layer->id())); | |
979 EXPECT_VECTOR_EQ(impl_thread_scroll_, | 1018 EXPECT_VECTOR_EQ(impl_thread_scroll_, |
980 active_scroll_layer->ScrollDelta()); | 1019 active_scroll_layer->ScrollDelta()); |
981 break; | 1020 break; |
982 case 2: | 1021 case 2: |
983 // On the next commit, this delta should have been sent and applied. | 1022 // On the next commit, this delta should have been sent and applied. |
984 EXPECT_VECTOR_EQ( | 1023 EXPECT_VECTOR_EQ( |
985 gfx::ScrollOffsetWithDelta(initial_scroll_, impl_thread_scroll_), | 1024 gfx::ScrollOffsetWithDelta(initial_scroll_, impl_thread_scroll_), |
986 pending_scroll_layer->BaseScrollOffset()); | 1025 scroll_tree(pending_scroll_layer) |
1026 ->GetScrollOffsetBaseForTesting(pending_scroll_layer->id())); | |
987 EXPECT_VECTOR_EQ(gfx::Vector2d(), pending_scroll_layer->ScrollDelta()); | 1027 EXPECT_VECTOR_EQ(gfx::Vector2d(), pending_scroll_layer->ScrollDelta()); |
988 break; | 1028 break; |
989 } | 1029 } |
990 } | 1030 } |
991 | 1031 |
992 void DrawLayersOnThread(LayerTreeHostImpl* impl) override { | 1032 void DrawLayersOnThread(LayerTreeHostImpl* impl) override { |
993 if (impl->pending_tree()) | 1033 if (impl->pending_tree()) |
994 impl->SetNeedsRedraw(); | 1034 impl->SetNeedsRedraw(); |
995 | 1035 |
996 LayerImpl* scroll_layer = impl->OuterViewportScrollLayer(); | 1036 LayerImpl* scroll_layer = impl->OuterViewportScrollLayer(); |
997 | 1037 |
998 switch (impl->active_tree()->source_frame_number()) { | 1038 switch (impl->active_tree()->source_frame_number()) { |
999 case 0: | 1039 case 0: |
1000 EXPECT_VECTOR_EQ(initial_scroll_, scroll_layer->BaseScrollOffset()); | 1040 EXPECT_VECTOR_EQ(initial_scroll_, scroll_tree(scroll_layer) |
1041 ->GetScrollOffsetBaseForTesting( | |
1042 scroll_layer->id())); | |
1001 EXPECT_VECTOR_EQ(gfx::Vector2d(), scroll_layer->ScrollDelta()); | 1043 EXPECT_VECTOR_EQ(gfx::Vector2d(), scroll_layer->ScrollDelta()); |
1002 EXPECT_EQ(1.f, impl->active_tree()->page_scale_delta()); | 1044 EXPECT_EQ(1.f, impl->active_tree()->page_scale_delta()); |
1003 EXPECT_EQ(1.f, impl->active_tree()->current_page_scale_factor()); | 1045 EXPECT_EQ(1.f, impl->active_tree()->current_page_scale_factor()); |
1004 PostSetNeedsCommitToMainThread(); | 1046 PostSetNeedsCommitToMainThread(); |
1005 break; | 1047 break; |
1006 case 1: | 1048 case 1: |
1007 EXPECT_VECTOR_EQ(initial_scroll_, scroll_layer->BaseScrollOffset()); | 1049 EXPECT_VECTOR_EQ(initial_scroll_, scroll_tree(scroll_layer) |
1050 ->GetScrollOffsetBaseForTesting( | |
1051 scroll_layer->id())); | |
1008 EXPECT_VECTOR_EQ(impl_thread_scroll_, scroll_layer->ScrollDelta()); | 1052 EXPECT_VECTOR_EQ(impl_thread_scroll_, scroll_layer->ScrollDelta()); |
1009 EXPECT_EQ(impl_scale_, impl->active_tree()->page_scale_delta()); | 1053 EXPECT_EQ(impl_scale_, impl->active_tree()->page_scale_delta()); |
1010 EXPECT_EQ(impl_scale_, | 1054 EXPECT_EQ(impl_scale_, |
1011 impl->active_tree()->current_page_scale_factor()); | 1055 impl->active_tree()->current_page_scale_factor()); |
1012 PostSetNeedsCommitToMainThread(); | 1056 PostSetNeedsCommitToMainThread(); |
1013 break; | 1057 break; |
1014 case 2: | 1058 case 2: |
1015 EXPECT_EQ(1.f, impl->active_tree()->page_scale_delta()); | 1059 EXPECT_EQ(1.f, impl->active_tree()->page_scale_delta()); |
1016 EXPECT_EQ(impl_scale_, | 1060 EXPECT_EQ(impl_scale_, |
1017 impl->active_tree()->current_page_scale_factor()); | 1061 impl->active_tree()->current_page_scale_factor()); |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1306 CreateScrollLayer(root_scroll_layer, &child_scroll_layer_client_); | 1350 CreateScrollLayer(root_scroll_layer, &child_scroll_layer_client_); |
1307 fake_content_layer_client_.set_bounds(root_layer->bounds()); | 1351 fake_content_layer_client_.set_bounds(root_layer->bounds()); |
1308 } | 1352 } |
1309 | 1353 |
1310 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 1354 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
1311 | 1355 |
1312 void DrawLayersOnThread(LayerTreeHostImpl* impl) override { | 1356 void DrawLayersOnThread(LayerTreeHostImpl* impl) override { |
1313 LayerImpl* root = impl->OuterViewportScrollLayer(); | 1357 LayerImpl* root = impl->OuterViewportScrollLayer(); |
1314 switch (impl->active_tree()->source_frame_number()) { | 1358 switch (impl->active_tree()->source_frame_number()) { |
1315 case 0: | 1359 case 0: |
1316 root->child_at(0)->SetScrollDelta(gfx::Vector2dF(5, 5)); | 1360 SetScrollOffsetDelta(root->child_at(0), gfx::Vector2dF(5, 5)); |
1317 root->child_at(0)->child_at(0)->SetScrollDelta(gfx::Vector2dF(5, 5)); | 1361 SetScrollOffsetDelta(root->child_at(0)->child_at(0), |
1318 root->child_at(1)->SetScrollDelta(gfx::Vector2dF(5, 5)); | 1362 gfx::Vector2dF(5, 5)); |
1363 SetScrollOffsetDelta(root->child_at(1), gfx::Vector2dF(5, 5)); | |
1319 PostSetNeedsCommitToMainThread(); | 1364 PostSetNeedsCommitToMainThread(); |
1320 break; | 1365 break; |
1321 case 1: | 1366 case 1: |
1322 EndTest(); | 1367 EndTest(); |
1323 break; | 1368 break; |
1324 } | 1369 } |
1325 } | 1370 } |
1326 | 1371 |
1327 void AfterTest() override {} | 1372 void AfterTest() override {} |
1328 | 1373 |
(...skipping 27 matching lines...) Expand all Loading... | |
1356 scroll_layer->SetBounds(gfx::Size(parent->bounds().width() + 100, | 1401 scroll_layer->SetBounds(gfx::Size(parent->bounds().width() + 100, |
1357 parent->bounds().height() + 100)); | 1402 parent->bounds().height() + 100)); |
1358 scroll_layer->set_did_scroll_callback(base::Bind( | 1403 scroll_layer->set_did_scroll_callback(base::Bind( |
1359 &FakeLayerScrollClient::DidScroll, base::Unretained(client))); | 1404 &FakeLayerScrollClient::DidScroll, base::Unretained(client))); |
1360 client->owner_ = this; | 1405 client->owner_ = this; |
1361 client->layer_ = scroll_layer.get(); | 1406 client->layer_ = scroll_layer.get(); |
1362 parent->AddChild(scroll_layer); | 1407 parent->AddChild(scroll_layer); |
1363 return scroll_layer.get(); | 1408 return scroll_layer.get(); |
1364 } | 1409 } |
1365 | 1410 |
1411 void SetScrollOffsetDelta(LayerImpl* layer_impl, | |
ajuma
2016/03/07 19:10:19
static
sunxd
2016/03/09 01:51:21
Done.
| |
1412 const gfx::Vector2dF& delta) { | |
1413 layer_impl->SetCurrentScrollOffset( | |
1414 layer_impl->synced_scroll_offset()->ActiveBase() + | |
1415 gfx::ScrollOffset(delta)); | |
1416 } | |
1417 | |
1366 FakeLayerScrollClient root_scroll_layer_client_; | 1418 FakeLayerScrollClient root_scroll_layer_client_; |
1367 FakeLayerScrollClient sibling_scroll_layer_client_; | 1419 FakeLayerScrollClient sibling_scroll_layer_client_; |
1368 FakeLayerScrollClient child_scroll_layer_client_; | 1420 FakeLayerScrollClient child_scroll_layer_client_; |
1369 | 1421 |
1370 FakeContentLayerClient fake_content_layer_client_; | 1422 FakeContentLayerClient fake_content_layer_client_; |
1371 | 1423 |
1372 bool scroll_destroy_whole_tree_; | 1424 bool scroll_destroy_whole_tree_; |
1373 }; | 1425 }; |
1374 | 1426 |
1375 TEST_F(LayerTreeHostScrollTestLayerStructureChange, ScrollDestroyLayer) { | 1427 TEST_F(LayerTreeHostScrollTestLayerStructureChange, ScrollDestroyLayer) { |
1376 RunTest(CompositorMode::THREADED, false); | 1428 RunTest(CompositorMode::THREADED, false); |
1377 } | 1429 } |
1378 | 1430 |
1379 TEST_F(LayerTreeHostScrollTestLayerStructureChange, ScrollDestroyWholeTree) { | 1431 TEST_F(LayerTreeHostScrollTestLayerStructureChange, ScrollDestroyWholeTree) { |
1380 scroll_destroy_whole_tree_ = true; | 1432 scroll_destroy_whole_tree_ = true; |
1381 RunTest(CompositorMode::THREADED, false); | 1433 RunTest(CompositorMode::THREADED, false); |
1382 } | 1434 } |
1383 | 1435 |
1384 } // namespace | 1436 } // namespace |
1385 } // namespace cc | 1437 } // namespace cc |
OLD | NEW |