Chromium Code Reviews| 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/resources/raster_worker_pool.h" | 5 #include "cc/resources/raster_worker_pool.h" |
| 6 | 6 |
| 7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "cc/debug/devtools_instrumentation.h" | 10 #include "cc/debug/devtools_instrumentation.h" |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 217 | 217 |
| 218 private: | 218 private: |
| 219 virtual ~RasterFinishedWorkerPoolTaskImpl() {} | 219 virtual ~RasterFinishedWorkerPoolTaskImpl() {} |
| 220 | 220 |
| 221 scoped_refptr<base::MessageLoopProxy> origin_loop_; | 221 scoped_refptr<base::MessageLoopProxy> origin_loop_; |
| 222 const base::Closure on_raster_finished_callback_; | 222 const base::Closure on_raster_finished_callback_; |
| 223 | 223 |
| 224 DISALLOW_COPY_AND_ASSIGN(RasterFinishedWorkerPoolTaskImpl); | 224 DISALLOW_COPY_AND_ASSIGN(RasterFinishedWorkerPoolTaskImpl); |
| 225 }; | 225 }; |
| 226 | 226 |
| 227 void Noop() {} | |
| 228 | |
| 229 const char* kWorkerThreadNamePrefix = "CompositorRaster"; | 227 const char* kWorkerThreadNamePrefix = "CompositorRaster"; |
| 230 | 228 |
| 231 } // namespace | 229 } // namespace |
| 232 | 230 |
| 233 namespace internal { | 231 namespace internal { |
| 234 | 232 |
| 235 RasterWorkerPoolTask::RasterWorkerPoolTask( | 233 RasterWorkerPoolTask::RasterWorkerPoolTask( |
| 236 const Resource* resource, TaskVector* dependencies) | 234 const Resource* resource, TaskVector* dependencies) |
| 237 : did_run_(false), | 235 : did_run_(false), |
| 238 did_complete_(false), | 236 did_complete_(false), |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 328 | 326 |
| 329 void RasterWorkerPool::RasterTask::Reset() { | 327 void RasterWorkerPool::RasterTask::Reset() { |
| 330 internal_ = NULL; | 328 internal_ = NULL; |
| 331 } | 329 } |
| 332 | 330 |
| 333 RasterWorkerPool::RasterTask::~RasterTask() { | 331 RasterWorkerPool::RasterTask::~RasterTask() { |
| 334 } | 332 } |
| 335 | 333 |
| 336 RasterWorkerPool::RasterTaskGraph::RasterTaskGraph() | 334 RasterWorkerPool::RasterTaskGraph::RasterTaskGraph() |
| 337 : raster_finished_node_(new GraphNode), | 335 : raster_finished_node_(new GraphNode), |
| 338 next_priority_(1u) { | 336 raster_required_for_activation_finished_node_(new GraphNode), |
| 337 next_priority_(2u) { // priority 0-1 is reserved for OnRasterFinished. | |
| 338 raster_finished_node_->add_dependency(); | |
| 339 raster_required_for_activation_finished_node_->add_dependent( | |
| 340 raster_finished_node_.get()); | |
| 339 } | 341 } |
| 340 | 342 |
| 341 RasterWorkerPool::RasterTaskGraph::~RasterTaskGraph() { | 343 RasterWorkerPool::RasterTaskGraph::~RasterTaskGraph() { |
| 342 } | 344 } |
| 343 | 345 |
| 344 void RasterWorkerPool::RasterTaskGraph::InsertRasterTask( | 346 void RasterWorkerPool::RasterTaskGraph::InsertRasterTask( |
| 345 internal::WorkerPoolTask* raster_task, | 347 internal::WorkerPoolTask* raster_task, |
| 346 const TaskVector& decode_tasks) { | 348 const TaskVector& decode_tasks, |
| 349 bool required_for_activation) { | |
| 347 DCHECK(!raster_task->HasCompleted()); | 350 DCHECK(!raster_task->HasCompleted()); |
| 348 DCHECK(graph_.find(raster_task) == graph_.end()); | 351 DCHECK(graph_.find(raster_task) == graph_.end()); |
| 349 | 352 |
| 350 scoped_ptr<GraphNode> raster_node(new GraphNode); | 353 scoped_ptr<GraphNode> raster_node(new GraphNode); |
| 351 raster_node->set_task(raster_task); | 354 raster_node->set_task(raster_task); |
| 352 raster_node->set_priority(next_priority_++); | 355 raster_node->set_priority(next_priority_++); |
| 353 | 356 |
| 354 // Insert image decode tasks. | 357 // Insert image decode tasks. |
| 355 for (TaskVector::const_iterator it = decode_tasks.begin(); | 358 for (TaskVector::const_iterator it = decode_tasks.begin(); |
| 356 it != decode_tasks.end(); ++it) { | 359 it != decode_tasks.end(); ++it) { |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 370 continue; | 373 continue; |
| 371 } | 374 } |
| 372 | 375 |
| 373 scoped_ptr<GraphNode> decode_node(new GraphNode); | 376 scoped_ptr<GraphNode> decode_node(new GraphNode); |
| 374 decode_node->set_task(decode_task); | 377 decode_node->set_task(decode_task); |
| 375 decode_node->set_priority(next_priority_++); | 378 decode_node->set_priority(next_priority_++); |
| 376 decode_node->add_dependent(raster_node.get()); | 379 decode_node->add_dependent(raster_node.get()); |
| 377 graph_.set(decode_task, decode_node.Pass()); | 380 graph_.set(decode_task, decode_node.Pass()); |
| 378 } | 381 } |
| 379 | 382 |
| 380 raster_finished_node_->add_dependency(); | 383 if (required_for_activation) { |
| 381 raster_node->add_dependent(raster_finished_node_.get()); | 384 raster_required_for_activation_finished_node_->add_dependency(); |
| 385 raster_node->add_dependent( | |
| 386 raster_required_for_activation_finished_node_.get()); | |
| 387 } else { | |
| 388 raster_finished_node_->add_dependency(); | |
| 389 raster_node->add_dependent(raster_finished_node_.get()); | |
| 390 } | |
| 382 | 391 |
| 383 graph_.set(raster_task, raster_node.Pass()); | 392 graph_.set(raster_task, raster_node.Pass()); |
| 384 } | 393 } |
| 385 | 394 |
| 386 // static | 395 // static |
| 387 RasterWorkerPool::RasterTask RasterWorkerPool::CreateRasterTask( | 396 RasterWorkerPool::RasterTask RasterWorkerPool::CreateRasterTask( |
| 388 const Resource* resource, | 397 const Resource* resource, |
| 389 PicturePileImpl* picture_pile, | 398 PicturePileImpl* picture_pile, |
| 390 gfx::Rect content_rect, | 399 gfx::Rect content_rect, |
| 391 float contents_scale, | 400 float contents_scale, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 429 } | 438 } |
| 430 | 439 |
| 431 RasterWorkerPool::~RasterWorkerPool() { | 440 RasterWorkerPool::~RasterWorkerPool() { |
| 432 } | 441 } |
| 433 | 442 |
| 434 void RasterWorkerPool::SetClient(RasterWorkerPoolClient* client) { | 443 void RasterWorkerPool::SetClient(RasterWorkerPoolClient* client) { |
| 435 client_ = client; | 444 client_ = client; |
| 436 } | 445 } |
| 437 | 446 |
| 438 void RasterWorkerPool::Shutdown() { | 447 void RasterWorkerPool::Shutdown() { |
| 448 // Cancel any pending OnRasterFinished callbacks. | |
| 449 weak_ptr_factory_.InvalidateWeakPtrs(); | |
| 450 raster_tasks_.clear(); | |
| 439 TaskGraph empty; | 451 TaskGraph empty; |
| 440 SetTaskGraph(&empty); | 452 SetTaskGraph(&empty); |
| 441 WorkerPool::Shutdown(); | 453 WorkerPool::Shutdown(); |
| 442 raster_tasks_.clear(); | |
| 443 // Cancel any pending OnRasterFinished callback. | |
| 444 weak_ptr_factory_.InvalidateWeakPtrs(); | |
| 445 } | 454 } |
| 446 | 455 |
| 447 void RasterWorkerPool::SetRasterTasks(RasterTask::Queue* queue) { | 456 void RasterWorkerPool::SetRasterTasks(RasterTask::Queue* queue) { |
| 448 raster_tasks_.swap(queue->tasks_); | 457 raster_tasks_.swap(queue->tasks_); |
| 449 raster_tasks_required_for_activation_.swap( | 458 raster_tasks_required_for_activation_.swap( |
| 450 queue->tasks_required_for_activation_); | 459 queue->tasks_required_for_activation_); |
| 451 } | 460 } |
| 452 | 461 |
| 453 void RasterWorkerPool::SetRasterTaskGraph(RasterTaskGraph* graph) { | 462 void RasterWorkerPool::SetRasterTaskGraph(RasterTaskGraph* graph) { |
| 454 scoped_ptr<GraphNode> raster_finished_node( | 463 scoped_ptr<GraphNode> raster_finished_node( |
| 455 graph->raster_finished_node_.Pass()); | 464 graph->raster_finished_node_.Pass()); |
| 465 scoped_ptr<GraphNode> raster_required_for_activation_finished_node( | |
| 466 graph->raster_required_for_activation_finished_node_.Pass()); | |
| 456 TaskGraph new_graph; | 467 TaskGraph new_graph; |
| 457 new_graph.swap(graph->graph_); | 468 new_graph.swap(graph->graph_); |
| 458 | 469 |
| 459 if (new_graph.empty()) { | |
| 460 SetTaskGraph(&new_graph); | |
| 461 raster_finished_task_ = NULL; | |
| 462 return; | |
| 463 } | |
| 464 | |
| 465 ++schedule_raster_tasks_count_; | 470 ++schedule_raster_tasks_count_; |
| 466 | 471 |
| 467 scoped_refptr<internal::WorkerPoolTask> new_raster_finished_task( | 472 scoped_refptr<internal::WorkerPoolTask> new_raster_finished_task( |
| 468 new RasterFinishedWorkerPoolTaskImpl( | 473 new RasterFinishedWorkerPoolTaskImpl( |
| 469 base::MessageLoopProxy::current(), | 474 base::MessageLoopProxy::current(), |
| 470 base::Bind(&RasterWorkerPool::OnRasterFinished, | 475 base::Bind(&RasterWorkerPool::OnRasterFinished, |
| 471 weak_ptr_factory_.GetWeakPtr(), | 476 weak_ptr_factory_.GetWeakPtr(), |
| 472 schedule_raster_tasks_count_))); | 477 schedule_raster_tasks_count_))); |
| 473 raster_finished_node->set_task(new_raster_finished_task.get()); | 478 raster_finished_node->set_task(new_raster_finished_task.get()); |
| 474 // Insert "raster finished" task before switching to new graph. | 479 raster_finished_node->set_priority(0u); |
| 475 new_graph.set(new_raster_finished_task.get(), raster_finished_node.Pass()); | 480 new_graph.set(new_raster_finished_task.get(), raster_finished_node.Pass()); |
| 481 | |
| 482 scoped_refptr<internal::WorkerPoolTask> | |
| 483 new_raster_required_for_activation_finished_task( | |
|
vmpstr
2013/06/24 16:34:03
Should this one be marked as a dependency of the r
reveman
2013/06/24 19:05:17
That's currently done in RasterTaskGraph ctor.
| |
| 484 new RasterFinishedWorkerPoolTaskImpl( | |
| 485 base::MessageLoopProxy::current(), | |
| 486 base::Bind( | |
| 487 &RasterWorkerPool::OnRasterRequiredForActivationFinished, | |
| 488 weak_ptr_factory_.GetWeakPtr(), | |
| 489 schedule_raster_tasks_count_))); | |
| 490 raster_required_for_activation_finished_node->set_task( | |
| 491 new_raster_required_for_activation_finished_task.get()); | |
| 492 raster_required_for_activation_finished_node->set_priority(1u); | |
|
vmpstr
2013/06/24 16:34:03
As a follow-up, we might want to do something like
reveman
2013/06/24 19:05:17
Sounds good. This will likely be done as part of t
| |
| 493 new_graph.set(new_raster_required_for_activation_finished_task.get(), | |
| 494 raster_required_for_activation_finished_node.Pass()); | |
| 495 | |
| 476 SetTaskGraph(&new_graph); | 496 SetTaskGraph(&new_graph); |
| 497 | |
| 477 raster_finished_task_.swap(new_raster_finished_task); | 498 raster_finished_task_.swap(new_raster_finished_task); |
| 499 raster_required_for_activation_finished_task_.swap( | |
| 500 new_raster_required_for_activation_finished_task); | |
| 478 } | 501 } |
| 479 | 502 |
| 480 bool RasterWorkerPool::IsRasterTaskRequiredForActivation( | 503 bool RasterWorkerPool::IsRasterTaskRequiredForActivation( |
| 481 internal::RasterWorkerPoolTask* task) const { | 504 internal::RasterWorkerPoolTask* task) const { |
| 482 return | 505 return |
| 483 raster_tasks_required_for_activation_.find(task) != | 506 raster_tasks_required_for_activation_.find(task) != |
| 484 raster_tasks_required_for_activation_.end(); | 507 raster_tasks_required_for_activation_.end(); |
| 485 } | 508 } |
| 486 | 509 |
| 487 void RasterWorkerPool::OnRasterFinished(int64 schedule_raster_tasks_count) { | 510 void RasterWorkerPool::OnRasterFinished( |
| 511 int64 schedule_raster_tasks_count) { | |
| 488 TRACE_EVENT1("cc", "RasterWorkerPool::OnRasterFinished", | 512 TRACE_EVENT1("cc", "RasterWorkerPool::OnRasterFinished", |
| 489 "schedule_raster_tasks_count", schedule_raster_tasks_count); | 513 "schedule_raster_tasks_count", schedule_raster_tasks_count); |
| 490 DCHECK_GE(schedule_raster_tasks_count_, schedule_raster_tasks_count); | 514 DCHECK_GE(schedule_raster_tasks_count_, schedule_raster_tasks_count); |
| 491 // Call OnRasterTasksFinished() when we've finished running all raster | 515 // Call OnRasterTasksFinished() if this callback is |
| 492 // tasks needed since last time SetRasterTaskGraph() was called. | 516 // associated with the last call to SetRasterTaskGraph(). |
| 493 if (schedule_raster_tasks_count_ == schedule_raster_tasks_count) | 517 if (schedule_raster_tasks_count_ == schedule_raster_tasks_count) |
| 494 OnRasterTasksFinished(); | 518 OnRasterTasksFinished(); |
| 495 } | 519 } |
| 496 | 520 |
| 521 void RasterWorkerPool::OnRasterRequiredForActivationFinished( | |
| 522 int64 schedule_raster_tasks_count) { | |
| 523 TRACE_EVENT1("cc", "RasterWorkerPool::OnRasterRequiredForActivationFinished", | |
| 524 "schedule_raster_tasks_count", schedule_raster_tasks_count); | |
| 525 DCHECK_GE(schedule_raster_tasks_count_, schedule_raster_tasks_count); | |
| 526 // Call OnRasterTasksRequiredForActivationFinished() if this callback is | |
| 527 // associated with the last call to SetRasterTaskGraph(). | |
| 528 if (schedule_raster_tasks_count_ == schedule_raster_tasks_count) | |
| 529 OnRasterTasksRequiredForActivationFinished(); | |
| 530 } | |
| 531 | |
| 497 } // namespace cc | 532 } // namespace cc |
| OLD | NEW |