| 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 "content/browser/gpu/browser_gpu_memory_buffer_manager.h" | 5 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" |
| 6 | 6 |
| 7 #include "base/atomic_sequence_num.h" | 7 #include "base/atomic_sequence_num.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 ~AllocateGpuMemoryBufferRequest() {} | 141 ~AllocateGpuMemoryBufferRequest() {} |
| 142 base::WaitableEvent event; | 142 base::WaitableEvent event; |
| 143 gfx::Size size; | 143 gfx::Size size; |
| 144 gfx::GpuMemoryBuffer::Format format; | 144 gfx::GpuMemoryBuffer::Format format; |
| 145 gfx::GpuMemoryBuffer::Usage usage; | 145 gfx::GpuMemoryBuffer::Usage usage; |
| 146 int client_id; | 146 int client_id; |
| 147 int surface_id; | 147 int surface_id; |
| 148 scoped_ptr<gfx::GpuMemoryBuffer> result; | 148 scoped_ptr<gfx::GpuMemoryBuffer> result; |
| 149 }; | 149 }; |
| 150 | 150 |
| 151 BrowserGpuMemoryBufferManager::BrowserGpuMemoryBufferManager(int gpu_client_id) | 151 BrowserGpuMemoryBufferManager::BrowserGpuMemoryBufferManager( |
| 152 int gpu_client_id, |
| 153 uint64_t gpu_client_tracing_id) |
| 152 : factory_type_(GetGpuMemoryBufferFactoryType()), | 154 : factory_type_(GetGpuMemoryBufferFactoryType()), |
| 153 supported_configurations_( | 155 supported_configurations_( |
| 154 GetSupportedGpuMemoryBufferConfigurations(factory_type_)), | 156 GetSupportedGpuMemoryBufferConfigurations(factory_type_)), |
| 155 gpu_client_id_(gpu_client_id), | 157 gpu_client_id_(gpu_client_id), |
| 158 gpu_client_tracing_id_(gpu_client_tracing_id), |
| 156 gpu_host_id_(0) { | 159 gpu_host_id_(0) { |
| 157 DCHECK(!g_gpu_memory_buffer_manager); | 160 DCHECK(!g_gpu_memory_buffer_manager); |
| 158 g_gpu_memory_buffer_manager = this; | 161 g_gpu_memory_buffer_manager = this; |
| 159 } | 162 } |
| 160 | 163 |
| 161 BrowserGpuMemoryBufferManager::~BrowserGpuMemoryBufferManager() { | 164 BrowserGpuMemoryBufferManager::~BrowserGpuMemoryBufferManager() { |
| 162 g_gpu_memory_buffer_manager = nullptr; | 165 g_gpu_memory_buffer_manager = nullptr; |
| 163 } | 166 } |
| 164 | 167 |
| 165 // static | 168 // static |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 DCHECK(valid_size); | 290 DCHECK(valid_size); |
| 288 | 291 |
| 289 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, | 292 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, |
| 290 base::trace_event::MemoryAllocatorDump::kUnitsBytes, | 293 base::trace_event::MemoryAllocatorDump::kUnitsBytes, |
| 291 buffer_size_in_bytes); | 294 buffer_size_in_bytes); |
| 292 | 295 |
| 293 // Create the cross-process ownership edge. If the client creates a | 296 // Create the cross-process ownership edge. If the client creates a |
| 294 // corresponding dump for the same buffer, this will avoid to | 297 // corresponding dump for the same buffer, this will avoid to |
| 295 // double-count them in tracing. If, instead, no other process will emit a | 298 // double-count them in tracing. If, instead, no other process will emit a |
| 296 // dump with the same guid, the segment will be accounted to the browser. | 299 // dump with the same guid, the segment will be accounted to the browser. |
| 297 const uint64 client_tracing_process_id = | 300 uint64 client_tracing_process_id = ClientIdToTracingProcessId(client_id); |
| 298 ChildProcessHostImpl::ChildProcessUniqueIdToTracingProcessId( | 301 |
| 299 client_id); | |
| 300 base::trace_event::MemoryAllocatorDumpGuid shared_buffer_guid = | 302 base::trace_event::MemoryAllocatorDumpGuid shared_buffer_guid = |
| 301 gfx::GetGpuMemoryBufferGUIDForTracing(client_tracing_process_id, | 303 gfx::GetGpuMemoryBufferGUIDForTracing(client_tracing_process_id, |
| 302 buffer_id); | 304 buffer_id); |
| 303 pmd->CreateSharedGlobalAllocatorDump(shared_buffer_guid); | 305 pmd->CreateSharedGlobalAllocatorDump(shared_buffer_guid); |
| 304 pmd->AddOwnershipEdge(dump->guid(), shared_buffer_guid); | 306 pmd->AddOwnershipEdge(dump->guid(), shared_buffer_guid); |
| 305 } | 307 } |
| 306 } | 308 } |
| 307 | 309 |
| 308 return true; | 310 return true; |
| 309 } | 311 } |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 584 return; | 586 return; |
| 585 } | 587 } |
| 586 | 588 |
| 587 GpuProcessHost* host = GpuProcessHost::FromID(buffer_it->second.gpu_host_id); | 589 GpuProcessHost* host = GpuProcessHost::FromID(buffer_it->second.gpu_host_id); |
| 588 if (host) | 590 if (host) |
| 589 host->DestroyGpuMemoryBuffer(id, client_id, sync_point); | 591 host->DestroyGpuMemoryBuffer(id, client_id, sync_point); |
| 590 | 592 |
| 591 buffers.erase(buffer_it); | 593 buffers.erase(buffer_it); |
| 592 } | 594 } |
| 593 | 595 |
| 596 uint64_t BrowserGpuMemoryBufferManager::ClientIdToTracingProcessId( |
| 597 int client_id) const { |
| 598 if (client_id == gpu_client_id_) { |
| 599 // The gpu_client uses a fixed tracing ID. |
| 600 return gpu_client_tracing_id_; |
| 601 } |
| 602 |
| 603 // In normal cases, |client_id| is a child process id, so we can perform |
| 604 // the standard conversion. |
| 605 return ChildProcessHostImpl::ChildProcessUniqueIdToTracingProcessId( |
| 606 client_id); |
| 607 } |
| 608 |
| 594 } // namespace content | 609 } // namespace content |
| OLD | NEW |