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 <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <limits> | 10 #include <limits> |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 | 178 |
179 // static | 179 // static |
180 scoped_ptr<TileTaskWorkerPool> OneCopyTileTaskWorkerPool::Create( | 180 scoped_ptr<TileTaskWorkerPool> OneCopyTileTaskWorkerPool::Create( |
181 base::SequencedTaskRunner* task_runner, | 181 base::SequencedTaskRunner* task_runner, |
182 TaskGraphRunner* task_graph_runner, | 182 TaskGraphRunner* task_graph_runner, |
183 ContextProvider* context_provider, | 183 ContextProvider* context_provider, |
184 ResourceProvider* resource_provider, | 184 ResourceProvider* resource_provider, |
185 int max_copy_texture_chromium_size, | 185 int max_copy_texture_chromium_size, |
186 bool use_partial_raster, | 186 bool use_partial_raster, |
187 int max_staging_buffer_usage_in_bytes, | 187 int max_staging_buffer_usage_in_bytes, |
188 bool use_rgba_4444_texture_format) { | 188 ResourceFormat preferred_tile_format) { |
189 return make_scoped_ptr<TileTaskWorkerPool>(new OneCopyTileTaskWorkerPool( | 189 return make_scoped_ptr<TileTaskWorkerPool>(new OneCopyTileTaskWorkerPool( |
190 task_runner, task_graph_runner, resource_provider, | 190 task_runner, task_graph_runner, resource_provider, |
191 max_copy_texture_chromium_size, use_partial_raster, | 191 max_copy_texture_chromium_size, use_partial_raster, |
192 max_staging_buffer_usage_in_bytes, use_rgba_4444_texture_format)); | 192 max_staging_buffer_usage_in_bytes, preferred_tile_format)); |
193 } | 193 } |
194 | 194 |
195 OneCopyTileTaskWorkerPool::OneCopyTileTaskWorkerPool( | 195 OneCopyTileTaskWorkerPool::OneCopyTileTaskWorkerPool( |
196 base::SequencedTaskRunner* task_runner, | 196 base::SequencedTaskRunner* task_runner, |
197 TaskGraphRunner* task_graph_runner, | 197 TaskGraphRunner* task_graph_runner, |
198 ResourceProvider* resource_provider, | 198 ResourceProvider* resource_provider, |
199 int max_copy_texture_chromium_size, | 199 int max_copy_texture_chromium_size, |
200 bool use_partial_raster, | 200 bool use_partial_raster, |
201 int max_staging_buffer_usage_in_bytes, | 201 int max_staging_buffer_usage_in_bytes, |
202 bool use_rgba_4444_texture_format) | 202 ResourceFormat preferred_tile_format) |
203 : task_runner_(task_runner), | 203 : task_runner_(task_runner), |
204 task_graph_runner_(task_graph_runner), | 204 task_graph_runner_(task_graph_runner), |
205 namespace_token_(task_graph_runner->GetNamespaceToken()), | 205 namespace_token_(task_graph_runner->GetNamespaceToken()), |
206 resource_provider_(resource_provider), | 206 resource_provider_(resource_provider), |
207 max_bytes_per_copy_operation_( | 207 max_bytes_per_copy_operation_( |
208 max_copy_texture_chromium_size | 208 max_copy_texture_chromium_size |
209 ? std::min(kMaxBytesPerCopyOperation, | 209 ? std::min(kMaxBytesPerCopyOperation, |
210 max_copy_texture_chromium_size) | 210 max_copy_texture_chromium_size) |
211 : kMaxBytesPerCopyOperation), | 211 : kMaxBytesPerCopyOperation), |
212 use_partial_raster_(use_partial_raster), | 212 use_partial_raster_(use_partial_raster), |
213 bytes_scheduled_since_last_flush_(0), | 213 bytes_scheduled_since_last_flush_(0), |
214 max_staging_buffer_usage_in_bytes_(max_staging_buffer_usage_in_bytes), | 214 max_staging_buffer_usage_in_bytes_(max_staging_buffer_usage_in_bytes), |
215 use_rgba_4444_texture_format_(use_rgba_4444_texture_format), | 215 preferred_tile_format_(preferred_tile_format), |
216 staging_buffer_usage_in_bytes_(0), | 216 staging_buffer_usage_in_bytes_(0), |
217 free_staging_buffer_usage_in_bytes_(0), | 217 free_staging_buffer_usage_in_bytes_(0), |
218 staging_buffer_expiration_delay_( | 218 staging_buffer_expiration_delay_( |
219 base::TimeDelta::FromMilliseconds(kStagingBufferExpirationDelayMs)), | 219 base::TimeDelta::FromMilliseconds(kStagingBufferExpirationDelayMs)), |
220 reduce_memory_usage_pending_(false), | 220 reduce_memory_usage_pending_(false), |
221 weak_ptr_factory_(this) { | 221 weak_ptr_factory_(this) { |
222 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( | 222 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( |
223 this, "OneCopyTileTaskWorkerPool", base::ThreadTaskRunnerHandle::Get()); | 223 this, "OneCopyTileTaskWorkerPool", base::ThreadTaskRunnerHandle::Get()); |
224 reduce_memory_usage_callback_ = | 224 reduce_memory_usage_callback_ = |
225 base::Bind(&OneCopyTileTaskWorkerPool::ReduceMemoryUsage, | 225 base::Bind(&OneCopyTileTaskWorkerPool::ReduceMemoryUsage, |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 | 278 |
279 task->WillComplete(); | 279 task->WillComplete(); |
280 task->CompleteOnOriginThread(this); | 280 task->CompleteOnOriginThread(this); |
281 task->DidComplete(); | 281 task->DidComplete(); |
282 } | 282 } |
283 completed_tasks_.clear(); | 283 completed_tasks_.clear(); |
284 } | 284 } |
285 | 285 |
286 ResourceFormat OneCopyTileTaskWorkerPool::GetResourceFormat( | 286 ResourceFormat OneCopyTileTaskWorkerPool::GetResourceFormat( |
287 bool must_support_alpha) const { | 287 bool must_support_alpha) const { |
288 return use_rgba_4444_texture_format_ | 288 if (resource_provider_->IsResourceFormatSupported(preferred_tile_format_) && |
289 ? RGBA_4444 | 289 (DoesResourceFormatSupportAlpha(preferred_tile_format_) || |
290 : resource_provider_->best_texture_format(); | 290 !must_support_alpha)) { |
| 291 return preferred_tile_format_; |
| 292 } |
| 293 |
| 294 return resource_provider_->best_texture_format(); |
291 } | 295 } |
292 | 296 |
293 bool OneCopyTileTaskWorkerPool::GetResourceRequiresSwizzle( | 297 bool OneCopyTileTaskWorkerPool::GetResourceRequiresSwizzle( |
294 bool must_support_alpha) const { | 298 bool must_support_alpha) const { |
295 return !PlatformColor::SameComponentOrder( | 299 return !PlatformColor::SameComponentOrder( |
296 GetResourceFormat(must_support_alpha)); | 300 GetResourceFormat(must_support_alpha)); |
297 } | 301 } |
298 | 302 |
299 scoped_ptr<RasterBuffer> OneCopyTileTaskWorkerPool::AcquireBufferForRaster( | 303 scoped_ptr<RasterBuffer> OneCopyTileTaskWorkerPool::AcquireBufferForRaster( |
300 const Resource* resource, | 304 const Resource* resource, |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY) | 424 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY) |
421 // TODO(reveman): This avoids a performance problem on ARM ChromeOS | 425 // TODO(reveman): This avoids a performance problem on ARM ChromeOS |
422 // devices. crbug.com/580166 | 426 // devices. crbug.com/580166 |
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(staging_buffer->texture_id, |
434 // Align chunk size to 4. Required to support compressed texture formats. | 438 resource_lock->texture_id()); |
435 chunk_size_in_rows = MathUtil::UncheckedRoundUp(chunk_size_in_rows, 4); | 439 } else { |
436 int y = 0; | 440 int bytes_per_row = |
437 int height = resource->size().height(); | 441 (BitsPerPixel(resource->format()) * resource->size().width()) / 8; |
438 while (y < height) { | 442 int chunk_size_in_rows = |
439 // Copy at most |chunk_size_in_rows|. | 443 std::max(1, max_bytes_per_copy_operation_ / bytes_per_row); |
440 int rows_to_copy = std::min(chunk_size_in_rows, height - y); | 444 // Align chunk size to 4. Required to support compressed texture formats. |
441 DCHECK_GT(rows_to_copy, 0); | 445 chunk_size_in_rows = MathUtil::UncheckedRoundUp(chunk_size_in_rows, 4); |
| 446 int y = 0; |
| 447 int height = resource->size().height(); |
| 448 while (y < height) { |
| 449 // Copy at most |chunk_size_in_rows|. |
| 450 int rows_to_copy = std::min(chunk_size_in_rows, height - y); |
| 451 DCHECK_GT(rows_to_copy, 0); |
442 | 452 |
443 gl->CopySubTextureCHROMIUM( | 453 gl->CopySubTextureCHROMIUM( |
444 staging_buffer->texture_id, resource_lock->texture_id(), 0, y, 0, y, | 454 staging_buffer->texture_id, resource_lock->texture_id(), 0, y, 0, y, |
445 resource->size().width(), rows_to_copy, false, false, false); | 455 resource->size().width(), rows_to_copy, false, false, false); |
446 y += rows_to_copy; | 456 y += rows_to_copy; |
447 | 457 |
448 // Increment |bytes_scheduled_since_last_flush_| by the amount of memory | 458 // Increment |bytes_scheduled_since_last_flush_| by the amount of memory |
449 // used for this copy operation. | 459 // used for this copy operation. |
450 bytes_scheduled_since_last_flush_ += rows_to_copy * bytes_per_row; | 460 bytes_scheduled_since_last_flush_ += rows_to_copy * bytes_per_row; |
451 | 461 |
452 if (bytes_scheduled_since_last_flush_ >= max_bytes_per_copy_operation_) { | 462 if (bytes_scheduled_since_last_flush_ >= |
453 gl->ShallowFlushCHROMIUM(); | 463 max_bytes_per_copy_operation_) { |
454 bytes_scheduled_since_last_flush_ = 0; | 464 gl->ShallowFlushCHROMIUM(); |
| 465 bytes_scheduled_since_last_flush_ = 0; |
| 466 } |
455 } | 467 } |
456 } | 468 } |
457 | 469 |
458 if (resource_provider_->use_sync_query()) { | 470 if (resource_provider_->use_sync_query()) { |
459 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY) | 471 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY) |
460 gl->EndQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM); | 472 gl->EndQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM); |
461 #else | 473 #else |
462 gl->EndQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM); | 474 gl->EndQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM); |
463 #endif | 475 #endif |
464 } | 476 } |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
725 return; | 737 return; |
726 | 738 |
727 busy_buffers_.front()->DestroyGLResources(gl); | 739 busy_buffers_.front()->DestroyGLResources(gl); |
728 RemoveStagingBuffer(busy_buffers_.front().get()); | 740 RemoveStagingBuffer(busy_buffers_.front().get()); |
729 busy_buffers_.pop_front(); | 741 busy_buffers_.pop_front(); |
730 } | 742 } |
731 } | 743 } |
732 } | 744 } |
733 | 745 |
734 } // namespace cc | 746 } // namespace cc |
OLD | NEW |