| 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> |
| 11 #include <utility> | 11 #include <utility> |
| 12 | 12 |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/ptr_util.h" |
| 14 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 15 #include "base/thread_task_runner_handle.h" | 16 #include "base/thread_task_runner_handle.h" |
| 16 #include "base/trace_event/memory_dump_manager.h" | 17 #include "base/trace_event/memory_dump_manager.h" |
| 17 #include "base/trace_event/trace_event.h" | 18 #include "base/trace_event/trace_event.h" |
| 18 #include "base/trace_event/trace_event_argument.h" | 19 #include "base/trace_event/trace_event_argument.h" |
| 19 #include "cc/base/container_util.h" | 20 #include "cc/base/container_util.h" |
| 20 #include "cc/base/math_util.h" | 21 #include "cc/base/math_util.h" |
| 21 #include "cc/debug/traced_value.h" | 22 #include "cc/debug/traced_value.h" |
| 22 #include "cc/raster/raster_buffer.h" | 23 #include "cc/raster/raster_buffer.h" |
| 23 #include "cc/resources/platform_color.h" | 24 #include "cc/resources/platform_color.h" |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 gfx::GetGpuMemoryBufferGUIDForTracing(tracing_process_id, buffer_id); | 172 gfx::GetGpuMemoryBufferGUIDForTracing(tracing_process_id, buffer_id); |
| 172 pmd->CreateSharedGlobalAllocatorDump(shared_buffer_guid); | 173 pmd->CreateSharedGlobalAllocatorDump(shared_buffer_guid); |
| 173 | 174 |
| 174 // By creating an edge with a higher |importance| (w.r.t. browser-side dumps) | 175 // By creating an edge with a higher |importance| (w.r.t. browser-side dumps) |
| 175 // the tracing UI will account the effective size of the buffer to the child. | 176 // the tracing UI will account the effective size of the buffer to the child. |
| 176 const int kImportance = 2; | 177 const int kImportance = 2; |
| 177 pmd->AddOwnershipEdge(buffer_dump->guid(), shared_buffer_guid, kImportance); | 178 pmd->AddOwnershipEdge(buffer_dump->guid(), shared_buffer_guid, kImportance); |
| 178 } | 179 } |
| 179 | 180 |
| 180 // static | 181 // static |
| 181 scoped_ptr<TileTaskWorkerPool> OneCopyTileTaskWorkerPool::Create( | 182 std::unique_ptr<TileTaskWorkerPool> OneCopyTileTaskWorkerPool::Create( |
| 182 base::SequencedTaskRunner* task_runner, | 183 base::SequencedTaskRunner* task_runner, |
| 183 TaskGraphRunner* task_graph_runner, | 184 TaskGraphRunner* task_graph_runner, |
| 184 ContextProvider* context_provider, | 185 ContextProvider* context_provider, |
| 185 ResourceProvider* resource_provider, | 186 ResourceProvider* resource_provider, |
| 186 int max_copy_texture_chromium_size, | 187 int max_copy_texture_chromium_size, |
| 187 bool use_partial_raster, | 188 bool use_partial_raster, |
| 188 int max_staging_buffer_usage_in_bytes, | 189 int max_staging_buffer_usage_in_bytes, |
| 189 ResourceFormat preferred_tile_format) { | 190 ResourceFormat preferred_tile_format) { |
| 190 return make_scoped_ptr<TileTaskWorkerPool>(new OneCopyTileTaskWorkerPool( | 191 return base::WrapUnique<TileTaskWorkerPool>(new OneCopyTileTaskWorkerPool( |
| 191 task_runner, task_graph_runner, resource_provider, | 192 task_runner, task_graph_runner, resource_provider, |
| 192 max_copy_texture_chromium_size, use_partial_raster, | 193 max_copy_texture_chromium_size, use_partial_raster, |
| 193 max_staging_buffer_usage_in_bytes, preferred_tile_format)); | 194 max_staging_buffer_usage_in_bytes, preferred_tile_format)); |
| 194 } | 195 } |
| 195 | 196 |
| 196 OneCopyTileTaskWorkerPool::OneCopyTileTaskWorkerPool( | 197 OneCopyTileTaskWorkerPool::OneCopyTileTaskWorkerPool( |
| 197 base::SequencedTaskRunner* task_runner, | 198 base::SequencedTaskRunner* task_runner, |
| 198 TaskGraphRunner* task_graph_runner, | 199 TaskGraphRunner* task_graph_runner, |
| 199 ResourceProvider* resource_provider, | 200 ResourceProvider* resource_provider, |
| 200 int max_copy_texture_chromium_size, | 201 int max_copy_texture_chromium_size, |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 } | 294 } |
| 294 | 295 |
| 295 return resource_provider_->best_texture_format(); | 296 return resource_provider_->best_texture_format(); |
| 296 } | 297 } |
| 297 | 298 |
| 298 bool OneCopyTileTaskWorkerPool::GetResourceRequiresSwizzle( | 299 bool OneCopyTileTaskWorkerPool::GetResourceRequiresSwizzle( |
| 299 bool must_support_alpha) const { | 300 bool must_support_alpha) const { |
| 300 return ResourceFormatRequiresSwizzle(GetResourceFormat(must_support_alpha)); | 301 return ResourceFormatRequiresSwizzle(GetResourceFormat(must_support_alpha)); |
| 301 } | 302 } |
| 302 | 303 |
| 303 scoped_ptr<RasterBuffer> OneCopyTileTaskWorkerPool::AcquireBufferForRaster( | 304 std::unique_ptr<RasterBuffer> OneCopyTileTaskWorkerPool::AcquireBufferForRaster( |
| 304 const Resource* resource, | 305 const Resource* resource, |
| 305 uint64_t resource_content_id, | 306 uint64_t resource_content_id, |
| 306 uint64_t previous_content_id) { | 307 uint64_t previous_content_id) { |
| 307 // TODO(danakj): If resource_content_id != 0, we only need to copy/upload | 308 // TODO(danakj): If resource_content_id != 0, we only need to copy/upload |
| 308 // the dirty rect. | 309 // the dirty rect. |
| 309 return make_scoped_ptr<RasterBuffer>( | 310 return base::WrapUnique<RasterBuffer>( |
| 310 new RasterBufferImpl(this, resource_provider_, resource->format(), | 311 new RasterBufferImpl(this, resource_provider_, resource->format(), |
| 311 resource, previous_content_id)); | 312 resource, previous_content_id)); |
| 312 } | 313 } |
| 313 | 314 |
| 314 void OneCopyTileTaskWorkerPool::ReleaseBufferForRaster( | 315 void OneCopyTileTaskWorkerPool::ReleaseBufferForRaster( |
| 315 scoped_ptr<RasterBuffer> buffer) { | 316 std::unique_ptr<RasterBuffer> buffer) { |
| 316 // Nothing to do here. RasterBufferImpl destructor cleans up after itself. | 317 // Nothing to do here. RasterBufferImpl destructor cleans up after itself. |
| 317 } | 318 } |
| 318 | 319 |
| 319 void OneCopyTileTaskWorkerPool::PlaybackAndCopyOnWorkerThread( | 320 void OneCopyTileTaskWorkerPool::PlaybackAndCopyOnWorkerThread( |
| 320 const Resource* resource, | 321 const Resource* resource, |
| 321 ResourceProvider::ScopedWriteLockGL* resource_lock, | 322 ResourceProvider::ScopedWriteLockGL* resource_lock, |
| 322 const RasterSource* raster_source, | 323 const RasterSource* raster_source, |
| 323 const gfx::Rect& raster_full_rect, | 324 const gfx::Rect& raster_full_rect, |
| 324 const gfx::Rect& raster_dirty_rect, | 325 const gfx::Rect& raster_dirty_rect, |
| 325 float scale, | 326 float scale, |
| 326 const RasterSource::PlaybackSettings& playback_settings, | 327 const RasterSource::PlaybackSettings& playback_settings, |
| 327 uint64_t previous_content_id, | 328 uint64_t previous_content_id, |
| 328 uint64_t new_content_id) { | 329 uint64_t new_content_id) { |
| 329 base::AutoLock lock(lock_); | 330 base::AutoLock lock(lock_); |
| 330 | 331 |
| 331 scoped_ptr<StagingBuffer> staging_buffer = | 332 std::unique_ptr<StagingBuffer> staging_buffer = |
| 332 AcquireStagingBuffer(resource, previous_content_id); | 333 AcquireStagingBuffer(resource, previous_content_id); |
| 333 DCHECK(staging_buffer); | 334 DCHECK(staging_buffer); |
| 334 | 335 |
| 335 { | 336 { |
| 336 base::AutoUnlock unlock(lock_); | 337 base::AutoUnlock unlock(lock_); |
| 337 | 338 |
| 338 // Allocate GpuMemoryBuffer if necessary. If using partial raster, we | 339 // Allocate GpuMemoryBuffer if necessary. If using partial raster, we |
| 339 // must allocate a buffer with BufferUsage CPU_READ_WRITE_PERSISTENT. | 340 // must allocate a buffer with BufferUsage CPU_READ_WRITE_PERSISTENT. |
| 340 if (!staging_buffer->gpu_memory_buffer) { | 341 if (!staging_buffer->gpu_memory_buffer) { |
| 341 staging_buffer->gpu_memory_buffer = | 342 staging_buffer->gpu_memory_buffer = |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 } | 495 } |
| 495 | 496 |
| 496 bool OneCopyTileTaskWorkerPool::OnMemoryDump( | 497 bool OneCopyTileTaskWorkerPool::OnMemoryDump( |
| 497 const base::trace_event::MemoryDumpArgs& args, | 498 const base::trace_event::MemoryDumpArgs& args, |
| 498 base::trace_event::ProcessMemoryDump* pmd) { | 499 base::trace_event::ProcessMemoryDump* pmd) { |
| 499 base::AutoLock lock(lock_); | 500 base::AutoLock lock(lock_); |
| 500 | 501 |
| 501 for (const auto* buffer : buffers_) { | 502 for (const auto* buffer : buffers_) { |
| 502 auto in_free_buffers = | 503 auto in_free_buffers = |
| 503 std::find_if(free_buffers_.begin(), free_buffers_.end(), | 504 std::find_if(free_buffers_.begin(), free_buffers_.end(), |
| 504 [buffer](const scoped_ptr<StagingBuffer>& b) { | 505 [buffer](const std::unique_ptr<StagingBuffer>& b) { |
| 505 return b.get() == buffer; | 506 return b.get() == buffer; |
| 506 }); | 507 }); |
| 507 buffer->OnMemoryDump(pmd, buffer->format, | 508 buffer->OnMemoryDump(pmd, buffer->format, |
| 508 in_free_buffers != free_buffers_.end()); | 509 in_free_buffers != free_buffers_.end()); |
| 509 } | 510 } |
| 510 | 511 |
| 511 return true; | 512 return true; |
| 512 } | 513 } |
| 513 | 514 |
| 514 void OneCopyTileTaskWorkerPool::AddStagingBuffer( | 515 void OneCopyTileTaskWorkerPool::AddStagingBuffer( |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 void OneCopyTileTaskWorkerPool::MarkStagingBufferAsBusy( | 548 void OneCopyTileTaskWorkerPool::MarkStagingBufferAsBusy( |
| 548 const StagingBuffer* staging_buffer) { | 549 const StagingBuffer* staging_buffer) { |
| 549 lock_.AssertAcquired(); | 550 lock_.AssertAcquired(); |
| 550 | 551 |
| 551 int buffer_usage_in_bytes = ResourceUtil::UncheckedSizeInBytes<int>( | 552 int buffer_usage_in_bytes = ResourceUtil::UncheckedSizeInBytes<int>( |
| 552 staging_buffer->size, staging_buffer->format); | 553 staging_buffer->size, staging_buffer->format); |
| 553 DCHECK_GE(free_staging_buffer_usage_in_bytes_, buffer_usage_in_bytes); | 554 DCHECK_GE(free_staging_buffer_usage_in_bytes_, buffer_usage_in_bytes); |
| 554 free_staging_buffer_usage_in_bytes_ -= buffer_usage_in_bytes; | 555 free_staging_buffer_usage_in_bytes_ -= buffer_usage_in_bytes; |
| 555 } | 556 } |
| 556 | 557 |
| 557 scoped_ptr<OneCopyTileTaskWorkerPool::StagingBuffer> | 558 std::unique_ptr<OneCopyTileTaskWorkerPool::StagingBuffer> |
| 558 OneCopyTileTaskWorkerPool::AcquireStagingBuffer(const Resource* resource, | 559 OneCopyTileTaskWorkerPool::AcquireStagingBuffer(const Resource* resource, |
| 559 uint64_t previous_content_id) { | 560 uint64_t previous_content_id) { |
| 560 lock_.AssertAcquired(); | 561 lock_.AssertAcquired(); |
| 561 | 562 |
| 562 scoped_ptr<StagingBuffer> staging_buffer; | 563 std::unique_ptr<StagingBuffer> staging_buffer; |
| 563 | 564 |
| 564 ContextProvider* context_provider = | 565 ContextProvider* context_provider = |
| 565 resource_provider_->output_surface()->worker_context_provider(); | 566 resource_provider_->output_surface()->worker_context_provider(); |
| 566 DCHECK(context_provider); | 567 DCHECK(context_provider); |
| 567 | 568 |
| 568 ContextProvider::ScopedContextLock scoped_context(context_provider); | 569 ContextProvider::ScopedContextLock scoped_context(context_provider); |
| 569 | 570 |
| 570 gpu::gles2::GLES2Interface* gl = scoped_context.ContextGL(); | 571 gpu::gles2::GLES2Interface* gl = scoped_context.ContextGL(); |
| 571 DCHECK(gl); | 572 DCHECK(gl); |
| 572 | 573 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 601 free_buffers_.push_back(PopFront(&busy_buffers_)); | 602 free_buffers_.push_back(PopFront(&busy_buffers_)); |
| 602 } | 603 } |
| 603 } | 604 } |
| 604 } | 605 } |
| 605 | 606 |
| 606 // Find a staging buffer that allows us to perform partial raster when | 607 // Find a staging buffer that allows us to perform partial raster when |
| 607 // using persistent GpuMemoryBuffers. | 608 // using persistent GpuMemoryBuffers. |
| 608 if (use_partial_raster_ && previous_content_id) { | 609 if (use_partial_raster_ && previous_content_id) { |
| 609 StagingBufferDeque::iterator it = std::find_if( | 610 StagingBufferDeque::iterator it = std::find_if( |
| 610 free_buffers_.begin(), free_buffers_.end(), | 611 free_buffers_.begin(), free_buffers_.end(), |
| 611 [previous_content_id](const scoped_ptr<StagingBuffer>& buffer) { | 612 [previous_content_id](const std::unique_ptr<StagingBuffer>& buffer) { |
| 612 return buffer->content_id == previous_content_id; | 613 return buffer->content_id == previous_content_id; |
| 613 }); | 614 }); |
| 614 if (it != free_buffers_.end()) { | 615 if (it != free_buffers_.end()) { |
| 615 staging_buffer = std::move(*it); | 616 staging_buffer = std::move(*it); |
| 616 free_buffers_.erase(it); | 617 free_buffers_.erase(it); |
| 617 MarkStagingBufferAsBusy(staging_buffer.get()); | 618 MarkStagingBufferAsBusy(staging_buffer.get()); |
| 618 } | 619 } |
| 619 } | 620 } |
| 620 | 621 |
| 621 // Find staging buffer of correct size and format. | 622 // Find staging buffer of correct size and format. |
| 622 if (!staging_buffer) { | 623 if (!staging_buffer) { |
| 623 StagingBufferDeque::iterator it = | 624 StagingBufferDeque::iterator it = |
| 624 std::find_if(free_buffers_.begin(), free_buffers_.end(), | 625 std::find_if(free_buffers_.begin(), free_buffers_.end(), |
| 625 [resource](const scoped_ptr<StagingBuffer>& buffer) { | 626 [resource](const std::unique_ptr<StagingBuffer>& buffer) { |
| 626 return buffer->size == resource->size() && | 627 return buffer->size == resource->size() && |
| 627 buffer->format == resource->format(); | 628 buffer->format == resource->format(); |
| 628 }); | 629 }); |
| 629 if (it != free_buffers_.end()) { | 630 if (it != free_buffers_.end()) { |
| 630 staging_buffer = std::move(*it); | 631 staging_buffer = std::move(*it); |
| 631 free_buffers_.erase(it); | 632 free_buffers_.erase(it); |
| 632 MarkStagingBufferAsBusy(staging_buffer.get()); | 633 MarkStagingBufferAsBusy(staging_buffer.get()); |
| 633 } | 634 } |
| 634 } | 635 } |
| 635 | 636 |
| 636 // Create new staging buffer if necessary. | 637 // Create new staging buffer if necessary. |
| 637 if (!staging_buffer) { | 638 if (!staging_buffer) { |
| 638 staging_buffer = make_scoped_ptr( | 639 staging_buffer = base::WrapUnique( |
| 639 new StagingBuffer(resource->size(), resource->format())); | 640 new StagingBuffer(resource->size(), resource->format())); |
| 640 AddStagingBuffer(staging_buffer.get(), resource->format()); | 641 AddStagingBuffer(staging_buffer.get(), resource->format()); |
| 641 } | 642 } |
| 642 | 643 |
| 643 // Release enough free buffers to stay within the limit. | 644 // Release enough free buffers to stay within the limit. |
| 644 while (staging_buffer_usage_in_bytes_ > max_staging_buffer_usage_in_bytes_) { | 645 while (staging_buffer_usage_in_bytes_ > max_staging_buffer_usage_in_bytes_) { |
| 645 if (free_buffers_.empty()) | 646 if (free_buffers_.empty()) |
| 646 break; | 647 break; |
| 647 | 648 |
| 648 free_buffers_.front()->DestroyGLResources(gl); | 649 free_buffers_.front()->DestroyGLResources(gl); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 738 return; | 739 return; |
| 739 | 740 |
| 740 busy_buffers_.front()->DestroyGLResources(gl); | 741 busy_buffers_.front()->DestroyGLResources(gl); |
| 741 RemoveStagingBuffer(busy_buffers_.front().get()); | 742 RemoveStagingBuffer(busy_buffers_.front().get()); |
| 742 busy_buffers_.pop_front(); | 743 busy_buffers_.pop_front(); |
| 743 } | 744 } |
| 744 } | 745 } |
| 745 } | 746 } |
| 746 | 747 |
| 747 } // namespace cc | 748 } // namespace cc |
| OLD | NEW |