| 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 704 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 715 } | 715 } |
| 716 }; | 716 }; |
| 717 | 717 |
| 718 class ImplSidePaintingScrollTestSimple : public ImplSidePaintingScrollTest { | 718 class ImplSidePaintingScrollTestSimple : public ImplSidePaintingScrollTest { |
| 719 public: | 719 public: |
| 720 ImplSidePaintingScrollTestSimple() | 720 ImplSidePaintingScrollTestSimple() |
| 721 : initial_scroll_(10, 20), | 721 : initial_scroll_(10, 20), |
| 722 main_thread_scroll_(40, 5), | 722 main_thread_scroll_(40, 5), |
| 723 impl_thread_scroll1_(2, -1), | 723 impl_thread_scroll1_(2, -1), |
| 724 impl_thread_scroll2_(-3, 10), | 724 impl_thread_scroll2_(-3, 10), |
| 725 num_scrolls_(0), | 725 num_scrolls_(0) {} |
| 726 can_activate_(true) {} | |
| 727 | 726 |
| 728 virtual void BeginTest() OVERRIDE { | 727 virtual void BeginTest() OVERRIDE { |
| 729 layer_tree_host()->root_layer()->SetScrollable(true); | 728 layer_tree_host()->root_layer()->SetScrollable(true); |
| 730 layer_tree_host()->root_layer() | 729 layer_tree_host()->root_layer() |
| 731 ->SetMaxScrollOffset(gfx::Vector2d(100, 100)); | 730 ->SetMaxScrollOffset(gfx::Vector2d(100, 100)); |
| 732 layer_tree_host()->root_layer()->SetScrollOffset(initial_scroll_); | 731 layer_tree_host()->root_layer()->SetScrollOffset(initial_scroll_); |
| 733 PostSetNeedsCommitToMainThread(); | 732 PostSetNeedsCommitToMainThread(); |
| 734 } | 733 } |
| 735 | 734 |
| 736 virtual void Layout() OVERRIDE { | 735 virtual void Layout() OVERRIDE { |
| 737 Layer* root = layer_tree_host()->root_layer(); | 736 Layer* root = layer_tree_host()->root_layer(); |
| 738 if (!layer_tree_host()->source_frame_number()) { | 737 if (!layer_tree_host()->source_frame_number()) { |
| 739 EXPECT_VECTOR_EQ(root->scroll_offset(), initial_scroll_); | 738 EXPECT_VECTOR_EQ(root->scroll_offset(), initial_scroll_); |
| 740 } else { | 739 } else { |
| 741 EXPECT_VECTOR_EQ(root->scroll_offset(), | 740 EXPECT_VECTOR_EQ(root->scroll_offset(), |
| 742 initial_scroll_ + impl_thread_scroll1_); | 741 initial_scroll_ + impl_thread_scroll1_); |
| 743 | 742 |
| 744 // Pretend like Javascript updated the scroll position itself with a | 743 // Pretend like Javascript updated the scroll position itself with a |
| 745 // change of main_thread_scroll. | 744 // change of main_thread_scroll. |
| 746 root->SetScrollOffset(initial_scroll_ + main_thread_scroll_ + | 745 root->SetScrollOffset(initial_scroll_ + main_thread_scroll_ + |
| 747 impl_thread_scroll1_); | 746 impl_thread_scroll1_); |
| 748 } | 747 } |
| 749 } | 748 } |
| 750 | 749 |
| 751 virtual bool CanActivatePendingTree(LayerTreeHostImpl* impl) OVERRIDE { | |
| 752 return can_activate_; | |
| 753 } | |
| 754 | |
| 755 virtual bool CanActivatePendingTreeIfNeeded(LayerTreeHostImpl* impl) | |
| 756 OVERRIDE { | |
| 757 return can_activate_; | |
| 758 } | |
| 759 | |
| 760 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { | 750 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
| 761 // 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 |
| 762 // the second commit. | 752 // the second commit. |
| 763 if (impl->active_tree()->source_frame_number() == 0) | 753 if (impl->active_tree()->source_frame_number() == 0) |
| 764 impl->SetNeedsRedraw(); | 754 impl->SetNeedsRedraw(); |
| 765 } | 755 } |
| 766 | 756 |
| 767 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { | 757 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
| 768 ImplSidePaintingScrollTest::DrawLayersOnThread(impl); | 758 ImplSidePaintingScrollTest::DrawLayersOnThread(impl); |
| 769 | 759 |
| 770 LayerImpl* root = impl->active_tree()->root_layer(); | 760 LayerImpl* root = impl->active_tree()->root_layer(); |
| 771 LayerImpl* pending_root = | 761 LayerImpl* pending_root = |
| 772 impl->active_tree()->FindPendingTreeLayerById(root->id()); | 762 impl->active_tree()->FindPendingTreeLayerById(root->id()); |
| 773 | 763 |
| 774 switch (impl->active_tree()->source_frame_number()) { | 764 switch (impl->active_tree()->source_frame_number()) { |
| 775 case 0: | 765 case 0: |
| 776 if (!impl->pending_tree()) { | 766 if (!impl->pending_tree()) { |
| 777 can_activate_ = false; | 767 impl->BlockNotifyReadyToActivateForTesting(true); |
| 778 EXPECT_VECTOR_EQ(root->ScrollDelta(), gfx::Vector2d()); | 768 EXPECT_VECTOR_EQ(root->ScrollDelta(), gfx::Vector2d()); |
| 779 root->ScrollBy(impl_thread_scroll1_); | 769 root->ScrollBy(impl_thread_scroll1_); |
| 780 | 770 |
| 781 EXPECT_VECTOR_EQ(root->scroll_offset(), initial_scroll_); | 771 EXPECT_VECTOR_EQ(root->scroll_offset(), initial_scroll_); |
| 782 EXPECT_VECTOR_EQ(root->ScrollDelta(), impl_thread_scroll1_); | 772 EXPECT_VECTOR_EQ(root->ScrollDelta(), impl_thread_scroll1_); |
| 783 EXPECT_VECTOR_EQ(root->sent_scroll_delta(), gfx::Vector2d()); | 773 EXPECT_VECTOR_EQ(root->sent_scroll_delta(), gfx::Vector2d()); |
| 784 PostSetNeedsCommitToMainThread(); | 774 PostSetNeedsCommitToMainThread(); |
| 785 | 775 |
| 786 // CommitCompleteOnThread will trigger this function again | 776 // CommitCompleteOnThread will trigger this function again |
| 787 // and cause us to take the else clause. | 777 // and cause us to take the else clause. |
| 788 } else { | 778 } else { |
| 789 can_activate_ = true; | 779 impl->BlockNotifyReadyToActivateForTesting(false); |
| 790 ASSERT_TRUE(pending_root); | 780 ASSERT_TRUE(pending_root); |
| 791 EXPECT_EQ(impl->pending_tree()->source_frame_number(), 1); | 781 EXPECT_EQ(impl->pending_tree()->source_frame_number(), 1); |
| 792 | 782 |
| 793 root->ScrollBy(impl_thread_scroll2_); | 783 root->ScrollBy(impl_thread_scroll2_); |
| 794 EXPECT_VECTOR_EQ(root->scroll_offset(), initial_scroll_); | 784 EXPECT_VECTOR_EQ(root->scroll_offset(), initial_scroll_); |
| 795 EXPECT_VECTOR_EQ(root->ScrollDelta(), | 785 EXPECT_VECTOR_EQ(root->ScrollDelta(), |
| 796 impl_thread_scroll1_ + impl_thread_scroll2_); | 786 impl_thread_scroll1_ + impl_thread_scroll2_); |
| 797 EXPECT_VECTOR_EQ(root->sent_scroll_delta(), impl_thread_scroll1_); | 787 EXPECT_VECTOR_EQ(root->sent_scroll_delta(), impl_thread_scroll1_); |
| 798 | 788 |
| 799 EXPECT_VECTOR_EQ( | 789 EXPECT_VECTOR_EQ( |
| (...skipping 21 matching lines...) Expand all Loading... |
| 821 } | 811 } |
| 822 | 812 |
| 823 virtual void AfterTest() OVERRIDE { EXPECT_EQ(1, num_scrolls_); } | 813 virtual void AfterTest() OVERRIDE { EXPECT_EQ(1, num_scrolls_); } |
| 824 | 814 |
| 825 private: | 815 private: |
| 826 gfx::Vector2d initial_scroll_; | 816 gfx::Vector2d initial_scroll_; |
| 827 gfx::Vector2d main_thread_scroll_; | 817 gfx::Vector2d main_thread_scroll_; |
| 828 gfx::Vector2d impl_thread_scroll1_; | 818 gfx::Vector2d impl_thread_scroll1_; |
| 829 gfx::Vector2d impl_thread_scroll2_; | 819 gfx::Vector2d impl_thread_scroll2_; |
| 830 int num_scrolls_; | 820 int num_scrolls_; |
| 831 bool can_activate_; | |
| 832 }; | 821 }; |
| 833 | 822 |
| 834 MULTI_THREAD_TEST_F(ImplSidePaintingScrollTestSimple); | 823 MULTI_THREAD_TEST_F(ImplSidePaintingScrollTestSimple); |
| 835 | 824 |
| 836 // 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 |
| 837 // beginning a commit and finishing a commit (aka scroll deltas not | 826 // beginning a commit and finishing a commit (aka scroll deltas not |
| 838 // 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 |
| 839 // push properties. | 828 // push properties. |
| 840 class ImplSidePaintingScrollTestImplOnlyScroll | 829 class ImplSidePaintingScrollTestImplOnlyScroll |
| 841 : public ImplSidePaintingScrollTest { | 830 : public ImplSidePaintingScrollTest { |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1127 RunTest(true, false, false); | 1116 RunTest(true, false, false); |
| 1128 } | 1117 } |
| 1129 | 1118 |
| 1130 TEST_F(LayerTreeHostScrollTestLayerStructureChange, ScrollDestroyWholeTree) { | 1119 TEST_F(LayerTreeHostScrollTestLayerStructureChange, ScrollDestroyWholeTree) { |
| 1131 scroll_destroy_whole_tree_ = true; | 1120 scroll_destroy_whole_tree_ = true; |
| 1132 RunTest(true, false, false); | 1121 RunTest(true, false, false); |
| 1133 } | 1122 } |
| 1134 | 1123 |
| 1135 } // namespace | 1124 } // namespace |
| 1136 } // namespace cc | 1125 } // namespace cc |
| OLD | NEW |