Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(497)

Side by Side Diff: cc/resources/pixel_buffer_raster_worker_pool.cc

Issue 174453003: cc: Replace RasterTaskStateMap with a vector and brute force search instead of hash map lookups. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add comment Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cc/resources/pixel_buffer_raster_worker_pool.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
106 // Build new raster task state map. 107 // Update raster task state and remove items from old queue.
107 RasterTaskStateMap new_raster_task_states;
108 for (RasterTaskQueue::Item::Vector::const_iterator it = queue->items.begin(); 108 for (RasterTaskQueue::Item::Vector::const_iterator it = queue->items.begin();
109 it != queue->items.end(); 109 it != queue->items.end();
110 ++it) { 110 ++it) {
111 const RasterTaskQueue::Item& item = *it; 111 const RasterTaskQueue::Item& item = *it;
112 internal::WorkerPoolTask* task = item.task; 112 internal::WorkerPoolTask* task = item.task;
113 DCHECK(new_raster_task_states.find(task) == new_raster_task_states.end());
114 113
115 RasterTaskStateMap::iterator state_it = raster_task_states_.find(task); 114 // Remove any old items that are associated with this task. The result is
115 // that the old queue is left with all items not present in this queue,
116 // which we use below to determine what tasks need to be canceled.
117 RasterTaskQueue::Item::Vector::iterator old_it =
118 std::find_if(raster_tasks_.items.begin(),
119 raster_tasks_.items.end(),
120 RasterTaskQueue::Item::TaskComparator(task));
121 if (old_it != raster_tasks_.items.end()) {
122 std::swap(*old_it, raster_tasks_.items.back());
123 raster_tasks_.items.pop_back();
124 }
125
126 RasterTaskState::Vector::iterator state_it =
127 std::find_if(raster_task_states_.begin(),
128 raster_task_states_.end(),
129 RasterTaskState::TaskComparator(task));
116 if (state_it != raster_task_states_.end()) { 130 if (state_it != raster_task_states_.end()) {
117 const RasterTaskState& state = state_it->second; 131 RasterTaskState& state = *state_it;
118 132
119 new_raster_task_states[task] = 133 state.required_for_activation = item.required_for_activation;
120 RasterTaskState(state)
121 .set_required_for_activation(item.required_for_activation);
122 // |raster_tasks_required_for_activation_count| accounts for all tasks 134 // |raster_tasks_required_for_activation_count| accounts for all tasks
123 // that need to complete before we can send a "ready to activate" signal. 135 // 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. 136 // Tasks that have already completed should not be part of this count.
125 if (state.type != RasterTaskState::COMPLETED) { 137 if (state.type != RasterTaskState::COMPLETED) {
126 raster_tasks_required_for_activation_count_ += 138 raster_tasks_required_for_activation_count_ +=
127 item.required_for_activation; 139 item.required_for_activation;
128 } 140 }
141 continue;
142 }
129 143
130 raster_task_states_.erase(state_it); 144 DCHECK(!task->HasBeenScheduled());
131 } else { 145 raster_task_states_.push_back(
132 DCHECK(!task->HasBeenScheduled()); 146 RasterTaskState(task, item.required_for_activation));
133 new_raster_task_states[task] = 147 raster_tasks_required_for_activation_count_ += item.required_for_activation;
134 RasterTaskState().set_required_for_activation(
135 item.required_for_activation);
136 raster_tasks_required_for_activation_count_ +=
137 item.required_for_activation;
138 }
139 } 148 }
140 149
141 // Transfer old raster task state to |new_raster_task_states| and cancel all 150 // Determine what tasks in old queue need to be canceled.
142 // remaining unscheduled tasks. 151 for (RasterTaskQueue::Item::Vector::const_iterator it =
143 for (RasterTaskStateMap::const_iterator it = raster_task_states_.begin(); 152 raster_tasks_.items.begin();
144 it != raster_task_states_.end(); 153 it != raster_tasks_.items.end();
145 ++it) { 154 ++it) {
146 internal::WorkerPoolTask* task = it->first; 155 const RasterTaskQueue::Item& item = *it;
147 const RasterTaskState& state = it->second; 156 internal::WorkerPoolTask* task = item.task;
148 DCHECK(new_raster_task_states.find(task) == new_raster_task_states.end()); 157
158 RasterTaskState::Vector::iterator state_it =
159 std::find_if(raster_task_states_.begin(),
160 raster_task_states_.end(),
161 RasterTaskState::TaskComparator(task));
162 if (state_it == raster_task_states_.end())
163 continue; // Already processed completion of task.
vmpstr 2014/02/24 19:22:28 nit: Can you put the comment before the if instead
reveman 2014/02/24 19:37:42 Done.
164
165 RasterTaskState& state = *state_it;
149 166
150 // Unscheduled task can be canceled. 167 // Unscheduled task can be canceled.
151 if (state.type == RasterTaskState::UNSCHEDULED) { 168 if (state.type == RasterTaskState::UNSCHEDULED) {
152 DCHECK(!task->HasBeenScheduled()); 169 DCHECK(!task->HasBeenScheduled());
153 DCHECK(std::find(completed_raster_tasks_.begin(), 170 DCHECK(std::find(completed_raster_tasks_.begin(),
154 completed_raster_tasks_.end(), 171 completed_raster_tasks_.end(),
155 task) == completed_raster_tasks_.end()); 172 task) == completed_raster_tasks_.end());
156 completed_raster_tasks_.push_back(task); 173 completed_raster_tasks_.push_back(task);
157 new_raster_task_states[task] = RasterTaskState(state).set_completed(); 174 state.type = RasterTaskState::COMPLETED;
158 continue;
159 } 175 }
160 176
161 // Move state to |new_raster_task_states|. 177 // No longer required for activation.
162 new_raster_task_states[task] = 178 state.required_for_activation = false;
163 RasterTaskState(state).set_required_for_activation(false);
164 } 179 }
165 180
166 raster_tasks_.Swap(queue); 181 raster_tasks_.Swap(queue);
167 raster_task_states_.swap(new_raster_task_states);
168 182
169 // Check for completed tasks when ScheduleTasks() is called as 183 // Check for completed tasks when ScheduleTasks() is called as
170 // priorities might have changed and this maximizes the number 184 // priorities might have changed and this maximizes the number
171 // of top priority tasks that are scheduled. 185 // of top priority tasks that are scheduled.
172 CheckForCompletedWorkerPoolTasks(); 186 CheckForCompletedWorkerPoolTasks();
173 CheckForCompletedUploads(); 187 CheckForCompletedUploads();
174 FlushUploads(); 188 FlushUploads();
175 189
176 // Schedule new tasks. 190 // Schedule new tasks.
177 ScheduleMoreTasks(); 191 ScheduleMoreTasks();
(...skipping 20 matching lines...) Expand all
198 return resource_provider()->memory_efficient_texture_format(); 212 return resource_provider()->memory_efficient_texture_format();
199 } 213 }
200 214
201 void PixelBufferRasterWorkerPool::CheckForCompletedTasks() { 215 void PixelBufferRasterWorkerPool::CheckForCompletedTasks() {
202 TRACE_EVENT0("cc", "PixelBufferRasterWorkerPool::CheckForCompletedTasks"); 216 TRACE_EVENT0("cc", "PixelBufferRasterWorkerPool::CheckForCompletedTasks");
203 217
204 CheckForCompletedWorkerPoolTasks(); 218 CheckForCompletedWorkerPoolTasks();
205 CheckForCompletedUploads(); 219 CheckForCompletedUploads();
206 FlushUploads(); 220 FlushUploads();
207 221
208 while (!completed_image_decode_tasks_.empty()) { 222 for (TaskVector::const_iterator it = completed_image_decode_tasks_.begin();
209 internal::WorkerPoolTask* task = 223 it != completed_image_decode_tasks_.end();
210 completed_image_decode_tasks_.front().get(); 224 ++it) {
225 internal::WorkerPoolTask* task = it->get();
226 task->RunReplyOnOriginThread();
227 }
228 completed_image_decode_tasks_.clear();
229
230 for (TaskVector::const_iterator it = completed_raster_tasks_.begin();
231 it != completed_raster_tasks_.end();
232 ++it) {
233 internal::WorkerPoolTask* task = it->get();
234 RasterTaskState::Vector::iterator state_it =
235 std::find_if(raster_task_states_.begin(),
236 raster_task_states_.end(),
237 RasterTaskState::TaskComparator(task));
238 DCHECK(state_it != raster_task_states_.end());
239 DCHECK_EQ(RasterTaskState::COMPLETED, state_it->type);
240
241 std::swap(*state_it, raster_task_states_.back());
242 raster_task_states_.pop_back();
211 243
212 task->RunReplyOnOriginThread(); 244 task->RunReplyOnOriginThread();
213
214 completed_image_decode_tasks_.pop_front();
215 } 245 }
216 246 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 } 247 }
229 248
230 SkCanvas* PixelBufferRasterWorkerPool::AcquireCanvasForRaster( 249 SkCanvas* PixelBufferRasterWorkerPool::AcquireCanvasForRaster(
231 internal::WorkerPoolTask* task, 250 internal::WorkerPoolTask* task,
232 const Resource* resource) { 251 const Resource* resource) {
233 DCHECK(raster_task_states_.find(task) != raster_task_states_.end()); 252 RasterTaskState::Vector::iterator it =
234 DCHECK(!raster_task_states_[task].resource); 253 std::find_if(raster_task_states_.begin(),
235 raster_task_states_[task].resource = resource; 254 raster_task_states_.end(),
255 RasterTaskState::TaskComparator(task));
256 DCHECK(it != raster_task_states_.end());
257 DCHECK(!it->resource);
258 it->resource = resource;
236 resource_provider()->AcquirePixelRasterBuffer(resource->id()); 259 resource_provider()->AcquirePixelRasterBuffer(resource->id());
237 return resource_provider()->MapPixelRasterBuffer(resource->id()); 260 return resource_provider()->MapPixelRasterBuffer(resource->id());
238 } 261 }
239 262
240 void PixelBufferRasterWorkerPool::ReleaseCanvasForRaster( 263 void PixelBufferRasterWorkerPool::ReleaseCanvasForRaster(
241 internal::WorkerPoolTask* task, 264 internal::WorkerPoolTask* task,
242 const Resource* resource) { 265 const Resource* resource) {
243 DCHECK(raster_task_states_.find(task) != raster_task_states_.end()); 266 RasterTaskState::Vector::iterator it =
244 DCHECK(raster_task_states_[task].resource == resource); 267 std::find_if(raster_task_states_.begin(),
268 raster_task_states_.end(),
269 RasterTaskState::TaskComparator(task));
270 DCHECK(it != raster_task_states_.end());
271 DCHECK(it->resource == resource);
245 resource_provider()->ReleasePixelRasterBuffer(resource->id()); 272 resource_provider()->ReleasePixelRasterBuffer(resource->id());
246 } 273 }
247 274
248 void PixelBufferRasterWorkerPool::OnRasterTasksFinished() { 275 void PixelBufferRasterWorkerPool::OnRasterTasksFinished() {
249 // |should_notify_client_if_no_tasks_are_pending_| can be set to false as 276 // |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 277 // a result of a scheduled CheckForCompletedRasterTasks() call. No need to
251 // perform another check in that case as we've already notified the client. 278 // perform another check in that case as we've already notified the client.
252 if (!should_notify_client_if_no_tasks_are_pending_) 279 if (!should_notify_client_if_no_tasks_are_pending_)
253 return; 280 return;
254 raster_finished_task_pending_ = false; 281 raster_finished_task_pending_ = false;
(...skipping 20 matching lines...) Expand all
275 302
276 void PixelBufferRasterWorkerPool::FlushUploads() { 303 void PixelBufferRasterWorkerPool::FlushUploads() {
277 if (!has_performed_uploads_since_last_flush_) 304 if (!has_performed_uploads_since_last_flush_)
278 return; 305 return;
279 306
280 resource_provider()->ShallowFlushIfSupported(); 307 resource_provider()->ShallowFlushIfSupported();
281 has_performed_uploads_since_last_flush_ = false; 308 has_performed_uploads_since_last_flush_ = false;
282 } 309 }
283 310
284 void PixelBufferRasterWorkerPool::CheckForCompletedUploads() { 311 void PixelBufferRasterWorkerPool::CheckForCompletedUploads() {
285 TaskDeque tasks_with_completed_uploads; 312 TaskVector tasks_with_completed_uploads;
286 313
287 // First check if any have completed. 314 // First check if any have completed.
288 while (!raster_tasks_with_pending_upload_.empty()) { 315 while (!raster_tasks_with_pending_upload_.empty()) {
289 internal::WorkerPoolTask* task = 316 internal::WorkerPoolTask* task =
290 raster_tasks_with_pending_upload_.front().get(); 317 raster_tasks_with_pending_upload_.front().get();
291 DCHECK(raster_task_states_.find(task) != raster_task_states_.end()); 318 RasterTaskState::Vector::const_iterator it =
292 const RasterTaskState& state = raster_task_states_[task]; 319 std::find_if(raster_task_states_.begin(),
293 DCHECK_EQ(RasterTaskState::UPLOADING, state.type); 320 raster_task_states_.end(),
321 RasterTaskState::TaskComparator(task));
322 DCHECK(it != raster_task_states_.end());
323 DCHECK_EQ(RasterTaskState::UPLOADING, it->type);
294 324
295 // Uploads complete in the order they are issued. 325 // Uploads complete in the order they are issued.
296 if (!resource_provider()->DidSetPixelsComplete(state.resource->id())) 326 if (!resource_provider()->DidSetPixelsComplete(it->resource->id()))
297 break; 327 break;
298 328
299 tasks_with_completed_uploads.push_back(task); 329 tasks_with_completed_uploads.push_back(task);
300 raster_tasks_with_pending_upload_.pop_front(); 330 raster_tasks_with_pending_upload_.pop_front();
301 } 331 }
302 332
303 DCHECK(client()); 333 DCHECK(client());
304 bool should_force_some_uploads_to_complete = 334 bool should_force_some_uploads_to_complete =
305 shutdown_ || client()->ShouldForceTasksRequiredForActivationToComplete(); 335 shutdown_ || client()->ShouldForceTasksRequiredForActivationToComplete();
306 336
307 if (should_force_some_uploads_to_complete) { 337 if (should_force_some_uploads_to_complete) {
308 TaskDeque tasks_with_uploads_to_force; 338 TaskVector tasks_with_uploads_to_force;
309 TaskDeque::iterator it = raster_tasks_with_pending_upload_.begin(); 339 TaskDeque::iterator it = raster_tasks_with_pending_upload_.begin();
310 while (it != raster_tasks_with_pending_upload_.end()) { 340 while (it != raster_tasks_with_pending_upload_.end()) {
311 internal::WorkerPoolTask* task = it->get(); 341 internal::WorkerPoolTask* task = it->get();
312 DCHECK(raster_task_states_.find(task) != raster_task_states_.end()); 342 RasterTaskState::Vector::const_iterator state_it =
313 const RasterTaskState& state = raster_task_states_[task]; 343 std::find_if(raster_task_states_.begin(),
344 raster_task_states_.end(),
345 RasterTaskState::TaskComparator(task));
346 DCHECK(state_it != raster_task_states_.end());
314 347
315 // Force all uploads required for activation to complete. 348 // Force all uploads required for activation to complete.
316 // During shutdown, force all pending uploads to complete. 349 // During shutdown, force all pending uploads to complete.
317 if (shutdown_ || state.required_for_activation) { 350 if (shutdown_ || state_it->required_for_activation) {
318 tasks_with_uploads_to_force.push_back(task); 351 tasks_with_uploads_to_force.push_back(task);
319 tasks_with_completed_uploads.push_back(task); 352 tasks_with_completed_uploads.push_back(task);
320 it = raster_tasks_with_pending_upload_.erase(it); 353 it = raster_tasks_with_pending_upload_.erase(it);
321 continue; 354 continue;
322 } 355 }
323 356
324 ++it; 357 ++it;
325 } 358 }
326 359
327 // Force uploads in reverse order. Since forcing can cause a wait on 360 // Force uploads in reverse order. Since forcing can cause a wait on
328 // all previous uploads, we would rather wait only once downstream. 361 // all previous uploads, we would rather wait only once downstream.
329 for (TaskDeque::reverse_iterator it = tasks_with_uploads_to_force.rbegin(); 362 for (TaskVector::const_reverse_iterator it =
363 tasks_with_uploads_to_force.rbegin();
330 it != tasks_with_uploads_to_force.rend(); 364 it != tasks_with_uploads_to_force.rend();
331 ++it) { 365 ++it) {
332 internal::WorkerPoolTask* task = it->get(); 366 internal::WorkerPoolTask* task = it->get();
333 const RasterTaskState& state = raster_task_states_[task]; 367 RasterTaskState::Vector::const_iterator state_it =
334 DCHECK(state.resource); 368 std::find_if(raster_task_states_.begin(),
369 raster_task_states_.end(),
370 RasterTaskState::TaskComparator(task));
371 DCHECK(state_it != raster_task_states_.end());
372 DCHECK(state_it->resource);
335 373
336 resource_provider()->ForceSetPixelsToComplete(state.resource->id()); 374 resource_provider()->ForceSetPixelsToComplete(state_it->resource->id());
337 has_performed_uploads_since_last_flush_ = true; 375 has_performed_uploads_since_last_flush_ = true;
338 } 376 }
339 } 377 }
340 378
341 // Release shared memory and move tasks with completed uploads 379 // Release shared memory and move tasks with completed uploads
342 // to |completed_raster_tasks_|. 380 // to |completed_raster_tasks_|.
343 while (!tasks_with_completed_uploads.empty()) { 381 for (TaskVector::const_iterator it = tasks_with_completed_uploads.begin();
344 internal::WorkerPoolTask* task = tasks_with_completed_uploads.front().get(); 382 it != tasks_with_completed_uploads.end();
345 RasterTaskState& state = raster_task_states_[task]; 383 ++it) {
384 internal::WorkerPoolTask* task = it->get();
385 RasterTaskState::Vector::iterator state_it =
386 std::find_if(raster_task_states_.begin(),
387 raster_task_states_.end(),
388 RasterTaskState::TaskComparator(task));
389 DCHECK(state_it != raster_task_states_.end());
390 RasterTaskState& state = *state_it;
346 391
347 bytes_pending_upload_ -= state.resource->bytes(); 392 bytes_pending_upload_ -= state.resource->bytes();
348 393
349 task->WillComplete(); 394 task->WillComplete();
350 task->CompleteOnOriginThread(this); 395 task->CompleteOnOriginThread(this);
351 task->DidComplete(); 396 task->DidComplete();
352 397
353 DCHECK(std::find(completed_raster_tasks_.begin(), 398 DCHECK(std::find(completed_raster_tasks_.begin(),
354 completed_raster_tasks_.end(), 399 completed_raster_tasks_.end(),
355 task) == completed_raster_tasks_.end()); 400 task) == completed_raster_tasks_.end());
356 completed_raster_tasks_.push_back(task); 401 completed_raster_tasks_.push_back(task);
357 state.type = RasterTaskState::COMPLETED; 402 state.type = RasterTaskState::COMPLETED;
358 DCHECK_LE(state.required_for_activation, 403 DCHECK_LE(state.required_for_activation,
359 raster_tasks_required_for_activation_count_); 404 raster_tasks_required_for_activation_count_);
360 raster_tasks_required_for_activation_count_ -= 405 raster_tasks_required_for_activation_count_ -=
361 state.required_for_activation; 406 state.required_for_activation;
362
363 tasks_with_completed_uploads.pop_front();
364 } 407 }
365 } 408 }
366 409
367 void PixelBufferRasterWorkerPool::ScheduleCheckForCompletedRasterTasks() { 410 void PixelBufferRasterWorkerPool::ScheduleCheckForCompletedRasterTasks() {
368 base::TimeDelta delay = 411 base::TimeDelta delay =
369 base::TimeDelta::FromMilliseconds(kCheckForCompletedRasterTasksDelayMs); 412 base::TimeDelta::FromMilliseconds(kCheckForCompletedRasterTasksDelayMs);
370 if (check_for_completed_raster_tasks_time_.is_null()) 413 if (check_for_completed_raster_tasks_time_.is_null())
371 check_for_completed_raster_tasks_time_ = base::TimeTicks::Now() + delay; 414 check_for_completed_raster_tasks_time_ = base::TimeTicks::Now() + delay;
372 415
373 if (check_for_completed_raster_tasks_pending_) 416 if (check_for_completed_raster_tasks_pending_)
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 519
477 for (RasterTaskQueue::Item::Vector::const_iterator it = 520 for (RasterTaskQueue::Item::Vector::const_iterator it =
478 raster_tasks_.items.begin(); 521 raster_tasks_.items.begin();
479 it != raster_tasks_.items.end(); 522 it != raster_tasks_.items.end();
480 ++it) { 523 ++it) {
481 const RasterTaskQueue::Item& item = *it; 524 const RasterTaskQueue::Item& item = *it;
482 internal::RasterWorkerPoolTask* task = item.task; 525 internal::RasterWorkerPoolTask* task = item.task;
483 526
484 // |raster_task_states_| contains the state of all tasks that we have not 527 // |raster_task_states_| contains the state of all tasks that we have not
485 // yet run reply callbacks for. 528 // yet run reply callbacks for.
486 RasterTaskStateMap::iterator state_it = raster_task_states_.find(task); 529 RasterTaskState::Vector::iterator state_it =
530 std::find_if(raster_task_states_.begin(),
531 raster_task_states_.end(),
532 RasterTaskState::TaskComparator(task));
487 if (state_it == raster_task_states_.end()) 533 if (state_it == raster_task_states_.end())
488 continue; 534 continue;
489 535
490 RasterTaskState& state = state_it->second; 536 RasterTaskState& state = *state_it;
491 537
492 // Skip task if completed. 538 // Skip task if completed.
493 if (state.type == RasterTaskState::COMPLETED) { 539 if (state.type == RasterTaskState::COMPLETED) {
494 DCHECK(std::find(completed_raster_tasks_.begin(), 540 DCHECK(std::find(completed_raster_tasks_.begin(),
495 completed_raster_tasks_.end(), 541 completed_raster_tasks_.end(),
496 task) != completed_raster_tasks_.end()); 542 task) != completed_raster_tasks_.end());
497 continue; 543 continue;
498 } 544 }
499 545
500 // All raster tasks need to be throttled by bytes of pending uploads. 546 // All raster tasks need to be throttled by bytes of pending uploads.
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 } 668 }
623 669
624 void PixelBufferRasterWorkerPool::CheckForCompletedWorkerPoolTasks() { 670 void PixelBufferRasterWorkerPool::CheckForCompletedWorkerPoolTasks() {
625 CollectCompletedWorkerPoolTasks(&completed_tasks_); 671 CollectCompletedWorkerPoolTasks(&completed_tasks_);
626 for (internal::Task::Vector::const_iterator it = completed_tasks_.begin(); 672 for (internal::Task::Vector::const_iterator it = completed_tasks_.begin();
627 it != completed_tasks_.end(); 673 it != completed_tasks_.end();
628 ++it) { 674 ++it) {
629 internal::WorkerPoolTask* task = 675 internal::WorkerPoolTask* task =
630 static_cast<internal::WorkerPoolTask*>(it->get()); 676 static_cast<internal::WorkerPoolTask*>(it->get());
631 677
632 RasterTaskStateMap::iterator state_it = raster_task_states_.find(task); 678 RasterTaskState::Vector::iterator state_it =
679 std::find_if(raster_task_states_.begin(),
680 raster_task_states_.end(),
681 RasterTaskState::TaskComparator(task));
633 if (state_it == raster_task_states_.end()) { 682 if (state_it == raster_task_states_.end()) {
634 task->WillComplete(); 683 task->WillComplete();
635 task->CompleteOnOriginThread(this); 684 task->CompleteOnOriginThread(this);
636 task->DidComplete(); 685 task->DidComplete();
637 686
638 completed_image_decode_tasks_.push_back(task); 687 completed_image_decode_tasks_.push_back(task);
639 continue; 688 continue;
640 } 689 }
641 690
642 RasterTaskState& state = state_it->second; 691 RasterTaskState& state = *state_it;
643 DCHECK_EQ(RasterTaskState::SCHEDULED, state.type); 692 DCHECK_EQ(RasterTaskState::SCHEDULED, state.type);
644 DCHECK(state.resource); 693 DCHECK(state.resource);
645 694
646 // Balanced with MapPixelRasterBuffer() call in AcquireCanvasForRaster(). 695 // Balanced with MapPixelRasterBuffer() call in AcquireCanvasForRaster().
647 bool content_has_changed = 696 bool content_has_changed =
648 resource_provider()->UnmapPixelRasterBuffer(state.resource->id()); 697 resource_provider()->UnmapPixelRasterBuffer(state.resource->id());
649 698
650 // |content_has_changed| can be false as result of task being canceled or 699 // |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 700 // task implementation deciding not to modify bitmap (ie. analysis of raster
652 // commands detected content as a solid color). 701 // commands detected content as a solid color).
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
713 762
714 throttle_state->SetInteger("bytes_available_for_upload", 763 throttle_state->SetInteger("bytes_available_for_upload",
715 max_bytes_pending_upload_ - bytes_pending_upload_); 764 max_bytes_pending_upload_ - bytes_pending_upload_);
716 throttle_state->SetInteger("bytes_pending_upload", bytes_pending_upload_); 765 throttle_state->SetInteger("bytes_pending_upload", bytes_pending_upload_);
717 throttle_state->SetInteger("scheduled_raster_task_count", 766 throttle_state->SetInteger("scheduled_raster_task_count",
718 scheduled_raster_task_count_); 767 scheduled_raster_task_count_);
719 return throttle_state.PassAs<base::Value>(); 768 return throttle_state.PassAs<base::Value>();
720 } 769 }
721 770
722 } // namespace cc 771 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/pixel_buffer_raster_worker_pool.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698