| 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..5735a7282cef86583776045a4d0f59463764a4bc 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,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(
|
| + std::make_pair(id, BufferInfo(size, gfx::SHARED_MEMORY_BUFFER,
|
| + format, usage, 0)))
|
| + .second) {
|
| + LOG(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 +296,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 +403,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 +426,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 =
|
| + 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 +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,
|
| @@ -499,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);
|
| + if (!buffers.insert(std::make_pair(id, BufferInfo(size, gfx::EMPTY_BUFFER,
|
| + format, usage, 0)))
|
| + .second) {
|
| + LOG(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.
|
|
|