| 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/pixel_buffer_raster_worker_pool.h" | 5 #include "cc/resources/pixel_buffer_raster_worker_pool.h" |
| 6 | 6 |
| 7 #include "base/containers/stack_container.h" | 7 #include "base/containers/stack_container.h" |
| 8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "cc/debug/traced_value.h" | 10 #include "cc/debug/traced_value.h" |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 enum RasterTaskType { | 440 enum RasterTaskType { |
| 441 PREPAINT_TYPE = 0, | 441 PREPAINT_TYPE = 0, |
| 442 REQUIRED_FOR_ACTIVATION_TYPE = 1, | 442 REQUIRED_FOR_ACTIVATION_TYPE = 1, |
| 443 NUM_TYPES = 2 | 443 NUM_TYPES = 2 |
| 444 }; | 444 }; |
| 445 NodeVector tasks[NUM_TYPES]; | 445 NodeVector tasks[NUM_TYPES]; |
| 446 unsigned priority = 2u; // 0-1 reserved for RasterFinished tasks. | 446 unsigned priority = 2u; // 0-1 reserved for RasterFinished tasks. |
| 447 TaskGraph graph; | 447 TaskGraph graph; |
| 448 | 448 |
| 449 size_t bytes_pending_upload = bytes_pending_upload_; | 449 size_t bytes_pending_upload = bytes_pending_upload_; |
| 450 bool did_throttle_raster_tasks = false; |
| 450 | 451 |
| 451 for (RasterTaskVector::const_iterator it = raster_tasks().begin(); | 452 for (RasterTaskVector::const_iterator it = raster_tasks().begin(); |
| 452 it != raster_tasks().end(); ++it) { | 453 it != raster_tasks().end(); ++it) { |
| 453 internal::RasterWorkerPoolTask* task = it->get(); | 454 internal::RasterWorkerPoolTask* task = it->get(); |
| 454 | 455 |
| 455 // |pixel_buffer_tasks_| contains all tasks that have not yet completed. | 456 // |pixel_buffer_tasks_| contains all tasks that have not yet completed. |
| 456 TaskMap::iterator pixel_buffer_it = pixel_buffer_tasks_.find(task); | 457 TaskMap::iterator pixel_buffer_it = pixel_buffer_tasks_.find(task); |
| 457 if (pixel_buffer_it == pixel_buffer_tasks_.end()) | 458 if (pixel_buffer_it == pixel_buffer_tasks_.end()) |
| 458 continue; | 459 continue; |
| 459 | 460 |
| 460 // HasFinishedRunning() will return true when set pixels has completed. | 461 // HasFinishedRunning() will return true when set pixels has completed. |
| 461 if (task->HasFinishedRunning()) { | 462 if (task->HasFinishedRunning()) { |
| 462 DCHECK(std::find(completed_tasks_.begin(), | 463 DCHECK(std::find(completed_tasks_.begin(), |
| 463 completed_tasks_.end(), | 464 completed_tasks_.end(), |
| 464 task) != completed_tasks_.end()); | 465 task) != completed_tasks_.end()); |
| 465 continue; | 466 continue; |
| 466 } | 467 } |
| 467 | 468 |
| 468 // All raster tasks need to be throttled by bytes of pending uploads. | 469 // All raster tasks need to be throttled by bytes of pending uploads. |
| 469 size_t new_bytes_pending_upload = bytes_pending_upload; | 470 size_t new_bytes_pending_upload = bytes_pending_upload; |
| 470 new_bytes_pending_upload += task->resource()->bytes(); | 471 new_bytes_pending_upload += task->resource()->bytes(); |
| 471 if (new_bytes_pending_upload > max_bytes_pending_upload_) | 472 if (new_bytes_pending_upload > max_bytes_pending_upload_) { |
| 473 did_throttle_raster_tasks = true; |
| 472 break; | 474 break; |
| 475 } |
| 473 | 476 |
| 474 internal::WorkerPoolTask* pixel_buffer_task = pixel_buffer_it->second.get(); | 477 internal::WorkerPoolTask* pixel_buffer_task = pixel_buffer_it->second.get(); |
| 475 | 478 |
| 476 // If raster has finished, just update |bytes_pending_upload|. | 479 // If raster has finished, just update |bytes_pending_upload|. |
| 477 if (pixel_buffer_task && pixel_buffer_task->HasCompleted()) { | 480 if (pixel_buffer_task && pixel_buffer_task->HasCompleted()) { |
| 478 bytes_pending_upload = new_bytes_pending_upload; | 481 bytes_pending_upload = new_bytes_pending_upload; |
| 479 continue; | 482 continue; |
| 480 } | 483 } |
| 481 | 484 |
| 482 // Throttle raster tasks based on kMaxScheduledRasterTasks. | 485 // Throttle raster tasks based on kMaxScheduledRasterTasks. |
| 483 size_t scheduled_raster_task_count = | 486 size_t scheduled_raster_task_count = |
| 484 tasks[PREPAINT_TYPE].container().size() + | 487 tasks[PREPAINT_TYPE].container().size() + |
| 485 tasks[REQUIRED_FOR_ACTIVATION_TYPE].container().size(); | 488 tasks[REQUIRED_FOR_ACTIVATION_TYPE].container().size(); |
| 486 if (scheduled_raster_task_count >= kMaxScheduledRasterTasks) | 489 if (scheduled_raster_task_count >= kMaxScheduledRasterTasks) { |
| 490 did_throttle_raster_tasks = true; |
| 487 break; | 491 break; |
| 492 } |
| 488 | 493 |
| 489 // Update |bytes_pending_upload| now that task has cleared all | 494 // Update |bytes_pending_upload| now that task has cleared all |
| 490 // throttling limits. | 495 // throttling limits. |
| 491 bytes_pending_upload = new_bytes_pending_upload; | 496 bytes_pending_upload = new_bytes_pending_upload; |
| 492 | 497 |
| 493 RasterTaskType type = IsRasterTaskRequiredForActivation(task) ? | 498 RasterTaskType type = IsRasterTaskRequiredForActivation(task) ? |
| 494 REQUIRED_FOR_ACTIVATION_TYPE : | 499 REQUIRED_FOR_ACTIVATION_TYPE : |
| 495 PREPAINT_TYPE; | 500 PREPAINT_TYPE; |
| 496 | 501 |
| 497 // Use existing pixel buffer task if available. | 502 // Use existing pixel buffer task if available. |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 554 } | 559 } |
| 555 | 560 |
| 556 scoped_refptr<internal::WorkerPoolTask> new_raster_finished_task; | 561 scoped_refptr<internal::WorkerPoolTask> new_raster_finished_task; |
| 557 | 562 |
| 558 size_t scheduled_raster_task_count = | 563 size_t scheduled_raster_task_count = |
| 559 tasks[PREPAINT_TYPE].container().size() + | 564 tasks[PREPAINT_TYPE].container().size() + |
| 560 tasks[REQUIRED_FOR_ACTIVATION_TYPE].container().size(); | 565 tasks[REQUIRED_FOR_ACTIVATION_TYPE].container().size(); |
| 561 DCHECK_LE(scheduled_raster_task_count, PendingRasterTaskCount()); | 566 DCHECK_LE(scheduled_raster_task_count, PendingRasterTaskCount()); |
| 562 // Schedule OnRasterTasksFinished call only when notification is pending | 567 // Schedule OnRasterTasksFinished call only when notification is pending |
| 563 // and throttling is not preventing all pending tasks from being scheduled. | 568 // and throttling is not preventing all pending tasks from being scheduled. |
| 564 if (scheduled_raster_task_count == PendingRasterTaskCount() && | 569 if (!did_throttle_raster_tasks && |
| 565 should_notify_client_if_no_tasks_are_pending_) { | 570 should_notify_client_if_no_tasks_are_pending_) { |
| 566 new_raster_finished_task = CreateRasterFinishedTask(); | 571 new_raster_finished_task = CreateRasterFinishedTask(); |
| 567 internal::GraphNode* raster_finished_node = | 572 internal::GraphNode* raster_finished_node = |
| 568 CreateGraphNodeForTask(new_raster_finished_task.get(), | 573 CreateGraphNodeForTask(new_raster_finished_task.get(), |
| 569 1u, // Priority 1 | 574 1u, // Priority 1 |
| 570 &graph); | 575 &graph); |
| 571 for (unsigned type = 0; type < NUM_TYPES; ++type) { | 576 for (unsigned type = 0; type < NUM_TYPES; ++type) { |
| 572 AddDependenciesToGraphNode( | 577 AddDependenciesToGraphNode( |
| 573 raster_finished_node, | 578 raster_finished_node, |
| 574 tasks[type].container()); | 579 tasks[type].container()); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 678 | 683 |
| 679 throttle_state->SetInteger("bytes_available_for_upload", | 684 throttle_state->SetInteger("bytes_available_for_upload", |
| 680 max_bytes_pending_upload_ - bytes_pending_upload_); | 685 max_bytes_pending_upload_ - bytes_pending_upload_); |
| 681 throttle_state->SetInteger("bytes_pending_upload", bytes_pending_upload_); | 686 throttle_state->SetInteger("bytes_pending_upload", bytes_pending_upload_); |
| 682 throttle_state->SetInteger("scheduled_raster_task_count", | 687 throttle_state->SetInteger("scheduled_raster_task_count", |
| 683 scheduled_raster_task_count_); | 688 scheduled_raster_task_count_); |
| 684 return throttle_state.PassAs<base::Value>(); | 689 return throttle_state.PassAs<base::Value>(); |
| 685 } | 690 } |
| 686 | 691 |
| 687 } // namespace cc | 692 } // namespace cc |
| OLD | NEW |