| 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 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 |
| 735 virtual void Animate(base::TimeTicks) OVERRIDE { | 742 virtual void Animate(base::TimeTicks) OVERRIDE { |
| 736 if (num_draw_layers_ == 2) | 743 if (num_draw_layers_ == 2) |
| 737 return; | 744 return; |
| 738 layer_tree_host()->SetNeedsAnimate(); | 745 layer_tree_host()->SetNeedsUpdateLayers(); |
| 739 } | 746 } |
| 740 | 747 |
| 741 virtual void Layout() OVERRIDE { | 748 virtual void Layout() OVERRIDE { |
| 742 layer_tree_host()->root_layer()->SetNeedsDisplay(); | 749 content_->SetNeedsDisplay(); |
| 743 } | 750 } |
| 744 | 751 |
| 745 virtual void CommitCompleteOnThread(LayerTreeHostImpl* tree_impl) OVERRIDE { | 752 virtual void CommitCompleteOnThread(LayerTreeHostImpl* tree_impl) OVERRIDE { |
| 746 if (num_draw_layers_ == 1) | 753 if (num_draw_layers_ == 1) |
| 747 num_commit_complete_++; | 754 num_commit_complete_++; |
| 748 } | 755 } |
| 749 | 756 |
| 750 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { | 757 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
| 751 num_draw_layers_++; | 758 num_draw_layers_++; |
| 752 if (num_draw_layers_ == 2) | 759 if (num_draw_layers_ == 2) |
| 753 EndTest(); | 760 EndTest(); |
| 754 } | 761 } |
| 755 | 762 |
| 756 virtual void AfterTest() OVERRIDE { | 763 virtual void AfterTest() OVERRIDE { |
| 757 // Check that we didn't commit twice between first and second draw. | 764 // Check that we didn't commit twice between first and second draw. |
| 758 EXPECT_EQ(1, num_commit_complete_); | 765 EXPECT_EQ(1, num_commit_complete_); |
| 759 } | 766 } |
| 760 | 767 |
| 761 private: | 768 private: |
| 762 int num_commit_complete_; | 769 int num_commit_complete_; |
| 763 int num_draw_layers_; | 770 int num_draw_layers_; |
| 771 FakeContentLayerClient client_; |
| 772 scoped_refptr<FakeContentLayer> content_; |
| 764 }; | 773 }; |
| 765 | 774 |
| 766 MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestContinuousAnimate); | 775 MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestContinuousAnimate); |
| 767 | 776 |
| 768 // Make sure the main thread can still execute animations when CanDraw() is not | 777 // Make sure the main thread can still execute animations when CanDraw() is not |
| 769 // true. | 778 // true. |
| 770 class LayerTreeHostAnimationTestRunAnimationWhenNotCanDraw | 779 class LayerTreeHostAnimationTestRunAnimationWhenNotCanDraw |
| 771 : public LayerTreeHostAnimationTest { | 780 : public LayerTreeHostAnimationTest { |
| 772 public: | 781 public: |
| 773 LayerTreeHostAnimationTestRunAnimationWhenNotCanDraw() : started_times_(0) {} | 782 LayerTreeHostAnimationTestRunAnimationWhenNotCanDraw() : started_times_(0) {} |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1008 FakeContentLayerClient client_; | 1017 FakeContentLayerClient client_; |
| 1009 scoped_refptr<FakeContentLayer> scroll_layer_; | 1018 scoped_refptr<FakeContentLayer> scroll_layer_; |
| 1010 }; | 1019 }; |
| 1011 | 1020 |
| 1012 // SingleThreadProxy doesn't send scroll updates from LayerTreeHostImpl to | 1021 // SingleThreadProxy doesn't send scroll updates from LayerTreeHostImpl to |
| 1013 // LayerTreeHost. | 1022 // LayerTreeHost. |
| 1014 MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestScrollOffsetChangesArePropagated); | 1023 MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestScrollOffsetChangesArePropagated); |
| 1015 | 1024 |
| 1016 } // namespace | 1025 } // namespace |
| 1017 } // namespace cc | 1026 } // namespace cc |
| OLD | NEW |