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 ResourceFormat preferred_tile_format) { | 184 bool use_rgba_4444_texture_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, preferred_tile_format)); | 188 max_staging_buffer_usage_in_bytes, use_rgba_4444_texture_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 ResourceFormat preferred_tile_format) | 198 bool use_rgba_4444_texture_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 preferred_tile_format_(preferred_tile_format), | 211 use_rgba_4444_texture_format_(use_rgba_4444_texture_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 if (resource_provider_->IsResourceFormatSupported(preferred_tile_format_) && | 284 return use_rgba_4444_texture_format_ |
285 (DoesResourceFormatSupportAlpha(preferred_tile_format_) || | 285 ? RGBA_4444 |
286 !must_support_alpha)) { | 286 : resource_provider_->best_texture_format(); |
287 return preferred_tile_format_; | |
288 } | |
289 | |
290 return resource_provider_->best_texture_format(); | |
291 } | 287 } |
292 | 288 |
293 bool OneCopyTileTaskWorkerPool::GetResourceRequiresSwizzle( | 289 bool OneCopyTileTaskWorkerPool::GetResourceRequiresSwizzle( |
294 bool must_support_alpha) const { | 290 bool must_support_alpha) const { |
295 return !PlatformColor::SameComponentOrder( | 291 return !PlatformColor::SameComponentOrder( |
296 GetResourceFormat(must_support_alpha)); | 292 GetResourceFormat(must_support_alpha)); |
297 } | 293 } |
298 | 294 |
299 scoped_ptr<RasterBuffer> OneCopyTileTaskWorkerPool::AcquireBufferForRaster( | 295 scoped_ptr<RasterBuffer> OneCopyTileTaskWorkerPool::AcquireBufferForRaster( |
300 const Resource* resource, | 296 const Resource* resource, |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 // TODO(reveman): This avoids a performance problem on some ChromeOS | 420 // TODO(reveman): This avoids a performance problem on some ChromeOS |
425 // devices. This needs to be removed to support native GpuMemoryBuffer | 421 // devices. This needs to be removed to support native GpuMemoryBuffer |
426 // implementations. crbug.com/436314 | 422 // implementations. crbug.com/436314 |
427 gl->BeginQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM, staging_buffer->query_id); | 423 gl->BeginQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM, staging_buffer->query_id); |
428 #else | 424 #else |
429 gl->BeginQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM, | 425 gl->BeginQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM, |
430 staging_buffer->query_id); | 426 staging_buffer->query_id); |
431 #endif | 427 #endif |
432 } | 428 } |
433 | 429 |
434 // Since compressed texture's cannot be pre-allocated we might have an | 430 int bytes_per_row = |
435 // unallocated resource in which case we need to perform a full size copy. | 431 (BitsPerPixel(resource->format()) * resource->size().width()) / 8; |
436 if (IsResourceFormatCompressed(resource->format())) { | 432 int chunk_size_in_rows = |
437 gl->CompressedCopyTextureCHROMIUM(GL_TEXTURE_2D, | 433 std::max(1, max_bytes_per_copy_operation_ / bytes_per_row); |
438 staging_buffer->texture_id, | 434 // Align chunk size to 4. Required to support compressed texture formats. |
439 resource_lock->texture_id()); | 435 chunk_size_in_rows = MathUtil::UncheckedRoundUp(chunk_size_in_rows, 4); |
440 } else { | 436 int y = 0; |
441 int bytes_per_row = | 437 int height = resource->size().height(); |
442 (BitsPerPixel(resource->format()) * resource->size().width()) / 8; | 438 while (y < height) { |
443 int chunk_size_in_rows = | 439 // Copy at most |chunk_size_in_rows|. |
444 std::max(1, max_bytes_per_copy_operation_ / bytes_per_row); | 440 int rows_to_copy = std::min(chunk_size_in_rows, height - y); |
445 // Align chunk size to 4. Required to support compressed texture formats. | 441 DCHECK_GT(rows_to_copy, 0); |
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); | |
453 | 442 |
454 gl->CopySubTextureCHROMIUM(GL_TEXTURE_2D, staging_buffer->texture_id, | 443 gl->CopySubTextureCHROMIUM(GL_TEXTURE_2D, staging_buffer->texture_id, |
455 resource_lock->texture_id(), 0, y, 0, y, | 444 resource_lock->texture_id(), 0, y, 0, y, |
456 resource->size().width(), rows_to_copy, | 445 resource->size().width(), rows_to_copy, false, |
457 false, false, false); | 446 false, false); |
458 y += rows_to_copy; | 447 y += rows_to_copy; |
459 | 448 |
460 // Increment |bytes_scheduled_since_last_flush_| by the amount of memory | 449 // Increment |bytes_scheduled_since_last_flush_| by the amount of memory |
461 // used for this copy operation. | 450 // used for this copy operation. |
462 bytes_scheduled_since_last_flush_ += rows_to_copy * bytes_per_row; | 451 bytes_scheduled_since_last_flush_ += rows_to_copy * bytes_per_row; |
463 | 452 |
464 if (bytes_scheduled_since_last_flush_ >= | 453 if (bytes_scheduled_since_last_flush_ >= max_bytes_per_copy_operation_) { |
465 max_bytes_per_copy_operation_) { | 454 gl->ShallowFlushCHROMIUM(); |
466 gl->ShallowFlushCHROMIUM(); | 455 bytes_scheduled_since_last_flush_ = 0; |
467 bytes_scheduled_since_last_flush_ = 0; | |
468 } | |
469 } | 456 } |
470 } | 457 } |
471 | 458 |
472 if (resource_provider_->use_sync_query()) { | 459 if (resource_provider_->use_sync_query()) { |
473 #if defined(OS_CHROMEOS) | 460 #if defined(OS_CHROMEOS) |
474 gl->EndQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM); | 461 gl->EndQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM); |
475 #else | 462 #else |
476 gl->EndQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM); | 463 gl->EndQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM); |
477 #endif | 464 #endif |
478 } | 465 } |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
732 return; | 719 return; |
733 | 720 |
734 busy_buffers_.front()->DestroyGLResources(gl); | 721 busy_buffers_.front()->DestroyGLResources(gl); |
735 RemoveStagingBuffer(busy_buffers_.front().get()); | 722 RemoveStagingBuffer(busy_buffers_.front().get()); |
736 busy_buffers_.pop_front(); | 723 busy_buffers_.pop_front(); |
737 } | 724 } |
738 } | 725 } |
739 } | 726 } |
740 | 727 |
741 } // namespace cc | 728 } // namespace cc |
OLD | NEW |