1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "cc/animation/animation_host.h"
#include "base/thread_task_runner_handle.h"
#include "cc/animation/animation_id_provider.h"
#include "cc/animation/animation_player.h"
#include "cc/animation/animation_timeline.h"
#include "cc/debug/lap_timer.h"
#include "cc/layers/layer.h"
#include "cc/test/fake_impl_task_runner_provider.h"
#include "cc/test/fake_layer_tree_host.h"
#include "cc/test/fake_layer_tree_host_client.h"
#include "cc/test/fake_layer_tree_host_impl.h"
#include "cc/test/test_task_graph_runner.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/perf/perf_test.h"
namespace cc {
static const int kNumberOfAnimationPlayers = 1000;
class AnimationHostPerfTest : public testing::Test {
public:
AnimationHostPerfTest() : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {}
protected:
void SetUp() override {
LayerTreeSettings settings;
layer_tree_host_ =
FakeLayerTreeHost::Create(&fake_client_, &task_graph_runner_, settings);
layer_tree_host_->InitializeSingleThreaded(
&fake_client_, base::ThreadTaskRunnerHandle::Get(), nullptr);
}
void TearDown() override {
layer_tree_host_->SetRootLayer(nullptr);
layer_tree_host_ = nullptr;
}
scoped_ptr<FakeLayerTreeHost> layer_tree_host_;
LapTimer timer_;
TestTaskGraphRunner task_graph_runner_;
FakeLayerTreeHostClient fake_client_;
};
TEST_F(AnimationHostPerfTest, PushPropertiesTo) {
AnimationHost* host = layer_tree_host_->animation_host();
AnimationHost* host_impl = layer_tree_host_->host_impl()->animation_host();
scoped_refptr<Layer> root_layer = Layer::Create();
layer_tree_host_->SetRootLayer(root_layer);
scoped_ptr<LayerImpl> root_layer_impl = LayerImpl::Create(
layer_tree_host_->host_impl()->active_tree(), root_layer->id());
scoped_refptr<AnimationTimeline> timeline =
AnimationTimeline::Create(AnimationIdProvider::NextTimelineId());
host->AddAnimationTimeline(timeline);
scoped_refptr<AnimationTimeline> timeline_impl =
timeline->CreateImplInstance();
host_impl->AddAnimationTimeline(timeline_impl);
for (int i = 0; i < kNumberOfAnimationPlayers; ++i) {
scoped_refptr<Layer> layer = Layer::Create();
root_layer->AddChild(layer);
const int layer_id = layer->id();
scoped_ptr<LayerImpl> layer_impl = LayerImpl::Create(
layer_tree_host_->host_impl()->active_tree(), layer_id);
root_layer_impl->AddChild(std::move(layer_impl));
scoped_refptr<AnimationPlayer> player =
AnimationPlayer::Create(AnimationIdProvider::NextPlayerId());
timeline->AttachPlayer(player);
player->AttachLayer(layer_id);
EXPECT_TRUE(player->element_animations());
scoped_refptr<AnimationPlayer> impl_player = player->CreateImplInstance();
timeline_impl->AttachPlayer(impl_player);
impl_player->AttachLayer(layer_id);
EXPECT_TRUE(impl_player->element_animations());
}
timer_.Reset();
do {
host->PushPropertiesTo(host_impl);
timer_.NextLap();
} while (!timer_.HasTimeLimitExpired());
perf_test::PrintResult("push_properties_to", "", "", timer_.LapsPerSecond(),
"runs/s", true);
}
} // namespace cc
|