| 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/memory_coordinator_client_registry.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 12 #include "base/threading/thread_task_runner_handle.h" | 12 #include "base/threading/thread_task_runner_handle.h" |
| 13 #include "base/trace_event/memory_dump_manager.h" | 13 #include "base/trace_event/memory_dump_manager.h" |
| 14 #include "cc/base/container_util.h" | 14 #include "cc/base/container_util.h" |
| 15 #include "cc/debug/traced_value.h" | 15 #include "cc/debug/traced_value.h" |
| 16 #include "cc/resources/scoped_resource.h" | 16 #include "cc/resources/scoped_resource.h" |
| 17 #include "gpu/command_buffer/client/gles2_interface.h" | 17 #include "gpu/command_buffer/client/gles2_interface.h" |
| 18 #include "ui/gfx/gpu_memory_buffer_tracing.h" | 18 #include "ui/gfx/gpu_memory_buffer_tracing.h" |
| 19 | 19 |
| 20 using base::trace_event::MemoryAllocatorDump; |
| 21 using base::trace_event::MemoryAllocatorDumpGuid; |
| 22 using base::trace_event::MemoryDumpLevelOfDetail; |
| 23 |
| 20 namespace cc { | 24 namespace cc { |
| 21 namespace { | 25 namespace { |
| 22 | 26 |
| 23 // Delay between checking for query result to be available. | 27 // Delay between checking for query result to be available. |
| 24 const int kCheckForQueryResultAvailableTickRateMs = 1; | 28 const int kCheckForQueryResultAvailableTickRateMs = 1; |
| 25 | 29 |
| 26 // Number of attempts to allow before we perform a check that will wait for | 30 // Number of attempts to allow before we perform a check that will wait for |
| 27 // query to complete. | 31 // query to complete. |
| 28 const int kMaxCheckForQueryResultAvailableAttempts = 256; | 32 const int kMaxCheckForQueryResultAvailableAttempts = 256; |
| 29 | 33 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 | 93 |
| 90 void StagingBuffer::OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd, | 94 void StagingBuffer::OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd, |
| 91 ResourceFormat format, | 95 ResourceFormat format, |
| 92 bool in_free_list) const { | 96 bool in_free_list) const { |
| 93 if (!gpu_memory_buffer) | 97 if (!gpu_memory_buffer) |
| 94 return; | 98 return; |
| 95 | 99 |
| 96 gfx::GpuMemoryBufferId buffer_id = gpu_memory_buffer->GetId(); | 100 gfx::GpuMemoryBufferId buffer_id = gpu_memory_buffer->GetId(); |
| 97 std::string buffer_dump_name = | 101 std::string buffer_dump_name = |
| 98 base::StringPrintf("cc/one_copy/staging_memory/buffer_%d", buffer_id.id); | 102 base::StringPrintf("cc/one_copy/staging_memory/buffer_%d", buffer_id.id); |
| 99 base::trace_event::MemoryAllocatorDump* buffer_dump = | 103 MemoryAllocatorDump* buffer_dump = pmd->CreateAllocatorDump(buffer_dump_name); |
| 100 pmd->CreateAllocatorDump(buffer_dump_name); | |
| 101 | 104 |
| 102 uint64_t buffer_size_in_bytes = | 105 uint64_t buffer_size_in_bytes = |
| 103 ResourceUtil::UncheckedSizeInBytes<uint64_t>(size, format); | 106 ResourceUtil::UncheckedSizeInBytes<uint64_t>(size, format); |
| 104 buffer_dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, | 107 buffer_dump->AddScalar(MemoryAllocatorDump::kNameSize, |
| 105 base::trace_event::MemoryAllocatorDump::kUnitsBytes, | 108 MemoryAllocatorDump::kUnitsBytes, |
| 106 buffer_size_in_bytes); | 109 buffer_size_in_bytes); |
| 107 buffer_dump->AddScalar("free_size", | 110 buffer_dump->AddScalar("free_size", MemoryAllocatorDump::kUnitsBytes, |
| 108 base::trace_event::MemoryAllocatorDump::kUnitsBytes, | |
| 109 in_free_list ? buffer_size_in_bytes : 0); | 111 in_free_list ? buffer_size_in_bytes : 0); |
| 110 | 112 |
| 111 // Emit an ownership edge towards a global allocator dump node. | 113 // Emit an ownership edge towards a global allocator dump node. |
| 112 const uint64_t tracing_process_id = | 114 const uint64_t tracing_process_id = |
| 113 base::trace_event::MemoryDumpManager::GetInstance() | 115 base::trace_event::MemoryDumpManager::GetInstance() |
| 114 ->GetTracingProcessId(); | 116 ->GetTracingProcessId(); |
| 115 base::trace_event::MemoryAllocatorDumpGuid shared_buffer_guid = | 117 MemoryAllocatorDumpGuid shared_buffer_guid = |
| 116 gfx::GetGpuMemoryBufferGUIDForTracing(tracing_process_id, buffer_id); | 118 gfx::GetGpuMemoryBufferGUIDForTracing(tracing_process_id, buffer_id); |
| 117 pmd->CreateSharedGlobalAllocatorDump(shared_buffer_guid); | 119 pmd->CreateSharedGlobalAllocatorDump(shared_buffer_guid); |
| 118 | 120 |
| 119 // By creating an edge with a higher |importance| (w.r.t. browser-side dumps) | 121 // By creating an edge with a higher |importance| (w.r.t. browser-side dumps) |
| 120 // the tracing UI will account the effective size of the buffer to the child. | 122 // the tracing UI will account the effective size of the buffer to the child. |
| 121 const int kImportance = 2; | 123 const int kImportance = 2; |
| 122 pmd->AddOwnershipEdge(buffer_dump->guid(), shared_buffer_guid, kImportance); | 124 pmd->AddOwnershipEdge(buffer_dump->guid(), shared_buffer_guid, kImportance); |
| 123 } | 125 } |
| 124 | 126 |
| 125 StagingBufferPool::StagingBufferPool(base::SequencedTaskRunner* task_runner, | 127 StagingBufferPool::StagingBufferPool(base::SequencedTaskRunner* task_runner, |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 busy_buffers_.push_back(std::move(staging_buffer)); | 175 busy_buffers_.push_back(std::move(staging_buffer)); |
| 174 | 176 |
| 175 ScheduleReduceMemoryUsage(); | 177 ScheduleReduceMemoryUsage(); |
| 176 } | 178 } |
| 177 | 179 |
| 178 bool StagingBufferPool::OnMemoryDump( | 180 bool StagingBufferPool::OnMemoryDump( |
| 179 const base::trace_event::MemoryDumpArgs& args, | 181 const base::trace_event::MemoryDumpArgs& args, |
| 180 base::trace_event::ProcessMemoryDump* pmd) { | 182 base::trace_event::ProcessMemoryDump* pmd) { |
| 181 base::AutoLock lock(lock_); | 183 base::AutoLock lock(lock_); |
| 182 | 184 |
| 183 for (const auto* buffer : buffers_) { | 185 if (args.level_of_detail == MemoryDumpLevelOfDetail::BACKGROUND) { |
| 184 auto in_free_buffers = | 186 std::string dump_name("cc/one_copy/staging_memory"); |
| 185 std::find_if(free_buffers_.begin(), free_buffers_.end(), | 187 MemoryAllocatorDump* dump = pmd->CreateAllocatorDump(dump_name); |
| 186 [buffer](const std::unique_ptr<StagingBuffer>& b) { | 188 dump->AddScalar(MemoryAllocatorDump::kNameSize, |
| 187 return b.get() == buffer; | 189 MemoryAllocatorDump::kUnitsBytes, |
| 188 }); | 190 staging_buffer_usage_in_bytes_); |
| 189 buffer->OnMemoryDump(pmd, buffer->format, | 191 } else { |
| 190 in_free_buffers != free_buffers_.end()); | 192 for (const auto* buffer : buffers_) { |
| 193 auto in_free_buffers = |
| 194 std::find_if(free_buffers_.begin(), free_buffers_.end(), |
| 195 [buffer](const std::unique_ptr<StagingBuffer>& b) { |
| 196 return b.get() == buffer; |
| 197 }); |
| 198 buffer->OnMemoryDump(pmd, buffer->format, |
| 199 in_free_buffers != free_buffers_.end()); |
| 200 } |
| 191 } | 201 } |
| 192 | |
| 193 return true; | 202 return true; |
| 194 } | 203 } |
| 195 | 204 |
| 196 void StagingBufferPool::AddStagingBuffer(const StagingBuffer* staging_buffer, | 205 void StagingBufferPool::AddStagingBuffer(const StagingBuffer* staging_buffer, |
| 197 ResourceFormat format) { | 206 ResourceFormat format) { |
| 198 lock_.AssertAcquired(); | 207 lock_.AssertAcquired(); |
| 199 | 208 |
| 200 DCHECK(buffers_.find(staging_buffer) == buffers_.end()); | 209 DCHECK(buffers_.find(staging_buffer) == buffers_.end()); |
| 201 buffers_.insert(staging_buffer); | 210 buffers_.insert(staging_buffer); |
| 202 int buffer_usage_in_bytes = | 211 int buffer_usage_in_bytes = |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 // Release all buffers, regardless of how recently they were used. | 438 // Release all buffers, regardless of how recently they were used. |
| 430 ReleaseBuffersNotUsedSince(base::TimeTicks() + base::TimeDelta::Max()); | 439 ReleaseBuffersNotUsedSince(base::TimeTicks() + base::TimeDelta::Max()); |
| 431 break; | 440 break; |
| 432 case base::MemoryState::UNKNOWN: | 441 case base::MemoryState::UNKNOWN: |
| 433 // NOT_REACHED. | 442 // NOT_REACHED. |
| 434 break; | 443 break; |
| 435 } | 444 } |
| 436 } | 445 } |
| 437 | 446 |
| 438 } // namespace cc | 447 } // namespace cc |
| OLD | NEW |