| 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 task_set_finished_weak_ptr_factory_(this) { | 218 task_set_finished_weak_ptr_factory_(this) { |
| 219 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( | 219 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( |
| 220 this, "OneCopyTileTaskWorkerPool", base::ThreadTaskRunnerHandle::Get()); | 220 this, "OneCopyTileTaskWorkerPool", base::ThreadTaskRunnerHandle::Get()); |
| 221 reduce_memory_usage_callback_ = | 221 reduce_memory_usage_callback_ = |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 | 335 |
| 336 task->WillComplete(); | 336 task->WillComplete(); |
| 337 task->CompleteOnOriginThread(this); | 337 task->CompleteOnOriginThread(this); |
| 338 task->DidComplete(); | 338 task->DidComplete(); |
| 339 } | 339 } |
| 340 completed_tasks_.clear(); | 340 completed_tasks_.clear(); |
| 341 } | 341 } |
| 342 | 342 |
| 343 ResourceFormat OneCopyTileTaskWorkerPool::GetResourceFormat( | 343 ResourceFormat OneCopyTileTaskWorkerPool::GetResourceFormat( |
| 344 bool must_support_alpha) const { | 344 bool must_support_alpha) const { |
| 345 return use_rgba_4444_texture_format_ | 345 if (resource_provider_->IsResourceFormatSupported(preferred_tile_format_) && |
| 346 ? RGBA_4444 | 346 (DoesResourceFormatSupportAlpha(preferred_tile_format_) || |
| 347 : resource_provider_->best_texture_format(); | 347 !must_support_alpha)) { |
| 348 return preferred_tile_format_; |
| 349 } |
| 350 |
| 351 return resource_provider_->best_texture_format(); |
| 348 } | 352 } |
| 349 | 353 |
| 350 bool OneCopyTileTaskWorkerPool::GetResourceRequiresSwizzle( | 354 bool OneCopyTileTaskWorkerPool::GetResourceRequiresSwizzle( |
| 351 bool must_support_alpha) const { | 355 bool must_support_alpha) const { |
| 352 return !PlatformColor::SameComponentOrder( | 356 return !PlatformColor::SameComponentOrder( |
| 353 GetResourceFormat(must_support_alpha)); | 357 GetResourceFormat(must_support_alpha)); |
| 354 } | 358 } |
| 355 | 359 |
| 356 scoped_ptr<RasterBuffer> OneCopyTileTaskWorkerPool::AcquireBufferForRaster( | 360 scoped_ptr<RasterBuffer> OneCopyTileTaskWorkerPool::AcquireBufferForRaster( |
| 357 const Resource* resource, | 361 const Resource* resource, |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 481 // TODO(reveman): This avoids a performance problem on some ChromeOS | 485 // TODO(reveman): This avoids a performance problem on some ChromeOS |
| 482 // devices. This needs to be removed to support native GpuMemoryBuffer | 486 // devices. This needs to be removed to support native GpuMemoryBuffer |
| 483 // implementations. crbug.com/436314 | 487 // implementations. crbug.com/436314 |
| 484 gl->BeginQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM, staging_buffer->query_id); | 488 gl->BeginQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM, staging_buffer->query_id); |
| 485 #else | 489 #else |
| 486 gl->BeginQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM, | 490 gl->BeginQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM, |
| 487 staging_buffer->query_id); | 491 staging_buffer->query_id); |
| 488 #endif | 492 #endif |
| 489 } | 493 } |
| 490 | 494 |
| 491 int bytes_per_row = | 495 // Since compressed texture's cannot be pre-allocated we might have an |
| 492 (BitsPerPixel(resource->format()) * resource->size().width()) / 8; | 496 // unallocated resource in which case we need to perform a full size copy. |
| 493 int chunk_size_in_rows = | 497 if (IsResourceFormatCompressed(resource->format())) { |
| 494 std::max(1, max_bytes_per_copy_operation_ / bytes_per_row); | 498 gl->CompressedCopyTextureCHROMIUM(GL_TEXTURE_2D, |
| 495 // Align chunk size to 4. Required to support compressed texture formats. | 499 staging_buffer->texture_id, |
| 496 chunk_size_in_rows = MathUtil::UncheckedRoundUp(chunk_size_in_rows, 4); | 500 resource_lock->texture_id()); |
| 497 int y = 0; | 501 } else { |
| 498 int height = resource->size().height(); | 502 int bytes_per_row = |
| 499 while (y < height) { | 503 (BitsPerPixel(resource->format()) * resource->size().width()) / 8; |
| 500 // Copy at most |chunk_size_in_rows|. | 504 int chunk_size_in_rows = |
| 501 int rows_to_copy = std::min(chunk_size_in_rows, height - y); | 505 std::max(1, max_bytes_per_copy_operation_ / bytes_per_row); |
| 502 DCHECK_GT(rows_to_copy, 0); | 506 // Align chunk size to 4. Required to support compressed texture formats. |
| 507 chunk_size_in_rows = MathUtil::UncheckedRoundUp(chunk_size_in_rows, 4); |
| 508 int y = 0; |
| 509 int height = resource->size().height(); |
| 510 while (y < height) { |
| 511 // Copy at most |chunk_size_in_rows|. |
| 512 int rows_to_copy = std::min(chunk_size_in_rows, height - y); |
| 513 DCHECK_GT(rows_to_copy, 0); |
| 503 | 514 |
| 504 gl->CopySubTextureCHROMIUM(GL_TEXTURE_2D, staging_buffer->texture_id, | 515 gl->CopySubTextureCHROMIUM(GL_TEXTURE_2D, staging_buffer->texture_id, |
| 505 resource_lock->texture_id(), 0, y, 0, y, | 516 resource_lock->texture_id(), 0, y, 0, y, |
| 506 resource->size().width(), rows_to_copy, false, | 517 resource->size().width(), rows_to_copy, |
| 507 false, false); | 518 false, false, false); |
| 508 y += rows_to_copy; | 519 y += rows_to_copy; |
| 509 | 520 |
| 510 // Increment |bytes_scheduled_since_last_flush_| by the amount of memory | 521 // Increment |bytes_scheduled_since_last_flush_| by the amount of memory |
| 511 // used for this copy operation. | 522 // used for this copy operation. |
| 512 bytes_scheduled_since_last_flush_ += rows_to_copy * bytes_per_row; | 523 bytes_scheduled_since_last_flush_ += rows_to_copy * bytes_per_row; |
| 513 | 524 |
| 514 if (bytes_scheduled_since_last_flush_ >= max_bytes_per_copy_operation_) { | 525 if (bytes_scheduled_since_last_flush_ >= |
| 515 gl->ShallowFlushCHROMIUM(); | 526 max_bytes_per_copy_operation_) { |
| 516 bytes_scheduled_since_last_flush_ = 0; | 527 gl->ShallowFlushCHROMIUM(); |
| 528 bytes_scheduled_since_last_flush_ = 0; |
| 529 } |
| 517 } | 530 } |
| 518 } | 531 } |
| 519 | 532 |
| 520 if (resource_provider_->use_sync_query()) { | 533 if (resource_provider_->use_sync_query()) { |
| 521 #if defined(OS_CHROMEOS) | 534 #if defined(OS_CHROMEOS) |
| 522 gl->EndQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM); | 535 gl->EndQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM); |
| 523 #else | 536 #else |
| 524 gl->EndQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM); | 537 gl->EndQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM); |
| 525 #endif | 538 #endif |
| 526 } | 539 } |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 823 | 836 |
| 824 staging_state->SetInteger("staging_buffer_count", | 837 staging_state->SetInteger("staging_buffer_count", |
| 825 static_cast<int>(buffers_.size())); | 838 static_cast<int>(buffers_.size())); |
| 826 staging_state->SetInteger("busy_count", | 839 staging_state->SetInteger("busy_count", |
| 827 static_cast<int>(busy_buffers_.size())); | 840 static_cast<int>(busy_buffers_.size())); |
| 828 staging_state->SetInteger("free_count", | 841 staging_state->SetInteger("free_count", |
| 829 static_cast<int>(free_buffers_.size())); | 842 static_cast<int>(free_buffers_.size())); |
| 830 } | 843 } |
| 831 | 844 |
| 832 } // namespace cc | 845 } // namespace cc |
| OLD | NEW |