Chromium Code Reviews| 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" |
| 11 #include "base/threading/thread_task_runner_handle.h" | 11 #include "base/threading/thread_task_runner_handle.h" |
| 12 #include "base/trace_event/memory_dump_manager.h" | 12 #include "base/trace_event/memory_dump_manager.h" |
| 13 #include "cc/base/container_util.h" | 13 #include "cc/base/container_util.h" |
| 14 #include "cc/debug/traced_value.h" | 14 #include "cc/debug/traced_value.h" |
| 15 #include "cc/resources/scoped_resource.h" | 15 #include "cc/resources/scoped_resource.h" |
| 16 #include "components/memory_coordinator/common/client_registry.h" | |
| 16 #include "gpu/command_buffer/client/gles2_interface.h" | 17 #include "gpu/command_buffer/client/gles2_interface.h" |
| 17 | 18 |
| 18 namespace cc { | 19 namespace cc { |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 // Delay between checking for query result to be available. | 22 // Delay between checking for query result to be available. |
| 22 const int kCheckForQueryResultAvailableTickRateMs = 1; | 23 const int kCheckForQueryResultAvailableTickRateMs = 1; |
| 23 | 24 |
| 24 // Number of attempts to allow before we perform a check that will wait for | 25 // Number of attempts to allow before we perform a check that will wait for |
| 25 // query to complete. | 26 // query to complete. |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 134 free_staging_buffer_usage_in_bytes_(0), | 135 free_staging_buffer_usage_in_bytes_(0), |
| 135 staging_buffer_expiration_delay_( | 136 staging_buffer_expiration_delay_( |
| 136 base::TimeDelta::FromMilliseconds(kStagingBufferExpirationDelayMs)), | 137 base::TimeDelta::FromMilliseconds(kStagingBufferExpirationDelayMs)), |
| 137 reduce_memory_usage_pending_(false), | 138 reduce_memory_usage_pending_(false), |
| 138 weak_ptr_factory_(this) { | 139 weak_ptr_factory_(this) { |
| 139 DCHECK(worker_context_provider_); | 140 DCHECK(worker_context_provider_); |
| 140 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( | 141 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( |
| 141 this, "cc::StagingBufferPool", base::ThreadTaskRunnerHandle::Get()); | 142 this, "cc::StagingBufferPool", base::ThreadTaskRunnerHandle::Get()); |
| 142 reduce_memory_usage_callback_ = base::Bind( | 143 reduce_memory_usage_callback_ = base::Bind( |
| 143 &StagingBufferPool::ReduceMemoryUsage, weak_ptr_factory_.GetWeakPtr()); | 144 &StagingBufferPool::ReduceMemoryUsage, weak_ptr_factory_.GetWeakPtr()); |
| 145 | |
| 146 // Register this component with memory_coordinator::ClientRegistry. | |
| 147 memory_coordinator::ClientRegistry* registry = | |
| 148 memory_coordinator::ClientRegistry::GetInstance(); | |
| 149 if (registry) | |
| 150 registry->RegisterClient(this); | |
| 144 } | 151 } |
| 145 | 152 |
| 146 StagingBufferPool::~StagingBufferPool() { | 153 StagingBufferPool::~StagingBufferPool() { |
| 147 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( | 154 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( |
| 148 this); | 155 this); |
| 156 // Unregister this component with memory_coordinator::ClientRegistry. | |
| 157 memory_coordinator::ClientRegistry* registry = | |
| 158 memory_coordinator::ClientRegistry::GetInstance(); | |
| 159 if (registry) | |
| 160 registry->UnregisterClient(this); | |
| 149 } | 161 } |
| 150 | 162 |
| 151 void StagingBufferPool::Shutdown() { | 163 void StagingBufferPool::Shutdown() { |
| 152 base::AutoLock lock(lock_); | 164 base::AutoLock lock(lock_); |
| 153 if (buffers_.empty()) | 165 if (buffers_.empty()) |
| 154 return; | 166 return; |
| 155 | 167 |
| 156 ReleaseBuffersNotUsedSince(base::TimeTicks() + base::TimeDelta::Max()); | 168 ReleaseBuffersNotUsedSince(base::TimeTicks() + base::TimeDelta::Max()); |
| 157 DCHECK_EQ(staging_buffer_usage_in_bytes_, 0); | 169 DCHECK_EQ(staging_buffer_usage_in_bytes_, 0); |
| 158 DCHECK_EQ(free_staging_buffer_usage_in_bytes_, 0); | 170 DCHECK_EQ(free_staging_buffer_usage_in_bytes_, 0); |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 402 if (busy_buffers_.front()->last_usage > time) | 414 if (busy_buffers_.front()->last_usage > time) |
| 403 return; | 415 return; |
| 404 | 416 |
| 405 busy_buffers_.front()->DestroyGLResources(gl); | 417 busy_buffers_.front()->DestroyGLResources(gl); |
| 406 RemoveStagingBuffer(busy_buffers_.front().get()); | 418 RemoveStagingBuffer(busy_buffers_.front().get()); |
| 407 busy_buffers_.pop_front(); | 419 busy_buffers_.pop_front(); |
| 408 } | 420 } |
| 409 } | 421 } |
| 410 } | 422 } |
| 411 | 423 |
| 424 void StagingBufferPool::OnMemoryStateChange( | |
| 425 memory_coordinator::mojom::MemoryState state) { | |
| 426 switch (state) { | |
| 427 case memory_coordinator::mojom::MemoryState::NORMAL: | |
| 428 // TODO(tasak): go back to normal state. | |
| 429 break; | |
| 430 case memory_coordinator::mojom::MemoryState::THROTTLED: | |
| 431 // TODO(tasak): make the limits of this component's caches smaller to | |
| 432 // save memory usage. | |
| 433 break; | |
| 434 case memory_coordinator::mojom::MemoryState::SUSPENDED: | |
| 435 // TODO(tasak): free this component's caches as much as possible before | |
| 436 // suspending renderer. | |
| 437 break; | |
| 438 default: | |
|
vmpstr
2016/09/06 18:14:47
nit: typically, if we handle all of the cases in t
tasak
2016/09/15 07:08:44
Done.
| |
| 439 // NOT_REACHED. | |
| 440 break; | |
| 441 } | |
| 442 } | |
| 443 | |
| 412 } // namespace cc | 444 } // namespace cc |
| OLD | NEW |