| 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 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 } | 268 } |
| 269 | 269 |
| 270 CopySequenceNumber | 270 CopySequenceNumber |
| 271 OneCopyRasterWorkerPool::PlaybackAndScheduleCopyOnWorkerThread( | 271 OneCopyRasterWorkerPool::PlaybackAndScheduleCopyOnWorkerThread( |
| 272 scoped_ptr<ResourceProvider::ScopedWriteLockGpuMemoryBuffer> write_lock, | 272 scoped_ptr<ResourceProvider::ScopedWriteLockGpuMemoryBuffer> write_lock, |
| 273 scoped_ptr<ScopedResource> src, | 273 scoped_ptr<ScopedResource> src, |
| 274 const Resource* dst, | 274 const Resource* dst, |
| 275 const RasterSource* raster_source, | 275 const RasterSource* raster_source, |
| 276 const gfx::Rect& rect, | 276 const gfx::Rect& rect, |
| 277 float scale) { | 277 float scale) { |
| 278 CopySequenceNumber sequence; | 278 base::AutoLock lock(lock_); |
| 279 |
| 280 int failed_attempts = 0; |
| 281 while ((scheduled_copy_operation_count_ + issued_copy_operation_count_) >= |
| 282 kMaxCopyOperations) { |
| 283 // Ignore limit when shutdown is set. |
| 284 if (shutdown_) |
| 285 break; |
| 286 |
| 287 ++failed_attempts; |
| 288 |
| 289 // Schedule a check that will also wait for operations to complete |
| 290 // after too many failed attempts. |
| 291 bool wait_if_needed = failed_attempts > kFailedAttemptsBeforeWaitIfNeeded; |
| 292 |
| 293 // Schedule a check for completed copy operations if too many operations |
| 294 // are currently in-flight. |
| 295 ScheduleCheckForCompletedCopyOperationsWithLockAcquired(wait_if_needed); |
| 296 |
| 297 { |
| 298 TRACE_EVENT0("cc", "WaitingForCopyOperationsToComplete"); |
| 299 |
| 300 // Wait for in-flight copy operations to drop below limit. |
| 301 copy_operation_count_cv_.Wait(); |
| 302 } |
| 303 } |
| 304 |
| 305 // Increment |scheduled_copy_operation_count_| before releasing |lock_|. |
| 306 ++scheduled_copy_operation_count_; |
| 307 |
| 308 // There may be more work available, so wake up another worker thread. |
| 309 copy_operation_count_cv_.Signal(); |
| 279 | 310 |
| 280 { | 311 { |
| 281 base::AutoLock lock(lock_); | 312 base::AutoUnlock unlock(lock_); |
| 282 | 313 |
| 283 int failed_attempts = 0; | 314 gfx::GpuMemoryBuffer* gpu_memory_buffer = write_lock->GetGpuMemoryBuffer(); |
| 284 while ((scheduled_copy_operation_count_ + issued_copy_operation_count_) >= | 315 if (gpu_memory_buffer) { |
| 285 kMaxCopyOperations) { | 316 RasterWorkerPool::PlaybackToMemory(gpu_memory_buffer->Map(), |
| 286 // Ignore limit when shutdown is set. | 317 src->format(), |
| 287 if (shutdown_) | 318 src->size(), |
| 288 break; | 319 gpu_memory_buffer->GetStride(), |
| 320 raster_source, |
| 321 rect, |
| 322 scale); |
| 323 gpu_memory_buffer->Unmap(); |
| 324 } |
| 325 } |
| 289 | 326 |
| 290 ++failed_attempts; | 327 pending_copy_operations_.push_back( |
| 328 make_scoped_ptr(new CopyOperation(write_lock.Pass(), src.Pass(), dst))); |
| 291 | 329 |
| 292 // Schedule a check that will also wait for operations to complete | 330 // Acquire a sequence number for this copy operation. |
| 293 // after too many failed attempts. | 331 CopySequenceNumber sequence = next_copy_operation_sequence_++; |
| 294 bool wait_if_needed = failed_attempts > kFailedAttemptsBeforeWaitIfNeeded; | |
| 295 | |
| 296 // Schedule a check for completed copy operations if too many operations | |
| 297 // are currently in-flight. | |
| 298 ScheduleCheckForCompletedCopyOperationsWithLockAcquired(wait_if_needed); | |
| 299 | |
| 300 { | |
| 301 TRACE_EVENT0("cc", "WaitingForCopyOperationsToComplete"); | |
| 302 | |
| 303 // Wait for in-flight copy operations to drop below limit. | |
| 304 copy_operation_count_cv_.Wait(); | |
| 305 } | |
| 306 } | |
| 307 | |
| 308 // Increment |scheduled_copy_operation_count_| before releasing |lock_|. | |
| 309 ++scheduled_copy_operation_count_; | |
| 310 | |
| 311 // There may be more work available, so wake up another worker thread. | |
| 312 copy_operation_count_cv_.Signal(); | |
| 313 | |
| 314 { | |
| 315 base::AutoUnlock unlock(lock_); | |
| 316 | |
| 317 gfx::GpuMemoryBuffer* gpu_memory_buffer = | |
| 318 write_lock->GetGpuMemoryBuffer(); | |
| 319 if (gpu_memory_buffer) { | |
| 320 RasterWorkerPool::PlaybackToMemory( | |
| 321 gpu_memory_buffer->Map(), src->format(), src->size(), | |
| 322 gpu_memory_buffer->GetStride(), raster_source, rect, scale); | |
| 323 gpu_memory_buffer->Unmap(); | |
| 324 } | |
| 325 } | |
| 326 | |
| 327 // Acquire a sequence number for this copy operation. | |
| 328 sequence = next_copy_operation_sequence_++; | |
| 329 | |
| 330 pending_copy_operations_.push_back( | |
| 331 make_scoped_ptr(new CopyOperation(write_lock.Pass(), src.Pass(), dst))); | |
| 332 } | |
| 333 | 332 |
| 334 // Post task that will advance last flushed copy operation to |sequence| | 333 // Post task that will advance last flushed copy operation to |sequence| |
| 335 // if we have reached the flush period. | 334 // if we have reached the flush period. |
| 336 if ((sequence % kCopyFlushPeriod) == 0) { | 335 if ((sequence % kCopyFlushPeriod) == 0) { |
| 337 task_runner_->PostTask( | 336 task_runner_->PostTask( |
| 338 FROM_HERE, | 337 FROM_HERE, |
| 339 base::Bind(&OneCopyRasterWorkerPool::AdvanceLastFlushedCopyTo, | 338 base::Bind(&OneCopyRasterWorkerPool::AdvanceLastFlushedCopyTo, |
| 340 weak_ptr_factory_.GetWeakPtr(), | 339 weak_ptr_factory_.GetWeakPtr(), |
| 341 sequence)); | 340 sequence)); |
| 342 } | 341 } |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 resource_pool_->total_memory_usage_bytes()); | 497 resource_pool_->total_memory_usage_bytes()); |
| 499 staging_state->SetInteger("pending_copy_count", | 498 staging_state->SetInteger("pending_copy_count", |
| 500 resource_pool_->total_resource_count() - | 499 resource_pool_->total_resource_count() - |
| 501 resource_pool_->acquired_resource_count()); | 500 resource_pool_->acquired_resource_count()); |
| 502 staging_state->SetInteger("bytes_pending_copy", | 501 staging_state->SetInteger("bytes_pending_copy", |
| 503 resource_pool_->total_memory_usage_bytes() - | 502 resource_pool_->total_memory_usage_bytes() - |
| 504 resource_pool_->acquired_memory_usage_bytes()); | 503 resource_pool_->acquired_memory_usage_bytes()); |
| 505 } | 504 } |
| 506 | 505 |
| 507 } // namespace cc | 506 } // namespace cc |
| OLD | NEW |