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/raster/one_copy_tile_task_worker_pool.h" | 5 #include "cc/raster/one_copy_tile_task_worker_pool.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 | 9 |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 ResourcePool* resource_pool_; | 92 ResourcePool* resource_pool_; |
93 const Resource* output_resource_; | 93 const Resource* output_resource_; |
94 uint64_t raster_content_id_; | 94 uint64_t raster_content_id_; |
95 scoped_ptr<ScopedResource> raster_resource_; | 95 scoped_ptr<ScopedResource> raster_resource_; |
96 scoped_ptr<ResourceProvider::ScopedWriteLockGpuMemoryBuffer> lock_; | 96 scoped_ptr<ResourceProvider::ScopedWriteLockGpuMemoryBuffer> lock_; |
97 CopySequenceNumber sequence_; | 97 CopySequenceNumber sequence_; |
98 | 98 |
99 DISALLOW_COPY_AND_ASSIGN(RasterBufferImpl); | 99 DISALLOW_COPY_AND_ASSIGN(RasterBufferImpl); |
100 }; | 100 }; |
101 | 101 |
102 // Flush interval when performing copy operations. | |
103 const int kCopyFlushPeriod = 4; | |
104 | |
105 // Number of in-flight copy operations to allow. | 102 // Number of in-flight copy operations to allow. |
106 const int kMaxCopyOperations = 32; | 103 const int kMaxCopyOperations = 32; |
107 | 104 |
108 // Delay been checking for copy operations to complete. | 105 // Delay been checking for copy operations to complete. |
109 const int kCheckForCompletedCopyOperationsTickRateMs = 1; | 106 const int kCheckForCompletedCopyOperationsTickRateMs = 1; |
110 | 107 |
111 // Number of failed attempts to allow before we perform a check that will | 108 // Number of failed attempts to allow before we perform a check that will |
112 // wait for copy operations to complete if needed. | 109 // wait for copy operations to complete if needed. |
113 const int kFailedAttemptsBeforeWaitIfNeeded = 256; | 110 const int kFailedAttemptsBeforeWaitIfNeeded = 256; |
114 | 111 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 namespace_token_(task_graph_runner->GetNamespaceToken()), | 150 namespace_token_(task_graph_runner->GetNamespaceToken()), |
154 context_provider_(context_provider), | 151 context_provider_(context_provider), |
155 resource_provider_(resource_provider), | 152 resource_provider_(resource_provider), |
156 resource_pool_(resource_pool), | 153 resource_pool_(resource_pool), |
157 max_bytes_per_copy_operation_(max_bytes_per_copy_operation), | 154 max_bytes_per_copy_operation_(max_bytes_per_copy_operation), |
158 have_persistent_gpu_memory_buffers_(have_persistent_gpu_memory_buffers), | 155 have_persistent_gpu_memory_buffers_(have_persistent_gpu_memory_buffers), |
159 last_issued_copy_operation_(0), | 156 last_issued_copy_operation_(0), |
160 last_flushed_copy_operation_(0), | 157 last_flushed_copy_operation_(0), |
161 lock_(), | 158 lock_(), |
162 copy_operation_count_cv_(&lock_), | 159 copy_operation_count_cv_(&lock_), |
| 160 bytes_scheduled_since_last_flush_(0), |
163 issued_copy_operation_count_(0), | 161 issued_copy_operation_count_(0), |
164 next_copy_operation_sequence_(1), | 162 next_copy_operation_sequence_(1), |
165 check_for_completed_copy_operations_pending_(false), | 163 check_for_completed_copy_operations_pending_(false), |
166 shutdown_(false), | 164 shutdown_(false), |
167 weak_ptr_factory_(this), | 165 weak_ptr_factory_(this), |
168 task_set_finished_weak_ptr_factory_(this) { | 166 task_set_finished_weak_ptr_factory_(this) { |
169 DCHECK(context_provider_); | 167 DCHECK(context_provider_); |
170 } | 168 } |
171 | 169 |
172 OneCopyTileTaskWorkerPool::~OneCopyTileTaskWorkerPool() { | 170 OneCopyTileTaskWorkerPool::~OneCopyTileTaskWorkerPool() { |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 // |raster_resource_write_lock| is passed to the first copy operation as it | 392 // |raster_resource_write_lock| is passed to the first copy operation as it |
395 // needs to be released before we can issue a copy. | 393 // needs to be released before we can issue a copy. |
396 pending_copy_operations_.push_back(make_scoped_ptr(new CopyOperation( | 394 pending_copy_operations_.push_back(make_scoped_ptr(new CopyOperation( |
397 raster_resource_write_lock.Pass(), raster_resource, output_resource, | 395 raster_resource_write_lock.Pass(), raster_resource, output_resource, |
398 gfx::Rect(0, y, raster_resource->size().width(), rows_to_copy)))); | 396 gfx::Rect(0, y, raster_resource->size().width(), rows_to_copy)))); |
399 y += rows_to_copy; | 397 y += rows_to_copy; |
400 | 398 |
401 // Acquire a sequence number for this copy operation. | 399 // Acquire a sequence number for this copy operation. |
402 sequence = next_copy_operation_sequence_++; | 400 sequence = next_copy_operation_sequence_++; |
403 | 401 |
| 402 // Increment |bytes_scheduled_since_last_flush_| by the amount of memory |
| 403 // used for this copy operation. |
| 404 bytes_scheduled_since_last_flush_ += rows_to_copy * bytes_per_row; |
| 405 |
404 // Post task that will advance last flushed copy operation to |sequence| | 406 // Post task that will advance last flushed copy operation to |sequence| |
405 // if we have reached the flush period. | 407 // when |bytes_scheduled_since_last_flush_| has reached |
406 if ((sequence % kCopyFlushPeriod) == 0) { | 408 // |max_bytes_per_copy_operation_|. |
| 409 if (bytes_scheduled_since_last_flush_ >= max_bytes_per_copy_operation_) { |
407 task_runner_->PostTask( | 410 task_runner_->PostTask( |
408 FROM_HERE, | 411 FROM_HERE, |
409 base::Bind(&OneCopyTileTaskWorkerPool::AdvanceLastFlushedCopyTo, | 412 base::Bind(&OneCopyTileTaskWorkerPool::AdvanceLastFlushedCopyTo, |
410 weak_ptr_factory_.GetWeakPtr(), sequence)); | 413 weak_ptr_factory_.GetWeakPtr(), sequence)); |
| 414 bytes_scheduled_since_last_flush_ = 0; |
411 } | 415 } |
412 } | 416 } |
413 | 417 |
414 return sequence; | 418 return sequence; |
415 } | 419 } |
416 | 420 |
417 void OneCopyTileTaskWorkerPool::AdvanceLastIssuedCopyTo( | 421 void OneCopyTileTaskWorkerPool::AdvanceLastIssuedCopyTo( |
418 CopySequenceNumber sequence) { | 422 CopySequenceNumber sequence) { |
419 if (last_issued_copy_operation_ >= sequence) | 423 if (last_issued_copy_operation_ >= sequence) |
420 return; | 424 return; |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
564 "pending_copy_count", | 568 "pending_copy_count", |
565 static_cast<int>(resource_pool_->total_resource_count() - | 569 static_cast<int>(resource_pool_->total_resource_count() - |
566 resource_pool_->acquired_resource_count())); | 570 resource_pool_->acquired_resource_count())); |
567 staging_state->SetInteger( | 571 staging_state->SetInteger( |
568 "bytes_pending_copy", | 572 "bytes_pending_copy", |
569 static_cast<int>(resource_pool_->total_memory_usage_bytes() - | 573 static_cast<int>(resource_pool_->total_memory_usage_bytes() - |
570 resource_pool_->acquired_memory_usage_bytes())); | 574 resource_pool_->acquired_memory_usage_bytes())); |
571 } | 575 } |
572 | 576 |
573 } // namespace cc | 577 } // namespace cc |
OLD | NEW |