Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/resources/pixel_buffer_raster_worker_pool.h" | 5 #include "cc/resources/pixel_buffer_raster_worker_pool.h" |
| 6 | 6 |
| 7 #include "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
| 8 #include "cc/resources/resource.h" | 8 #include "cc/resources/resource.h" |
| 9 #include "third_party/skia/include/core/SkDevice.h" | 9 #include "third_party/skia/include/core/SkDevice.h" |
| 10 | 10 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 77 | 77 |
| 78 const int kCheckForCompletedRasterTasksDelayMs = 6; | 78 const int kCheckForCompletedRasterTasksDelayMs = 6; |
| 79 | 79 |
| 80 const size_t kMaxPendingRasterBytes = | 80 const size_t kMaxPendingRasterBytes = |
| 81 kMaxBytesUploadedPerMs * kCheckForCompletedRasterTasksDelayMs; | 81 kMaxBytesUploadedPerMs * kCheckForCompletedRasterTasksDelayMs; |
| 82 | 82 |
| 83 } // namespace | 83 } // namespace |
| 84 | 84 |
| 85 PixelBufferRasterWorkerPool::PixelBufferRasterWorkerPool( | 85 PixelBufferRasterWorkerPool::PixelBufferRasterWorkerPool( |
| 86 ResourceProvider* resource_provider, | 86 ResourceProvider* resource_provider, |
| 87 size_t num_threads) : RasterWorkerPool(resource_provider, num_threads), | 87 size_t num_threads) |
| 88 shutdown_(false), | 88 : RasterWorkerPool(resource_provider, num_threads), |
| 89 bytes_pending_upload_(0), | 89 shutdown_(false), |
| 90 has_performed_uploads_since_last_flush_(false), | 90 bytes_pending_upload_(0), |
| 91 check_for_completed_raster_tasks_pending_(false) { | 91 has_performed_uploads_since_last_flush_(false), |
| 92 check_for_completed_raster_tasks_pending_(false), | |
| 93 num_scheduled_raster_tasks_(0), | |
| 94 num_scheduled_raster_tasks_required_for_activation_(0), | |
| 95 finished_running_tasks_pending_(false), | |
| 96 finished_running_tasks_required_for_activation_pending_(false) { | |
| 92 } | 97 } |
| 93 | 98 |
| 94 PixelBufferRasterWorkerPool::~PixelBufferRasterWorkerPool() { | 99 PixelBufferRasterWorkerPool::~PixelBufferRasterWorkerPool() { |
| 95 DCHECK(shutdown_); | 100 DCHECK(shutdown_); |
| 96 DCHECK(!check_for_completed_raster_tasks_pending_); | 101 DCHECK(!check_for_completed_raster_tasks_pending_); |
| 97 DCHECK_EQ(0u, pixel_buffer_tasks_.size()); | 102 DCHECK_EQ(0u, pixel_buffer_tasks_.size()); |
| 98 DCHECK_EQ(0u, tasks_with_pending_upload_.size()); | 103 DCHECK_EQ(0u, tasks_with_pending_upload_.size()); |
| 99 DCHECK_EQ(0u, completed_tasks_.size()); | 104 DCHECK_EQ(0u, completed_tasks_.size()); |
| 100 } | 105 } |
| 101 | 106 |
| 102 void PixelBufferRasterWorkerPool::Shutdown() { | 107 void PixelBufferRasterWorkerPool::Shutdown() { |
| 103 shutdown_ = true; | 108 shutdown_ = true; |
| 104 RasterWorkerPool::Shutdown(); | 109 RasterWorkerPool::Shutdown(); |
| 105 CheckForCompletedRasterTasks(); | 110 RasterWorkerPool::CheckForCompletedTasks(); |
| 111 CheckForCompletedUploads(); | |
| 112 check_for_completed_raster_tasks_callback_.Cancel(); | |
| 113 check_for_completed_raster_tasks_pending_ = false; | |
| 106 for (TaskMap::iterator it = pixel_buffer_tasks_.begin(); | 114 for (TaskMap::iterator it = pixel_buffer_tasks_.begin(); |
| 107 it != pixel_buffer_tasks_.end(); ++it) { | 115 it != pixel_buffer_tasks_.end(); ++it) { |
| 108 internal::RasterWorkerPoolTask* task = it->first; | 116 internal::RasterWorkerPoolTask* task = it->first; |
| 109 internal::WorkerPoolTask* pixel_buffer_task = it->second.get(); | 117 internal::WorkerPoolTask* pixel_buffer_task = it->second.get(); |
| 110 | 118 |
| 111 // All inactive tasks needs to be canceled. | 119 // All inactive tasks needs to be canceled. |
| 112 if (!pixel_buffer_task && !task->HasFinishedRunning()) { | 120 if (!pixel_buffer_task && !task->HasFinishedRunning()) { |
| 113 task->DidRun(true); | 121 task->DidRun(true); |
| 114 completed_tasks_.push_back(task); | 122 completed_tasks_.push_back(task); |
| 115 } | 123 } |
| 116 } | 124 } |
| 125 DCHECK_EQ(completed_tasks_.size(), pixel_buffer_tasks_.size()); | |
| 117 } | 126 } |
| 118 | 127 |
| 119 void PixelBufferRasterWorkerPool::ScheduleTasks(RasterTask::Queue* queue) { | 128 void PixelBufferRasterWorkerPool::ScheduleTasks(RasterTask::Queue* queue) { |
| 120 TRACE_EVENT0("cc", "PixelBufferRasterWorkerPool::ScheduleTasks"); | 129 TRACE_EVENT0("cc", "PixelBufferRasterWorkerPool::ScheduleTasks"); |
| 121 | 130 |
| 122 RasterWorkerPool::SetRasterTasks(queue); | 131 RasterWorkerPool::SetRasterTasks(queue); |
| 123 | 132 |
| 133 finished_running_tasks_pending_ = true; | |
| 134 finished_running_tasks_required_for_activation_pending_ = true; | |
| 135 | |
| 124 // Build new pixel buffer task set. | 136 // Build new pixel buffer task set. |
| 125 TaskMap new_pixel_buffer_tasks; | 137 TaskMap new_pixel_buffer_tasks; |
| 126 for (RasterTaskVector::const_iterator it = raster_tasks().begin(); | 138 for (RasterTaskVector::const_iterator it = raster_tasks().begin(); |
| 127 it != raster_tasks().end(); ++it) { | 139 it != raster_tasks().end(); ++it) { |
| 128 internal::RasterWorkerPoolTask* task = it->get(); | 140 internal::RasterWorkerPoolTask* task = it->get(); |
| 129 DCHECK(new_pixel_buffer_tasks.find(task) == new_pixel_buffer_tasks.end()); | 141 DCHECK(new_pixel_buffer_tasks.find(task) == new_pixel_buffer_tasks.end()); |
| 130 DCHECK(!task->HasCompleted()); | 142 DCHECK(!task->HasCompleted()); |
| 131 | 143 |
| 132 // Use existing pixel buffer task if available. | 144 // Use existing pixel buffer task if available. |
| 133 TaskMap::iterator pixel_buffer_it = pixel_buffer_tasks_.find(task); | 145 TaskMap::iterator pixel_buffer_it = pixel_buffer_tasks_.find(task); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 153 // Inactive task can be canceled. | 165 // Inactive task can be canceled. |
| 154 if (!pixel_buffer_task && !task->HasFinishedRunning()) { | 166 if (!pixel_buffer_task && !task->HasFinishedRunning()) { |
| 155 task->DidRun(true); | 167 task->DidRun(true); |
| 156 DCHECK(std::find(completed_tasks_.begin(), | 168 DCHECK(std::find(completed_tasks_.begin(), |
| 157 completed_tasks_.end(), | 169 completed_tasks_.end(), |
| 158 task) == completed_tasks_.end()); | 170 task) == completed_tasks_.end()); |
| 159 completed_tasks_.push_back(task); | 171 completed_tasks_.push_back(task); |
| 160 } | 172 } |
| 161 } | 173 } |
| 162 | 174 |
| 175 tasks_required_for_activation_.clear(); | |
| 176 raster_tasks_required_for_activation_.clear(); | |
| 177 for (TaskMap::iterator it = new_pixel_buffer_tasks.begin(); | |
| 178 it != new_pixel_buffer_tasks.end(); ++it) { | |
| 179 internal::RasterWorkerPoolTask* task = it->first; | |
| 180 if (IsRasterTaskRequiredForActivation(task)) { | |
| 181 internal::WorkerPoolTask* pixel_buffer_task = it->second.get(); | |
| 182 | |
| 183 tasks_required_for_activation_.insert(task); | |
| 184 if (!pixel_buffer_task || !pixel_buffer_task->HasCompleted()) | |
| 185 raster_tasks_required_for_activation_.insert(task); | |
| 186 } | |
| 187 } | |
| 188 | |
| 163 pixel_buffer_tasks_.swap(new_pixel_buffer_tasks); | 189 pixel_buffer_tasks_.swap(new_pixel_buffer_tasks); |
| 164 | 190 |
| 165 // This will schedule more tasks after checking for completed raster | 191 // Check for completed tasks when ScheduleTasks() is called as |
| 166 // tasks. It's worth checking for completed tasks when ScheduleTasks() | 192 // priorities might have changed and this maximizes the number |
| 167 // is called as priorities might have changed and this allows us to | 193 // of top priority tasks that are scheduled. |
| 168 // schedule as many new top priority tasks as possible. | 194 RasterWorkerPool::CheckForCompletedTasks(); |
| 169 CheckForCompletedRasterTasks(); | 195 CheckForCompletedUploads(); |
| 196 FlushUploads(); | |
| 197 | |
| 198 // Schedule new tasks. | |
| 199 ScheduleMoreTasks(); | |
| 200 | |
| 201 // Cancel any pending check for completed raster tasks and schedule | |
| 202 // another check. | |
| 203 check_for_completed_raster_tasks_callback_.Cancel(); | |
| 204 check_for_completed_raster_tasks_pending_ = false; | |
| 205 ScheduleCheckForCompletedRasterTasks(); | |
| 170 } | 206 } |
| 171 | 207 |
| 172 void PixelBufferRasterWorkerPool::CheckForCompletedTasks() { | 208 void PixelBufferRasterWorkerPool::CheckForCompletedTasks() { |
| 173 TRACE_EVENT0("cc", "PixelBufferRasterWorkerPool::CheckForCompletedTasks"); | 209 TRACE_EVENT0("cc", "PixelBufferRasterWorkerPool::CheckForCompletedTasks"); |
| 174 | 210 |
| 175 RasterWorkerPool::CheckForCompletedTasks(); | 211 RasterWorkerPool::CheckForCompletedTasks(); |
| 176 CheckForCompletedUploads(); | 212 CheckForCompletedUploads(); |
| 177 FlushUploads(); | 213 FlushUploads(); |
| 178 | 214 |
| 179 while (!completed_tasks_.empty()) { | 215 TaskDeque completed_tasks; |
| 180 internal::RasterWorkerPoolTask* task = completed_tasks_.front().get(); | 216 completed_tasks_.swap(completed_tasks); |
| 217 | |
| 218 while (!completed_tasks.empty()) { | |
| 219 internal::RasterWorkerPoolTask* task = completed_tasks.front().get(); | |
| 181 DCHECK(pixel_buffer_tasks_.find(task) != pixel_buffer_tasks_.end()); | 220 DCHECK(pixel_buffer_tasks_.find(task) != pixel_buffer_tasks_.end()); |
| 182 | 221 |
| 183 pixel_buffer_tasks_.erase(task); | 222 pixel_buffer_tasks_.erase(task); |
| 184 | 223 |
| 185 task->DidComplete(); | 224 task->DidComplete(); |
| 186 task->DispatchCompletionCallback(); | 225 task->DispatchCompletionCallback(); |
| 187 | 226 |
| 188 completed_tasks_.pop_front(); | 227 completed_tasks.pop_front(); |
| 189 } | 228 } |
| 190 } | 229 } |
| 191 | 230 |
| 192 void PixelBufferRasterWorkerPool::OnRasterTasksFinished() { | 231 void PixelBufferRasterWorkerPool::OnRasterTasksFinished() { |
| 232 // Early out when more raster tasks are pending. | |
| 233 if (num_scheduled_raster_tasks_ != PendingRasterTaskCount()) | |
|
vmpstr
2013/06/26 18:05:07
I don't understand this check. Shouldn't this be i
reveman
2013/06/27 09:06:58
They will be the same if we're not throttled in an
| |
| 234 return; | |
| 235 | |
| 193 // Call CheckForCompletedTasks() when we've finished running all raster | 236 // Call CheckForCompletedTasks() when we've finished running all raster |
| 194 // tasks needed since last time ScheduleMoreTasks() was called. This | 237 // tasks needed since last time ScheduleTasks() was called. This |
| 195 // reduces latency when processing only a small number of raster tasks. | 238 // reduces latency when processing only a small number of raster tasks. |
| 196 CheckForCompletedRasterTasks(); | 239 CheckForCompletedRasterTasks(); |
| 197 } | 240 } |
| 198 | 241 |
| 242 void PixelBufferRasterWorkerPool::OnRasterTasksRequiredForActivationFinished() { | |
| 243 if (raster_tasks_required_for_activation_.empty()) | |
| 244 return; | |
| 245 | |
| 246 // Early out when more raster tasks required for activation are pending. | |
| 247 if (raster_tasks_required_for_activation_.size() != | |
|
vmpstr
2013/06/26 18:05:07
I guess I'm missing something, since I have the sa
reveman
2013/06/27 09:06:58
Not sure what you mean by "first time". These func
vmpstr
2013/06/27 16:32:12
What I mean is that, in the case where we schedule
reveman
2013/06/27 22:33:18
hm, OnRasterTaskCompleted is usually not called be
| |
| 248 num_scheduled_raster_tasks_required_for_activation_) | |
| 249 return; | |
| 250 | |
| 251 OnRasterTasksFinished(); | |
| 252 } | |
| 253 | |
| 199 void PixelBufferRasterWorkerPool::FlushUploads() { | 254 void PixelBufferRasterWorkerPool::FlushUploads() { |
| 200 if (!has_performed_uploads_since_last_flush_) | 255 if (!has_performed_uploads_since_last_flush_) |
| 201 return; | 256 return; |
| 202 | 257 |
| 203 resource_provider()->ShallowFlushIfSupported(); | 258 resource_provider()->ShallowFlushIfSupported(); |
| 204 has_performed_uploads_since_last_flush_ = false; | 259 has_performed_uploads_since_last_flush_ = false; |
| 205 } | 260 } |
| 206 | 261 |
| 207 void PixelBufferRasterWorkerPool::CheckForCompletedUploads() { | 262 void PixelBufferRasterWorkerPool::CheckForCompletedUploads() { |
| 208 TaskDeque tasks_with_completed_uploads; | 263 TaskDeque tasks_with_completed_uploads; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 264 | 319 |
| 265 bytes_pending_upload_ -= task->resource()->bytes(); | 320 bytes_pending_upload_ -= task->resource()->bytes(); |
| 266 | 321 |
| 267 task->DidRun(false); | 322 task->DidRun(false); |
| 268 | 323 |
| 269 DCHECK(std::find(completed_tasks_.begin(), | 324 DCHECK(std::find(completed_tasks_.begin(), |
| 270 completed_tasks_.end(), | 325 completed_tasks_.end(), |
| 271 task) == completed_tasks_.end()); | 326 task) == completed_tasks_.end()); |
| 272 completed_tasks_.push_back(task); | 327 completed_tasks_.push_back(task); |
| 273 | 328 |
| 329 tasks_required_for_activation_.erase(task); | |
| 330 | |
| 274 tasks_with_completed_uploads.pop_front(); | 331 tasks_with_completed_uploads.pop_front(); |
| 275 } | 332 } |
| 276 } | 333 } |
| 277 | 334 |
| 278 void PixelBufferRasterWorkerPool::ScheduleCheckForCompletedRasterTasks() { | 335 void PixelBufferRasterWorkerPool::ScheduleCheckForCompletedRasterTasks() { |
| 279 if (check_for_completed_raster_tasks_pending_) | 336 if (check_for_completed_raster_tasks_pending_) |
| 280 return; | 337 return; |
| 281 | 338 |
| 282 check_for_completed_raster_tasks_callback_.Reset( | 339 check_for_completed_raster_tasks_callback_.Reset( |
| 283 base::Bind(&PixelBufferRasterWorkerPool::CheckForCompletedRasterTasks, | 340 base::Bind(&PixelBufferRasterWorkerPool::CheckForCompletedRasterTasks, |
| 284 base::Unretained(this))); | 341 base::Unretained(this))); |
| 285 base::MessageLoopProxy::current()->PostDelayedTask( | 342 base::MessageLoopProxy::current()->PostDelayedTask( |
| 286 FROM_HERE, | 343 FROM_HERE, |
| 287 check_for_completed_raster_tasks_callback_.callback(), | 344 check_for_completed_raster_tasks_callback_.callback(), |
| 288 base::TimeDelta::FromMilliseconds(kCheckForCompletedRasterTasksDelayMs)); | 345 base::TimeDelta::FromMilliseconds(kCheckForCompletedRasterTasksDelayMs)); |
| 289 check_for_completed_raster_tasks_pending_ = true; | 346 check_for_completed_raster_tasks_pending_ = true; |
| 290 } | 347 } |
| 291 | 348 |
| 292 void PixelBufferRasterWorkerPool::CheckForCompletedRasterTasks() { | 349 void PixelBufferRasterWorkerPool::CheckForCompletedRasterTasks() { |
| 293 TRACE_EVENT0( | 350 TRACE_EVENT0( |
| 294 "cc", "PixelBufferRasterWorkerPool::CheckForCompletedRasterTasks"); | 351 "cc", "PixelBufferRasterWorkerPool::CheckForCompletedRasterTasks"); |
| 295 | 352 |
| 296 check_for_completed_raster_tasks_callback_.Cancel(); | 353 check_for_completed_raster_tasks_callback_.Cancel(); |
| 297 check_for_completed_raster_tasks_pending_ = false; | 354 check_for_completed_raster_tasks_pending_ = false; |
| 298 | 355 |
| 299 RasterWorkerPool::CheckForCompletedTasks(); | 356 RasterWorkerPool::CheckForCompletedTasks(); |
| 300 CheckForCompletedUploads(); | 357 CheckForCompletedUploads(); |
| 301 FlushUploads(); | 358 FlushUploads(); |
| 302 | 359 |
| 303 ScheduleMoreTasks(); | 360 if (PendingRasterTaskCount()) |
| 361 ScheduleMoreTasks(); | |
| 304 | 362 |
| 305 // Make sure another check for completed uploads is scheduled | 363 // Schedule another check for completed raster tasks while there are |
| 306 // while there is still pending uploads left. | 364 // pending raster tasks or pending uploads. |
| 307 if (!tasks_with_pending_upload_.empty()) | 365 if (PendingRasterTaskCount() || !tasks_with_pending_upload_.empty()) |
| 308 ScheduleCheckForCompletedRasterTasks(); | 366 ScheduleCheckForCompletedRasterTasks(); |
| 367 | |
| 368 NotifyClientIfFinishedRunningTasksRequiredForActivation(); | |
| 369 NotifyClientIfFinishedRunningTasks(); | |
| 309 } | 370 } |
| 310 | 371 |
| 311 void PixelBufferRasterWorkerPool::ScheduleMoreTasks() { | 372 void PixelBufferRasterWorkerPool::ScheduleMoreTasks() { |
| 312 TRACE_EVENT0("cc", "PixelBufferRasterWorkerPool::ScheduleMoreTasks"); | 373 TRACE_EVENT0("cc", "PixelBufferRasterWorkerPool::ScheduleMoreTasks"); |
| 313 | 374 |
| 314 size_t bytes_pending_upload = bytes_pending_upload_; | 375 size_t bytes_pending_upload = bytes_pending_upload_; |
| 315 size_t bytes_pending_raster = 0; | 376 size_t bytes_pending_raster = 0; |
| 316 | 377 |
| 378 num_scheduled_raster_tasks_ = 0; | |
| 379 num_scheduled_raster_tasks_required_for_activation_ = 0; | |
| 380 | |
| 317 RasterTaskGraph graph; | 381 RasterTaskGraph graph; |
| 318 for (RasterTaskVector::const_iterator it = raster_tasks().begin(); | 382 for (RasterTaskVector::const_iterator it = raster_tasks().begin(); |
| 319 it != raster_tasks().end(); ++it) { | 383 it != raster_tasks().end(); ++it) { |
| 320 internal::RasterWorkerPoolTask* task = it->get(); | 384 internal::RasterWorkerPoolTask* task = it->get(); |
| 321 | 385 |
| 322 // |pixel_buffer_tasks_| contains all tasks that have not yet completed. | 386 // |pixel_buffer_tasks_| contains all tasks that have not yet completed. |
| 323 TaskMap::iterator pixel_buffer_it = pixel_buffer_tasks_.find(task); | 387 TaskMap::iterator pixel_buffer_it = pixel_buffer_tasks_.find(task); |
| 324 if (pixel_buffer_it == pixel_buffer_tasks_.end()) | 388 if (pixel_buffer_it == pixel_buffer_tasks_.end()) |
| 325 continue; | 389 continue; |
| 326 | 390 |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 351 size_t new_bytes_pending_raster = bytes_pending_raster; | 415 size_t new_bytes_pending_raster = bytes_pending_raster; |
| 352 new_bytes_pending_raster += task->resource()->bytes(); | 416 new_bytes_pending_raster += task->resource()->bytes(); |
| 353 if (new_bytes_pending_raster > kMaxPendingRasterBytes) | 417 if (new_bytes_pending_raster > kMaxPendingRasterBytes) |
| 354 break; | 418 break; |
| 355 | 419 |
| 356 // Update both |bytes_pending_raster| and |bytes_pending_upload| | 420 // Update both |bytes_pending_raster| and |bytes_pending_upload| |
| 357 // now that task has cleared all throttling limits. | 421 // now that task has cleared all throttling limits. |
| 358 bytes_pending_raster = new_bytes_pending_raster; | 422 bytes_pending_raster = new_bytes_pending_raster; |
| 359 bytes_pending_upload = new_bytes_pending_upload; | 423 bytes_pending_upload = new_bytes_pending_upload; |
| 360 | 424 |
| 425 ++num_scheduled_raster_tasks_; | |
| 426 if (IsRasterTaskRequiredForActivation(task)) | |
| 427 ++num_scheduled_raster_tasks_required_for_activation_; | |
| 428 | |
| 361 // Use existing pixel buffer task if available. | 429 // Use existing pixel buffer task if available. |
| 362 if (pixel_buffer_task) { | 430 if (pixel_buffer_task) { |
| 363 graph.InsertRasterTask(pixel_buffer_task, task->dependencies()); | 431 graph.InsertRasterTask(pixel_buffer_task, |
| 432 task->dependencies(), | |
| 433 IsRasterTaskRequiredForActivation(task)); | |
| 364 continue; | 434 continue; |
| 365 } | 435 } |
| 366 | 436 |
| 367 // Request a pixel buffer. This will reserve shared memory. | 437 // Request a pixel buffer. This will reserve shared memory. |
| 368 resource_provider()->AcquirePixelBuffer(task->resource()->id()); | 438 resource_provider()->AcquirePixelBuffer(task->resource()->id()); |
| 369 | 439 |
| 370 // MapPixelBuffer() returns NULL if context was lost at the time | 440 // MapPixelBuffer() returns NULL if context was lost at the time |
| 371 // AcquirePixelBuffer() was called. For simplicity we still post | 441 // AcquirePixelBuffer() was called. For simplicity we still post |
| 372 // a raster task that is essentially a noop in these situations. | 442 // a raster task that is essentially a noop in these situations. |
| 373 uint8* buffer = resource_provider()->MapPixelBuffer( | 443 uint8* buffer = resource_provider()->MapPixelBuffer( |
| 374 task->resource()->id()); | 444 task->resource()->id()); |
| 375 | 445 |
| 376 scoped_refptr<internal::WorkerPoolTask> new_pixel_buffer_task( | 446 scoped_refptr<internal::WorkerPoolTask> new_pixel_buffer_task( |
| 377 new PixelBufferWorkerPoolTaskImpl( | 447 new PixelBufferWorkerPoolTaskImpl( |
| 378 task, | 448 task, |
| 379 buffer, | 449 buffer, |
| 380 base::Bind(&PixelBufferRasterWorkerPool::OnRasterTaskCompleted, | 450 base::Bind(&PixelBufferRasterWorkerPool::OnRasterTaskCompleted, |
| 381 base::Unretained(this), | 451 base::Unretained(this), |
| 382 make_scoped_refptr(task)))); | 452 make_scoped_refptr(task)))); |
| 383 pixel_buffer_tasks_[task] = new_pixel_buffer_task; | 453 pixel_buffer_tasks_[task] = new_pixel_buffer_task; |
| 384 graph.InsertRasterTask(new_pixel_buffer_task.get(), task->dependencies()); | 454 graph.InsertRasterTask(new_pixel_buffer_task.get(), |
| 455 task->dependencies(), | |
| 456 IsRasterTaskRequiredForActivation(task)); | |
| 385 } | 457 } |
| 386 | 458 |
| 459 // We might fail to schedule pending raster tasks when upload bound. | |
| 460 if (!bytes_pending_raster) | |
| 461 return; | |
| 462 | |
| 387 SetRasterTaskGraph(&graph); | 463 SetRasterTaskGraph(&graph); |
| 388 | |
| 389 // At least one task that could need an upload is now pending, schedule | |
| 390 // a check for completed raster tasks to ensure this upload is dispatched | |
| 391 // without too much latency. | |
| 392 if (bytes_pending_raster) | |
| 393 ScheduleCheckForCompletedRasterTasks(); | |
| 394 } | 464 } |
| 395 | 465 |
| 396 void PixelBufferRasterWorkerPool::OnRasterTaskCompleted( | 466 void PixelBufferRasterWorkerPool::OnRasterTaskCompleted( |
| 397 scoped_refptr<internal::RasterWorkerPoolTask> task, | 467 scoped_refptr<internal::RasterWorkerPoolTask> task, |
| 398 bool was_canceled, | 468 bool was_canceled, |
| 399 bool needs_upload) { | 469 bool needs_upload) { |
| 400 TRACE_EVENT2("cc", "PixelBufferRasterWorkerPool::OnRasterTaskCompleted", | 470 TRACE_EVENT2("cc", "PixelBufferRasterWorkerPool::OnRasterTaskCompleted", |
| 401 "was_canceled", was_canceled, | 471 "was_canceled", was_canceled, |
| 402 "needs_upload", needs_upload); | 472 "needs_upload", needs_upload); |
| 403 | 473 |
| 404 DCHECK(pixel_buffer_tasks_.find(task.get()) != pixel_buffer_tasks_.end()); | 474 DCHECK(pixel_buffer_tasks_.find(task.get()) != pixel_buffer_tasks_.end()); |
| 405 | 475 |
| 406 // Balanced with MapPixelBuffer() call in ScheduleMoreTasks(). | 476 // Balanced with MapPixelBuffer() call in ScheduleMoreTasks(). |
| 407 resource_provider()->UnmapPixelBuffer(task->resource()->id()); | 477 resource_provider()->UnmapPixelBuffer(task->resource()->id()); |
| 408 | 478 |
| 479 raster_tasks_required_for_activation_.erase(task); | |
| 480 | |
| 409 if (!needs_upload) { | 481 if (!needs_upload) { |
| 410 resource_provider()->ReleasePixelBuffer(task->resource()->id()); | 482 resource_provider()->ReleasePixelBuffer(task->resource()->id()); |
| 411 task->DidRun(was_canceled); | 483 task->DidRun(was_canceled); |
| 412 DCHECK(std::find(completed_tasks_.begin(), | 484 DCHECK(std::find(completed_tasks_.begin(), |
| 413 completed_tasks_.end(), | 485 completed_tasks_.end(), |
| 414 task) == completed_tasks_.end()); | 486 task) == completed_tasks_.end()); |
| 415 completed_tasks_.push_back(task); | 487 completed_tasks_.push_back(task); |
| 488 tasks_required_for_activation_.erase(task); | |
| 416 return; | 489 return; |
| 417 } | 490 } |
| 418 | 491 |
| 419 resource_provider()->BeginSetPixels(task->resource()->id()); | 492 resource_provider()->BeginSetPixels(task->resource()->id()); |
| 420 has_performed_uploads_since_last_flush_ = true; | 493 has_performed_uploads_since_last_flush_ = true; |
| 421 | 494 |
| 422 bytes_pending_upload_ += task->resource()->bytes(); | 495 bytes_pending_upload_ += task->resource()->bytes(); |
| 423 tasks_with_pending_upload_.push_back(task); | 496 tasks_with_pending_upload_.push_back(task); |
| 424 } | 497 } |
| 425 | 498 |
| 499 unsigned PixelBufferRasterWorkerPool::PendingRasterTaskCount() const { | |
| 500 unsigned num_completed_raster_tasks = | |
| 501 tasks_with_pending_upload_.size() + completed_tasks_.size(); | |
| 502 DCHECK_GE(pixel_buffer_tasks_.size(), num_completed_raster_tasks); | |
| 503 return pixel_buffer_tasks_.size() - num_completed_raster_tasks; | |
| 504 } | |
| 505 | |
| 506 void PixelBufferRasterWorkerPool:: | |
| 507 NotifyClientIfFinishedRunningTasksRequiredForActivation() { | |
| 508 if (!finished_running_tasks_required_for_activation_pending_) | |
| 509 return; | |
| 510 | |
| 511 if (!tasks_required_for_activation_.empty()) | |
| 512 return; | |
| 513 | |
| 514 client()->DidFinishedRunningTasksRequiredForActivation(); | |
| 515 finished_running_tasks_required_for_activation_pending_ = false; | |
| 516 } | |
| 517 | |
| 518 void PixelBufferRasterWorkerPool::NotifyClientIfFinishedRunningTasks() { | |
| 519 if (!finished_running_tasks_pending_) | |
| 520 return; | |
| 521 | |
| 522 if (PendingRasterTaskCount()) | |
| 523 return; | |
| 524 | |
| 525 if (!tasks_with_pending_upload_.empty()) | |
| 526 return; | |
| 527 | |
| 528 client()->DidFinishedRunningTasks(); | |
| 529 finished_running_tasks_pending_ = false; | |
| 530 } | |
| 531 | |
| 426 } // namespace cc | 532 } // namespace cc |
| OLD | NEW |