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 <algorithm> |
| 8 |
7 #include "base/containers/stack_container.h" | 9 #include "base/containers/stack_container.h" |
8 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
9 #include "base/values.h" | 11 #include "base/values.h" |
10 #include "cc/debug/traced_value.h" | 12 #include "cc/debug/traced_value.h" |
11 #include "cc/resources/resource.h" | 13 #include "cc/resources/resource.h" |
12 | 14 |
13 namespace cc { | 15 namespace cc { |
14 namespace { | 16 namespace { |
15 | 17 |
16 const int kCheckForCompletedRasterTasksDelayMs = 6; | 18 const int kCheckForCompletedRasterTasksDelayMs = 6; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 void PixelBufferRasterWorkerPool::Shutdown() { | 69 void PixelBufferRasterWorkerPool::Shutdown() { |
68 shutdown_ = true; | 70 shutdown_ = true; |
69 RasterWorkerPool::Shutdown(); | 71 RasterWorkerPool::Shutdown(); |
70 | 72 |
71 CheckForCompletedWorkerPoolTasks(); | 73 CheckForCompletedWorkerPoolTasks(); |
72 CheckForCompletedUploads(); | 74 CheckForCompletedUploads(); |
73 | 75 |
74 weak_factory_.InvalidateWeakPtrs(); | 76 weak_factory_.InvalidateWeakPtrs(); |
75 check_for_completed_raster_tasks_pending_ = false; | 77 check_for_completed_raster_tasks_pending_ = false; |
76 | 78 |
77 for (RasterTaskStateMap::iterator it = raster_task_states_.begin(); | 79 for (RasterTaskState::Vector::iterator it = raster_task_states_.begin(); |
78 it != raster_task_states_.end(); | 80 it != raster_task_states_.end(); |
79 ++it) { | 81 ++it) { |
80 internal::WorkerPoolTask* task = it->first; | 82 RasterTaskState& state = *it; |
81 RasterTaskState& state = it->second; | |
82 | 83 |
83 // All unscheduled tasks need to be canceled. | 84 // All unscheduled tasks need to be canceled. |
84 if (state.type == RasterTaskState::UNSCHEDULED) { | 85 if (state.type == RasterTaskState::UNSCHEDULED) { |
85 completed_raster_tasks_.push_back(task); | 86 completed_raster_tasks_.push_back(state.task); |
86 state.type = RasterTaskState::COMPLETED; | 87 state.type = RasterTaskState::COMPLETED; |
87 } | 88 } |
88 } | 89 } |
89 DCHECK_EQ(completed_raster_tasks_.size(), raster_task_states_.size()); | 90 DCHECK_EQ(completed_raster_tasks_.size(), raster_task_states_.size()); |
90 } | 91 } |
91 | 92 |
92 void PixelBufferRasterWorkerPool::ScheduleTasks(RasterTaskQueue* queue) { | 93 void PixelBufferRasterWorkerPool::ScheduleTasks(RasterTaskQueue* queue) { |
93 TRACE_EVENT0("cc", "PixelBufferRasterWorkerPool::ScheduleTasks"); | 94 TRACE_EVENT0("cc", "PixelBufferRasterWorkerPool::ScheduleTasks"); |
94 | 95 |
95 DCHECK_EQ(queue->required_for_activation_count, | 96 DCHECK_EQ(queue->required_for_activation_count, |
96 static_cast<size_t>( | 97 static_cast<size_t>( |
97 std::count_if(queue->items.begin(), | 98 std::count_if(queue->items.begin(), |
98 queue->items.end(), | 99 queue->items.end(), |
99 RasterTaskQueue::Item::IsRequiredForActivation))); | 100 RasterTaskQueue::Item::IsRequiredForActivation))); |
100 | 101 |
101 if (!should_notify_client_if_no_tasks_are_pending_) | 102 if (!should_notify_client_if_no_tasks_are_pending_) |
102 TRACE_EVENT_ASYNC_BEGIN0("cc", "ScheduledTasks", this); | 103 TRACE_EVENT_ASYNC_BEGIN0("cc", "ScheduledTasks", this); |
103 | 104 |
104 should_notify_client_if_no_tasks_are_pending_ = true; | 105 should_notify_client_if_no_tasks_are_pending_ = true; |
105 should_notify_client_if_no_tasks_required_for_activation_are_pending_ = true; | 106 should_notify_client_if_no_tasks_required_for_activation_are_pending_ = true; |
106 | 107 |
107 raster_tasks_required_for_activation_count_ = 0u; | 108 raster_tasks_required_for_activation_count_ = 0u; |
108 | 109 |
109 // Build new raster task state map. | 110 // Update raster task state and remove items from old queue. |
110 RasterTaskStateMap new_raster_task_states; | |
111 for (RasterTaskQueue::Item::Vector::const_iterator it = queue->items.begin(); | 111 for (RasterTaskQueue::Item::Vector::const_iterator it = queue->items.begin(); |
112 it != queue->items.end(); | 112 it != queue->items.end(); |
113 ++it) { | 113 ++it) { |
114 const RasterTaskQueue::Item& item = *it; | 114 const RasterTaskQueue::Item& item = *it; |
115 internal::WorkerPoolTask* task = item.task; | 115 internal::WorkerPoolTask* task = item.task; |
116 DCHECK(new_raster_task_states.find(task) == new_raster_task_states.end()); | |
117 | 116 |
118 RasterTaskStateMap::iterator state_it = raster_task_states_.find(task); | 117 // Remove any old items that are associated with this task. The result is |
| 118 // that the old queue is left with all items not present in this queue, |
| 119 // which we use below to determine what tasks need to be canceled. |
| 120 RasterTaskQueue::Item::Vector::iterator old_it = |
| 121 std::find_if(raster_tasks_.items.begin(), |
| 122 raster_tasks_.items.end(), |
| 123 RasterTaskQueue::Item::TaskComparator(task)); |
| 124 if (old_it != raster_tasks_.items.end()) { |
| 125 std::swap(*old_it, raster_tasks_.items.back()); |
| 126 raster_tasks_.items.pop_back(); |
| 127 } |
| 128 |
| 129 RasterTaskState::Vector::iterator state_it = |
| 130 std::find_if(raster_task_states_.begin(), |
| 131 raster_task_states_.end(), |
| 132 RasterTaskState::TaskComparator(task)); |
119 if (state_it != raster_task_states_.end()) { | 133 if (state_it != raster_task_states_.end()) { |
120 const RasterTaskState& state = state_it->second; | 134 RasterTaskState& state = *state_it; |
121 | 135 |
122 new_raster_task_states[task] = | 136 state.required_for_activation = item.required_for_activation; |
123 RasterTaskState(state) | |
124 .set_required_for_activation(item.required_for_activation); | |
125 // |raster_tasks_required_for_activation_count| accounts for all tasks | 137 // |raster_tasks_required_for_activation_count| accounts for all tasks |
126 // that need to complete before we can send a "ready to activate" signal. | 138 // that need to complete before we can send a "ready to activate" signal. |
127 // Tasks that have already completed should not be part of this count. | 139 // Tasks that have already completed should not be part of this count. |
128 if (state.type != RasterTaskState::COMPLETED) { | 140 if (state.type != RasterTaskState::COMPLETED) { |
129 raster_tasks_required_for_activation_count_ += | 141 raster_tasks_required_for_activation_count_ += |
130 item.required_for_activation; | 142 item.required_for_activation; |
131 } | 143 } |
| 144 continue; |
| 145 } |
132 | 146 |
133 raster_task_states_.erase(state_it); | 147 DCHECK(!task->HasBeenScheduled()); |
134 } else { | 148 raster_task_states_.push_back( |
135 DCHECK(!task->HasBeenScheduled()); | 149 RasterTaskState(task, item.required_for_activation)); |
136 new_raster_task_states[task] = | 150 raster_tasks_required_for_activation_count_ += item.required_for_activation; |
137 RasterTaskState().set_required_for_activation( | |
138 item.required_for_activation); | |
139 raster_tasks_required_for_activation_count_ += | |
140 item.required_for_activation; | |
141 } | |
142 } | 151 } |
143 | 152 |
144 // Transfer old raster task state to |new_raster_task_states| and cancel all | 153 // Determine what tasks in old queue need to be canceled. |
145 // remaining unscheduled tasks. | 154 for (RasterTaskQueue::Item::Vector::const_iterator it = |
146 for (RasterTaskStateMap::const_iterator it = raster_task_states_.begin(); | 155 raster_tasks_.items.begin(); |
147 it != raster_task_states_.end(); | 156 it != raster_tasks_.items.end(); |
148 ++it) { | 157 ++it) { |
149 internal::WorkerPoolTask* task = it->first; | 158 const RasterTaskQueue::Item& item = *it; |
150 const RasterTaskState& state = it->second; | 159 internal::WorkerPoolTask* task = item.task; |
151 DCHECK(new_raster_task_states.find(task) == new_raster_task_states.end()); | 160 |
| 161 RasterTaskState::Vector::iterator state_it = |
| 162 std::find_if(raster_task_states_.begin(), |
| 163 raster_task_states_.end(), |
| 164 RasterTaskState::TaskComparator(task)); |
| 165 // We've already processed completion if we can't find a RasterTaskState for |
| 166 // this task. |
| 167 if (state_it == raster_task_states_.end()) |
| 168 continue; |
| 169 |
| 170 RasterTaskState& state = *state_it; |
152 | 171 |
153 // Unscheduled task can be canceled. | 172 // Unscheduled task can be canceled. |
154 if (state.type == RasterTaskState::UNSCHEDULED) { | 173 if (state.type == RasterTaskState::UNSCHEDULED) { |
155 DCHECK(!task->HasBeenScheduled()); | 174 DCHECK(!task->HasBeenScheduled()); |
156 DCHECK(std::find(completed_raster_tasks_.begin(), | 175 DCHECK(std::find(completed_raster_tasks_.begin(), |
157 completed_raster_tasks_.end(), | 176 completed_raster_tasks_.end(), |
158 task) == completed_raster_tasks_.end()); | 177 task) == completed_raster_tasks_.end()); |
159 completed_raster_tasks_.push_back(task); | 178 completed_raster_tasks_.push_back(task); |
160 new_raster_task_states[task] = RasterTaskState(state).set_completed(); | 179 state.type = RasterTaskState::COMPLETED; |
161 continue; | |
162 } | 180 } |
163 | 181 |
164 // Move state to |new_raster_task_states|. | 182 // No longer required for activation. |
165 new_raster_task_states[task] = | 183 state.required_for_activation = false; |
166 RasterTaskState(state).set_required_for_activation(false); | |
167 } | 184 } |
168 | 185 |
169 raster_tasks_.Swap(queue); | 186 raster_tasks_.Swap(queue); |
170 raster_task_states_.swap(new_raster_task_states); | |
171 | 187 |
172 // Check for completed tasks when ScheduleTasks() is called as | 188 // Check for completed tasks when ScheduleTasks() is called as |
173 // priorities might have changed and this maximizes the number | 189 // priorities might have changed and this maximizes the number |
174 // of top priority tasks that are scheduled. | 190 // of top priority tasks that are scheduled. |
175 CheckForCompletedWorkerPoolTasks(); | 191 CheckForCompletedWorkerPoolTasks(); |
176 CheckForCompletedUploads(); | 192 CheckForCompletedUploads(); |
177 FlushUploads(); | 193 FlushUploads(); |
178 | 194 |
179 // Schedule new tasks. | 195 // Schedule new tasks. |
180 ScheduleMoreTasks(); | 196 ScheduleMoreTasks(); |
(...skipping 20 matching lines...) Expand all Loading... |
201 return resource_provider()->memory_efficient_texture_format(); | 217 return resource_provider()->memory_efficient_texture_format(); |
202 } | 218 } |
203 | 219 |
204 void PixelBufferRasterWorkerPool::CheckForCompletedTasks() { | 220 void PixelBufferRasterWorkerPool::CheckForCompletedTasks() { |
205 TRACE_EVENT0("cc", "PixelBufferRasterWorkerPool::CheckForCompletedTasks"); | 221 TRACE_EVENT0("cc", "PixelBufferRasterWorkerPool::CheckForCompletedTasks"); |
206 | 222 |
207 CheckForCompletedWorkerPoolTasks(); | 223 CheckForCompletedWorkerPoolTasks(); |
208 CheckForCompletedUploads(); | 224 CheckForCompletedUploads(); |
209 FlushUploads(); | 225 FlushUploads(); |
210 | 226 |
211 while (!completed_image_decode_tasks_.empty()) { | 227 for (TaskVector::const_iterator it = completed_image_decode_tasks_.begin(); |
212 internal::WorkerPoolTask* task = | 228 it != completed_image_decode_tasks_.end(); |
213 completed_image_decode_tasks_.front().get(); | 229 ++it) { |
| 230 internal::WorkerPoolTask* task = it->get(); |
| 231 task->RunReplyOnOriginThread(); |
| 232 } |
| 233 completed_image_decode_tasks_.clear(); |
| 234 |
| 235 for (TaskVector::const_iterator it = completed_raster_tasks_.begin(); |
| 236 it != completed_raster_tasks_.end(); |
| 237 ++it) { |
| 238 internal::WorkerPoolTask* task = it->get(); |
| 239 RasterTaskState::Vector::iterator state_it = |
| 240 std::find_if(raster_task_states_.begin(), |
| 241 raster_task_states_.end(), |
| 242 RasterTaskState::TaskComparator(task)); |
| 243 DCHECK(state_it != raster_task_states_.end()); |
| 244 DCHECK_EQ(RasterTaskState::COMPLETED, state_it->type); |
| 245 |
| 246 std::swap(*state_it, raster_task_states_.back()); |
| 247 raster_task_states_.pop_back(); |
214 | 248 |
215 task->RunReplyOnOriginThread(); | 249 task->RunReplyOnOriginThread(); |
216 | |
217 completed_image_decode_tasks_.pop_front(); | |
218 } | 250 } |
219 | 251 completed_raster_tasks_.clear(); |
220 while (!completed_raster_tasks_.empty()) { | |
221 internal::WorkerPoolTask* task = completed_raster_tasks_.front().get(); | |
222 DCHECK(raster_task_states_.find(task) != raster_task_states_.end()); | |
223 DCHECK_EQ(RasterTaskState::COMPLETED, raster_task_states_[task].type); | |
224 | |
225 raster_task_states_.erase(task); | |
226 | |
227 task->RunReplyOnOriginThread(); | |
228 | |
229 completed_raster_tasks_.pop_front(); | |
230 } | |
231 } | 252 } |
232 | 253 |
233 SkCanvas* PixelBufferRasterWorkerPool::AcquireCanvasForRaster( | 254 SkCanvas* PixelBufferRasterWorkerPool::AcquireCanvasForRaster( |
234 internal::WorkerPoolTask* task, | 255 internal::WorkerPoolTask* task, |
235 const Resource* resource) { | 256 const Resource* resource) { |
236 DCHECK(raster_task_states_.find(task) != raster_task_states_.end()); | 257 RasterTaskState::Vector::iterator it = |
237 DCHECK(!raster_task_states_[task].resource); | 258 std::find_if(raster_task_states_.begin(), |
238 raster_task_states_[task].resource = resource; | 259 raster_task_states_.end(), |
| 260 RasterTaskState::TaskComparator(task)); |
| 261 DCHECK(it != raster_task_states_.end()); |
| 262 DCHECK(!it->resource); |
| 263 it->resource = resource; |
239 resource_provider()->AcquirePixelRasterBuffer(resource->id()); | 264 resource_provider()->AcquirePixelRasterBuffer(resource->id()); |
240 return resource_provider()->MapPixelRasterBuffer(resource->id()); | 265 return resource_provider()->MapPixelRasterBuffer(resource->id()); |
241 } | 266 } |
242 | 267 |
243 void PixelBufferRasterWorkerPool::ReleaseCanvasForRaster( | 268 void PixelBufferRasterWorkerPool::ReleaseCanvasForRaster( |
244 internal::WorkerPoolTask* task, | 269 internal::WorkerPoolTask* task, |
245 const Resource* resource) { | 270 const Resource* resource) { |
246 DCHECK(raster_task_states_.find(task) != raster_task_states_.end()); | 271 RasterTaskState::Vector::iterator it = |
247 DCHECK(raster_task_states_[task].resource == resource); | 272 std::find_if(raster_task_states_.begin(), |
| 273 raster_task_states_.end(), |
| 274 RasterTaskState::TaskComparator(task)); |
| 275 DCHECK(it != raster_task_states_.end()); |
| 276 DCHECK(it->resource == resource); |
248 resource_provider()->ReleasePixelRasterBuffer(resource->id()); | 277 resource_provider()->ReleasePixelRasterBuffer(resource->id()); |
249 } | 278 } |
250 | 279 |
251 void PixelBufferRasterWorkerPool::OnRasterTasksFinished() { | 280 void PixelBufferRasterWorkerPool::OnRasterTasksFinished() { |
252 // |should_notify_client_if_no_tasks_are_pending_| can be set to false as | 281 // |should_notify_client_if_no_tasks_are_pending_| can be set to false as |
253 // a result of a scheduled CheckForCompletedRasterTasks() call. No need to | 282 // a result of a scheduled CheckForCompletedRasterTasks() call. No need to |
254 // perform another check in that case as we've already notified the client. | 283 // perform another check in that case as we've already notified the client. |
255 if (!should_notify_client_if_no_tasks_are_pending_) | 284 if (!should_notify_client_if_no_tasks_are_pending_) |
256 return; | 285 return; |
257 raster_finished_task_pending_ = false; | 286 raster_finished_task_pending_ = false; |
(...skipping 20 matching lines...) Expand all Loading... |
278 | 307 |
279 void PixelBufferRasterWorkerPool::FlushUploads() { | 308 void PixelBufferRasterWorkerPool::FlushUploads() { |
280 if (!has_performed_uploads_since_last_flush_) | 309 if (!has_performed_uploads_since_last_flush_) |
281 return; | 310 return; |
282 | 311 |
283 resource_provider()->ShallowFlushIfSupported(); | 312 resource_provider()->ShallowFlushIfSupported(); |
284 has_performed_uploads_since_last_flush_ = false; | 313 has_performed_uploads_since_last_flush_ = false; |
285 } | 314 } |
286 | 315 |
287 void PixelBufferRasterWorkerPool::CheckForCompletedUploads() { | 316 void PixelBufferRasterWorkerPool::CheckForCompletedUploads() { |
288 TaskDeque tasks_with_completed_uploads; | 317 TaskVector tasks_with_completed_uploads; |
289 | 318 |
290 // First check if any have completed. | 319 // First check if any have completed. |
291 while (!raster_tasks_with_pending_upload_.empty()) { | 320 while (!raster_tasks_with_pending_upload_.empty()) { |
292 internal::WorkerPoolTask* task = | 321 internal::WorkerPoolTask* task = |
293 raster_tasks_with_pending_upload_.front().get(); | 322 raster_tasks_with_pending_upload_.front().get(); |
294 DCHECK(raster_task_states_.find(task) != raster_task_states_.end()); | 323 RasterTaskState::Vector::const_iterator it = |
295 const RasterTaskState& state = raster_task_states_[task]; | 324 std::find_if(raster_task_states_.begin(), |
296 DCHECK_EQ(RasterTaskState::UPLOADING, state.type); | 325 raster_task_states_.end(), |
| 326 RasterTaskState::TaskComparator(task)); |
| 327 DCHECK(it != raster_task_states_.end()); |
| 328 DCHECK_EQ(RasterTaskState::UPLOADING, it->type); |
297 | 329 |
298 // Uploads complete in the order they are issued. | 330 // Uploads complete in the order they are issued. |
299 if (!resource_provider()->DidSetPixelsComplete(state.resource->id())) | 331 if (!resource_provider()->DidSetPixelsComplete(it->resource->id())) |
300 break; | 332 break; |
301 | 333 |
302 tasks_with_completed_uploads.push_back(task); | 334 tasks_with_completed_uploads.push_back(task); |
303 raster_tasks_with_pending_upload_.pop_front(); | 335 raster_tasks_with_pending_upload_.pop_front(); |
304 } | 336 } |
305 | 337 |
306 DCHECK(client()); | 338 DCHECK(client()); |
307 bool should_force_some_uploads_to_complete = | 339 bool should_force_some_uploads_to_complete = |
308 shutdown_ || client()->ShouldForceTasksRequiredForActivationToComplete(); | 340 shutdown_ || client()->ShouldForceTasksRequiredForActivationToComplete(); |
309 | 341 |
310 if (should_force_some_uploads_to_complete) { | 342 if (should_force_some_uploads_to_complete) { |
311 TaskDeque tasks_with_uploads_to_force; | 343 TaskVector tasks_with_uploads_to_force; |
312 TaskDeque::iterator it = raster_tasks_with_pending_upload_.begin(); | 344 TaskDeque::iterator it = raster_tasks_with_pending_upload_.begin(); |
313 while (it != raster_tasks_with_pending_upload_.end()) { | 345 while (it != raster_tasks_with_pending_upload_.end()) { |
314 internal::WorkerPoolTask* task = it->get(); | 346 internal::WorkerPoolTask* task = it->get(); |
315 DCHECK(raster_task_states_.find(task) != raster_task_states_.end()); | 347 RasterTaskState::Vector::const_iterator state_it = |
316 const RasterTaskState& state = raster_task_states_[task]; | 348 std::find_if(raster_task_states_.begin(), |
| 349 raster_task_states_.end(), |
| 350 RasterTaskState::TaskComparator(task)); |
| 351 DCHECK(state_it != raster_task_states_.end()); |
317 | 352 |
318 // Force all uploads required for activation to complete. | 353 // Force all uploads required for activation to complete. |
319 // During shutdown, force all pending uploads to complete. | 354 // During shutdown, force all pending uploads to complete. |
320 if (shutdown_ || state.required_for_activation) { | 355 if (shutdown_ || state_it->required_for_activation) { |
321 tasks_with_uploads_to_force.push_back(task); | 356 tasks_with_uploads_to_force.push_back(task); |
322 tasks_with_completed_uploads.push_back(task); | 357 tasks_with_completed_uploads.push_back(task); |
323 it = raster_tasks_with_pending_upload_.erase(it); | 358 it = raster_tasks_with_pending_upload_.erase(it); |
324 continue; | 359 continue; |
325 } | 360 } |
326 | 361 |
327 ++it; | 362 ++it; |
328 } | 363 } |
329 | 364 |
330 // Force uploads in reverse order. Since forcing can cause a wait on | 365 // Force uploads in reverse order. Since forcing can cause a wait on |
331 // all previous uploads, we would rather wait only once downstream. | 366 // all previous uploads, we would rather wait only once downstream. |
332 for (TaskDeque::reverse_iterator it = tasks_with_uploads_to_force.rbegin(); | 367 for (TaskVector::reverse_iterator it = tasks_with_uploads_to_force.rbegin(); |
333 it != tasks_with_uploads_to_force.rend(); | 368 it != tasks_with_uploads_to_force.rend(); |
334 ++it) { | 369 ++it) { |
335 internal::WorkerPoolTask* task = it->get(); | 370 internal::WorkerPoolTask* task = it->get(); |
336 const RasterTaskState& state = raster_task_states_[task]; | 371 RasterTaskState::Vector::const_iterator state_it = |
337 DCHECK(state.resource); | 372 std::find_if(raster_task_states_.begin(), |
| 373 raster_task_states_.end(), |
| 374 RasterTaskState::TaskComparator(task)); |
| 375 DCHECK(state_it != raster_task_states_.end()); |
| 376 DCHECK(state_it->resource); |
338 | 377 |
339 resource_provider()->ForceSetPixelsToComplete(state.resource->id()); | 378 resource_provider()->ForceSetPixelsToComplete(state_it->resource->id()); |
340 has_performed_uploads_since_last_flush_ = true; | 379 has_performed_uploads_since_last_flush_ = true; |
341 } | 380 } |
342 } | 381 } |
343 | 382 |
344 // Release shared memory and move tasks with completed uploads | 383 // Release shared memory and move tasks with completed uploads |
345 // to |completed_raster_tasks_|. | 384 // to |completed_raster_tasks_|. |
346 while (!tasks_with_completed_uploads.empty()) { | 385 for (TaskVector::const_iterator it = tasks_with_completed_uploads.begin(); |
347 internal::WorkerPoolTask* task = tasks_with_completed_uploads.front().get(); | 386 it != tasks_with_completed_uploads.end(); |
348 RasterTaskState& state = raster_task_states_[task]; | 387 ++it) { |
| 388 internal::WorkerPoolTask* task = it->get(); |
| 389 RasterTaskState::Vector::iterator state_it = |
| 390 std::find_if(raster_task_states_.begin(), |
| 391 raster_task_states_.end(), |
| 392 RasterTaskState::TaskComparator(task)); |
| 393 DCHECK(state_it != raster_task_states_.end()); |
| 394 RasterTaskState& state = *state_it; |
349 | 395 |
350 bytes_pending_upload_ -= state.resource->bytes(); | 396 bytes_pending_upload_ -= state.resource->bytes(); |
351 | 397 |
352 task->WillComplete(); | 398 task->WillComplete(); |
353 task->CompleteOnOriginThread(this); | 399 task->CompleteOnOriginThread(this); |
354 task->DidComplete(); | 400 task->DidComplete(); |
355 | 401 |
356 DCHECK(std::find(completed_raster_tasks_.begin(), | 402 DCHECK(std::find(completed_raster_tasks_.begin(), |
357 completed_raster_tasks_.end(), | 403 completed_raster_tasks_.end(), |
358 task) == completed_raster_tasks_.end()); | 404 task) == completed_raster_tasks_.end()); |
359 completed_raster_tasks_.push_back(task); | 405 completed_raster_tasks_.push_back(task); |
360 state.type = RasterTaskState::COMPLETED; | 406 state.type = RasterTaskState::COMPLETED; |
361 DCHECK_LE(static_cast<size_t>(state.required_for_activation), | 407 DCHECK_LE(static_cast<size_t>(state.required_for_activation), |
362 raster_tasks_required_for_activation_count_); | 408 raster_tasks_required_for_activation_count_); |
363 raster_tasks_required_for_activation_count_ -= | 409 raster_tasks_required_for_activation_count_ -= |
364 state.required_for_activation; | 410 state.required_for_activation; |
365 | |
366 tasks_with_completed_uploads.pop_front(); | |
367 } | 411 } |
368 } | 412 } |
369 | 413 |
370 void PixelBufferRasterWorkerPool::ScheduleCheckForCompletedRasterTasks() { | 414 void PixelBufferRasterWorkerPool::ScheduleCheckForCompletedRasterTasks() { |
371 base::TimeDelta delay = | 415 base::TimeDelta delay = |
372 base::TimeDelta::FromMilliseconds(kCheckForCompletedRasterTasksDelayMs); | 416 base::TimeDelta::FromMilliseconds(kCheckForCompletedRasterTasksDelayMs); |
373 if (check_for_completed_raster_tasks_time_.is_null()) | 417 if (check_for_completed_raster_tasks_time_.is_null()) |
374 check_for_completed_raster_tasks_time_ = base::TimeTicks::Now() + delay; | 418 check_for_completed_raster_tasks_time_ = base::TimeTicks::Now() + delay; |
375 | 419 |
376 if (check_for_completed_raster_tasks_pending_) | 420 if (check_for_completed_raster_tasks_pending_) |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 | 524 |
481 for (RasterTaskQueue::Item::Vector::const_iterator it = | 525 for (RasterTaskQueue::Item::Vector::const_iterator it = |
482 raster_tasks_.items.begin(); | 526 raster_tasks_.items.begin(); |
483 it != raster_tasks_.items.end(); | 527 it != raster_tasks_.items.end(); |
484 ++it) { | 528 ++it) { |
485 const RasterTaskQueue::Item& item = *it; | 529 const RasterTaskQueue::Item& item = *it; |
486 internal::RasterWorkerPoolTask* task = item.task; | 530 internal::RasterWorkerPoolTask* task = item.task; |
487 | 531 |
488 // |raster_task_states_| contains the state of all tasks that we have not | 532 // |raster_task_states_| contains the state of all tasks that we have not |
489 // yet run reply callbacks for. | 533 // yet run reply callbacks for. |
490 RasterTaskStateMap::iterator state_it = raster_task_states_.find(task); | 534 RasterTaskState::Vector::iterator state_it = |
| 535 std::find_if(raster_task_states_.begin(), |
| 536 raster_task_states_.end(), |
| 537 RasterTaskState::TaskComparator(task)); |
491 if (state_it == raster_task_states_.end()) | 538 if (state_it == raster_task_states_.end()) |
492 continue; | 539 continue; |
493 | 540 |
494 RasterTaskState& state = state_it->second; | 541 RasterTaskState& state = *state_it; |
495 | 542 |
496 // Skip task if completed. | 543 // Skip task if completed. |
497 if (state.type == RasterTaskState::COMPLETED) { | 544 if (state.type == RasterTaskState::COMPLETED) { |
498 DCHECK(std::find(completed_raster_tasks_.begin(), | 545 DCHECK(std::find(completed_raster_tasks_.begin(), |
499 completed_raster_tasks_.end(), | 546 completed_raster_tasks_.end(), |
500 task) != completed_raster_tasks_.end()); | 547 task) != completed_raster_tasks_.end()); |
501 continue; | 548 continue; |
502 } | 549 } |
503 | 550 |
504 // All raster tasks need to be throttled by bytes of pending uploads. | 551 // All raster tasks need to be throttled by bytes of pending uploads. |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 } | 676 } |
630 | 677 |
631 void PixelBufferRasterWorkerPool::CheckForCompletedWorkerPoolTasks() { | 678 void PixelBufferRasterWorkerPool::CheckForCompletedWorkerPoolTasks() { |
632 CollectCompletedWorkerPoolTasks(&completed_tasks_); | 679 CollectCompletedWorkerPoolTasks(&completed_tasks_); |
633 for (internal::Task::Vector::const_iterator it = completed_tasks_.begin(); | 680 for (internal::Task::Vector::const_iterator it = completed_tasks_.begin(); |
634 it != completed_tasks_.end(); | 681 it != completed_tasks_.end(); |
635 ++it) { | 682 ++it) { |
636 internal::WorkerPoolTask* task = | 683 internal::WorkerPoolTask* task = |
637 static_cast<internal::WorkerPoolTask*>(it->get()); | 684 static_cast<internal::WorkerPoolTask*>(it->get()); |
638 | 685 |
639 RasterTaskStateMap::iterator state_it = raster_task_states_.find(task); | 686 RasterTaskState::Vector::iterator state_it = |
| 687 std::find_if(raster_task_states_.begin(), |
| 688 raster_task_states_.end(), |
| 689 RasterTaskState::TaskComparator(task)); |
640 if (state_it == raster_task_states_.end()) { | 690 if (state_it == raster_task_states_.end()) { |
641 task->WillComplete(); | 691 task->WillComplete(); |
642 task->CompleteOnOriginThread(this); | 692 task->CompleteOnOriginThread(this); |
643 task->DidComplete(); | 693 task->DidComplete(); |
644 | 694 |
645 completed_image_decode_tasks_.push_back(task); | 695 completed_image_decode_tasks_.push_back(task); |
646 continue; | 696 continue; |
647 } | 697 } |
648 | 698 |
649 RasterTaskState& state = state_it->second; | 699 RasterTaskState& state = *state_it; |
650 DCHECK_EQ(RasterTaskState::SCHEDULED, state.type); | 700 DCHECK_EQ(RasterTaskState::SCHEDULED, state.type); |
651 DCHECK(state.resource); | 701 DCHECK(state.resource); |
652 | 702 |
653 // Balanced with MapPixelRasterBuffer() call in AcquireCanvasForRaster(). | 703 // Balanced with MapPixelRasterBuffer() call in AcquireCanvasForRaster(). |
654 bool content_has_changed = | 704 bool content_has_changed = |
655 resource_provider()->UnmapPixelRasterBuffer(state.resource->id()); | 705 resource_provider()->UnmapPixelRasterBuffer(state.resource->id()); |
656 | 706 |
657 // |content_has_changed| can be false as result of task being canceled or | 707 // |content_has_changed| can be false as result of task being canceled or |
658 // task implementation deciding not to modify bitmap (ie. analysis of raster | 708 // task implementation deciding not to modify bitmap (ie. analysis of raster |
659 // commands detected content as a solid color). | 709 // commands detected content as a solid color). |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
720 | 770 |
721 throttle_state->SetInteger("bytes_available_for_upload", | 771 throttle_state->SetInteger("bytes_available_for_upload", |
722 max_bytes_pending_upload_ - bytes_pending_upload_); | 772 max_bytes_pending_upload_ - bytes_pending_upload_); |
723 throttle_state->SetInteger("bytes_pending_upload", bytes_pending_upload_); | 773 throttle_state->SetInteger("bytes_pending_upload", bytes_pending_upload_); |
724 throttle_state->SetInteger("scheduled_raster_task_count", | 774 throttle_state->SetInteger("scheduled_raster_task_count", |
725 scheduled_raster_task_count_); | 775 scheduled_raster_task_count_); |
726 return throttle_state.PassAs<base::Value>(); | 776 return throttle_state.PassAs<base::Value>(); |
727 } | 777 } |
728 | 778 |
729 } // namespace cc | 779 } // namespace cc |
OLD | NEW |