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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
90 const NodeVector::ContainerType& dependencies) { | 90 const NodeVector::ContainerType& dependencies) { |
91 for (NodeVector::ContainerType::const_iterator it = dependencies.begin(); | 91 for (NodeVector::ContainerType::const_iterator it = dependencies.begin(); |
92 it != dependencies.end(); ++it) { | 92 it != dependencies.end(); ++it) { |
93 internal::GraphNode* dependency = *it; | 93 internal::GraphNode* dependency = *it; |
94 | 94 |
95 node->add_dependency(); | 95 node->add_dependency(); |
96 dependency->add_dependent(node); | 96 dependency->add_dependent(node); |
97 } | 97 } |
98 } | 98 } |
99 | 99 |
100 // Only used as std::find_if predicate for DCHECKs. | |
101 bool WasCanceled(const internal::RasterWorkerPoolTask* task) { | |
102 return task->WasCanceled(); | |
103 } | |
104 | |
100 } // namespace | 105 } // namespace |
101 | 106 |
102 PixelBufferRasterWorkerPool::PixelBufferRasterWorkerPool( | 107 PixelBufferRasterWorkerPool::PixelBufferRasterWorkerPool( |
103 ResourceProvider* resource_provider, | 108 ResourceProvider* resource_provider, |
104 size_t num_threads) | 109 size_t num_threads) |
105 : RasterWorkerPool(resource_provider, num_threads), | 110 : RasterWorkerPool(resource_provider, num_threads), |
106 shutdown_(false), | 111 shutdown_(false), |
107 scheduled_raster_task_count_(0), | 112 scheduled_raster_task_count_(0), |
108 bytes_pending_upload_(0), | 113 bytes_pending_upload_(0), |
109 has_performed_uploads_since_last_flush_(false), | 114 has_performed_uploads_since_last_flush_(false), |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
193 } | 198 } |
194 | 199 |
195 tasks_required_for_activation_.clear(); | 200 tasks_required_for_activation_.clear(); |
196 for (TaskMap::iterator it = new_pixel_buffer_tasks.begin(); | 201 for (TaskMap::iterator it = new_pixel_buffer_tasks.begin(); |
197 it != new_pixel_buffer_tasks.end(); ++it) { | 202 it != new_pixel_buffer_tasks.end(); ++it) { |
198 internal::RasterWorkerPoolTask* task = it->first; | 203 internal::RasterWorkerPoolTask* task = it->first; |
199 if (IsRasterTaskRequiredForActivation(task)) | 204 if (IsRasterTaskRequiredForActivation(task)) |
200 tasks_required_for_activation_.insert(task); | 205 tasks_required_for_activation_.insert(task); |
201 } | 206 } |
202 | 207 |
208 // |tasks_required_for_activation_| contains all tasks that need to | |
209 // complete before we can send a "ready to activate" signal. Tasks | |
210 // that have already completed should not be part of this set. | |
211 for (TaskDeque::const_iterator it = completed_tasks_.begin(); | |
212 it != completed_tasks_.end(); ++it) { | |
213 tasks_required_for_activation_.erase(*it); | |
214 } | |
215 | |
203 pixel_buffer_tasks_.swap(new_pixel_buffer_tasks); | 216 pixel_buffer_tasks_.swap(new_pixel_buffer_tasks); |
204 | 217 |
205 // Check for completed tasks when ScheduleTasks() is called as | 218 // Check for completed tasks when ScheduleTasks() is called as |
206 // priorities might have changed and this maximizes the number | 219 // priorities might have changed and this maximizes the number |
207 // of top priority tasks that are scheduled. | 220 // of top priority tasks that are scheduled. |
208 RasterWorkerPool::CheckForCompletedTasks(); | 221 RasterWorkerPool::CheckForCompletedTasks(); |
209 CheckForCompletedUploads(); | 222 CheckForCompletedUploads(); |
210 FlushUploads(); | 223 FlushUploads(); |
211 | 224 |
212 // Schedule new tasks. | 225 // Schedule new tasks. |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
402 TRACE_EVENT_ASYNC_STEP1( | 415 TRACE_EVENT_ASYNC_STEP1( |
403 "cc", "ScheduledTasks", this, StateName(), | 416 "cc", "ScheduledTasks", this, StateName(), |
404 "state", TracedValue::FromValue(StateAsValue().release())); | 417 "state", TracedValue::FromValue(StateAsValue().release())); |
405 | 418 |
406 // Schedule another check for completed raster tasks while there are | 419 // Schedule another check for completed raster tasks while there are |
407 // pending raster tasks or pending uploads. | 420 // pending raster tasks or pending uploads. |
408 if (HasPendingTasks()) | 421 if (HasPendingTasks()) |
409 ScheduleCheckForCompletedRasterTasks(); | 422 ScheduleCheckForCompletedRasterTasks(); |
410 | 423 |
411 // Generate client notifications. | 424 // Generate client notifications. |
412 if (will_notify_client_that_no_tasks_required_for_activation_are_pending) | 425 if (will_notify_client_that_no_tasks_required_for_activation_are_pending) { |
426 DCHECK(std::find_if(raster_tasks_required_for_activation().begin(), | |
427 raster_tasks_required_for_activation().end(), | |
428 WasCanceled) == | |
429 raster_tasks_required_for_activation().end()); | |
413 client()->DidFinishedRunningTasksRequiredForActivation(); | 430 client()->DidFinishedRunningTasksRequiredForActivation(); |
431 } | |
414 if (will_notify_client_that_no_tasks_are_pending) { | 432 if (will_notify_client_that_no_tasks_are_pending) { |
415 TRACE_EVENT_ASYNC_END0("cc", "ScheduledTasks", this); | 433 TRACE_EVENT_ASYNC_END0("cc", "ScheduledTasks", this); |
434 DCHECK(!HasPendingTasksRequiredForActivation()); | |
416 client()->DidFinishedRunningTasks(); | 435 client()->DidFinishedRunningTasks(); |
417 } | 436 } |
418 } | 437 } |
419 | 438 |
420 void PixelBufferRasterWorkerPool::ScheduleMoreTasks() { | 439 void PixelBufferRasterWorkerPool::ScheduleMoreTasks() { |
421 TRACE_EVENT0("cc", "PixelBufferRasterWorkerPool::ScheduleMoreTasks"); | 440 TRACE_EVENT0("cc", "PixelBufferRasterWorkerPool::ScheduleMoreTasks"); |
422 | 441 |
423 enum RasterTaskType { | 442 enum RasterTaskType { |
424 PREPAINT_TYPE = 0, | 443 PREPAINT_TYPE = 0, |
425 REQUIRED_FOR_ACTIVATION_TYPE = 1, | 444 REQUIRED_FOR_ACTIVATION_TYPE = 1, |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
575 "was_canceled", was_canceled, | 594 "was_canceled", was_canceled, |
576 "needs_upload", needs_upload); | 595 "needs_upload", needs_upload); |
577 | 596 |
578 DCHECK(pixel_buffer_tasks_.find(task.get()) != pixel_buffer_tasks_.end()); | 597 DCHECK(pixel_buffer_tasks_.find(task.get()) != pixel_buffer_tasks_.end()); |
579 | 598 |
580 // Balanced with MapPixelBuffer() call in ScheduleMoreTasks(). | 599 // Balanced with MapPixelBuffer() call in ScheduleMoreTasks(). |
581 resource_provider()->UnmapPixelBuffer(task->resource()->id()); | 600 resource_provider()->UnmapPixelBuffer(task->resource()->id()); |
582 | 601 |
583 if (!needs_upload) { | 602 if (!needs_upload) { |
584 resource_provider()->ReleasePixelBuffer(task->resource()->id()); | 603 resource_provider()->ReleasePixelBuffer(task->resource()->id()); |
604 | |
605 if (was_canceled) { | |
606 // When priorites change, a raster task can be canceled as a result of | |
607 // no longer being of high enough priority to fit in our throttled | |
608 // raster task budget. The task has not yet completed in this case. | |
609 RasterTaskVector::const_iterator it = std::find(raster_tasks().begin(), | |
610 raster_tasks().end(), | |
611 task); | |
612 if (it != raster_tasks().end()) { | |
613 pixel_buffer_tasks_[task.get()] = NULL; | |
614 return; | |
615 } | |
616 } | |
617 | |
585 task->DidRun(was_canceled); | 618 task->DidRun(was_canceled); |
586 DCHECK(std::find(completed_tasks_.begin(), | 619 DCHECK(std::find(completed_tasks_.begin(), |
587 completed_tasks_.end(), | 620 completed_tasks_.end(), |
588 task) == completed_tasks_.end()); | 621 task) == completed_tasks_.end()); |
589 completed_tasks_.push_back(task); | 622 completed_tasks_.push_back(task); |
590 tasks_required_for_activation_.erase(task); | 623 tasks_required_for_activation_.erase(task); |
591 return; | 624 return; |
592 } | 625 } |
593 | 626 |
627 DCHECK(!was_canceled); | |
vmpstr
2013/07/11 17:55:12
nit: I would also prefer DCHECK(!was_canceled || !
vmpstr
2013/07/11 18:12:55
Nevermind this, I missed the fact that the if retu
| |
628 | |
594 resource_provider()->BeginSetPixels(task->resource()->id()); | 629 resource_provider()->BeginSetPixels(task->resource()->id()); |
595 has_performed_uploads_since_last_flush_ = true; | 630 has_performed_uploads_since_last_flush_ = true; |
596 | 631 |
597 bytes_pending_upload_ += task->resource()->bytes(); | 632 bytes_pending_upload_ += task->resource()->bytes(); |
598 tasks_with_pending_upload_.push_back(task); | 633 tasks_with_pending_upload_.push_back(task); |
599 } | 634 } |
600 | 635 |
601 unsigned PixelBufferRasterWorkerPool::PendingRasterTaskCount() const { | 636 unsigned PixelBufferRasterWorkerPool::PendingRasterTaskCount() const { |
602 unsigned num_completed_raster_tasks = | 637 unsigned num_completed_raster_tasks = |
603 tasks_with_pending_upload_.size() + completed_tasks_.size(); | 638 tasks_with_pending_upload_.size() + completed_tasks_.size(); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
643 | 678 |
644 throttle_state->SetInteger("bytes_available_for_upload", | 679 throttle_state->SetInteger("bytes_available_for_upload", |
645 kMaxPendingUploadBytes - bytes_pending_upload_); | 680 kMaxPendingUploadBytes - bytes_pending_upload_); |
646 throttle_state->SetInteger("bytes_pending_upload", bytes_pending_upload_); | 681 throttle_state->SetInteger("bytes_pending_upload", bytes_pending_upload_); |
647 throttle_state->SetInteger("scheduled_raster_task_count", | 682 throttle_state->SetInteger("scheduled_raster_task_count", |
648 scheduled_raster_task_count_); | 683 scheduled_raster_task_count_); |
649 return throttle_state.PassAs<base::Value>(); | 684 return throttle_state.PassAs<base::Value>(); |
650 } | 685 } |
651 | 686 |
652 } // namespace cc | 687 } // namespace cc |
OLD | NEW |