| 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/thread_task_runner_handle.h" | 7 #include "base/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/test_task_graph_runner.h" | 17 #include "cc/test/test_task_graph_runner.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 19 #include "testing/perf/perf_test.h" | 19 #include "testing/perf/perf_test.h" |
| 20 | 20 |
| 21 namespace cc { | 21 namespace cc { |
| 22 | 22 |
| 23 static const int kNumberOfAnimationPlayers = 1000; | |
| 24 | |
| 25 class AnimationHostPerfTest : public testing::Test { | 23 class AnimationHostPerfTest : public testing::Test { |
| 26 public: | 24 public: |
| 27 AnimationHostPerfTest() : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {} | 25 AnimationHostPerfTest() : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {} |
| 28 | 26 |
| 29 protected: | 27 protected: |
| 30 void SetUp() override { | 28 void SetUp() override { |
| 31 LayerTreeSettings settings; | 29 LayerTreeSettings settings; |
| 32 layer_tree_host_ = | 30 layer_tree_host_ = |
| 33 FakeLayerTreeHost::Create(&fake_client_, &task_graph_runner_, settings); | 31 FakeLayerTreeHost::Create(&fake_client_, &task_graph_runner_, settings); |
| 34 layer_tree_host_->InitializeSingleThreaded( | 32 layer_tree_host_->InitializeSingleThreaded( |
| 35 &fake_client_, base::ThreadTaskRunnerHandle::Get(), nullptr); | 33 &fake_client_, base::ThreadTaskRunnerHandle::Get(), nullptr); |
| 34 |
| 35 root_layer_ = Layer::Create(); |
| 36 layer_tree_host_->SetRootLayer(root_layer_); |
| 37 |
| 38 root_layer_impl_ = layer_tree_host_->CommitAndCreateLayerImplTree(); |
| 36 } | 39 } |
| 37 | 40 |
| 38 void TearDown() override { | 41 void TearDown() override { |
| 42 root_layer_ = nullptr; |
| 43 root_layer_impl_ = nullptr; |
| 44 |
| 39 layer_tree_host_->SetRootLayer(nullptr); | 45 layer_tree_host_->SetRootLayer(nullptr); |
| 40 layer_tree_host_ = nullptr; | 46 layer_tree_host_ = nullptr; |
| 41 } | 47 } |
| 42 | 48 |
| 49 AnimationHost* host() const { return layer_tree_host_->animation_host(); } |
| 50 AnimationHost* host_impl() const { |
| 51 return layer_tree_host_->host_impl()->animation_host(); |
| 52 } |
| 53 |
| 54 void CreatePlayers(const int num_players) { |
| 55 scoped_refptr<AnimationTimeline> timeline = |
| 56 AnimationTimeline::Create(AnimationIdProvider::NextTimelineId()); |
| 57 host()->AddAnimationTimeline(timeline); |
| 58 |
| 59 const int first_player_id = AnimationIdProvider::NextPlayerId(); |
| 60 int last_player_id = first_player_id; |
| 61 |
| 62 for (int i = 0; i < num_players; ++i) { |
| 63 scoped_refptr<Layer> layer = Layer::Create(); |
| 64 root_layer_->AddChild(layer); |
| 65 |
| 66 scoped_refptr<AnimationPlayer> player = |
| 67 AnimationPlayer::Create(last_player_id); |
| 68 last_player_id = AnimationIdProvider::NextPlayerId(); |
| 69 |
| 70 timeline->AttachPlayer(player); |
| 71 player->AttachLayer(layer->id()); |
| 72 EXPECT_TRUE(player->element_animations()); |
| 73 } |
| 74 |
| 75 // Create impl players. |
| 76 layer_tree_host_->CommitAndCreateLayerImplTree(); |
| 77 |
| 78 // Check impl instances created. |
| 79 scoped_refptr<AnimationTimeline> timeline_impl = |
| 80 host_impl()->GetTimelineById(timeline->id()); |
| 81 EXPECT_TRUE(timeline_impl); |
| 82 for (int i = first_player_id; i < last_player_id; ++i) |
| 83 EXPECT_TRUE(timeline_impl->GetPlayerById(i)); |
| 84 } |
| 85 |
| 86 void CreateTimelines(const int num_timelines) { |
| 87 const int first_timeline_id = AnimationIdProvider::NextTimelineId(); |
| 88 int last_timeline_id = first_timeline_id; |
| 89 |
| 90 for (int i = 0; i < num_timelines; ++i) { |
| 91 scoped_refptr<AnimationTimeline> timeline = |
| 92 AnimationTimeline::Create(last_timeline_id); |
| 93 last_timeline_id = AnimationIdProvider::NextTimelineId(); |
| 94 host()->AddAnimationTimeline(timeline); |
| 95 } |
| 96 |
| 97 // Create impl timelines. |
| 98 layer_tree_host_->CommitAndCreateLayerImplTree(); |
| 99 |
| 100 // Check impl instances created. |
| 101 for (int i = first_timeline_id; i < last_timeline_id; ++i) |
| 102 EXPECT_TRUE(host_impl()->GetTimelineById(i)); |
| 103 } |
| 104 |
| 105 void DoTest() { |
| 106 timer_.Reset(); |
| 107 do { |
| 108 host()->PushPropertiesTo(host_impl()); |
| 109 timer_.NextLap(); |
| 110 } while (!timer_.HasTimeLimitExpired()); |
| 111 |
| 112 perf_test::PrintResult("push_properties_to", "", "", timer_.LapsPerSecond(), |
| 113 "runs/s", true); |
| 114 } |
| 115 |
| 116 protected: |
| 43 scoped_ptr<FakeLayerTreeHost> layer_tree_host_; | 117 scoped_ptr<FakeLayerTreeHost> layer_tree_host_; |
| 118 scoped_refptr<Layer> root_layer_; |
| 119 LayerImpl* root_layer_impl_; |
| 120 |
| 44 LapTimer timer_; | 121 LapTimer timer_; |
| 45 | |
| 46 TestTaskGraphRunner task_graph_runner_; | 122 TestTaskGraphRunner task_graph_runner_; |
| 47 FakeLayerTreeHostClient fake_client_; | 123 FakeLayerTreeHostClient fake_client_; |
| 48 }; | 124 }; |
| 49 | 125 |
| 50 TEST_F(AnimationHostPerfTest, PushPropertiesTo) { | 126 TEST_F(AnimationHostPerfTest, Push1000PlayersPropertiesTo) { |
| 51 AnimationHost* host = layer_tree_host_->animation_host(); | 127 CreatePlayers(1000); |
| 52 AnimationHost* host_impl = layer_tree_host_->host_impl()->animation_host(); | 128 DoTest(); |
| 129 } |
| 53 | 130 |
| 54 scoped_refptr<Layer> root_layer = Layer::Create(); | 131 TEST_F(AnimationHostPerfTest, Push10TimelinesPropertiesTo) { |
| 55 layer_tree_host_->SetRootLayer(root_layer); | 132 CreateTimelines(10); |
| 133 DoTest(); |
| 134 } |
| 56 | 135 |
| 57 scoped_ptr<LayerImpl> root_layer_impl = LayerImpl::Create( | 136 TEST_F(AnimationHostPerfTest, Push1000TimelinesPropertiesTo) { |
| 58 layer_tree_host_->host_impl()->active_tree(), root_layer->id()); | 137 CreateTimelines(1000); |
| 59 | 138 DoTest(); |
| 60 scoped_refptr<AnimationTimeline> timeline = | |
| 61 AnimationTimeline::Create(AnimationIdProvider::NextTimelineId()); | |
| 62 host->AddAnimationTimeline(timeline); | |
| 63 | |
| 64 scoped_refptr<AnimationTimeline> timeline_impl = | |
| 65 timeline->CreateImplInstance(); | |
| 66 host_impl->AddAnimationTimeline(timeline_impl); | |
| 67 | |
| 68 for (int i = 0; i < kNumberOfAnimationPlayers; ++i) { | |
| 69 scoped_refptr<Layer> layer = Layer::Create(); | |
| 70 root_layer->AddChild(layer); | |
| 71 | |
| 72 const int layer_id = layer->id(); | |
| 73 | |
| 74 scoped_ptr<LayerImpl> layer_impl = LayerImpl::Create( | |
| 75 layer_tree_host_->host_impl()->active_tree(), layer_id); | |
| 76 root_layer_impl->AddChild(std::move(layer_impl)); | |
| 77 | |
| 78 scoped_refptr<AnimationPlayer> player = | |
| 79 AnimationPlayer::Create(AnimationIdProvider::NextPlayerId()); | |
| 80 timeline->AttachPlayer(player); | |
| 81 player->AttachLayer(layer_id); | |
| 82 EXPECT_TRUE(player->element_animations()); | |
| 83 | |
| 84 scoped_refptr<AnimationPlayer> impl_player = player->CreateImplInstance(); | |
| 85 timeline_impl->AttachPlayer(impl_player); | |
| 86 impl_player->AttachLayer(layer_id); | |
| 87 EXPECT_TRUE(impl_player->element_animations()); | |
| 88 } | |
| 89 | |
| 90 timer_.Reset(); | |
| 91 do { | |
| 92 host->PushPropertiesTo(host_impl); | |
| 93 timer_.NextLap(); | |
| 94 } while (!timer_.HasTimeLimitExpired()); | |
| 95 | |
| 96 perf_test::PrintResult("push_properties_to", "", "", timer_.LapsPerSecond(), | |
| 97 "runs/s", true); | |
| 98 } | 139 } |
| 99 | 140 |
| 100 } // namespace cc | 141 } // namespace cc |
| OLD | NEW |