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 7df495c816d2a2933aa3d712c49e9df6eb7dc14c..3565845ae2ecc7d01dbc906910b37991e00524ef 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_tracing_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" |
| @@ -136,9 +137,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 { |
| @@ -229,6 +227,7 @@ BrowserGpuMemoryBufferManager::AllocateGpuMemoryBufferForScanout( |
| } |
| void BrowserGpuMemoryBufferManager::AllocateGpuMemoryBufferForChildProcess( |
| + gfx::GpuMemoryBufferId id, |
| const gfx::Size& size, |
| gfx::BufferFormat format, |
| gfx::BufferUsage usage, |
| @@ -237,11 +236,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; |
| } |
| @@ -255,13 +252,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( |
|
danakj
2015/08/13 00:25:06
Looks good.
|
| + 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* |
| @@ -292,7 +295,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; |
| @@ -399,7 +402,8 @@ 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::GetNextGenericSharedMemoryTracingId(); |
| // Use service side allocation if this is a supported configuration. |
| if (IsGpuMemoryBufferConfigurationSupported(request->format, |
| @@ -421,11 +425,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( |
| @@ -472,9 +478,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, |
| @@ -499,10 +502,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 " |
|
reveman
2015/08/13 08:24:44
If using DLOG here then please switch to DLOG for
|
| + "an existing ID."; |
| + callback.Run(gfx::GpuMemoryBufferHandle()); |
| + return; |
| + } |
| // Note: Unretained is safe as IO thread is stopped before manager is |
| // destroyed. |