Index: content/browser/gpu/browser_gpu_memory_buffer_manager.cc |
diff --git a/content/browser/gpu/browser_gpu_memory_buffer_manager.cc b/content/browser/gpu/browser_gpu_memory_buffer_manager.cc |
index a1d54b7b365c2f4485e71dfe0bd38a63402556d5..92ffe086bb159c09ef628665e6e0e597ef921d64 100644 |
--- a/content/browser/gpu/browser_gpu_memory_buffer_manager.cc |
+++ b/content/browser/gpu/browser_gpu_memory_buffer_manager.cc |
@@ -14,6 +14,7 @@ |
#include "base/trace_event/trace_event.h" |
#include "content/browser/gpu/gpu_process_host.h" |
#include "content/common/child_process_host_impl.h" |
+#include "content/common/generic_shared_memory_id_generator.h" |
#include "content/common/gpu/client/gpu_memory_buffer_impl.h" |
#include "content/common/gpu/client/gpu_memory_buffer_impl_shared_memory.h" |
#include "content/common/gpu/gpu_memory_buffer_factory_shared_memory.h" |
@@ -120,9 +121,6 @@ GetSupportedGpuMemoryBufferConfigurations(gfx::GpuMemoryBufferType type) { |
BrowserGpuMemoryBufferManager* g_gpu_memory_buffer_manager = nullptr; |
-// Global atomic to generate gpu memory buffer unique IDs. |
-base::StaticAtomicSequenceNumber g_next_gpu_memory_buffer_id; |
- |
} // namespace |
struct BrowserGpuMemoryBufferManager::AllocateGpuMemoryBufferRequest { |
@@ -213,6 +211,7 @@ BrowserGpuMemoryBufferManager::AllocateGpuMemoryBufferForScanout( |
} |
void BrowserGpuMemoryBufferManager::AllocateGpuMemoryBufferForChildProcess( |
+ gfx::GpuMemoryBufferId id, |
const gfx::Size& size, |
gfx::BufferFormat format, |
gfx::BufferUsage usage, |
@@ -221,11 +220,9 @@ void BrowserGpuMemoryBufferManager::AllocateGpuMemoryBufferForChildProcess( |
const AllocationCallback& callback) { |
DCHECK_CURRENTLY_ON(BrowserThread::IO); |
- gfx::GpuMemoryBufferId new_id = g_next_gpu_memory_buffer_id.GetNext(); |
- |
// Use service side allocation if this is a supported configuration. |
if (IsGpuMemoryBufferConfigurationSupported(format, usage)) { |
- AllocateGpuMemoryBufferOnIO(new_id, size, format, usage, child_client_id, 0, |
+ AllocateGpuMemoryBufferOnIO(id, size, format, usage, child_client_id, 0, |
false, callback); |
return; |
} |
@@ -239,13 +236,12 @@ void BrowserGpuMemoryBufferManager::AllocateGpuMemoryBufferForChildProcess( |
} |
BufferMap& buffers = clients_[child_client_id]; |
- DCHECK(buffers.find(new_id) == buffers.end()); |
+ DCHECK(buffers.find(id) == buffers.end()); |
// Allocate shared memory buffer as fallback. |
- buffers[new_id] = |
- BufferInfo(size, gfx::SHARED_MEMORY_BUFFER, format, usage, 0); |
+ buffers[id] = BufferInfo(size, gfx::SHARED_MEMORY_BUFFER, format, usage, 0); |
callback.Run(GpuMemoryBufferImplSharedMemory::AllocateForChildProcess( |
- new_id, size, format, child_process_handle)); |
+ id, size, format, child_process_handle)); |
} |
gfx::GpuMemoryBuffer* |
@@ -291,17 +287,31 @@ bool BrowserGpuMemoryBufferManager::OnMemoryDump( |
base::trace_event::MemoryAllocatorDump::kUnitsBytes, |
buffer_size_in_bytes); |
+ uint64 client_tracing_process_id = ClientIdToTracingProcessId(client_id); |
+ |
// Create the cross-process ownership edge. If the client creates a |
// corresponding dump for the same buffer, this will avoid to |
// double-count them in tracing. If, instead, no other process will emit a |
// dump with the same guid, the segment will be accounted to the browser. |
- uint64 client_tracing_process_id = ClientIdToTracingProcessId(client_id); |
- |
base::trace_event::MemoryAllocatorDumpGuid shared_buffer_guid = |
gfx::GetGpuMemoryBufferGUIDForTracing(client_tracing_process_id, |
buffer_id); |
pmd->CreateSharedGlobalAllocatorDump(shared_buffer_guid); |
pmd->AddOwnershipEdge(dump->guid(), shared_buffer_guid); |
+ |
+ // Create an additional shared ownership edge with the generic shared |
+ // memory id for the shared memory which backs this GpuMemoryBuffer. |
+ base::trace_event::MemoryAllocatorDumpGuid shared_memory_guid = |
+ base::trace_event::GetGenericSharedMemoryGUIDForTracing( |
+ client_tracing_process_id, buffer_id); |
+ pmd->CreateSharedGlobalAllocatorDump(shared_memory_guid); |
+ |
+ // The link from the shared memory guid to the gpu memory buffer guid is |
+ // set higher than the link from the shared memory guid to its various |
+ // dumps. This ensures that memory is tracked with the gpu memory buffer. |
+ const int kImportance = 2; |
+ pmd->AddOwnershipEdge(shared_buffer_guid, shared_memory_guid, |
+ kImportance); |
} |
} |
@@ -382,7 +392,7 @@ void BrowserGpuMemoryBufferManager::AllocateGpuMemoryBufferForSurfaceOnIO( |
AllocateGpuMemoryBufferRequest* request) { |
DCHECK_CURRENTLY_ON(BrowserThread::IO); |
- gfx::GpuMemoryBufferId new_id = g_next_gpu_memory_buffer_id.GetNext(); |
+ gfx::GpuMemoryBufferId new_id = content::GetNextGenericSharedMemoryId(); |
// Use service side allocation if this is a supported configuration. |
if (IsGpuMemoryBufferConfigurationSupported(request->format, |