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 "cc/animation/animation_curve.h" | 7 #include "cc/animation/animation_curve.h" |
8 #include "cc/animation/layer_animation_controller.h" | 8 #include "cc/animation/layer_animation_controller.h" |
9 #include "cc/animation/scroll_offset_animation_curve.h" | 9 #include "cc/animation/scroll_offset_animation_curve.h" |
10 #include "cc/animation/timing_function.h" | 10 #include "cc/animation/timing_function.h" |
11 #include "cc/layers/layer.h" | 11 #include "cc/layers/layer.h" |
12 #include "cc/layers/layer_impl.h" | 12 #include "cc/layers/layer_impl.h" |
13 #include "cc/test/animation_test_common.h" | 13 #include "cc/test/animation_test_common.h" |
14 #include "cc/test/fake_content_layer.h" | 14 #include "cc/test/fake_content_layer.h" |
15 #include "cc/test/fake_content_layer_client.h" | 15 #include "cc/test/fake_content_layer_client.h" |
16 #include "cc/test/layer_tree_test.h" | 16 #include "cc/test/layer_tree_test.h" |
17 #include "cc/trees/layer_tree_impl.h" | 17 #include "cc/trees/layer_tree_impl.h" |
18 | 18 |
19 namespace cc { | 19 namespace cc { |
20 namespace { | 20 namespace { |
21 | 21 |
22 class LayerTreeHostAnimationTest : public LayerTreeTest { | 22 class LayerTreeHostAnimationTest : public LayerTreeTest { |
23 public: | 23 public: |
24 virtual void SetupTree() OVERRIDE { | 24 virtual void SetupTree() OVERRIDE { |
25 LayerTreeTest::SetupTree(); | 25 LayerTreeTest::SetupTree(); |
26 layer_tree_host()->root_layer()->set_layer_animation_delegate(this); | 26 layer_tree_host()->root_layer()->set_layer_animation_delegate(this); |
27 } | 27 } |
28 }; | 28 }; |
29 | 29 |
30 // Makes sure that SetNeedsUpdateLayers does not cause the CommitRequested() | 30 // Makes sure that SetNeedsAnimate does not cause the CommitRequested() state to |
31 // state to be set. | 31 // be set. |
32 class LayerTreeHostAnimationTestSetNeedsUpdateLayersShouldNotSetCommitRequested | 32 class LayerTreeHostAnimationTestSetNeedsAnimateShouldNotSetCommitRequested |
33 : public LayerTreeHostAnimationTest { | 33 : public LayerTreeHostAnimationTest { |
34 public: | 34 public: |
35 LayerTreeHostAnimationTestSetNeedsUpdateLayersShouldNotSetCommitRequested() | 35 LayerTreeHostAnimationTestSetNeedsAnimateShouldNotSetCommitRequested() |
36 : num_commits_(0) {} | 36 : num_commits_(0) {} |
37 | 37 |
38 virtual void BeginTest() OVERRIDE { | 38 virtual void BeginTest() OVERRIDE { |
39 PostSetNeedsCommitToMainThread(); | 39 PostSetNeedsCommitToMainThread(); |
40 } | 40 } |
41 | 41 |
42 virtual void Animate(base::TimeTicks monotonic_time) OVERRIDE { | 42 virtual void Animate(base::TimeTicks monotonic_time) OVERRIDE { |
43 // We skip the first commit becasue its the commit that populates the | 43 // We skip the first commit becasue its the commit that populates the |
44 // impl thread with a tree. After the second commit, the test is done. | 44 // impl thread with a tree. After the second commit, the test is done. |
45 if (num_commits_ != 1) | 45 if (num_commits_ != 1) |
46 return; | 46 return; |
47 | 47 |
48 layer_tree_host()->SetNeedsUpdateLayers(); | 48 layer_tree_host()->SetNeedsAnimate(); |
49 // Right now, CommitRequested is going to be true, because during | 49 // Right now, CommitRequested is going to be true, because during |
50 // BeginFrame, we force CommitRequested to true to prevent requests from | 50 // BeginFrame, we force CommitRequested to true to prevent requests from |
51 // hitting the impl thread. But, when the next DidCommit happens, we should | 51 // hitting the impl thread. But, when the next DidCommit happens, we should |
52 // verify that CommitRequested has gone back to false. | 52 // verify that CommitRequested has gone back to false. |
53 } | 53 } |
54 | 54 |
55 virtual void DidCommit() OVERRIDE { | 55 virtual void DidCommit() OVERRIDE { |
56 if (!num_commits_) { | 56 if (!num_commits_) { |
57 EXPECT_FALSE(layer_tree_host()->CommitRequested()); | 57 EXPECT_FALSE(layer_tree_host()->CommitRequested()); |
58 layer_tree_host()->SetNeedsUpdateLayers(); | 58 layer_tree_host()->SetNeedsAnimate(); |
59 EXPECT_FALSE(layer_tree_host()->CommitRequested()); | 59 EXPECT_FALSE(layer_tree_host()->CommitRequested()); |
60 } | 60 } |
61 | 61 |
62 // Verifies that the SetNeedsUpdateLayers we made in ::Animate did not | 62 // Verifies that the SetNeedsAnimate we made in ::Animate did not |
63 // trigger CommitRequested. | 63 // trigger CommitRequested. |
64 EXPECT_FALSE(layer_tree_host()->CommitRequested()); | 64 EXPECT_FALSE(layer_tree_host()->CommitRequested()); |
65 EndTest(); | 65 EndTest(); |
66 num_commits_++; | 66 num_commits_++; |
67 } | 67 } |
68 | 68 |
69 virtual void AfterTest() OVERRIDE {} | 69 virtual void AfterTest() OVERRIDE {} |
70 | 70 |
71 private: | 71 private: |
72 int num_commits_; | 72 int num_commits_; |
73 }; | 73 }; |
74 | 74 |
75 MULTI_THREAD_TEST_F( | 75 MULTI_THREAD_TEST_F( |
76 LayerTreeHostAnimationTestSetNeedsUpdateLayersShouldNotSetCommitRequested); | 76 LayerTreeHostAnimationTestSetNeedsAnimateShouldNotSetCommitRequested); |
77 | 77 |
78 // Trigger a frame with SetNeedsCommit. Then, inside the resulting animate | 78 // Trigger a frame with SetNeedsCommit. Then, inside the resulting animate |
79 // callback, request another frame using SetNeedsUpdateLayers. End the test when | 79 // callback, request another frame using SetNeedsAnimate. End the test when |
80 // animate gets called yet-again, indicating that the proxy is correctly | 80 // animate gets called yet-again, indicating that the proxy is correctly |
81 // handling the case where SetNeedsUpdateLayers() is called inside the | 81 // handling the case where SetNeedsAnimate() is called inside the BeginFrame |
82 // BeginFrame flow. | 82 // flow. |
83 class LayerTreeHostAnimationTestSetNeedsUpdateLayersInsideAnimationCallback | 83 class LayerTreeHostAnimationTestSetNeedsAnimateInsideAnimationCallback |
84 : public LayerTreeHostAnimationTest { | 84 : public LayerTreeHostAnimationTest { |
85 public: | 85 public: |
86 LayerTreeHostAnimationTestSetNeedsUpdateLayersInsideAnimationCallback() | 86 LayerTreeHostAnimationTestSetNeedsAnimateInsideAnimationCallback() |
87 : num_animates_(0) {} | 87 : num_animates_(0) {} |
88 | 88 |
89 virtual void BeginTest() OVERRIDE { | 89 virtual void BeginTest() OVERRIDE { |
90 PostSetNeedsCommitToMainThread(); | 90 PostSetNeedsCommitToMainThread(); |
91 } | 91 } |
92 | 92 |
93 virtual void Animate(base::TimeTicks) OVERRIDE { | 93 virtual void Animate(base::TimeTicks) OVERRIDE { |
94 if (!num_animates_) { | 94 if (!num_animates_) { |
95 layer_tree_host()->SetNeedsUpdateLayers(); | 95 layer_tree_host()->SetNeedsAnimate(); |
96 num_animates_++; | 96 num_animates_++; |
97 return; | 97 return; |
98 } | 98 } |
99 EndTest(); | 99 EndTest(); |
100 } | 100 } |
101 | 101 |
102 virtual void AfterTest() OVERRIDE {} | 102 virtual void AfterTest() OVERRIDE {} |
103 | 103 |
104 private: | 104 private: |
105 int num_animates_; | 105 int num_animates_; |
106 }; | 106 }; |
107 | 107 |
108 MULTI_THREAD_TEST_F( | 108 MULTI_THREAD_TEST_F( |
109 LayerTreeHostAnimationTestSetNeedsUpdateLayersInsideAnimationCallback); | 109 LayerTreeHostAnimationTestSetNeedsAnimateInsideAnimationCallback); |
110 | 110 |
111 // Add a layer animation and confirm that | 111 // Add a layer animation and confirm that |
112 // LayerTreeHostImpl::updateAnimationState does get called and continues to | 112 // LayerTreeHostImpl::updateAnimationState does get called and continues to |
113 // get called. | 113 // get called. |
114 class LayerTreeHostAnimationTestAddAnimation | 114 class LayerTreeHostAnimationTestAddAnimation |
115 : public LayerTreeHostAnimationTest { | 115 : public LayerTreeHostAnimationTest { |
116 public: | 116 public: |
117 LayerTreeHostAnimationTestAddAnimation() | 117 LayerTreeHostAnimationTestAddAnimation() |
118 : num_animates_(0), | 118 : num_animates_(0), |
119 received_animation_started_notification_(false) { | 119 received_animation_started_notification_(false) { |
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
725 public: | 725 public: |
726 LayerTreeHostAnimationTestContinuousAnimate() | 726 LayerTreeHostAnimationTestContinuousAnimate() |
727 : num_commit_complete_(0), | 727 : num_commit_complete_(0), |
728 num_draw_layers_(0) { | 728 num_draw_layers_(0) { |
729 } | 729 } |
730 | 730 |
731 virtual void BeginTest() OVERRIDE { | 731 virtual void BeginTest() OVERRIDE { |
732 PostSetNeedsCommitToMainThread(); | 732 PostSetNeedsCommitToMainThread(); |
733 } | 733 } |
734 | 734 |
735 virtual void SetupTree() OVERRIDE { | |
736 LayerTreeHostAnimationTest::SetupTree(); | |
737 content_ = FakeContentLayer::Create(&client_); | |
738 content_->set_always_update_resources(true); | |
739 layer_tree_host()->root_layer()->AddChild(content_); | |
740 } | |
741 | |
742 virtual void Animate(base::TimeTicks) OVERRIDE { | 735 virtual void Animate(base::TimeTicks) OVERRIDE { |
743 if (num_draw_layers_ == 2) | 736 if (num_draw_layers_ == 2) |
744 return; | 737 return; |
745 layer_tree_host()->SetNeedsUpdateLayers(); | 738 layer_tree_host()->SetNeedsAnimate(); |
746 } | 739 } |
747 | 740 |
748 virtual void Layout() OVERRIDE { | 741 virtual void Layout() OVERRIDE { |
749 content_->SetNeedsDisplay(); | 742 layer_tree_host()->root_layer()->SetNeedsDisplay(); |
750 } | 743 } |
751 | 744 |
752 virtual void CommitCompleteOnThread(LayerTreeHostImpl* tree_impl) OVERRIDE { | 745 virtual void CommitCompleteOnThread(LayerTreeHostImpl* tree_impl) OVERRIDE { |
753 if (num_draw_layers_ == 1) | 746 if (num_draw_layers_ == 1) |
754 num_commit_complete_++; | 747 num_commit_complete_++; |
755 } | 748 } |
756 | 749 |
757 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { | 750 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
758 num_draw_layers_++; | 751 num_draw_layers_++; |
759 if (num_draw_layers_ == 2) | 752 if (num_draw_layers_ == 2) |
760 EndTest(); | 753 EndTest(); |
761 } | 754 } |
762 | 755 |
763 virtual void AfterTest() OVERRIDE { | 756 virtual void AfterTest() OVERRIDE { |
764 // Check that we didn't commit twice between first and second draw. | 757 // Check that we didn't commit twice between first and second draw. |
765 EXPECT_EQ(1, num_commit_complete_); | 758 EXPECT_EQ(1, num_commit_complete_); |
766 } | 759 } |
767 | 760 |
768 private: | 761 private: |
769 int num_commit_complete_; | 762 int num_commit_complete_; |
770 int num_draw_layers_; | 763 int num_draw_layers_; |
771 FakeContentLayerClient client_; | |
772 scoped_refptr<FakeContentLayer> content_; | |
773 }; | 764 }; |
774 | 765 |
775 MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestContinuousAnimate); | 766 MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestContinuousAnimate); |
776 | 767 |
777 // Make sure the main thread can still execute animations when CanDraw() is not | 768 // Make sure the main thread can still execute animations when CanDraw() is not |
778 // true. | 769 // true. |
779 class LayerTreeHostAnimationTestRunAnimationWhenNotCanDraw | 770 class LayerTreeHostAnimationTestRunAnimationWhenNotCanDraw |
780 : public LayerTreeHostAnimationTest { | 771 : public LayerTreeHostAnimationTest { |
781 public: | 772 public: |
782 LayerTreeHostAnimationTestRunAnimationWhenNotCanDraw() : started_times_(0) {} | 773 LayerTreeHostAnimationTestRunAnimationWhenNotCanDraw() : started_times_(0) {} |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1017 FakeContentLayerClient client_; | 1008 FakeContentLayerClient client_; |
1018 scoped_refptr<FakeContentLayer> scroll_layer_; | 1009 scoped_refptr<FakeContentLayer> scroll_layer_; |
1019 }; | 1010 }; |
1020 | 1011 |
1021 // SingleThreadProxy doesn't send scroll updates from LayerTreeHostImpl to | 1012 // SingleThreadProxy doesn't send scroll updates from LayerTreeHostImpl to |
1022 // LayerTreeHost. | 1013 // LayerTreeHost. |
1023 MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestScrollOffsetChangesArePropagated); | 1014 MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestScrollOffsetChangesArePropagated); |
1024 | 1015 |
1025 } // namespace | 1016 } // namespace |
1026 } // namespace cc | 1017 } // namespace cc |
OLD | NEW |