blob: 0bb74407fabfadb35798d874499a132f9c0047ed [file] [log] [blame]
[email protected]eeb4e4a2011-07-19 16:22:061// 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
16using ppapi::thunk::EnterFunctionNoLock;
17using ppapi::thunk::EnterResourceNoLock;
18using ppapi::thunk::PPB_Graphics3D_API;
19using ppapi::thunk::ResourceCreationAPI;
20
[email protected]4d2efd22011-08-18 21:58:0221namespace ppapi {
[email protected]eeb4e4a2011-07-19 16:22:0622namespace proxy {
23
24namespace {
25const int32 kCommandBufferSize = 1024 * 1024;
26const int32 kTransferBufferSize = 1024 * 1024;
27
28class 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();
[email protected]d58730d2011-07-26 00:00:4138 virtual State GetLastState();
[email protected]eeb4e4a2011-07-19 16:22:0639 virtual void Flush(int32 put_offset);
40 virtual State FlushSync(int32 put_offset, int32 last_known_get);
41 virtual void SetGetOffset(int32 get_offset);
42 virtual int32 CreateTransferBuffer(size_t size, int32 id_request);
43 virtual int32 RegisterTransferBuffer(base::SharedMemory* shared_memory,
44 size_t size,
45 int32 id_request);
46 virtual void DestroyTransferBuffer(int32 id);
47 virtual gpu::Buffer GetTransferBuffer(int32 handle);
48 virtual void SetToken(int32 token);
49 virtual void SetParseError(gpu::error::Error error);
50 virtual void SetContextLostReason(gpu::error::ContextLostReason reason);
51
52 private:
53 bool Send(IPC::Message* msg);
54 void UpdateState(const gpu::CommandBuffer::State& state);
55
56 int32 num_entries_;
57 scoped_ptr<base::SharedMemory> ring_buffer_;
58
59 typedef base::hash_map<int32, gpu::Buffer> TransferBufferMap;
60 TransferBufferMap transfer_buffers_;
61
62 State last_state_;
63
64 HostResource resource_;
65 PluginDispatcher* dispatcher_;
66
67 DISALLOW_COPY_AND_ASSIGN(CommandBuffer);
68};
69
70CommandBuffer::CommandBuffer(const HostResource& resource,
71 PluginDispatcher* dispatcher)
72 : num_entries_(0),
73 resource_(resource),
74 dispatcher_(dispatcher) {
75}
76
77CommandBuffer::~CommandBuffer() {
78 // Delete all the locally cached shared memory objects, closing the handle
79 // in this process.
80 for (TransferBufferMap::iterator it = transfer_buffers_.begin();
81 it != transfer_buffers_.end(); ++it) {
82 delete it->second.shared_memory;
83 it->second.shared_memory = NULL;
84 }
85}
86
87bool CommandBuffer::Initialize(int32 size) {
88 DCHECK(!ring_buffer_.get());
89
90 // Initialize the service. Assuming we are sandboxed, the GPU
91 // process is responsible for duplicating the handle. This might not be true
92 // for NaCl.
93 base::SharedMemoryHandle handle;
94 if (Send(new PpapiHostMsg_PPBGraphics3D_InitCommandBuffer(
[email protected]ac4b54d2011-10-20 23:09:2895 API_ID_PPB_GRAPHICS_3D, resource_, size, &handle)) &&
[email protected]eeb4e4a2011-07-19 16:22:0696 base::SharedMemory::IsHandleValid(handle)) {
97 ring_buffer_.reset(new base::SharedMemory(handle, false));
98 if (ring_buffer_->Map(size)) {
99 num_entries_ = size / sizeof(gpu::CommandBufferEntry);
100 return true;
101 }
102
103 ring_buffer_.reset();
104 }
105
106 return false;
107}
108
109bool CommandBuffer::Initialize(base::SharedMemory* buffer, int32 size) {
110 // Not implemented in proxy.
111 NOTREACHED();
112 return false;
113}
114
115gpu::Buffer CommandBuffer::GetRingBuffer() {
116 // Return locally cached ring buffer.
117 gpu::Buffer buffer;
118 buffer.ptr = ring_buffer_->memory();
119 buffer.size = num_entries_ * sizeof(gpu::CommandBufferEntry);
120 buffer.shared_memory = ring_buffer_.get();
121 return buffer;
122}
123
124gpu::CommandBuffer::State CommandBuffer::GetState() {
125 // Send will flag state with lost context if IPC fails.
126 if (last_state_.error == gpu::error::kNoError) {
127 gpu::CommandBuffer::State state;
128 if (Send(new PpapiHostMsg_PPBGraphics3D_GetState(
[email protected]ac4b54d2011-10-20 23:09:28129 API_ID_PPB_GRAPHICS_3D, resource_, &state)))
[email protected]eeb4e4a2011-07-19 16:22:06130 UpdateState(state);
131 }
132
133 return last_state_;
134}
135
[email protected]d58730d2011-07-26 00:00:41136gpu::CommandBuffer::State CommandBuffer::GetLastState() {
137 return last_state_;
138}
139
[email protected]eeb4e4a2011-07-19 16:22:06140void CommandBuffer::Flush(int32 put_offset) {
141 if (last_state_.error != gpu::error::kNoError)
142 return;
143
144 IPC::Message* message = new PpapiHostMsg_PPBGraphics3D_AsyncFlush(
[email protected]ac4b54d2011-10-20 23:09:28145 API_ID_PPB_GRAPHICS_3D, resource_, put_offset);
[email protected]eeb4e4a2011-07-19 16:22:06146
147 // Do not let a synchronous flush hold up this message. If this handler is
148 // deferred until after the synchronous flush completes, it will overwrite the
149 // cached last_state_ with out-of-date data.
150 message->set_unblock(true);
151 Send(message);
152}
153
154gpu::CommandBuffer::State CommandBuffer::FlushSync(int32 put_offset,
155 int32 last_known_get) {
156 if (last_known_get == last_state_.get_offset) {
157 // Send will flag state with lost context if IPC fails.
158 if (last_state_.error == gpu::error::kNoError) {
159 gpu::CommandBuffer::State state;
160 if (Send(new PpapiHostMsg_PPBGraphics3D_Flush(
[email protected]ac4b54d2011-10-20 23:09:28161 API_ID_PPB_GRAPHICS_3D, resource_, put_offset,
[email protected]eeb4e4a2011-07-19 16:22:06162 last_known_get, &state)))
163 UpdateState(state);
164 }
165 } else {
166 Flush(put_offset);
167 }
168
169 return last_state_;
170}
171
172void CommandBuffer::SetGetOffset(int32 get_offset) {
173 // Not implemented in proxy.
174 NOTREACHED();
175}
176
177int32 CommandBuffer::CreateTransferBuffer(size_t size, int32 id_request) {
178 if (last_state_.error == gpu::error::kNoError) {
179 int32 id;
180 if (Send(new PpapiHostMsg_PPBGraphics3D_CreateTransferBuffer(
[email protected]ac4b54d2011-10-20 23:09:28181 API_ID_PPB_GRAPHICS_3D, resource_, size, &id))) {
[email protected]eeb4e4a2011-07-19 16:22:06182 return id;
183 }
184 }
185
186 return -1;
187}
188
189int32 CommandBuffer::RegisterTransferBuffer(
190 base::SharedMemory* shared_memory,
191 size_t size,
192 int32 id_request) {
193 // Not implemented in proxy.
194 NOTREACHED();
195 return -1;
196}
197
198void CommandBuffer::DestroyTransferBuffer(int32 id) {
199 if (last_state_.error != gpu::error::kNoError)
200 return;
201
202 // Remove the transfer buffer from the client side4 cache.
203 TransferBufferMap::iterator it = transfer_buffers_.find(id);
204 DCHECK(it != transfer_buffers_.end());
205
206 // Delete the shared memory object, closing the handle in this process.
207 delete it->second.shared_memory;
208
209 transfer_buffers_.erase(it);
210
211 Send(new PpapiHostMsg_PPBGraphics3D_DestroyTransferBuffer(
[email protected]ac4b54d2011-10-20 23:09:28212 API_ID_PPB_GRAPHICS_3D, resource_, id));
[email protected]eeb4e4a2011-07-19 16:22:06213}
214
215gpu::Buffer CommandBuffer::GetTransferBuffer(int32 id) {
216 if (last_state_.error != gpu::error::kNoError)
217 return gpu::Buffer();
218
219 // Check local cache to see if there is already a client side shared memory
220 // object for this id.
221 TransferBufferMap::iterator it = transfer_buffers_.find(id);
222 if (it != transfer_buffers_.end()) {
223 return it->second;
224 }
225
226 // Assuming we are in the renderer process, the service is responsible for
227 // duplicating the handle. This might not be true for NaCl.
228 base::SharedMemoryHandle handle;
229 uint32 size;
230 if (!Send(new PpapiHostMsg_PPBGraphics3D_GetTransferBuffer(
[email protected]ac4b54d2011-10-20 23:09:28231 API_ID_PPB_GRAPHICS_3D, resource_, id, &handle, &size))) {
[email protected]eeb4e4a2011-07-19 16:22:06232 return gpu::Buffer();
233 }
234
235 // Cache the transfer buffer shared memory object client side.
236 scoped_ptr<base::SharedMemory> shared_memory(
237 new base::SharedMemory(handle, false));
238
239 // Map the shared memory on demand.
240 if (!shared_memory->memory()) {
241 if (!shared_memory->Map(size)) {
242 return gpu::Buffer();
243 }
244 }
245
246 gpu::Buffer buffer;
247 buffer.ptr = shared_memory->memory();
248 buffer.size = size;
249 buffer.shared_memory = shared_memory.release();
250 transfer_buffers_[id] = buffer;
251
252 return buffer;
253}
254
255void CommandBuffer::SetToken(int32 token) {
256 NOTREACHED();
257}
258
259void CommandBuffer::SetParseError(gpu::error::Error error) {
260 NOTREACHED();
261}
262
263void CommandBuffer::SetContextLostReason(
264 gpu::error::ContextLostReason reason) {
265 NOTREACHED();
266}
267
268bool CommandBuffer::Send(IPC::Message* msg) {
269 DCHECK(last_state_.error == gpu::error::kNoError);
270
271 if (dispatcher_->Send(msg))
272 return true;
273
274 last_state_.error = gpu::error::kLostContext;
275 return false;
276}
277
278void CommandBuffer::UpdateState(const gpu::CommandBuffer::State& state) {
279 // Handle wraparound. It works as long as we don't have more than 2B state
280 // updates in flight across which reordering occurs.
281 if (state.generation - last_state_.generation < 0x80000000U)
282 last_state_ = state;
283}
284
285base::SharedMemoryHandle TransportSHMHandleFromInt(Dispatcher* dispatcher,
286 int shm_handle) {
287 // TODO(piman): Change trusted interface to return a PP_FileHandle, those
288 // casts are ugly.
289 base::PlatformFile source =
290#if defined(OS_WIN)
291 reinterpret_cast<HANDLE>(static_cast<intptr_t>(shm_handle));
292#elif defined(OS_POSIX)
293 shm_handle;
294#else
295 #error Not implemented.
296#endif
297 // Don't close the handle, it doesn't belong to us.
298 return dispatcher->ShareHandleWithRemote(source, false);
299}
300
301PP_Graphics3DTrustedState GetErrorState() {
302 PP_Graphics3DTrustedState error_state = { 0 };
303 error_state.error = PPB_GRAPHICS3D_TRUSTED_ERROR_GENERICERROR;
304 return error_state;
305}
306
307gpu::CommandBuffer::State GPUStateFromPPState(
308 const PP_Graphics3DTrustedState& s) {
309 gpu::CommandBuffer::State state;
310 state.num_entries = s.num_entries;
311 state.get_offset = s.get_offset;
312 state.put_offset = s.put_offset;
313 state.token = s.token;
314 state.error = static_cast<gpu::error::Error>(s.error);
315 state.generation = s.generation;
316 return state;
317}
318
[email protected]eeb4e4a2011-07-19 16:22:06319} // namespace
320
321Graphics3D::Graphics3D(const HostResource& resource)
[email protected]7f8b26b2011-08-18 15:41:01322 : Resource(resource) {
[email protected]eeb4e4a2011-07-19 16:22:06323}
324
325Graphics3D::~Graphics3D() {
326 DestroyGLES2Impl();
327}
328
329bool Graphics3D::Init() {
[email protected]7f8b26b2011-08-18 15:41:01330 PluginDispatcher* dispatcher = PluginDispatcher::GetForResource(this);
[email protected]eeb4e4a2011-07-19 16:22:06331 if (!dispatcher)
332 return false;
333
334 command_buffer_.reset(new CommandBuffer(host_resource(), dispatcher));
[email protected]0e50fc4d2011-08-01 15:33:51335 if (!command_buffer_->Initialize(kCommandBufferSize))
336 return false;
[email protected]eeb4e4a2011-07-19 16:22:06337
338 return CreateGLES2Impl(kCommandBufferSize, kTransferBufferSize);
339}
340
341PP_Bool Graphics3D::InitCommandBuffer(int32_t size) {
342 return PP_FALSE;
343}
344
345PP_Bool Graphics3D::GetRingBuffer(int* shm_handle, uint32_t* shm_size) {
346 return PP_FALSE;
347}
348
349PP_Graphics3DTrustedState Graphics3D::GetState() {
350 return GetErrorState();
351}
352
353PP_Bool Graphics3D::Flush(int32_t put_offset) {
354 return PP_FALSE;
355}
356
357PP_Graphics3DTrustedState Graphics3D::FlushSync(int32_t put_offset) {
358 return GetErrorState();
359}
360
361int32_t Graphics3D::CreateTransferBuffer(uint32_t size) {
362 return PP_FALSE;
363}
364
365PP_Bool Graphics3D::DestroyTransferBuffer(int32_t id) {
366 return PP_FALSE;
367}
368
369PP_Bool Graphics3D::GetTransferBuffer(int32_t id,
370 int* shm_handle,
371 uint32_t* shm_size) {
372 return PP_FALSE;
373}
374
375PP_Graphics3DTrustedState Graphics3D::FlushSyncFast(int32_t put_offset,
376 int32_t last_known_get) {
377 return GetErrorState();
378}
379
380gpu::CommandBuffer* Graphics3D::GetCommandBuffer() {
381 return command_buffer_.get();
382}
383
384int32 Graphics3D::DoSwapBuffers() {
385 IPC::Message* msg = new PpapiHostMsg_PPBGraphics3D_SwapBuffers(
[email protected]ac4b54d2011-10-20 23:09:28386 API_ID_PPB_GRAPHICS_3D, host_resource());
[email protected]eeb4e4a2011-07-19 16:22:06387 msg->set_unblock(true);
[email protected]7f8b26b2011-08-18 15:41:01388 PluginDispatcher::GetForResource(this)->Send(msg);
[email protected]eeb4e4a2011-07-19 16:22:06389
390 gles2_impl()->SwapBuffers();
391 return PP_OK_COMPLETIONPENDING;
392}
393
[email protected]5c966022011-09-13 18:09:37394PPB_Graphics3D_Proxy::PPB_Graphics3D_Proxy(Dispatcher* dispatcher)
395 : InterfaceProxy(dispatcher),
[email protected]0e50fc4d2011-08-01 15:33:51396 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
[email protected]eeb4e4a2011-07-19 16:22:06397}
398
399PPB_Graphics3D_Proxy::~PPB_Graphics3D_Proxy() {
400}
401
402// static
[email protected]eeb4e4a2011-07-19 16:22:06403PP_Resource PPB_Graphics3D_Proxy::CreateProxyResource(
404 PP_Instance instance,
[email protected]eeb4e4a2011-07-19 16:22:06405 PP_Resource share_context,
406 const int32_t* attrib_list) {
407 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
408 if (!dispatcher)
409 return PP_ERROR_BADARGUMENT;
410
411 // TODO(alokp): Support shared context.
412 DCHECK_EQ(0, share_context);
413 if (share_context != 0)
414 return 0;
415
416 std::vector<int32_t> attribs;
417 if (attrib_list) {
418 for (const int32_t* attr = attrib_list;
[email protected]0e50fc4d2011-08-01 15:33:51419 attr[0] != PP_GRAPHICS3DATTRIB_NONE;
420 attr += 2) {
421 attribs.push_back(attr[0]);
422 attribs.push_back(attr[1]);
[email protected]eeb4e4a2011-07-19 16:22:06423 }
[email protected]eeb4e4a2011-07-19 16:22:06424 }
[email protected]0e50fc4d2011-08-01 15:33:51425 attribs.push_back(PP_GRAPHICS3DATTRIB_NONE);
[email protected]eeb4e4a2011-07-19 16:22:06426
427 HostResource result;
428 dispatcher->Send(new PpapiHostMsg_PPBGraphics3D_Create(
[email protected]ac4b54d2011-10-20 23:09:28429 API_ID_PPB_GRAPHICS_3D, instance, attribs, &result));
[email protected]eeb4e4a2011-07-19 16:22:06430 if (result.is_null())
431 return 0;
432
[email protected]51e1aec2011-08-11 04:48:30433 scoped_refptr<Graphics3D> graphics_3d(new Graphics3D(result));
[email protected]eeb4e4a2011-07-19 16:22:06434 if (!graphics_3d->Init())
435 return 0;
[email protected]7f8b26b2011-08-18 15:41:01436 return graphics_3d->GetReference();
[email protected]eeb4e4a2011-07-19 16:22:06437}
438
439bool PPB_Graphics3D_Proxy::OnMessageReceived(const IPC::Message& msg) {
440 bool handled = true;
441 IPC_BEGIN_MESSAGE_MAP(PPB_Graphics3D_Proxy, msg)
442 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_Create,
443 OnMsgCreate)
444 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_InitCommandBuffer,
445 OnMsgInitCommandBuffer)
446 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_GetState,
447 OnMsgGetState)
448 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_Flush,
449 OnMsgFlush)
450 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_AsyncFlush,
451 OnMsgAsyncFlush)
452 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_CreateTransferBuffer,
453 OnMsgCreateTransferBuffer)
454 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_DestroyTransferBuffer,
455 OnMsgDestroyTransferBuffer)
456 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_GetTransferBuffer,
457 OnMsgGetTransferBuffer)
458 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_SwapBuffers,
459 OnMsgSwapBuffers)
460
461 IPC_MESSAGE_HANDLER(PpapiMsg_PPBGraphics3D_SwapBuffersACK,
462 OnMsgSwapBuffersACK)
463 IPC_MESSAGE_UNHANDLED(handled = false)
464
465 IPC_END_MESSAGE_MAP()
466 // FIXME(brettw) handle bad messages!
467 return handled;
468}
469
470void PPB_Graphics3D_Proxy::OnMsgCreate(PP_Instance instance,
[email protected]eeb4e4a2011-07-19 16:22:06471 const std::vector<int32_t>& attribs,
472 HostResource* result) {
[email protected]0e50fc4d2011-08-01 15:33:51473 if (attribs.empty() || attribs.back() != PP_GRAPHICS3DATTRIB_NONE)
[email protected]eeb4e4a2011-07-19 16:22:06474 return; // Bad message.
475
[email protected]5c966022011-09-13 18:09:37476 thunk::EnterResourceCreation enter(instance);
[email protected]eeb4e4a2011-07-19 16:22:06477 if (enter.succeeded()) {
478 result->SetHostResource(
479 instance,
[email protected]9d8fe822011-08-16 21:02:52480 enter.functions()->CreateGraphics3DRaw(instance, 0, &attribs.front()));
[email protected]eeb4e4a2011-07-19 16:22:06481 }
482}
483
484void PPB_Graphics3D_Proxy::OnMsgInitCommandBuffer(
485 const HostResource& context,
486 int32 size,
487 base::SharedMemoryHandle* ring_buffer) {
488 *ring_buffer = base::SharedMemory::NULLHandle();
489 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context);
490 if (enter.failed())
491 return;
492
493 if (!enter.object()->InitCommandBuffer(size))
494 return;
495
496 int shm_handle;
497 uint32_t shm_size;
498 if (!enter.object()->GetRingBuffer(&shm_handle, &shm_size))
499 return;
500 *ring_buffer = TransportSHMHandleFromInt(dispatcher(), shm_handle);
501}
502
503void PPB_Graphics3D_Proxy::OnMsgGetState(const HostResource& context,
504 gpu::CommandBuffer::State* state) {
505 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context);
506 if (enter.failed())
507 return;
508 PP_Graphics3DTrustedState pp_state = enter.object()->GetState();
509 *state = GPUStateFromPPState(pp_state);
510}
511
512void PPB_Graphics3D_Proxy::OnMsgFlush(const HostResource& context,
513 int32 put_offset,
514 int32 last_known_get,
515 gpu::CommandBuffer::State* state) {
516 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context);
517 if (enter.failed())
518 return;
519 PP_Graphics3DTrustedState pp_state = enter.object()->FlushSyncFast(
520 put_offset, last_known_get);
521 *state = GPUStateFromPPState(pp_state);
522}
523
524void PPB_Graphics3D_Proxy::OnMsgAsyncFlush(const HostResource& context,
525 int32 put_offset) {
526 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context);
527 if (enter.succeeded())
528 enter.object()->Flush(put_offset);
529}
530
531void PPB_Graphics3D_Proxy::OnMsgCreateTransferBuffer(
532 const HostResource& context,
533 int32 size,
534 int32* id) {
535 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context);
536 if (enter.succeeded())
537 *id = enter.object()->CreateTransferBuffer(size);
538 else
539 *id = 0;
540}
541
542void PPB_Graphics3D_Proxy::OnMsgDestroyTransferBuffer(
543 const HostResource& context,
544 int32 id) {
545 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context);
546 if (enter.succeeded())
547 enter.object()->DestroyTransferBuffer(id);
548}
549
550void PPB_Graphics3D_Proxy::OnMsgGetTransferBuffer(
551 const HostResource& context,
552 int32 id,
553 base::SharedMemoryHandle* transfer_buffer,
554 uint32* size) {
555 *transfer_buffer = base::SharedMemory::NULLHandle();
556 *size = 0;
557
558 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context);
559 int shm_handle = 0;
560 uint32_t shm_size = 0;
561 if (enter.succeeded() &&
562 enter.object()->GetTransferBuffer(id, &shm_handle, &shm_size)) {
563 *transfer_buffer = TransportSHMHandleFromInt(dispatcher(), shm_handle);
564 *size = shm_size;
565 }
566}
567
568void PPB_Graphics3D_Proxy::OnMsgSwapBuffers(const HostResource& context) {
[email protected]79d23c72011-08-08 19:40:40569 EnterHostFromHostResourceForceCallback<PPB_Graphics3D_API> enter(
570 context, callback_factory_,
[email protected]eeb4e4a2011-07-19 16:22:06571 &PPB_Graphics3D_Proxy::SendSwapBuffersACKToPlugin, context);
[email protected]eeb4e4a2011-07-19 16:22:06572 if (enter.succeeded())
[email protected]79d23c72011-08-08 19:40:40573 enter.SetResult(enter.object()->SwapBuffers(enter.callback()));
[email protected]eeb4e4a2011-07-19 16:22:06574}
575
576void PPB_Graphics3D_Proxy::OnMsgSwapBuffersACK(const HostResource& resource,
577 int32_t pp_error) {
578 EnterPluginFromHostResource<PPB_Graphics3D_API> enter(resource);
579 if (enter.succeeded())
580 static_cast<Graphics3D*>(enter.object())->SwapBuffersACK(pp_error);
581}
582
583void PPB_Graphics3D_Proxy::SendSwapBuffersACKToPlugin(
584 int32_t result,
585 const HostResource& context) {
586 dispatcher()->Send(new PpapiMsg_PPBGraphics3D_SwapBuffersACK(
[email protected]ac4b54d2011-10-20 23:09:28587 API_ID_PPB_GRAPHICS_3D, context, result));
[email protected]eeb4e4a2011-07-19 16:22:06588}
589
590} // namespace proxy
[email protected]4d2efd22011-08-18 21:58:02591} // namespace ppapi
[email protected]eeb4e4a2011-07-19 16:22:06592