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 3770c7628222f94dc0a38c96b3e0e727d0116be7..99394ac2cbd2f15847acfc22075a268eb9b42075 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" |
@@ -141,9 +142,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 { |
@@ -234,6 +232,7 @@ BrowserGpuMemoryBufferManager::AllocateGpuMemoryBufferForScanout( |
} |
void BrowserGpuMemoryBufferManager::AllocateGpuMemoryBufferForChildProcess( |
+ gfx::GpuMemoryBufferId id, |
const gfx::Size& size, |
gfx::BufferFormat format, |
gfx::BufferUsage usage, |
@@ -242,11 +241,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; |
} |
@@ -260,13 +257,19 @@ void BrowserGpuMemoryBufferManager::AllocateGpuMemoryBufferForChildProcess( |
} |
BufferMap& buffers = clients_[child_client_id]; |
- DCHECK(buffers.find(new_id) == buffers.end()); |
// Allocate shared memory buffer as fallback. |
- buffers[new_id] = |
- BufferInfo(size, gfx::SHARED_MEMORY_BUFFER, format, usage, 0); |
+ auto insert_result = buffers.insert(std::make_pair( |
+ id, BufferInfo(size, gfx::SHARED_MEMORY_BUFFER, format, usage, 0))); |
+ if (!insert_result.second) { |
+ DLOG(ERROR) << "Child process attempted to allocate a GpuMemoryBuffer with " |
+ "an existing ID."; |
+ callback.Run(gfx::GpuMemoryBufferHandle()); |
+ return; |
+ } |
+ |
callback.Run(GpuMemoryBufferImplSharedMemory::AllocateForChildProcess( |
- new_id, size, format, child_process_handle)); |
+ id, size, format, child_process_handle)); |
} |
gfx::GpuMemoryBuffer* |
@@ -297,7 +300,7 @@ bool BrowserGpuMemoryBufferManager::OnMemoryDump( |
gfx::GpuMemoryBufferId buffer_id = buffer.first; |
base::trace_event::MemoryAllocatorDump* dump = |
pmd->CreateAllocatorDump(base::StringPrintf( |
- "gpumemorybuffer/client_%d/buffer_%d", client_id, buffer_id)); |
+ "gpumemorybuffer/client_%d/buffer_%d", client_id, buffer_id.id)); |
if (!dump) |
return false; |
@@ -404,7 +407,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, |
@@ -426,11 +429,13 @@ void BrowserGpuMemoryBufferManager::AllocateGpuMemoryBufferForSurfaceOnIO( |
<< static_cast<int>(request->usage); |
BufferMap& buffers = clients_[request->client_id]; |
- DCHECK(buffers.find(new_id) == buffers.end()); |
// Allocate shared memory buffer as fallback. |
- buffers[new_id] = BufferInfo(request->size, gfx::SHARED_MEMORY_BUFFER, |
- request->format, request->usage, 0); |
+ auto insert_result = buffers.insert(std::make_pair( |
+ new_id, BufferInfo(request->size, gfx::SHARED_MEMORY_BUFFER, |
+ request->format, request->usage, 0))); |
+ DCHECK(insert_result.second); |
+ |
// Note: Unretained is safe as IO thread is stopped before manager is |
// destroyed. |
request->result = GpuMemoryBufferImplSharedMemory::Create( |
@@ -477,9 +482,6 @@ void BrowserGpuMemoryBufferManager::AllocateGpuMemoryBufferOnIO( |
const AllocationCallback& callback) { |
DCHECK_CURRENTLY_ON(BrowserThread::IO); |
- BufferMap& buffers = clients_[client_id]; |
- DCHECK(buffers.find(id) == buffers.end()); |
- |
GpuProcessHost* host = GpuProcessHost::FromID(gpu_host_id_); |
if (!host) { |
host = GpuProcessHost::Get(GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED, |
@@ -504,10 +506,19 @@ void BrowserGpuMemoryBufferManager::AllocateGpuMemoryBufferOnIO( |
reused_gpu_process = true; |
} |
+ BufferMap& buffers = clients_[client_id]; |
+ |
// Note: Handling of cases where the client is removed before the allocation |
// completes is less subtle if we set the buffer type to EMPTY_BUFFER here |
// and verify that this has not changed when allocation completes. |
- buffers[id] = BufferInfo(size, gfx::EMPTY_BUFFER, format, usage, 0); |
+ auto insert_result = buffers.insert(std::make_pair( |
+ id, BufferInfo(size, gfx::EMPTY_BUFFER, format, usage, 0))); |
+ if (!insert_result.second) { |
+ DLOG(ERROR) << "Child process attempted to allocate a GpuMemoryBuffer with " |
+ "an existing ID."; |
+ callback.Run(gfx::GpuMemoryBufferHandle()); |
+ return; |
+ } |
// Note: Unretained is safe as IO thread is stopped before manager is |
// destroyed. |