| 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/raster/tile_task_worker_pool.h" | 5 #include "cc/raster/tile_task_worker_pool.h" |
| 6 | 6 |
| 7 #include "base/test/test_simple_task_runner.h" | 7 #include "base/test/test_simple_task_runner.h" |
| 8 #include "base/time/time.h" | 8 #include "base/time/time.h" |
| 9 #include "cc/debug/lap_timer.h" | 9 #include "cc/debug/lap_timer.h" |
| 10 #include "cc/output/context_provider.h" | 10 #include "cc/output/context_provider.h" |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 ScopedResource::Create(resource_provider_.get())); | 207 ScopedResource::Create(resource_provider_.get())); |
| 208 resource->Allocate(size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, | 208 resource->Allocate(size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, |
| 209 RGBA_8888); | 209 RGBA_8888); |
| 210 | 210 |
| 211 ImageDecodeTask::Vector dependencies = image_decode_tasks; | 211 ImageDecodeTask::Vector dependencies = image_decode_tasks; |
| 212 raster_tasks->push_back( | 212 raster_tasks->push_back( |
| 213 new PerfRasterTaskImpl(std::move(resource), &dependencies)); | 213 new PerfRasterTaskImpl(std::move(resource), &dependencies)); |
| 214 } | 214 } |
| 215 } | 215 } |
| 216 | 216 |
| 217 void BuildTileTaskQueue(TileTaskQueue* queue, | 217 void BuildTileTaskGraph(TaskGraph* graph, |
| 218 const RasterTaskVector& raster_tasks) { | 218 const RasterTaskVector& raster_tasks) { |
| 219 for (size_t i = 0u; i < raster_tasks.size(); ++i) { | 219 size_t priority = 0; |
| 220 bool required_for_activation = (i % 2) == 0; | 220 |
| 221 TaskSetCollection task_set_collection; | 221 for (auto& raster_task : raster_tasks) { |
| 222 task_set_collection[ALL] = true; | 222 priority++; |
| 223 task_set_collection[REQUIRED_FOR_ACTIVATION] = required_for_activation; | 223 |
| 224 queue->items.push_back( | 224 for (auto& decode_task : raster_task->dependencies()) { |
| 225 TileTaskQueue::Item(raster_tasks[i].get(), task_set_collection)); | 225 graph->nodes.push_back( |
| 226 TaskGraph::Node(decode_task.get(), priority, 0u)); |
| 227 graph->edges.push_back( |
| 228 TaskGraph::Edge(raster_task.get(), decode_task.get())); |
| 229 } |
| 230 |
| 231 graph->nodes.push_back(TaskGraph::Node( |
| 232 raster_task.get(), priority, raster_task->dependencies().size())); |
| 226 } | 233 } |
| 227 } | 234 } |
| 228 | 235 |
| 229 protected: | 236 protected: |
| 230 scoped_refptr<ContextProvider> context_provider_; | 237 scoped_refptr<ContextProvider> context_provider_; |
| 231 FakeOutputSurfaceClient output_surface_client_; | 238 FakeOutputSurfaceClient output_surface_client_; |
| 232 scoped_ptr<FakeOutputSurface> output_surface_; | 239 scoped_ptr<FakeOutputSurface> output_surface_; |
| 233 scoped_ptr<ResourceProvider> resource_provider_; | 240 scoped_ptr<ResourceProvider> resource_provider_; |
| 234 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; | 241 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; |
| 235 scoped_ptr<SynchronousTaskGraphRunner> task_graph_runner_; | 242 scoped_ptr<SynchronousTaskGraphRunner> task_graph_runner_; |
| 236 LapTimer timer_; | 243 LapTimer timer_; |
| 237 }; | 244 }; |
| 238 | 245 |
| 239 class TileTaskWorkerPoolPerfTest | 246 class TileTaskWorkerPoolPerfTest |
| 240 : public TileTaskWorkerPoolPerfTestBase, | 247 : public TileTaskWorkerPoolPerfTestBase, |
| 241 public testing::TestWithParam<TileTaskWorkerPoolType>, | 248 public testing::TestWithParam<TileTaskWorkerPoolType> { |
| 242 public TileTaskRunnerClient { | |
| 243 public: | 249 public: |
| 244 // Overridden from testing::Test: | 250 // Overridden from testing::Test: |
| 245 void SetUp() override { | 251 void SetUp() override { |
| 246 switch (GetParam()) { | 252 switch (GetParam()) { |
| 247 case TILE_TASK_WORKER_POOL_TYPE_ZERO_COPY: | 253 case TILE_TASK_WORKER_POOL_TYPE_ZERO_COPY: |
| 248 Create3dOutputSurfaceAndResourceProvider(); | 254 Create3dOutputSurfaceAndResourceProvider(); |
| 249 tile_task_worker_pool_ = ZeroCopyTileTaskWorkerPool::Create( | 255 tile_task_worker_pool_ = ZeroCopyTileTaskWorkerPool::Create( |
| 250 task_runner_.get(), task_graph_runner_.get(), | 256 task_runner_.get(), task_graph_runner_.get(), |
| 251 resource_provider_.get(), false); | 257 resource_provider_.get(), false); |
| 252 break; | 258 break; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 266 break; | 272 break; |
| 267 case TILE_TASK_WORKER_POOL_TYPE_BITMAP: | 273 case TILE_TASK_WORKER_POOL_TYPE_BITMAP: |
| 268 CreateSoftwareOutputSurfaceAndResourceProvider(); | 274 CreateSoftwareOutputSurfaceAndResourceProvider(); |
| 269 tile_task_worker_pool_ = BitmapTileTaskWorkerPool::Create( | 275 tile_task_worker_pool_ = BitmapTileTaskWorkerPool::Create( |
| 270 task_runner_.get(), task_graph_runner_.get(), | 276 task_runner_.get(), task_graph_runner_.get(), |
| 271 resource_provider_.get()); | 277 resource_provider_.get()); |
| 272 break; | 278 break; |
| 273 } | 279 } |
| 274 | 280 |
| 275 DCHECK(tile_task_worker_pool_); | 281 DCHECK(tile_task_worker_pool_); |
| 276 tile_task_worker_pool_->AsTileTaskRunner()->SetClient(this); | |
| 277 } | 282 } |
| 278 void TearDown() override { | 283 void TearDown() override { |
| 279 tile_task_worker_pool_->AsTileTaskRunner()->Shutdown(); | 284 tile_task_worker_pool_->AsTileTaskRunner()->Shutdown(); |
| 280 tile_task_worker_pool_->AsTileTaskRunner()->CheckForCompletedTasks(); | 285 tile_task_worker_pool_->AsTileTaskRunner()->CheckForCompletedTasks(); |
| 281 } | 286 } |
| 282 | 287 |
| 283 // Overriden from TileTaskRunnerClient: | |
| 284 void DidFinishRunningTileTasks(TaskSet task_set) override { | |
| 285 tile_task_worker_pool_->AsTileTaskRunner()->CheckForCompletedTasks(); | |
| 286 } | |
| 287 | |
| 288 void RunMessageLoopUntilAllTasksHaveCompleted() { | 288 void RunMessageLoopUntilAllTasksHaveCompleted() { |
| 289 task_graph_runner_->RunUntilIdle(); | 289 task_graph_runner_->RunUntilIdle(); |
| 290 task_runner_->RunUntilIdle(); | 290 task_runner_->RunUntilIdle(); |
| 291 } | 291 } |
| 292 | 292 |
| 293 void RunScheduleTasksTest(const std::string& test_name, | 293 void RunScheduleTasksTest(const std::string& test_name, |
| 294 unsigned num_raster_tasks, | 294 unsigned num_raster_tasks, |
| 295 unsigned num_image_decode_tasks) { | 295 unsigned num_image_decode_tasks) { |
| 296 ImageDecodeTask::Vector image_decode_tasks; | 296 ImageDecodeTask::Vector image_decode_tasks; |
| 297 RasterTaskVector raster_tasks; | 297 RasterTaskVector raster_tasks; |
| 298 CreateImageDecodeTasks(num_image_decode_tasks, &image_decode_tasks); | 298 CreateImageDecodeTasks(num_image_decode_tasks, &image_decode_tasks); |
| 299 CreateRasterTasks(num_raster_tasks, image_decode_tasks, &raster_tasks); | 299 CreateRasterTasks(num_raster_tasks, image_decode_tasks, &raster_tasks); |
| 300 | 300 |
| 301 // Avoid unnecessary heap allocations by reusing the same queue. | 301 // Avoid unnecessary heap allocations by reusing the same graph. |
| 302 TileTaskQueue queue; | 302 TaskGraph graph; |
| 303 | 303 |
| 304 timer_.Reset(); | 304 timer_.Reset(); |
| 305 do { | 305 do { |
| 306 queue.Reset(); | 306 graph.Reset(); |
| 307 BuildTileTaskQueue(&queue, raster_tasks); | 307 BuildTileTaskGraph(&graph, raster_tasks); |
| 308 tile_task_worker_pool_->AsTileTaskRunner()->ScheduleTasks(&queue); | 308 tile_task_worker_pool_->AsTileTaskRunner()->ScheduleTasks(&graph); |
| 309 tile_task_worker_pool_->AsTileTaskRunner()->CheckForCompletedTasks(); | 309 tile_task_worker_pool_->AsTileTaskRunner()->CheckForCompletedTasks(); |
| 310 timer_.NextLap(); | 310 timer_.NextLap(); |
| 311 } while (!timer_.HasTimeLimitExpired()); | 311 } while (!timer_.HasTimeLimitExpired()); |
| 312 | 312 |
| 313 TileTaskQueue empty; | 313 TaskGraph empty; |
| 314 tile_task_worker_pool_->AsTileTaskRunner()->ScheduleTasks(&empty); | 314 tile_task_worker_pool_->AsTileTaskRunner()->ScheduleTasks(&empty); |
| 315 RunMessageLoopUntilAllTasksHaveCompleted(); | 315 RunMessageLoopUntilAllTasksHaveCompleted(); |
| 316 | 316 |
| 317 perf_test::PrintResult("schedule_tasks", TestModifierString(), test_name, | 317 perf_test::PrintResult("schedule_tasks", TestModifierString(), test_name, |
| 318 timer_.LapsPerSecond(), "runs/s", true); | 318 timer_.LapsPerSecond(), "runs/s", true); |
| 319 } | 319 } |
| 320 | 320 |
| 321 void RunScheduleAlternateTasksTest(const std::string& test_name, | 321 void RunScheduleAlternateTasksTest(const std::string& test_name, |
| 322 unsigned num_raster_tasks, | 322 unsigned num_raster_tasks, |
| 323 unsigned num_image_decode_tasks) { | 323 unsigned num_image_decode_tasks) { |
| 324 const size_t kNumVersions = 2; | 324 const size_t kNumVersions = 2; |
| 325 ImageDecodeTask::Vector image_decode_tasks[kNumVersions]; | 325 ImageDecodeTask::Vector image_decode_tasks[kNumVersions]; |
| 326 RasterTaskVector raster_tasks[kNumVersions]; | 326 RasterTaskVector raster_tasks[kNumVersions]; |
| 327 for (size_t i = 0; i < kNumVersions; ++i) { | 327 for (size_t i = 0; i < kNumVersions; ++i) { |
| 328 CreateImageDecodeTasks(num_image_decode_tasks, &image_decode_tasks[i]); | 328 CreateImageDecodeTasks(num_image_decode_tasks, &image_decode_tasks[i]); |
| 329 CreateRasterTasks(num_raster_tasks, image_decode_tasks[i], | 329 CreateRasterTasks(num_raster_tasks, image_decode_tasks[i], |
| 330 &raster_tasks[i]); | 330 &raster_tasks[i]); |
| 331 } | 331 } |
| 332 | 332 |
| 333 // Avoid unnecessary heap allocations by reusing the same queue. | 333 // Avoid unnecessary heap allocations by reusing the same graph. |
| 334 TileTaskQueue queue; | 334 TaskGraph graph; |
| 335 | 335 |
| 336 size_t count = 0; | 336 size_t count = 0; |
| 337 timer_.Reset(); | 337 timer_.Reset(); |
| 338 do { | 338 do { |
| 339 queue.Reset(); | 339 graph.Reset(); |
| 340 BuildTileTaskQueue(&queue, raster_tasks[count % kNumVersions]); | 340 BuildTileTaskGraph(&graph, raster_tasks[count % kNumVersions]); |
| 341 tile_task_worker_pool_->AsTileTaskRunner()->ScheduleTasks(&queue); | 341 tile_task_worker_pool_->AsTileTaskRunner()->ScheduleTasks(&graph); |
| 342 tile_task_worker_pool_->AsTileTaskRunner()->CheckForCompletedTasks(); | 342 tile_task_worker_pool_->AsTileTaskRunner()->CheckForCompletedTasks(); |
| 343 ++count; | 343 ++count; |
| 344 timer_.NextLap(); | 344 timer_.NextLap(); |
| 345 } while (!timer_.HasTimeLimitExpired()); | 345 } while (!timer_.HasTimeLimitExpired()); |
| 346 | 346 |
| 347 TileTaskQueue empty; | 347 TaskGraph empty; |
| 348 tile_task_worker_pool_->AsTileTaskRunner()->ScheduleTasks(&empty); | 348 tile_task_worker_pool_->AsTileTaskRunner()->ScheduleTasks(&empty); |
| 349 RunMessageLoopUntilAllTasksHaveCompleted(); | 349 RunMessageLoopUntilAllTasksHaveCompleted(); |
| 350 | 350 |
| 351 perf_test::PrintResult("schedule_alternate_tasks", TestModifierString(), | 351 perf_test::PrintResult("schedule_alternate_tasks", TestModifierString(), |
| 352 test_name, timer_.LapsPerSecond(), "runs/s", true); | 352 test_name, timer_.LapsPerSecond(), "runs/s", true); |
| 353 } | 353 } |
| 354 | 354 |
| 355 void RunScheduleAndExecuteTasksTest(const std::string& test_name, | 355 void RunScheduleAndExecuteTasksTest(const std::string& test_name, |
| 356 unsigned num_raster_tasks, | 356 unsigned num_raster_tasks, |
| 357 unsigned num_image_decode_tasks) { | 357 unsigned num_image_decode_tasks) { |
| 358 ImageDecodeTask::Vector image_decode_tasks; | 358 ImageDecodeTask::Vector image_decode_tasks; |
| 359 RasterTaskVector raster_tasks; | 359 RasterTaskVector raster_tasks; |
| 360 CreateImageDecodeTasks(num_image_decode_tasks, &image_decode_tasks); | 360 CreateImageDecodeTasks(num_image_decode_tasks, &image_decode_tasks); |
| 361 CreateRasterTasks(num_raster_tasks, image_decode_tasks, &raster_tasks); | 361 CreateRasterTasks(num_raster_tasks, image_decode_tasks, &raster_tasks); |
| 362 | 362 |
| 363 // Avoid unnecessary heap allocations by reusing the same queue. | 363 // Avoid unnecessary heap allocations by reusing the same graph. |
| 364 TileTaskQueue queue; | 364 TaskGraph graph; |
| 365 | 365 |
| 366 timer_.Reset(); | 366 timer_.Reset(); |
| 367 do { | 367 do { |
| 368 queue.Reset(); | 368 graph.Reset(); |
| 369 BuildTileTaskQueue(&queue, raster_tasks); | 369 BuildTileTaskGraph(&graph, raster_tasks); |
| 370 tile_task_worker_pool_->AsTileTaskRunner()->ScheduleTasks(&queue); | 370 tile_task_worker_pool_->AsTileTaskRunner()->ScheduleTasks(&graph); |
| 371 RunMessageLoopUntilAllTasksHaveCompleted(); | 371 RunMessageLoopUntilAllTasksHaveCompleted(); |
| 372 timer_.NextLap(); | 372 timer_.NextLap(); |
| 373 } while (!timer_.HasTimeLimitExpired()); | 373 } while (!timer_.HasTimeLimitExpired()); |
| 374 | 374 |
| 375 TileTaskQueue empty; | 375 TaskGraph empty; |
| 376 tile_task_worker_pool_->AsTileTaskRunner()->ScheduleTasks(&empty); | 376 tile_task_worker_pool_->AsTileTaskRunner()->ScheduleTasks(&empty); |
| 377 RunMessageLoopUntilAllTasksHaveCompleted(); | 377 RunMessageLoopUntilAllTasksHaveCompleted(); |
| 378 | 378 |
| 379 perf_test::PrintResult("schedule_and_execute_tasks", TestModifierString(), | 379 perf_test::PrintResult("schedule_and_execute_tasks", TestModifierString(), |
| 380 test_name, timer_.LapsPerSecond(), "runs/s", true); | 380 test_name, timer_.LapsPerSecond(), "runs/s", true); |
| 381 } | 381 } |
| 382 | 382 |
| 383 private: | 383 private: |
| 384 void Create3dOutputSurfaceAndResourceProvider() { | 384 void Create3dOutputSurfaceAndResourceProvider() { |
| 385 output_surface_ = FakeOutputSurface::Create3d(context_provider_); | 385 output_surface_ = FakeOutputSurface::Create3d(context_provider_); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 public testing::Test { | 454 public testing::Test { |
| 455 public: | 455 public: |
| 456 // Overridden from testing::Test: | 456 // Overridden from testing::Test: |
| 457 void SetUp() override { | 457 void SetUp() override { |
| 458 output_surface_ = FakeOutputSurface::Create3d(context_provider_); | 458 output_surface_ = FakeOutputSurface::Create3d(context_provider_); |
| 459 CHECK(output_surface_->BindToClient(&output_surface_client_)); | 459 CHECK(output_surface_->BindToClient(&output_surface_client_)); |
| 460 resource_provider_ = | 460 resource_provider_ = |
| 461 FakeResourceProvider::Create(output_surface_.get(), nullptr); | 461 FakeResourceProvider::Create(output_surface_.get(), nullptr); |
| 462 } | 462 } |
| 463 | 463 |
| 464 void RunBuildTileTaskQueueTest(const std::string& test_name, | 464 void RunBuildTileTaskGraphTest(const std::string& test_name, |
| 465 unsigned num_raster_tasks, | 465 unsigned num_raster_tasks, |
| 466 unsigned num_image_decode_tasks) { | 466 unsigned num_image_decode_tasks) { |
| 467 ImageDecodeTask::Vector image_decode_tasks; | 467 ImageDecodeTask::Vector image_decode_tasks; |
| 468 RasterTaskVector raster_tasks; | 468 RasterTaskVector raster_tasks; |
| 469 CreateImageDecodeTasks(num_image_decode_tasks, &image_decode_tasks); | 469 CreateImageDecodeTasks(num_image_decode_tasks, &image_decode_tasks); |
| 470 CreateRasterTasks(num_raster_tasks, image_decode_tasks, &raster_tasks); | 470 CreateRasterTasks(num_raster_tasks, image_decode_tasks, &raster_tasks); |
| 471 | 471 |
| 472 // Avoid unnecessary heap allocations by reusing the same queue. | 472 // Avoid unnecessary heap allocations by reusing the same graph. |
| 473 TileTaskQueue queue; | 473 TaskGraph graph; |
| 474 | 474 |
| 475 timer_.Reset(); | 475 timer_.Reset(); |
| 476 do { | 476 do { |
| 477 queue.Reset(); | 477 graph.Reset(); |
| 478 BuildTileTaskQueue(&queue, raster_tasks); | 478 BuildTileTaskGraph(&graph, raster_tasks); |
| 479 timer_.NextLap(); | 479 timer_.NextLap(); |
| 480 } while (!timer_.HasTimeLimitExpired()); | 480 } while (!timer_.HasTimeLimitExpired()); |
| 481 | 481 |
| 482 perf_test::PrintResult("build_raster_task_queue", "", test_name, | 482 perf_test::PrintResult("build_raster_task_graph", "", test_name, |
| 483 timer_.LapsPerSecond(), "runs/s", true); | 483 timer_.LapsPerSecond(), "runs/s", true); |
| 484 } | 484 } |
| 485 }; | 485 }; |
| 486 | 486 |
| 487 TEST_F(TileTaskWorkerPoolCommonPerfTest, BuildTileTaskQueue) { | 487 TEST_F(TileTaskWorkerPoolCommonPerfTest, BuildTileTaskGraph) { |
| 488 RunBuildTileTaskQueueTest("1_0", 1, 0); | 488 RunBuildTileTaskGraphTest("1_0", 1, 0); |
| 489 RunBuildTileTaskQueueTest("32_0", 32, 0); | 489 RunBuildTileTaskGraphTest("32_0", 32, 0); |
| 490 RunBuildTileTaskQueueTest("1_1", 1, 1); | 490 RunBuildTileTaskGraphTest("1_1", 1, 1); |
| 491 RunBuildTileTaskQueueTest("32_1", 32, 1); | 491 RunBuildTileTaskGraphTest("32_1", 32, 1); |
| 492 RunBuildTileTaskQueueTest("1_4", 1, 4); | 492 RunBuildTileTaskGraphTest("1_4", 1, 4); |
| 493 RunBuildTileTaskQueueTest("32_4", 32, 4); | 493 RunBuildTileTaskGraphTest("32_4", 32, 4); |
| 494 } | 494 } |
| 495 | 495 |
| 496 } // namespace | 496 } // namespace |
| 497 } // namespace cc | 497 } // namespace cc |
| OLD | NEW |