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 "build/build_config.h" |
8 #include "gpu/command_buffer/client/gles2_implementation.h" | 9 #include "gpu/command_buffer/client/gles2_implementation.h" |
9 #include "gpu/command_buffer/common/command_buffer.h" | 10 #include "gpu/command_buffer/common/command_buffer.h" |
10 #include "ppapi/c/pp_errors.h" | 11 #include "ppapi/c/pp_errors.h" |
11 #include "ppapi/proxy/enter_proxy.h" | 12 #include "ppapi/proxy/enter_proxy.h" |
12 #include "ppapi/proxy/plugin_dispatcher.h" | 13 #include "ppapi/proxy/plugin_dispatcher.h" |
13 #include "ppapi/proxy/ppapi_command_buffer_proxy.h" | 14 #include "ppapi/proxy/ppapi_command_buffer_proxy.h" |
14 #include "ppapi/proxy/ppapi_messages.h" | 15 #include "ppapi/proxy/ppapi_messages.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 { |
25 namespace proxy { | 26 namespace proxy { |
26 | 27 |
27 namespace { | 28 namespace { |
28 | 29 |
29 const int32 kCommandBufferSize = 1024 * 1024; | 30 const int32_t kCommandBufferSize = 1024 * 1024; |
30 const int32 kTransferBufferSize = 1024 * 1024; | 31 const int32_t kTransferBufferSize = 1024 * 1024; |
31 | 32 |
32 #if !defined(OS_NACL) | 33 #if !defined(OS_NACL) |
33 base::SharedMemoryHandle TransportSHMHandle( | 34 base::SharedMemoryHandle TransportSHMHandle( |
34 Dispatcher* dispatcher, | 35 Dispatcher* dispatcher, |
35 const base::SharedMemoryHandle& handle) { | 36 const base::SharedMemoryHandle& handle) { |
36 // Don't close the handle, it doesn't belong to us. | 37 // Don't close the handle, it doesn't belong to us. |
37 return dispatcher->ShareSharedMemoryHandleWithRemote(handle); | 38 return dispatcher->ShareSharedMemoryHandleWithRemote(handle); |
38 } | 39 } |
39 #endif // !defined(OS_NACL) | 40 #endif // !defined(OS_NACL) |
40 | 41 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 } | 115 } |
115 | 116 |
116 gpu::CommandBuffer* Graphics3D::GetCommandBuffer() { | 117 gpu::CommandBuffer* Graphics3D::GetCommandBuffer() { |
117 return command_buffer_.get(); | 118 return command_buffer_.get(); |
118 } | 119 } |
119 | 120 |
120 gpu::GpuControl* Graphics3D::GetGpuControl() { | 121 gpu::GpuControl* Graphics3D::GetGpuControl() { |
121 return command_buffer_.get(); | 122 return command_buffer_.get(); |
122 } | 123 } |
123 | 124 |
124 int32 Graphics3D::DoSwapBuffers() { | 125 int32_t Graphics3D::DoSwapBuffers() { |
125 gles2_impl()->SwapBuffers(); | 126 gles2_impl()->SwapBuffers(); |
126 IPC::Message* msg = new PpapiHostMsg_PPBGraphics3D_SwapBuffers( | 127 IPC::Message* msg = new PpapiHostMsg_PPBGraphics3D_SwapBuffers( |
127 API_ID_PPB_GRAPHICS_3D, host_resource()); | 128 API_ID_PPB_GRAPHICS_3D, host_resource()); |
128 msg->set_unblock(true); | 129 msg->set_unblock(true); |
129 PluginDispatcher::GetForResource(this)->Send(msg); | 130 PluginDispatcher::GetForResource(this)->Send(msg); |
130 | 131 |
131 return PP_OK_COMPLETIONPENDING; | 132 return PP_OK_COMPLETIONPENDING; |
132 } | 133 } |
133 | 134 |
134 PPB_Graphics3D_Proxy::PPB_Graphics3D_Proxy(Dispatcher* dispatcher) | 135 PPB_Graphics3D_Proxy::PPB_Graphics3D_Proxy(Dispatcher* dispatcher) |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 IPC_MESSAGE_HANDLER(PpapiMsg_PPBGraphics3D_SwapBuffersACK, | 222 IPC_MESSAGE_HANDLER(PpapiMsg_PPBGraphics3D_SwapBuffersACK, |
222 OnMsgSwapBuffersACK) | 223 OnMsgSwapBuffersACK) |
223 IPC_MESSAGE_UNHANDLED(handled = false) | 224 IPC_MESSAGE_UNHANDLED(handled = false) |
224 | 225 |
225 IPC_END_MESSAGE_MAP() | 226 IPC_END_MESSAGE_MAP() |
226 // FIXME(brettw) handle bad messages! | 227 // FIXME(brettw) handle bad messages! |
227 return handled; | 228 return handled; |
228 } | 229 } |
229 | 230 |
230 #if !defined(OS_NACL) | 231 #if !defined(OS_NACL) |
231 void PPB_Graphics3D_Proxy::OnMsgCreate( | 232 void PPB_Graphics3D_Proxy::OnMsgCreate(PP_Instance instance, |
232 PP_Instance instance, | 233 HostResource share_context, |
233 HostResource share_context, | 234 const std::vector<int32_t>& attribs, |
234 const std::vector<int32_t>& attribs, | 235 HostResource* result, |
235 HostResource* result, | 236 gpu::Capabilities* capabilities, |
236 gpu::Capabilities* capabilities, | 237 SerializedHandle* shared_state, |
237 SerializedHandle* shared_state, | 238 uint64_t* command_buffer_id) { |
238 uint64* command_buffer_id) { | |
239 shared_state->set_null_shmem(); | 239 shared_state->set_null_shmem(); |
240 if (attribs.empty() || | 240 if (attribs.empty() || |
241 attribs.back() != PP_GRAPHICS3DATTRIB_NONE || | 241 attribs.back() != PP_GRAPHICS3DATTRIB_NONE || |
242 !(attribs.size() & 1)) | 242 !(attribs.size() & 1)) |
243 return; // Bad message. | 243 return; // Bad message. |
244 | 244 |
245 thunk::EnterResourceCreation enter(instance); | 245 thunk::EnterResourceCreation enter(instance); |
246 | 246 |
247 if (!enter.succeeded()) | 247 if (!enter.succeeded()) |
248 return; | 248 return; |
249 | 249 |
250 base::SharedMemoryHandle handle = base::SharedMemory::NULLHandle(); | 250 base::SharedMemoryHandle handle = base::SharedMemory::NULLHandle(); |
251 result->SetHostResource( | 251 result->SetHostResource( |
252 instance, | 252 instance, |
253 enter.functions()->CreateGraphics3DRaw(instance, | 253 enter.functions()->CreateGraphics3DRaw(instance, |
254 share_context.host_resource(), | 254 share_context.host_resource(), |
255 &attribs.front(), | 255 &attribs.front(), |
256 capabilities, | 256 capabilities, |
257 &handle, | 257 &handle, |
258 command_buffer_id)); | 258 command_buffer_id)); |
259 if (!result->is_null()) { | 259 if (!result->is_null()) { |
260 shared_state->set_shmem(TransportSHMHandle(dispatcher(), handle), | 260 shared_state->set_shmem(TransportSHMHandle(dispatcher(), handle), |
261 sizeof(gpu::CommandBuffer::State)); | 261 sizeof(gpu::CommandBuffer::State)); |
262 } | 262 } |
263 } | 263 } |
264 | 264 |
265 void PPB_Graphics3D_Proxy::OnMsgSetGetBuffer( | 265 void PPB_Graphics3D_Proxy::OnMsgSetGetBuffer(const HostResource& context, |
266 const HostResource& context, | 266 int32_t transfer_buffer_id) { |
267 int32 transfer_buffer_id) { | |
268 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); | 267 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); |
269 if (enter.succeeded()) | 268 if (enter.succeeded()) |
270 enter.object()->SetGetBuffer(transfer_buffer_id); | 269 enter.object()->SetGetBuffer(transfer_buffer_id); |
271 } | 270 } |
272 | 271 |
273 void PPB_Graphics3D_Proxy::OnMsgWaitForTokenInRange( | 272 void PPB_Graphics3D_Proxy::OnMsgWaitForTokenInRange( |
274 const HostResource& context, | 273 const HostResource& context, |
275 int32 start, | 274 int32_t start, |
276 int32 end, | 275 int32_t end, |
277 gpu::CommandBuffer::State* state, | 276 gpu::CommandBuffer::State* state, |
278 bool* success) { | 277 bool* success) { |
279 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); | 278 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); |
280 if (enter.failed()) { | 279 if (enter.failed()) { |
281 *success = false; | 280 *success = false; |
282 return; | 281 return; |
283 } | 282 } |
284 *state = enter.object()->WaitForTokenInRange(start, end); | 283 *state = enter.object()->WaitForTokenInRange(start, end); |
285 *success = true; | 284 *success = true; |
286 } | 285 } |
287 | 286 |
288 void PPB_Graphics3D_Proxy::OnMsgWaitForGetOffsetInRange( | 287 void PPB_Graphics3D_Proxy::OnMsgWaitForGetOffsetInRange( |
289 const HostResource& context, | 288 const HostResource& context, |
290 int32 start, | 289 int32_t start, |
291 int32 end, | 290 int32_t end, |
292 gpu::CommandBuffer::State* state, | 291 gpu::CommandBuffer::State* state, |
293 bool* success) { | 292 bool* success) { |
294 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); | 293 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); |
295 if (enter.failed()) { | 294 if (enter.failed()) { |
296 *success = false; | 295 *success = false; |
297 return; | 296 return; |
298 } | 297 } |
299 *state = enter.object()->WaitForGetOffsetInRange(start, end); | 298 *state = enter.object()->WaitForGetOffsetInRange(start, end); |
300 *success = true; | 299 *success = true; |
301 } | 300 } |
302 | 301 |
303 void PPB_Graphics3D_Proxy::OnMsgAsyncFlush(const HostResource& context, | 302 void PPB_Graphics3D_Proxy::OnMsgAsyncFlush(const HostResource& context, |
304 int32 put_offset) { | 303 int32_t put_offset) { |
305 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); | 304 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); |
306 if (enter.succeeded()) | 305 if (enter.succeeded()) |
307 enter.object()->Flush(put_offset); | 306 enter.object()->Flush(put_offset); |
308 } | 307 } |
309 | 308 |
310 void PPB_Graphics3D_Proxy::OnMsgCreateTransferBuffer( | 309 void PPB_Graphics3D_Proxy::OnMsgCreateTransferBuffer( |
311 const HostResource& context, | 310 const HostResource& context, |
312 uint32 size, | 311 uint32_t size, |
313 int32* id, | 312 int32_t* id, |
314 SerializedHandle* transfer_buffer) { | 313 SerializedHandle* transfer_buffer) { |
315 transfer_buffer->set_null_shmem(); | 314 transfer_buffer->set_null_shmem(); |
316 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); | 315 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); |
317 if (enter.succeeded()) { | 316 if (enter.succeeded()) { |
318 scoped_refptr<gpu::Buffer> buffer = | 317 scoped_refptr<gpu::Buffer> buffer = |
319 enter.object()->CreateTransferBuffer(size, id); | 318 enter.object()->CreateTransferBuffer(size, id); |
320 if (!buffer.get()) | 319 if (!buffer.get()) |
321 return; | 320 return; |
322 gpu::SharedMemoryBufferBacking* backing = | 321 gpu::SharedMemoryBufferBacking* backing = |
323 static_cast<gpu::SharedMemoryBufferBacking*>(buffer->backing()); | 322 static_cast<gpu::SharedMemoryBufferBacking*>(buffer->backing()); |
324 DCHECK(backing && backing->shared_memory()); | 323 DCHECK(backing && backing->shared_memory()); |
325 transfer_buffer->set_shmem( | 324 transfer_buffer->set_shmem( |
326 TransportSHMHandle(dispatcher(), backing->shared_memory()->handle()), | 325 TransportSHMHandle(dispatcher(), backing->shared_memory()->handle()), |
327 base::checked_cast<uint32_t>(buffer->size())); | 326 base::checked_cast<uint32_t>(buffer->size())); |
328 } else { | 327 } else { |
329 *id = -1; | 328 *id = -1; |
330 } | 329 } |
331 } | 330 } |
332 | 331 |
333 void PPB_Graphics3D_Proxy::OnMsgDestroyTransferBuffer( | 332 void PPB_Graphics3D_Proxy::OnMsgDestroyTransferBuffer( |
334 const HostResource& context, | 333 const HostResource& context, |
335 int32 id) { | 334 int32_t id) { |
336 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); | 335 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); |
337 if (enter.succeeded()) | 336 if (enter.succeeded()) |
338 enter.object()->DestroyTransferBuffer(id); | 337 enter.object()->DestroyTransferBuffer(id); |
339 } | 338 } |
340 | 339 |
341 void PPB_Graphics3D_Proxy::OnMsgSwapBuffers(const HostResource& context) { | 340 void PPB_Graphics3D_Proxy::OnMsgSwapBuffers(const HostResource& context) { |
342 EnterHostFromHostResourceForceCallback<PPB_Graphics3D_API> enter( | 341 EnterHostFromHostResourceForceCallback<PPB_Graphics3D_API> enter( |
343 context, callback_factory_, | 342 context, callback_factory_, |
344 &PPB_Graphics3D_Proxy::SendSwapBuffersACKToPlugin, context); | 343 &PPB_Graphics3D_Proxy::SendSwapBuffersACKToPlugin, context); |
345 if (enter.succeeded()) | 344 if (enter.succeeded()) |
346 enter.SetResult(enter.object()->SwapBuffers(enter.callback())); | 345 enter.SetResult(enter.object()->SwapBuffers(enter.callback())); |
347 } | 346 } |
348 | 347 |
349 void PPB_Graphics3D_Proxy::OnMsgInsertSyncPoint(const HostResource& context, | 348 void PPB_Graphics3D_Proxy::OnMsgInsertSyncPoint(const HostResource& context, |
350 uint32* sync_point) { | 349 uint32_t* sync_point) { |
351 *sync_point = 0; | 350 *sync_point = 0; |
352 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); | 351 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); |
353 if (enter.succeeded()) | 352 if (enter.succeeded()) |
354 *sync_point = enter.object()->InsertSyncPoint(); | 353 *sync_point = enter.object()->InsertSyncPoint(); |
355 } | 354 } |
356 | 355 |
357 void PPB_Graphics3D_Proxy::OnMsgInsertFutureSyncPoint( | 356 void PPB_Graphics3D_Proxy::OnMsgInsertFutureSyncPoint( |
358 const HostResource& context, | 357 const HostResource& context, |
359 uint32* sync_point) { | 358 uint32_t* sync_point) { |
360 *sync_point = 0; | 359 *sync_point = 0; |
361 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); | 360 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); |
362 if (enter.succeeded()) | 361 if (enter.succeeded()) |
363 *sync_point = enter.object()->InsertFutureSyncPoint(); | 362 *sync_point = enter.object()->InsertFutureSyncPoint(); |
364 } | 363 } |
365 | 364 |
366 void PPB_Graphics3D_Proxy::OnMsgRetireSyncPoint(const HostResource& context, | 365 void PPB_Graphics3D_Proxy::OnMsgRetireSyncPoint(const HostResource& context, |
367 uint32 sync_point) { | 366 uint32_t sync_point) { |
368 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); | 367 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); |
369 if (enter.succeeded()) | 368 if (enter.succeeded()) |
370 enter.object()->RetireSyncPoint(sync_point); | 369 enter.object()->RetireSyncPoint(sync_point); |
371 } | 370 } |
372 #endif // !defined(OS_NACL) | 371 #endif // !defined(OS_NACL) |
373 | 372 |
374 void PPB_Graphics3D_Proxy::OnMsgSwapBuffersACK(const HostResource& resource, | 373 void PPB_Graphics3D_Proxy::OnMsgSwapBuffersACK(const HostResource& resource, |
375 int32_t pp_error) { | 374 int32_t pp_error) { |
376 EnterPluginFromHostResource<PPB_Graphics3D_API> enter(resource); | 375 EnterPluginFromHostResource<PPB_Graphics3D_API> enter(resource); |
377 if (enter.succeeded()) | 376 if (enter.succeeded()) |
378 static_cast<Graphics3D*>(enter.object())->SwapBuffersACK(pp_error); | 377 static_cast<Graphics3D*>(enter.object())->SwapBuffersACK(pp_error); |
379 } | 378 } |
380 | 379 |
381 #if !defined(OS_NACL) | 380 #if !defined(OS_NACL) |
382 void PPB_Graphics3D_Proxy::SendSwapBuffersACKToPlugin( | 381 void PPB_Graphics3D_Proxy::SendSwapBuffersACKToPlugin( |
383 int32_t result, | 382 int32_t result, |
384 const HostResource& context) { | 383 const HostResource& context) { |
385 dispatcher()->Send(new PpapiMsg_PPBGraphics3D_SwapBuffersACK( | 384 dispatcher()->Send(new PpapiMsg_PPBGraphics3D_SwapBuffersACK( |
386 API_ID_PPB_GRAPHICS_3D, context, result)); | 385 API_ID_PPB_GRAPHICS_3D, context, result)); |
387 } | 386 } |
388 #endif // !defined(OS_NACL) | 387 #endif // !defined(OS_NACL) |
389 | 388 |
390 } // namespace proxy | 389 } // namespace proxy |
391 } // namespace ppapi | 390 } // namespace ppapi |
OLD | NEW |