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 bool WasCanceled(const internal::RasterWorkerPoolTask* task) { | |
vmpstr
2013/07/10 16:46:49
If this is only for a DCHECK, maybe we can name it
reveman
2013/07/11 00:37:21
ForDebug in the name makes it sound like it's chec
| |
101 return task->WasCanceled(); | |
102 } | |
103 | |
100 } // namespace | 104 } // namespace |
101 | 105 |
102 PixelBufferRasterWorkerPool::PixelBufferRasterWorkerPool( | 106 PixelBufferRasterWorkerPool::PixelBufferRasterWorkerPool( |
103 ResourceProvider* resource_provider, | 107 ResourceProvider* resource_provider, |
104 size_t num_threads) | 108 size_t num_threads) |
105 : RasterWorkerPool(resource_provider, num_threads), | 109 : RasterWorkerPool(resource_provider, num_threads), |
106 shutdown_(false), | 110 shutdown_(false), |
107 scheduled_raster_task_count_(0), | 111 scheduled_raster_task_count_(0), |
108 bytes_pending_upload_(0), | 112 bytes_pending_upload_(0), |
109 has_performed_uploads_since_last_flush_(false), | 113 has_performed_uploads_since_last_flush_(false), |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
193 } | 197 } |
194 | 198 |
195 tasks_required_for_activation_.clear(); | 199 tasks_required_for_activation_.clear(); |
196 for (TaskMap::iterator it = new_pixel_buffer_tasks.begin(); | 200 for (TaskMap::iterator it = new_pixel_buffer_tasks.begin(); |
197 it != new_pixel_buffer_tasks.end(); ++it) { | 201 it != new_pixel_buffer_tasks.end(); ++it) { |
198 internal::RasterWorkerPoolTask* task = it->first; | 202 internal::RasterWorkerPoolTask* task = it->first; |
199 if (IsRasterTaskRequiredForActivation(task)) | 203 if (IsRasterTaskRequiredForActivation(task)) |
200 tasks_required_for_activation_.insert(task); | 204 tasks_required_for_activation_.insert(task); |
201 } | 205 } |
202 | 206 |
207 // |tasks_required_for_activation_| contains all tasks that need to | |
208 // complete before we can send a "ready to activate" signal. Tasks | |
209 // that have already completed should not be part of this set. | |
210 for (TaskDeque::const_iterator it = completed_tasks_.begin(); | |
vmpstr
2013/07/10 16:46:49
I think we can fold this loop and the one above in
reveman
2013/07/11 00:37:21
This and ScheduleMoreTasks needs a rewrite at some
| |
211 it != completed_tasks_.end(); ++it) { | |
212 tasks_required_for_activation_.erase(*it); | |
213 } | |
214 | |
203 pixel_buffer_tasks_.swap(new_pixel_buffer_tasks); | 215 pixel_buffer_tasks_.swap(new_pixel_buffer_tasks); |
204 | 216 |
205 // Check for completed tasks when ScheduleTasks() is called as | 217 // Check for completed tasks when ScheduleTasks() is called as |
206 // priorities might have changed and this maximizes the number | 218 // priorities might have changed and this maximizes the number |
207 // of top priority tasks that are scheduled. | 219 // of top priority tasks that are scheduled. |
208 RasterWorkerPool::CheckForCompletedTasks(); | 220 RasterWorkerPool::CheckForCompletedTasks(); |
209 CheckForCompletedUploads(); | 221 CheckForCompletedUploads(); |
210 FlushUploads(); | 222 FlushUploads(); |
211 | 223 |
212 // Schedule new tasks. | 224 // Schedule new tasks. |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
402 TRACE_EVENT_ASYNC_STEP1( | 414 TRACE_EVENT_ASYNC_STEP1( |
403 "cc", "ScheduledTasks", this, StateName(), | 415 "cc", "ScheduledTasks", this, StateName(), |
404 "state", TracedValue::FromValue(StateAsValue().release())); | 416 "state", TracedValue::FromValue(StateAsValue().release())); |
405 | 417 |
406 // Schedule another check for completed raster tasks while there are | 418 // Schedule another check for completed raster tasks while there are |
407 // pending raster tasks or pending uploads. | 419 // pending raster tasks or pending uploads. |
408 if (HasPendingTasks()) | 420 if (HasPendingTasks()) |
409 ScheduleCheckForCompletedRasterTasks(); | 421 ScheduleCheckForCompletedRasterTasks(); |
410 | 422 |
411 // Generate client notifications. | 423 // Generate client notifications. |
412 if (will_notify_client_that_no_tasks_required_for_activation_are_pending) | 424 if (will_notify_client_that_no_tasks_required_for_activation_are_pending) { |
425 DCHECK(std::find_if(raster_tasks_required_for_activation().begin(), | |
426 raster_tasks_required_for_activation().end(), | |
427 WasCanceled) == | |
428 raster_tasks_required_for_activation().end()); | |
413 client()->DidFinishedRunningTasksRequiredForActivation(); | 429 client()->DidFinishedRunningTasksRequiredForActivation(); |
430 } | |
414 if (will_notify_client_that_no_tasks_are_pending) { | 431 if (will_notify_client_that_no_tasks_are_pending) { |
415 TRACE_EVENT_ASYNC_END0("cc", "ScheduledTasks", this); | 432 TRACE_EVENT_ASYNC_END0("cc", "ScheduledTasks", this); |
433 DCHECK(!HasPendingTasksRequiredForActivation()); | |
416 client()->DidFinishedRunningTasks(); | 434 client()->DidFinishedRunningTasks(); |
417 } | 435 } |
418 } | 436 } |
419 | 437 |
420 void PixelBufferRasterWorkerPool::ScheduleMoreTasks() { | 438 void PixelBufferRasterWorkerPool::ScheduleMoreTasks() { |
421 TRACE_EVENT0("cc", "PixelBufferRasterWorkerPool::ScheduleMoreTasks"); | 439 TRACE_EVENT0("cc", "PixelBufferRasterWorkerPool::ScheduleMoreTasks"); |
422 | 440 |
423 enum RasterTaskType { | 441 enum RasterTaskType { |
424 PREPAINT_TYPE = 0, | 442 PREPAINT_TYPE = 0, |
425 REQUIRED_FOR_ACTIVATION_TYPE = 1, | 443 REQUIRED_FOR_ACTIVATION_TYPE = 1, |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
575 "was_canceled", was_canceled, | 593 "was_canceled", was_canceled, |
576 "needs_upload", needs_upload); | 594 "needs_upload", needs_upload); |
577 | 595 |
578 DCHECK(pixel_buffer_tasks_.find(task.get()) != pixel_buffer_tasks_.end()); | 596 DCHECK(pixel_buffer_tasks_.find(task.get()) != pixel_buffer_tasks_.end()); |
579 | 597 |
580 // Balanced with MapPixelBuffer() call in ScheduleMoreTasks(). | 598 // Balanced with MapPixelBuffer() call in ScheduleMoreTasks(). |
581 resource_provider()->UnmapPixelBuffer(task->resource()->id()); | 599 resource_provider()->UnmapPixelBuffer(task->resource()->id()); |
582 | 600 |
583 if (!needs_upload) { | 601 if (!needs_upload) { |
584 resource_provider()->ReleasePixelBuffer(task->resource()->id()); | 602 resource_provider()->ReleasePixelBuffer(task->resource()->id()); |
603 | |
604 if (was_canceled) { | |
vmpstr
2013/07/10 16:46:49
Does was_canceled guarantee that needs_upload is f
reveman
2013/07/11 00:37:21
Yes, see PixelBufferWorkerPoolTaskImpl above. I ad
| |
605 // When priorites change, a raster task can be canceled as a result of | |
606 // no longer being of high enough priority to fit in our throttled | |
607 // raster task budget. The task has not yet completed in this case. | |
608 if (std::find(raster_tasks().begin(), | |
vmpstr
2013/07/10 16:46:49
I prefer you save the iterator first, then do the
reveman
2013/07/11 00:37:21
Done.
| |
609 raster_tasks().end(), | |
610 task) != raster_tasks().end()) { | |
611 pixel_buffer_tasks_[task.get()] = NULL; | |
612 return; | |
613 } | |
614 } | |
615 | |
585 task->DidRun(was_canceled); | 616 task->DidRun(was_canceled); |
586 DCHECK(std::find(completed_tasks_.begin(), | 617 DCHECK(std::find(completed_tasks_.begin(), |
587 completed_tasks_.end(), | 618 completed_tasks_.end(), |
588 task) == completed_tasks_.end()); | 619 task) == completed_tasks_.end()); |
589 completed_tasks_.push_back(task); | 620 completed_tasks_.push_back(task); |
590 tasks_required_for_activation_.erase(task); | 621 tasks_required_for_activation_.erase(task); |
591 return; | 622 return; |
592 } | 623 } |
593 | 624 |
594 resource_provider()->BeginSetPixels(task->resource()->id()); | 625 resource_provider()->BeginSetPixels(task->resource()->id()); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
643 | 674 |
644 throttle_state->SetInteger("bytes_available_for_upload", | 675 throttle_state->SetInteger("bytes_available_for_upload", |
645 kMaxPendingUploadBytes - bytes_pending_upload_); | 676 kMaxPendingUploadBytes - bytes_pending_upload_); |
646 throttle_state->SetInteger("bytes_pending_upload", bytes_pending_upload_); | 677 throttle_state->SetInteger("bytes_pending_upload", bytes_pending_upload_); |
647 throttle_state->SetInteger("scheduled_raster_task_count", | 678 throttle_state->SetInteger("scheduled_raster_task_count", |
648 scheduled_raster_task_count_); | 679 scheduled_raster_task_count_); |
649 return throttle_state.PassAs<base::Value>(); | 680 return throttle_state.PassAs<base::Value>(); |
650 } | 681 } |
651 | 682 |
652 } // namespace cc | 683 } // namespace cc |
OLD | NEW |