diff options
author | reveman@chromium.org <reveman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-22 23:13:09 +0000 |
---|---|---|
committer | reveman@chromium.org <reveman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-22 23:13:09 +0000 |
commit | bc10f46abc6b4d6338fd1819b0360bc9115846f2 (patch) | |
tree | 34595adeaffa513af37b0caa4e9afd05cfcf65d0 /content/browser | |
parent | 9f67dd0edac097ff862e9f92e988da2f5cb19348 (diff) | |
download | chromium_src-bc10f46abc6b4d6338fd1819b0360bc9115846f2.zip chromium_src-bc10f46abc6b4d6338fd1819b0360bc9115846f2.tar.gz chromium_src-bc10f46abc6b4d6338fd1819b0360bc9115846f2.tar.bz2 |
Add multi-process GpuMemoryBuffer framework.
This adds a multi-process framework for reading/writing directly to
memory that the 3D graphics hardware can use for rendering without
any costly copying having to be done on the GPU process side.
A GpuMemoryBuffer is a type of shared memory that can be accessed
by the GPU. The high level procedure required to allocate this type
of memory is almost exactly the same as that for standard shared
memory. Only the browser process can allocated the memory and it
needs to be shared and registered with the GPU process before it can
be used.
This also adds a GpuMemoryBuffer type that is backed by standard
shared memory for testing purposes.
TEST=gpu_unittests --gtest_filter=MockGpuMemoryBufferTest.Lifecycle
BUG=261649
Review URL: https://codereview.chromium.org/19762004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@230248 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser')
4 files changed, 52 insertions, 1 deletions
diff --git a/content/browser/gpu/browser_gpu_channel_host_factory.cc b/content/browser/gpu/browser_gpu_channel_host_factory.cc index 7bc6fca..2f04189 100644 --- a/content/browser/gpu/browser_gpu_channel_host_factory.cc +++ b/content/browser/gpu/browser_gpu_channel_host_factory.cc @@ -9,8 +9,9 @@ #include "content/browser/gpu/gpu_data_manager_impl.h" #include "content/browser/gpu/gpu_process_host.h" #include "content/browser/gpu/gpu_surface_tracker.h" -#include "content/common/gpu/gpu_messages.h" #include "content/common/child_process_host_impl.h" +#include "content/common/gpu/client/gpu_memory_buffer_impl.h" +#include "content/common/gpu/gpu_messages.h" #include "content/public/browser/browser_thread.h" #include "content/public/common/content_client.h" #include "ipc/ipc_forwarding_message_filter.h" @@ -284,6 +285,27 @@ GpuChannelHost* BrowserGpuChannelHostFactory::EstablishGpuChannelSync( return gpu_channel_.get(); } +scoped_ptr<gfx::GpuMemoryBuffer> + BrowserGpuChannelHostFactory::AllocateGpuMemoryBuffer( + size_t width, + size_t height, + unsigned internalformat) { + if (!GpuMemoryBufferImpl::IsFormatValid(internalformat)) + return scoped_ptr<gfx::GpuMemoryBuffer>(); + + size_t size = width * height * + GpuMemoryBufferImpl::BytesPerPixel(internalformat); + scoped_ptr<base::SharedMemory> shm(new base::SharedMemory()); + if (!shm->CreateAnonymous(size)) + return scoped_ptr<gfx::GpuMemoryBuffer>(); + + return make_scoped_ptr<gfx::GpuMemoryBuffer>( + new GpuMemoryBufferImpl(shm.Pass(), + width, + height, + internalformat)); +} + // static void BrowserGpuChannelHostFactory::AddFilterOnIO( int host_id, diff --git a/content/browser/gpu/browser_gpu_channel_host_factory.h b/content/browser/gpu/browser_gpu_channel_host_factory.h index ca31183..0e10ece 100644 --- a/content/browser/gpu/browser_gpu_channel_host_factory.h +++ b/content/browser/gpu/browser_gpu_channel_host_factory.h @@ -38,6 +38,10 @@ class CONTENT_EXPORT BrowserGpuChannelHostFactory virtual void DeleteImage(int32 image_idu, int32 sync_point) OVERRIDE; virtual GpuChannelHost* EstablishGpuChannelSync( CauseForGpuLaunch cause_for_gpu_launch) OVERRIDE; + virtual scoped_ptr<gfx::GpuMemoryBuffer> AllocateGpuMemoryBuffer( + size_t width, + size_t height, + unsigned internalformat) OVERRIDE; // Specify a task runner and callback to be used for a set of messages. The // callback will be set up on the current GpuProcessHost, identified by diff --git a/content/browser/renderer_host/render_message_filter.cc b/content/browser/renderer_host/render_message_filter.cc index d7e32d0..7fd1870 100644 --- a/content/browser/renderer_host/render_message_filter.cc +++ b/content/browser/renderer_host/render_message_filter.cc @@ -398,6 +398,8 @@ bool RenderMessageFilter::OnMessageReceived(const IPC::Message& message, OnCheckNotificationPermission) IPC_MESSAGE_HANDLER(ChildProcessHostMsg_SyncAllocateSharedMemory, OnAllocateSharedMemory) + IPC_MESSAGE_HANDLER(ChildProcessHostMsg_SyncAllocateGpuMemoryBuffer, + OnAllocateGpuMemoryBuffer) #if defined(OS_POSIX) && !defined(TOOLKIT_GTK) && !defined(OS_ANDROID) IPC_MESSAGE_HANDLER(ViewHostMsg_AllocTransportDIB, OnAllocTransportDIB) IPC_MESSAGE_HANDLER(ViewHostMsg_FreeTransportDIB, OnFreeTransportDIB) @@ -1165,4 +1167,23 @@ void RenderMessageFilter::OnWebAudioMediaCodec( true); } #endif + +void RenderMessageFilter::OnAllocateGpuMemoryBuffer( + uint32 buffer_size, + gfx::GpuMemoryBufferHandle* handle) { + // TODO(reveman): Implement allocation of real GpuMemoryBuffer. + // Currently this function creates a fake GpuMemoryBuffer that is + // backed by shared memory and requires an upload before it can + // be used as a texture. The plan is to instead have this function + // allocate a real GpuMemoryBuffer in whatever form is supported + // by platform and drivers. + // + // Note: |buffer_size| likely needs to be replaced by a more + // specific buffer description but is enough for the shared memory + // backed GpuMemoryBuffer currently returned. + handle->type = gfx::SHARED_MEMORY_BUFFER; + ChildProcessHostImpl::AllocateSharedMemory( + buffer_size, PeerHandle(), &handle->handle); +} + } // namespace content diff --git a/content/browser/renderer_host/render_message_filter.h b/content/browser/renderer_host/render_message_filter.h index 446a531..d0a4386 100644 --- a/content/browser/renderer_host/render_message_filter.h +++ b/content/browser/renderer_host/render_message_filter.h @@ -52,6 +52,7 @@ class TaskRunner; namespace gfx { class Rect; +struct GpuMemoryBufferHandle; } namespace media { @@ -261,6 +262,9 @@ class RenderMessageFilter : public BrowserMessageFilter { uint32_t data_size); #endif + void OnAllocateGpuMemoryBuffer(uint32 buffer_size, + gfx::GpuMemoryBufferHandle* handle); + // Cached resource request dispatcher host and plugin service, guaranteed to // be non-null if Init succeeds. We do not own the objects, they are managed // by the BrowserProcess, which has a wider scope than we do. |