Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / ppapi / proxy / ppb_graphics_3d_proxy.cc
index 0d383c9..4e6398d 100644 (file)
@@ -28,10 +28,10 @@ namespace {
 const int32 kCommandBufferSize = 1024 * 1024;
 const int32 kTransferBufferSize = 1024 * 1024;
 
-base::SharedMemoryHandle TransportSHMHandle(Dispatcher* dispatcher,
-                                            base::SharedMemory* shm) {
-  base::PlatformFile source =
-      IPC::PlatformFileForTransitToPlatformFile(shm->handle());
+base::SharedMemoryHandle TransportSHMHandle(
+    Dispatcher* dispatcher,
+    const base::SharedMemoryHandle& handle) {
+  base::PlatformFile source = IPC::PlatformFileForTransitToPlatformFile(handle);
   // Don't close the handle, it doesn't belong to us.
   return dispatcher->ShareHandleWithRemote(source, false);
 }
@@ -52,13 +52,14 @@ Graphics3D::~Graphics3D() {
   DestroyGLES2Impl();
 }
 
-bool Graphics3D::Init(gpu::gles2::GLES2Implementation* share_gles2) {
+bool Graphics3D::Init(gpu::gles2::GLES2Implementation* share_gles2,
+                      const SerializedHandle& shared_state) {
   PluginDispatcher* dispatcher = PluginDispatcher::GetForResource(this);
   if (!dispatcher)
     return false;
 
   command_buffer_.reset(
-      new PpapiCommandBufferProxy(host_resource(), dispatcher));
+      new PpapiCommandBufferProxy(host_resource(), dispatcher, shared_state));
 
   return CreateGLES2Impl(kCommandBufferSize, kTransferBufferSize,
                          share_gles2);
@@ -167,13 +168,15 @@ PP_Resource PPB_Graphics3D_Proxy::CreateProxyResource(
   attribs.push_back(PP_GRAPHICS3DATTRIB_NONE);
 
   HostResource result;
-  dispatcher->Send(new PpapiHostMsg_PPBGraphics3D_Create(
-      API_ID_PPB_GRAPHICS_3D, instance, share_host, attribs, &result));
+  ppapi::proxy::SerializedHandle shared_state;
+  dispatcher->Send(new PpapiHostMsg_PPBGraphics3D_Create(API_ID_PPB_GRAPHICS_3D,
+        instance, share_host, attribs, &result, &shared_state));
+
   if (result.is_null())
     return 0;
 
   scoped_refptr<Graphics3D> graphics_3d(new Graphics3D(result));
-  if (!graphics_3d->Init(share_gles2))
+  if (!graphics_3d->Init(share_gles2, shared_state))
     return 0;
   return graphics_3d->GetReference();
 }
@@ -218,7 +221,9 @@ bool PPB_Graphics3D_Proxy::OnMessageReceived(const IPC::Message& msg) {
 void PPB_Graphics3D_Proxy::OnMsgCreate(PP_Instance instance,
                                        HostResource share_context,
                                        const std::vector<int32_t>& attribs,
-                                       HostResource* result) {
+                                       HostResource* result,
+                                       SerializedHandle* shared_state) {
+  shared_state->set_null_shmem();
   if (attribs.empty() ||
       attribs.back() != PP_GRAPHICS3DATTRIB_NONE ||
       !(attribs.size() & 1))
@@ -226,12 +231,19 @@ void PPB_Graphics3D_Proxy::OnMsgCreate(PP_Instance instance,
 
   thunk::EnterResourceCreation enter(instance);
 
-  if (enter.succeeded()) {
-    result->SetHostResource(
+  if (!enter.succeeded())
+    return;
+
+  base::SharedMemoryHandle handle = IPC::InvalidPlatformFileForTransit();
+  result->SetHostResource(
       instance,
       enter.functions()->CreateGraphics3DRaw(instance,
                                              share_context.host_resource(),
-                                             &attribs.front()));
+                                             &attribs.front(),
+                                             &handle));
+  if (!result->is_null()) {
+    shared_state->set_shmem(TransportSHMHandle(dispatcher(), handle),
+                            sizeof(gpu::CommandBuffer::State));
   }
 }
 
@@ -284,19 +296,19 @@ void PPB_Graphics3D_Proxy::OnMsgCreateTransferBuffer(
     const HostResource& context,
     uint32 size,
     int32* id,
-    ppapi::proxy::SerializedHandle* transfer_buffer) {
+    SerializedHandle* transfer_buffer) {
   transfer_buffer->set_null_shmem();
   EnterHostFromHostResource<PPB_Graphics3D_API> enter(context);
   if (enter.succeeded()) {
     scoped_refptr<gpu::Buffer> buffer =
         enter.object()->CreateTransferBuffer(size, id);
-    if (!buffer)
+    if (!buffer.get())
       return;
     gpu::SharedMemoryBufferBacking* backing =
         static_cast<gpu::SharedMemoryBufferBacking*>(buffer->backing());
     DCHECK(backing && backing->shared_memory());
     transfer_buffer->set_shmem(
-        TransportSHMHandle(dispatcher(), backing->shared_memory()),
+        TransportSHMHandle(dispatcher(), backing->shared_memory()->handle()),
         buffer->size());
   } else {
     *id = -1;