summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cc/test/test_gpu_memory_buffer_manager.cc2
-rw-r--r--components/view_manager/gles2/command_buffer_driver.cc2
-rw-r--r--components/view_manager/gles2/mojo_gpu_memory_buffer.cc2
-rw-r--r--content/browser/browser_io_surface_manager_mac.h5
-rw-r--r--content/browser/compositor/buffer_queue_unittest.cc4
-rw-r--r--content/browser/gpu/browser_gpu_memory_buffer_manager.cc49
-rw-r--r--content/browser/gpu/browser_gpu_memory_buffer_manager.h1
-rw-r--r--content/browser/renderer_host/media/video_capture_buffer_pool_unittest.cc4
-rw-r--r--content/browser/renderer_host/render_message_filter.cc12
-rw-r--r--content/browser/renderer_host/render_message_filter.h3
-rw-r--r--content/child/child_gpu_memory_buffer_manager.cc4
-rw-r--r--content/common/child_process_host_impl.cc7
-rw-r--r--content/common/child_process_host_impl.h3
-rw-r--r--content/common/child_process_messages.h7
-rw-r--r--content/common/generic_shared_memory_id_generator.cc21
-rw-r--r--content/common/generic_shared_memory_id_generator.h19
-rw-r--r--content/common/gpu/client/gpu_memory_buffer_impl_io_surface.cc2
-rw-r--r--content/common/gpu/client/gpu_memory_buffer_impl_surface_texture.cc5
-rw-r--r--content/common/gpu/client/gpu_memory_buffer_impl_unittest.cc6
-rw-r--r--content/common/gpu/gpu_memory_buffer_factory_io_surface.cc10
-rw-r--r--content/common/gpu/gpu_memory_buffer_factory_ozone_native_pixmap.cc6
-rw-r--r--content/common/gpu/gpu_memory_buffer_factory_surface_texture.cc11
-rw-r--r--content/common/gpu/gpu_memory_buffer_factory_unittest.cc2
-rw-r--r--content/common/gpu/gpu_messages.h2
-rw-r--r--content/content_common.gypi2
-rw-r--r--content/gpu/gpu_child_thread.cc3
-rw-r--r--gpu/command_buffer/tests/gl_manager.cc2
-rw-r--r--media/renderers/mock_gpu_video_accelerator_factories.cc2
-rw-r--r--ui/gfx/BUILD.gn2
-rw-r--r--ui/gfx/generic_shared_memory_id.cc20
-rw-r--r--ui/gfx/generic_shared_memory_id.h54
-rw-r--r--ui/gfx/gfx.gyp2
-rw-r--r--ui/gfx/gpu_memory_buffer.cc11
-rw-r--r--ui/gfx/gpu_memory_buffer.h3
34 files changed, 218 insertions, 72 deletions
diff --git a/cc/test/test_gpu_memory_buffer_manager.cc b/cc/test/test_gpu_memory_buffer_manager.cc
index 6648823..8d56a97 100644
--- a/cc/test/test_gpu_memory_buffer_manager.cc
+++ b/cc/test/test_gpu_memory_buffer_manager.cc
@@ -123,7 +123,7 @@ class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer {
}
gfx::GpuMemoryBufferId GetId() const override {
NOTREACHED();
- return 0;
+ return gfx::GpuMemoryBufferId(0);
}
gfx::GpuMemoryBufferHandle GetHandle() const override {
gfx::GpuMemoryBufferHandle handle;
diff --git a/components/view_manager/gles2/command_buffer_driver.cc b/components/view_manager/gles2/command_buffer_driver.cc
index cbb63dc..5a4ac83f 100644
--- a/components/view_manager/gles2/command_buffer_driver.cc
+++ b/components/view_manager/gles2/command_buffer_driver.cc
@@ -256,7 +256,7 @@ void CommandBufferDriver::CreateImage(int32_t id,
gfx::GpuMemoryBufferHandle gfx_handle;
// TODO(jam): create mojo enum for this and converter
gfx_handle.type = static_cast<gfx::GpuMemoryBufferType>(type);
- gfx_handle.id = id;
+ gfx_handle.id = gfx::GpuMemoryBufferId(id);
MojoPlatformHandle platform_handle;
MojoResult extract_result = MojoExtractPlatformHandle(
diff --git a/components/view_manager/gles2/mojo_gpu_memory_buffer.cc b/components/view_manager/gles2/mojo_gpu_memory_buffer.cc
index 5f6a2864..0efa398 100644
--- a/components/view_manager/gles2/mojo_gpu_memory_buffer.cc
+++ b/components/view_manager/gles2/mojo_gpu_memory_buffer.cc
@@ -152,7 +152,7 @@ void MojoGpuMemoryBufferImpl::GetStride(int* stride) const {
}
gfx::GpuMemoryBufferId MojoGpuMemoryBufferImpl::GetId() const {
- return 0;
+ return gfx::GpuMemoryBufferId(0);
}
gfx::GpuMemoryBufferHandle MojoGpuMemoryBufferImpl::GetHandle() const {
diff --git a/content/browser/browser_io_surface_manager_mac.h b/content/browser/browser_io_surface_manager_mac.h
index 7d786eb..62ae750 100644
--- a/content/browser/browser_io_surface_manager_mac.h
+++ b/content/browser/browser_io_surface_manager_mac.h
@@ -24,6 +24,11 @@
namespace content {
+// TODO(ericrk): Use gfx::GenericSharedMemoryId as the |io_surface_id| in
+// this file. Allows for more type-safe usage of GpuMemoryBufferIds as the
+// type of the |io_surface_id|, as it is a typedef of
+// gfx::GenericSharedMemoryId.
+
// Implementation of IOSurfaceManager that provides a mechanism for child
// processes to register and acquire IOSurfaces through a Mach service.
class CONTENT_EXPORT BrowserIOSurfaceManager : public IOSurfaceManager {
diff --git a/content/browser/compositor/buffer_queue_unittest.cc b/content/browser/compositor/buffer_queue_unittest.cc
index 4c52a8e..0fe4173 100644
--- a/content/browser/compositor/buffer_queue_unittest.cc
+++ b/content/browser/compositor/buffer_queue_unittest.cc
@@ -34,7 +34,9 @@ class StubGpuMemoryBufferImpl : public gfx::GpuMemoryBuffer {
return gfx::BufferFormat::RGBX_8888;
}
void GetStride(int* stride) const override {}
- gfx::GpuMemoryBufferId GetId() const override { return 0; }
+ gfx::GpuMemoryBufferId GetId() const override {
+ return gfx::GpuMemoryBufferId(0);
+ }
gfx::GpuMemoryBufferHandle GetHandle() const override {
return gfx::GpuMemoryBufferHandle();
}
diff --git a/content/browser/gpu/browser_gpu_memory_buffer_manager.cc b/content/browser/gpu/browser_gpu_memory_buffer_manager.cc
index 3770c762..99394ac 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.
diff --git a/content/browser/gpu/browser_gpu_memory_buffer_manager.h b/content/browser/gpu/browser_gpu_memory_buffer_manager.h
index b11faf8..12fd082 100644
--- a/content/browser/gpu/browser_gpu_memory_buffer_manager.h
+++ b/content/browser/gpu/browser_gpu_memory_buffer_manager.h
@@ -52,6 +52,7 @@ class CONTENT_EXPORT BrowserGpuMemoryBufferManager
int32 surface_id);
void AllocateGpuMemoryBufferForChildProcess(
+ gfx::GpuMemoryBufferId id,
const gfx::Size& size,
gfx::BufferFormat format,
gfx::BufferUsage usage,
diff --git a/content/browser/renderer_host/media/video_capture_buffer_pool_unittest.cc b/content/browser/renderer_host/media/video_capture_buffer_pool_unittest.cc
index a02aa93..7d5fce4 100644
--- a/content/browser/renderer_host/media/video_capture_buffer_pool_unittest.cc
+++ b/content/browser/renderer_host/media/video_capture_buffer_pool_unittest.cc
@@ -71,7 +71,9 @@ class VideoCaptureBufferPoolTest
*stride = size_.width() * 4;
return;
}
- gfx::GpuMemoryBufferId GetId() const override { return 0; }
+ gfx::GpuMemoryBufferId GetId() const override {
+ return gfx::GpuMemoryBufferId(0);
+ }
gfx::GpuMemoryBufferHandle GetHandle() const override {
return gfx::GpuMemoryBufferHandle();
}
diff --git a/content/browser/renderer_host/render_message_filter.cc b/content/browser/renderer_host/render_message_filter.cc
index e2df8be..ce6572a 100644
--- a/content/browser/renderer_host/render_message_filter.cc
+++ b/content/browser/renderer_host/render_message_filter.cc
@@ -1199,7 +1199,8 @@ void RenderMessageFilter::OnWebAudioMediaCodec(
}
#endif
-void RenderMessageFilter::OnAllocateGpuMemoryBuffer(uint32 width,
+void RenderMessageFilter::OnAllocateGpuMemoryBuffer(gfx::GpuMemoryBufferId id,
+ uint32 width,
uint32 height,
gfx::BufferFormat format,
gfx::BufferUsage usage,
@@ -1215,13 +1216,10 @@ void RenderMessageFilter::OnAllocateGpuMemoryBuffer(uint32 width,
BrowserGpuMemoryBufferManager::current()
->AllocateGpuMemoryBufferForChildProcess(
- gfx::Size(width, height),
- format,
- usage,
- PeerHandle(),
+ id, gfx::Size(width, height), format, usage, PeerHandle(),
render_process_id_,
- base::Bind(
- &RenderMessageFilter::GpuMemoryBufferAllocated, this, reply));
+ base::Bind(&RenderMessageFilter::GpuMemoryBufferAllocated, this,
+ reply));
}
void RenderMessageFilter::GpuMemoryBufferAllocated(
diff --git a/content/browser/renderer_host/render_message_filter.h b/content/browser/renderer_host/render_message_filter.h
index 8ef5be9..6d8ac3a 100644
--- a/content/browser/renderer_host/render_message_filter.h
+++ b/content/browser/renderer_host/render_message_filter.h
@@ -292,7 +292,8 @@ class CONTENT_EXPORT RenderMessageFilter : public BrowserMessageFilter {
uint32_t data_size);
#endif
- void OnAllocateGpuMemoryBuffer(uint32 width,
+ void OnAllocateGpuMemoryBuffer(gfx::GpuMemoryBufferId id,
+ uint32 width,
uint32 height,
gfx::BufferFormat format,
gfx::BufferUsage usage,
diff --git a/content/child/child_gpu_memory_buffer_manager.cc b/content/child/child_gpu_memory_buffer_manager.cc
index 9a7517d..1c7b67b 100644
--- a/content/child/child_gpu_memory_buffer_manager.cc
+++ b/content/child/child_gpu_memory_buffer_manager.cc
@@ -5,6 +5,7 @@
#include "content/child/child_gpu_memory_buffer_manager.h"
#include "content/common/child_process_messages.h"
+#include "content/common/generic_shared_memory_id_generator.h"
#include "content/common/gpu/client/gpu_memory_buffer_impl.h"
namespace content {
@@ -41,7 +42,8 @@ ChildGpuMemoryBufferManager::AllocateGpuMemoryBuffer(const gfx::Size& size,
gfx::GpuMemoryBufferHandle handle;
IPC::Message* message = new ChildProcessHostMsg_SyncAllocateGpuMemoryBuffer(
- size.width(), size.height(), format, usage, &handle);
+ content::GetNextGenericSharedMemoryId(), size.width(), size.height(),
+ format, usage, &handle);
bool success = sender_->Send(message);
if (!success || handle.is_null())
return nullptr;
diff --git a/content/common/child_process_host_impl.cc b/content/common/child_process_host_impl.cc
index 67004c1..3aad503 100644
--- a/content/common/child_process_host_impl.cc
+++ b/content/common/child_process_host_impl.cc
@@ -87,9 +87,6 @@ base::FilePath TransformPathForFeature(const base::FilePath& path,
// Global atomic to generate child process unique IDs.
base::StaticAtomicSequenceNumber g_unique_id;
-// Global atomic to generate gpu memory buffer unique IDs.
-base::StaticAtomicSequenceNumber g_next_gpu_memory_buffer_id;
-
} // namespace
namespace content {
@@ -358,6 +355,7 @@ void ChildProcessHostImpl::OnShutdownRequest() {
}
void ChildProcessHostImpl::OnAllocateGpuMemoryBuffer(
+ gfx::GpuMemoryBufferId id,
uint32 width,
uint32 height,
gfx::BufferFormat format,
@@ -371,8 +369,7 @@ void ChildProcessHostImpl::OnAllocateGpuMemoryBuffer(
if (GpuMemoryBufferImplSharedMemory::IsFormatSupported(format) &&
GpuMemoryBufferImplSharedMemory::IsUsageSupported(usage)) {
*handle = GpuMemoryBufferImplSharedMemory::AllocateForChildProcess(
- g_next_gpu_memory_buffer_id.GetNext(), gfx::Size(width, height), format,
- peer_process_.Handle());
+ id, gfx::Size(width, height), format, peer_process_.Handle());
}
}
diff --git a/content/common/child_process_host_impl.h b/content/common/child_process_host_impl.h
index dd1fae7..d859323 100644
--- a/content/common/child_process_host_impl.h
+++ b/content/common/child_process_host_impl.h
@@ -94,7 +94,8 @@ class CONTENT_EXPORT ChildProcessHostImpl : public ChildProcessHost,
void OnShutdownRequest();
void OnAllocateSharedMemory(uint32 buffer_size,
base::SharedMemoryHandle* handle);
- void OnAllocateGpuMemoryBuffer(uint32 width,
+ void OnAllocateGpuMemoryBuffer(gfx::GpuMemoryBufferId id,
+ uint32 width,
uint32 height,
gfx::BufferFormat format,
gfx::BufferUsage usage,
diff --git a/content/common/child_process_messages.h b/content/common/child_process_messages.h
index 896d864..5775054 100644
--- a/content/common/child_process_messages.h
+++ b/content/common/child_process_messages.h
@@ -70,6 +70,10 @@ IPC_STRUCT_TRAITS_BEGIN(gfx::GpuMemoryBufferHandle)
IPC_STRUCT_TRAITS_MEMBER(handle)
IPC_STRUCT_TRAITS_END()
+IPC_STRUCT_TRAITS_BEGIN(gfx::GpuMemoryBufferId)
+ IPC_STRUCT_TRAITS_MEMBER(id)
+IPC_STRUCT_TRAITS_END()
+
#undef IPC_MESSAGE_EXPORT
#define IPC_MESSAGE_EXPORT CONTENT_EXPORT
@@ -185,7 +189,8 @@ IPC_MESSAGE_CONTROL1(ChildProcessHostMsg_TcmallocStats,
#endif
// Asks the browser to create a gpu memory buffer.
-IPC_SYNC_MESSAGE_CONTROL4_1(ChildProcessHostMsg_SyncAllocateGpuMemoryBuffer,
+IPC_SYNC_MESSAGE_CONTROL5_1(ChildProcessHostMsg_SyncAllocateGpuMemoryBuffer,
+ gfx::GpuMemoryBufferId /* new_id */,
uint32 /* width */,
uint32 /* height */,
gfx::BufferFormat,
diff --git a/content/common/generic_shared_memory_id_generator.cc b/content/common/generic_shared_memory_id_generator.cc
new file mode 100644
index 0000000..c912bc2
--- /dev/null
+++ b/content/common/generic_shared_memory_id_generator.cc
@@ -0,0 +1,21 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/common/generic_shared_memory_id_generator.h"
+
+#include "base/atomic_sequence_num.h"
+
+namespace content {
+namespace {
+
+// Global atomic to generate gpu memory buffer unique IDs.
+base::StaticAtomicSequenceNumber g_next_generic_shared_memory_id;
+
+} // namespace
+
+gfx::GenericSharedMemoryId GetNextGenericSharedMemoryId() {
+ return gfx::GenericSharedMemoryId(g_next_generic_shared_memory_id.GetNext());
+}
+
+} // namespace content
diff --git a/content/common/generic_shared_memory_id_generator.h b/content/common/generic_shared_memory_id_generator.h
new file mode 100644
index 0000000..4640cc1
--- /dev/null
+++ b/content/common/generic_shared_memory_id_generator.h
@@ -0,0 +1,19 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_COMMON_GENERIC_SHARED_MEMORY_ID_GENERATOR_H_
+#define CONTENT_COMMON_GENERIC_SHARED_MEMORY_ID_GENERATOR_H_
+
+#include "ui/gfx/generic_shared_memory_id.h"
+#include "content/common/content_export.h"
+
+namespace content {
+
+// Returns the next GenericSharedMemoryId for the current process. This should
+// be used anywhere a new GenericSharedMemoryId is needed.
+CONTENT_EXPORT gfx::GenericSharedMemoryId GetNextGenericSharedMemoryId();
+
+} // namespace content
+
+#endif // CONTENT_COMMON_GENERIC_SHARED_MEMORY_ID_GENERATOR_H_
diff --git a/content/common/gpu/client/gpu_memory_buffer_impl_io_surface.cc b/content/common/gpu/client/gpu_memory_buffer_impl_io_surface.cc
index 7a3f044..16c27c8 100644
--- a/content/common/gpu/client/gpu_memory_buffer_impl_io_surface.cc
+++ b/content/common/gpu/client/gpu_memory_buffer_impl_io_surface.cc
@@ -48,7 +48,7 @@ scoped_ptr<GpuMemoryBufferImpl> GpuMemoryBufferImplIOSurface::CreateFromHandle(
gfx::BufferUsage usage,
const DestructionCallback& callback) {
base::ScopedCFTypeRef<IOSurfaceRef> io_surface(
- IOSurfaceManager::GetInstance()->AcquireIOSurface(handle.id));
+ IOSurfaceManager::GetInstance()->AcquireIOSurface(handle.id.id));
if (!io_surface)
return nullptr;
diff --git a/content/common/gpu/client/gpu_memory_buffer_impl_surface_texture.cc b/content/common/gpu/client/gpu_memory_buffer_impl_surface_texture.cc
index d4d2ef2..2bbea50 100644
--- a/content/common/gpu/client/gpu_memory_buffer_impl_surface_texture.cc
+++ b/content/common/gpu/client/gpu_memory_buffer_impl_surface_texture.cc
@@ -58,8 +58,9 @@ GpuMemoryBufferImplSurfaceTexture::CreateFromHandle(
const gfx::Size& size,
gfx::BufferFormat format,
const DestructionCallback& callback) {
- ANativeWindow* native_window = SurfaceTextureManager::GetInstance()->
- AcquireNativeWidgetForSurfaceTexture(handle.id);
+ ANativeWindow* native_window =
+ SurfaceTextureManager::GetInstance()
+ ->AcquireNativeWidgetForSurfaceTexture(handle.id.id);
if (!native_window)
return scoped_ptr<GpuMemoryBufferImpl>();
diff --git a/content/common/gpu/client/gpu_memory_buffer_impl_unittest.cc b/content/common/gpu/client/gpu_memory_buffer_impl_unittest.cc
index 1ab1d99..29fdd44 100644
--- a/content/common/gpu/client/gpu_memory_buffer_impl_unittest.cc
+++ b/content/common/gpu/client/gpu_memory_buffer_impl_unittest.cc
@@ -50,7 +50,7 @@ class GpuMemoryBufferImplTest
};
TEST_P(GpuMemoryBufferImplTest, CreateFromHandle) {
- const int kBufferId = 1;
+ const gfx::GpuMemoryBufferId kBufferId(1);
gfx::Size buffer_size(8, 8);
@@ -73,7 +73,7 @@ TEST_P(GpuMemoryBufferImplTest, CreateFromHandle) {
}
TEST_P(GpuMemoryBufferImplTest, Map) {
- const int kBufferId = 1;
+ const gfx::GpuMemoryBufferId kBufferId(1);
// Use a multiple of 4 for both dimensions to support compressed formats.
gfx::Size buffer_size(4, 4);
@@ -135,7 +135,7 @@ TEST_P(GpuMemoryBufferImplTest, Map) {
}
TEST_P(GpuMemoryBufferImplTest, PersistentMap) {
- const int kBufferId = 1;
+ const gfx::GpuMemoryBufferId kBufferId(1);
// Use a multiple of 4 for both dimensions to support compressed formats.
gfx::Size buffer_size(4, 4);
diff --git a/content/common/gpu/gpu_memory_buffer_factory_io_surface.cc b/content/common/gpu/gpu_memory_buffer_factory_io_surface.cc
index 1dd8cb4..41a9f5d 100644
--- a/content/common/gpu/gpu_memory_buffer_factory_io_surface.cc
+++ b/content/common/gpu/gpu_memory_buffer_factory_io_surface.cc
@@ -156,7 +156,7 @@ GpuMemoryBufferFactoryIOSurface::CreateGpuMemoryBuffer(
if (!io_surface)
return gfx::GpuMemoryBufferHandle();
- if (!IOSurfaceManager::GetInstance()->RegisterIOSurface(id, client_id,
+ if (!IOSurfaceManager::GetInstance()->RegisterIOSurface(id.id, client_id,
io_surface)) {
return gfx::GpuMemoryBufferHandle();
}
@@ -164,7 +164,7 @@ GpuMemoryBufferFactoryIOSurface::CreateGpuMemoryBuffer(
{
base::AutoLock lock(io_surfaces_lock_);
- IOSurfaceMapKey key(id, client_id);
+ IOSurfaceMapKey key(id.id, client_id);
DCHECK(io_surfaces_.find(key) == io_surfaces_.end());
io_surfaces_[key] = io_surface;
}
@@ -181,12 +181,12 @@ void GpuMemoryBufferFactoryIOSurface::DestroyGpuMemoryBuffer(
{
base::AutoLock lock(io_surfaces_lock_);
- IOSurfaceMapKey key(id, client_id);
+ IOSurfaceMapKey key(id.id, client_id);
DCHECK(io_surfaces_.find(key) != io_surfaces_.end());
io_surfaces_.erase(key);
}
- IOSurfaceManager::GetInstance()->UnregisterIOSurface(id, client_id);
+ IOSurfaceManager::GetInstance()->UnregisterIOSurface(id.id, client_id);
}
gpu::ImageFactory* GpuMemoryBufferFactoryIOSurface::AsImageFactory() {
@@ -203,7 +203,7 @@ GpuMemoryBufferFactoryIOSurface::CreateImageForGpuMemoryBuffer(
base::AutoLock lock(io_surfaces_lock_);
DCHECK_EQ(handle.type, gfx::IO_SURFACE_BUFFER);
- IOSurfaceMapKey key(handle.id, client_id);
+ IOSurfaceMapKey key(handle.id.id, client_id);
IOSurfaceMap::iterator it = io_surfaces_.find(key);
if (it == io_surfaces_.end())
return scoped_refptr<gfx::GLImage>();
diff --git a/content/common/gpu/gpu_memory_buffer_factory_ozone_native_pixmap.cc b/content/common/gpu/gpu_memory_buffer_factory_ozone_native_pixmap.cc
index 8435d69..6e482e5 100644
--- a/content/common/gpu/gpu_memory_buffer_factory_ozone_native_pixmap.cc
+++ b/content/common/gpu/gpu_memory_buffer_factory_ozone_native_pixmap.cc
@@ -75,7 +75,7 @@ GpuMemoryBufferFactoryOzoneNativePixmap::CreateGpuMemoryBuffer(
return gfx::GpuMemoryBufferHandle();
}
base::AutoLock lock(native_pixmaps_lock_);
- NativePixmapMapKey key(id, client_id);
+ NativePixmapMapKey key(id.id, client_id);
DCHECK(native_pixmaps_.find(key) == native_pixmaps_.end())
<< "pixmap with this key must not exist";
native_pixmaps_[key] = pixmap;
@@ -90,7 +90,7 @@ void GpuMemoryBufferFactoryOzoneNativePixmap::DestroyGpuMemoryBuffer(
gfx::GpuMemoryBufferId id,
int client_id) {
base::AutoLock lock(native_pixmaps_lock_);
- auto it = native_pixmaps_.find(NativePixmapMapKey(id, client_id));
+ auto it = native_pixmaps_.find(NativePixmapMapKey(id.id, client_id));
DCHECK(it != native_pixmaps_.end()) << "pixmap with this key must exist";
native_pixmaps_.erase(it);
}
@@ -111,7 +111,7 @@ GpuMemoryBufferFactoryOzoneNativePixmap::CreateImageForGpuMemoryBuffer(
{
base::AutoLock lock(native_pixmaps_lock_);
NativePixmapMap::iterator it =
- native_pixmaps_.find(NativePixmapMapKey(handle.id, client_id));
+ native_pixmaps_.find(NativePixmapMapKey(handle.id.id, client_id));
if (it == native_pixmaps_.end()) {
return nullptr;
}
diff --git a/content/common/gpu/gpu_memory_buffer_factory_surface_texture.cc b/content/common/gpu/gpu_memory_buffer_factory_surface_texture.cc
index 7c3c806..490c45e 100644
--- a/content/common/gpu/gpu_memory_buffer_factory_surface_texture.cc
+++ b/content/common/gpu/gpu_memory_buffer_factory_surface_texture.cc
@@ -61,12 +61,12 @@ GpuMemoryBufferFactorySurfaceTexture::CreateGpuMemoryBuffer(
return gfx::GpuMemoryBufferHandle();
SurfaceTextureManager::GetInstance()->RegisterSurfaceTexture(
- id, client_id, surface_texture.get());
+ id.id, client_id, surface_texture.get());
{
base::AutoLock lock(surface_textures_lock_);
- SurfaceTextureMapKey key(id, client_id);
+ SurfaceTextureMapKey key(id.id, client_id);
DCHECK(surface_textures_.find(key) == surface_textures_.end());
surface_textures_[key] = surface_texture;
}
@@ -83,12 +83,13 @@ void GpuMemoryBufferFactorySurfaceTexture::DestroyGpuMemoryBuffer(
{
base::AutoLock lock(surface_textures_lock_);
- SurfaceTextureMapKey key(id, client_id);
+ SurfaceTextureMapKey key(id.id, client_id);
DCHECK(surface_textures_.find(key) != surface_textures_.end());
surface_textures_.erase(key);
}
- SurfaceTextureManager::GetInstance()->UnregisterSurfaceTexture(id, client_id);
+ SurfaceTextureManager::GetInstance()->UnregisterSurfaceTexture(id.id,
+ client_id);
}
gpu::ImageFactory* GpuMemoryBufferFactorySurfaceTexture::AsImageFactory() {
@@ -106,7 +107,7 @@ GpuMemoryBufferFactorySurfaceTexture::CreateImageForGpuMemoryBuffer(
DCHECK_EQ(handle.type, gfx::SURFACE_TEXTURE_BUFFER);
- SurfaceTextureMapKey key(handle.id, client_id);
+ SurfaceTextureMapKey key(handle.id.id, client_id);
SurfaceTextureMap::iterator it = surface_textures_.find(key);
if (it == surface_textures_.end())
return scoped_refptr<gfx::GLImage>();
diff --git a/content/common/gpu/gpu_memory_buffer_factory_unittest.cc b/content/common/gpu/gpu_memory_buffer_factory_unittest.cc
index f9dc7e1..dbd9b76 100644
--- a/content/common/gpu/gpu_memory_buffer_factory_unittest.cc
+++ b/content/common/gpu/gpu_memory_buffer_factory_unittest.cc
@@ -28,7 +28,7 @@ class GpuMemoryBufferFactoryTest
};
TEST_P(GpuMemoryBufferFactoryTest, CreateAndDestroy) {
- const int kBufferId = 1;
+ const gfx::GpuMemoryBufferId kBufferId(1);
const int kClientId = 1;
gfx::Size buffer_size(2, 2);
diff --git a/content/common/gpu/gpu_messages.h b/content/common/gpu/gpu_messages.h
index acfbab6..a75b5ad 100644
--- a/content/common/gpu/gpu_messages.h
+++ b/content/common/gpu/gpu_messages.h
@@ -83,7 +83,7 @@ IPC_STRUCT_BEGIN(GPUCreateCommandBufferConfig)
IPC_STRUCT_END()
IPC_STRUCT_BEGIN(GpuMsg_CreateGpuMemoryBuffer_Params)
- IPC_STRUCT_MEMBER(int32, id)
+ IPC_STRUCT_MEMBER(gfx::GpuMemoryBufferId, id)
IPC_STRUCT_MEMBER(gfx::Size, size)
IPC_STRUCT_MEMBER(gfx::BufferFormat, format)
IPC_STRUCT_MEMBER(gfx::BufferUsage, usage)
diff --git a/content/content_common.gypi b/content/content_common.gypi
index 15c3889..97590df 100644
--- a/content/content_common.gypi
+++ b/content/content_common.gypi
@@ -272,6 +272,8 @@
'common/gamepad_param_traits.h',
'common/gamepad_user_gesture.cc',
'common/gamepad_user_gesture.h',
+ 'common/generic_shared_memory_id_generator.cc',
+ 'common/generic_shared_memory_id_generator.h',
'common/geofencing_messages.h',
'common/geofencing_types.cc',
'common/geofencing_types.h',
diff --git a/content/gpu/gpu_child_thread.cc b/content/gpu/gpu_child_thread.cc
index ac79e60..0c00dcc 100644
--- a/content/gpu/gpu_child_thread.cc
+++ b/content/gpu/gpu_child_thread.cc
@@ -80,7 +80,7 @@ class GpuMemoryBufferMessageFilter : public IPC::MessageFilter {
void OnCreateGpuMemoryBuffer(
const GpuMsg_CreateGpuMemoryBuffer_Params& params) {
TRACE_EVENT2("gpu", "GpuMemoryBufferMessageFilter::OnCreateGpuMemoryBuffer",
- "id", params.id, "client_id", params.client_id);
+ "id", params.id.id, "client_id", params.client_id);
sender_->Send(new GpuHostMsg_GpuMemoryBufferCreated(
gpu_memory_buffer_factory_->CreateGpuMemoryBuffer(
params.id, params.size, params.format, params.usage,
@@ -358,4 +358,3 @@ void GpuChildThread::OnGpuSwitched() {
}
} // namespace content
-
diff --git a/gpu/command_buffer/tests/gl_manager.cc b/gpu/command_buffer/tests/gl_manager.cc
index 7897d16..f32792f 100644
--- a/gpu/command_buffer/tests/gl_manager.cc
+++ b/gpu/command_buffer/tests/gl_manager.cc
@@ -145,7 +145,7 @@ class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer {
}
gfx::GpuMemoryBufferId GetId() const override {
NOTREACHED();
- return 0;
+ return gfx::GpuMemoryBufferId(0);
}
gfx::GpuMemoryBufferHandle GetHandle() const override {
NOTREACHED();
diff --git a/media/renderers/mock_gpu_video_accelerator_factories.cc b/media/renderers/mock_gpu_video_accelerator_factories.cc
index 4fb61ba..58bd5a3 100644
--- a/media/renderers/mock_gpu_video_accelerator_factories.cc
+++ b/media/renderers/mock_gpu_video_accelerator_factories.cc
@@ -32,7 +32,7 @@ class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer {
void GetStride(int* stride) const override { stride[0] = size_.width(); }
gfx::GpuMemoryBufferId GetId() const override {
NOTREACHED();
- return 0;
+ return gfx::GpuMemoryBufferId(0);
}
gfx::GpuMemoryBufferHandle GetHandle() const override {
NOTREACHED();
diff --git a/ui/gfx/BUILD.gn b/ui/gfx/BUILD.gn
index 4cd3576..32fc674 100644
--- a/ui/gfx/BUILD.gn
+++ b/ui/gfx/BUILD.gn
@@ -103,6 +103,8 @@ component("gfx") {
"font_render_params_win.cc",
"gdi_util.cc",
"gdi_util.h",
+ "generic_shared_memory_id.cc",
+ "generic_shared_memory_id.h",
"gfx_paths.cc",
"gfx_paths.h",
"gpu_memory_buffer.cc",
diff --git a/ui/gfx/generic_shared_memory_id.cc b/ui/gfx/generic_shared_memory_id.cc
new file mode 100644
index 0000000..33a5ef0
--- /dev/null
+++ b/ui/gfx/generic_shared_memory_id.cc
@@ -0,0 +1,20 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/gfx/generic_shared_memory_id.h"
+
+#include "base/format_macros.h"
+#include "base/strings/stringprintf.h"
+
+namespace gfx {
+
+base::trace_event::MemoryAllocatorDumpGuid GetGenericSharedMemoryGUIDForTracing(
+ uint64_t tracing_process_id,
+ GenericSharedMemoryId generic_shared_memory_id) {
+ return base::trace_event::MemoryAllocatorDumpGuid(
+ base::StringPrintf("genericsharedmemory-x-process/%" PRIx64 "/%d",
+ tracing_process_id, generic_shared_memory_id.id));
+}
+
+} // namespace gfx
diff --git a/ui/gfx/generic_shared_memory_id.h b/ui/gfx/generic_shared_memory_id.h
new file mode 100644
index 0000000..9aa226f
--- /dev/null
+++ b/ui/gfx/generic_shared_memory_id.h
@@ -0,0 +1,54 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef UI_GFX_GENERIC_SHARED_MEMORY_ID_H_
+#define UI_GFX_GENERIC_SHARED_MEMORY_ID_H_
+
+#include "base/trace_event/memory_allocator_dump.h"
+#include "ui/gfx/gfx_export.h"
+
+namespace gfx {
+
+// Defines an ID type which is used across all types of shared memory
+// allocations in content/. This ID type is in ui/gfx, as components outside
+// content/ may need to hold an ID (but should not generate one).
+class GFX_EXPORT GenericSharedMemoryId {
+ public:
+ int id;
+
+ // Invalid ID is -1 to match semantics of base::StaticAtomicSequenceNumber.
+ GenericSharedMemoryId() : id(-1) {}
+ explicit GenericSharedMemoryId(int id) : id(id) {}
+ GenericSharedMemoryId(const GenericSharedMemoryId& other) = default;
+ GenericSharedMemoryId& operator=(const GenericSharedMemoryId& other) =
+ default;
+
+ bool operator==(const GenericSharedMemoryId& other) const {
+ return id == other.id;
+ }
+
+ bool operator<(const GenericSharedMemoryId& other) const {
+ return id < other.id;
+ }
+};
+
+// Generates GUID which can be used to trace shared memory using its
+// GenericSharedMemoryId.
+GFX_EXPORT base::trace_event::MemoryAllocatorDumpGuid
+GetGenericSharedMemoryGUIDForTracing(
+ uint64_t tracing_process_id,
+ GenericSharedMemoryId generic_shared_memory_id);
+
+} // namespace gfx
+
+namespace BASE_HASH_NAMESPACE {
+template <>
+struct hash<gfx::GenericSharedMemoryId> {
+ size_t operator()(gfx::GenericSharedMemoryId key) const {
+ return BASE_HASH_NAMESPACE::hash<int>()(key.id);
+ }
+};
+} // namespace BASE_HASH_NAMESPACE
+
+#endif // UI_GFX_GENERIC_SHARED_MEMORY_ID_H_
diff --git a/ui/gfx/gfx.gyp b/ui/gfx/gfx.gyp
index d741b0e..98575ae 100644
--- a/ui/gfx/gfx.gyp
+++ b/ui/gfx/gfx.gyp
@@ -173,6 +173,8 @@
'font_render_params_linux.cc',
'font_render_params_mac.cc',
'font_render_params_win.cc',
+ 'generic_shared_memory_id.cc',
+ 'generic_shared_memory_id.h',
'gfx_export.h',
'gfx_paths.cc',
'gfx_paths.h',
diff --git a/ui/gfx/gpu_memory_buffer.cc b/ui/gfx/gpu_memory_buffer.cc
index 44fcd31..9ccd410 100644
--- a/ui/gfx/gpu_memory_buffer.cc
+++ b/ui/gfx/gpu_memory_buffer.cc
@@ -4,17 +4,16 @@
#include "ui/gfx/gpu_memory_buffer.h"
-#include "base/format_macros.h"
-#include "base/strings/stringprintf.h"
-
namespace gfx {
base::trace_event::MemoryAllocatorDumpGuid GetGpuMemoryBufferGUIDForTracing(
uint64 tracing_process_id,
GpuMemoryBufferId buffer_id) {
- return base::trace_event::MemoryAllocatorDumpGuid(
- base::StringPrintf("gpumemorybuffer-x-process/%" PRIx64 "/%d",
- tracing_process_id, buffer_id));
+ // TODO(ericrk): Currently this function just wraps
+ // GetGenericSharedMemoryGUIDForTracing, we may want to special case this if
+ // the GPU memory buffer is not backed by shared memory.
+ return gfx::GetGenericSharedMemoryGUIDForTracing(tracing_process_id,
+ buffer_id);
}
GpuMemoryBufferHandle::GpuMemoryBufferHandle()
diff --git a/ui/gfx/gpu_memory_buffer.h b/ui/gfx/gpu_memory_buffer.h
index 263a0ef..1234dc2 100644
--- a/ui/gfx/gpu_memory_buffer.h
+++ b/ui/gfx/gpu_memory_buffer.h
@@ -9,6 +9,7 @@
#include "base/trace_event/memory_dump_manager.h"
#include "build/build_config.h"
#include "ui/gfx/buffer_types.h"
+#include "ui/gfx/generic_shared_memory_id.h"
#include "ui/gfx/gfx_export.h"
extern "C" typedef struct _ClientBuffer* ClientBuffer;
@@ -24,7 +25,7 @@ enum GpuMemoryBufferType {
GPU_MEMORY_BUFFER_TYPE_LAST = OZONE_NATIVE_PIXMAP
};
-using GpuMemoryBufferId = int32;
+using GpuMemoryBufferId = gfx::GenericSharedMemoryId;
struct GFX_EXPORT GpuMemoryBufferHandle {
GpuMemoryBufferHandle();