OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/one_copy_raster_worker_pool.h" | 5 #include "cc/resources/one_copy_raster_worker_pool.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 | 9 |
10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 | 80 |
81 // Flush interval when performing copy operations. | 81 // Flush interval when performing copy operations. |
82 const int kCopyFlushPeriod = 4; | 82 const int kCopyFlushPeriod = 4; |
83 | 83 |
84 // Number of in-flight copy operations to allow. | 84 // Number of in-flight copy operations to allow. |
85 const int kMaxCopyOperations = 16; | 85 const int kMaxCopyOperations = 16; |
86 | 86 |
87 // Delay been checking for copy operations to complete. | 87 // Delay been checking for copy operations to complete. |
88 const int kCheckForCompletedCopyOperationsTickRateMs = 1; | 88 const int kCheckForCompletedCopyOperationsTickRateMs = 1; |
89 | 89 |
| 90 // Number of failed attempts to allow before we perform a check that will |
| 91 // wait for copy operations to complete if needed. |
| 92 const int kFailedAttemptsBeforeWaitIfNeeded = 256; |
| 93 |
90 } // namespace | 94 } // namespace |
91 | 95 |
92 OneCopyRasterWorkerPool::CopyOperation::CopyOperation( | 96 OneCopyRasterWorkerPool::CopyOperation::CopyOperation( |
93 scoped_ptr<ResourceProvider::ScopedWriteLockGpuMemoryBuffer> write_lock, | 97 scoped_ptr<ResourceProvider::ScopedWriteLockGpuMemoryBuffer> write_lock, |
94 scoped_ptr<ScopedResource> src, | 98 scoped_ptr<ScopedResource> src, |
95 const Resource* dst) | 99 const Resource* dst) |
96 : write_lock(write_lock.Pass()), src(src.Pass()), dst(dst) { | 100 : write_lock(write_lock.Pass()), src(src.Pass()), dst(dst) { |
97 } | 101 } |
98 | 102 |
99 OneCopyRasterWorkerPool::CopyOperation::~CopyOperation() { | 103 OneCopyRasterWorkerPool::CopyOperation::~CopyOperation() { |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 size_t task_count[kNumberOfTaskSets] = {0}; | 192 size_t task_count[kNumberOfTaskSets] = {0}; |
189 | 193 |
190 for (TaskSet task_set = 0; task_set < kNumberOfTaskSets; ++task_set) { | 194 for (TaskSet task_set = 0; task_set < kNumberOfTaskSets; ++task_set) { |
191 new_raster_finished_tasks[task_set] = CreateRasterFinishedTask( | 195 new_raster_finished_tasks[task_set] = CreateRasterFinishedTask( |
192 task_runner_.get(), | 196 task_runner_.get(), |
193 base::Bind(&OneCopyRasterWorkerPool::OnRasterFinished, | 197 base::Bind(&OneCopyRasterWorkerPool::OnRasterFinished, |
194 raster_finished_weak_ptr_factory_.GetWeakPtr(), | 198 raster_finished_weak_ptr_factory_.GetWeakPtr(), |
195 task_set)); | 199 task_set)); |
196 } | 200 } |
197 | 201 |
198 resource_pool_->CheckBusyResources(); | 202 resource_pool_->CheckBusyResources(false); |
199 | 203 |
200 for (RasterTaskQueue::Item::Vector::const_iterator it = queue->items.begin(); | 204 for (RasterTaskQueue::Item::Vector::const_iterator it = queue->items.begin(); |
201 it != queue->items.end(); | 205 it != queue->items.end(); |
202 ++it) { | 206 ++it) { |
203 const RasterTaskQueue::Item& item = *it; | 207 const RasterTaskQueue::Item& item = *it; |
204 RasterTask* task = item.task; | 208 RasterTask* task = item.task; |
205 DCHECK(!task->HasCompleted()); | 209 DCHECK(!task->HasCompleted()); |
206 | 210 |
207 for (TaskSet task_set = 0; task_set < kNumberOfTaskSets; ++task_set) { | 211 for (TaskSet task_set = 0; task_set < kNumberOfTaskSets; ++task_set) { |
208 if (!item.task_sets[task_set]) | 212 if (!item.task_sets[task_set]) |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 const Resource* dst, | 280 const Resource* dst, |
277 const RasterSource* raster_source, | 281 const RasterSource* raster_source, |
278 const gfx::Rect& rect, | 282 const gfx::Rect& rect, |
279 float scale, | 283 float scale, |
280 RenderingStatsInstrumentation* stats) { | 284 RenderingStatsInstrumentation* stats) { |
281 CopySequenceNumber sequence; | 285 CopySequenceNumber sequence; |
282 | 286 |
283 { | 287 { |
284 base::AutoLock lock(lock_); | 288 base::AutoLock lock(lock_); |
285 | 289 |
| 290 int failed_attempts = 0; |
286 while ((scheduled_copy_operation_count_ + issued_copy_operation_count_) >= | 291 while ((scheduled_copy_operation_count_ + issued_copy_operation_count_) >= |
287 kMaxCopyOperations) { | 292 kMaxCopyOperations) { |
288 // Ignore limit when shutdown is set. | 293 // Ignore limit when shutdown is set. |
289 if (shutdown_) | 294 if (shutdown_) |
290 break; | 295 break; |
291 | 296 |
| 297 ++failed_attempts; |
| 298 |
| 299 // Schedule a check that will also wait for operations to complete |
| 300 // after too many failed attempts. |
| 301 bool wait_if_needed = failed_attempts > kFailedAttemptsBeforeWaitIfNeeded; |
| 302 |
292 // Schedule a check for completed copy operations if too many operations | 303 // Schedule a check for completed copy operations if too many operations |
293 // are currently in-flight. | 304 // are currently in-flight. |
294 ScheduleCheckForCompletedCopyOperationsWithLockAcquired(); | 305 ScheduleCheckForCompletedCopyOperationsWithLockAcquired(wait_if_needed); |
295 | 306 |
296 { | 307 { |
297 TRACE_EVENT0("cc", "WaitingForCopyOperationsToComplete"); | 308 TRACE_EVENT0("cc", "WaitingForCopyOperationsToComplete"); |
298 | 309 |
299 // Wait for in-flight copy operations to drop below limit. | 310 // Wait for in-flight copy operations to drop below limit. |
300 copy_operation_count_cv_.Wait(); | 311 copy_operation_count_cv_.Wait(); |
301 } | 312 } |
302 } | 313 } |
303 | 314 |
304 // Increment |scheduled_copy_operation_count_| before releasing |lock_|. | 315 // Increment |scheduled_copy_operation_count_| before releasing |lock_|. |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 resource_provider_->CopyResource(copy_operation->src->id(), | 424 resource_provider_->CopyResource(copy_operation->src->id(), |
414 copy_operation->dst->id()); | 425 copy_operation->dst->id()); |
415 | 426 |
416 // Return source resource to pool where it can be reused once copy | 427 // Return source resource to pool where it can be reused once copy |
417 // operation has completed and resource is no longer busy. | 428 // operation has completed and resource is no longer busy. |
418 resource_pool_->ReleaseResource(copy_operation->src.Pass()); | 429 resource_pool_->ReleaseResource(copy_operation->src.Pass()); |
419 } | 430 } |
420 } | 431 } |
421 | 432 |
422 void OneCopyRasterWorkerPool:: | 433 void OneCopyRasterWorkerPool:: |
423 ScheduleCheckForCompletedCopyOperationsWithLockAcquired() { | 434 ScheduleCheckForCompletedCopyOperationsWithLockAcquired( |
| 435 bool wait_if_needed) { |
424 lock_.AssertAcquired(); | 436 lock_.AssertAcquired(); |
425 | 437 |
426 if (check_for_completed_copy_operations_pending_) | 438 if (check_for_completed_copy_operations_pending_) |
427 return; | 439 return; |
428 | 440 |
429 base::TimeTicks now = base::TimeTicks::Now(); | 441 base::TimeTicks now = base::TimeTicks::Now(); |
430 | 442 |
431 // Schedule a check for completed copy operations as soon as possible but | 443 // Schedule a check for completed copy operations as soon as possible but |
432 // don't allow two consecutive checks to be scheduled to run less than the | 444 // don't allow two consecutive checks to be scheduled to run less than the |
433 // tick rate apart. | 445 // tick rate apart. |
434 base::TimeTicks next_check_for_completed_copy_operations_time = | 446 base::TimeTicks next_check_for_completed_copy_operations_time = |
435 std::max(last_check_for_completed_copy_operations_time_ + | 447 std::max(last_check_for_completed_copy_operations_time_ + |
436 base::TimeDelta::FromMilliseconds( | 448 base::TimeDelta::FromMilliseconds( |
437 kCheckForCompletedCopyOperationsTickRateMs), | 449 kCheckForCompletedCopyOperationsTickRateMs), |
438 now); | 450 now); |
439 | 451 |
440 task_runner_->PostDelayedTask( | 452 task_runner_->PostDelayedTask( |
441 FROM_HERE, | 453 FROM_HERE, |
442 base::Bind(&OneCopyRasterWorkerPool::CheckForCompletedCopyOperations, | 454 base::Bind(&OneCopyRasterWorkerPool::CheckForCompletedCopyOperations, |
443 weak_ptr_factory_.GetWeakPtr()), | 455 weak_ptr_factory_.GetWeakPtr(), |
| 456 wait_if_needed), |
444 next_check_for_completed_copy_operations_time - now); | 457 next_check_for_completed_copy_operations_time - now); |
445 | 458 |
446 last_check_for_completed_copy_operations_time_ = | 459 last_check_for_completed_copy_operations_time_ = |
447 next_check_for_completed_copy_operations_time; | 460 next_check_for_completed_copy_operations_time; |
448 check_for_completed_copy_operations_pending_ = true; | 461 check_for_completed_copy_operations_pending_ = true; |
449 } | 462 } |
450 | 463 |
451 void OneCopyRasterWorkerPool::CheckForCompletedCopyOperations() { | 464 void OneCopyRasterWorkerPool::CheckForCompletedCopyOperations( |
452 TRACE_EVENT0("cc", | 465 bool wait_if_needed) { |
453 "OneCopyRasterWorkerPool::CheckForCompletedCopyOperations"); | 466 TRACE_EVENT1("cc", |
| 467 "OneCopyRasterWorkerPool::CheckForCompletedCopyOperations", |
| 468 "wait_if_needed", |
| 469 wait_if_needed); |
454 | 470 |
455 resource_pool_->CheckBusyResources(); | 471 resource_pool_->CheckBusyResources(wait_if_needed); |
456 | 472 |
457 { | 473 { |
458 base::AutoLock lock(lock_); | 474 base::AutoLock lock(lock_); |
459 | 475 |
460 DCHECK(check_for_completed_copy_operations_pending_); | 476 DCHECK(check_for_completed_copy_operations_pending_); |
461 check_for_completed_copy_operations_pending_ = false; | 477 check_for_completed_copy_operations_pending_ = false; |
462 | 478 |
463 // The number of busy resources in the pool reflects the number of issued | 479 // The number of busy resources in the pool reflects the number of issued |
464 // copy operations that have not yet completed. | 480 // copy operations that have not yet completed. |
465 issued_copy_operation_count_ = resource_pool_->busy_resource_count(); | 481 issued_copy_operation_count_ = resource_pool_->busy_resource_count(); |
(...skipping 28 matching lines...) Expand all Loading... |
494 resource_pool_->total_memory_usage_bytes()); | 510 resource_pool_->total_memory_usage_bytes()); |
495 staging_state->SetInteger("pending_copy_count", | 511 staging_state->SetInteger("pending_copy_count", |
496 resource_pool_->total_resource_count() - | 512 resource_pool_->total_resource_count() - |
497 resource_pool_->acquired_resource_count()); | 513 resource_pool_->acquired_resource_count()); |
498 staging_state->SetInteger("bytes_pending_copy", | 514 staging_state->SetInteger("bytes_pending_copy", |
499 resource_pool_->total_memory_usage_bytes() - | 515 resource_pool_->total_memory_usage_bytes() - |
500 resource_pool_->acquired_memory_usage_bytes()); | 516 resource_pool_->acquired_memory_usage_bytes()); |
501 } | 517 } |
502 | 518 |
503 } // namespace cc | 519 } // namespace cc |
OLD | NEW |