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/memory_coordinator_client_registry.h" | |
| 9 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 10 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 11 #include "base/threading/thread_task_runner_handle.h" | 12 #include "base/threading/thread_task_runner_handle.h" |
| 12 #include "base/trace_event/memory_dump_manager.h" | 13 #include "base/trace_event/memory_dump_manager.h" |
| 13 #include "cc/base/container_util.h" | 14 #include "cc/base/container_util.h" |
| 14 #include "cc/debug/traced_value.h" | 15 #include "cc/debug/traced_value.h" |
| 15 #include "cc/resources/scoped_resource.h" | 16 #include "cc/resources/scoped_resource.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 { |
| (...skipping 115 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 base::MemoryCoordinatorClientRegistry. | |
| 147 base::MemoryCoordinatorClientRegistry::GetInstance()->Register(this); | |
|
bashi
2016/09/15 07:41:01
Could you check base::FeatureList::IsEnabled(featu
tasak
2016/09/15 09:06:06
Hmmm... I would like to ask one question.
Is it po
bashi
2016/09/15 10:00:34
Ah, I wasn't aware of that. Then registering uncon
| |
| 144 } | 148 } |
| 145 | 149 |
| 146 StagingBufferPool::~StagingBufferPool() { | 150 StagingBufferPool::~StagingBufferPool() { |
| 147 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( | 151 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( |
| 148 this); | 152 this); |
| 153 // Unregister this component with memory_coordinator::ClientRegistry. | |
| 154 base::MemoryCoordinatorClientRegistry::GetInstance()->Unregister(this); | |
| 149 } | 155 } |
| 150 | 156 |
| 151 void StagingBufferPool::Shutdown() { | 157 void StagingBufferPool::Shutdown() { |
| 152 base::AutoLock lock(lock_); | 158 base::AutoLock lock(lock_); |
| 153 if (buffers_.empty()) | 159 if (buffers_.empty()) |
| 154 return; | 160 return; |
| 155 | 161 |
| 156 ReleaseBuffersNotUsedSince(base::TimeTicks() + base::TimeDelta::Max()); | 162 ReleaseBuffersNotUsedSince(base::TimeTicks() + base::TimeDelta::Max()); |
| 157 DCHECK_EQ(staging_buffer_usage_in_bytes_, 0); | 163 DCHECK_EQ(staging_buffer_usage_in_bytes_, 0); |
| 158 DCHECK_EQ(free_staging_buffer_usage_in_bytes_, 0); | 164 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) | 408 if (busy_buffers_.front()->last_usage > time) |
| 403 return; | 409 return; |
| 404 | 410 |
| 405 busy_buffers_.front()->DestroyGLResources(gl); | 411 busy_buffers_.front()->DestroyGLResources(gl); |
| 406 RemoveStagingBuffer(busy_buffers_.front().get()); | 412 RemoveStagingBuffer(busy_buffers_.front().get()); |
| 407 busy_buffers_.pop_front(); | 413 busy_buffers_.pop_front(); |
| 408 } | 414 } |
| 409 } | 415 } |
| 410 } | 416 } |
| 411 | 417 |
| 418 void StagingBufferPool::OnMemoryStateChange(base::MemoryState state) { | |
| 419 switch (state) { | |
| 420 case base::MemoryState::NORMAL: | |
| 421 // TODO(tasak): go back to normal state. | |
| 422 break; | |
| 423 case base::MemoryState::THROTTLED: | |
| 424 // TODO(tasak): make the limits of this component's caches smaller to | |
| 425 // save memory usage. | |
| 426 break; | |
| 427 case base::MemoryState::SUSPENDED: | |
| 428 // TODO(tasak): free this component's caches as much as possible before | |
| 429 // suspending renderer. | |
| 430 break; | |
| 431 case base::MemoryState::UNKNOWN: | |
| 432 // NOT_REACHED. | |
| 433 break; | |
| 434 } | |
| 435 } | |
| 436 | |
| 412 } // namespace cc | 437 } // namespace cc |
| OLD | NEW |