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
This commit is contained in:
@ -440,8 +440,9 @@ bool RenderMessageFilter::OnMessageReceived(const IPC::Message& message) {
|
||||
OnAllocateSharedMemory)
|
||||
IPC_MESSAGE_HANDLER(ChildProcessHostMsg_SyncAllocateSharedBitmap,
|
||||
OnAllocateSharedBitmap)
|
||||
IPC_MESSAGE_HANDLER(ChildProcessHostMsg_SyncAllocateGpuMemoryBuffer,
|
||||
OnAllocateGpuMemoryBuffer)
|
||||
IPC_MESSAGE_HANDLER_DELAY_REPLY(
|
||||
ChildProcessHostMsg_SyncAllocateGpuMemoryBuffer,
|
||||
OnAllocateGpuMemoryBuffer)
|
||||
IPC_MESSAGE_HANDLER(ChildProcessHostMsg_AllocatedSharedBitmap,
|
||||
OnAllocatedSharedBitmap)
|
||||
IPC_MESSAGE_HANDLER(ChildProcessHostMsg_DeletedSharedBitmap,
|
||||
@ -1230,21 +1231,20 @@ void RenderMessageFilter::OnWebAudioMediaCodec(
|
||||
}
|
||||
#endif
|
||||
|
||||
void RenderMessageFilter::OnAllocateGpuMemoryBuffer(
|
||||
uint32 width,
|
||||
uint32 height,
|
||||
uint32 internalformat,
|
||||
uint32 usage,
|
||||
gfx::GpuMemoryBufferHandle* handle) {
|
||||
void RenderMessageFilter::OnAllocateGpuMemoryBuffer(uint32 width,
|
||||
uint32 height,
|
||||
uint32 internalformat,
|
||||
uint32 usage,
|
||||
IPC::Message* reply) {
|
||||
if (!GpuMemoryBufferImpl::IsFormatValid(internalformat) ||
|
||||
!GpuMemoryBufferImpl::IsUsageValid(usage)) {
|
||||
handle->type = gfx::EMPTY_BUFFER;
|
||||
GpuMemoryBufferAllocated(reply, gfx::GpuMemoryBufferHandle());
|
||||
return;
|
||||
}
|
||||
base::CheckedNumeric<int> size = width;
|
||||
size *= height;
|
||||
if (!size.IsValid()) {
|
||||
handle->type = gfx::EMPTY_BUFFER;
|
||||
GpuMemoryBufferAllocated(reply, gfx::GpuMemoryBufferHandle());
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1284,13 +1284,15 @@ void RenderMessageFilter::OnAllocateGpuMemoryBuffer(
|
||||
base::ScopedCFTypeRef<CFTypeRef> io_surface(
|
||||
io_surface_support->IOSurfaceCreate(properties));
|
||||
if (io_surface) {
|
||||
handle->type = gfx::IO_SURFACE_BUFFER;
|
||||
handle->io_surface_id = io_surface_support->IOSurfaceGetID(io_surface);
|
||||
gfx::GpuMemoryBufferHandle handle;
|
||||
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
|
||||
// grab a reference to the surface before sending another message.
|
||||
// crbug.com/325045
|
||||
last_io_surface_ = io_surface;
|
||||
GpuMemoryBufferAllocated(reply, handle);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -1310,16 +1312,30 @@ void RenderMessageFilter::OnAllocateGpuMemoryBuffer(
|
||||
int surface_texture_id =
|
||||
CompositorImpl::CreateSurfaceTexture(render_process_id_);
|
||||
if (surface_texture_id != -1) {
|
||||
handle->type = gfx::SURFACE_TEXTURE_BUFFER;
|
||||
handle->surface_texture_id =
|
||||
gfx::GpuMemoryBufferHandle handle;
|
||||
handle.type = gfx::SURFACE_TEXTURE_BUFFER;
|
||||
handle.surface_texture_id =
|
||||
gfx::SurfaceTextureId(surface_texture_id, render_process_id_);
|
||||
GpuMemoryBufferAllocated(reply, handle);
|
||||
return;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
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
|
||||
|
@ -277,7 +277,9 @@ class RenderMessageFilter : public BrowserMessageFilter {
|
||||
uint32 height,
|
||||
uint32 internalformat,
|
||||
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
|
||||
// be non-null if Init succeeds. We do not own the objects, they are managed
|
||||
|
@ -5,6 +5,7 @@
|
||||
#ifndef 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 "ui/gfx/gpu_memory_buffer.h"
|
||||
#include "ui/gfx/size.h"
|
||||
@ -14,6 +15,9 @@ namespace content {
|
||||
// Provides common implementation of a GPU memory buffer.
|
||||
class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer {
|
||||
public:
|
||||
typedef base::Callback<void(const gfx::GpuMemoryBufferHandle& handle)>
|
||||
AllocationCallback;
|
||||
|
||||
virtual ~GpuMemoryBufferImpl();
|
||||
|
||||
// Creates a GPU memory buffer instance with |size| and |internalformat| for
|
||||
@ -29,7 +33,7 @@ class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer {
|
||||
unsigned internalformat,
|
||||
unsigned usage,
|
||||
base::ProcessHandle child_process,
|
||||
gfx::GpuMemoryBufferHandle* handle);
|
||||
const AllocationCallback& callback);
|
||||
|
||||
// Creates an instance from the given |handle|. |size| and |internalformat|
|
||||
// should match what was used to allocate the |handle|.
|
||||
|
@ -33,15 +33,15 @@ void GpuMemoryBufferImpl::AllocateForChildProcess(
|
||||
unsigned internalformat,
|
||||
unsigned usage,
|
||||
base::ProcessHandle child_process,
|
||||
gfx::GpuMemoryBufferHandle* handle) {
|
||||
const AllocationCallback& callback) {
|
||||
if (GpuMemoryBufferImplShm::IsConfigurationSupported(
|
||||
size, internalformat, usage)) {
|
||||
GpuMemoryBufferImplShm::AllocateSharedMemoryForChildProcess(
|
||||
size, internalformat, child_process, handle);
|
||||
size, internalformat, child_process, callback);
|
||||
return;
|
||||
}
|
||||
|
||||
handle->type = gfx::EMPTY_BUFFER;
|
||||
callback.Run(gfx::GpuMemoryBufferHandle());
|
||||
}
|
||||
|
||||
// static
|
||||
|
@ -32,15 +32,15 @@ void GpuMemoryBufferImpl::AllocateForChildProcess(
|
||||
unsigned internalformat,
|
||||
unsigned usage,
|
||||
base::ProcessHandle child_process,
|
||||
gfx::GpuMemoryBufferHandle* handle) {
|
||||
const AllocationCallback& callback) {
|
||||
if (GpuMemoryBufferImplShm::IsConfigurationSupported(
|
||||
size, internalformat, usage)) {
|
||||
GpuMemoryBufferImplShm::AllocateSharedMemoryForChildProcess(
|
||||
size, internalformat, child_process, handle);
|
||||
size, internalformat, child_process, callback);
|
||||
return;
|
||||
}
|
||||
|
||||
handle->type = gfx::EMPTY_BUFFER;
|
||||
callback.Run(gfx::GpuMemoryBufferHandle());
|
||||
}
|
||||
|
||||
// static
|
||||
|
@ -33,15 +33,15 @@ void GpuMemoryBufferImpl::AllocateForChildProcess(
|
||||
unsigned internalformat,
|
||||
unsigned usage,
|
||||
base::ProcessHandle child_process,
|
||||
gfx::GpuMemoryBufferHandle* handle) {
|
||||
const AllocationCallback& callback) {
|
||||
if (GpuMemoryBufferImplShm::IsConfigurationSupported(
|
||||
size, internalformat, usage)) {
|
||||
GpuMemoryBufferImplShm::AllocateSharedMemoryForChildProcess(
|
||||
size, internalformat, child_process, handle);
|
||||
size, internalformat, child_process, callback);
|
||||
return;
|
||||
}
|
||||
|
||||
handle->type = gfx::EMPTY_BUFFER;
|
||||
callback.Run(gfx::GpuMemoryBufferHandle());
|
||||
}
|
||||
|
||||
// static
|
||||
|
@ -20,16 +20,18 @@ void GpuMemoryBufferImplShm::AllocateSharedMemoryForChildProcess(
|
||||
const gfx::Size& size,
|
||||
unsigned internalformat,
|
||||
base::ProcessHandle child_process,
|
||||
gfx::GpuMemoryBufferHandle* handle) {
|
||||
const AllocationCallback& callback) {
|
||||
DCHECK(IsLayoutSupported(size, internalformat));
|
||||
gfx::GpuMemoryBufferHandle handle;
|
||||
base::SharedMemory shared_memory;
|
||||
if (!shared_memory.CreateAnonymous(size.GetArea() *
|
||||
BytesPerPixel(internalformat))) {
|
||||
handle->type = gfx::EMPTY_BUFFER;
|
||||
handle.type = gfx::EMPTY_BUFFER;
|
||||
return;
|
||||
}
|
||||
handle->type = gfx::SHARED_MEMORY_BUFFER;
|
||||
shared_memory.GiveToProcess(child_process, &handle->handle);
|
||||
handle.type = gfx::SHARED_MEMORY_BUFFER;
|
||||
shared_memory.GiveToProcess(child_process, &handle.handle);
|
||||
callback.Run(handle);
|
||||
}
|
||||
|
||||
// static
|
||||
|
@ -21,7 +21,7 @@ class GpuMemoryBufferImplShm : public GpuMemoryBufferImpl {
|
||||
const gfx::Size& size,
|
||||
unsigned internalformat,
|
||||
base::ProcessHandle child_process,
|
||||
gfx::GpuMemoryBufferHandle* handle);
|
||||
const AllocationCallback& callback);
|
||||
|
||||
static bool IsLayoutSupported(const gfx::Size& size, unsigned internalformat);
|
||||
static bool IsUsageSupported(unsigned usage);
|
||||
|
@ -32,15 +32,15 @@ void GpuMemoryBufferImpl::AllocateForChildProcess(
|
||||
unsigned internalformat,
|
||||
unsigned usage,
|
||||
base::ProcessHandle child_process,
|
||||
gfx::GpuMemoryBufferHandle* handle) {
|
||||
const AllocationCallback& callback) {
|
||||
if (GpuMemoryBufferImplShm::IsConfigurationSupported(
|
||||
size, internalformat, usage)) {
|
||||
GpuMemoryBufferImplShm::AllocateSharedMemoryForChildProcess(
|
||||
size, internalformat, child_process, handle);
|
||||
size, internalformat, child_process, callback);
|
||||
return;
|
||||
}
|
||||
|
||||
handle->type = gfx::EMPTY_BUFFER;
|
||||
callback.Run(gfx::GpuMemoryBufferHandle());
|
||||
}
|
||||
|
||||
// static
|
||||
|
Reference in New Issue
Block a user