| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ppapi/proxy/ppb_graphics_3d_proxy.h" | 5 #include "ppapi/proxy/ppb_graphics_3d_proxy.h" |
| 6 | 6 |
| 7 #include "gpu/command_buffer/client/gles2_implementation.h" | 7 #include "gpu/command_buffer/client/gles2_implementation.h" |
| 8 #include "gpu/command_buffer/common/command_buffer.h" | 8 #include "gpu/command_buffer/common/command_buffer.h" |
| 9 #include "ppapi/c/pp_errors.h" | 9 #include "ppapi/c/pp_errors.h" |
| 10 #include "ppapi/proxy/enter_proxy.h" | 10 #include "ppapi/proxy/enter_proxy.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 using ppapi::thunk::ResourceCreationAPI; | 21 using ppapi::thunk::ResourceCreationAPI; |
| 22 | 22 |
| 23 namespace ppapi { | 23 namespace ppapi { |
| 24 namespace proxy { | 24 namespace proxy { |
| 25 | 25 |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 const int32 kCommandBufferSize = 1024 * 1024; | 28 const int32 kCommandBufferSize = 1024 * 1024; |
| 29 const int32 kTransferBufferSize = 1024 * 1024; | 29 const int32 kTransferBufferSize = 1024 * 1024; |
| 30 | 30 |
| 31 base::SharedMemoryHandle TransportSHMHandle(Dispatcher* dispatcher, | 31 base::SharedMemoryHandle TransportSHMHandle( |
| 32 base::SharedMemory* shm) { | 32 Dispatcher* dispatcher, |
| 33 base::PlatformFile source = | 33 const base::SharedMemoryHandle& handle) { |
| 34 IPC::PlatformFileForTransitToPlatformFile(shm->handle()); | 34 base::PlatformFile source = IPC::PlatformFileForTransitToPlatformFile(handle); |
| 35 // Don't close the handle, it doesn't belong to us. | 35 // Don't close the handle, it doesn't belong to us. |
| 36 return dispatcher->ShareHandleWithRemote(source, false); | 36 return dispatcher->ShareHandleWithRemote(source, false); |
| 37 } | 37 } |
| 38 | 38 |
| 39 gpu::CommandBuffer::State GetErrorState() { | 39 gpu::CommandBuffer::State GetErrorState() { |
| 40 gpu::CommandBuffer::State error_state; | 40 gpu::CommandBuffer::State error_state; |
| 41 error_state.error = gpu::error::kGenericError; | 41 error_state.error = gpu::error::kGenericError; |
| 42 return error_state; | 42 return error_state; |
| 43 } | 43 } |
| 44 | 44 |
| 45 } // namespace | 45 } // namespace |
| 46 | 46 |
| 47 Graphics3D::Graphics3D(const HostResource& resource) | 47 Graphics3D::Graphics3D(const HostResource& resource) |
| 48 : PPB_Graphics3D_Shared(resource) { | 48 : PPB_Graphics3D_Shared(resource) { |
| 49 } | 49 } |
| 50 | 50 |
| 51 Graphics3D::~Graphics3D() { | 51 Graphics3D::~Graphics3D() { |
| 52 DestroyGLES2Impl(); | 52 DestroyGLES2Impl(); |
| 53 } | 53 } |
| 54 | 54 |
| 55 bool Graphics3D::Init(gpu::gles2::GLES2Implementation* share_gles2) { | 55 bool Graphics3D::Init(gpu::gles2::GLES2Implementation* share_gles2, |
| 56 const SerializedHandle& shared_state) { |
| 56 PluginDispatcher* dispatcher = PluginDispatcher::GetForResource(this); | 57 PluginDispatcher* dispatcher = PluginDispatcher::GetForResource(this); |
| 57 if (!dispatcher) | 58 if (!dispatcher) |
| 58 return false; | 59 return false; |
| 59 | 60 |
| 60 command_buffer_.reset( | 61 command_buffer_.reset( |
| 61 new PpapiCommandBufferProxy(host_resource(), dispatcher)); | 62 new PpapiCommandBufferProxy(host_resource(), dispatcher, shared_state)); |
| 62 | 63 |
| 63 return CreateGLES2Impl(kCommandBufferSize, kTransferBufferSize, | 64 return CreateGLES2Impl(kCommandBufferSize, kTransferBufferSize, |
| 64 share_gles2); | 65 share_gles2); |
| 65 } | 66 } |
| 66 | 67 |
| 67 PP_Bool Graphics3D::SetGetBuffer(int32_t /* transfer_buffer_id */) { | 68 PP_Bool Graphics3D::SetGetBuffer(int32_t /* transfer_buffer_id */) { |
| 68 return PP_FALSE; | 69 return PP_FALSE; |
| 69 } | 70 } |
| 70 | 71 |
| 71 PP_Bool Graphics3D::Flush(int32_t put_offset) { | 72 PP_Bool Graphics3D::Flush(int32_t put_offset) { |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 for (const int32_t* attr = attrib_list; | 161 for (const int32_t* attr = attrib_list; |
| 161 attr[0] != PP_GRAPHICS3DATTRIB_NONE; | 162 attr[0] != PP_GRAPHICS3DATTRIB_NONE; |
| 162 attr += 2) { | 163 attr += 2) { |
| 163 attribs.push_back(attr[0]); | 164 attribs.push_back(attr[0]); |
| 164 attribs.push_back(attr[1]); | 165 attribs.push_back(attr[1]); |
| 165 } | 166 } |
| 166 } | 167 } |
| 167 attribs.push_back(PP_GRAPHICS3DATTRIB_NONE); | 168 attribs.push_back(PP_GRAPHICS3DATTRIB_NONE); |
| 168 | 169 |
| 169 HostResource result; | 170 HostResource result; |
| 170 dispatcher->Send(new PpapiHostMsg_PPBGraphics3D_Create( | 171 ppapi::proxy::SerializedHandle shared_state; |
| 171 API_ID_PPB_GRAPHICS_3D, instance, share_host, attribs, &result)); | 172 dispatcher->Send(new PpapiHostMsg_PPBGraphics3D_Create(API_ID_PPB_GRAPHICS_3D, |
| 173 instance, share_host, attribs, &result, &shared_state)); |
| 174 |
| 172 if (result.is_null()) | 175 if (result.is_null()) |
| 173 return 0; | 176 return 0; |
| 174 | 177 |
| 175 scoped_refptr<Graphics3D> graphics_3d(new Graphics3D(result)); | 178 scoped_refptr<Graphics3D> graphics_3d(new Graphics3D(result)); |
| 176 if (!graphics_3d->Init(share_gles2)) | 179 if (!graphics_3d->Init(share_gles2, shared_state)) |
| 177 return 0; | 180 return 0; |
| 178 return graphics_3d->GetReference(); | 181 return graphics_3d->GetReference(); |
| 179 } | 182 } |
| 180 | 183 |
| 181 bool PPB_Graphics3D_Proxy::OnMessageReceived(const IPC::Message& msg) { | 184 bool PPB_Graphics3D_Proxy::OnMessageReceived(const IPC::Message& msg) { |
| 182 bool handled = true; | 185 bool handled = true; |
| 183 IPC_BEGIN_MESSAGE_MAP(PPB_Graphics3D_Proxy, msg) | 186 IPC_BEGIN_MESSAGE_MAP(PPB_Graphics3D_Proxy, msg) |
| 184 #if !defined(OS_NACL) | 187 #if !defined(OS_NACL) |
| 185 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_Create, | 188 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_Create, |
| 186 OnMsgCreate) | 189 OnMsgCreate) |
| (...skipping 24 matching lines...) Expand all Loading... |
| 211 | 214 |
| 212 IPC_END_MESSAGE_MAP() | 215 IPC_END_MESSAGE_MAP() |
| 213 // FIXME(brettw) handle bad messages! | 216 // FIXME(brettw) handle bad messages! |
| 214 return handled; | 217 return handled; |
| 215 } | 218 } |
| 216 | 219 |
| 217 #if !defined(OS_NACL) | 220 #if !defined(OS_NACL) |
| 218 void PPB_Graphics3D_Proxy::OnMsgCreate(PP_Instance instance, | 221 void PPB_Graphics3D_Proxy::OnMsgCreate(PP_Instance instance, |
| 219 HostResource share_context, | 222 HostResource share_context, |
| 220 const std::vector<int32_t>& attribs, | 223 const std::vector<int32_t>& attribs, |
| 221 HostResource* result) { | 224 HostResource* result, |
| 225 SerializedHandle* shared_state) { |
| 226 shared_state->set_null_shmem(); |
| 222 if (attribs.empty() || | 227 if (attribs.empty() || |
| 223 attribs.back() != PP_GRAPHICS3DATTRIB_NONE || | 228 attribs.back() != PP_GRAPHICS3DATTRIB_NONE || |
| 224 !(attribs.size() & 1)) | 229 !(attribs.size() & 1)) |
| 225 return; // Bad message. | 230 return; // Bad message. |
| 226 | 231 |
| 227 thunk::EnterResourceCreation enter(instance); | 232 thunk::EnterResourceCreation enter(instance); |
| 228 | 233 |
| 229 if (enter.succeeded()) { | 234 if (!enter.succeeded()) |
| 230 result->SetHostResource( | 235 return; |
| 236 |
| 237 base::SharedMemoryHandle handle = IPC::InvalidPlatformFileForTransit(); |
| 238 result->SetHostResource( |
| 231 instance, | 239 instance, |
| 232 enter.functions()->CreateGraphics3DRaw(instance, | 240 enter.functions()->CreateGraphics3DRaw(instance, |
| 233 share_context.host_resource(), | 241 share_context.host_resource(), |
| 234 &attribs.front())); | 242 &attribs.front(), |
| 243 &handle)); |
| 244 if (!result->is_null()) { |
| 245 shared_state->set_shmem(TransportSHMHandle(dispatcher(), handle), |
| 246 sizeof(gpu::CommandBuffer::State)); |
| 235 } | 247 } |
| 236 } | 248 } |
| 237 | 249 |
| 238 void PPB_Graphics3D_Proxy::OnMsgSetGetBuffer( | 250 void PPB_Graphics3D_Proxy::OnMsgSetGetBuffer( |
| 239 const HostResource& context, | 251 const HostResource& context, |
| 240 int32 transfer_buffer_id) { | 252 int32 transfer_buffer_id) { |
| 241 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); | 253 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); |
| 242 if (enter.succeeded()) | 254 if (enter.succeeded()) |
| 243 enter.object()->SetGetBuffer(transfer_buffer_id); | 255 enter.object()->SetGetBuffer(transfer_buffer_id); |
| 244 } | 256 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 int32 put_offset) { | 289 int32 put_offset) { |
| 278 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); | 290 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); |
| 279 if (enter.succeeded()) | 291 if (enter.succeeded()) |
| 280 enter.object()->Flush(put_offset); | 292 enter.object()->Flush(put_offset); |
| 281 } | 293 } |
| 282 | 294 |
| 283 void PPB_Graphics3D_Proxy::OnMsgCreateTransferBuffer( | 295 void PPB_Graphics3D_Proxy::OnMsgCreateTransferBuffer( |
| 284 const HostResource& context, | 296 const HostResource& context, |
| 285 uint32 size, | 297 uint32 size, |
| 286 int32* id, | 298 int32* id, |
| 287 ppapi::proxy::SerializedHandle* transfer_buffer) { | 299 SerializedHandle* transfer_buffer) { |
| 288 transfer_buffer->set_null_shmem(); | 300 transfer_buffer->set_null_shmem(); |
| 289 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); | 301 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); |
| 290 if (enter.succeeded()) { | 302 if (enter.succeeded()) { |
| 291 scoped_refptr<gpu::Buffer> buffer = | 303 scoped_refptr<gpu::Buffer> buffer = |
| 292 enter.object()->CreateTransferBuffer(size, id); | 304 enter.object()->CreateTransferBuffer(size, id); |
| 293 if (!buffer.get()) | 305 if (!buffer.get()) |
| 294 return; | 306 return; |
| 295 gpu::SharedMemoryBufferBacking* backing = | 307 gpu::SharedMemoryBufferBacking* backing = |
| 296 static_cast<gpu::SharedMemoryBufferBacking*>(buffer->backing()); | 308 static_cast<gpu::SharedMemoryBufferBacking*>(buffer->backing()); |
| 297 DCHECK(backing && backing->shared_memory()); | 309 DCHECK(backing && backing->shared_memory()); |
| 298 transfer_buffer->set_shmem( | 310 transfer_buffer->set_shmem( |
| 299 TransportSHMHandle(dispatcher(), backing->shared_memory()), | 311 TransportSHMHandle(dispatcher(), backing->shared_memory()->handle()), |
| 300 buffer->size()); | 312 buffer->size()); |
| 301 } else { | 313 } else { |
| 302 *id = -1; | 314 *id = -1; |
| 303 } | 315 } |
| 304 } | 316 } |
| 305 | 317 |
| 306 void PPB_Graphics3D_Proxy::OnMsgDestroyTransferBuffer( | 318 void PPB_Graphics3D_Proxy::OnMsgDestroyTransferBuffer( |
| 307 const HostResource& context, | 319 const HostResource& context, |
| 308 int32 id) { | 320 int32 id) { |
| 309 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); | 321 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 int32_t result, | 368 int32_t result, |
| 357 const HostResource& context) { | 369 const HostResource& context) { |
| 358 dispatcher()->Send(new PpapiMsg_PPBGraphics3D_SwapBuffersACK( | 370 dispatcher()->Send(new PpapiMsg_PPBGraphics3D_SwapBuffersACK( |
| 359 API_ID_PPB_GRAPHICS_3D, context, result)); | 371 API_ID_PPB_GRAPHICS_3D, context, result)); |
| 360 } | 372 } |
| 361 #endif // !defined(OS_NACL) | 373 #endif // !defined(OS_NACL) |
| 362 | 374 |
| 363 } // namespace proxy | 375 } // namespace proxy |
| 364 } // namespace ppapi | 376 } // namespace ppapi |
| 365 | 377 |
| OLD | NEW |