OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ppapi/proxy/ppb_graphics_3d_proxy.h" | |
6 | |
7 #include "gpu/command_buffer/client/gles2_implementation.h" | |
8 #include "ppapi/c/pp_errors.h" | |
9 #include "ppapi/proxy/enter_proxy.h" | |
10 #include "ppapi/proxy/plugin_dispatcher.h" | |
11 #include "ppapi/proxy/ppapi_messages.h" | |
12 #include "ppapi/thunk/enter.h" | |
13 #include "ppapi/thunk/resource_creation_api.h" | |
14 #include "ppapi/thunk/thunk.h" | |
15 | |
16 using ppapi::thunk::EnterFunctionNoLock; | |
17 using ppapi::thunk::EnterResourceNoLock; | |
18 using ppapi::thunk::PPB_Graphics3D_API; | |
19 using ppapi::thunk::ResourceCreationAPI; | |
20 | |
21 namespace pp { | |
22 namespace proxy { | |
23 | |
24 namespace { | |
25 const int32 kCommandBufferSize = 1024 * 1024; | |
26 const int32 kTransferBufferSize = 1024 * 1024; | |
27 | |
28 class CommandBuffer : public gpu::CommandBuffer { | |
29 public: | |
30 CommandBuffer(const HostResource& resource, PluginDispatcher* dispatcher); | |
31 virtual ~CommandBuffer(); | |
32 | |
33 // gpu::CommandBuffer implementation: | |
34 virtual bool Initialize(int32 size); | |
35 virtual bool Initialize(base::SharedMemory* buffer, int32 size); | |
36 virtual gpu::Buffer GetRingBuffer(); | |
37 virtual State GetState(); | |
38 virtual void Flush(int32 put_offset); | |
39 virtual State FlushSync(int32 put_offset, int32 last_known_get); | |
40 virtual void SetGetOffset(int32 get_offset); | |
41 virtual int32 CreateTransferBuffer(size_t size, int32 id_request); | |
42 virtual int32 RegisterTransferBuffer(base::SharedMemory* shared_memory, | |
43 size_t size, | |
44 int32 id_request); | |
45 virtual void DestroyTransferBuffer(int32 id); | |
46 virtual gpu::Buffer GetTransferBuffer(int32 handle); | |
47 virtual void SetToken(int32 token); | |
48 virtual void SetParseError(gpu::error::Error error); | |
49 virtual void SetContextLostReason(gpu::error::ContextLostReason reason); | |
50 | |
51 private: | |
52 bool Send(IPC::Message* msg); | |
53 void UpdateState(const gpu::CommandBuffer::State& state); | |
54 | |
55 int32 num_entries_; | |
56 scoped_ptr<base::SharedMemory> ring_buffer_; | |
57 | |
58 typedef base::hash_map<int32, gpu::Buffer> TransferBufferMap; | |
59 TransferBufferMap transfer_buffers_; | |
60 | |
61 State last_state_; | |
62 | |
63 HostResource resource_; | |
64 PluginDispatcher* dispatcher_; | |
65 | |
66 DISALLOW_COPY_AND_ASSIGN(CommandBuffer); | |
67 }; | |
68 | |
69 CommandBuffer::CommandBuffer(const HostResource& resource, | |
70 PluginDispatcher* dispatcher) | |
71 : num_entries_(0), | |
72 resource_(resource), | |
73 dispatcher_(dispatcher) { | |
74 } | |
75 | |
76 CommandBuffer::~CommandBuffer() { | |
77 // Delete all the locally cached shared memory objects, closing the handle | |
78 // in this process. | |
79 for (TransferBufferMap::iterator it = transfer_buffers_.begin(); | |
80 it != transfer_buffers_.end(); ++it) { | |
81 delete it->second.shared_memory; | |
82 it->second.shared_memory = NULL; | |
83 } | |
84 } | |
85 | |
86 bool CommandBuffer::Initialize(int32 size) { | |
87 DCHECK(!ring_buffer_.get()); | |
88 | |
89 // Initialize the service. Assuming we are sandboxed, the GPU | |
90 // process is responsible for duplicating the handle. This might not be true | |
91 // for NaCl. | |
92 base::SharedMemoryHandle handle; | |
93 if (Send(new PpapiHostMsg_PPBGraphics3D_InitCommandBuffer( | |
94 INTERFACE_ID_PPB_GRAPHICS_3D, resource_, size, &handle)) && | |
95 base::SharedMemory::IsHandleValid(handle)) { | |
96 ring_buffer_.reset(new base::SharedMemory(handle, false)); | |
97 if (ring_buffer_->Map(size)) { | |
98 num_entries_ = size / sizeof(gpu::CommandBufferEntry); | |
99 return true; | |
100 } | |
101 | |
102 ring_buffer_.reset(); | |
103 } | |
104 | |
105 return false; | |
106 } | |
107 | |
108 bool CommandBuffer::Initialize(base::SharedMemory* buffer, int32 size) { | |
109 // Not implemented in proxy. | |
110 NOTREACHED(); | |
111 return false; | |
112 } | |
113 | |
114 gpu::Buffer CommandBuffer::GetRingBuffer() { | |
115 // Return locally cached ring buffer. | |
116 gpu::Buffer buffer; | |
117 buffer.ptr = ring_buffer_->memory(); | |
118 buffer.size = num_entries_ * sizeof(gpu::CommandBufferEntry); | |
119 buffer.shared_memory = ring_buffer_.get(); | |
120 return buffer; | |
121 } | |
122 | |
123 gpu::CommandBuffer::State CommandBuffer::GetState() { | |
124 // Send will flag state with lost context if IPC fails. | |
125 if (last_state_.error == gpu::error::kNoError) { | |
126 gpu::CommandBuffer::State state; | |
127 if (Send(new PpapiHostMsg_PPBGraphics3D_GetState( | |
128 INTERFACE_ID_PPB_GRAPHICS_3D, resource_, &state))) | |
129 UpdateState(state); | |
130 } | |
131 | |
132 return last_state_; | |
133 } | |
134 | |
135 void CommandBuffer::Flush(int32 put_offset) { | |
136 if (last_state_.error != gpu::error::kNoError) | |
137 return; | |
138 | |
139 IPC::Message* message = new PpapiHostMsg_PPBGraphics3D_AsyncFlush( | |
140 INTERFACE_ID_PPB_GRAPHICS_3D, resource_, put_offset); | |
141 | |
142 // Do not let a synchronous flush hold up this message. If this handler is | |
143 // deferred until after the synchronous flush completes, it will overwrite the | |
144 // cached last_state_ with out-of-date data. | |
145 message->set_unblock(true); | |
146 Send(message); | |
147 } | |
148 | |
149 gpu::CommandBuffer::State CommandBuffer::FlushSync(int32 put_offset, | |
150 int32 last_known_get) { | |
151 if (last_known_get == last_state_.get_offset) { | |
152 // Send will flag state with lost context if IPC fails. | |
153 if (last_state_.error == gpu::error::kNoError) { | |
154 gpu::CommandBuffer::State state; | |
155 if (Send(new PpapiHostMsg_PPBGraphics3D_Flush( | |
156 INTERFACE_ID_PPB_GRAPHICS_3D, resource_, put_offset, | |
157 last_known_get, &state))) | |
158 UpdateState(state); | |
159 } | |
160 } else { | |
161 Flush(put_offset); | |
162 } | |
163 | |
164 return last_state_; | |
165 } | |
166 | |
167 void CommandBuffer::SetGetOffset(int32 get_offset) { | |
168 // Not implemented in proxy. | |
169 NOTREACHED(); | |
170 } | |
171 | |
172 int32 CommandBuffer::CreateTransferBuffer(size_t size, int32 id_request) { | |
173 if (last_state_.error == gpu::error::kNoError) { | |
174 int32 id; | |
175 if (Send(new PpapiHostMsg_PPBGraphics3D_CreateTransferBuffer( | |
176 INTERFACE_ID_PPB_GRAPHICS_3D, resource_, size, &id))) { | |
177 return id; | |
178 } | |
179 } | |
180 | |
181 return -1; | |
182 } | |
183 | |
184 int32 CommandBuffer::RegisterTransferBuffer( | |
185 base::SharedMemory* shared_memory, | |
186 size_t size, | |
187 int32 id_request) { | |
188 // Not implemented in proxy. | |
189 NOTREACHED(); | |
190 return -1; | |
191 } | |
192 | |
193 void CommandBuffer::DestroyTransferBuffer(int32 id) { | |
194 if (last_state_.error != gpu::error::kNoError) | |
195 return; | |
196 | |
197 // Remove the transfer buffer from the client side4 cache. | |
198 TransferBufferMap::iterator it = transfer_buffers_.find(id); | |
199 DCHECK(it != transfer_buffers_.end()); | |
200 | |
201 // Delete the shared memory object, closing the handle in this process. | |
202 delete it->second.shared_memory; | |
203 | |
204 transfer_buffers_.erase(it); | |
205 | |
206 Send(new PpapiHostMsg_PPBGraphics3D_DestroyTransferBuffer( | |
207 INTERFACE_ID_PPB_GRAPHICS_3D, resource_, id)); | |
208 } | |
209 | |
210 gpu::Buffer CommandBuffer::GetTransferBuffer(int32 id) { | |
211 if (last_state_.error != gpu::error::kNoError) | |
212 return gpu::Buffer(); | |
213 | |
214 // Check local cache to see if there is already a client side shared memory | |
215 // object for this id. | |
216 TransferBufferMap::iterator it = transfer_buffers_.find(id); | |
217 if (it != transfer_buffers_.end()) { | |
218 return it->second; | |
219 } | |
220 | |
221 // Assuming we are in the renderer process, the service is responsible for | |
222 // duplicating the handle. This might not be true for NaCl. | |
223 base::SharedMemoryHandle handle; | |
224 uint32 size; | |
225 if (!Send(new PpapiHostMsg_PPBGraphics3D_GetTransferBuffer( | |
226 INTERFACE_ID_PPB_GRAPHICS_3D, resource_, id, &handle, &size))) { | |
227 return gpu::Buffer(); | |
228 } | |
229 | |
230 // Cache the transfer buffer shared memory object client side. | |
231 scoped_ptr<base::SharedMemory> shared_memory( | |
232 new base::SharedMemory(handle, false)); | |
233 | |
234 // Map the shared memory on demand. | |
235 if (!shared_memory->memory()) { | |
236 if (!shared_memory->Map(size)) { | |
237 return gpu::Buffer(); | |
238 } | |
239 } | |
240 | |
241 gpu::Buffer buffer; | |
242 buffer.ptr = shared_memory->memory(); | |
243 buffer.size = size; | |
244 buffer.shared_memory = shared_memory.release(); | |
245 transfer_buffers_[id] = buffer; | |
246 | |
247 return buffer; | |
248 } | |
249 | |
250 void CommandBuffer::SetToken(int32 token) { | |
251 NOTREACHED(); | |
252 } | |
253 | |
254 void CommandBuffer::SetParseError(gpu::error::Error error) { | |
255 NOTREACHED(); | |
256 } | |
257 | |
258 void CommandBuffer::SetContextLostReason( | |
259 gpu::error::ContextLostReason reason) { | |
260 NOTREACHED(); | |
261 } | |
262 | |
263 bool CommandBuffer::Send(IPC::Message* msg) { | |
264 DCHECK(last_state_.error == gpu::error::kNoError); | |
265 | |
266 if (dispatcher_->Send(msg)) | |
267 return true; | |
268 | |
269 last_state_.error = gpu::error::kLostContext; | |
270 return false; | |
271 } | |
272 | |
273 void CommandBuffer::UpdateState(const gpu::CommandBuffer::State& state) { | |
274 // Handle wraparound. It works as long as we don't have more than 2B state | |
275 // updates in flight across which reordering occurs. | |
276 if (state.generation - last_state_.generation < 0x80000000U) | |
277 last_state_ = state; | |
278 } | |
279 | |
280 base::SharedMemoryHandle TransportSHMHandleFromInt(Dispatcher* dispatcher, | |
281 int shm_handle) { | |
282 // TODO(piman): Change trusted interface to return a PP_FileHandle, those | |
283 // casts are ugly. | |
284 base::PlatformFile source = | |
285 #if defined(OS_WIN) | |
286 reinterpret_cast<HANDLE>(static_cast<intptr_t>(shm_handle)); | |
287 #elif defined(OS_POSIX) | |
288 shm_handle; | |
289 #else | |
290 #error Not implemented. | |
291 #endif | |
292 // Don't close the handle, it doesn't belong to us. | |
293 return dispatcher->ShareHandleWithRemote(source, false); | |
294 } | |
295 | |
296 PP_Graphics3DTrustedState GetErrorState() { | |
297 PP_Graphics3DTrustedState error_state = { 0 }; | |
298 error_state.error = PPB_GRAPHICS3D_TRUSTED_ERROR_GENERICERROR; | |
299 return error_state; | |
300 } | |
301 | |
302 gpu::CommandBuffer::State GPUStateFromPPState( | |
303 const PP_Graphics3DTrustedState& s) { | |
304 gpu::CommandBuffer::State state; | |
305 state.num_entries = s.num_entries; | |
306 state.get_offset = s.get_offset; | |
307 state.put_offset = s.put_offset; | |
308 state.token = s.token; | |
309 state.error = static_cast<gpu::error::Error>(s.error); | |
310 state.generation = s.generation; | |
311 return state; | |
312 } | |
313 | |
314 InterfaceProxy* CreateGraphics3DProxy(Dispatcher* dispatcher, | |
315 const void* target_interface) { | |
316 return new PPB_Graphics3D_Proxy(dispatcher, target_interface); | |
317 } | |
318 } // namespace | |
319 | |
320 Graphics3D::Graphics3D(const HostResource& resource) | |
321 : PluginResource(resource) { | |
322 } | |
323 | |
324 Graphics3D::~Graphics3D() { | |
325 DestroyGLES2Impl(); | |
326 } | |
327 | |
328 bool Graphics3D::Init() { | |
329 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance()); | |
330 if (!dispatcher) | |
331 return false; | |
332 | |
333 command_buffer_.reset(new CommandBuffer(host_resource(), dispatcher)); | |
334 | |
335 return CreateGLES2Impl(kCommandBufferSize, kTransferBufferSize); | |
336 } | |
337 | |
338 PP_Bool Graphics3D::InitCommandBuffer(int32_t size) { | |
339 return PP_FALSE; | |
340 } | |
341 | |
342 PP_Bool Graphics3D::GetRingBuffer(int* shm_handle, uint32_t* shm_size) { | |
343 return PP_FALSE; | |
344 } | |
345 | |
346 PP_Graphics3DTrustedState Graphics3D::GetState() { | |
347 return GetErrorState(); | |
348 } | |
349 | |
350 PP_Bool Graphics3D::Flush(int32_t put_offset) { | |
351 return PP_FALSE; | |
352 } | |
353 | |
354 PP_Graphics3DTrustedState Graphics3D::FlushSync(int32_t put_offset) { | |
355 return GetErrorState(); | |
356 } | |
357 | |
358 int32_t Graphics3D::CreateTransferBuffer(uint32_t size) { | |
359 return PP_FALSE; | |
360 } | |
361 | |
362 PP_Bool Graphics3D::DestroyTransferBuffer(int32_t id) { | |
363 return PP_FALSE; | |
364 } | |
365 | |
366 PP_Bool Graphics3D::GetTransferBuffer(int32_t id, | |
367 int* shm_handle, | |
368 uint32_t* shm_size) { | |
369 return PP_FALSE; | |
370 } | |
371 | |
372 PP_Graphics3DTrustedState Graphics3D::FlushSyncFast(int32_t put_offset, | |
373 int32_t last_known_get) { | |
374 return GetErrorState(); | |
375 } | |
376 | |
377 gpu::CommandBuffer* Graphics3D::GetCommandBuffer() { | |
378 return command_buffer_.get(); | |
379 } | |
380 | |
381 int32 Graphics3D::DoSwapBuffers() { | |
382 IPC::Message* msg = new PpapiHostMsg_PPBGraphics3D_SwapBuffers( | |
383 INTERFACE_ID_PPB_GRAPHICS_3D, host_resource()); | |
384 msg->set_unblock(true); | |
385 GetDispatcher()->Send(msg); | |
386 | |
387 gles2_impl()->SwapBuffers(); | |
388 return PP_OK_COMPLETIONPENDING; | |
389 } | |
390 | |
391 PPB_Graphics3D_Proxy::PPB_Graphics3D_Proxy(Dispatcher* dispatcher, | |
392 const void* target_interface) | |
393 : InterfaceProxy(dispatcher, target_interface) { | |
394 } | |
395 | |
396 PPB_Graphics3D_Proxy::~PPB_Graphics3D_Proxy() { | |
397 } | |
398 | |
399 // static | |
400 const InterfaceProxy::Info* PPB_Graphics3D_Proxy::GetInfo() { | |
401 static const Info info = { | |
402 ::ppapi::thunk::GetPPB_Graphics3D_Thunk(), | |
403 PPB_GRAPHICS_3D_DEV_INTERFACE, | |
404 INTERFACE_ID_PPB_GRAPHICS_3D, | |
405 false, | |
406 &CreateGraphics3DProxy, | |
407 }; | |
408 return &info; | |
409 } | |
410 | |
411 // static | |
412 PP_Resource PPB_Graphics3D_Proxy::CreateProxyResource( | |
413 PP_Instance instance, | |
414 PP_Config3D_Dev config, | |
415 PP_Resource share_context, | |
416 const int32_t* attrib_list) { | |
417 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); | |
418 if (!dispatcher) | |
419 return PP_ERROR_BADARGUMENT; | |
420 | |
421 // TODO(alokp): Support shared context. | |
422 DCHECK_EQ(0, share_context); | |
423 if (share_context != 0) | |
424 return 0; | |
425 | |
426 std::vector<int32_t> attribs; | |
427 if (attrib_list) { | |
428 for (const int32_t* attr = attrib_list; | |
429 *attr != PP_GRAPHICS3DATTRIB_NONE; | |
430 ++attr) { | |
431 attribs.push_back(*attr); | |
432 } | |
433 attribs.push_back(PP_GRAPHICS3DATTRIB_NONE); | |
434 } | |
435 | |
436 HostResource result; | |
437 dispatcher->Send(new PpapiHostMsg_PPBGraphics3D_Create( | |
438 INTERFACE_ID_PPB_GRAPHICS_3D, instance, config, attribs, &result)); | |
439 if (result.is_null()) | |
440 return 0; | |
441 | |
442 linked_ptr<Graphics3D> graphics_3d(new Graphics3D(result)); | |
443 if (!graphics_3d->Init()) | |
444 return 0; | |
445 | |
446 return PluginResourceTracker::GetInstance()->AddResource(graphics_3d); | |
447 } | |
448 | |
449 bool PPB_Graphics3D_Proxy::OnMessageReceived(const IPC::Message& msg) { | |
450 bool handled = true; | |
451 IPC_BEGIN_MESSAGE_MAP(PPB_Graphics3D_Proxy, msg) | |
452 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_Create, | |
453 OnMsgCreate) | |
454 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_InitCommandBuffer, | |
455 OnMsgInitCommandBuffer) | |
456 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_GetState, | |
457 OnMsgGetState) | |
458 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_Flush, | |
459 OnMsgFlush) | |
460 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_AsyncFlush, | |
461 OnMsgAsyncFlush) | |
462 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_CreateTransferBuffer, | |
463 OnMsgCreateTransferBuffer) | |
464 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_DestroyTransferBuffer, | |
465 OnMsgDestroyTransferBuffer) | |
466 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_GetTransferBuffer, | |
467 OnMsgGetTransferBuffer) | |
468 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_SwapBuffers, | |
469 OnMsgSwapBuffers) | |
470 | |
471 IPC_MESSAGE_HANDLER(PpapiMsg_PPBGraphics3D_SwapBuffersACK, | |
472 OnMsgSwapBuffersACK) | |
473 IPC_MESSAGE_UNHANDLED(handled = false) | |
474 | |
475 IPC_END_MESSAGE_MAP() | |
476 // FIXME(brettw) handle bad messages! | |
477 return handled; | |
478 } | |
479 | |
480 void PPB_Graphics3D_Proxy::OnMsgCreate(PP_Instance instance, | |
481 PP_Config3D_Dev config, | |
482 const std::vector<int32_t>& attribs, | |
483 HostResource* result) { | |
484 if (attribs.empty() || attribs.back() != 0) | |
485 return; // Bad message. | |
486 | |
487 EnterFunctionNoLock<ResourceCreationAPI> enter(instance, true); | |
488 if (enter.succeeded()) { | |
489 result->SetHostResource( | |
490 instance, | |
491 enter.functions()->CreateGraphics3DRaw(instance, config, 0, | |
492 &attribs.front())); | |
493 } | |
494 } | |
495 | |
496 void PPB_Graphics3D_Proxy::OnMsgInitCommandBuffer( | |
497 const HostResource& context, | |
498 int32 size, | |
499 base::SharedMemoryHandle* ring_buffer) { | |
500 *ring_buffer = base::SharedMemory::NULLHandle(); | |
501 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); | |
502 if (enter.failed()) | |
503 return; | |
504 | |
505 if (!enter.object()->InitCommandBuffer(size)) | |
506 return; | |
507 | |
508 int shm_handle; | |
509 uint32_t shm_size; | |
510 if (!enter.object()->GetRingBuffer(&shm_handle, &shm_size)) | |
511 return; | |
512 *ring_buffer = TransportSHMHandleFromInt(dispatcher(), shm_handle); | |
513 } | |
514 | |
515 void PPB_Graphics3D_Proxy::OnMsgGetState(const HostResource& context, | |
516 gpu::CommandBuffer::State* state) { | |
517 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); | |
518 if (enter.failed()) | |
519 return; | |
520 PP_Graphics3DTrustedState pp_state = enter.object()->GetState(); | |
521 *state = GPUStateFromPPState(pp_state); | |
522 } | |
523 | |
524 void PPB_Graphics3D_Proxy::OnMsgFlush(const HostResource& context, | |
525 int32 put_offset, | |
526 int32 last_known_get, | |
527 gpu::CommandBuffer::State* state) { | |
528 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); | |
529 if (enter.failed()) | |
530 return; | |
531 PP_Graphics3DTrustedState pp_state = enter.object()->FlushSyncFast( | |
532 put_offset, last_known_get); | |
533 *state = GPUStateFromPPState(pp_state); | |
534 } | |
535 | |
536 void PPB_Graphics3D_Proxy::OnMsgAsyncFlush(const HostResource& context, | |
537 int32 put_offset) { | |
538 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); | |
539 if (enter.succeeded()) | |
540 enter.object()->Flush(put_offset); | |
541 } | |
542 | |
543 void PPB_Graphics3D_Proxy::OnMsgCreateTransferBuffer( | |
544 const HostResource& context, | |
545 int32 size, | |
546 int32* id) { | |
547 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); | |
548 if (enter.succeeded()) | |
549 *id = enter.object()->CreateTransferBuffer(size); | |
550 else | |
551 *id = 0; | |
552 } | |
553 | |
554 void PPB_Graphics3D_Proxy::OnMsgDestroyTransferBuffer( | |
555 const HostResource& context, | |
556 int32 id) { | |
557 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); | |
558 if (enter.succeeded()) | |
559 enter.object()->DestroyTransferBuffer(id); | |
560 } | |
561 | |
562 void PPB_Graphics3D_Proxy::OnMsgGetTransferBuffer( | |
563 const HostResource& context, | |
564 int32 id, | |
565 base::SharedMemoryHandle* transfer_buffer, | |
566 uint32* size) { | |
567 *transfer_buffer = base::SharedMemory::NULLHandle(); | |
568 *size = 0; | |
569 | |
570 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); | |
571 int shm_handle = 0; | |
572 uint32_t shm_size = 0; | |
573 if (enter.succeeded() && | |
574 enter.object()->GetTransferBuffer(id, &shm_handle, &shm_size)) { | |
575 *transfer_buffer = TransportSHMHandleFromInt(dispatcher(), shm_handle); | |
576 *size = shm_size; | |
577 } | |
578 } | |
579 | |
580 void PPB_Graphics3D_Proxy::OnMsgSwapBuffers(const HostResource& context) { | |
581 CompletionCallback callback = callback_factory_.NewOptionalCallback( | |
582 &PPB_Graphics3D_Proxy::SendSwapBuffersACKToPlugin, context); | |
583 | |
584 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); | |
585 int32_t result = PP_ERROR_BADRESOURCE; | |
586 if (enter.succeeded()) | |
587 result = enter.object()->SwapBuffers(callback.pp_completion_callback()); | |
588 if (result != PP_OK_COMPLETIONPENDING) { | |
589 // There was some error, so we won't get a flush callback. We need to now | |
590 // issue the ACK to the plugin hears about the error. This will also clean | |
591 // up the data associated with the callback. | |
592 callback.Run(result); | |
593 } | |
594 } | |
595 | |
596 void PPB_Graphics3D_Proxy::OnMsgSwapBuffersACK(const HostResource& resource, | |
597 int32_t pp_error) { | |
598 EnterPluginFromHostResource<PPB_Graphics3D_API> enter(resource); | |
599 if (enter.succeeded()) | |
600 static_cast<Graphics3D*>(enter.object())->SwapBuffersACK(pp_error); | |
601 } | |
602 | |
603 void PPB_Graphics3D_Proxy::SendSwapBuffersACKToPlugin( | |
604 int32_t result, | |
605 const HostResource& context) { | |
606 dispatcher()->Send(new PpapiMsg_PPBGraphics3D_SwapBuffersACK( | |
607 INTERFACE_ID_PPB_GRAPHICS_3D, context, result)); | |
608 } | |
609 | |
610 } // namespace proxy | |
611 } // namespace pp | |
612 | |
OLD | NEW |