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 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 328 | 328 |
| 329 void RasterWorkerPool::RasterTask::Reset() { | 329 void RasterWorkerPool::RasterTask::Reset() { |
| 330 internal_ = NULL; | 330 internal_ = NULL; |
| 331 } | 331 } |
| 332 | 332 |
| 333 RasterWorkerPool::RasterTask::~RasterTask() { | 333 RasterWorkerPool::RasterTask::~RasterTask() { |
| 334 } | 334 } |
| 335 | 335 |
| 336 RasterWorkerPool::RasterTaskGraph::RasterTaskGraph() | 336 RasterWorkerPool::RasterTaskGraph::RasterTaskGraph() |
| 337 : raster_finished_node_(new GraphNode), | 337 : raster_finished_node_(new GraphNode), |
| 338 next_priority_(1u) { | 338 raster_required_for_activation_finished_node_(new GraphNode), |
| 339 next_priority_(2u) { // priority 0-1 is reserved for OnRasterFinished. | |
| 339 } | 340 } |
| 340 | 341 |
| 341 RasterWorkerPool::RasterTaskGraph::~RasterTaskGraph() { | 342 RasterWorkerPool::RasterTaskGraph::~RasterTaskGraph() { |
| 342 } | 343 } |
| 343 | 344 |
| 344 void RasterWorkerPool::RasterTaskGraph::InsertRasterTask( | 345 void RasterWorkerPool::RasterTaskGraph::InsertRasterTask( |
| 345 internal::WorkerPoolTask* raster_task, | 346 internal::WorkerPoolTask* raster_task, |
| 346 const TaskVector& decode_tasks) { | 347 const TaskVector& decode_tasks, |
| 348 bool required_for_activation) { | |
| 347 DCHECK(!raster_task->HasCompleted()); | 349 DCHECK(!raster_task->HasCompleted()); |
| 348 DCHECK(graph_.find(raster_task) == graph_.end()); | 350 DCHECK(graph_.find(raster_task) == graph_.end()); |
| 349 | 351 |
| 350 scoped_ptr<GraphNode> raster_node(new GraphNode); | 352 scoped_ptr<GraphNode> raster_node(new GraphNode); |
| 351 raster_node->set_task(raster_task); | 353 raster_node->set_task(raster_task); |
| 352 raster_node->set_priority(next_priority_++); | 354 raster_node->set_priority(next_priority_++); |
| 353 | 355 |
| 354 // Insert image decode tasks. | 356 // Insert image decode tasks. |
| 355 for (TaskVector::const_iterator it = decode_tasks.begin(); | 357 for (TaskVector::const_iterator it = decode_tasks.begin(); |
| 356 it != decode_tasks.end(); ++it) { | 358 it != decode_tasks.end(); ++it) { |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 373 scoped_ptr<GraphNode> decode_node(new GraphNode); | 375 scoped_ptr<GraphNode> decode_node(new GraphNode); |
| 374 decode_node->set_task(decode_task); | 376 decode_node->set_task(decode_task); |
| 375 decode_node->set_priority(next_priority_++); | 377 decode_node->set_priority(next_priority_++); |
| 376 decode_node->add_dependent(raster_node.get()); | 378 decode_node->add_dependent(raster_node.get()); |
| 377 graph_.set(decode_task, decode_node.Pass()); | 379 graph_.set(decode_task, decode_node.Pass()); |
| 378 } | 380 } |
| 379 | 381 |
| 380 raster_finished_node_->add_dependency(); | 382 raster_finished_node_->add_dependency(); |
| 381 raster_node->add_dependent(raster_finished_node_.get()); | 383 raster_node->add_dependent(raster_finished_node_.get()); |
| 382 | 384 |
| 385 if (required_for_activation) { | |
| 386 raster_required_for_activation_finished_node_->add_dependency(); | |
|
vmpstr
2013/06/21 18:38:33
Could you maybe add required_for_activation_task a
reveman
2013/06/24 16:04:03
Done.
| |
| 387 raster_node->add_dependent( | |
| 388 raster_required_for_activation_finished_node_.get()); | |
| 389 } | |
| 390 | |
| 383 graph_.set(raster_task, raster_node.Pass()); | 391 graph_.set(raster_task, raster_node.Pass()); |
| 384 } | 392 } |
| 385 | 393 |
| 386 // static | 394 // static |
| 387 RasterWorkerPool::RasterTask RasterWorkerPool::CreateRasterTask( | 395 RasterWorkerPool::RasterTask RasterWorkerPool::CreateRasterTask( |
| 388 const Resource* resource, | 396 const Resource* resource, |
| 389 PicturePileImpl* picture_pile, | 397 PicturePileImpl* picture_pile, |
| 390 gfx::Rect content_rect, | 398 gfx::Rect content_rect, |
| 391 float contents_scale, | 399 float contents_scale, |
| 392 RasterMode raster_mode, | 400 RasterMode raster_mode, |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 429 } | 437 } |
| 430 | 438 |
| 431 RasterWorkerPool::~RasterWorkerPool() { | 439 RasterWorkerPool::~RasterWorkerPool() { |
| 432 } | 440 } |
| 433 | 441 |
| 434 void RasterWorkerPool::SetClient(RasterWorkerPoolClient* client) { | 442 void RasterWorkerPool::SetClient(RasterWorkerPoolClient* client) { |
| 435 client_ = client; | 443 client_ = client; |
| 436 } | 444 } |
| 437 | 445 |
| 438 void RasterWorkerPool::Shutdown() { | 446 void RasterWorkerPool::Shutdown() { |
| 447 // Cancel any pending OnRasterFinished callbacks. | |
| 448 weak_ptr_factory_.InvalidateWeakPtrs(); | |
| 449 raster_tasks_.clear(); | |
| 439 TaskGraph empty; | 450 TaskGraph empty; |
| 440 SetTaskGraph(&empty); | 451 SetTaskGraph(&empty); |
| 441 WorkerPool::Shutdown(); | 452 WorkerPool::Shutdown(); |
| 442 raster_tasks_.clear(); | |
| 443 // Cancel any pending OnRasterFinished callback. | |
| 444 weak_ptr_factory_.InvalidateWeakPtrs(); | |
| 445 } | 453 } |
| 446 | 454 |
| 447 void RasterWorkerPool::SetRasterTasks(RasterTask::Queue* queue) { | 455 void RasterWorkerPool::SetRasterTasks(RasterTask::Queue* queue) { |
| 448 raster_tasks_.swap(queue->tasks_); | 456 raster_tasks_.swap(queue->tasks_); |
| 449 raster_tasks_required_for_activation_.swap( | 457 raster_tasks_required_for_activation_.swap( |
| 450 queue->tasks_required_for_activation_); | 458 queue->tasks_required_for_activation_); |
| 451 } | 459 } |
| 452 | 460 |
| 453 void RasterWorkerPool::SetRasterTaskGraph(RasterTaskGraph* graph) { | 461 void RasterWorkerPool::SetRasterTaskGraph(RasterTaskGraph* graph) { |
| 454 scoped_ptr<GraphNode> raster_finished_node( | 462 scoped_ptr<GraphNode> raster_finished_node( |
| 455 graph->raster_finished_node_.Pass()); | 463 graph->raster_finished_node_.Pass()); |
| 464 scoped_ptr<GraphNode> raster_required_for_activation_finished_node( | |
| 465 graph->raster_required_for_activation_finished_node_.Pass()); | |
| 456 TaskGraph new_graph; | 466 TaskGraph new_graph; |
| 457 new_graph.swap(graph->graph_); | 467 new_graph.swap(graph->graph_); |
| 458 | 468 |
| 459 if (new_graph.empty()) { | |
| 460 SetTaskGraph(&new_graph); | |
| 461 raster_finished_task_ = NULL; | |
| 462 return; | |
| 463 } | |
| 464 | |
| 465 ++schedule_raster_tasks_count_; | 469 ++schedule_raster_tasks_count_; |
| 466 | 470 |
| 467 scoped_refptr<internal::WorkerPoolTask> new_raster_finished_task( | 471 scoped_refptr<internal::WorkerPoolTask> new_raster_finished_task( |
| 468 new RasterFinishedWorkerPoolTaskImpl( | 472 new RasterFinishedWorkerPoolTaskImpl( |
| 469 base::MessageLoopProxy::current(), | 473 base::MessageLoopProxy::current(), |
| 470 base::Bind(&RasterWorkerPool::OnRasterFinished, | 474 base::Bind(&RasterWorkerPool::OnRasterFinished, |
| 471 weak_ptr_factory_.GetWeakPtr(), | 475 weak_ptr_factory_.GetWeakPtr(), |
| 472 schedule_raster_tasks_count_))); | 476 schedule_raster_tasks_count_, |
| 477 base::Bind(&RasterWorkerPool::OnRasterTasksFinished, | |
| 478 weak_ptr_factory_.GetWeakPtr())))); | |
| 473 raster_finished_node->set_task(new_raster_finished_task.get()); | 479 raster_finished_node->set_task(new_raster_finished_task.get()); |
| 474 // Insert "raster finished" task before switching to new graph. | 480 raster_finished_node->set_priority(1u); |
| 475 new_graph.set(new_raster_finished_task.get(), raster_finished_node.Pass()); | 481 new_graph.set(new_raster_finished_task.get(), raster_finished_node.Pass()); |
| 482 | |
| 483 scoped_refptr<internal::WorkerPoolTask> | |
| 484 new_raster_required_for_activation_finished_task( | |
| 485 new RasterFinishedWorkerPoolTaskImpl( | |
| 486 base::MessageLoopProxy::current(), | |
| 487 base::Bind(&RasterWorkerPool::OnRasterFinished, | |
| 488 weak_ptr_factory_.GetWeakPtr(), | |
| 489 schedule_raster_tasks_count_, | |
| 490 base::Bind(&RasterWorkerPool:: | |
|
vmpstr
2013/06/21 18:38:33
Would it be better if we just explicitly call this
reveman
2013/06/24 16:04:03
Done. I used two levels of bind here to avoid OnRa
| |
| 491 OnRasterTasksRequiredForActivationFinished, | |
| 492 weak_ptr_factory_.GetWeakPtr())))); | |
| 493 raster_required_for_activation_finished_node->set_task( | |
| 494 new_raster_required_for_activation_finished_task.get()); | |
| 495 raster_required_for_activation_finished_node->set_priority(0u); | |
| 496 new_graph.set(new_raster_required_for_activation_finished_task.get(), | |
| 497 raster_required_for_activation_finished_node.Pass()); | |
| 498 | |
| 476 SetTaskGraph(&new_graph); | 499 SetTaskGraph(&new_graph); |
| 500 | |
| 477 raster_finished_task_.swap(new_raster_finished_task); | 501 raster_finished_task_.swap(new_raster_finished_task); |
| 502 raster_required_for_activation_finished_task_.swap( | |
| 503 new_raster_required_for_activation_finished_task); | |
| 478 } | 504 } |
| 479 | 505 |
| 480 bool RasterWorkerPool::IsRasterTaskRequiredForActivation( | 506 bool RasterWorkerPool::IsRasterTaskRequiredForActivation( |
| 481 internal::RasterWorkerPoolTask* task) const { | 507 internal::RasterWorkerPoolTask* task) const { |
| 482 return | 508 return |
| 483 raster_tasks_required_for_activation_.find(task) != | 509 raster_tasks_required_for_activation_.find(task) != |
| 484 raster_tasks_required_for_activation_.end(); | 510 raster_tasks_required_for_activation_.end(); |
| 485 } | 511 } |
| 486 | 512 |
| 487 void RasterWorkerPool::OnRasterFinished(int64 schedule_raster_tasks_count) { | 513 void RasterWorkerPool::OnRasterFinished( |
| 514 int64 schedule_raster_tasks_count, | |
| 515 const base::Closure& on_raster_tasks_finished_callback) { | |
| 488 TRACE_EVENT1("cc", "RasterWorkerPool::OnRasterFinished", | 516 TRACE_EVENT1("cc", "RasterWorkerPool::OnRasterFinished", |
| 489 "schedule_raster_tasks_count", schedule_raster_tasks_count); | 517 "schedule_raster_tasks_count", schedule_raster_tasks_count); |
| 490 DCHECK_GE(schedule_raster_tasks_count_, schedule_raster_tasks_count); | 518 DCHECK_GE(schedule_raster_tasks_count_, schedule_raster_tasks_count); |
| 491 // Call OnRasterTasksFinished() when we've finished running all raster | 519 // Run |on_raster_tasks_finished_callback| if this callback is associated |
| 492 // tasks needed since last time SetRasterTaskGraph() was called. | 520 // with the last call to SetRasterTaskGraph(). |
| 493 if (schedule_raster_tasks_count_ == schedule_raster_tasks_count) | 521 if (schedule_raster_tasks_count_ == schedule_raster_tasks_count) |
| 494 OnRasterTasksFinished(); | 522 on_raster_tasks_finished_callback.Run(); |
| 495 } | 523 } |
| 496 | 524 |
| 497 } // namespace cc | 525 } // namespace cc |
| OLD | NEW |