OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/debug/micro_benchmark_controller.h" |
| 6 |
| 7 #include <memory> |
| 8 |
5 #include "base/callback.h" | 9 #include "base/callback.h" |
6 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/ptr_util.h" |
7 #include "cc/debug/micro_benchmark.h" | 11 #include "cc/debug/micro_benchmark.h" |
8 #include "cc/debug/micro_benchmark_controller.h" | |
9 #include "cc/layers/layer.h" | 12 #include "cc/layers/layer.h" |
10 #include "cc/test/fake_impl_task_runner_provider.h" | 13 #include "cc/test/fake_impl_task_runner_provider.h" |
11 #include "cc/test/fake_layer_tree_host.h" | 14 #include "cc/test/fake_layer_tree_host.h" |
12 #include "cc/test/fake_layer_tree_host_impl.h" | 15 #include "cc/test/fake_layer_tree_host_impl.h" |
13 #include "cc/test/fake_proxy.h" | 16 #include "cc/test/fake_proxy.h" |
14 #include "cc/test/test_task_graph_runner.h" | 17 #include "cc/test/test_task_graph_runner.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
16 | 19 |
17 namespace cc { | 20 namespace cc { |
18 namespace { | 21 namespace { |
19 | 22 |
20 class MicroBenchmarkControllerTest : public testing::Test { | 23 class MicroBenchmarkControllerTest : public testing::Test { |
21 public: | 24 public: |
22 MicroBenchmarkControllerTest() | 25 MicroBenchmarkControllerTest() |
23 : layer_tree_host_client_(FakeLayerTreeHostClient::DIRECT_3D) {} | 26 : layer_tree_host_client_(FakeLayerTreeHostClient::DIRECT_3D) {} |
24 | 27 |
25 void SetUp() override { | 28 void SetUp() override { |
26 impl_task_runner_provider_ = | 29 impl_task_runner_provider_ = |
27 make_scoped_ptr(new FakeImplTaskRunnerProvider); | 30 base::WrapUnique(new FakeImplTaskRunnerProvider); |
28 layer_tree_host_impl_ = make_scoped_ptr(new FakeLayerTreeHostImpl( | 31 layer_tree_host_impl_ = base::WrapUnique(new FakeLayerTreeHostImpl( |
29 impl_task_runner_provider_.get(), &shared_bitmap_manager_, | 32 impl_task_runner_provider_.get(), &shared_bitmap_manager_, |
30 &task_graph_runner_)); | 33 &task_graph_runner_)); |
31 | 34 |
32 layer_tree_host_ = FakeLayerTreeHost::Create(&layer_tree_host_client_, | 35 layer_tree_host_ = FakeLayerTreeHost::Create(&layer_tree_host_client_, |
33 &task_graph_runner_); | 36 &task_graph_runner_); |
34 layer_tree_host_->SetRootLayer(Layer::Create()); | 37 layer_tree_host_->SetRootLayer(Layer::Create()); |
35 layer_tree_host_->InitializeForTesting( | 38 layer_tree_host_->InitializeForTesting( |
36 TaskRunnerProvider::Create(nullptr, nullptr), | 39 TaskRunnerProvider::Create(nullptr, nullptr), |
37 scoped_ptr<Proxy>(new FakeProxy), nullptr); | 40 std::unique_ptr<Proxy>(new FakeProxy), nullptr); |
38 } | 41 } |
39 | 42 |
40 void TearDown() override { | 43 void TearDown() override { |
41 layer_tree_host_impl_ = nullptr; | 44 layer_tree_host_impl_ = nullptr; |
42 layer_tree_host_ = nullptr; | 45 layer_tree_host_ = nullptr; |
43 impl_task_runner_provider_ = nullptr; | 46 impl_task_runner_provider_ = nullptr; |
44 } | 47 } |
45 | 48 |
46 FakeLayerTreeHostClient layer_tree_host_client_; | 49 FakeLayerTreeHostClient layer_tree_host_client_; |
47 TestTaskGraphRunner task_graph_runner_; | 50 TestTaskGraphRunner task_graph_runner_; |
48 TestSharedBitmapManager shared_bitmap_manager_; | 51 TestSharedBitmapManager shared_bitmap_manager_; |
49 scoped_ptr<FakeLayerTreeHost> layer_tree_host_; | 52 std::unique_ptr<FakeLayerTreeHost> layer_tree_host_; |
50 scoped_ptr<FakeLayerTreeHostImpl> layer_tree_host_impl_; | 53 std::unique_ptr<FakeLayerTreeHostImpl> layer_tree_host_impl_; |
51 scoped_ptr<FakeImplTaskRunnerProvider> impl_task_runner_provider_; | 54 std::unique_ptr<FakeImplTaskRunnerProvider> impl_task_runner_provider_; |
52 }; | 55 }; |
53 | 56 |
54 void Noop(scoped_ptr<base::Value> value) { | 57 void Noop(std::unique_ptr<base::Value> value) {} |
55 } | |
56 | 58 |
57 void IncrementCallCount(int* count, scoped_ptr<base::Value> value) { | 59 void IncrementCallCount(int* count, std::unique_ptr<base::Value> value) { |
58 ++(*count); | 60 ++(*count); |
59 } | 61 } |
60 | 62 |
61 TEST_F(MicroBenchmarkControllerTest, ScheduleFail) { | 63 TEST_F(MicroBenchmarkControllerTest, ScheduleFail) { |
62 int id = layer_tree_host_->ScheduleMicroBenchmark( | 64 int id = layer_tree_host_->ScheduleMicroBenchmark( |
63 "non_existant_benchmark", nullptr, base::Bind(&Noop)); | 65 "non_existant_benchmark", nullptr, base::Bind(&Noop)); |
64 EXPECT_EQ(id, 0); | 66 EXPECT_EQ(id, 0); |
65 } | 67 } |
66 | 68 |
67 TEST_F(MicroBenchmarkControllerTest, CommitScheduled) { | 69 TEST_F(MicroBenchmarkControllerTest, CommitScheduled) { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 | 119 |
118 layer_tree_host_->UpdateLayers(); | 120 layer_tree_host_->UpdateLayers(); |
119 EXPECT_EQ(4, run_count); | 121 EXPECT_EQ(4, run_count); |
120 | 122 |
121 layer_tree_host_->UpdateLayers(); | 123 layer_tree_host_->UpdateLayers(); |
122 EXPECT_EQ(4, run_count); | 124 EXPECT_EQ(4, run_count); |
123 } | 125 } |
124 | 126 |
125 TEST_F(MicroBenchmarkControllerTest, BenchmarkImplRan) { | 127 TEST_F(MicroBenchmarkControllerTest, BenchmarkImplRan) { |
126 int run_count = 0; | 128 int run_count = 0; |
127 scoped_ptr<base::DictionaryValue> settings(new base::DictionaryValue); | 129 std::unique_ptr<base::DictionaryValue> settings(new base::DictionaryValue); |
128 settings->SetBoolean("run_benchmark_impl", true); | 130 settings->SetBoolean("run_benchmark_impl", true); |
129 | 131 |
130 // Schedule a main thread benchmark. | 132 // Schedule a main thread benchmark. |
131 int id = layer_tree_host_->ScheduleMicroBenchmark( | 133 int id = layer_tree_host_->ScheduleMicroBenchmark( |
132 "unittest_only_benchmark", std::move(settings), | 134 "unittest_only_benchmark", std::move(settings), |
133 base::Bind(&IncrementCallCount, base::Unretained(&run_count))); | 135 base::Bind(&IncrementCallCount, base::Unretained(&run_count))); |
134 EXPECT_GT(id, 0); | 136 EXPECT_GT(id, 0); |
135 | 137 |
136 // Schedule impl benchmarks. In production code, this is run in commit. | 138 // Schedule impl benchmarks. In production code, this is run in commit. |
137 layer_tree_host_->GetMicroBenchmarkController()->ScheduleImplBenchmarks( | 139 layer_tree_host_->GetMicroBenchmarkController()->ScheduleImplBenchmarks( |
138 layer_tree_host_impl_.get()); | 140 layer_tree_host_impl_.get()); |
139 | 141 |
140 // Now complete the commit (as if on the impl thread). | 142 // Now complete the commit (as if on the impl thread). |
141 layer_tree_host_impl_->CommitComplete(); | 143 layer_tree_host_impl_->CommitComplete(); |
142 | 144 |
143 // Make sure all posted messages run. | 145 // Make sure all posted messages run. |
144 base::MessageLoop::current()->RunUntilIdle(); | 146 base::MessageLoop::current()->RunUntilIdle(); |
145 | 147 |
146 EXPECT_EQ(1, run_count); | 148 EXPECT_EQ(1, run_count); |
147 } | 149 } |
148 | 150 |
149 TEST_F(MicroBenchmarkControllerTest, SendMessage) { | 151 TEST_F(MicroBenchmarkControllerTest, SendMessage) { |
150 // Send valid message to invalid benchmark (id = 0) | 152 // Send valid message to invalid benchmark (id = 0) |
151 scoped_ptr<base::DictionaryValue> message(new base::DictionaryValue); | 153 std::unique_ptr<base::DictionaryValue> message(new base::DictionaryValue); |
152 message->SetBoolean("can_handle", true); | 154 message->SetBoolean("can_handle", true); |
153 bool message_handled = | 155 bool message_handled = |
154 layer_tree_host_->SendMessageToMicroBenchmark(0, std::move(message)); | 156 layer_tree_host_->SendMessageToMicroBenchmark(0, std::move(message)); |
155 EXPECT_FALSE(message_handled); | 157 EXPECT_FALSE(message_handled); |
156 | 158 |
157 // Schedule a benchmark | 159 // Schedule a benchmark |
158 int run_count = 0; | 160 int run_count = 0; |
159 int id = layer_tree_host_->ScheduleMicroBenchmark( | 161 int id = layer_tree_host_->ScheduleMicroBenchmark( |
160 "unittest_only_benchmark", | 162 "unittest_only_benchmark", |
161 nullptr, | 163 nullptr, |
162 base::Bind(&IncrementCallCount, base::Unretained(&run_count))); | 164 base::Bind(&IncrementCallCount, base::Unretained(&run_count))); |
163 EXPECT_GT(id, 0); | 165 EXPECT_GT(id, 0); |
164 | 166 |
165 // Send valid message to valid benchmark | 167 // Send valid message to valid benchmark |
166 message = make_scoped_ptr(new base::DictionaryValue); | 168 message = base::WrapUnique(new base::DictionaryValue); |
167 message->SetBoolean("can_handle", true); | 169 message->SetBoolean("can_handle", true); |
168 message_handled = | 170 message_handled = |
169 layer_tree_host_->SendMessageToMicroBenchmark(id, std::move(message)); | 171 layer_tree_host_->SendMessageToMicroBenchmark(id, std::move(message)); |
170 EXPECT_TRUE(message_handled); | 172 EXPECT_TRUE(message_handled); |
171 | 173 |
172 // Send invalid message to valid benchmark | 174 // Send invalid message to valid benchmark |
173 message = make_scoped_ptr(new base::DictionaryValue); | 175 message = base::WrapUnique(new base::DictionaryValue); |
174 message->SetBoolean("can_handle", false); | 176 message->SetBoolean("can_handle", false); |
175 message_handled = | 177 message_handled = |
176 layer_tree_host_->SendMessageToMicroBenchmark(id, std::move(message)); | 178 layer_tree_host_->SendMessageToMicroBenchmark(id, std::move(message)); |
177 EXPECT_FALSE(message_handled); | 179 EXPECT_FALSE(message_handled); |
178 } | 180 } |
179 | 181 |
180 } // namespace | 182 } // namespace |
181 } // namespace cc | 183 } // namespace cc |
OLD | NEW |