Commit 08d8f5de authored by alexst@chromium.org's avatar alexst@chromium.org

Delay the response to ChildProcessHostMsg_SyncAllocateGpuMemoryBuffer via a...

Delay the response to ChildProcessHostMsg_SyncAllocateGpuMemoryBuffer via a callback to allow for buffer allocation on the gpu process.

BUG=368716

Review URL: https://codereview.chromium.org/290573011

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@271861 0039d316-1c4b-4281-b951-d872f2087c98
parent f53bd4a9
...@@ -440,8 +440,9 @@ bool RenderMessageFilter::OnMessageReceived(const IPC::Message& message) { ...@@ -440,8 +440,9 @@ bool RenderMessageFilter::OnMessageReceived(const IPC::Message& message) {
OnAllocateSharedMemory) OnAllocateSharedMemory)
IPC_MESSAGE_HANDLER(ChildProcessHostMsg_SyncAllocateSharedBitmap, IPC_MESSAGE_HANDLER(ChildProcessHostMsg_SyncAllocateSharedBitmap,
OnAllocateSharedBitmap) OnAllocateSharedBitmap)
IPC_MESSAGE_HANDLER(ChildProcessHostMsg_SyncAllocateGpuMemoryBuffer, IPC_MESSAGE_HANDLER_DELAY_REPLY(
OnAllocateGpuMemoryBuffer) ChildProcessHostMsg_SyncAllocateGpuMemoryBuffer,
OnAllocateGpuMemoryBuffer)
IPC_MESSAGE_HANDLER(ChildProcessHostMsg_AllocatedSharedBitmap, IPC_MESSAGE_HANDLER(ChildProcessHostMsg_AllocatedSharedBitmap,
OnAllocatedSharedBitmap) OnAllocatedSharedBitmap)
IPC_MESSAGE_HANDLER(ChildProcessHostMsg_DeletedSharedBitmap, IPC_MESSAGE_HANDLER(ChildProcessHostMsg_DeletedSharedBitmap,
...@@ -1230,21 +1231,20 @@ void RenderMessageFilter::OnWebAudioMediaCodec( ...@@ -1230,21 +1231,20 @@ void RenderMessageFilter::OnWebAudioMediaCodec(
} }
#endif #endif
void RenderMessageFilter::OnAllocateGpuMemoryBuffer( void RenderMessageFilter::OnAllocateGpuMemoryBuffer(uint32 width,
uint32 width, uint32 height,
uint32 height, uint32 internalformat,
uint32 internalformat, uint32 usage,
uint32 usage, IPC::Message* reply) {
gfx::GpuMemoryBufferHandle* handle) {
if (!GpuMemoryBufferImpl::IsFormatValid(internalformat) || if (!GpuMemoryBufferImpl::IsFormatValid(internalformat) ||
!GpuMemoryBufferImpl::IsUsageValid(usage)) { !GpuMemoryBufferImpl::IsUsageValid(usage)) {
handle->type = gfx::EMPTY_BUFFER; GpuMemoryBufferAllocated(reply, gfx::GpuMemoryBufferHandle());
return; return;
} }
base::CheckedNumeric<int> size = width; base::CheckedNumeric<int> size = width;
size *= height; size *= height;
if (!size.IsValid()) { if (!size.IsValid()) {
handle->type = gfx::EMPTY_BUFFER; GpuMemoryBufferAllocated(reply, gfx::GpuMemoryBufferHandle());
return; return;
} }
...@@ -1284,13 +1284,15 @@ void RenderMessageFilter::OnAllocateGpuMemoryBuffer( ...@@ -1284,13 +1284,15 @@ void RenderMessageFilter::OnAllocateGpuMemoryBuffer(
base::ScopedCFTypeRef<CFTypeRef> io_surface( base::ScopedCFTypeRef<CFTypeRef> io_surface(
io_surface_support->IOSurfaceCreate(properties)); io_surface_support->IOSurfaceCreate(properties));
if (io_surface) { if (io_surface) {
handle->type = gfx::IO_SURFACE_BUFFER; gfx::GpuMemoryBufferHandle handle;
handle->io_surface_id = io_surface_support->IOSurfaceGetID(io_surface); handle.type = gfx::IO_SURFACE_BUFFER;
handle.io_surface_id = io_surface_support->IOSurfaceGetID(io_surface);
// TODO(reveman): This makes the assumption that the renderer will // TODO(reveman): This makes the assumption that the renderer will
// grab a reference to the surface before sending another message. // grab a reference to the surface before sending another message.
// crbug.com/325045 // crbug.com/325045
last_io_surface_ = io_surface; last_io_surface_ = io_surface;
GpuMemoryBufferAllocated(reply, handle);
return; return;
} }
} }
...@@ -1310,16 +1312,30 @@ void RenderMessageFilter::OnAllocateGpuMemoryBuffer( ...@@ -1310,16 +1312,30 @@ void RenderMessageFilter::OnAllocateGpuMemoryBuffer(
int surface_texture_id = int surface_texture_id =
CompositorImpl::CreateSurfaceTexture(render_process_id_); CompositorImpl::CreateSurfaceTexture(render_process_id_);
if (surface_texture_id != -1) { if (surface_texture_id != -1) {
handle->type = gfx::SURFACE_TEXTURE_BUFFER; gfx::GpuMemoryBufferHandle handle;
handle->surface_texture_id = handle.type = gfx::SURFACE_TEXTURE_BUFFER;
handle.surface_texture_id =
gfx::SurfaceTextureId(surface_texture_id, render_process_id_); gfx::SurfaceTextureId(surface_texture_id, render_process_id_);
GpuMemoryBufferAllocated(reply, handle);
return; return;
} }
} }
#endif #endif
GpuMemoryBufferImpl::AllocateForChildProcess( GpuMemoryBufferImpl::AllocateForChildProcess(
gfx::Size(width, height), internalformat, usage, PeerHandle(), handle); gfx::Size(width, height),
internalformat,
usage,
PeerHandle(),
base::Bind(&RenderMessageFilter::GpuMemoryBufferAllocated, this, reply));
}
void RenderMessageFilter::GpuMemoryBufferAllocated(
IPC::Message* reply,
const gfx::GpuMemoryBufferHandle& handle) {
ChildProcessHostMsg_SyncAllocateGpuMemoryBuffer::WriteReplyParams(reply,
handle);
Send(reply);
} }
} // namespace content } // namespace content
...@@ -277,7 +277,9 @@ class RenderMessageFilter : public BrowserMessageFilter { ...@@ -277,7 +277,9 @@ class RenderMessageFilter : public BrowserMessageFilter {
uint32 height, uint32 height,
uint32 internalformat, uint32 internalformat,
uint32 usage, uint32 usage,
gfx::GpuMemoryBufferHandle* handle); IPC::Message* reply);
void GpuMemoryBufferAllocated(IPC::Message* reply,
const gfx::GpuMemoryBufferHandle& handle);
// Cached resource request dispatcher host and plugin service, guaranteed to // 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 // be non-null if Init succeeds. We do not own the objects, they are managed
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#ifndef CONTENT_COMMON_GPU_CLIENT_GPU_MEMORY_BUFFER_IMPL_H_ #ifndef CONTENT_COMMON_GPU_CLIENT_GPU_MEMORY_BUFFER_IMPL_H_
#define CONTENT_COMMON_GPU_CLIENT_GPU_MEMORY_BUFFER_IMPL_H_ #define CONTENT_COMMON_GPU_CLIENT_GPU_MEMORY_BUFFER_IMPL_H_
#include "base/callback.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "ui/gfx/gpu_memory_buffer.h" #include "ui/gfx/gpu_memory_buffer.h"
#include "ui/gfx/size.h" #include "ui/gfx/size.h"
...@@ -14,6 +15,9 @@ namespace content { ...@@ -14,6 +15,9 @@ namespace content {
// Provides common implementation of a GPU memory buffer. // Provides common implementation of a GPU memory buffer.
class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer { class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer {
public: public:
typedef base::Callback<void(const gfx::GpuMemoryBufferHandle& handle)>
AllocationCallback;
virtual ~GpuMemoryBufferImpl(); virtual ~GpuMemoryBufferImpl();
// Creates a GPU memory buffer instance with |size| and |internalformat| for // Creates a GPU memory buffer instance with |size| and |internalformat| for
...@@ -29,7 +33,7 @@ class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer { ...@@ -29,7 +33,7 @@ class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer {
unsigned internalformat, unsigned internalformat,
unsigned usage, unsigned usage,
base::ProcessHandle child_process, base::ProcessHandle child_process,
gfx::GpuMemoryBufferHandle* handle); const AllocationCallback& callback);
// Creates an instance from the given |handle|. |size| and |internalformat| // Creates an instance from the given |handle|. |size| and |internalformat|
// should match what was used to allocate the |handle|. // should match what was used to allocate the |handle|.
......
...@@ -33,15 +33,15 @@ void GpuMemoryBufferImpl::AllocateForChildProcess( ...@@ -33,15 +33,15 @@ void GpuMemoryBufferImpl::AllocateForChildProcess(
unsigned internalformat, unsigned internalformat,
unsigned usage, unsigned usage,
base::ProcessHandle child_process, base::ProcessHandle child_process,
gfx::GpuMemoryBufferHandle* handle) { const AllocationCallback& callback) {
if (GpuMemoryBufferImplShm::IsConfigurationSupported( if (GpuMemoryBufferImplShm::IsConfigurationSupported(
size, internalformat, usage)) { size, internalformat, usage)) {
GpuMemoryBufferImplShm::AllocateSharedMemoryForChildProcess( GpuMemoryBufferImplShm::AllocateSharedMemoryForChildProcess(
size, internalformat, child_process, handle); size, internalformat, child_process, callback);
return; return;
} }
handle->type = gfx::EMPTY_BUFFER; callback.Run(gfx::GpuMemoryBufferHandle());
} }
// static // static
......
...@@ -32,15 +32,15 @@ void GpuMemoryBufferImpl::AllocateForChildProcess( ...@@ -32,15 +32,15 @@ void GpuMemoryBufferImpl::AllocateForChildProcess(
unsigned internalformat, unsigned internalformat,
unsigned usage, unsigned usage,
base::ProcessHandle child_process, base::ProcessHandle child_process,
gfx::GpuMemoryBufferHandle* handle) { const AllocationCallback& callback) {
if (GpuMemoryBufferImplShm::IsConfigurationSupported( if (GpuMemoryBufferImplShm::IsConfigurationSupported(
size, internalformat, usage)) { size, internalformat, usage)) {
GpuMemoryBufferImplShm::AllocateSharedMemoryForChildProcess( GpuMemoryBufferImplShm::AllocateSharedMemoryForChildProcess(
size, internalformat, child_process, handle); size, internalformat, child_process, callback);
return; return;
} }
handle->type = gfx::EMPTY_BUFFER; callback.Run(gfx::GpuMemoryBufferHandle());
} }
// static // static
......
...@@ -33,15 +33,15 @@ void GpuMemoryBufferImpl::AllocateForChildProcess( ...@@ -33,15 +33,15 @@ void GpuMemoryBufferImpl::AllocateForChildProcess(
unsigned internalformat, unsigned internalformat,
unsigned usage, unsigned usage,
base::ProcessHandle child_process, base::ProcessHandle child_process,
gfx::GpuMemoryBufferHandle* handle) { const AllocationCallback& callback) {
if (GpuMemoryBufferImplShm::IsConfigurationSupported( if (GpuMemoryBufferImplShm::IsConfigurationSupported(
size, internalformat, usage)) { size, internalformat, usage)) {
GpuMemoryBufferImplShm::AllocateSharedMemoryForChildProcess( GpuMemoryBufferImplShm::AllocateSharedMemoryForChildProcess(
size, internalformat, child_process, handle); size, internalformat, child_process, callback);
return; return;
} }
handle->type = gfx::EMPTY_BUFFER; callback.Run(gfx::GpuMemoryBufferHandle());
} }
// static // static
......
...@@ -20,16 +20,18 @@ void GpuMemoryBufferImplShm::AllocateSharedMemoryForChildProcess( ...@@ -20,16 +20,18 @@ void GpuMemoryBufferImplShm::AllocateSharedMemoryForChildProcess(
const gfx::Size& size, const gfx::Size& size,
unsigned internalformat, unsigned internalformat,
base::ProcessHandle child_process, base::ProcessHandle child_process,
gfx::GpuMemoryBufferHandle* handle) { const AllocationCallback& callback) {
DCHECK(IsLayoutSupported(size, internalformat)); DCHECK(IsLayoutSupported(size, internalformat));
gfx::GpuMemoryBufferHandle handle;
base::SharedMemory shared_memory; base::SharedMemory shared_memory;
if (!shared_memory.CreateAnonymous(size.GetArea() * if (!shared_memory.CreateAnonymous(size.GetArea() *
BytesPerPixel(internalformat))) { BytesPerPixel(internalformat))) {
handle->type = gfx::EMPTY_BUFFER; handle.type = gfx::EMPTY_BUFFER;
return; return;
} }
handle->type = gfx::SHARED_MEMORY_BUFFER; handle.type = gfx::SHARED_MEMORY_BUFFER;
shared_memory.GiveToProcess(child_process, &handle->handle); shared_memory.GiveToProcess(child_process, &handle.handle);
callback.Run(handle);
} }
// static // static
......
...@@ -21,7 +21,7 @@ class GpuMemoryBufferImplShm : public GpuMemoryBufferImpl { ...@@ -21,7 +21,7 @@ class GpuMemoryBufferImplShm : public GpuMemoryBufferImpl {
const gfx::Size& size, const gfx::Size& size,
unsigned internalformat, unsigned internalformat,
base::ProcessHandle child_process, base::ProcessHandle child_process,
gfx::GpuMemoryBufferHandle* handle); const AllocationCallback& callback);
static bool IsLayoutSupported(const gfx::Size& size, unsigned internalformat); static bool IsLayoutSupported(const gfx::Size& size, unsigned internalformat);
static bool IsUsageSupported(unsigned usage); static bool IsUsageSupported(unsigned usage);
......
...@@ -32,15 +32,15 @@ void GpuMemoryBufferImpl::AllocateForChildProcess( ...@@ -32,15 +32,15 @@ void GpuMemoryBufferImpl::AllocateForChildProcess(
unsigned internalformat, unsigned internalformat,
unsigned usage, unsigned usage,
base::ProcessHandle child_process, base::ProcessHandle child_process,
gfx::GpuMemoryBufferHandle* handle) { const AllocationCallback& callback) {
if (GpuMemoryBufferImplShm::IsConfigurationSupported( if (GpuMemoryBufferImplShm::IsConfigurationSupported(
size, internalformat, usage)) { size, internalformat, usage)) {
GpuMemoryBufferImplShm::AllocateSharedMemoryForChildProcess( GpuMemoryBufferImplShm::AllocateSharedMemoryForChildProcess(
size, internalformat, child_process, handle); size, internalformat, child_process, callback);
return; return;
} }
handle->type = gfx::EMPTY_BUFFER; callback.Run(gfx::GpuMemoryBufferHandle());
} }
// static // static
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment