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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 | 174 |
175 // static | 175 // static |
176 scoped_ptr<TileTaskWorkerPool> OneCopyTileTaskWorkerPool::Create( | 176 scoped_ptr<TileTaskWorkerPool> OneCopyTileTaskWorkerPool::Create( |
177 base::SequencedTaskRunner* task_runner, | 177 base::SequencedTaskRunner* task_runner, |
178 TaskGraphRunner* task_graph_runner, | 178 TaskGraphRunner* task_graph_runner, |
179 ContextProvider* context_provider, | 179 ContextProvider* context_provider, |
180 ResourceProvider* resource_provider, | 180 ResourceProvider* resource_provider, |
181 int max_copy_texture_chromium_size, | 181 int max_copy_texture_chromium_size, |
182 bool use_partial_raster, | 182 bool use_partial_raster, |
183 int max_staging_buffer_usage_in_bytes, | 183 int max_staging_buffer_usage_in_bytes, |
184 bool use_rgba_4444_texture_format) { | 184 ResourceFormat preferred_tile_format) { |
185 return make_scoped_ptr<TileTaskWorkerPool>(new OneCopyTileTaskWorkerPool( | 185 return make_scoped_ptr<TileTaskWorkerPool>(new OneCopyTileTaskWorkerPool( |
186 task_runner, task_graph_runner, resource_provider, | 186 task_runner, task_graph_runner, resource_provider, |
187 max_copy_texture_chromium_size, use_partial_raster, | 187 max_copy_texture_chromium_size, use_partial_raster, |
188 max_staging_buffer_usage_in_bytes, use_rgba_4444_texture_format)); | 188 max_staging_buffer_usage_in_bytes, preferred_tile_format)); |
189 } | 189 } |
190 | 190 |
191 OneCopyTileTaskWorkerPool::OneCopyTileTaskWorkerPool( | 191 OneCopyTileTaskWorkerPool::OneCopyTileTaskWorkerPool( |
192 base::SequencedTaskRunner* task_runner, | 192 base::SequencedTaskRunner* task_runner, |
193 TaskGraphRunner* task_graph_runner, | 193 TaskGraphRunner* task_graph_runner, |
194 ResourceProvider* resource_provider, | 194 ResourceProvider* resource_provider, |
195 int max_copy_texture_chromium_size, | 195 int max_copy_texture_chromium_size, |
196 bool use_partial_raster, | 196 bool use_partial_raster, |
197 int max_staging_buffer_usage_in_bytes, | 197 int max_staging_buffer_usage_in_bytes, |
198 bool use_rgba_4444_texture_format) | 198 ResourceFormat preferred_tile_format) |
199 : task_runner_(task_runner), | 199 : task_runner_(task_runner), |
200 task_graph_runner_(task_graph_runner), | 200 task_graph_runner_(task_graph_runner), |
201 namespace_token_(task_graph_runner->GetNamespaceToken()), | 201 namespace_token_(task_graph_runner->GetNamespaceToken()), |
202 resource_provider_(resource_provider), | 202 resource_provider_(resource_provider), |
203 max_bytes_per_copy_operation_( | 203 max_bytes_per_copy_operation_( |
204 max_copy_texture_chromium_size | 204 max_copy_texture_chromium_size |
205 ? std::min(kMaxBytesPerCopyOperation, | 205 ? std::min(kMaxBytesPerCopyOperation, |
206 max_copy_texture_chromium_size) | 206 max_copy_texture_chromium_size) |
207 : kMaxBytesPerCopyOperation), | 207 : kMaxBytesPerCopyOperation), |
208 use_partial_raster_(use_partial_raster), | 208 use_partial_raster_(use_partial_raster), |
209 bytes_scheduled_since_last_flush_(0), | 209 bytes_scheduled_since_last_flush_(0), |
210 max_staging_buffer_usage_in_bytes_(max_staging_buffer_usage_in_bytes), | 210 max_staging_buffer_usage_in_bytes_(max_staging_buffer_usage_in_bytes), |
211 use_rgba_4444_texture_format_(use_rgba_4444_texture_format), | 211 preferred_tile_format_(preferred_tile_format), |
212 staging_buffer_usage_in_bytes_(0), | 212 staging_buffer_usage_in_bytes_(0), |
213 free_staging_buffer_usage_in_bytes_(0), | 213 free_staging_buffer_usage_in_bytes_(0), |
214 staging_buffer_expiration_delay_( | 214 staging_buffer_expiration_delay_( |
215 base::TimeDelta::FromMilliseconds(kStagingBufferExpirationDelayMs)), | 215 base::TimeDelta::FromMilliseconds(kStagingBufferExpirationDelayMs)), |
216 reduce_memory_usage_pending_(false), | 216 reduce_memory_usage_pending_(false), |
217 weak_ptr_factory_(this) { | 217 weak_ptr_factory_(this) { |
218 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( | 218 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( |
219 this, "OneCopyTileTaskWorkerPool", base::ThreadTaskRunnerHandle::Get()); | 219 this, "OneCopyTileTaskWorkerPool", base::ThreadTaskRunnerHandle::Get()); |
220 reduce_memory_usage_callback_ = | 220 reduce_memory_usage_callback_ = |
221 base::Bind(&OneCopyTileTaskWorkerPool::ReduceMemoryUsage, | 221 base::Bind(&OneCopyTileTaskWorkerPool::ReduceMemoryUsage, |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 | 274 |
275 task->WillComplete(); | 275 task->WillComplete(); |
276 task->CompleteOnOriginThread(this); | 276 task->CompleteOnOriginThread(this); |
277 task->DidComplete(); | 277 task->DidComplete(); |
278 } | 278 } |
279 completed_tasks_.clear(); | 279 completed_tasks_.clear(); |
280 } | 280 } |
281 | 281 |
282 ResourceFormat OneCopyTileTaskWorkerPool::GetResourceFormat( | 282 ResourceFormat OneCopyTileTaskWorkerPool::GetResourceFormat( |
283 bool must_support_alpha) const { | 283 bool must_support_alpha) const { |
284 return use_rgba_4444_texture_format_ | 284 if (resource_provider_->IsResourceFormatSupported(preferred_tile_format_) && |
285 ? RGBA_4444 | 285 (DoesResourceFormatSupportAlpha(preferred_tile_format_) || |
286 : resource_provider_->best_texture_format(); | 286 !must_support_alpha)) { |
| 287 return preferred_tile_format_; |
| 288 } |
| 289 |
| 290 return resource_provider_->best_texture_format(); |
287 } | 291 } |
288 | 292 |
289 bool OneCopyTileTaskWorkerPool::GetResourceRequiresSwizzle( | 293 bool OneCopyTileTaskWorkerPool::GetResourceRequiresSwizzle( |
290 bool must_support_alpha) const { | 294 bool must_support_alpha) const { |
291 return !PlatformColor::SameComponentOrder( | 295 return !PlatformColor::SameComponentOrder( |
292 GetResourceFormat(must_support_alpha)); | 296 GetResourceFormat(must_support_alpha)); |
293 } | 297 } |
294 | 298 |
295 scoped_ptr<RasterBuffer> OneCopyTileTaskWorkerPool::AcquireBufferForRaster( | 299 scoped_ptr<RasterBuffer> OneCopyTileTaskWorkerPool::AcquireBufferForRaster( |
296 const Resource* resource, | 300 const Resource* resource, |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 // TODO(reveman): This avoids a performance problem on some ChromeOS | 424 // TODO(reveman): This avoids a performance problem on some ChromeOS |
421 // devices. This needs to be removed to support native GpuMemoryBuffer | 425 // devices. This needs to be removed to support native GpuMemoryBuffer |
422 // implementations. crbug.com/436314 | 426 // implementations. crbug.com/436314 |
423 gl->BeginQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM, staging_buffer->query_id); | 427 gl->BeginQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM, staging_buffer->query_id); |
424 #else | 428 #else |
425 gl->BeginQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM, | 429 gl->BeginQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM, |
426 staging_buffer->query_id); | 430 staging_buffer->query_id); |
427 #endif | 431 #endif |
428 } | 432 } |
429 | 433 |
430 int bytes_per_row = | 434 // Since compressed texture's cannot be pre-allocated we might have an |
431 (BitsPerPixel(resource->format()) * resource->size().width()) / 8; | 435 // unallocated resource in which case we need to perform a full size copy. |
432 int chunk_size_in_rows = | 436 if (IsResourceFormatCompressed(resource->format())) { |
433 std::max(1, max_bytes_per_copy_operation_ / bytes_per_row); | 437 gl->CompressedCopyTextureCHROMIUM(GL_TEXTURE_2D, |
434 // Align chunk size to 4. Required to support compressed texture formats. | 438 staging_buffer->texture_id, |
435 chunk_size_in_rows = MathUtil::UncheckedRoundUp(chunk_size_in_rows, 4); | 439 resource_lock->texture_id()); |
436 int y = 0; | 440 } else { |
437 int height = resource->size().height(); | 441 int bytes_per_row = |
438 while (y < height) { | 442 (BitsPerPixel(resource->format()) * resource->size().width()) / 8; |
439 // Copy at most |chunk_size_in_rows|. | 443 int chunk_size_in_rows = |
440 int rows_to_copy = std::min(chunk_size_in_rows, height - y); | 444 std::max(1, max_bytes_per_copy_operation_ / bytes_per_row); |
441 DCHECK_GT(rows_to_copy, 0); | 445 // Align chunk size to 4. Required to support compressed texture formats. |
| 446 chunk_size_in_rows = MathUtil::UncheckedRoundUp(chunk_size_in_rows, 4); |
| 447 int y = 0; |
| 448 int height = resource->size().height(); |
| 449 while (y < height) { |
| 450 // Copy at most |chunk_size_in_rows|. |
| 451 int rows_to_copy = std::min(chunk_size_in_rows, height - y); |
| 452 DCHECK_GT(rows_to_copy, 0); |
442 | 453 |
443 gl->CopySubTextureCHROMIUM(GL_TEXTURE_2D, staging_buffer->texture_id, | 454 gl->CopySubTextureCHROMIUM(GL_TEXTURE_2D, staging_buffer->texture_id, |
444 resource_lock->texture_id(), 0, y, 0, y, | 455 resource_lock->texture_id(), 0, y, 0, y, |
445 resource->size().width(), rows_to_copy, false, | 456 resource->size().width(), rows_to_copy, |
446 false, false); | 457 false, false, false); |
447 y += rows_to_copy; | 458 y += rows_to_copy; |
448 | 459 |
449 // Increment |bytes_scheduled_since_last_flush_| by the amount of memory | 460 // Increment |bytes_scheduled_since_last_flush_| by the amount of memory |
450 // used for this copy operation. | 461 // used for this copy operation. |
451 bytes_scheduled_since_last_flush_ += rows_to_copy * bytes_per_row; | 462 bytes_scheduled_since_last_flush_ += rows_to_copy * bytes_per_row; |
452 | 463 |
453 if (bytes_scheduled_since_last_flush_ >= max_bytes_per_copy_operation_) { | 464 if (bytes_scheduled_since_last_flush_ >= |
454 gl->ShallowFlushCHROMIUM(); | 465 max_bytes_per_copy_operation_) { |
455 bytes_scheduled_since_last_flush_ = 0; | 466 gl->ShallowFlushCHROMIUM(); |
| 467 bytes_scheduled_since_last_flush_ = 0; |
| 468 } |
456 } | 469 } |
457 } | 470 } |
458 | 471 |
459 if (resource_provider_->use_sync_query()) { | 472 if (resource_provider_->use_sync_query()) { |
460 #if defined(OS_CHROMEOS) | 473 #if defined(OS_CHROMEOS) |
461 gl->EndQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM); | 474 gl->EndQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM); |
462 #else | 475 #else |
463 gl->EndQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM); | 476 gl->EndQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM); |
464 #endif | 477 #endif |
465 } | 478 } |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
719 return; | 732 return; |
720 | 733 |
721 busy_buffers_.front()->DestroyGLResources(gl); | 734 busy_buffers_.front()->DestroyGLResources(gl); |
722 RemoveStagingBuffer(busy_buffers_.front().get()); | 735 RemoveStagingBuffer(busy_buffers_.front().get()); |
723 busy_buffers_.pop_front(); | 736 busy_buffers_.pop_front(); |
724 } | 737 } |
725 } | 738 } |
726 } | 739 } |
727 | 740 |
728 } // namespace cc | 741 } // namespace cc |
OLD | NEW |