| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/staging_buffer_pool.h" | 5 #include "cc/raster/staging_buffer_pool.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 base::trace_event::MemoryAllocatorDumpGuid shared_buffer_guid = | 113 base::trace_event::MemoryAllocatorDumpGuid shared_buffer_guid = |
| 114 gfx::GetGpuMemoryBufferGUIDForTracing(tracing_process_id, buffer_id); | 114 gfx::GetGpuMemoryBufferGUIDForTracing(tracing_process_id, buffer_id); |
| 115 pmd->CreateSharedGlobalAllocatorDump(shared_buffer_guid); | 115 pmd->CreateSharedGlobalAllocatorDump(shared_buffer_guid); |
| 116 | 116 |
| 117 // By creating an edge with a higher |importance| (w.r.t. browser-side dumps) | 117 // By creating an edge with a higher |importance| (w.r.t. browser-side dumps) |
| 118 // the tracing UI will account the effective size of the buffer to the child. | 118 // the tracing UI will account the effective size of the buffer to the child. |
| 119 const int kImportance = 2; | 119 const int kImportance = 2; |
| 120 pmd->AddOwnershipEdge(buffer_dump->guid(), shared_buffer_guid, kImportance); | 120 pmd->AddOwnershipEdge(buffer_dump->guid(), shared_buffer_guid, kImportance); |
| 121 } | 121 } |
| 122 | 122 |
| 123 // static | |
| 124 std::unique_ptr<StagingBufferPool> StagingBufferPool::Create( | |
| 125 base::SequencedTaskRunner* task_runner, | |
| 126 ResourceProvider* resource_provider, | |
| 127 bool use_partial_raster, | |
| 128 int max_staging_buffer_usage_in_bytes) { | |
| 129 return base::WrapUnique( | |
| 130 new StagingBufferPool(task_runner, resource_provider, use_partial_raster, | |
| 131 max_staging_buffer_usage_in_bytes)); | |
| 132 } | |
| 133 | |
| 134 StagingBufferPool::StagingBufferPool(base::SequencedTaskRunner* task_runner, | 123 StagingBufferPool::StagingBufferPool(base::SequencedTaskRunner* task_runner, |
| 124 ContextProvider* worker_context_provider, |
| 135 ResourceProvider* resource_provider, | 125 ResourceProvider* resource_provider, |
| 136 bool use_partial_raster, | 126 bool use_partial_raster, |
| 137 int max_staging_buffer_usage_in_bytes) | 127 int max_staging_buffer_usage_in_bytes) |
| 138 : task_runner_(task_runner), | 128 : task_runner_(task_runner), |
| 129 worker_context_provider_(worker_context_provider), |
| 139 resource_provider_(resource_provider), | 130 resource_provider_(resource_provider), |
| 140 use_partial_raster_(use_partial_raster), | 131 use_partial_raster_(use_partial_raster), |
| 141 max_staging_buffer_usage_in_bytes_(max_staging_buffer_usage_in_bytes), | 132 max_staging_buffer_usage_in_bytes_(max_staging_buffer_usage_in_bytes), |
| 142 staging_buffer_usage_in_bytes_(0), | 133 staging_buffer_usage_in_bytes_(0), |
| 143 free_staging_buffer_usage_in_bytes_(0), | 134 free_staging_buffer_usage_in_bytes_(0), |
| 144 staging_buffer_expiration_delay_( | 135 staging_buffer_expiration_delay_( |
| 145 base::TimeDelta::FromMilliseconds(kStagingBufferExpirationDelayMs)), | 136 base::TimeDelta::FromMilliseconds(kStagingBufferExpirationDelayMs)), |
| 146 reduce_memory_usage_pending_(false), | 137 reduce_memory_usage_pending_(false), |
| 147 weak_ptr_factory_(this) { | 138 weak_ptr_factory_(this) { |
| 139 DCHECK(worker_context_provider_); |
| 148 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( | 140 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( |
| 149 this, "cc::StagingBufferPool", base::ThreadTaskRunnerHandle::Get()); | 141 this, "cc::StagingBufferPool", base::ThreadTaskRunnerHandle::Get()); |
| 150 reduce_memory_usage_callback_ = base::Bind( | 142 reduce_memory_usage_callback_ = base::Bind( |
| 151 &StagingBufferPool::ReduceMemoryUsage, weak_ptr_factory_.GetWeakPtr()); | 143 &StagingBufferPool::ReduceMemoryUsage, weak_ptr_factory_.GetWeakPtr()); |
| 152 } | 144 } |
| 153 | 145 |
| 154 StagingBufferPool::~StagingBufferPool() { | 146 StagingBufferPool::~StagingBufferPool() { |
| 155 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( | 147 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( |
| 156 this); | 148 this); |
| 157 } | 149 } |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 free_staging_buffer_usage_in_bytes_ -= buffer_usage_in_bytes; | 228 free_staging_buffer_usage_in_bytes_ -= buffer_usage_in_bytes; |
| 237 } | 229 } |
| 238 | 230 |
| 239 std::unique_ptr<StagingBuffer> StagingBufferPool::AcquireStagingBuffer( | 231 std::unique_ptr<StagingBuffer> StagingBufferPool::AcquireStagingBuffer( |
| 240 const Resource* resource, | 232 const Resource* resource, |
| 241 uint64_t previous_content_id) { | 233 uint64_t previous_content_id) { |
| 242 base::AutoLock lock(lock_); | 234 base::AutoLock lock(lock_); |
| 243 | 235 |
| 244 std::unique_ptr<StagingBuffer> staging_buffer; | 236 std::unique_ptr<StagingBuffer> staging_buffer; |
| 245 | 237 |
| 246 ContextProvider* context_provider = | 238 ContextProvider::ScopedContextLock scoped_context(worker_context_provider_); |
| 247 resource_provider_->output_surface()->worker_context_provider(); | |
| 248 DCHECK(context_provider); | |
| 249 | |
| 250 ContextProvider::ScopedContextLock scoped_context(context_provider); | |
| 251 | 239 |
| 252 gpu::gles2::GLES2Interface* gl = scoped_context.ContextGL(); | 240 gpu::gles2::GLES2Interface* gl = scoped_context.ContextGL(); |
| 253 DCHECK(gl); | 241 DCHECK(gl); |
| 254 | 242 |
| 255 // Check if any busy buffers have become available. | 243 // Check if any busy buffers have become available. |
| 256 if (resource_provider_->use_sync_query()) { | 244 if (resource_provider_->use_sync_query()) { |
| 257 while (!busy_buffers_.empty()) { | 245 while (!busy_buffers_.empty()) { |
| 258 if (!CheckForQueryResult(gl, busy_buffers_.front()->query_id)) | 246 if (!CheckForQueryResult(gl, busy_buffers_.front()->query_id)) |
| 259 break; | 247 break; |
| 260 | 248 |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 // buffer should be released. | 373 // buffer should be released. |
| 386 base::TimeTicks reduce_memory_usage_time = | 374 base::TimeTicks reduce_memory_usage_time = |
| 387 GetUsageTimeForLRUBuffer() + staging_buffer_expiration_delay_; | 375 GetUsageTimeForLRUBuffer() + staging_buffer_expiration_delay_; |
| 388 task_runner_->PostDelayedTask(FROM_HERE, reduce_memory_usage_callback_, | 376 task_runner_->PostDelayedTask(FROM_HERE, reduce_memory_usage_callback_, |
| 389 reduce_memory_usage_time - current_time); | 377 reduce_memory_usage_time - current_time); |
| 390 } | 378 } |
| 391 | 379 |
| 392 void StagingBufferPool::ReleaseBuffersNotUsedSince(base::TimeTicks time) { | 380 void StagingBufferPool::ReleaseBuffersNotUsedSince(base::TimeTicks time) { |
| 393 lock_.AssertAcquired(); | 381 lock_.AssertAcquired(); |
| 394 | 382 |
| 395 ContextProvider* context_provider = | |
| 396 resource_provider_->output_surface()->worker_context_provider(); | |
| 397 DCHECK(context_provider); | |
| 398 | |
| 399 { | 383 { |
| 400 ContextProvider::ScopedContextLock scoped_context(context_provider); | 384 ContextProvider::ScopedContextLock scoped_context(worker_context_provider_); |
| 401 | 385 |
| 402 gpu::gles2::GLES2Interface* gl = scoped_context.ContextGL(); | 386 gpu::gles2::GLES2Interface* gl = scoped_context.ContextGL(); |
| 403 DCHECK(gl); | 387 DCHECK(gl); |
| 404 | 388 |
| 405 // Note: Front buffer is guaranteed to be LRU so we can stop releasing | 389 // Note: Front buffer is guaranteed to be LRU so we can stop releasing |
| 406 // buffers as soon as we find a buffer that has been used since |time|. | 390 // buffers as soon as we find a buffer that has been used since |time|. |
| 407 while (!free_buffers_.empty()) { | 391 while (!free_buffers_.empty()) { |
| 408 if (free_buffers_.front()->last_usage > time) | 392 if (free_buffers_.front()->last_usage > time) |
| 409 return; | 393 return; |
| 410 | 394 |
| 411 free_buffers_.front()->DestroyGLResources(gl); | 395 free_buffers_.front()->DestroyGLResources(gl); |
| 412 MarkStagingBufferAsBusy(free_buffers_.front().get()); | 396 MarkStagingBufferAsBusy(free_buffers_.front().get()); |
| 413 RemoveStagingBuffer(free_buffers_.front().get()); | 397 RemoveStagingBuffer(free_buffers_.front().get()); |
| 414 free_buffers_.pop_front(); | 398 free_buffers_.pop_front(); |
| 415 } | 399 } |
| 416 | 400 |
| 417 while (!busy_buffers_.empty()) { | 401 while (!busy_buffers_.empty()) { |
| 418 if (busy_buffers_.front()->last_usage > time) | 402 if (busy_buffers_.front()->last_usage > time) |
| 419 return; | 403 return; |
| 420 | 404 |
| 421 busy_buffers_.front()->DestroyGLResources(gl); | 405 busy_buffers_.front()->DestroyGLResources(gl); |
| 422 RemoveStagingBuffer(busy_buffers_.front().get()); | 406 RemoveStagingBuffer(busy_buffers_.front().get()); |
| 423 busy_buffers_.pop_front(); | 407 busy_buffers_.pop_front(); |
| 424 } | 408 } |
| 425 } | 409 } |
| 426 } | 410 } |
| 427 | 411 |
| 428 } // namespace cc | 412 } // namespace cc |
| OLD | NEW |