| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/animation/animation_host.h" | 5 #include "cc/animation/animation_host.h" |
| 6 | 6 |
| 7 #include "base/threading/thread_task_runner_handle.h" | 7 #include "base/threading/thread_task_runner_handle.h" |
| 8 #include "cc/animation/animation_id_provider.h" | 8 #include "cc/animation/animation_id_provider.h" |
| 9 #include "cc/animation/animation_player.h" | 9 #include "cc/animation/animation_player.h" |
| 10 #include "cc/animation/animation_timeline.h" | 10 #include "cc/animation/animation_timeline.h" |
| 11 #include "cc/debug/lap_timer.h" | 11 #include "cc/debug/lap_timer.h" |
| 12 #include "cc/layers/layer.h" | 12 #include "cc/layers/layer.h" |
| 13 #include "cc/test/fake_impl_task_runner_provider.h" | 13 #include "cc/test/fake_impl_task_runner_provider.h" |
| 14 #include "cc/test/fake_layer_tree_host.h" | 14 #include "cc/test/fake_layer_tree_host.h" |
| 15 #include "cc/test/fake_layer_tree_host_client.h" | 15 #include "cc/test/fake_layer_tree_host_client.h" |
| 16 #include "cc/test/fake_layer_tree_host_impl.h" | 16 #include "cc/test/fake_layer_tree_host_impl.h" |
| 17 #include "cc/test/stub_layer_tree_host_single_thread_client.h" | 17 #include "cc/test/stub_layer_tree_host_single_thread_client.h" |
| 18 #include "cc/test/test_task_graph_runner.h" | 18 #include "cc/test/test_task_graph_runner.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 20 #include "testing/perf/perf_test.h" | 20 #include "testing/perf/perf_test.h" |
| 21 | 21 |
| 22 namespace cc { | 22 namespace cc { |
| 23 | 23 |
| 24 class AnimationHostPerfTest : public testing::Test { | 24 class AnimationHostPerfTest : public testing::Test { |
| 25 protected: | 25 protected: |
| 26 AnimationHostPerfTest() |
| 27 : root_layer_impl_(), |
| 28 first_timeline_id_(), |
| 29 last_timeline_id_(), |
| 30 first_player_id_(), |
| 31 last_player_id_() {} |
| 32 |
| 26 void SetUp() override { | 33 void SetUp() override { |
| 27 LayerTreeSettings settings; | 34 LayerTreeSettings settings; |
| 28 layer_tree_host_ = | 35 layer_tree_host_ = |
| 29 FakeLayerTreeHost::Create(&fake_client_, &task_graph_runner_, settings); | 36 FakeLayerTreeHost::Create(&fake_client_, &task_graph_runner_, settings); |
| 30 layer_tree_host_->InitializeSingleThreaded( | 37 layer_tree_host_->InitializeSingleThreaded( |
| 31 &single_thread_client_, base::ThreadTaskRunnerHandle::Get(), nullptr); | 38 &single_thread_client_, base::ThreadTaskRunnerHandle::Get(), nullptr); |
| 32 | 39 |
| 33 root_layer_ = Layer::Create(); | 40 root_layer_ = Layer::Create(); |
| 34 layer_tree_host_->SetRootLayer(root_layer_); | 41 layer_tree_host_->SetRootLayer(root_layer_); |
| 35 | 42 |
| 36 root_layer_impl_ = layer_tree_host_->CommitAndCreateLayerImplTree(); | 43 root_layer_impl_ = layer_tree_host_->CommitAndCreateLayerImplTree(); |
| 37 } | 44 } |
| 38 | 45 |
| 39 void TearDown() override { | 46 void TearDown() override { |
| 40 root_layer_ = nullptr; | 47 root_layer_ = nullptr; |
| 41 root_layer_impl_ = nullptr; | 48 root_layer_impl_ = nullptr; |
| 42 | 49 |
| 43 layer_tree_host_->SetRootLayer(nullptr); | 50 layer_tree_host_->SetRootLayer(nullptr); |
| 44 layer_tree_host_ = nullptr; | 51 layer_tree_host_ = nullptr; |
| 45 } | 52 } |
| 46 | 53 |
| 47 AnimationHost* host() const { | 54 AnimationHost* host() const { |
| 48 return layer_tree_host_->GetLayerTree()->animation_host(); | 55 return layer_tree_host_->GetLayerTree()->animation_host(); |
| 49 } | 56 } |
| 50 AnimationHost* host_impl() const { | 57 AnimationHost* host_impl() const { |
| 51 return layer_tree_host_->host_impl()->animation_host(); | 58 return layer_tree_host_->host_impl()->animation_host(); |
| 52 } | 59 } |
| 53 | 60 |
| 54 void CreatePlayers(const int num_players) { | 61 void CreatePlayers(const int num_players) { |
| 55 scoped_refptr<AnimationTimeline> timeline = | 62 all_players_timeline_ = |
| 56 AnimationTimeline::Create(AnimationIdProvider::NextTimelineId()); | 63 AnimationTimeline::Create(AnimationIdProvider::NextTimelineId()); |
| 57 host()->AddAnimationTimeline(timeline); | 64 host()->AddAnimationTimeline(all_players_timeline_); |
| 58 | 65 |
| 59 const int first_player_id = AnimationIdProvider::NextPlayerId(); | 66 first_player_id_ = AnimationIdProvider::NextPlayerId(); |
| 60 int last_player_id = first_player_id; | 67 last_player_id_ = first_player_id_; |
| 61 | 68 |
| 62 for (int i = 0; i < num_players; ++i) { | 69 for (int i = 0; i < num_players; ++i) { |
| 63 scoped_refptr<Layer> layer = Layer::Create(); | 70 scoped_refptr<Layer> layer = Layer::Create(); |
| 64 root_layer_->AddChild(layer); | 71 root_layer_->AddChild(layer); |
| 65 layer->SetElementId(LayerIdToElementIdForTesting(layer->id())); | 72 layer->SetElementId(LayerIdToElementIdForTesting(layer->id())); |
| 66 | 73 |
| 67 scoped_refptr<AnimationPlayer> player = | 74 scoped_refptr<AnimationPlayer> player = |
| 68 AnimationPlayer::Create(last_player_id); | 75 AnimationPlayer::Create(last_player_id_); |
| 69 last_player_id = AnimationIdProvider::NextPlayerId(); | 76 last_player_id_ = AnimationIdProvider::NextPlayerId(); |
| 70 | 77 |
| 71 timeline->AttachPlayer(player); | 78 all_players_timeline_->AttachPlayer(player); |
| 72 player->AttachElement(layer->element_id()); | 79 player->AttachElement(layer->element_id()); |
| 73 EXPECT_TRUE(player->element_animations()); | 80 EXPECT_TRUE(player->element_animations()); |
| 74 } | 81 } |
| 75 | 82 |
| 76 // Create impl players. | 83 // Create impl players. |
| 77 layer_tree_host_->CommitAndCreateLayerImplTree(); | 84 layer_tree_host_->CommitAndCreateLayerImplTree(); |
| 78 | 85 |
| 79 // Check impl instances created. | 86 // Check impl instances created. |
| 80 scoped_refptr<AnimationTimeline> timeline_impl = | 87 scoped_refptr<AnimationTimeline> timeline_impl = |
| 81 host_impl()->GetTimelineById(timeline->id()); | 88 host_impl()->GetTimelineById(all_players_timeline_->id()); |
| 82 EXPECT_TRUE(timeline_impl); | 89 EXPECT_TRUE(timeline_impl); |
| 83 for (int i = first_player_id; i < last_player_id; ++i) | 90 for (int i = first_player_id_; i < last_player_id_; ++i) |
| 84 EXPECT_TRUE(timeline_impl->GetPlayerById(i)); | 91 EXPECT_TRUE(timeline_impl->GetPlayerById(i)); |
| 85 } | 92 } |
| 86 | 93 |
| 87 void CreateTimelines(const int num_timelines) { | 94 void CreateTimelines(const int num_timelines) { |
| 88 const int first_timeline_id = AnimationIdProvider::NextTimelineId(); | 95 first_timeline_id_ = AnimationIdProvider::NextTimelineId(); |
| 89 int last_timeline_id = first_timeline_id; | 96 last_timeline_id_ = first_timeline_id_; |
| 90 | 97 |
| 91 for (int i = 0; i < num_timelines; ++i) { | 98 for (int i = 0; i < num_timelines; ++i) { |
| 92 scoped_refptr<AnimationTimeline> timeline = | 99 scoped_refptr<AnimationTimeline> timeline = |
| 93 AnimationTimeline::Create(last_timeline_id); | 100 AnimationTimeline::Create(last_timeline_id_); |
| 94 last_timeline_id = AnimationIdProvider::NextTimelineId(); | 101 last_timeline_id_ = AnimationIdProvider::NextTimelineId(); |
| 95 host()->AddAnimationTimeline(timeline); | 102 host()->AddAnimationTimeline(timeline); |
| 96 } | 103 } |
| 97 | 104 |
| 98 // Create impl timelines. | 105 // Create impl timelines. |
| 99 layer_tree_host_->CommitAndCreateLayerImplTree(); | 106 layer_tree_host_->CommitAndCreateLayerImplTree(); |
| 100 | 107 |
| 101 // Check impl instances created. | 108 // Check impl instances created. |
| 102 for (int i = first_timeline_id; i < last_timeline_id; ++i) | 109 for (int i = first_timeline_id_; i < last_timeline_id_; ++i) |
| 103 EXPECT_TRUE(host_impl()->GetTimelineById(i)); | 110 EXPECT_TRUE(host_impl()->GetTimelineById(i)); |
| 104 } | 111 } |
| 105 | 112 |
| 113 void SetAllTimelinesNeedPushProperties() const { |
| 114 for (int i = first_timeline_id_; i < last_timeline_id_; ++i) |
| 115 host_impl()->GetTimelineById(i)->SetNeedsPushProperties(); |
| 116 } |
| 117 |
| 118 void SetAllPlayersNeedPushProperties() const { |
| 119 for (int i = first_player_id_; i < last_player_id_; ++i) |
| 120 all_players_timeline_->GetPlayerById(i)->SetNeedsPushProperties(); |
| 121 } |
| 122 |
| 106 void DoTest() { | 123 void DoTest() { |
| 107 timer_.Reset(); | 124 timer_.Reset(); |
| 108 do { | 125 do { |
| 126 // Invalidate dirty flags. |
| 127 SetAllTimelinesNeedPushProperties(); |
| 128 SetAllPlayersNeedPushProperties(); |
| 109 host()->PushPropertiesTo(host_impl()); | 129 host()->PushPropertiesTo(host_impl()); |
| 110 timer_.NextLap(); | 130 timer_.NextLap(); |
| 111 } while (!timer_.HasTimeLimitExpired()); | 131 } while (!timer_.HasTimeLimitExpired()); |
| 112 | 132 |
| 113 perf_test::PrintResult("push_properties_to", "", "", timer_.LapsPerSecond(), | 133 perf_test::PrintResult("push_properties_to", "", "", timer_.LapsPerSecond(), |
| 114 "runs/s", true); | 134 "runs/s", true); |
| 115 } | 135 } |
| 116 | 136 |
| 117 protected: | 137 private: |
| 118 StubLayerTreeHostSingleThreadClient single_thread_client_; | 138 StubLayerTreeHostSingleThreadClient single_thread_client_; |
| 119 FakeLayerTreeHostClient fake_client_; | 139 FakeLayerTreeHostClient fake_client_; |
| 120 std::unique_ptr<FakeLayerTreeHost> layer_tree_host_; | 140 std::unique_ptr<FakeLayerTreeHost> layer_tree_host_; |
| 121 scoped_refptr<Layer> root_layer_; | 141 scoped_refptr<Layer> root_layer_; |
| 122 LayerImpl* root_layer_impl_; | 142 LayerImpl* root_layer_impl_; |
| 143 scoped_refptr<AnimationTimeline> all_players_timeline_; |
| 144 |
| 145 int first_timeline_id_; |
| 146 int last_timeline_id_; |
| 147 |
| 148 int first_player_id_; |
| 149 int last_player_id_; |
| 123 | 150 |
| 124 LapTimer timer_; | 151 LapTimer timer_; |
| 125 TestTaskGraphRunner task_graph_runner_; | 152 TestTaskGraphRunner task_graph_runner_; |
| 126 }; | 153 }; |
| 127 | 154 |
| 128 TEST_F(AnimationHostPerfTest, Push1000PlayersPropertiesTo) { | 155 TEST_F(AnimationHostPerfTest, Push1000PlayersPropertiesTo) { |
| 129 CreatePlayers(1000); | 156 CreatePlayers(1000); |
| 130 DoTest(); | 157 DoTest(); |
| 131 } | 158 } |
| 132 | 159 |
| 133 TEST_F(AnimationHostPerfTest, Push10TimelinesPropertiesTo) { | 160 TEST_F(AnimationHostPerfTest, Push10TimelinesPropertiesTo) { |
| 134 CreateTimelines(10); | 161 CreateTimelines(10); |
| 135 DoTest(); | 162 DoTest(); |
| 136 } | 163 } |
| 137 | 164 |
| 138 TEST_F(AnimationHostPerfTest, Push1000TimelinesPropertiesTo) { | 165 TEST_F(AnimationHostPerfTest, Push1000TimelinesPropertiesTo) { |
| 139 CreateTimelines(1000); | 166 CreateTimelines(1000); |
| 140 DoTest(); | 167 DoTest(); |
| 141 } | 168 } |
| 142 | 169 |
| 143 } // namespace cc | 170 } // namespace cc |
| OLD | NEW |