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