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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
64 void PixelBufferRasterWorkerPool::Shutdown() { | 66 void PixelBufferRasterWorkerPool::Shutdown() { |
65 shutdown_ = true; | 67 shutdown_ = true; |
66 RasterWorkerPool::Shutdown(); | 68 RasterWorkerPool::Shutdown(); |
67 | 69 |
68 CheckForCompletedWorkerPoolTasks(); | 70 CheckForCompletedWorkerPoolTasks(); |
69 CheckForCompletedUploads(); | 71 CheckForCompletedUploads(); |
70 | 72 |
71 weak_factory_.InvalidateWeakPtrs(); | 73 weak_factory_.InvalidateWeakPtrs(); |
72 check_for_completed_raster_tasks_pending_ = false; | 74 check_for_completed_raster_tasks_pending_ = false; |
73 | 75 |
74 for (RasterTaskStateMap::iterator it = raster_task_states_.begin(); | 76 for (RasterTaskState::Vector::iterator it = raster_task_states_.begin(); |
75 it != raster_task_states_.end(); | 77 it != raster_task_states_.end(); |
76 ++it) { | 78 ++it) { |
77 internal::WorkerPoolTask* task = it->first; | 79 RasterTaskState& state = *it; |
78 RasterTaskState& state = it->second; | |
79 | 80 |
80 // All unscheduled tasks need to be canceled. | 81 // All unscheduled tasks need to be canceled. |
81 if (state.type == RasterTaskState::UNSCHEDULED) { | 82 if (state.type == RasterTaskState::UNSCHEDULED) { |
82 completed_raster_tasks_.push_back(task); | 83 completed_raster_tasks_.push_back(state.task); |
83 state.type = RasterTaskState::COMPLETED; | 84 state.type = RasterTaskState::COMPLETED; |
84 } | 85 } |
85 } | 86 } |
86 DCHECK_EQ(completed_raster_tasks_.size(), raster_task_states_.size()); | 87 DCHECK_EQ(completed_raster_tasks_.size(), raster_task_states_.size()); |
87 } | 88 } |
88 | 89 |
89 void PixelBufferRasterWorkerPool::ScheduleTasks(RasterTaskQueue* queue) { | 90 void PixelBufferRasterWorkerPool::ScheduleTasks(RasterTaskQueue* queue) { |
90 TRACE_EVENT0("cc", "PixelBufferRasterWorkerPool::ScheduleTasks"); | 91 TRACE_EVENT0("cc", "PixelBufferRasterWorkerPool::ScheduleTasks"); |
91 | 92 |
92 DCHECK_EQ(queue->required_for_activation_count, | 93 DCHECK_EQ(queue->required_for_activation_count, |
93 static_cast<size_t>( | 94 static_cast<size_t>( |
94 std::count_if(queue->items.begin(), | 95 std::count_if(queue->items.begin(), |
95 queue->items.end(), | 96 queue->items.end(), |
96 RasterTaskQueue::Item::IsRequiredForActivation))); | 97 RasterTaskQueue::Item::IsRequiredForActivation))); |
97 | 98 |
98 if (!should_notify_client_if_no_tasks_are_pending_) | 99 if (!should_notify_client_if_no_tasks_are_pending_) |
99 TRACE_EVENT_ASYNC_BEGIN0("cc", "ScheduledTasks", this); | 100 TRACE_EVENT_ASYNC_BEGIN0("cc", "ScheduledTasks", this); |
100 | 101 |
101 should_notify_client_if_no_tasks_are_pending_ = true; | 102 should_notify_client_if_no_tasks_are_pending_ = true; |
102 should_notify_client_if_no_tasks_required_for_activation_are_pending_ = true; | 103 should_notify_client_if_no_tasks_required_for_activation_are_pending_ = true; |
103 | 104 |
104 raster_tasks_required_for_activation_count_ = 0u; | 105 raster_tasks_required_for_activation_count_ = 0u; |
105 | 106 |
107 recycled_raster_task_states_.clear(); | |
108 | |
106 // Build new raster task state map. | 109 // Build new raster task state map. |
107 RasterTaskStateMap new_raster_task_states; | |
108 for (RasterTaskQueue::Item::Vector::const_iterator it = queue->items.begin(); | 110 for (RasterTaskQueue::Item::Vector::const_iterator it = queue->items.begin(); |
109 it != queue->items.end(); | 111 it != queue->items.end(); |
110 ++it) { | 112 ++it) { |
111 const RasterTaskQueue::Item& item = *it; | 113 const RasterTaskQueue::Item& item = *it; |
112 internal::WorkerPoolTask* task = item.task; | 114 internal::WorkerPoolTask* task = item.task; |
113 DCHECK(new_raster_task_states.find(task) == new_raster_task_states.end()); | 115 DCHECK(std::find_if(recycled_raster_task_states_.begin(), |
116 recycled_raster_task_states_.end(), | |
117 RasterTaskState::TaskComparator(task)) == | |
118 recycled_raster_task_states_.end()); | |
114 | 119 |
115 RasterTaskStateMap::iterator state_it = raster_task_states_.find(task); | 120 RasterTaskState::Vector::iterator state_it = |
vmpstr
2014/02/21 18:39:41
Out of curiousity... The current approach will hav
reveman
2014/02/22 11:32:01
We get about the same performance when reaching ~1
vmpstr
2014/02/24 17:37:58
Nice. Let's hope we don't schedule more than that
| |
121 std::find_if(raster_task_states_.begin(), | |
122 raster_task_states_.end(), | |
123 RasterTaskState::TaskComparator(task)); | |
116 if (state_it != raster_task_states_.end()) { | 124 if (state_it != raster_task_states_.end()) { |
117 const RasterTaskState& state = state_it->second; | 125 RasterTaskState& state = *state_it; |
118 | 126 |
119 new_raster_task_states[task] = | 127 recycled_raster_task_states_.push_back( |
120 RasterTaskState(state) | 128 RasterTaskState(state) |
121 .set_required_for_activation(item.required_for_activation); | 129 .set_required_for_activation(item.required_for_activation)); |
122 // |raster_tasks_required_for_activation_count| accounts for all tasks | 130 // |raster_tasks_required_for_activation_count| accounts for all tasks |
123 // that need to complete before we can send a "ready to activate" signal. | 131 // that need to complete before we can send a "ready to activate" signal. |
124 // Tasks that have already completed should not be part of this count. | 132 // Tasks that have already completed should not be part of this count. |
125 if (state.type != RasterTaskState::COMPLETED) { | 133 if (state.type != RasterTaskState::COMPLETED) { |
126 raster_tasks_required_for_activation_count_ += | 134 raster_tasks_required_for_activation_count_ += |
127 item.required_for_activation; | 135 item.required_for_activation; |
128 } | 136 } |
129 | 137 |
130 raster_task_states_.erase(state_it); | 138 std::swap(*state_it, raster_task_states_.back()); |
vmpstr
2014/02/21 18:39:41
nit: s/\*state_it/state/
reveman
2014/02/22 11:32:01
Done.
| |
139 raster_task_states_.pop_back(); | |
131 } else { | 140 } else { |
132 DCHECK(!task->HasBeenScheduled()); | 141 DCHECK(!task->HasBeenScheduled()); |
133 new_raster_task_states[task] = | 142 recycled_raster_task_states_.push_back( |
134 RasterTaskState().set_required_for_activation( | 143 RasterTaskState(task, item.required_for_activation)); |
135 item.required_for_activation); | |
136 raster_tasks_required_for_activation_count_ += | 144 raster_tasks_required_for_activation_count_ += |
137 item.required_for_activation; | 145 item.required_for_activation; |
138 } | 146 } |
139 } | 147 } |
140 | 148 |
141 // Transfer old raster task state to |new_raster_task_states| and cancel all | 149 // Transfer old raster task state to |recycled_raster_task_states_| and cancel |
142 // remaining unscheduled tasks. | 150 // all remaining unscheduled tasks. |
143 for (RasterTaskStateMap::const_iterator it = raster_task_states_.begin(); | 151 for (RasterTaskState::Vector::const_iterator it = raster_task_states_.begin(); |
144 it != raster_task_states_.end(); | 152 it != raster_task_states_.end(); |
145 ++it) { | 153 ++it) { |
146 internal::WorkerPoolTask* task = it->first; | 154 const RasterTaskState& state = *it; |
147 const RasterTaskState& state = it->second; | 155 internal::WorkerPoolTask* task = state.task; |
148 DCHECK(new_raster_task_states.find(task) == new_raster_task_states.end()); | 156 DCHECK(std::find_if(recycled_raster_task_states_.begin(), |
157 recycled_raster_task_states_.end(), | |
158 RasterTaskState::TaskComparator(task)) == | |
159 recycled_raster_task_states_.end()); | |
149 | 160 |
150 // Unscheduled task can be canceled. | 161 // Unscheduled task can be canceled. |
151 if (state.type == RasterTaskState::UNSCHEDULED) { | 162 if (state.type == RasterTaskState::UNSCHEDULED) { |
152 DCHECK(!task->HasBeenScheduled()); | 163 DCHECK(!task->HasBeenScheduled()); |
153 DCHECK(std::find(completed_raster_tasks_.begin(), | 164 DCHECK(std::find(completed_raster_tasks_.begin(), |
154 completed_raster_tasks_.end(), | 165 completed_raster_tasks_.end(), |
155 task) == completed_raster_tasks_.end()); | 166 task) == completed_raster_tasks_.end()); |
156 completed_raster_tasks_.push_back(task); | 167 completed_raster_tasks_.push_back(task); |
157 new_raster_task_states[task] = RasterTaskState(state).set_completed(); | 168 recycled_raster_task_states_.push_back( |
169 RasterTaskState(state).set_completed()); | |
158 continue; | 170 continue; |
159 } | 171 } |
160 | 172 |
161 // Move state to |new_raster_task_states|. | 173 // Move state to |recycled_raster_task_states_|. |
162 new_raster_task_states[task] = | 174 recycled_raster_task_states_.push_back( |
163 RasterTaskState(state).set_required_for_activation(false); | 175 RasterTaskState(state).set_required_for_activation(false)); |
164 } | 176 } |
165 | 177 |
166 raster_tasks_.Swap(queue); | 178 raster_tasks_.Swap(queue); |
167 raster_task_states_.swap(new_raster_task_states); | 179 raster_task_states_.swap(recycled_raster_task_states_); |
vmpstr
2014/02/21 18:39:41
Is there a better name for this vector? Recycled m
reveman
2014/02/22 11:32:01
I figured out a faster way to do this that avoids
| |
168 | 180 |
169 // Check for completed tasks when ScheduleTasks() is called as | 181 // Check for completed tasks when ScheduleTasks() is called as |
170 // priorities might have changed and this maximizes the number | 182 // priorities might have changed and this maximizes the number |
171 // of top priority tasks that are scheduled. | 183 // of top priority tasks that are scheduled. |
172 CheckForCompletedWorkerPoolTasks(); | 184 CheckForCompletedWorkerPoolTasks(); |
173 CheckForCompletedUploads(); | 185 CheckForCompletedUploads(); |
174 FlushUploads(); | 186 FlushUploads(); |
175 | 187 |
176 // Schedule new tasks. | 188 // Schedule new tasks. |
177 ScheduleMoreTasks(); | 189 ScheduleMoreTasks(); |
(...skipping 20 matching lines...) Expand all Loading... | |
198 return resource_provider()->memory_efficient_texture_format(); | 210 return resource_provider()->memory_efficient_texture_format(); |
199 } | 211 } |
200 | 212 |
201 void PixelBufferRasterWorkerPool::CheckForCompletedTasks() { | 213 void PixelBufferRasterWorkerPool::CheckForCompletedTasks() { |
202 TRACE_EVENT0("cc", "PixelBufferRasterWorkerPool::CheckForCompletedTasks"); | 214 TRACE_EVENT0("cc", "PixelBufferRasterWorkerPool::CheckForCompletedTasks"); |
203 | 215 |
204 CheckForCompletedWorkerPoolTasks(); | 216 CheckForCompletedWorkerPoolTasks(); |
205 CheckForCompletedUploads(); | 217 CheckForCompletedUploads(); |
206 FlushUploads(); | 218 FlushUploads(); |
207 | 219 |
208 while (!completed_image_decode_tasks_.empty()) { | 220 for (TaskVector::iterator it = completed_image_decode_tasks_.begin(); |
209 internal::WorkerPoolTask* task = | 221 it != completed_image_decode_tasks_.end(); |
210 completed_image_decode_tasks_.front().get(); | 222 ++it) { |
223 internal::WorkerPoolTask* task = it->get(); | |
224 task->RunReplyOnOriginThread(); | |
225 } | |
226 completed_image_decode_tasks_.clear(); | |
227 | |
228 for (TaskVector::iterator it = completed_raster_tasks_.begin(); | |
229 it != completed_raster_tasks_.end(); | |
230 ++it) { | |
231 internal::WorkerPoolTask* task = it->get(); | |
232 RasterTaskState::Vector::iterator state_it = | |
233 std::find_if(raster_task_states_.begin(), | |
234 raster_task_states_.end(), | |
235 RasterTaskState::TaskComparator(task)); | |
236 DCHECK(state_it != raster_task_states_.end()); | |
237 DCHECK_EQ(RasterTaskState::COMPLETED, state_it->type); | |
238 | |
239 std::swap(*state_it, raster_task_states_.back()); | |
240 raster_task_states_.pop_back(); | |
211 | 241 |
212 task->RunReplyOnOriginThread(); | 242 task->RunReplyOnOriginThread(); |
213 | |
214 completed_image_decode_tasks_.pop_front(); | |
215 } | 243 } |
216 | 244 completed_raster_tasks_.clear(); |
217 while (!completed_raster_tasks_.empty()) { | |
218 internal::WorkerPoolTask* task = completed_raster_tasks_.front().get(); | |
219 DCHECK(raster_task_states_.find(task) != raster_task_states_.end()); | |
220 DCHECK_EQ(RasterTaskState::COMPLETED, raster_task_states_[task].type); | |
221 | |
222 raster_task_states_.erase(task); | |
223 | |
224 task->RunReplyOnOriginThread(); | |
225 | |
226 completed_raster_tasks_.pop_front(); | |
227 } | |
228 } | 245 } |
229 | 246 |
230 SkCanvas* PixelBufferRasterWorkerPool::AcquireCanvasForRaster( | 247 SkCanvas* PixelBufferRasterWorkerPool::AcquireCanvasForRaster( |
231 internal::WorkerPoolTask* task, | 248 internal::WorkerPoolTask* task, |
232 const Resource* resource) { | 249 const Resource* resource) { |
233 DCHECK(raster_task_states_.find(task) != raster_task_states_.end()); | 250 RasterTaskState::Vector::iterator it = |
234 DCHECK(!raster_task_states_[task].resource); | 251 std::find_if(raster_task_states_.begin(), |
235 raster_task_states_[task].resource = resource; | 252 raster_task_states_.end(), |
253 RasterTaskState::TaskComparator(task)); | |
254 DCHECK(it != raster_task_states_.end()); | |
255 DCHECK(!it->resource); | |
256 it->resource = resource; | |
236 resource_provider()->AcquirePixelRasterBuffer(resource->id()); | 257 resource_provider()->AcquirePixelRasterBuffer(resource->id()); |
237 return resource_provider()->MapPixelRasterBuffer(resource->id()); | 258 return resource_provider()->MapPixelRasterBuffer(resource->id()); |
238 } | 259 } |
239 | 260 |
240 void PixelBufferRasterWorkerPool::ReleaseCanvasForRaster( | 261 void PixelBufferRasterWorkerPool::ReleaseCanvasForRaster( |
241 internal::WorkerPoolTask* task, | 262 internal::WorkerPoolTask* task, |
242 const Resource* resource) { | 263 const Resource* resource) { |
243 DCHECK(raster_task_states_.find(task) != raster_task_states_.end()); | 264 RasterTaskState::Vector::iterator it = |
244 DCHECK(raster_task_states_[task].resource == resource); | 265 std::find_if(raster_task_states_.begin(), |
266 raster_task_states_.end(), | |
267 RasterTaskState::TaskComparator(task)); | |
268 DCHECK(it != raster_task_states_.end()); | |
269 DCHECK(it->resource == resource); | |
245 resource_provider()->ReleasePixelRasterBuffer(resource->id()); | 270 resource_provider()->ReleasePixelRasterBuffer(resource->id()); |
246 } | 271 } |
247 | 272 |
248 void PixelBufferRasterWorkerPool::OnRasterTasksFinished() { | 273 void PixelBufferRasterWorkerPool::OnRasterTasksFinished() { |
249 // |should_notify_client_if_no_tasks_are_pending_| can be set to false as | 274 // |should_notify_client_if_no_tasks_are_pending_| can be set to false as |
250 // a result of a scheduled CheckForCompletedRasterTasks() call. No need to | 275 // a result of a scheduled CheckForCompletedRasterTasks() call. No need to |
251 // perform another check in that case as we've already notified the client. | 276 // perform another check in that case as we've already notified the client. |
252 if (!should_notify_client_if_no_tasks_are_pending_) | 277 if (!should_notify_client_if_no_tasks_are_pending_) |
253 return; | 278 return; |
254 raster_finished_task_pending_ = false; | 279 raster_finished_task_pending_ = false; |
(...skipping 20 matching lines...) Expand all Loading... | |
275 | 300 |
276 void PixelBufferRasterWorkerPool::FlushUploads() { | 301 void PixelBufferRasterWorkerPool::FlushUploads() { |
277 if (!has_performed_uploads_since_last_flush_) | 302 if (!has_performed_uploads_since_last_flush_) |
278 return; | 303 return; |
279 | 304 |
280 resource_provider()->ShallowFlushIfSupported(); | 305 resource_provider()->ShallowFlushIfSupported(); |
281 has_performed_uploads_since_last_flush_ = false; | 306 has_performed_uploads_since_last_flush_ = false; |
282 } | 307 } |
283 | 308 |
284 void PixelBufferRasterWorkerPool::CheckForCompletedUploads() { | 309 void PixelBufferRasterWorkerPool::CheckForCompletedUploads() { |
285 TaskDeque tasks_with_completed_uploads; | 310 TaskVector tasks_with_completed_uploads; |
286 | 311 |
287 // First check if any have completed. | 312 // First check if any have completed. |
288 while (!raster_tasks_with_pending_upload_.empty()) { | 313 while (!raster_tasks_with_pending_upload_.empty()) { |
289 internal::WorkerPoolTask* task = | 314 internal::WorkerPoolTask* task = |
290 raster_tasks_with_pending_upload_.front().get(); | 315 raster_tasks_with_pending_upload_.front().get(); |
291 DCHECK(raster_task_states_.find(task) != raster_task_states_.end()); | 316 RasterTaskState::Vector::const_iterator it = |
292 const RasterTaskState& state = raster_task_states_[task]; | 317 std::find_if(raster_task_states_.begin(), |
293 DCHECK_EQ(RasterTaskState::UPLOADING, state.type); | 318 raster_task_states_.end(), |
319 RasterTaskState::TaskComparator(task)); | |
320 DCHECK(it != raster_task_states_.end()); | |
321 DCHECK_EQ(RasterTaskState::UPLOADING, it->type); | |
294 | 322 |
295 // Uploads complete in the order they are issued. | 323 // Uploads complete in the order they are issued. |
296 if (!resource_provider()->DidSetPixelsComplete(state.resource->id())) | 324 if (!resource_provider()->DidSetPixelsComplete(it->resource->id())) |
297 break; | 325 break; |
298 | 326 |
299 tasks_with_completed_uploads.push_back(task); | 327 tasks_with_completed_uploads.push_back(task); |
300 raster_tasks_with_pending_upload_.pop_front(); | 328 raster_tasks_with_pending_upload_.pop_front(); |
301 } | 329 } |
302 | 330 |
303 DCHECK(client()); | 331 DCHECK(client()); |
304 bool should_force_some_uploads_to_complete = | 332 bool should_force_some_uploads_to_complete = |
305 shutdown_ || client()->ShouldForceTasksRequiredForActivationToComplete(); | 333 shutdown_ || client()->ShouldForceTasksRequiredForActivationToComplete(); |
306 | 334 |
307 if (should_force_some_uploads_to_complete) { | 335 if (should_force_some_uploads_to_complete) { |
308 TaskDeque tasks_with_uploads_to_force; | 336 TaskVector tasks_with_uploads_to_force; |
309 TaskDeque::iterator it = raster_tasks_with_pending_upload_.begin(); | 337 TaskDeque::iterator it = raster_tasks_with_pending_upload_.begin(); |
310 while (it != raster_tasks_with_pending_upload_.end()) { | 338 while (it != raster_tasks_with_pending_upload_.end()) { |
311 internal::WorkerPoolTask* task = it->get(); | 339 internal::WorkerPoolTask* task = it->get(); |
312 DCHECK(raster_task_states_.find(task) != raster_task_states_.end()); | 340 RasterTaskState::Vector::const_iterator state_it = |
313 const RasterTaskState& state = raster_task_states_[task]; | 341 std::find_if(raster_task_states_.begin(), |
342 raster_task_states_.end(), | |
343 RasterTaskState::TaskComparator(task)); | |
344 DCHECK(state_it != raster_task_states_.end()); | |
314 | 345 |
315 // Force all uploads required for activation to complete. | 346 // Force all uploads required for activation to complete. |
316 // During shutdown, force all pending uploads to complete. | 347 // During shutdown, force all pending uploads to complete. |
317 if (shutdown_ || state.required_for_activation) { | 348 if (shutdown_ || state_it->required_for_activation) { |
318 tasks_with_uploads_to_force.push_back(task); | 349 tasks_with_uploads_to_force.push_back(task); |
319 tasks_with_completed_uploads.push_back(task); | 350 tasks_with_completed_uploads.push_back(task); |
320 it = raster_tasks_with_pending_upload_.erase(it); | 351 it = raster_tasks_with_pending_upload_.erase(it); |
321 continue; | 352 continue; |
322 } | 353 } |
323 | 354 |
324 ++it; | 355 ++it; |
325 } | 356 } |
326 | 357 |
327 // Force uploads in reverse order. Since forcing can cause a wait on | 358 // Force uploads in reverse order. Since forcing can cause a wait on |
328 // all previous uploads, we would rather wait only once downstream. | 359 // all previous uploads, we would rather wait only once downstream. |
329 for (TaskDeque::reverse_iterator it = tasks_with_uploads_to_force.rbegin(); | 360 for (TaskVector::reverse_iterator it = tasks_with_uploads_to_force.rbegin(); |
330 it != tasks_with_uploads_to_force.rend(); | 361 it != tasks_with_uploads_to_force.rend(); |
331 ++it) { | 362 ++it) { |
332 internal::WorkerPoolTask* task = it->get(); | 363 internal::WorkerPoolTask* task = it->get(); |
333 const RasterTaskState& state = raster_task_states_[task]; | 364 RasterTaskState::Vector::const_iterator state_it = |
334 DCHECK(state.resource); | 365 std::find_if(raster_task_states_.begin(), |
366 raster_task_states_.end(), | |
367 RasterTaskState::TaskComparator(task)); | |
368 DCHECK(state_it != raster_task_states_.end()); | |
369 DCHECK(state_it->resource); | |
335 | 370 |
336 resource_provider()->ForceSetPixelsToComplete(state.resource->id()); | 371 resource_provider()->ForceSetPixelsToComplete(state_it->resource->id()); |
337 has_performed_uploads_since_last_flush_ = true; | 372 has_performed_uploads_since_last_flush_ = true; |
338 } | 373 } |
339 } | 374 } |
340 | 375 |
341 // Release shared memory and move tasks with completed uploads | 376 // Release shared memory and move tasks with completed uploads |
342 // to |completed_raster_tasks_|. | 377 // to |completed_raster_tasks_|. |
343 while (!tasks_with_completed_uploads.empty()) { | 378 for (TaskVector::iterator it = tasks_with_completed_uploads.begin(); |
344 internal::WorkerPoolTask* task = tasks_with_completed_uploads.front().get(); | 379 it != tasks_with_completed_uploads.end(); |
345 RasterTaskState& state = raster_task_states_[task]; | 380 ++it) { |
381 internal::WorkerPoolTask* task = it->get(); | |
382 RasterTaskState::Vector::iterator state_it = | |
383 std::find_if(raster_task_states_.begin(), | |
384 raster_task_states_.end(), | |
385 RasterTaskState::TaskComparator(task)); | |
386 DCHECK(state_it != raster_task_states_.end()); | |
387 RasterTaskState& state = *state_it; | |
346 | 388 |
347 bytes_pending_upload_ -= state.resource->bytes(); | 389 bytes_pending_upload_ -= state.resource->bytes(); |
348 | 390 |
349 task->WillComplete(); | 391 task->WillComplete(); |
350 task->CompleteOnOriginThread(this); | 392 task->CompleteOnOriginThread(this); |
351 task->DidComplete(); | 393 task->DidComplete(); |
352 | 394 |
353 DCHECK(std::find(completed_raster_tasks_.begin(), | 395 DCHECK(std::find(completed_raster_tasks_.begin(), |
354 completed_raster_tasks_.end(), | 396 completed_raster_tasks_.end(), |
355 task) == completed_raster_tasks_.end()); | 397 task) == completed_raster_tasks_.end()); |
356 completed_raster_tasks_.push_back(task); | 398 completed_raster_tasks_.push_back(task); |
357 state.type = RasterTaskState::COMPLETED; | 399 state.type = RasterTaskState::COMPLETED; |
358 DCHECK_LE(state.required_for_activation, | 400 DCHECK_LE(state.required_for_activation, |
359 raster_tasks_required_for_activation_count_); | 401 raster_tasks_required_for_activation_count_); |
360 raster_tasks_required_for_activation_count_ -= | 402 raster_tasks_required_for_activation_count_ -= |
361 state.required_for_activation; | 403 state.required_for_activation; |
362 | |
363 tasks_with_completed_uploads.pop_front(); | |
364 } | 404 } |
365 } | 405 } |
366 | 406 |
367 void PixelBufferRasterWorkerPool::ScheduleCheckForCompletedRasterTasks() { | 407 void PixelBufferRasterWorkerPool::ScheduleCheckForCompletedRasterTasks() { |
368 base::TimeDelta delay = | 408 base::TimeDelta delay = |
369 base::TimeDelta::FromMilliseconds(kCheckForCompletedRasterTasksDelayMs); | 409 base::TimeDelta::FromMilliseconds(kCheckForCompletedRasterTasksDelayMs); |
370 if (check_for_completed_raster_tasks_time_.is_null()) | 410 if (check_for_completed_raster_tasks_time_.is_null()) |
371 check_for_completed_raster_tasks_time_ = base::TimeTicks::Now() + delay; | 411 check_for_completed_raster_tasks_time_ = base::TimeTicks::Now() + delay; |
372 | 412 |
373 if (check_for_completed_raster_tasks_pending_) | 413 if (check_for_completed_raster_tasks_pending_) |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
476 | 516 |
477 for (RasterTaskQueue::Item::Vector::const_iterator it = | 517 for (RasterTaskQueue::Item::Vector::const_iterator it = |
478 raster_tasks_.items.begin(); | 518 raster_tasks_.items.begin(); |
479 it != raster_tasks_.items.end(); | 519 it != raster_tasks_.items.end(); |
480 ++it) { | 520 ++it) { |
481 const RasterTaskQueue::Item& item = *it; | 521 const RasterTaskQueue::Item& item = *it; |
482 internal::RasterWorkerPoolTask* task = item.task; | 522 internal::RasterWorkerPoolTask* task = item.task; |
483 | 523 |
484 // |raster_task_states_| contains the state of all tasks that we have not | 524 // |raster_task_states_| contains the state of all tasks that we have not |
485 // yet run reply callbacks for. | 525 // yet run reply callbacks for. |
486 RasterTaskStateMap::iterator state_it = raster_task_states_.find(task); | 526 RasterTaskState::Vector::iterator state_it = |
527 std::find_if(raster_task_states_.begin(), | |
528 raster_task_states_.end(), | |
529 RasterTaskState::TaskComparator(task)); | |
487 if (state_it == raster_task_states_.end()) | 530 if (state_it == raster_task_states_.end()) |
488 continue; | 531 continue; |
489 | 532 |
490 RasterTaskState& state = state_it->second; | 533 RasterTaskState& state = *state_it; |
491 | 534 |
492 // Skip task if completed. | 535 // Skip task if completed. |
493 if (state.type == RasterTaskState::COMPLETED) { | 536 if (state.type == RasterTaskState::COMPLETED) { |
494 DCHECK(std::find(completed_raster_tasks_.begin(), | 537 DCHECK(std::find(completed_raster_tasks_.begin(), |
495 completed_raster_tasks_.end(), | 538 completed_raster_tasks_.end(), |
496 task) != completed_raster_tasks_.end()); | 539 task) != completed_raster_tasks_.end()); |
497 continue; | 540 continue; |
498 } | 541 } |
499 | 542 |
500 // All raster tasks need to be throttled by bytes of pending uploads. | 543 // All raster tasks need to be throttled by bytes of pending uploads. |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
622 } | 665 } |
623 | 666 |
624 void PixelBufferRasterWorkerPool::CheckForCompletedWorkerPoolTasks() { | 667 void PixelBufferRasterWorkerPool::CheckForCompletedWorkerPoolTasks() { |
625 CollectCompletedWorkerPoolTasks(&completed_tasks_); | 668 CollectCompletedWorkerPoolTasks(&completed_tasks_); |
626 for (internal::Task::Vector::const_iterator it = completed_tasks_.begin(); | 669 for (internal::Task::Vector::const_iterator it = completed_tasks_.begin(); |
627 it != completed_tasks_.end(); | 670 it != completed_tasks_.end(); |
628 ++it) { | 671 ++it) { |
629 internal::WorkerPoolTask* task = | 672 internal::WorkerPoolTask* task = |
630 static_cast<internal::WorkerPoolTask*>(it->get()); | 673 static_cast<internal::WorkerPoolTask*>(it->get()); |
631 | 674 |
632 RasterTaskStateMap::iterator state_it = raster_task_states_.find(task); | 675 RasterTaskState::Vector::iterator state_it = |
676 std::find_if(raster_task_states_.begin(), | |
677 raster_task_states_.end(), | |
678 RasterTaskState::TaskComparator(task)); | |
633 if (state_it == raster_task_states_.end()) { | 679 if (state_it == raster_task_states_.end()) { |
634 task->WillComplete(); | 680 task->WillComplete(); |
635 task->CompleteOnOriginThread(this); | 681 task->CompleteOnOriginThread(this); |
636 task->DidComplete(); | 682 task->DidComplete(); |
637 | 683 |
638 completed_image_decode_tasks_.push_back(task); | 684 completed_image_decode_tasks_.push_back(task); |
639 continue; | 685 continue; |
640 } | 686 } |
641 | 687 |
642 RasterTaskState& state = state_it->second; | 688 RasterTaskState& state = *state_it; |
643 DCHECK_EQ(RasterTaskState::SCHEDULED, state.type); | 689 DCHECK_EQ(RasterTaskState::SCHEDULED, state.type); |
644 DCHECK(state.resource); | 690 DCHECK(state.resource); |
645 | 691 |
646 // Balanced with MapPixelRasterBuffer() call in AcquireCanvasForRaster(). | 692 // Balanced with MapPixelRasterBuffer() call in AcquireCanvasForRaster(). |
647 bool content_has_changed = | 693 bool content_has_changed = |
648 resource_provider()->UnmapPixelRasterBuffer(state.resource->id()); | 694 resource_provider()->UnmapPixelRasterBuffer(state.resource->id()); |
649 | 695 |
650 // |content_has_changed| can be false as result of task being canceled or | 696 // |content_has_changed| can be false as result of task being canceled or |
651 // task implementation deciding not to modify bitmap (ie. analysis of raster | 697 // task implementation deciding not to modify bitmap (ie. analysis of raster |
652 // commands detected content as a solid color). | 698 // commands detected content as a solid color). |
653 if (!content_has_changed) { | 699 if (!content_has_changed) { |
654 task->WillComplete(); | 700 task->WillComplete(); |
655 task->CompleteOnOriginThread(this); | 701 task->CompleteOnOriginThread(this); |
656 task->DidComplete(); | 702 task->DidComplete(); |
657 | 703 |
658 if (!task->HasFinishedRunning()) { | 704 if (!task->HasFinishedRunning()) { |
659 // When priorites change, a raster task can be canceled as a result of | 705 // When priorites change, a raster task can be canceled as a result of |
660 // no longer being of high enough priority to fit in our throttled | 706 // no longer being of high enough priority to fit in our throttled |
661 // raster task budget. The task has not yet completed in this case. | 707 // raster task budget. The task has not yet completed in this case. |
662 for (RasterTaskQueue::Item::Vector::const_iterator it = | 708 for (RasterTaskQueue::Item::Vector::const_iterator item_it = |
663 raster_tasks_.items.begin(); | 709 raster_tasks_.items.begin(); |
664 it != raster_tasks_.items.end(); | 710 item_it != raster_tasks_.items.end(); |
665 ++it) { | 711 ++item_it) { |
666 if (it->task == task) { | 712 if (item_it->task == task) { |
667 state.type = RasterTaskState::UNSCHEDULED; | 713 state.type = RasterTaskState::UNSCHEDULED; |
668 state.resource = NULL; | 714 state.resource = NULL; |
669 continue; | 715 continue; |
vmpstr
2014/02/21 18:39:41
no need for continue
reveman
2014/02/22 11:32:01
Oh, this is a bug! This continue statement was sup
| |
670 } | 716 } |
671 } | 717 } |
672 } | 718 } |
673 | 719 |
674 DCHECK(std::find(completed_raster_tasks_.begin(), | 720 DCHECK(std::find(completed_raster_tasks_.begin(), |
675 completed_raster_tasks_.end(), | 721 completed_raster_tasks_.end(), |
676 task) == completed_raster_tasks_.end()); | 722 task) == completed_raster_tasks_.end()); |
677 completed_raster_tasks_.push_back(task); | 723 completed_raster_tasks_.push_back(task); |
678 state.type = RasterTaskState::COMPLETED; | 724 state.type = RasterTaskState::COMPLETED; |
679 DCHECK_LE(state.required_for_activation, | 725 DCHECK_LE(state.required_for_activation, |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
714 | 760 |
715 throttle_state->SetInteger("bytes_available_for_upload", | 761 throttle_state->SetInteger("bytes_available_for_upload", |
716 max_bytes_pending_upload_ - bytes_pending_upload_); | 762 max_bytes_pending_upload_ - bytes_pending_upload_); |
717 throttle_state->SetInteger("bytes_pending_upload", bytes_pending_upload_); | 763 throttle_state->SetInteger("bytes_pending_upload", bytes_pending_upload_); |
718 throttle_state->SetInteger("scheduled_raster_task_count", | 764 throttle_state->SetInteger("scheduled_raster_task_count", |
719 scheduled_raster_task_count_); | 765 scheduled_raster_task_count_); |
720 return throttle_state.PassAs<base::Value>(); | 766 return throttle_state.PassAs<base::Value>(); |
721 } | 767 } |
722 | 768 |
723 } // namespace cc | 769 } // namespace cc |
OLD | NEW |