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 SetNeedsAnimate does not cause the CommitRequested() state to | 30 // Makes sure that SetNeedsUpdateLayers does not cause the CommitRequested() |
31 // be set. | 31 // state to be set. |
32 class LayerTreeHostAnimationTestSetNeedsAnimateShouldNotSetCommitRequested | 32 class LayerTreeHostAnimationTestSetNeedsUpdateLayersShouldNotSetCommitRequested |
33 : public LayerTreeHostAnimationTest { | 33 : public LayerTreeHostAnimationTest { |
34 public: | 34 public: |
35 LayerTreeHostAnimationTestSetNeedsAnimateShouldNotSetCommitRequested() | 35 LayerTreeHostAnimationTestSetNeedsUpdateLayersShouldNotSetCommitRequested() |
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()->SetNeedsAnimate(); | 48 layer_tree_host()->SetNeedsUpdateLayers(); |
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()->SetNeedsAnimate(); | 58 layer_tree_host()->SetNeedsUpdateLayers(); |
59 EXPECT_FALSE(layer_tree_host()->CommitRequested()); | 59 EXPECT_FALSE(layer_tree_host()->CommitRequested()); |
60 } | 60 } |
61 | 61 |
62 // Verifies that the SetNeedsAnimate we made in ::Animate did not | 62 // Verifies that the SetNeedsUpdateLayers 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 LayerTreeHostAnimationTestSetNeedsAnimateShouldNotSetCommitRequested); | 76 LayerTreeHostAnimationTestSetNeedsUpdateLayersShouldNotSetCommitRequested); |
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 SetNeedsAnimate. End the test when | 79 // callback, request another frame using SetNeedsUpdateLayers. 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 SetNeedsAnimate() is called inside the BeginFrame | 81 // handling the case where SetNeedsUpdateLayers() is called inside the |
82 // flow. | 82 // BeginFrame flow. |
83 class LayerTreeHostAnimationTestSetNeedsAnimateInsideAnimationCallback | 83 class LayerTreeHostAnimationTestSetNeedsUpdateLayersInsideAnimationCallback |
84 : public LayerTreeHostAnimationTest { | 84 : public LayerTreeHostAnimationTest { |
85 public: | 85 public: |
86 LayerTreeHostAnimationTestSetNeedsAnimateInsideAnimationCallback() | 86 LayerTreeHostAnimationTestSetNeedsUpdateLayersInsideAnimationCallback() |
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()->SetNeedsAnimate(); | 95 layer_tree_host()->SetNeedsUpdateLayers(); |
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 LayerTreeHostAnimationTestSetNeedsAnimateInsideAnimationCallback); | 109 LayerTreeHostAnimationTestSetNeedsUpdateLayersInsideAnimationCallback); |
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 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
711 public: | 711 public: |
712 LayerTreeHostAnimationTestContinuousAnimate() | 712 LayerTreeHostAnimationTestContinuousAnimate() |
713 : num_commit_complete_(0), | 713 : num_commit_complete_(0), |
714 num_draw_layers_(0) { | 714 num_draw_layers_(0) { |
715 } | 715 } |
716 | 716 |
717 virtual void BeginTest() OVERRIDE { | 717 virtual void BeginTest() OVERRIDE { |
718 PostSetNeedsCommitToMainThread(); | 718 PostSetNeedsCommitToMainThread(); |
719 } | 719 } |
720 | 720 |
| 721 virtual void SetupTree() OVERRIDE { |
| 722 LayerTreeHostAnimationTest::SetupTree(); |
| 723 content_ = FakeContentLayer::Create(&client_); |
| 724 content_->set_always_update_resources(true); |
| 725 layer_tree_host()->root_layer()->AddChild(content_); |
| 726 } |
| 727 |
721 virtual void Animate(base::TimeTicks) OVERRIDE { | 728 virtual void Animate(base::TimeTicks) OVERRIDE { |
722 if (num_draw_layers_ == 2) | 729 if (num_draw_layers_ == 2) |
723 return; | 730 return; |
724 layer_tree_host()->SetNeedsAnimate(); | 731 layer_tree_host()->SetNeedsUpdateLayers(); |
725 } | 732 } |
726 | 733 |
727 virtual void Layout() OVERRIDE { | 734 virtual void Layout() OVERRIDE { |
728 layer_tree_host()->root_layer()->SetNeedsDisplay(); | 735 content_->SetNeedsDisplay(); |
729 } | 736 } |
730 | 737 |
731 virtual void CommitCompleteOnThread(LayerTreeHostImpl* tree_impl) OVERRIDE { | 738 virtual void CommitCompleteOnThread(LayerTreeHostImpl* tree_impl) OVERRIDE { |
732 if (num_draw_layers_ == 1) | 739 if (num_draw_layers_ == 1) |
733 num_commit_complete_++; | 740 num_commit_complete_++; |
734 } | 741 } |
735 | 742 |
736 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { | 743 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
737 num_draw_layers_++; | 744 num_draw_layers_++; |
738 if (num_draw_layers_ == 2) | 745 if (num_draw_layers_ == 2) |
739 EndTest(); | 746 EndTest(); |
740 } | 747 } |
741 | 748 |
742 virtual void AfterTest() OVERRIDE { | 749 virtual void AfterTest() OVERRIDE { |
743 // Check that we didn't commit twice between first and second draw. | 750 // Check that we didn't commit twice between first and second draw. |
744 EXPECT_EQ(1, num_commit_complete_); | 751 EXPECT_EQ(1, num_commit_complete_); |
745 } | 752 } |
746 | 753 |
747 private: | 754 private: |
748 int num_commit_complete_; | 755 int num_commit_complete_; |
749 int num_draw_layers_; | 756 int num_draw_layers_; |
| 757 FakeContentLayerClient client_; |
| 758 scoped_refptr<FakeContentLayer> content_; |
750 }; | 759 }; |
751 | 760 |
752 MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestContinuousAnimate); | 761 MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestContinuousAnimate); |
753 | 762 |
754 // Make sure the main thread can still execute animations when CanDraw() is not | 763 // Make sure the main thread can still execute animations when CanDraw() is not |
755 // true. | 764 // true. |
756 class LayerTreeHostAnimationTestRunAnimationWhenNotCanDraw | 765 class LayerTreeHostAnimationTestRunAnimationWhenNotCanDraw |
757 : public LayerTreeHostAnimationTest { | 766 : public LayerTreeHostAnimationTest { |
758 public: | 767 public: |
759 LayerTreeHostAnimationTestRunAnimationWhenNotCanDraw() : started_times_(0) {} | 768 LayerTreeHostAnimationTestRunAnimationWhenNotCanDraw() : started_times_(0) {} |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
976 FakeContentLayerClient client_; | 985 FakeContentLayerClient client_; |
977 scoped_refptr<FakeContentLayer> scroll_layer_; | 986 scoped_refptr<FakeContentLayer> scroll_layer_; |
978 }; | 987 }; |
979 | 988 |
980 // SingleThreadProxy doesn't send scroll updates from LayerTreeHostImpl to | 989 // SingleThreadProxy doesn't send scroll updates from LayerTreeHostImpl to |
981 // LayerTreeHost. | 990 // LayerTreeHost. |
982 MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestScrollOffsetChangesArePropagated); | 991 MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestScrollOffsetChangesArePropagated); |
983 | 992 |
984 } // namespace | 993 } // namespace |
985 } // namespace cc | 994 } // namespace cc |
OLD | NEW |