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 "base/numerics/safe_conversions.h" | 7 #include "base/numerics/safe_conversions.h" |
8 #include "gpu/command_buffer/client/gles2_implementation.h" | 8 #include "gpu/command_buffer/client/gles2_implementation.h" |
9 #include "gpu/command_buffer/common/command_buffer.h" | 9 #include "gpu/command_buffer/common/command_buffer.h" |
10 #include "ppapi/c/pp_errors.h" | 10 #include "ppapi/c/pp_errors.h" |
11 #include "ppapi/proxy/enter_proxy.h" | 11 #include "ppapi/proxy/enter_proxy.h" |
12 #include "ppapi/proxy/plugin_dispatcher.h" | 12 #include "ppapi/proxy/plugin_dispatcher.h" |
13 #include "ppapi/proxy/ppapi_command_buffer_proxy.h" | 13 #include "ppapi/proxy/ppapi_command_buffer_proxy.h" |
14 #include "ppapi/proxy/ppapi_messages.h" | 14 #include "ppapi/proxy/ppapi_messages.h" |
| 15 #include "ppapi/shared_impl/command_buffer_id_pair.h" |
15 #include "ppapi/shared_impl/ppapi_globals.h" | 16 #include "ppapi/shared_impl/ppapi_globals.h" |
16 #include "ppapi/thunk/enter.h" | 17 #include "ppapi/thunk/enter.h" |
17 #include "ppapi/thunk/resource_creation_api.h" | 18 #include "ppapi/thunk/resource_creation_api.h" |
18 #include "ppapi/thunk/thunk.h" | 19 #include "ppapi/thunk/thunk.h" |
19 | 20 |
20 using ppapi::thunk::EnterResourceNoLock; | 21 using ppapi::thunk::EnterResourceNoLock; |
21 using ppapi::thunk::PPB_Graphics3D_API; | 22 using ppapi::thunk::PPB_Graphics3D_API; |
22 using ppapi::thunk::ResourceCreationAPI; | 23 using ppapi::thunk::ResourceCreationAPI; |
23 | 24 |
24 namespace ppapi { | 25 namespace ppapi { |
(...skipping 24 matching lines...) Expand all Loading... |
49 Graphics3D::Graphics3D(const HostResource& resource) | 50 Graphics3D::Graphics3D(const HostResource& resource) |
50 : PPB_Graphics3D_Shared(resource) { | 51 : PPB_Graphics3D_Shared(resource) { |
51 } | 52 } |
52 | 53 |
53 Graphics3D::~Graphics3D() { | 54 Graphics3D::~Graphics3D() { |
54 DestroyGLES2Impl(); | 55 DestroyGLES2Impl(); |
55 } | 56 } |
56 | 57 |
57 bool Graphics3D::Init(gpu::gles2::GLES2Implementation* share_gles2, | 58 bool Graphics3D::Init(gpu::gles2::GLES2Implementation* share_gles2, |
58 const gpu::Capabilities& capabilities, | 59 const gpu::Capabilities& capabilities, |
59 const SerializedHandle& shared_state) { | 60 const SerializedHandle& shared_state, |
| 61 gpu::CommandBufferNamespace namespace_id, |
| 62 uint64_t command_buffer_id) { |
60 PluginDispatcher* dispatcher = PluginDispatcher::GetForResource(this); | 63 PluginDispatcher* dispatcher = PluginDispatcher::GetForResource(this); |
61 if (!dispatcher) | 64 if (!dispatcher) |
62 return false; | 65 return false; |
63 | 66 |
64 command_buffer_.reset(new PpapiCommandBufferProxy( | 67 command_buffer_.reset(new PpapiCommandBufferProxy( |
65 host_resource(), dispatcher, capabilities, shared_state)); | 68 host_resource(), dispatcher, capabilities, shared_state, |
| 69 namespace_id, command_buffer_id)); |
66 | 70 |
67 return CreateGLES2Impl(kCommandBufferSize, kTransferBufferSize, | 71 return CreateGLES2Impl(kCommandBufferSize, kTransferBufferSize, |
68 share_gles2); | 72 share_gles2); |
69 } | 73 } |
70 | 74 |
71 PP_Bool Graphics3D::SetGetBuffer(int32_t /* transfer_buffer_id */) { | 75 PP_Bool Graphics3D::SetGetBuffer(int32_t /* transfer_buffer_id */) { |
72 return PP_FALSE; | 76 return PP_FALSE; |
73 } | 77 } |
74 | 78 |
75 PP_Bool Graphics3D::Flush(int32_t put_offset) { | 79 PP_Bool Graphics3D::Flush(int32_t put_offset) { |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 attr += 2) { | 170 attr += 2) { |
167 attribs.push_back(attr[0]); | 171 attribs.push_back(attr[0]); |
168 attribs.push_back(attr[1]); | 172 attribs.push_back(attr[1]); |
169 } | 173 } |
170 } | 174 } |
171 attribs.push_back(PP_GRAPHICS3DATTRIB_NONE); | 175 attribs.push_back(PP_GRAPHICS3DATTRIB_NONE); |
172 | 176 |
173 HostResource result; | 177 HostResource result; |
174 gpu::Capabilities capabilities; | 178 gpu::Capabilities capabilities; |
175 ppapi::proxy::SerializedHandle shared_state; | 179 ppapi::proxy::SerializedHandle shared_state; |
| 180 CommandBufferIDPair id_pair; |
176 dispatcher->Send(new PpapiHostMsg_PPBGraphics3D_Create(API_ID_PPB_GRAPHICS_3D, | 181 dispatcher->Send(new PpapiHostMsg_PPBGraphics3D_Create(API_ID_PPB_GRAPHICS_3D, |
177 instance, share_host, attribs, &result, &capabilities, &shared_state)); | 182 instance, share_host, attribs, &result, &capabilities, &shared_state, |
| 183 &id_pair)); |
178 | 184 |
179 if (result.is_null()) | 185 if (result.is_null()) |
180 return 0; | 186 return 0; |
181 | 187 |
182 scoped_refptr<Graphics3D> graphics_3d(new Graphics3D(result)); | 188 scoped_refptr<Graphics3D> graphics_3d(new Graphics3D(result)); |
183 if (!graphics_3d->Init(share_gles2, capabilities, shared_state)) | 189 if (!graphics_3d->Init(share_gles2, capabilities, shared_state, |
| 190 id_pair.namespace_id, id_pair.command_buffer_id)) { |
184 return 0; | 191 return 0; |
| 192 } |
185 return graphics_3d->GetReference(); | 193 return graphics_3d->GetReference(); |
186 } | 194 } |
187 | 195 |
188 bool PPB_Graphics3D_Proxy::OnMessageReceived(const IPC::Message& msg) { | 196 bool PPB_Graphics3D_Proxy::OnMessageReceived(const IPC::Message& msg) { |
189 bool handled = true; | 197 bool handled = true; |
190 IPC_BEGIN_MESSAGE_MAP(PPB_Graphics3D_Proxy, msg) | 198 IPC_BEGIN_MESSAGE_MAP(PPB_Graphics3D_Proxy, msg) |
191 #if !defined(OS_NACL) | 199 #if !defined(OS_NACL) |
192 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_Create, | 200 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_Create, |
193 OnMsgCreate) | 201 OnMsgCreate) |
194 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_SetGetBuffer, | 202 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_SetGetBuffer, |
(...skipping 20 matching lines...) Expand all Loading... |
215 IPC_MESSAGE_HANDLER(PpapiMsg_PPBGraphics3D_SwapBuffersACK, | 223 IPC_MESSAGE_HANDLER(PpapiMsg_PPBGraphics3D_SwapBuffersACK, |
216 OnMsgSwapBuffersACK) | 224 OnMsgSwapBuffersACK) |
217 IPC_MESSAGE_UNHANDLED(handled = false) | 225 IPC_MESSAGE_UNHANDLED(handled = false) |
218 | 226 |
219 IPC_END_MESSAGE_MAP() | 227 IPC_END_MESSAGE_MAP() |
220 // FIXME(brettw) handle bad messages! | 228 // FIXME(brettw) handle bad messages! |
221 return handled; | 229 return handled; |
222 } | 230 } |
223 | 231 |
224 #if !defined(OS_NACL) | 232 #if !defined(OS_NACL) |
225 void PPB_Graphics3D_Proxy::OnMsgCreate(PP_Instance instance, | 233 void PPB_Graphics3D_Proxy::OnMsgCreate( |
226 HostResource share_context, | 234 PP_Instance instance, |
227 const std::vector<int32_t>& attribs, | 235 HostResource share_context, |
228 HostResource* result, | 236 const std::vector<int32_t>& attribs, |
229 gpu::Capabilities* capabilities, | 237 HostResource* result, |
230 SerializedHandle* shared_state) { | 238 gpu::Capabilities* capabilities, |
| 239 SerializedHandle* shared_state, |
| 240 CommandBufferIDPair* id_pair) { |
231 shared_state->set_null_shmem(); | 241 shared_state->set_null_shmem(); |
232 if (attribs.empty() || | 242 if (attribs.empty() || |
233 attribs.back() != PP_GRAPHICS3DATTRIB_NONE || | 243 attribs.back() != PP_GRAPHICS3DATTRIB_NONE || |
234 !(attribs.size() & 1)) | 244 !(attribs.size() & 1)) |
235 return; // Bad message. | 245 return; // Bad message. |
236 | 246 |
237 thunk::EnterResourceCreation enter(instance); | 247 thunk::EnterResourceCreation enter(instance); |
238 | 248 |
239 if (!enter.succeeded()) | 249 if (!enter.succeeded()) |
240 return; | 250 return; |
241 | 251 |
242 base::SharedMemoryHandle handle = base::SharedMemory::NULLHandle(); | 252 base::SharedMemoryHandle handle = base::SharedMemory::NULLHandle(); |
243 result->SetHostResource( | 253 result->SetHostResource( |
244 instance, | 254 instance, |
245 enter.functions()->CreateGraphics3DRaw(instance, | 255 enter.functions()->CreateGraphics3DRaw(instance, |
246 share_context.host_resource(), | 256 share_context.host_resource(), |
247 &attribs.front(), | 257 &attribs.front(), |
248 capabilities, | 258 capabilities, |
249 &handle)); | 259 &handle, |
| 260 id_pair)); |
250 if (!result->is_null()) { | 261 if (!result->is_null()) { |
251 shared_state->set_shmem(TransportSHMHandle(dispatcher(), handle), | 262 shared_state->set_shmem(TransportSHMHandle(dispatcher(), handle), |
252 sizeof(gpu::CommandBuffer::State)); | 263 sizeof(gpu::CommandBuffer::State)); |
253 } | 264 } |
254 } | 265 } |
255 | 266 |
256 void PPB_Graphics3D_Proxy::OnMsgSetGetBuffer( | 267 void PPB_Graphics3D_Proxy::OnMsgSetGetBuffer( |
257 const HostResource& context, | 268 const HostResource& context, |
258 int32 transfer_buffer_id) { | 269 int32 transfer_buffer_id) { |
259 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); | 270 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 void PPB_Graphics3D_Proxy::SendSwapBuffersACKToPlugin( | 384 void PPB_Graphics3D_Proxy::SendSwapBuffersACKToPlugin( |
374 int32_t result, | 385 int32_t result, |
375 const HostResource& context) { | 386 const HostResource& context) { |
376 dispatcher()->Send(new PpapiMsg_PPBGraphics3D_SwapBuffersACK( | 387 dispatcher()->Send(new PpapiMsg_PPBGraphics3D_SwapBuffersACK( |
377 API_ID_PPB_GRAPHICS_3D, context, result)); | 388 API_ID_PPB_GRAPHICS_3D, context, result)); |
378 } | 389 } |
379 #endif // !defined(OS_NACL) | 390 #endif // !defined(OS_NACL) |
380 | 391 |
381 } // namespace proxy | 392 } // namespace proxy |
382 } // namespace ppapi | 393 } // namespace ppapi |
OLD | NEW |