| 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 | 47 |
| 48 // Return raster resource to pool so it can be used by another RasterBuffer | 48 // Return raster resource to pool so it can be used by another RasterBuffer |
| 49 // instance. | 49 // instance. |
| 50 if (raster_resource_) | 50 if (raster_resource_) |
| 51 resource_pool_->ReleaseResource(raster_resource_.Pass()); | 51 resource_pool_->ReleaseResource(raster_resource_.Pass()); |
| 52 } | 52 } |
| 53 | 53 |
| 54 // Overridden from RasterBuffer: | 54 // Overridden from RasterBuffer: |
| 55 void Playback(const RasterSource* raster_source, | 55 void Playback(const RasterSource* raster_source, |
| 56 const gfx::Rect& rect, | 56 const gfx::Rect& rect, |
| 57 float scale, | 57 float scale) override { |
| 58 RenderingStatsInstrumentation* stats) override { | |
| 59 sequence_ = worker_pool_->PlaybackAndScheduleCopyOnWorkerThread( | 58 sequence_ = worker_pool_->PlaybackAndScheduleCopyOnWorkerThread( |
| 60 lock_.Pass(), | 59 lock_.Pass(), raster_resource_.Pass(), resource_, raster_source, rect, |
| 61 raster_resource_.Pass(), | 60 scale); |
| 62 resource_, | |
| 63 raster_source, | |
| 64 rect, | |
| 65 scale, | |
| 66 stats); | |
| 67 } | 61 } |
| 68 | 62 |
| 69 private: | 63 private: |
| 70 OneCopyRasterWorkerPool* worker_pool_; | 64 OneCopyRasterWorkerPool* worker_pool_; |
| 71 ResourceProvider* resource_provider_; | 65 ResourceProvider* resource_provider_; |
| 72 ResourcePool* resource_pool_; | 66 ResourcePool* resource_pool_; |
| 73 const Resource* resource_; | 67 const Resource* resource_; |
| 74 scoped_ptr<ScopedResource> raster_resource_; | 68 scoped_ptr<ScopedResource> raster_resource_; |
| 75 scoped_ptr<ResourceProvider::ScopedWriteLockGpuMemoryBuffer> lock_; | 69 scoped_ptr<ResourceProvider::ScopedWriteLockGpuMemoryBuffer> lock_; |
| 76 CopySequenceNumber sequence_; | 70 CopySequenceNumber sequence_; |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 // Nothing to do here. RasterBufferImpl destructor cleans up after itself. | 267 // Nothing to do here. RasterBufferImpl destructor cleans up after itself. |
| 274 } | 268 } |
| 275 | 269 |
| 276 CopySequenceNumber | 270 CopySequenceNumber |
| 277 OneCopyRasterWorkerPool::PlaybackAndScheduleCopyOnWorkerThread( | 271 OneCopyRasterWorkerPool::PlaybackAndScheduleCopyOnWorkerThread( |
| 278 scoped_ptr<ResourceProvider::ScopedWriteLockGpuMemoryBuffer> write_lock, | 272 scoped_ptr<ResourceProvider::ScopedWriteLockGpuMemoryBuffer> write_lock, |
| 279 scoped_ptr<ScopedResource> src, | 273 scoped_ptr<ScopedResource> src, |
| 280 const Resource* dst, | 274 const Resource* dst, |
| 281 const RasterSource* raster_source, | 275 const RasterSource* raster_source, |
| 282 const gfx::Rect& rect, | 276 const gfx::Rect& rect, |
| 283 float scale, | 277 float scale) { |
| 284 RenderingStatsInstrumentation* stats) { | 278 base::AutoLock lock(lock_); |
| 285 CopySequenceNumber sequence; | 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(); |
| 286 | 310 |
| 287 { | 311 { |
| 288 base::AutoLock lock(lock_); | 312 base::AutoUnlock unlock(lock_); |
| 289 | 313 |
| 290 int failed_attempts = 0; | 314 gfx::GpuMemoryBuffer* gpu_memory_buffer = write_lock->GetGpuMemoryBuffer(); |
| 291 while ((scheduled_copy_operation_count_ + issued_copy_operation_count_) >= | 315 if (gpu_memory_buffer) { |
| 292 kMaxCopyOperations) { | 316 RasterWorkerPool::PlaybackToMemory(gpu_memory_buffer->Map(), |
| 293 // Ignore limit when shutdown is set. | 317 src->format(), |
| 294 if (shutdown_) | 318 src->size(), |
| 295 break; | 319 gpu_memory_buffer->GetStride(), |
| 320 raster_source, |
| 321 rect, |
| 322 scale); |
| 323 gpu_memory_buffer->Unmap(); |
| 324 } |
| 325 } |
| 296 | 326 |
| 297 ++failed_attempts; | 327 pending_copy_operations_.push_back( |
| 328 make_scoped_ptr(new CopyOperation(write_lock.Pass(), src.Pass(), dst))); |
| 298 | 329 |
| 299 // Schedule a check that will also wait for operations to complete | 330 // Acquire a sequence number for this copy operation. |
| 300 // after too many failed attempts. | 331 CopySequenceNumber sequence = next_copy_operation_sequence_++; |
| 301 bool wait_if_needed = failed_attempts > kFailedAttemptsBeforeWaitIfNeeded; | |
| 302 | |
| 303 // Schedule a check for completed copy operations if too many operations | |
| 304 // are currently in-flight. | |
| 305 ScheduleCheckForCompletedCopyOperationsWithLockAcquired(wait_if_needed); | |
| 306 | |
| 307 { | |
| 308 TRACE_EVENT0("cc", "WaitingForCopyOperationsToComplete"); | |
| 309 | |
| 310 // Wait for in-flight copy operations to drop below limit. | |
| 311 copy_operation_count_cv_.Wait(); | |
| 312 } | |
| 313 } | |
| 314 | |
| 315 // Increment |scheduled_copy_operation_count_| before releasing |lock_|. | |
| 316 ++scheduled_copy_operation_count_; | |
| 317 | |
| 318 // There may be more work available, so wake up another worker thread. | |
| 319 copy_operation_count_cv_.Signal(); | |
| 320 | |
| 321 { | |
| 322 base::AutoUnlock unlock(lock_); | |
| 323 | |
| 324 gfx::GpuMemoryBuffer* gpu_memory_buffer = | |
| 325 write_lock->GetGpuMemoryBuffer(); | |
| 326 if (gpu_memory_buffer) { | |
| 327 RasterWorkerPool::PlaybackToMemory(gpu_memory_buffer->Map(), | |
| 328 src->format(), | |
| 329 src->size(), | |
| 330 gpu_memory_buffer->GetStride(), | |
| 331 raster_source, | |
| 332 rect, | |
| 333 scale, | |
| 334 stats); | |
| 335 gpu_memory_buffer->Unmap(); | |
| 336 } | |
| 337 } | |
| 338 | |
| 339 // Acquire a sequence number for this copy operation. | |
| 340 sequence = next_copy_operation_sequence_++; | |
| 341 | |
| 342 pending_copy_operations_.push_back( | |
| 343 make_scoped_ptr(new CopyOperation(write_lock.Pass(), src.Pass(), dst))); | |
| 344 } | |
| 345 | 332 |
| 346 // Post task that will advance last flushed copy operation to |sequence| | 333 // Post task that will advance last flushed copy operation to |sequence| |
| 347 // if we have reached the flush period. | 334 // if we have reached the flush period. |
| 348 if ((sequence % kCopyFlushPeriod) == 0) { | 335 if ((sequence % kCopyFlushPeriod) == 0) { |
| 349 task_runner_->PostTask( | 336 task_runner_->PostTask( |
| 350 FROM_HERE, | 337 FROM_HERE, |
| 351 base::Bind(&OneCopyRasterWorkerPool::AdvanceLastFlushedCopyTo, | 338 base::Bind(&OneCopyRasterWorkerPool::AdvanceLastFlushedCopyTo, |
| 352 weak_ptr_factory_.GetWeakPtr(), | 339 weak_ptr_factory_.GetWeakPtr(), |
| 353 sequence)); | 340 sequence)); |
| 354 } | 341 } |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 resource_pool_->total_memory_usage_bytes()); | 497 resource_pool_->total_memory_usage_bytes()); |
| 511 staging_state->SetInteger("pending_copy_count", | 498 staging_state->SetInteger("pending_copy_count", |
| 512 resource_pool_->total_resource_count() - | 499 resource_pool_->total_resource_count() - |
| 513 resource_pool_->acquired_resource_count()); | 500 resource_pool_->acquired_resource_count()); |
| 514 staging_state->SetInteger("bytes_pending_copy", | 501 staging_state->SetInteger("bytes_pending_copy", |
| 515 resource_pool_->total_memory_usage_bytes() - | 502 resource_pool_->total_memory_usage_bytes() - |
| 516 resource_pool_->acquired_memory_usage_bytes()); | 503 resource_pool_->acquired_memory_usage_bytes()); |
| 517 } | 504 } |
| 518 | 505 |
| 519 } // namespace cc | 506 } // namespace cc |
| OLD | NEW |