| 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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 size_t max_transfer_buffer_usage_bytes) | 95 size_t max_transfer_buffer_usage_bytes) |
| 96 : RasterWorkerPool(resource_provider, num_threads), | 96 : RasterWorkerPool(resource_provider, num_threads), |
| 97 shutdown_(false), | 97 shutdown_(false), |
| 98 scheduled_raster_task_count_(0), | 98 scheduled_raster_task_count_(0), |
| 99 bytes_pending_upload_(0), | 99 bytes_pending_upload_(0), |
| 100 max_bytes_pending_upload_(max_transfer_buffer_usage_bytes), | 100 max_bytes_pending_upload_(max_transfer_buffer_usage_bytes), |
| 101 has_performed_uploads_since_last_flush_(false), | 101 has_performed_uploads_since_last_flush_(false), |
| 102 check_for_completed_raster_tasks_pending_(false), | 102 check_for_completed_raster_tasks_pending_(false), |
| 103 should_notify_client_if_no_tasks_are_pending_(false), | 103 should_notify_client_if_no_tasks_are_pending_(false), |
| 104 should_notify_client_if_no_tasks_required_for_activation_are_pending_( | 104 should_notify_client_if_no_tasks_required_for_activation_are_pending_( |
| 105 false), | 105 false) { |
| 106 raster_finished_task_pending_(false), | |
| 107 raster_required_for_activation_finished_task_pending_(false) { | |
| 108 } | 106 } |
| 109 | 107 |
| 110 PixelBufferRasterWorkerPool::~PixelBufferRasterWorkerPool() { | 108 PixelBufferRasterWorkerPool::~PixelBufferRasterWorkerPool() { |
| 111 DCHECK(shutdown_); | 109 DCHECK(shutdown_); |
| 112 DCHECK(!check_for_completed_raster_tasks_pending_); | 110 DCHECK(!check_for_completed_raster_tasks_pending_); |
| 113 DCHECK_EQ(0u, pixel_buffer_tasks_.size()); | 111 DCHECK_EQ(0u, pixel_buffer_tasks_.size()); |
| 114 DCHECK_EQ(0u, tasks_with_pending_upload_.size()); | 112 DCHECK_EQ(0u, tasks_with_pending_upload_.size()); |
| 115 DCHECK_EQ(0u, completed_tasks_.size()); | 113 DCHECK_EQ(0u, completed_tasks_.size()); |
| 116 } | 114 } |
| 117 | 115 |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 completed_tasks.pop_front(); | 248 completed_tasks.pop_front(); |
| 251 } | 249 } |
| 252 } | 250 } |
| 253 | 251 |
| 254 void PixelBufferRasterWorkerPool::OnRasterTasksFinished() { | 252 void PixelBufferRasterWorkerPool::OnRasterTasksFinished() { |
| 255 // |should_notify_client_if_no_tasks_are_pending_| can be set to false as | 253 // |should_notify_client_if_no_tasks_are_pending_| can be set to false as |
| 256 // a result of a scheduled CheckForCompletedRasterTasks() call. No need to | 254 // a result of a scheduled CheckForCompletedRasterTasks() call. No need to |
| 257 // perform another check in that case as we've already notified the client. | 255 // perform another check in that case as we've already notified the client. |
| 258 if (!should_notify_client_if_no_tasks_are_pending_) | 256 if (!should_notify_client_if_no_tasks_are_pending_) |
| 259 return; | 257 return; |
| 260 raster_finished_task_pending_ = false; | |
| 261 | 258 |
| 262 // Call CheckForCompletedRasterTasks() when we've finished running all | 259 // Call CheckForCompletedRasterTasks() when we've finished running all |
| 263 // raster tasks needed since last time ScheduleTasks() was called. | 260 // raster tasks needed since last time ScheduleTasks() was called. |
| 264 // This reduces latency between the time when all tasks have finished | 261 // This reduces latency between the time when all tasks have finished |
| 265 // running and the time when the client is notified. | 262 // running and the time when the client is notified. |
| 266 CheckForCompletedRasterTasks(); | 263 CheckForCompletedRasterTasks(); |
| 267 } | 264 } |
| 268 | 265 |
| 269 void PixelBufferRasterWorkerPool::OnRasterTasksRequiredForActivationFinished() { | 266 void PixelBufferRasterWorkerPool::OnRasterTasksRequiredForActivationFinished() { |
| 270 // Analogous to OnRasterTasksFinished(), there's no need to call | 267 // Analogous to OnRasterTasksFinished(), there's no need to call |
| 271 // CheckForCompletedRasterTasks() if the client has already been notified. | 268 // CheckForCompletedRasterTasks() if the client has already been notified. |
| 272 if (!should_notify_client_if_no_tasks_required_for_activation_are_pending_) | 269 if (!should_notify_client_if_no_tasks_required_for_activation_are_pending_) |
| 273 return; | 270 return; |
| 274 raster_required_for_activation_finished_task_pending_ = false; | |
| 275 | 271 |
| 276 // This reduces latency between the time when all tasks required for | 272 // This reduces latency between the time when all tasks required for |
| 277 // activation have finished running and the time when the client is | 273 // activation have finished running and the time when the client is |
| 278 // notified. | 274 // notified. |
| 279 CheckForCompletedRasterTasks(); | 275 CheckForCompletedRasterTasks(); |
| 280 } | 276 } |
| 281 | 277 |
| 282 void PixelBufferRasterWorkerPool::FlushUploads() { | 278 void PixelBufferRasterWorkerPool::FlushUploads() { |
| 283 if (!has_performed_uploads_since_last_flush_) | 279 if (!has_performed_uploads_since_last_flush_) |
| 284 return; | 280 return; |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 check_for_completed_raster_tasks_callback_.Cancel(); | 379 check_for_completed_raster_tasks_callback_.Cancel(); |
| 384 check_for_completed_raster_tasks_pending_ = false; | 380 check_for_completed_raster_tasks_pending_ = false; |
| 385 | 381 |
| 386 RasterWorkerPool::CheckForCompletedTasks(); | 382 RasterWorkerPool::CheckForCompletedTasks(); |
| 387 CheckForCompletedUploads(); | 383 CheckForCompletedUploads(); |
| 388 FlushUploads(); | 384 FlushUploads(); |
| 389 | 385 |
| 390 // Determine what client notifications to generate. | 386 // Determine what client notifications to generate. |
| 391 bool will_notify_client_that_no_tasks_required_for_activation_are_pending = | 387 bool will_notify_client_that_no_tasks_required_for_activation_are_pending = |
| 392 (should_notify_client_if_no_tasks_required_for_activation_are_pending_ && | 388 (should_notify_client_if_no_tasks_required_for_activation_are_pending_ && |
| 393 !raster_required_for_activation_finished_task_pending_ && | |
| 394 !HasPendingTasksRequiredForActivation()); | 389 !HasPendingTasksRequiredForActivation()); |
| 395 bool will_notify_client_that_no_tasks_are_pending = | 390 bool will_notify_client_that_no_tasks_are_pending = |
| 396 (should_notify_client_if_no_tasks_are_pending_ && | 391 (should_notify_client_if_no_tasks_are_pending_ && |
| 397 !raster_finished_task_pending_ && | |
| 398 !HasPendingTasks()); | 392 !HasPendingTasks()); |
| 399 | 393 |
| 400 // Adjust the need to generate notifications before scheduling more tasks. | 394 // Adjust the need to generate notifications before scheduling more tasks. |
| 401 should_notify_client_if_no_tasks_required_for_activation_are_pending_ &= | 395 should_notify_client_if_no_tasks_required_for_activation_are_pending_ &= |
| 402 !will_notify_client_that_no_tasks_required_for_activation_are_pending; | 396 !will_notify_client_that_no_tasks_required_for_activation_are_pending; |
| 403 should_notify_client_if_no_tasks_are_pending_ &= | 397 should_notify_client_if_no_tasks_are_pending_ &= |
| 404 !will_notify_client_that_no_tasks_are_pending; | 398 !will_notify_client_that_no_tasks_are_pending; |
| 405 | 399 |
| 406 scheduled_raster_task_count_ = 0; | 400 scheduled_raster_task_count_ = 0; |
| 407 if (PendingRasterTaskCount()) | 401 if (PendingRasterTaskCount()) |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 533 DCHECK_LE(scheduled_raster_task_required_for_activation_count, | 527 DCHECK_LE(scheduled_raster_task_required_for_activation_count, |
| 534 tasks_required_for_activation_.size()); | 528 tasks_required_for_activation_.size()); |
| 535 // Schedule OnRasterTasksRequiredForActivationFinished call only when | 529 // Schedule OnRasterTasksRequiredForActivationFinished call only when |
| 536 // notification is pending and throttling is not preventing all pending | 530 // notification is pending and throttling is not preventing all pending |
| 537 // tasks required for activation from being scheduled. | 531 // tasks required for activation from being scheduled. |
| 538 if (scheduled_raster_task_required_for_activation_count == | 532 if (scheduled_raster_task_required_for_activation_count == |
| 539 tasks_required_for_activation_.size() && | 533 tasks_required_for_activation_.size() && |
| 540 should_notify_client_if_no_tasks_required_for_activation_are_pending_) { | 534 should_notify_client_if_no_tasks_required_for_activation_are_pending_) { |
| 541 new_raster_required_for_activation_finished_task = | 535 new_raster_required_for_activation_finished_task = |
| 542 CreateRasterRequiredForActivationFinishedTask(); | 536 CreateRasterRequiredForActivationFinishedTask(); |
| 543 raster_required_for_activation_finished_task_pending_ = true; | |
| 544 internal::GraphNode* raster_required_for_activation_finished_node = | 537 internal::GraphNode* raster_required_for_activation_finished_node = |
| 545 CreateGraphNodeForTask( | 538 CreateGraphNodeForTask( |
| 546 new_raster_required_for_activation_finished_task.get(), | 539 new_raster_required_for_activation_finished_task.get(), |
| 547 0u, // Priority 0 | 540 0u, // Priority 0 |
| 548 &graph); | 541 &graph); |
| 549 AddDependenciesToGraphNode( | 542 AddDependenciesToGraphNode( |
| 550 raster_required_for_activation_finished_node, | 543 raster_required_for_activation_finished_node, |
| 551 tasks[REQUIRED_FOR_ACTIVATION_TYPE].container()); | 544 tasks[REQUIRED_FOR_ACTIVATION_TYPE].container()); |
| 552 } | 545 } |
| 553 | 546 |
| 554 scoped_refptr<internal::WorkerPoolTask> new_raster_finished_task; | 547 scoped_refptr<internal::WorkerPoolTask> new_raster_finished_task; |
| 555 | 548 |
| 556 size_t scheduled_raster_task_count = | 549 size_t scheduled_raster_task_count = |
| 557 tasks[PREPAINT_TYPE].container().size() + | 550 tasks[PREPAINT_TYPE].container().size() + |
| 558 tasks[REQUIRED_FOR_ACTIVATION_TYPE].container().size(); | 551 tasks[REQUIRED_FOR_ACTIVATION_TYPE].container().size(); |
| 559 DCHECK_LE(scheduled_raster_task_count, PendingRasterTaskCount()); | 552 DCHECK_LE(scheduled_raster_task_count, PendingRasterTaskCount()); |
| 560 // Schedule OnRasterTasksFinished call only when notification is pending | 553 // Schedule OnRasterTasksFinished call only when notification is pending |
| 561 // and throttling is not preventing all pending tasks from being scheduled. | 554 // and throttling is not preventing all pending tasks from being scheduled. |
| 562 if (scheduled_raster_task_count == PendingRasterTaskCount() && | 555 if (scheduled_raster_task_count == PendingRasterTaskCount() && |
| 563 should_notify_client_if_no_tasks_are_pending_) { | 556 should_notify_client_if_no_tasks_are_pending_) { |
| 564 new_raster_finished_task = CreateRasterFinishedTask(); | 557 new_raster_finished_task = CreateRasterFinishedTask(); |
| 565 raster_finished_task_pending_ = true; | |
| 566 internal::GraphNode* raster_finished_node = | 558 internal::GraphNode* raster_finished_node = |
| 567 CreateGraphNodeForTask(new_raster_finished_task.get(), | 559 CreateGraphNodeForTask(new_raster_finished_task.get(), |
| 568 1u, // Priority 1 | 560 1u, // Priority 1 |
| 569 &graph); | 561 &graph); |
| 570 for (unsigned type = 0; type < NUM_TYPES; ++type) { | 562 for (unsigned type = 0; type < NUM_TYPES; ++type) { |
| 571 AddDependenciesToGraphNode( | 563 AddDependenciesToGraphNode( |
| 572 raster_finished_node, | 564 raster_finished_node, |
| 573 tasks[type].container()); | 565 tasks[type].container()); |
| 574 } | 566 } |
| 575 } | 567 } |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 676 | 668 |
| 677 throttle_state->SetInteger("bytes_available_for_upload", | 669 throttle_state->SetInteger("bytes_available_for_upload", |
| 678 max_bytes_pending_upload_ - bytes_pending_upload_); | 670 max_bytes_pending_upload_ - bytes_pending_upload_); |
| 679 throttle_state->SetInteger("bytes_pending_upload", bytes_pending_upload_); | 671 throttle_state->SetInteger("bytes_pending_upload", bytes_pending_upload_); |
| 680 throttle_state->SetInteger("scheduled_raster_task_count", | 672 throttle_state->SetInteger("scheduled_raster_task_count", |
| 681 scheduled_raster_task_count_); | 673 scheduled_raster_task_count_); |
| 682 return throttle_state.PassAs<base::Value>(); | 674 return throttle_state.PassAs<base::Value>(); |
| 683 } | 675 } |
| 684 | 676 |
| 685 } // namespace cc | 677 } // namespace cc |
| OLD | NEW |