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