Chromium Code Reviews| 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..eed489ab6bae41c637f9eea4e226d9bb54cbcd00 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,17 @@ void BrowserGpuMemoryBufferManager::AllocateGpuMemoryBufferForChildProcess( |
| } |
| BufferMap& buffers = clients_[child_client_id]; |
| - DCHECK(buffers.find(new_id) == buffers.end()); |
| + if (buffers.find(id) != buffers.end()) { |
| + LOG(ERROR) << "Client process attempted to allocate a GpuMemoryBuffer with " |
| + "an existing ID. Failing allocation."; |
| + callback.Run(gfx::GpuMemoryBufferHandle()); |
| + return; |
| + } |
| // 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); |
|
piman
2015/08/06 23:29:12
To avoid the double-search, what you can do is:
au
ericrk
2015/08/10 21:12:14
Good call, moved to a helper fun to make this a bi
|
| callback.Run(GpuMemoryBufferImplSharedMemory::AllocateForChildProcess( |
| - new_id, size, format, child_process_handle)); |
| + id, size, format, child_process_handle)); |
| } |
| gfx::GpuMemoryBuffer* |
| @@ -298,8 +299,8 @@ bool BrowserGpuMemoryBufferManager::OnMemoryDump( |
| uint64 client_tracing_process_id = ClientIdToTracingProcessId(client_id); |
| base::trace_event::MemoryAllocatorDumpGuid shared_buffer_guid = |
| - gfx::GetGpuMemoryBufferGUIDForTracing(client_tracing_process_id, |
| - buffer_id); |
| + base::GetGenericSharedMemoryGUIDForTracing(client_tracing_process_id, |
| + buffer_id); |
| pmd->CreateSharedGlobalAllocatorDump(shared_buffer_guid); |
| pmd->AddOwnershipEdge(dump->guid(), shared_buffer_guid); |
| } |
| @@ -382,7 +383,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, |
| @@ -456,7 +457,12 @@ void BrowserGpuMemoryBufferManager::AllocateGpuMemoryBufferOnIO( |
| DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| BufferMap& buffers = clients_[client_id]; |
| - DCHECK(buffers.find(id) == buffers.end()); |
| + if (buffers.find(id) != buffers.end()) { |
| + LOG(ERROR) << "Client process attempted to allocate a GpuMemoryBuffer with " |
| + "an existing ID. Failing allocation."; |
| + callback.Run(gfx::GpuMemoryBufferHandle()); |
| + return; |
| + } |
| GpuProcessHost* host = GpuProcessHost::FromID(gpu_host_id_); |
| if (!host) { |