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 <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 | 7 |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "base/test/test_simple_task_runner.h" | 10 #include "base/test/test_simple_task_runner.h" |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 static const int kTimeCheckInterval = 10; | 122 static const int kTimeCheckInterval = 10; |
123 | 123 |
124 class PerfImageDecodeTaskImpl : public TileTask { | 124 class PerfImageDecodeTaskImpl : public TileTask { |
125 public: | 125 public: |
126 PerfImageDecodeTaskImpl() : TileTask(true) {} | 126 PerfImageDecodeTaskImpl() : TileTask(true) {} |
127 | 127 |
128 // Overridden from Task: | 128 // Overridden from Task: |
129 void RunOnWorkerThread() override {} | 129 void RunOnWorkerThread() override {} |
130 | 130 |
131 // Overridden from TileTask: | 131 // Overridden from TileTask: |
132 void ScheduleOnOriginThread(RasterBufferProvider* provider) override {} | 132 void OnTaskCompleted() override { state().Reset(); } |
133 void CompleteOnOriginThread(RasterBufferProvider* provider) override { | |
134 Reset(); | |
135 } | |
136 | |
137 void Reset() { | |
138 state().Reset(); | |
139 did_complete_ = false; | |
140 } | |
141 | 133 |
142 protected: | 134 protected: |
143 ~PerfImageDecodeTaskImpl() override {} | 135 ~PerfImageDecodeTaskImpl() override {} |
144 | 136 |
145 private: | 137 private: |
146 DISALLOW_COPY_AND_ASSIGN(PerfImageDecodeTaskImpl); | 138 DISALLOW_COPY_AND_ASSIGN(PerfImageDecodeTaskImpl); |
147 }; | 139 }; |
148 | 140 |
| 141 class PerfRasterBufferProviderHelper { |
| 142 public: |
| 143 virtual std::unique_ptr<RasterBuffer> AcquireBufferForRaster( |
| 144 const Resource* resource, |
| 145 uint64_t resource_content_id, |
| 146 uint64_t previous_content_id) = 0; |
| 147 virtual void ReleaseBufferForRaster(std::unique_ptr<RasterBuffer> buffer) = 0; |
| 148 }; |
| 149 |
149 class PerfRasterTaskImpl : public TileTask { | 150 class PerfRasterTaskImpl : public TileTask { |
150 public: | 151 public: |
151 PerfRasterTaskImpl(std::unique_ptr<ScopedResource> resource, | 152 PerfRasterTaskImpl(PerfRasterBufferProviderHelper* helper, |
| 153 std::unique_ptr<ScopedResource> resource, |
| 154 std::unique_ptr<RasterBuffer> raster_buffer, |
152 TileTask::Vector* dependencies) | 155 TileTask::Vector* dependencies) |
153 : TileTask(true, dependencies), resource_(std::move(resource)) {} | 156 : TileTask(true, dependencies), |
| 157 helper_(helper), |
| 158 resource_(std::move(resource)), |
| 159 raster_buffer_(std::move(raster_buffer)) {} |
154 | 160 |
155 // Overridden from Task: | 161 // Overridden from Task: |
156 void RunOnWorkerThread() override {} | 162 void RunOnWorkerThread() override {} |
157 | 163 |
158 // Overridden from TileTask: | 164 // Overridden from TileTask: |
159 void ScheduleOnOriginThread(RasterBufferProvider* provider) override { | 165 void OnTaskCompleted() override { |
160 // No tile ids are given to support partial updates. | 166 if (helper_) |
161 raster_buffer_ = provider->AcquireBufferForRaster(resource_.get(), 0, 0); | 167 helper_->ReleaseBufferForRaster(std::move(raster_buffer_)); |
162 } | |
163 void CompleteOnOriginThread(RasterBufferProvider* provider) override { | |
164 provider->ReleaseBufferForRaster(std::move(raster_buffer_)); | |
165 Reset(); | |
166 } | |
167 | 168 |
168 void Reset() { | |
169 state().Reset(); | 169 state().Reset(); |
170 did_complete_ = false; | |
171 } | 170 } |
172 | 171 |
173 protected: | 172 protected: |
174 ~PerfRasterTaskImpl() override {} | 173 ~PerfRasterTaskImpl() override {} |
175 | 174 |
176 private: | 175 private: |
| 176 PerfRasterBufferProviderHelper* helper_; |
177 std::unique_ptr<ScopedResource> resource_; | 177 std::unique_ptr<ScopedResource> resource_; |
178 std::unique_ptr<RasterBuffer> raster_buffer_; | 178 std::unique_ptr<RasterBuffer> raster_buffer_; |
179 | 179 |
180 DISALLOW_COPY_AND_ASSIGN(PerfRasterTaskImpl); | 180 DISALLOW_COPY_AND_ASSIGN(PerfRasterTaskImpl); |
181 }; | 181 }; |
182 | 182 |
183 class RasterBufferProviderPerfTestBase { | 183 class RasterBufferProviderPerfTestBase { |
184 public: | 184 public: |
185 typedef std::vector<scoped_refptr<TileTask>> RasterTaskVector; | 185 typedef std::vector<scoped_refptr<TileTask>> RasterTaskVector; |
186 | 186 |
187 enum NamedTaskSet { REQUIRED_FOR_ACTIVATION, REQUIRED_FOR_DRAW, ALL }; | 187 enum NamedTaskSet { REQUIRED_FOR_ACTIVATION, REQUIRED_FOR_DRAW, ALL }; |
188 | 188 |
189 RasterBufferProviderPerfTestBase() | 189 RasterBufferProviderPerfTestBase() |
190 : context_provider_(make_scoped_refptr(new PerfContextProvider)), | 190 : context_provider_(make_scoped_refptr(new PerfContextProvider)), |
191 task_runner_(new base::TestSimpleTaskRunner), | 191 task_runner_(new base::TestSimpleTaskRunner), |
192 task_graph_runner_(new SynchronousTaskGraphRunner), | 192 task_graph_runner_(new SynchronousTaskGraphRunner), |
193 timer_(kWarmupRuns, | 193 timer_(kWarmupRuns, |
194 base::TimeDelta::FromMilliseconds(kTimeLimitMillis), | 194 base::TimeDelta::FromMilliseconds(kTimeLimitMillis), |
195 kTimeCheckInterval) {} | 195 kTimeCheckInterval) {} |
196 | 196 |
197 void CreateImageDecodeTasks(unsigned num_image_decode_tasks, | 197 void CreateImageDecodeTasks(unsigned num_image_decode_tasks, |
198 TileTask::Vector* image_decode_tasks) { | 198 TileTask::Vector* image_decode_tasks) { |
199 for (unsigned i = 0; i < num_image_decode_tasks; ++i) | 199 for (unsigned i = 0; i < num_image_decode_tasks; ++i) |
200 image_decode_tasks->push_back(new PerfImageDecodeTaskImpl); | 200 image_decode_tasks->push_back(new PerfImageDecodeTaskImpl); |
201 } | 201 } |
202 | 202 |
203 void CreateRasterTasks(unsigned num_raster_tasks, | 203 void CreateRasterTasks(PerfRasterBufferProviderHelper* helper, |
| 204 unsigned num_raster_tasks, |
204 const TileTask::Vector& image_decode_tasks, | 205 const TileTask::Vector& image_decode_tasks, |
205 RasterTaskVector* raster_tasks) { | 206 RasterTaskVector* raster_tasks) { |
206 const gfx::Size size(1, 1); | 207 const gfx::Size size(1, 1); |
207 | 208 |
208 for (unsigned i = 0; i < num_raster_tasks; ++i) { | 209 for (unsigned i = 0; i < num_raster_tasks; ++i) { |
209 std::unique_ptr<ScopedResource> resource( | 210 std::unique_ptr<ScopedResource> resource( |
210 ScopedResource::Create(resource_provider_.get())); | 211 ScopedResource::Create(resource_provider_.get())); |
211 resource->Allocate(size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, | 212 resource->Allocate(size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, |
212 RGBA_8888); | 213 RGBA_8888); |
213 | 214 |
| 215 // No tile ids are given to support partial updates. |
| 216 std::unique_ptr<RasterBuffer> raster_buffer; |
| 217 if (helper) |
| 218 raster_buffer = helper->AcquireBufferForRaster(resource.get(), 0, 0); |
214 TileTask::Vector dependencies = image_decode_tasks; | 219 TileTask::Vector dependencies = image_decode_tasks; |
215 raster_tasks->push_back( | 220 raster_tasks->push_back( |
216 new PerfRasterTaskImpl(std::move(resource), &dependencies)); | 221 new PerfRasterTaskImpl(helper, std::move(resource), |
| 222 std::move(raster_buffer), &dependencies)); |
217 } | 223 } |
218 } | 224 } |
219 | 225 |
220 void BuildTileTaskGraph(TaskGraph* graph, | 226 void BuildTileTaskGraph(TaskGraph* graph, |
221 const RasterTaskVector& raster_tasks) { | 227 const RasterTaskVector& raster_tasks) { |
222 uint16_t priority = 0; | 228 uint16_t priority = 0; |
223 | 229 |
224 for (auto& raster_task : raster_tasks) { | 230 for (auto& raster_task : raster_tasks) { |
225 priority++; | 231 priority++; |
226 | 232 |
(...skipping 25 matching lines...) Expand all Loading... |
252 FakeOutputSurfaceClient output_surface_client_; | 258 FakeOutputSurfaceClient output_surface_client_; |
253 std::unique_ptr<FakeOutputSurface> output_surface_; | 259 std::unique_ptr<FakeOutputSurface> output_surface_; |
254 std::unique_ptr<ResourceProvider> resource_provider_; | 260 std::unique_ptr<ResourceProvider> resource_provider_; |
255 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; | 261 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; |
256 std::unique_ptr<SynchronousTaskGraphRunner> task_graph_runner_; | 262 std::unique_ptr<SynchronousTaskGraphRunner> task_graph_runner_; |
257 LapTimer timer_; | 263 LapTimer timer_; |
258 }; | 264 }; |
259 | 265 |
260 class RasterBufferProviderPerfTest | 266 class RasterBufferProviderPerfTest |
261 : public RasterBufferProviderPerfTestBase, | 267 : public RasterBufferProviderPerfTestBase, |
| 268 public PerfRasterBufferProviderHelper, |
262 public testing::TestWithParam<RasterBufferProviderType> { | 269 public testing::TestWithParam<RasterBufferProviderType> { |
263 public: | 270 public: |
264 // Overridden from testing::Test: | 271 // Overridden from testing::Test: |
265 void SetUp() override { | 272 void SetUp() override { |
266 std::unique_ptr<RasterBufferProvider> raster_buffer_provider; | 273 std::unique_ptr<RasterBufferProvider> raster_buffer_provider; |
267 switch (GetParam()) { | 274 switch (GetParam()) { |
268 case RASTER_BUFFER_PROVIDER_TYPE_ZERO_COPY: | 275 case RASTER_BUFFER_PROVIDER_TYPE_ZERO_COPY: |
269 Create3dOutputSurfaceAndResourceProvider(); | 276 Create3dOutputSurfaceAndResourceProvider(); |
270 raster_buffer_provider = ZeroCopyRasterBufferProvider::Create( | 277 raster_buffer_provider = ZeroCopyRasterBufferProvider::Create( |
271 resource_provider_.get(), PlatformColor::BestTextureFormat()); | 278 resource_provider_.get(), PlatformColor::BestTextureFormat()); |
(...skipping 21 matching lines...) Expand all Loading... |
293 DCHECK(raster_buffer_provider); | 300 DCHECK(raster_buffer_provider); |
294 | 301 |
295 tile_task_manager_ = TileTaskManagerImpl::Create( | 302 tile_task_manager_ = TileTaskManagerImpl::Create( |
296 std::move(raster_buffer_provider), task_graph_runner_.get()); | 303 std::move(raster_buffer_provider), task_graph_runner_.get()); |
297 } | 304 } |
298 void TearDown() override { | 305 void TearDown() override { |
299 tile_task_manager_->Shutdown(); | 306 tile_task_manager_->Shutdown(); |
300 tile_task_manager_->CheckForCompletedTasks(); | 307 tile_task_manager_->CheckForCompletedTasks(); |
301 } | 308 } |
302 | 309 |
| 310 // Overridden from PerfRasterBufferProviderHelper: |
| 311 std::unique_ptr<RasterBuffer> AcquireBufferForRaster( |
| 312 const Resource* resource, |
| 313 uint64_t resource_content_id, |
| 314 uint64_t previous_content_id) override { |
| 315 return tile_task_manager_->GetRasterBufferProvider() |
| 316 ->AcquireBufferForRaster(resource, resource_content_id, |
| 317 previous_content_id); |
| 318 } |
| 319 void ReleaseBufferForRaster(std::unique_ptr<RasterBuffer> buffer) override { |
| 320 tile_task_manager_->GetRasterBufferProvider()->ReleaseBufferForRaster( |
| 321 std::move(buffer)); |
| 322 } |
| 323 |
303 void RunMessageLoopUntilAllTasksHaveCompleted() { | 324 void RunMessageLoopUntilAllTasksHaveCompleted() { |
304 task_graph_runner_->RunUntilIdle(); | 325 task_graph_runner_->RunUntilIdle(); |
305 task_runner_->RunUntilIdle(); | 326 task_runner_->RunUntilIdle(); |
306 } | 327 } |
307 | 328 |
308 void RunScheduleTasksTest(const std::string& test_name, | 329 void RunScheduleTasksTest(const std::string& test_name, |
309 unsigned num_raster_tasks, | 330 unsigned num_raster_tasks, |
310 unsigned num_image_decode_tasks) { | 331 unsigned num_image_decode_tasks) { |
311 TileTask::Vector image_decode_tasks; | 332 TileTask::Vector image_decode_tasks; |
312 RasterTaskVector raster_tasks; | 333 RasterTaskVector raster_tasks; |
313 CreateImageDecodeTasks(num_image_decode_tasks, &image_decode_tasks); | 334 CreateImageDecodeTasks(num_image_decode_tasks, &image_decode_tasks); |
314 CreateRasterTasks(num_raster_tasks, image_decode_tasks, &raster_tasks); | 335 CreateRasterTasks(this, num_raster_tasks, image_decode_tasks, |
| 336 &raster_tasks); |
315 | 337 |
316 // Avoid unnecessary heap allocations by reusing the same graph. | 338 // Avoid unnecessary heap allocations by reusing the same graph. |
317 TaskGraph graph; | 339 TaskGraph graph; |
318 | 340 |
319 timer_.Reset(); | 341 timer_.Reset(); |
320 do { | 342 do { |
321 graph.Reset(); | 343 graph.Reset(); |
322 BuildTileTaskGraph(&graph, raster_tasks); | 344 BuildTileTaskGraph(&graph, raster_tasks); |
323 tile_task_manager_->ScheduleTasks(&graph); | 345 tile_task_manager_->ScheduleTasks(&graph); |
324 tile_task_manager_->CheckForCompletedTasks(); | 346 tile_task_manager_->CheckForCompletedTasks(); |
325 timer_.NextLap(); | 347 timer_.NextLap(); |
326 } while (!timer_.HasTimeLimitExpired()); | 348 } while (!timer_.HasTimeLimitExpired()); |
327 | 349 |
328 TaskGraph empty; | 350 TaskGraph empty; |
329 tile_task_manager_->ScheduleTasks(&empty); | 351 tile_task_manager_->ScheduleTasks(&empty); |
330 RunMessageLoopUntilAllTasksHaveCompleted(); | 352 RunMessageLoopUntilAllTasksHaveCompleted(); |
331 | 353 |
332 perf_test::PrintResult("schedule_tasks", TestModifierString(), test_name, | 354 perf_test::PrintResult("schedule_tasks", TestModifierString(), test_name, |
333 timer_.LapsPerSecond(), "runs/s", true); | 355 timer_.LapsPerSecond(), "runs/s", true); |
334 } | 356 } |
335 | 357 |
336 void RunScheduleAlternateTasksTest(const std::string& test_name, | 358 void RunScheduleAlternateTasksTest(const std::string& test_name, |
337 unsigned num_raster_tasks, | 359 unsigned num_raster_tasks, |
338 unsigned num_image_decode_tasks) { | 360 unsigned num_image_decode_tasks) { |
339 const size_t kNumVersions = 2; | 361 const size_t kNumVersions = 2; |
340 TileTask::Vector image_decode_tasks[kNumVersions]; | 362 TileTask::Vector image_decode_tasks[kNumVersions]; |
341 RasterTaskVector raster_tasks[kNumVersions]; | 363 RasterTaskVector raster_tasks[kNumVersions]; |
342 for (size_t i = 0; i < kNumVersions; ++i) { | 364 for (size_t i = 0; i < kNumVersions; ++i) { |
343 CreateImageDecodeTasks(num_image_decode_tasks, &image_decode_tasks[i]); | 365 CreateImageDecodeTasks(num_image_decode_tasks, &image_decode_tasks[i]); |
344 CreateRasterTasks(num_raster_tasks, image_decode_tasks[i], | 366 CreateRasterTasks(this, num_raster_tasks, image_decode_tasks[i], |
345 &raster_tasks[i]); | 367 &raster_tasks[i]); |
346 } | 368 } |
347 | 369 |
348 // Avoid unnecessary heap allocations by reusing the same graph. | 370 // Avoid unnecessary heap allocations by reusing the same graph. |
349 TaskGraph graph; | 371 TaskGraph graph; |
350 | 372 |
351 size_t count = 0; | 373 size_t count = 0; |
352 timer_.Reset(); | 374 timer_.Reset(); |
353 do { | 375 do { |
354 graph.Reset(); | 376 graph.Reset(); |
(...skipping 11 matching lines...) Expand all Loading... |
366 perf_test::PrintResult("schedule_alternate_tasks", TestModifierString(), | 388 perf_test::PrintResult("schedule_alternate_tasks", TestModifierString(), |
367 test_name, timer_.LapsPerSecond(), "runs/s", true); | 389 test_name, timer_.LapsPerSecond(), "runs/s", true); |
368 } | 390 } |
369 | 391 |
370 void RunScheduleAndExecuteTasksTest(const std::string& test_name, | 392 void RunScheduleAndExecuteTasksTest(const std::string& test_name, |
371 unsigned num_raster_tasks, | 393 unsigned num_raster_tasks, |
372 unsigned num_image_decode_tasks) { | 394 unsigned num_image_decode_tasks) { |
373 TileTask::Vector image_decode_tasks; | 395 TileTask::Vector image_decode_tasks; |
374 RasterTaskVector raster_tasks; | 396 RasterTaskVector raster_tasks; |
375 CreateImageDecodeTasks(num_image_decode_tasks, &image_decode_tasks); | 397 CreateImageDecodeTasks(num_image_decode_tasks, &image_decode_tasks); |
376 CreateRasterTasks(num_raster_tasks, image_decode_tasks, &raster_tasks); | 398 CreateRasterTasks(this, num_raster_tasks, image_decode_tasks, |
| 399 &raster_tasks); |
377 | 400 |
378 // Avoid unnecessary heap allocations by reusing the same graph. | 401 // Avoid unnecessary heap allocations by reusing the same graph. |
379 TaskGraph graph; | 402 TaskGraph graph; |
380 | 403 |
381 timer_.Reset(); | 404 timer_.Reset(); |
382 do { | 405 do { |
383 graph.Reset(); | 406 graph.Reset(); |
384 BuildTileTaskGraph(&graph, raster_tasks); | 407 BuildTileTaskGraph(&graph, raster_tasks); |
385 tile_task_manager_->ScheduleTasks(&graph); | 408 tile_task_manager_->ScheduleTasks(&graph); |
386 RunMessageLoopUntilAllTasksHaveCompleted(); | 409 RunMessageLoopUntilAllTasksHaveCompleted(); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 resource_provider_ = | 499 resource_provider_ = |
477 FakeResourceProvider::Create(output_surface_.get(), nullptr); | 500 FakeResourceProvider::Create(output_surface_.get(), nullptr); |
478 } | 501 } |
479 | 502 |
480 void RunBuildTileTaskGraphTest(const std::string& test_name, | 503 void RunBuildTileTaskGraphTest(const std::string& test_name, |
481 unsigned num_raster_tasks, | 504 unsigned num_raster_tasks, |
482 unsigned num_image_decode_tasks) { | 505 unsigned num_image_decode_tasks) { |
483 TileTask::Vector image_decode_tasks; | 506 TileTask::Vector image_decode_tasks; |
484 RasterTaskVector raster_tasks; | 507 RasterTaskVector raster_tasks; |
485 CreateImageDecodeTasks(num_image_decode_tasks, &image_decode_tasks); | 508 CreateImageDecodeTasks(num_image_decode_tasks, &image_decode_tasks); |
486 CreateRasterTasks(num_raster_tasks, image_decode_tasks, &raster_tasks); | 509 CreateRasterTasks(nullptr, num_raster_tasks, image_decode_tasks, |
| 510 &raster_tasks); |
487 | 511 |
488 // Avoid unnecessary heap allocations by reusing the same graph. | 512 // Avoid unnecessary heap allocations by reusing the same graph. |
489 TaskGraph graph; | 513 TaskGraph graph; |
490 | 514 |
491 timer_.Reset(); | 515 timer_.Reset(); |
492 do { | 516 do { |
493 graph.Reset(); | 517 graph.Reset(); |
494 BuildTileTaskGraph(&graph, raster_tasks); | 518 BuildTileTaskGraph(&graph, raster_tasks); |
495 timer_.NextLap(); | 519 timer_.NextLap(); |
496 } while (!timer_.HasTimeLimitExpired()); | 520 } while (!timer_.HasTimeLimitExpired()); |
497 | 521 |
498 perf_test::PrintResult("build_raster_task_graph", "", test_name, | 522 perf_test::PrintResult("build_raster_task_graph", "", test_name, |
499 timer_.LapsPerSecond(), "runs/s", true); | 523 timer_.LapsPerSecond(), "runs/s", true); |
500 } | 524 } |
501 }; | 525 }; |
502 | 526 |
503 TEST_F(RasterBufferProviderCommonPerfTest, BuildTileTaskGraph) { | 527 TEST_F(RasterBufferProviderCommonPerfTest, BuildTileTaskGraph) { |
504 RunBuildTileTaskGraphTest("1_0", 1, 0); | 528 RunBuildTileTaskGraphTest("1_0", 1, 0); |
505 RunBuildTileTaskGraphTest("32_0", 32, 0); | 529 RunBuildTileTaskGraphTest("32_0", 32, 0); |
506 RunBuildTileTaskGraphTest("1_1", 1, 1); | 530 RunBuildTileTaskGraphTest("1_1", 1, 1); |
507 RunBuildTileTaskGraphTest("32_1", 32, 1); | 531 RunBuildTileTaskGraphTest("32_1", 32, 1); |
508 RunBuildTileTaskGraphTest("1_4", 1, 4); | 532 RunBuildTileTaskGraphTest("1_4", 1, 4); |
509 RunBuildTileTaskGraphTest("32_4", 32, 4); | 533 RunBuildTileTaskGraphTest("32_4", 32, 4); |
510 } | 534 } |
511 | 535 |
512 } // namespace | 536 } // namespace |
513 } // namespace cc | 537 } // namespace cc |
OLD | NEW |