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 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 pmd->AddOwnershipEdge(buffer_dump->guid(), shared_buffer_guid, kImportance); | 167 pmd->AddOwnershipEdge(buffer_dump->guid(), shared_buffer_guid, kImportance); |
168 } | 168 } |
169 | 169 |
170 // static | 170 // static |
171 scoped_ptr<TileTaskWorkerPool> OneCopyTileTaskWorkerPool::Create( | 171 scoped_ptr<TileTaskWorkerPool> OneCopyTileTaskWorkerPool::Create( |
172 base::SequencedTaskRunner* task_runner, | 172 base::SequencedTaskRunner* task_runner, |
173 TaskGraphRunner* task_graph_runner, | 173 TaskGraphRunner* task_graph_runner, |
174 ContextProvider* context_provider, | 174 ContextProvider* context_provider, |
175 ResourceProvider* resource_provider, | 175 ResourceProvider* resource_provider, |
176 int max_copy_texture_chromium_size, | 176 int max_copy_texture_chromium_size, |
177 bool use_persistent_gpu_memory_buffers, | 177 bool use_partial_raster, |
178 int max_staging_buffer_usage_in_bytes, | 178 int max_staging_buffer_usage_in_bytes, |
179 bool use_rgba_4444_texture_format) { | 179 bool use_rgba_4444_texture_format) { |
180 return make_scoped_ptr<TileTaskWorkerPool>(new OneCopyTileTaskWorkerPool( | 180 return make_scoped_ptr<TileTaskWorkerPool>(new OneCopyTileTaskWorkerPool( |
181 task_runner, task_graph_runner, resource_provider, | 181 task_runner, task_graph_runner, resource_provider, |
182 max_copy_texture_chromium_size, use_persistent_gpu_memory_buffers, | 182 max_copy_texture_chromium_size, use_partial_raster, |
183 max_staging_buffer_usage_in_bytes, use_rgba_4444_texture_format)); | 183 max_staging_buffer_usage_in_bytes, use_rgba_4444_texture_format)); |
184 } | 184 } |
185 | 185 |
186 OneCopyTileTaskWorkerPool::OneCopyTileTaskWorkerPool( | 186 OneCopyTileTaskWorkerPool::OneCopyTileTaskWorkerPool( |
187 base::SequencedTaskRunner* task_runner, | 187 base::SequencedTaskRunner* task_runner, |
188 TaskGraphRunner* task_graph_runner, | 188 TaskGraphRunner* task_graph_runner, |
189 ResourceProvider* resource_provider, | 189 ResourceProvider* resource_provider, |
190 int max_copy_texture_chromium_size, | 190 int max_copy_texture_chromium_size, |
191 bool use_persistent_gpu_memory_buffers, | 191 bool use_partial_raster, |
192 int max_staging_buffer_usage_in_bytes, | 192 int max_staging_buffer_usage_in_bytes, |
193 bool use_rgba_4444_texture_format) | 193 bool use_rgba_4444_texture_format) |
194 : task_runner_(task_runner), | 194 : task_runner_(task_runner), |
195 task_graph_runner_(task_graph_runner), | 195 task_graph_runner_(task_graph_runner), |
196 namespace_token_(task_graph_runner->GetNamespaceToken()), | 196 namespace_token_(task_graph_runner->GetNamespaceToken()), |
197 resource_provider_(resource_provider), | 197 resource_provider_(resource_provider), |
198 max_bytes_per_copy_operation_( | 198 max_bytes_per_copy_operation_( |
199 max_copy_texture_chromium_size | 199 max_copy_texture_chromium_size |
200 ? std::min(kMaxBytesPerCopyOperation, | 200 ? std::min(kMaxBytesPerCopyOperation, |
201 max_copy_texture_chromium_size) | 201 max_copy_texture_chromium_size) |
202 : kMaxBytesPerCopyOperation), | 202 : kMaxBytesPerCopyOperation), |
203 use_persistent_gpu_memory_buffers_(use_persistent_gpu_memory_buffers), | 203 use_partial_raster_(use_partial_raster), |
204 bytes_scheduled_since_last_flush_(0), | 204 bytes_scheduled_since_last_flush_(0), |
205 max_staging_buffer_usage_in_bytes_(max_staging_buffer_usage_in_bytes), | 205 max_staging_buffer_usage_in_bytes_(max_staging_buffer_usage_in_bytes), |
206 use_rgba_4444_texture_format_(use_rgba_4444_texture_format), | 206 use_rgba_4444_texture_format_(use_rgba_4444_texture_format), |
207 staging_buffer_usage_in_bytes_(0), | 207 staging_buffer_usage_in_bytes_(0), |
208 free_staging_buffer_usage_in_bytes_(0), | 208 free_staging_buffer_usage_in_bytes_(0), |
209 staging_buffer_expiration_delay_( | 209 staging_buffer_expiration_delay_( |
210 base::TimeDelta::FromMilliseconds(kStagingBufferExpirationDelayMs)), | 210 base::TimeDelta::FromMilliseconds(kStagingBufferExpirationDelayMs)), |
211 reduce_memory_usage_pending_(false), | 211 reduce_memory_usage_pending_(false), |
212 weak_ptr_factory_(this), | 212 weak_ptr_factory_(this), |
213 task_set_finished_weak_ptr_factory_(this) { | 213 task_set_finished_weak_ptr_factory_(this) { |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 uint64_t new_content_id) { | 376 uint64_t new_content_id) { |
377 base::AutoLock lock(lock_); | 377 base::AutoLock lock(lock_); |
378 | 378 |
379 scoped_ptr<StagingBuffer> staging_buffer = | 379 scoped_ptr<StagingBuffer> staging_buffer = |
380 AcquireStagingBuffer(resource, previous_content_id); | 380 AcquireStagingBuffer(resource, previous_content_id); |
381 DCHECK(staging_buffer); | 381 DCHECK(staging_buffer); |
382 | 382 |
383 { | 383 { |
384 base::AutoUnlock unlock(lock_); | 384 base::AutoUnlock unlock(lock_); |
385 | 385 |
386 // Allocate GpuMemoryBuffer if necessary. | 386 // Allocate GpuMemoryBuffer if necessary. If using partial raster, we |
| 387 // must allocate a buffer with BufferUsage PERSISTENT_MAP. |
387 if (!staging_buffer->gpu_memory_buffer) { | 388 if (!staging_buffer->gpu_memory_buffer) { |
388 staging_buffer->gpu_memory_buffer = | 389 staging_buffer->gpu_memory_buffer = |
389 resource_provider_->gpu_memory_buffer_manager() | 390 resource_provider_->gpu_memory_buffer_manager() |
390 ->AllocateGpuMemoryBuffer(staging_buffer->size, | 391 ->AllocateGpuMemoryBuffer( |
391 BufferFormat(resource->format()), | 392 staging_buffer->size, BufferFormat(resource->format()), |
392 use_persistent_gpu_memory_buffers_ | 393 use_partial_raster_ ? gfx::BufferUsage::PERSISTENT_MAP |
393 ? gfx::BufferUsage::PERSISTENT_MAP | 394 : gfx::BufferUsage::MAP); |
394 : gfx::BufferUsage::MAP); | |
395 DCHECK_EQ(gfx::NumberOfPlanesForBufferFormat( | 395 DCHECK_EQ(gfx::NumberOfPlanesForBufferFormat( |
396 staging_buffer->gpu_memory_buffer->GetFormat()), | 396 staging_buffer->gpu_memory_buffer->GetFormat()), |
397 1u); | 397 1u); |
398 } | 398 } |
399 | 399 |
400 gfx::Rect playback_rect = raster_full_rect; | 400 gfx::Rect playback_rect = raster_full_rect; |
401 if (use_persistent_gpu_memory_buffers_ && previous_content_id) { | 401 if (use_partial_raster_ && previous_content_id) { |
402 // Reduce playback rect to dirty region if the content id of the staging | 402 // Reduce playback rect to dirty region if the content id of the staging |
403 // buffer matches the prevous content id. | 403 // buffer matches the prevous content id. |
404 if (previous_content_id == staging_buffer->content_id) | 404 if (previous_content_id == staging_buffer->content_id) |
405 playback_rect.Intersect(raster_dirty_rect); | 405 playback_rect.Intersect(raster_dirty_rect); |
406 } | 406 } |
407 | 407 |
408 if (staging_buffer->gpu_memory_buffer) { | 408 if (staging_buffer->gpu_memory_buffer) { |
409 void* data = nullptr; | 409 void* data = nullptr; |
410 bool rv = staging_buffer->gpu_memory_buffer->Map(&data); | 410 bool rv = staging_buffer->gpu_memory_buffer->Map(&data); |
411 DCHECK(rv); | 411 DCHECK(rv); |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
630 gl->Finish(); | 630 gl->Finish(); |
631 while (!busy_buffers_.empty()) { | 631 while (!busy_buffers_.empty()) { |
632 MarkStagingBufferAsFree(busy_buffers_.front()); | 632 MarkStagingBufferAsFree(busy_buffers_.front()); |
633 free_buffers_.push_back(busy_buffers_.take_front()); | 633 free_buffers_.push_back(busy_buffers_.take_front()); |
634 } | 634 } |
635 } | 635 } |
636 } | 636 } |
637 | 637 |
638 // Find a staging buffer that allows us to perform partial raster when | 638 // Find a staging buffer that allows us to perform partial raster when |
639 // using persistent GpuMemoryBuffers. | 639 // using persistent GpuMemoryBuffers. |
640 if (use_persistent_gpu_memory_buffers_ && previous_content_id) { | 640 if (use_partial_raster_ && previous_content_id) { |
641 StagingBufferDeque::iterator it = | 641 StagingBufferDeque::iterator it = |
642 std::find_if(free_buffers_.begin(), free_buffers_.end(), | 642 std::find_if(free_buffers_.begin(), free_buffers_.end(), |
643 [previous_content_id](const StagingBuffer* buffer) { | 643 [previous_content_id](const StagingBuffer* buffer) { |
644 return buffer->content_id == previous_content_id; | 644 return buffer->content_id == previous_content_id; |
645 }); | 645 }); |
646 if (it != free_buffers_.end()) { | 646 if (it != free_buffers_.end()) { |
647 staging_buffer = free_buffers_.take(it); | 647 staging_buffer = free_buffers_.take(it); |
648 MarkStagingBufferAsBusy(staging_buffer.get()); | 648 MarkStagingBufferAsBusy(staging_buffer.get()); |
649 } | 649 } |
650 } | 650 } |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
811 | 811 |
812 staging_state->SetInteger("staging_buffer_count", | 812 staging_state->SetInteger("staging_buffer_count", |
813 static_cast<int>(buffers_.size())); | 813 static_cast<int>(buffers_.size())); |
814 staging_state->SetInteger("busy_count", | 814 staging_state->SetInteger("busy_count", |
815 static_cast<int>(busy_buffers_.size())); | 815 static_cast<int>(busy_buffers_.size())); |
816 staging_state->SetInteger("free_count", | 816 staging_state->SetInteger("free_count", |
817 static_cast<int>(free_buffers_.size())); | 817 static_cast<int>(free_buffers_.size())); |
818 } | 818 } |
819 | 819 |
820 } // namespace cc | 820 } // namespace cc |
OLD | NEW |