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 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 218 | 218 |
| 219 private: | 219 private: |
| 220 skia::LazyPixelRef* pixel_ref_; | 220 skia::LazyPixelRef* pixel_ref_; |
| 221 int layer_id_; | 221 int layer_id_; |
| 222 RenderingStatsInstrumentation* rendering_stats_; | 222 RenderingStatsInstrumentation* rendering_stats_; |
| 223 const RasterWorkerPool::Task::Reply reply_; | 223 const RasterWorkerPool::Task::Reply reply_; |
| 224 | 224 |
| 225 DISALLOW_COPY_AND_ASSIGN(ImageDecodeWorkerPoolTaskImpl); | 225 DISALLOW_COPY_AND_ASSIGN(ImageDecodeWorkerPoolTaskImpl); |
| 226 }; | 226 }; |
| 227 | 227 |
| 228 class RasterFinishedWorkerPoolTaskImpl : public internal::WorkerPoolTask { | |
| 229 public: | |
| 230 RasterFinishedWorkerPoolTaskImpl( | |
| 231 base::MessageLoopProxy* origin_loop, | |
| 232 const base::Closure& on_raster_finished_callback) | |
| 233 : origin_loop_(origin_loop), | |
| 234 on_raster_finished_callback_(on_raster_finished_callback) { | |
| 235 } | |
| 236 | |
| 237 // Overridden from internal::WorkerPoolTask: | |
| 238 virtual void RunOnWorkerThread(unsigned thread_index) OVERRIDE { | |
| 239 origin_loop_->PostTask(FROM_HERE, on_raster_finished_callback_); | |
| 240 } | |
| 241 virtual void CompleteOnOriginThread() OVERRIDE {} | |
| 242 | |
| 243 private: | |
| 244 virtual ~RasterFinishedWorkerPoolTaskImpl() {} | |
| 245 | |
| 246 scoped_refptr<base::MessageLoopProxy> origin_loop_; | |
| 247 const base::Closure on_raster_finished_callback_; | |
| 248 | |
| 249 DISALLOW_COPY_AND_ASSIGN(RasterFinishedWorkerPoolTaskImpl); | |
| 250 }; | |
| 251 | |
| 252 void Noop() {} | |
| 253 | |
| 254 const char* kWorkerThreadNamePrefix = "CompositorRaster"; | 228 const char* kWorkerThreadNamePrefix = "CompositorRaster"; |
| 255 | 229 |
| 256 } // namespace | 230 } // namespace |
| 257 | 231 |
| 258 namespace internal { | 232 namespace internal { |
| 259 | 233 |
| 260 RasterWorkerPoolTask::RasterWorkerPoolTask( | 234 RasterWorkerPoolTask::RasterWorkerPoolTask( |
| 261 const Resource* resource, TaskVector* dependencies) | 235 const Resource* resource, TaskVector* dependencies) |
| 262 : did_run_(false), | 236 : did_run_(false), |
| 263 did_complete_(false), | 237 did_complete_(false), |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 355 : internal_(internal) { | 329 : internal_(internal) { |
| 356 } | 330 } |
| 357 | 331 |
| 358 void RasterWorkerPool::RasterTask::Reset() { | 332 void RasterWorkerPool::RasterTask::Reset() { |
| 359 internal_ = NULL; | 333 internal_ = NULL; |
| 360 } | 334 } |
| 361 | 335 |
| 362 RasterWorkerPool::RasterTask::~RasterTask() { | 336 RasterWorkerPool::RasterTask::~RasterTask() { |
| 363 } | 337 } |
| 364 | 338 |
| 365 RasterWorkerPool::RasterTaskGraph::RasterTaskGraph() | |
| 366 : raster_finished_node_(new GraphNode), | |
| 367 next_priority_(1u) { | |
| 368 } | |
| 369 | |
| 370 RasterWorkerPool::RasterTaskGraph::~RasterTaskGraph() { | |
| 371 } | |
| 372 | |
| 373 void RasterWorkerPool::RasterTaskGraph::InsertRasterTask( | |
| 374 internal::WorkerPoolTask* raster_task, | |
| 375 const TaskVector& decode_tasks) { | |
| 376 DCHECK(!raster_task->HasCompleted()); | |
| 377 DCHECK(graph_.find(raster_task) == graph_.end()); | |
| 378 | |
| 379 scoped_ptr<GraphNode> raster_node(new GraphNode); | |
| 380 raster_node->set_task(raster_task); | |
| 381 raster_node->set_priority(next_priority_++); | |
| 382 | |
| 383 // Insert image decode tasks. | |
| 384 for (TaskVector::const_iterator it = decode_tasks.begin(); | |
| 385 it != decode_tasks.end(); ++it) { | |
| 386 internal::WorkerPoolTask* decode_task = it->get(); | |
| 387 | |
| 388 // Skip if already decoded. | |
| 389 if (decode_task->HasCompleted()) | |
| 390 continue; | |
| 391 | |
| 392 raster_node->add_dependency(); | |
| 393 | |
| 394 // Check if decode task already exists in graph. | |
| 395 GraphNodeMap::iterator decode_it = graph_.find(decode_task); | |
| 396 if (decode_it != graph_.end()) { | |
| 397 GraphNode* decode_node = decode_it->second; | |
| 398 decode_node->add_dependent(raster_node.get()); | |
| 399 continue; | |
| 400 } | |
| 401 | |
| 402 scoped_ptr<GraphNode> decode_node(new GraphNode); | |
| 403 decode_node->set_task(decode_task); | |
| 404 decode_node->set_priority(next_priority_++); | |
| 405 decode_node->add_dependent(raster_node.get()); | |
| 406 graph_.set(decode_task, decode_node.Pass()); | |
| 407 } | |
| 408 | |
| 409 raster_finished_node_->add_dependency(); | |
| 410 raster_node->add_dependent(raster_finished_node_.get()); | |
| 411 | |
| 412 graph_.set(raster_task, raster_node.Pass()); | |
| 413 } | |
| 414 | |
| 415 // static | 339 // static |
| 416 RasterWorkerPool::RasterTask RasterWorkerPool::CreateRasterTask( | 340 RasterWorkerPool::RasterTask RasterWorkerPool::CreateRasterTask( |
| 417 const Resource* resource, | 341 const Resource* resource, |
| 418 PicturePileImpl* picture_pile, | 342 PicturePileImpl* picture_pile, |
| 419 gfx::Rect content_rect, | 343 gfx::Rect content_rect, |
| 420 float contents_scale, | 344 float contents_scale, |
| 421 RasterMode raster_mode, | 345 RasterMode raster_mode, |
| 422 bool use_color_estimator, | 346 bool use_color_estimator, |
| 423 const RasterTaskMetadata& metadata, | 347 const RasterTaskMetadata& metadata, |
| 424 RenderingStatsInstrumentation* rendering_stats, | 348 RenderingStatsInstrumentation* rendering_stats, |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 445 return Task(new ImageDecodeWorkerPoolTaskImpl(pixel_ref, | 369 return Task(new ImageDecodeWorkerPoolTaskImpl(pixel_ref, |
| 446 layer_id, | 370 layer_id, |
| 447 stats_instrumentation, | 371 stats_instrumentation, |
| 448 reply)); | 372 reply)); |
| 449 } | 373 } |
| 450 | 374 |
| 451 RasterWorkerPool::RasterWorkerPool(ResourceProvider* resource_provider, | 375 RasterWorkerPool::RasterWorkerPool(ResourceProvider* resource_provider, |
| 452 size_t num_threads) | 376 size_t num_threads) |
| 453 : WorkerPool(num_threads, kWorkerThreadNamePrefix), | 377 : WorkerPool(num_threads, kWorkerThreadNamePrefix), |
| 454 client_(NULL), | 378 client_(NULL), |
| 455 resource_provider_(resource_provider), | 379 resource_provider_(resource_provider) { |
| 456 weak_ptr_factory_(this), | |
| 457 schedule_raster_tasks_count_(0) { | |
| 458 } | 380 } |
| 459 | 381 |
| 460 RasterWorkerPool::~RasterWorkerPool() { | 382 RasterWorkerPool::~RasterWorkerPool() { |
| 461 } | 383 } |
| 462 | 384 |
| 463 void RasterWorkerPool::SetClient(RasterWorkerPoolClient* client) { | 385 void RasterWorkerPool::SetClient(RasterWorkerPoolClient* client) { |
| 464 client_ = client; | 386 client_ = client; |
| 465 } | 387 } |
| 466 | 388 |
| 467 void RasterWorkerPool::Shutdown() { | 389 void RasterWorkerPool::Shutdown() { |
| 390 raster_tasks_.clear(); | |
| 468 TaskGraph empty; | 391 TaskGraph empty; |
| 469 SetTaskGraph(&empty); | 392 SetTaskGraph(&empty); |
| 470 WorkerPool::Shutdown(); | 393 WorkerPool::Shutdown(); |
| 471 raster_tasks_.clear(); | |
| 472 // Cancel any pending OnRasterFinished callback. | |
| 473 weak_ptr_factory_.InvalidateWeakPtrs(); | |
| 474 } | 394 } |
| 475 | 395 |
| 476 void RasterWorkerPool::SetRasterTasks(RasterTask::Queue* queue) { | 396 void RasterWorkerPool::SetRasterTasks(RasterTask::Queue* queue) { |
| 477 raster_tasks_.swap(queue->tasks_); | 397 raster_tasks_.swap(queue->tasks_); |
| 478 raster_tasks_required_for_activation_.swap( | 398 raster_tasks_required_for_activation_.swap( |
| 479 queue->tasks_required_for_activation_); | 399 queue->tasks_required_for_activation_); |
| 480 } | 400 } |
| 481 | 401 |
| 482 void RasterWorkerPool::SetRasterTaskGraph(RasterTaskGraph* graph) { | |
| 483 scoped_ptr<GraphNode> raster_finished_node( | |
| 484 graph->raster_finished_node_.Pass()); | |
| 485 TaskGraph new_graph; | |
| 486 new_graph.swap(graph->graph_); | |
| 487 | |
| 488 if (new_graph.empty()) { | |
| 489 SetTaskGraph(&new_graph); | |
| 490 raster_finished_task_ = NULL; | |
| 491 return; | |
| 492 } | |
| 493 | |
| 494 ++schedule_raster_tasks_count_; | |
| 495 | |
| 496 scoped_refptr<internal::WorkerPoolTask> new_raster_finished_task( | |
| 497 new RasterFinishedWorkerPoolTaskImpl( | |
| 498 base::MessageLoopProxy::current(), | |
| 499 base::Bind(&RasterWorkerPool::OnRasterFinished, | |
| 500 weak_ptr_factory_.GetWeakPtr(), | |
| 501 schedule_raster_tasks_count_))); | |
| 502 raster_finished_node->set_task(new_raster_finished_task.get()); | |
| 503 // Insert "raster finished" task before switching to new graph. | |
| 504 new_graph.set(new_raster_finished_task.get(), raster_finished_node.Pass()); | |
| 505 SetTaskGraph(&new_graph); | |
| 506 raster_finished_task_.swap(new_raster_finished_task); | |
| 507 } | |
| 508 | |
| 509 bool RasterWorkerPool::IsRasterTaskRequiredForActivation( | 402 bool RasterWorkerPool::IsRasterTaskRequiredForActivation( |
| 510 internal::RasterWorkerPoolTask* task) const { | 403 internal::RasterWorkerPoolTask* task) const { |
| 511 return | 404 return |
| 512 raster_tasks_required_for_activation_.find(task) != | 405 raster_tasks_required_for_activation_.find(task) != |
| 513 raster_tasks_required_for_activation_.end(); | 406 raster_tasks_required_for_activation_.end(); |
| 514 } | 407 } |
| 515 | 408 |
| 516 void RasterWorkerPool::OnRasterFinished(int64 schedule_raster_tasks_count) { | 409 // static |
| 517 TRACE_EVENT1("cc", "RasterWorkerPool::OnRasterFinished", | 410 scoped_ptr<WorkerPool::GraphNode> RasterWorkerPool::CreateRasterTaskGraphNode( |
|
vmpstr
2013/06/27 23:31:21
Can this be non-static on TaskGraph?
Something li
reveman
2013/06/28 17:26:07
TaskGraph is just a ScopedPtrHashMap at the moment
| |
| 518 "schedule_raster_tasks_count", schedule_raster_tasks_count); | 411 internal::WorkerPoolTask* raster_task, |
| 519 DCHECK_GE(schedule_raster_tasks_count_, schedule_raster_tasks_count); | 412 const TaskVector& decode_tasks, |
| 520 // Call OnRasterTasksFinished() when we've finished running all raster | 413 unsigned priority, |
| 521 // tasks needed since last time SetRasterTaskGraph() was called. | 414 TaskGraph* graph) { |
| 522 if (schedule_raster_tasks_count_ == schedule_raster_tasks_count) | 415 DCHECK(!raster_task->HasCompleted()); |
| 523 OnRasterTasksFinished(); | 416 |
| 417 scoped_ptr<GraphNode> raster_node(new GraphNode(raster_task, priority)); | |
| 418 | |
| 419 // Insert image decode tasks. | |
| 420 for (TaskVector::const_iterator it = decode_tasks.begin(); | |
| 421 it != decode_tasks.end(); ++it) { | |
| 422 internal::WorkerPoolTask* decode_task = it->get(); | |
| 423 | |
| 424 // Skip if already decoded. | |
| 425 if (decode_task->HasCompleted()) | |
| 426 continue; | |
| 427 | |
| 428 raster_node->add_dependency(); | |
| 429 | |
| 430 // Check if decode task already exists in graph. | |
| 431 GraphNodeMap::iterator decode_it = graph->find(decode_task); | |
| 432 if (decode_it != graph->end()) { | |
| 433 GraphNode* decode_node = decode_it->second; | |
| 434 decode_node->add_dependent(raster_node.get()); | |
| 435 continue; | |
| 436 } | |
| 437 | |
| 438 scoped_ptr<GraphNode> decode_node(new GraphNode(decode_task, priority)); | |
| 439 decode_node->add_dependent(raster_node.get()); | |
| 440 graph->set(decode_task, decode_node.Pass()); | |
| 441 } | |
| 442 | |
| 443 return raster_node.Pass(); | |
| 524 } | 444 } |
| 525 | 445 |
| 526 } // namespace cc | 446 } // namespace cc |
| OLD | NEW |