| 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/layers/layer_settings.h" | |
| 14 #include "cc/test/fake_impl_task_runner_provider.h" | 13 #include "cc/test/fake_impl_task_runner_provider.h" |
| 15 #include "cc/test/fake_layer_tree_host.h" | 14 #include "cc/test/fake_layer_tree_host.h" |
| 16 #include "cc/test/fake_layer_tree_host_client.h" | 15 #include "cc/test/fake_layer_tree_host_client.h" |
| 17 #include "cc/test/fake_layer_tree_host_impl.h" | 16 #include "cc/test/fake_layer_tree_host_impl.h" |
| 18 #include "cc/test/test_task_graph_runner.h" | 17 #include "cc/test/test_task_graph_runner.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 20 #include "testing/perf/perf_test.h" | 19 #include "testing/perf/perf_test.h" |
| 21 | 20 |
| 22 namespace cc { | 21 namespace cc { |
| 23 | 22 |
| 24 static const int kNumberOfAnimationPlayers = 1000; | 23 static const int kNumberOfAnimationPlayers = 1000; |
| 25 | 24 |
| 26 class AnimationHostPerfTest : public testing::Test { | 25 class AnimationHostPerfTest : public testing::Test { |
| 27 public: | 26 public: |
| 28 AnimationHostPerfTest() : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {} | 27 AnimationHostPerfTest() : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {} |
| 29 | 28 |
| 30 protected: | 29 protected: |
| 31 void SetUp() override { | 30 void SetUp() override { |
| 32 LayerTreeSettings settings; | 31 LayerTreeSettings settings; |
| 33 settings.use_compositor_animation_timelines = true; | |
| 34 | |
| 35 layer_tree_host_ = | 32 layer_tree_host_ = |
| 36 FakeLayerTreeHost::Create(&fake_client_, &task_graph_runner_, settings); | 33 FakeLayerTreeHost::Create(&fake_client_, &task_graph_runner_, settings); |
| 37 layer_tree_host_->InitializeSingleThreaded( | 34 layer_tree_host_->InitializeSingleThreaded( |
| 38 &fake_client_, base::ThreadTaskRunnerHandle::Get(), nullptr); | 35 &fake_client_, base::ThreadTaskRunnerHandle::Get(), nullptr); |
| 39 } | 36 } |
| 40 | 37 |
| 41 void TearDown() override { | 38 void TearDown() override { |
| 42 layer_tree_host_->SetRootLayer(nullptr); | 39 layer_tree_host_->SetRootLayer(nullptr); |
| 43 layer_tree_host_ = nullptr; | 40 layer_tree_host_ = nullptr; |
| 44 } | 41 } |
| 45 | 42 |
| 46 LayerSettings GetLayerSettings() const { | |
| 47 DCHECK(layer_tree_host_); | |
| 48 | |
| 49 LayerSettings settings; | |
| 50 settings.use_compositor_animation_timelines = | |
| 51 layer_tree_host_->settings().use_compositor_animation_timelines; | |
| 52 return settings; | |
| 53 } | |
| 54 | |
| 55 scoped_ptr<FakeLayerTreeHost> layer_tree_host_; | 43 scoped_ptr<FakeLayerTreeHost> layer_tree_host_; |
| 56 LapTimer timer_; | 44 LapTimer timer_; |
| 57 | 45 |
| 58 TestTaskGraphRunner task_graph_runner_; | 46 TestTaskGraphRunner task_graph_runner_; |
| 59 FakeLayerTreeHostClient fake_client_; | 47 FakeLayerTreeHostClient fake_client_; |
| 60 }; | 48 }; |
| 61 | 49 |
| 62 TEST_F(AnimationHostPerfTest, PushPropertiesTo) { | 50 TEST_F(AnimationHostPerfTest, PushPropertiesTo) { |
| 63 if (!layer_tree_host_->settings().use_compositor_animation_timelines) | |
| 64 return; | |
| 65 | |
| 66 AnimationHost* host = layer_tree_host_->animation_host(); | 51 AnimationHost* host = layer_tree_host_->animation_host(); |
| 67 AnimationHost* host_impl = layer_tree_host_->host_impl()->animation_host(); | 52 AnimationHost* host_impl = layer_tree_host_->host_impl()->animation_host(); |
| 68 | 53 |
| 69 scoped_refptr<Layer> root_layer = Layer::Create(GetLayerSettings()); | 54 scoped_refptr<Layer> root_layer = Layer::Create(); |
| 70 layer_tree_host_->SetRootLayer(root_layer); | 55 layer_tree_host_->SetRootLayer(root_layer); |
| 71 | 56 |
| 72 scoped_ptr<LayerImpl> root_layer_impl = LayerImpl::Create( | 57 scoped_ptr<LayerImpl> root_layer_impl = LayerImpl::Create( |
| 73 layer_tree_host_->host_impl()->active_tree(), root_layer->id()); | 58 layer_tree_host_->host_impl()->active_tree(), root_layer->id()); |
| 74 | 59 |
| 75 scoped_refptr<AnimationTimeline> timeline = | 60 scoped_refptr<AnimationTimeline> timeline = |
| 76 AnimationTimeline::Create(AnimationIdProvider::NextTimelineId()); | 61 AnimationTimeline::Create(AnimationIdProvider::NextTimelineId()); |
| 77 host->AddAnimationTimeline(timeline); | 62 host->AddAnimationTimeline(timeline); |
| 78 | 63 |
| 79 scoped_refptr<AnimationTimeline> timeline_impl = | 64 scoped_refptr<AnimationTimeline> timeline_impl = |
| 80 timeline->CreateImplInstance(); | 65 timeline->CreateImplInstance(); |
| 81 host_impl->AddAnimationTimeline(timeline_impl); | 66 host_impl->AddAnimationTimeline(timeline_impl); |
| 82 | 67 |
| 83 for (int i = 0; i < kNumberOfAnimationPlayers; ++i) { | 68 for (int i = 0; i < kNumberOfAnimationPlayers; ++i) { |
| 84 scoped_refptr<Layer> layer = Layer::Create(GetLayerSettings()); | 69 scoped_refptr<Layer> layer = Layer::Create(); |
| 85 root_layer->AddChild(layer); | 70 root_layer->AddChild(layer); |
| 86 | 71 |
| 87 const int layer_id = layer->id(); | 72 const int layer_id = layer->id(); |
| 88 | 73 |
| 89 scoped_ptr<LayerImpl> layer_impl = LayerImpl::Create( | 74 scoped_ptr<LayerImpl> layer_impl = LayerImpl::Create( |
| 90 layer_tree_host_->host_impl()->active_tree(), layer_id); | 75 layer_tree_host_->host_impl()->active_tree(), layer_id); |
| 91 root_layer_impl->AddChild(std::move(layer_impl)); | 76 root_layer_impl->AddChild(std::move(layer_impl)); |
| 92 | 77 |
| 93 scoped_refptr<AnimationPlayer> player = | 78 scoped_refptr<AnimationPlayer> player = |
| 94 AnimationPlayer::Create(AnimationIdProvider::NextPlayerId()); | 79 AnimationPlayer::Create(AnimationIdProvider::NextPlayerId()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 106 do { | 91 do { |
| 107 host->PushPropertiesTo(host_impl); | 92 host->PushPropertiesTo(host_impl); |
| 108 timer_.NextLap(); | 93 timer_.NextLap(); |
| 109 } while (!timer_.HasTimeLimitExpired()); | 94 } while (!timer_.HasTimeLimitExpired()); |
| 110 | 95 |
| 111 perf_test::PrintResult("push_properties_to", "", "", timer_.LapsPerSecond(), | 96 perf_test::PrintResult("push_properties_to", "", "", timer_.LapsPerSecond(), |
| 112 "runs/s", true); | 97 "runs/s", true); |
| 113 } | 98 } |
| 114 | 99 |
| 115 } // namespace cc | 100 } // namespace cc |
| OLD | NEW |