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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 | 84 |
85 // Only used as std::find_if predicate for DCHECKs. | 85 // Only used as std::find_if predicate for DCHECKs. |
86 bool WasCanceled(const internal::RasterWorkerPoolTask* task) { | 86 bool WasCanceled(const internal::RasterWorkerPoolTask* task) { |
87 return task->WasCanceled(); | 87 return task->WasCanceled(); |
88 } | 88 } |
89 | 89 |
90 } // namespace | 90 } // namespace |
91 | 91 |
92 PixelBufferRasterWorkerPool::PixelBufferRasterWorkerPool( | 92 PixelBufferRasterWorkerPool::PixelBufferRasterWorkerPool( |
93 ResourceProvider* resource_provider, | 93 ResourceProvider* resource_provider, |
| 94 ContextProvider* context_provider, |
94 size_t num_threads, | 95 size_t num_threads, |
95 size_t max_transfer_buffer_usage_bytes) | 96 size_t max_transfer_buffer_usage_bytes) |
96 : RasterWorkerPool(resource_provider, num_threads), | 97 : RasterWorkerPool(resource_provider, context_provider, num_threads), |
97 shutdown_(false), | 98 shutdown_(false), |
98 scheduled_raster_task_count_(0), | 99 scheduled_raster_task_count_(0), |
99 bytes_pending_upload_(0), | 100 bytes_pending_upload_(0), |
100 max_bytes_pending_upload_(max_transfer_buffer_usage_bytes), | 101 max_bytes_pending_upload_(max_transfer_buffer_usage_bytes), |
101 has_performed_uploads_since_last_flush_(false), | 102 has_performed_uploads_since_last_flush_(false), |
102 check_for_completed_raster_tasks_pending_(false), | 103 check_for_completed_raster_tasks_pending_(false), |
103 should_notify_client_if_no_tasks_are_pending_(false), | 104 should_notify_client_if_no_tasks_are_pending_(false), |
104 should_notify_client_if_no_tasks_required_for_activation_are_pending_( | 105 should_notify_client_if_no_tasks_required_for_activation_are_pending_( |
105 false), | 106 false), |
106 raster_finished_task_pending_(false), | 107 raster_finished_task_pending_(false), |
107 raster_required_for_activation_finished_task_pending_(false) { | 108 raster_required_for_activation_finished_task_pending_(false) { |
108 } | 109 } |
109 | 110 |
110 PixelBufferRasterWorkerPool::~PixelBufferRasterWorkerPool() { | 111 PixelBufferRasterWorkerPool::~PixelBufferRasterWorkerPool() { |
111 DCHECK(shutdown_); | 112 DCHECK(shutdown_); |
112 DCHECK(!check_for_completed_raster_tasks_pending_); | 113 DCHECK(!check_for_completed_raster_tasks_pending_); |
113 DCHECK_EQ(0u, pixel_buffer_tasks_.size()); | 114 DCHECK_EQ(0u, pixel_buffer_tasks_.size()); |
114 DCHECK_EQ(0u, tasks_with_pending_upload_.size()); | 115 DCHECK_EQ(0u, tasks_with_pending_upload_.size()); |
115 DCHECK_EQ(0u, completed_tasks_.size()); | 116 DCHECK_EQ(0u, completed_tasks_.size()); |
116 } | 117 } |
117 | 118 |
118 void PixelBufferRasterWorkerPool::Shutdown() { | 119 void PixelBufferRasterWorkerPool::Shutdown() { |
119 shutdown_ = true; | 120 shutdown_ = true; |
120 RasterWorkerPool::Shutdown(); | 121 RasterWorkerPool::Shutdown(); |
121 RasterWorkerPool::CheckForCompletedTasks(); | 122 CheckForCompletedWorkerTasks(); |
122 CheckForCompletedUploads(); | 123 CheckForCompletedUploads(); |
123 check_for_completed_raster_tasks_callback_.Cancel(); | 124 check_for_completed_raster_tasks_callback_.Cancel(); |
124 check_for_completed_raster_tasks_pending_ = false; | 125 check_for_completed_raster_tasks_pending_ = false; |
125 for (TaskMap::iterator it = pixel_buffer_tasks_.begin(); | 126 for (TaskMap::iterator it = pixel_buffer_tasks_.begin(); |
126 it != pixel_buffer_tasks_.end(); ++it) { | 127 it != pixel_buffer_tasks_.end(); ++it) { |
127 internal::RasterWorkerPoolTask* task = it->first; | 128 internal::RasterWorkerPoolTask* task = it->first; |
128 internal::WorkerPoolTask* pixel_buffer_task = it->second.get(); | 129 internal::WorkerPoolTask* pixel_buffer_task = it->second.get(); |
129 | 130 |
130 // All inactive tasks needs to be canceled. | 131 // All inactive tasks needs to be canceled. |
131 if (!pixel_buffer_task && !task->HasFinishedRunning()) { | 132 if (!pixel_buffer_task && !task->HasFinishedRunning()) { |
(...skipping 12 matching lines...) Expand all Loading... |
144 if (!should_notify_client_if_no_tasks_are_pending_) | 145 if (!should_notify_client_if_no_tasks_are_pending_) |
145 TRACE_EVENT_ASYNC_BEGIN0("cc", "ScheduledTasks", this); | 146 TRACE_EVENT_ASYNC_BEGIN0("cc", "ScheduledTasks", this); |
146 | 147 |
147 should_notify_client_if_no_tasks_are_pending_ = true; | 148 should_notify_client_if_no_tasks_are_pending_ = true; |
148 should_notify_client_if_no_tasks_required_for_activation_are_pending_ = true; | 149 should_notify_client_if_no_tasks_required_for_activation_are_pending_ = true; |
149 | 150 |
150 tasks_required_for_activation_.clear(); | 151 tasks_required_for_activation_.clear(); |
151 | 152 |
152 // Build new pixel buffer task set. | 153 // Build new pixel buffer task set. |
153 TaskMap new_pixel_buffer_tasks; | 154 TaskMap new_pixel_buffer_tasks; |
| 155 RasterTaskVector gpu_raster_tasks; |
154 for (RasterTaskVector::const_iterator it = raster_tasks().begin(); | 156 for (RasterTaskVector::const_iterator it = raster_tasks().begin(); |
155 it != raster_tasks().end(); ++it) { | 157 it != raster_tasks().end(); ++it) { |
156 internal::RasterWorkerPoolTask* task = it->get(); | 158 internal::RasterWorkerPoolTask* task = it->get(); |
157 DCHECK(new_pixel_buffer_tasks.find(task) == new_pixel_buffer_tasks.end()); | 159 DCHECK(new_pixel_buffer_tasks.find(task) == new_pixel_buffer_tasks.end()); |
158 DCHECK(!task->HasCompleted()); | 160 DCHECK(!task->HasCompleted()); |
159 DCHECK(!task->WasCanceled()); | 161 DCHECK(!task->WasCanceled()); |
160 | 162 |
| 163 if (task->use_gpu_rasterization()) { |
| 164 gpu_raster_tasks.push_back(task); |
| 165 continue; |
| 166 } |
| 167 |
161 new_pixel_buffer_tasks[task] = pixel_buffer_tasks_[task]; | 168 new_pixel_buffer_tasks[task] = pixel_buffer_tasks_[task]; |
162 pixel_buffer_tasks_.erase(task); | 169 pixel_buffer_tasks_.erase(task); |
163 | 170 |
164 if (IsRasterTaskRequiredForActivation(task)) | 171 if (IsRasterTaskRequiredForActivation(task)) |
165 tasks_required_for_activation_.insert(task); | 172 tasks_required_for_activation_.insert(task); |
166 } | 173 } |
167 | 174 |
168 // Transfer remaining pixel buffer tasks to |new_pixel_buffer_tasks| | 175 // Transfer remaining pixel buffer tasks to |new_pixel_buffer_tasks| |
169 // and cancel all remaining inactive tasks. | 176 // and cancel all remaining inactive tasks. |
170 for (TaskMap::iterator it = pixel_buffer_tasks_.begin(); | 177 for (TaskMap::iterator it = pixel_buffer_tasks_.begin(); |
(...skipping 23 matching lines...) Expand all Loading... |
194 it != completed_tasks_.end() && !tasks_required_for_activation_.empty(); | 201 it != completed_tasks_.end() && !tasks_required_for_activation_.empty(); |
195 ++it) { | 202 ++it) { |
196 tasks_required_for_activation_.erase(*it); | 203 tasks_required_for_activation_.erase(*it); |
197 } | 204 } |
198 | 205 |
199 pixel_buffer_tasks_.swap(new_pixel_buffer_tasks); | 206 pixel_buffer_tasks_.swap(new_pixel_buffer_tasks); |
200 | 207 |
201 // Check for completed tasks when ScheduleTasks() is called as | 208 // Check for completed tasks when ScheduleTasks() is called as |
202 // priorities might have changed and this maximizes the number | 209 // priorities might have changed and this maximizes the number |
203 // of top priority tasks that are scheduled. | 210 // of top priority tasks that are scheduled. |
204 RasterWorkerPool::CheckForCompletedTasks(); | 211 CheckForCompletedWorkerTasks(); |
205 CheckForCompletedUploads(); | 212 CheckForCompletedUploads(); |
206 FlushUploads(); | 213 FlushUploads(); |
207 | 214 |
208 // Schedule new tasks. | 215 // Schedule new tasks. |
209 ScheduleMoreTasks(); | 216 ScheduleMoreTasks(); |
210 | 217 |
211 // Cancel any pending check for completed raster tasks and schedule | 218 // Cancel any pending check for completed raster tasks and schedule |
212 // another check. | 219 // another check. |
213 check_for_completed_raster_tasks_callback_.Cancel(); | 220 check_for_completed_raster_tasks_callback_.Cancel(); |
214 check_for_completed_raster_tasks_pending_ = false; | 221 check_for_completed_raster_tasks_pending_ = false; |
215 ScheduleCheckForCompletedRasterTasks(); | 222 ScheduleCheckForCompletedRasterTasks(); |
216 | 223 |
| 224 RunGpuRasterTasks(gpu_raster_tasks); |
| 225 |
217 TRACE_EVENT_ASYNC_STEP_INTO1( | 226 TRACE_EVENT_ASYNC_STEP_INTO1( |
218 "cc", "ScheduledTasks", this, StateName(), | 227 "cc", "ScheduledTasks", this, StateName(), |
219 "state", TracedValue::FromValue(StateAsValue().release())); | 228 "state", TracedValue::FromValue(StateAsValue().release())); |
220 } | 229 } |
221 | 230 |
222 GLenum PixelBufferRasterWorkerPool::GetResourceTarget() const { | 231 GLenum PixelBufferRasterWorkerPool::GetResourceTarget() const { |
223 return GL_TEXTURE_2D; | 232 return GL_TEXTURE_2D; |
224 } | 233 } |
225 | 234 |
226 ResourceFormat PixelBufferRasterWorkerPool::GetResourceFormat() const { | 235 ResourceFormat PixelBufferRasterWorkerPool::GetResourceFormat() const { |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 | 385 |
377 void PixelBufferRasterWorkerPool::CheckForCompletedRasterTasks() { | 386 void PixelBufferRasterWorkerPool::CheckForCompletedRasterTasks() { |
378 TRACE_EVENT0( | 387 TRACE_EVENT0( |
379 "cc", "PixelBufferRasterWorkerPool::CheckForCompletedRasterTasks"); | 388 "cc", "PixelBufferRasterWorkerPool::CheckForCompletedRasterTasks"); |
380 | 389 |
381 DCHECK(should_notify_client_if_no_tasks_are_pending_); | 390 DCHECK(should_notify_client_if_no_tasks_are_pending_); |
382 | 391 |
383 check_for_completed_raster_tasks_callback_.Cancel(); | 392 check_for_completed_raster_tasks_callback_.Cancel(); |
384 check_for_completed_raster_tasks_pending_ = false; | 393 check_for_completed_raster_tasks_pending_ = false; |
385 | 394 |
386 RasterWorkerPool::CheckForCompletedTasks(); | 395 CheckForCompletedWorkerTasks(); |
387 CheckForCompletedUploads(); | 396 CheckForCompletedUploads(); |
388 FlushUploads(); | 397 FlushUploads(); |
389 | 398 |
390 // Determine what client notifications to generate. | 399 // Determine what client notifications to generate. |
391 bool will_notify_client_that_no_tasks_required_for_activation_are_pending = | 400 bool will_notify_client_that_no_tasks_required_for_activation_are_pending = |
392 (should_notify_client_if_no_tasks_required_for_activation_are_pending_ && | 401 (should_notify_client_if_no_tasks_required_for_activation_are_pending_ && |
393 !raster_required_for_activation_finished_task_pending_ && | 402 !raster_required_for_activation_finished_task_pending_ && |
394 !HasPendingTasksRequiredForActivation()); | 403 !HasPendingTasksRequiredForActivation()); |
395 bool will_notify_client_that_no_tasks_are_pending = | 404 bool will_notify_client_that_no_tasks_are_pending = |
396 (should_notify_client_if_no_tasks_are_pending_ && | 405 (should_notify_client_if_no_tasks_are_pending_ && |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
585 | 594 |
586 void PixelBufferRasterWorkerPool::OnRasterTaskCompleted( | 595 void PixelBufferRasterWorkerPool::OnRasterTaskCompleted( |
587 scoped_refptr<internal::RasterWorkerPoolTask> task, | 596 scoped_refptr<internal::RasterWorkerPoolTask> task, |
588 bool was_canceled, | 597 bool was_canceled, |
589 bool needs_upload) { | 598 bool needs_upload) { |
590 TRACE_EVENT2(TRACE_DISABLED_BY_DEFAULT("cc"), | 599 TRACE_EVENT2(TRACE_DISABLED_BY_DEFAULT("cc"), |
591 "PixelBufferRasterWorkerPool::OnRasterTaskCompleted", | 600 "PixelBufferRasterWorkerPool::OnRasterTaskCompleted", |
592 "was_canceled", was_canceled, | 601 "was_canceled", was_canceled, |
593 "needs_upload", needs_upload); | 602 "needs_upload", needs_upload); |
594 | 603 |
| 604 DCHECK(!task->use_gpu_rasterization()); |
595 DCHECK(pixel_buffer_tasks_.find(task.get()) != pixel_buffer_tasks_.end()); | 605 DCHECK(pixel_buffer_tasks_.find(task.get()) != pixel_buffer_tasks_.end()); |
596 | 606 |
597 // Balanced with MapPixelBuffer() call in ScheduleMoreTasks(). | 607 // Balanced with MapPixelBuffer() call in ScheduleMoreTasks(). |
598 resource_provider()->UnmapPixelBuffer(task->resource()->id()); | 608 resource_provider()->UnmapPixelBuffer(task->resource()->id()); |
599 | 609 |
600 if (!needs_upload) { | 610 if (!needs_upload) { |
601 resource_provider()->ReleasePixelBuffer(task->resource()->id()); | 611 resource_provider()->ReleasePixelBuffer(task->resource()->id()); |
602 | 612 |
603 if (was_canceled) { | 613 if (was_canceled) { |
604 // When priorites change, a raster task can be canceled as a result of | 614 // When priorites change, a raster task can be canceled as a result of |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
676 | 686 |
677 throttle_state->SetInteger("bytes_available_for_upload", | 687 throttle_state->SetInteger("bytes_available_for_upload", |
678 max_bytes_pending_upload_ - bytes_pending_upload_); | 688 max_bytes_pending_upload_ - bytes_pending_upload_); |
679 throttle_state->SetInteger("bytes_pending_upload", bytes_pending_upload_); | 689 throttle_state->SetInteger("bytes_pending_upload", bytes_pending_upload_); |
680 throttle_state->SetInteger("scheduled_raster_task_count", | 690 throttle_state->SetInteger("scheduled_raster_task_count", |
681 scheduled_raster_task_count_); | 691 scheduled_raster_task_count_); |
682 return throttle_state.PassAs<base::Value>(); | 692 return throttle_state.PassAs<base::Value>(); |
683 } | 693 } |
684 | 694 |
685 } // namespace cc | 695 } // namespace cc |
OLD | NEW |