Index: content/common/child_process_host_impl.cc |
diff --git a/content/common/child_process_host_impl.cc b/content/common/child_process_host_impl.cc |
index c4d209e08773d5b103922d3809f43556e85210dc..a1fa5fc8b0bc557ab21f6b611b1c0c38668abb6c 100644 |
--- a/content/common/child_process_host_impl.cc |
+++ b/content/common/child_process_host_impl.cc |
@@ -11,13 +11,14 @@ |
#include "base/files/file_path.h" |
#include "base/logging.h" |
#include "base/metrics/histogram.h" |
+#include "base/numerics/safe_math.h" |
#include "base/path_service.h" |
#include "base/process/process_metrics.h" |
#include "base/rand_util.h" |
#include "base/strings/stringprintf.h" |
#include "base/third_party/dynamic_annotations/dynamic_annotations.h" |
#include "content/common/child_process_messages.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/public/common/child_process_host_delegate.h" |
#include "content/public/common/content_paths.h" |
#include "content/public/common/content_switches.h" |
@@ -253,8 +254,11 @@ bool ChildProcessHostImpl::OnMessageReceived(const IPC::Message& msg) { |
OnShutdownRequest) |
IPC_MESSAGE_HANDLER(ChildProcessHostMsg_SyncAllocateSharedMemory, |
OnAllocateSharedMemory) |
- IPC_MESSAGE_HANDLER(ChildProcessHostMsg_SyncAllocateGpuMemoryBuffer, |
- OnAllocateGpuMemoryBuffer) |
+ IPC_MESSAGE_HANDLER_DELAY_REPLY( |
+ ChildProcessHostMsg_SyncAllocateGpuMemoryBuffer, |
+ OnAllocateGpuMemoryBuffer) |
+ IPC_MESSAGE_HANDLER(ChildProcessHostMsg_DeletedGpuMemoryBuffer, |
+ OnDeletedGpuMemoryBuffer) |
IPC_MESSAGE_UNHANDLED(handled = false) |
IPC_END_MESSAGE_MAP() |
@@ -310,14 +314,47 @@ void ChildProcessHostImpl::OnShutdownRequest() { |
void ChildProcessHostImpl::OnAllocateGpuMemoryBuffer( |
uint32 width, |
uint32 height, |
- uint32 internalformat, |
- uint32 usage, |
- gfx::GpuMemoryBufferHandle* handle) { |
- handle->type = gfx::SHARED_MEMORY_BUFFER; |
- AllocateSharedMemory( |
- width * height * GpuMemoryBufferImpl::BytesPerPixel(internalformat), |
+ gfx::GpuMemoryBuffer::Format format, |
+ gfx::GpuMemoryBuffer::Usage usage, |
+ IPC::Message* reply) { |
+ base::CheckedNumeric<int> size = width; |
+ size *= height; |
+ if (!size.IsValid()) { |
+ GpuMemoryBufferAllocated(reply, gfx::GpuMemoryBufferHandle()); |
+ return; |
+ } |
+ |
+ // TODO(reveman): Add support for other types of GpuMemoryBuffers. |
+ if (!GpuMemoryBufferImplSharedMemory::IsConfigurationSupported( |
+ gfx::Size(width, height), format, usage)) { |
+ GpuMemoryBufferAllocated(reply, gfx::GpuMemoryBufferHandle()); |
+ return; |
+ } |
+ |
+ // Note: It is safe to use base::Unretained here as the shared memory |
+ // implementation of AllocateForChildProcess() calls this synchronously. |
+ GpuMemoryBufferImplSharedMemory::AllocateForChildProcess( |
+ gfx::Size(width, height), |
+ format, |
peer_handle_, |
- &handle->handle); |
+ base::Bind(&ChildProcessHostImpl::GpuMemoryBufferAllocated, |
+ base::Unretained(this), |
+ reply)); |
+} |
+ |
+void ChildProcessHostImpl::OnDeletedGpuMemoryBuffer( |
+ gfx::GpuMemoryBufferType type, |
+ const gfx::GpuMemoryBufferId& id) { |
+ // Note: Nothing to do here as ownership of shared memory backed |
+ // GpuMemoryBuffers is passed with IPC. |
+} |
+ |
+void ChildProcessHostImpl::GpuMemoryBufferAllocated( |
+ IPC::Message* reply, |
+ const gfx::GpuMemoryBufferHandle& handle) { |
+ ChildProcessHostMsg_SyncAllocateGpuMemoryBuffer::WriteReplyParams(reply, |
+ handle); |
+ Send(reply); |
} |
} // namespace content |