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..62d9c61aecd37253a07383da3516afef5a28e8c1 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" |
| @@ -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,20 @@ 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); |
| + if (!buffers.insert( |
|
danakj
2015/08/12 23:49:02
is is possible to split this up into multiple line
ericrk
2015/08/13 00:13:56
Done.
|
| + std::make_pair(id, BufferInfo(size, gfx::SHARED_MEMORY_BUFFER, |
| + format, usage, 0))) |
| + .second) { |
| + LOG(ERROR) << "Child process attempted to allocate a GpuMemoryBuffer with " |
|
danakj
2015/08/12 23:49:02
Can we use DLOG or VLOG? (prefer former so we don'
ericrk
2015/08/13 00:13:56
Done.
|
| + "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* |
| @@ -399,7 +403,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, |
| @@ -421,11 +425,16 @@ 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); |
| + bool insert_succeeded = |
|
danakj
2015/08/12 23:49:01
is is possible to split this up into multiple line
ericrk
2015/08/13 00:13:56
I think that after removing the .second things loo
|
| + buffers.insert(std::make_pair( |
| + new_id, |
| + BufferInfo(request->size, gfx::SHARED_MEMORY_BUFFER, |
| + request->format, request->usage, 0))) |
| + .second; |
| + DCHECK(insert_succeeded); |
| + |
| // Note: Unretained is safe as IO thread is stopped before manager is |
| // destroyed. |
| request->result = GpuMemoryBufferImplSharedMemory::Create( |
| @@ -472,9 +481,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 +505,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); |
| + if (!buffers.insert(std::make_pair(id, BufferInfo(size, gfx::EMPTY_BUFFER, |
|
danakj
2015/08/12 23:49:01
is is possible to split this up into multiple line
ericrk
2015/08/13 00:13:56
Done.
|
| + format, usage, 0))) |
| + .second) { |
| + LOG(ERROR) << "Child process attempted to allocate a GpuMemoryBuffer with " |
|
danakj
2015/08/12 23:49:01
DLOG? VLOD?
ericrk
2015/08/13 00:13:56
Done.
|
| + "an existing ID."; |
| + callback.Run(gfx::GpuMemoryBufferHandle()); |
| + return; |
| + } |
| // Note: Unretained is safe as IO thread is stopped before manager is |
| // destroyed. |