blob: 7d18850ea3c79bb97d588fd6a5a138660fcb2139 [file] [log] [blame]
[email protected]aaa11b32012-03-08 12:30:131// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]eeb4e4a2011-07-19 16:22:062// 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"
[email protected]84b44c552012-10-15 20:58:178#include "gpu/command_buffer/common/command_buffer.h"
[email protected]eeb4e4a2011-07-19 16:22:069#include "ppapi/c/pp_errors.h"
10#include "ppapi/proxy/enter_proxy.h"
11#include "ppapi/proxy/plugin_dispatcher.h"
[email protected]aaa11b32012-03-08 12:30:1312#include "ppapi/proxy/ppapi_command_buffer_proxy.h"
[email protected]eeb4e4a2011-07-19 16:22:0613#include "ppapi/proxy/ppapi_messages.h"
[email protected]84b44c552012-10-15 20:58:1714#include "ppapi/shared_impl/ppapi_globals.h"
15#include "ppapi/shared_impl/proxy_lock.h"
[email protected]eeb4e4a2011-07-19 16:22:0616#include "ppapi/thunk/enter.h"
17#include "ppapi/thunk/resource_creation_api.h"
18#include "ppapi/thunk/thunk.h"
19
[email protected]eeb4e4a2011-07-19 16:22:0620using ppapi::thunk::EnterResourceNoLock;
21using ppapi::thunk::PPB_Graphics3D_API;
22using ppapi::thunk::ResourceCreationAPI;
23
[email protected]4d2efd22011-08-18 21:58:0224namespace ppapi {
[email protected]eeb4e4a2011-07-19 16:22:0625namespace proxy {
26
27namespace {
[email protected]84b44c552012-10-15 20:58:1728
[email protected]eeb4e4a2011-07-19 16:22:0629const int32 kCommandBufferSize = 1024 * 1024;
30const int32 kTransferBufferSize = 1024 * 1024;
31
[email protected]eeb4e4a2011-07-19 16:22:0632base::SharedMemoryHandle TransportSHMHandleFromInt(Dispatcher* dispatcher,
33 int shm_handle) {
34 // TODO(piman): Change trusted interface to return a PP_FileHandle, those
35 // casts are ugly.
36 base::PlatformFile source =
37#if defined(OS_WIN)
38 reinterpret_cast<HANDLE>(static_cast<intptr_t>(shm_handle));
39#elif defined(OS_POSIX)
40 shm_handle;
41#else
42 #error Not implemented.
43#endif
44 // Don't close the handle, it doesn't belong to us.
45 return dispatcher->ShareHandleWithRemote(source, false);
46}
47
[email protected]914f5262013-06-01 00:17:2248gpu::CommandBuffer::State GetErrorState() {
49 gpu::CommandBuffer::State error_state;
50 error_state.error = gpu::error::kGenericError;
[email protected]eeb4e4a2011-07-19 16:22:0651 return error_state;
52}
53
[email protected]eeb4e4a2011-07-19 16:22:0654} // namespace
55
[email protected]84b44c552012-10-15 20:58:1756// This class just wraps a CommandBuffer and optionally locks around every
57// method. This is used to ensure that we have the Proxy lock any time we enter
58// PpapiCommandBufferProxy.
59//
60// Note, for performance reasons, most of this code is not truly thread
61// safe in the sense of multiple threads concurrently rendering to the same
62// Graphics3D context; this isn't allowed, and will likely either crash or
63// result in undefined behavior. It is assumed that the thread which creates
64// the Graphics3D context will be the thread on which subsequent gl rendering
65// will be done.
66//
67// TODO(nfullagar): At some point, allow multiple threads to concurrently render
68// each to its own context. First step is to allow a single thread (either main
69// thread or background thread) to render to a single Graphics3D context.
70class Graphics3D::LockingCommandBuffer : public gpu::CommandBuffer {
71 public:
72 explicit LockingCommandBuffer(gpu::CommandBuffer* gpu_command_buffer)
73 : gpu_command_buffer_(gpu_command_buffer), need_to_lock_(true) {
74 }
75 virtual ~LockingCommandBuffer() {
76 }
77 void set_need_to_lock(bool need_to_lock) { need_to_lock_ = need_to_lock; }
78 bool need_to_lock() const { return need_to_lock_; }
79
80 private:
81 // MaybeLock acquires the proxy lock on construction if and only if
82 // need_to_lock is true. If it acquired the lock, it releases it on
83 // destruction. If need_to_lock is false, then the lock must already be held.
84 struct MaybeLock {
85 explicit MaybeLock(bool need_to_lock) : locked_(need_to_lock) {
86 if (need_to_lock)
87 ppapi::ProxyLock::Acquire();
88 else
89 ppapi::ProxyLock::AssertAcquired();
90 }
91 ~MaybeLock() {
92 if (locked_)
93 ppapi::ProxyLock::Release();
94 }
95 private:
96 bool locked_;
97 };
98
99 // gpu::CommandBuffer implementation:
100 virtual bool Initialize() OVERRIDE {
101 MaybeLock lock(need_to_lock_);
102 return gpu_command_buffer_->Initialize();
103 }
104 virtual State GetState() OVERRIDE {
105 MaybeLock lock(need_to_lock_);
106 return gpu_command_buffer_->GetState();
107 }
108 virtual State GetLastState() OVERRIDE {
109 // During a normal scene, the vast majority of calls are to GetLastState().
110 // We don't allow multi-threaded rendering on the same contex, so for
111 // performance reasons, avoid the global lock for this entry point. We can
112 // get away with this here because the underlying implementation of
113 // GetLastState() is trivial and does not involve global or shared state
114 // between other contexts.
115 // TODO(nfullagar): We can probably skip MaybeLock for other methods, but
116 // the performance gain may not be worth it.
117 //
118 // MaybeLock lock(need_to_lock_);
119 return gpu_command_buffer_->GetLastState();
120 }
[email protected]a597c622013-01-25 05:08:38121 virtual int32 GetLastToken() OVERRIDE {
122 return GetLastState().token;
123 }
[email protected]84b44c552012-10-15 20:58:17124 virtual void Flush(int32 put_offset) OVERRIDE {
125 MaybeLock lock(need_to_lock_);
126 gpu_command_buffer_->Flush(put_offset);
127 }
128 virtual State FlushSync(int32 put_offset, int32 last_known_get) OVERRIDE {
129 MaybeLock lock(need_to_lock_);
130 return gpu_command_buffer_->FlushSync(put_offset, last_known_get);
131 }
132 virtual void SetGetBuffer(int32 transfer_buffer_id) OVERRIDE {
133 MaybeLock lock(need_to_lock_);
134 gpu_command_buffer_->SetGetBuffer(transfer_buffer_id);
135 }
136 virtual void SetGetOffset(int32 get_offset) OVERRIDE {
137 MaybeLock lock(need_to_lock_);
138 gpu_command_buffer_->SetGetOffset(get_offset);
139 }
[email protected]67c80782012-12-21 01:16:52140 virtual gpu::Buffer CreateTransferBuffer(size_t size,
141 int32* id) OVERRIDE {
[email protected]84b44c552012-10-15 20:58:17142 MaybeLock lock(need_to_lock_);
[email protected]67c80782012-12-21 01:16:52143 return gpu_command_buffer_->CreateTransferBuffer(size, id);
[email protected]84b44c552012-10-15 20:58:17144 }
145 virtual void DestroyTransferBuffer(int32 id) OVERRIDE {
146 MaybeLock lock(need_to_lock_);
147 gpu_command_buffer_->DestroyTransferBuffer(id);
148 }
[email protected]67c80782012-12-21 01:16:52149 virtual gpu::Buffer GetTransferBuffer(int32 id) OVERRIDE {
[email protected]84b44c552012-10-15 20:58:17150 MaybeLock lock(need_to_lock_);
[email protected]67c80782012-12-21 01:16:52151 return gpu_command_buffer_->GetTransferBuffer(id);
[email protected]84b44c552012-10-15 20:58:17152 }
153 virtual void SetToken(int32 token) OVERRIDE {
154 MaybeLock lock(need_to_lock_);
155 gpu_command_buffer_->SetToken(token);
156 }
157 virtual void SetParseError(gpu::error::Error error) OVERRIDE {
158 MaybeLock lock(need_to_lock_);
159 gpu_command_buffer_->SetParseError(error);
160 }
161 virtual void SetContextLostReason(
162 gpu::error::ContextLostReason reason) OVERRIDE {
163 MaybeLock lock(need_to_lock_);
164 gpu_command_buffer_->SetContextLostReason(reason);
165 }
[email protected]b096d032013-03-08 03:08:01166 virtual uint32 InsertSyncPoint() OVERRIDE {
167 MaybeLock lock(need_to_lock_);
168 return gpu_command_buffer_->InsertSyncPoint();
169 }
[email protected]84b44c552012-10-15 20:58:17170
171 // Weak pointer - see class Graphics3D for the scopted_ptr.
172 gpu::CommandBuffer* gpu_command_buffer_;
173
174 bool need_to_lock_;
175};
176
[email protected]eeb4e4a2011-07-19 16:22:06177Graphics3D::Graphics3D(const HostResource& resource)
[email protected]84b44c552012-10-15 20:58:17178 : PPB_Graphics3D_Shared(resource),
179 num_already_locked_calls_(0) {
[email protected]eeb4e4a2011-07-19 16:22:06180}
181
182Graphics3D::~Graphics3D() {
183 DestroyGLES2Impl();
184}
185
[email protected]9ed07f82012-05-29 21:54:55186bool Graphics3D::Init(gpu::gles2::GLES2Implementation* share_gles2) {
[email protected]7f8b26b2011-08-18 15:41:01187 PluginDispatcher* dispatcher = PluginDispatcher::GetForResource(this);
[email protected]eeb4e4a2011-07-19 16:22:06188 if (!dispatcher)
189 return false;
190
[email protected]aaa11b32012-03-08 12:30:13191 command_buffer_.reset(
192 new PpapiCommandBufferProxy(host_resource(), dispatcher));
[email protected]84b44c552012-10-15 20:58:17193 locking_command_buffer_.reset(
194 new LockingCommandBuffer(command_buffer_.get()));
195
196 ScopedNoLocking already_locked(this);
[email protected]9ed07f82012-05-29 21:54:55197 return CreateGLES2Impl(kCommandBufferSize, kTransferBufferSize,
198 share_gles2);
[email protected]eeb4e4a2011-07-19 16:22:06199}
200
[email protected]503b3a22011-12-12 23:29:40201PP_Bool Graphics3D::SetGetBuffer(int32_t /* transfer_buffer_id */) {
[email protected]eeb4e4a2011-07-19 16:22:06202 return PP_FALSE;
203}
204
[email protected]914f5262013-06-01 00:17:22205gpu::CommandBuffer::State Graphics3D::GetState() {
[email protected]eeb4e4a2011-07-19 16:22:06206 return GetErrorState();
207}
208
209PP_Bool Graphics3D::Flush(int32_t put_offset) {
210 return PP_FALSE;
211}
212
[email protected]914f5262013-06-01 00:17:22213gpu::CommandBuffer::State Graphics3D::FlushSync(int32_t put_offset) {
[email protected]eeb4e4a2011-07-19 16:22:06214 return GetErrorState();
215}
216
217int32_t Graphics3D::CreateTransferBuffer(uint32_t size) {
218 return PP_FALSE;
219}
220
221PP_Bool Graphics3D::DestroyTransferBuffer(int32_t id) {
222 return PP_FALSE;
223}
224
225PP_Bool Graphics3D::GetTransferBuffer(int32_t id,
226 int* shm_handle,
227 uint32_t* shm_size) {
228 return PP_FALSE;
229}
230
[email protected]914f5262013-06-01 00:17:22231gpu::CommandBuffer::State Graphics3D::FlushSyncFast(int32_t put_offset,
[email protected]eeb4e4a2011-07-19 16:22:06232 int32_t last_known_get) {
233 return GetErrorState();
234}
235
[email protected]b096d032013-03-08 03:08:01236uint32_t Graphics3D::InsertSyncPoint() {
237 NOTREACHED();
238 return 0;
239}
240
[email protected]eeb4e4a2011-07-19 16:22:06241gpu::CommandBuffer* Graphics3D::GetCommandBuffer() {
[email protected]84b44c552012-10-15 20:58:17242 return locking_command_buffer_.get();
[email protected]eeb4e4a2011-07-19 16:22:06243}
244
245int32 Graphics3D::DoSwapBuffers() {
[email protected]84b44c552012-10-15 20:58:17246 // gles2_impl()->SwapBuffers() results in CommandBuffer calls, and we already
247 // have the proxy lock.
248 ScopedNoLocking already_locked(this);
249
[email protected]561438abd2011-11-24 01:06:23250 gles2_impl()->SwapBuffers();
[email protected]eeb4e4a2011-07-19 16:22:06251 IPC::Message* msg = new PpapiHostMsg_PPBGraphics3D_SwapBuffers(
[email protected]ac4b54d2011-10-20 23:09:28252 API_ID_PPB_GRAPHICS_3D, host_resource());
[email protected]eeb4e4a2011-07-19 16:22:06253 msg->set_unblock(true);
[email protected]7f8b26b2011-08-18 15:41:01254 PluginDispatcher::GetForResource(this)->Send(msg);
[email protected]eeb4e4a2011-07-19 16:22:06255
[email protected]eeb4e4a2011-07-19 16:22:06256 return PP_OK_COMPLETIONPENDING;
257}
258
[email protected]84b44c552012-10-15 20:58:17259void Graphics3D::PushAlreadyLocked() {
260 ppapi::ProxyLock::AssertAcquired();
261 if (num_already_locked_calls_ == 0)
262 locking_command_buffer_->set_need_to_lock(false);
263 ++num_already_locked_calls_;
264}
265
266void Graphics3D::PopAlreadyLocked() {
267 // We must have Pushed before we can Pop.
268 DCHECK(!locking_command_buffer_->need_to_lock());
269 DCHECK_GT(num_already_locked_calls_, 0);
270 ppapi::ProxyLock::AssertAcquired();
271 --num_already_locked_calls_;
272 if (num_already_locked_calls_ == 0)
273 locking_command_buffer_->set_need_to_lock(true);
274}
275
[email protected]5c966022011-09-13 18:09:37276PPB_Graphics3D_Proxy::PPB_Graphics3D_Proxy(Dispatcher* dispatcher)
277 : InterfaceProxy(dispatcher),
[email protected]a2f53dc2013-04-30 01:06:35278 callback_factory_(this) {
[email protected]eeb4e4a2011-07-19 16:22:06279}
280
281PPB_Graphics3D_Proxy::~PPB_Graphics3D_Proxy() {
282}
283
284// static
[email protected]eeb4e4a2011-07-19 16:22:06285PP_Resource PPB_Graphics3D_Proxy::CreateProxyResource(
286 PP_Instance instance,
[email protected]eeb4e4a2011-07-19 16:22:06287 PP_Resource share_context,
288 const int32_t* attrib_list) {
289 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
290 if (!dispatcher)
291 return PP_ERROR_BADARGUMENT;
292
[email protected]9ed07f82012-05-29 21:54:55293 HostResource share_host;
294 gpu::gles2::GLES2Implementation* share_gles2 = NULL;
295 if (share_context != 0) {
296 EnterResourceNoLock<PPB_Graphics3D_API> enter(share_context, true);
297 if (enter.failed())
298 return PP_ERROR_BADARGUMENT;
299
300 PPB_Graphics3D_Shared* share_graphics =
301 static_cast<PPB_Graphics3D_Shared*>(enter.object());
302 share_host = share_graphics->host_resource();
303 share_gles2 = share_graphics->gles2_impl();
304 }
[email protected]eeb4e4a2011-07-19 16:22:06305
306 std::vector<int32_t> attribs;
307 if (attrib_list) {
308 for (const int32_t* attr = attrib_list;
[email protected]0e50fc4d2011-08-01 15:33:51309 attr[0] != PP_GRAPHICS3DATTRIB_NONE;
310 attr += 2) {
311 attribs.push_back(attr[0]);
312 attribs.push_back(attr[1]);
[email protected]eeb4e4a2011-07-19 16:22:06313 }
[email protected]eeb4e4a2011-07-19 16:22:06314 }
[email protected]0e50fc4d2011-08-01 15:33:51315 attribs.push_back(PP_GRAPHICS3DATTRIB_NONE);
[email protected]eeb4e4a2011-07-19 16:22:06316
317 HostResource result;
318 dispatcher->Send(new PpapiHostMsg_PPBGraphics3D_Create(
[email protected]9ed07f82012-05-29 21:54:55319 API_ID_PPB_GRAPHICS_3D, instance, share_host, attribs, &result));
[email protected]eeb4e4a2011-07-19 16:22:06320 if (result.is_null())
321 return 0;
322
[email protected]51e1aec2011-08-11 04:48:30323 scoped_refptr<Graphics3D> graphics_3d(new Graphics3D(result));
[email protected]9ed07f82012-05-29 21:54:55324 if (!graphics_3d->Init(share_gles2))
[email protected]eeb4e4a2011-07-19 16:22:06325 return 0;
[email protected]7f8b26b2011-08-18 15:41:01326 return graphics_3d->GetReference();
[email protected]eeb4e4a2011-07-19 16:22:06327}
328
329bool PPB_Graphics3D_Proxy::OnMessageReceived(const IPC::Message& msg) {
330 bool handled = true;
331 IPC_BEGIN_MESSAGE_MAP(PPB_Graphics3D_Proxy, msg)
[email protected]11494c5c2012-11-13 02:50:57332#if !defined(OS_NACL)
[email protected]eeb4e4a2011-07-19 16:22:06333 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_Create,
334 OnMsgCreate)
[email protected]503b3a22011-12-12 23:29:40335 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_SetGetBuffer,
336 OnMsgSetGetBuffer)
[email protected]eeb4e4a2011-07-19 16:22:06337 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_GetState,
338 OnMsgGetState)
339 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_Flush,
340 OnMsgFlush)
341 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_AsyncFlush,
342 OnMsgAsyncFlush)
343 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_CreateTransferBuffer,
344 OnMsgCreateTransferBuffer)
345 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_DestroyTransferBuffer,
346 OnMsgDestroyTransferBuffer)
347 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_GetTransferBuffer,
348 OnMsgGetTransferBuffer)
349 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_SwapBuffers,
350 OnMsgSwapBuffers)
[email protected]b096d032013-03-08 03:08:01351 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_InsertSyncPoint,
352 OnMsgInsertSyncPoint)
[email protected]11494c5c2012-11-13 02:50:57353#endif // !defined(OS_NACL)
[email protected]eeb4e4a2011-07-19 16:22:06354
355 IPC_MESSAGE_HANDLER(PpapiMsg_PPBGraphics3D_SwapBuffersACK,
356 OnMsgSwapBuffersACK)
357 IPC_MESSAGE_UNHANDLED(handled = false)
358
359 IPC_END_MESSAGE_MAP()
360 // FIXME(brettw) handle bad messages!
361 return handled;
362}
363
[email protected]11494c5c2012-11-13 02:50:57364#if !defined(OS_NACL)
[email protected]eeb4e4a2011-07-19 16:22:06365void PPB_Graphics3D_Proxy::OnMsgCreate(PP_Instance instance,
[email protected]9ed07f82012-05-29 21:54:55366 HostResource share_context,
[email protected]eeb4e4a2011-07-19 16:22:06367 const std::vector<int32_t>& attribs,
368 HostResource* result) {
[email protected]48c1db72012-12-17 20:56:11369 if (attribs.empty() ||
370 attribs.back() != PP_GRAPHICS3DATTRIB_NONE ||
371 !(attribs.size() & 1))
[email protected]eeb4e4a2011-07-19 16:22:06372 return; // Bad message.
373
[email protected]5c966022011-09-13 18:09:37374 thunk::EnterResourceCreation enter(instance);
[email protected]9ed07f82012-05-29 21:54:55375
[email protected]eeb4e4a2011-07-19 16:22:06376 if (enter.succeeded()) {
377 result->SetHostResource(
[email protected]9ed07f82012-05-29 21:54:55378 instance,
379 enter.functions()->CreateGraphics3DRaw(instance,
380 share_context.host_resource(),
381 &attribs.front()));
[email protected]eeb4e4a2011-07-19 16:22:06382 }
383}
384
[email protected]503b3a22011-12-12 23:29:40385void PPB_Graphics3D_Proxy::OnMsgSetGetBuffer(
386 const HostResource& context,
387 int32 transfer_buffer_id) {
388 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context);
389 if (enter.succeeded())
390 enter.object()->SetGetBuffer(transfer_buffer_id);
[email protected]eeb4e4a2011-07-19 16:22:06391}
392
393void PPB_Graphics3D_Proxy::OnMsgGetState(const HostResource& context,
[email protected]571b35e82012-05-19 00:04:35394 gpu::CommandBuffer::State* state,
395 bool* success) {
[email protected]eeb4e4a2011-07-19 16:22:06396 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context);
[email protected]571b35e82012-05-19 00:04:35397 if (enter.failed()) {
398 *success = false;
[email protected]eeb4e4a2011-07-19 16:22:06399 return;
[email protected]571b35e82012-05-19 00:04:35400 }
[email protected]914f5262013-06-01 00:17:22401 *state = enter.object()->GetState();
[email protected]571b35e82012-05-19 00:04:35402 *success = true;
[email protected]eeb4e4a2011-07-19 16:22:06403}
404
405void PPB_Graphics3D_Proxy::OnMsgFlush(const HostResource& context,
406 int32 put_offset,
407 int32 last_known_get,
[email protected]571b35e82012-05-19 00:04:35408 gpu::CommandBuffer::State* state,
409 bool* success) {
[email protected]eeb4e4a2011-07-19 16:22:06410 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context);
[email protected]571b35e82012-05-19 00:04:35411 if (enter.failed()) {
412 *success = false;
[email protected]eeb4e4a2011-07-19 16:22:06413 return;
[email protected]571b35e82012-05-19 00:04:35414 }
[email protected]914f5262013-06-01 00:17:22415 *state = enter.object()->FlushSyncFast(put_offset, last_known_get);
[email protected]571b35e82012-05-19 00:04:35416 *success = true;
[email protected]eeb4e4a2011-07-19 16:22:06417}
418
419void PPB_Graphics3D_Proxy::OnMsgAsyncFlush(const HostResource& context,
420 int32 put_offset) {
421 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context);
422 if (enter.succeeded())
423 enter.object()->Flush(put_offset);
424}
425
426void PPB_Graphics3D_Proxy::OnMsgCreateTransferBuffer(
427 const HostResource& context,
[email protected]b31199e2012-12-12 00:48:29428 uint32 size,
[email protected]eeb4e4a2011-07-19 16:22:06429 int32* id) {
430 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context);
431 if (enter.succeeded())
432 *id = enter.object()->CreateTransferBuffer(size);
433 else
[email protected]67c80782012-12-21 01:16:52434 *id = -1;
[email protected]eeb4e4a2011-07-19 16:22:06435}
436
437void PPB_Graphics3D_Proxy::OnMsgDestroyTransferBuffer(
438 const HostResource& context,
439 int32 id) {
440 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context);
441 if (enter.succeeded())
442 enter.object()->DestroyTransferBuffer(id);
443}
444
445void PPB_Graphics3D_Proxy::OnMsgGetTransferBuffer(
446 const HostResource& context,
447 int32 id,
[email protected]246fc492012-08-27 20:28:18448 ppapi::proxy::SerializedHandle* transfer_buffer) {
449 transfer_buffer->set_null_shmem();
[email protected]eeb4e4a2011-07-19 16:22:06450
451 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context);
452 int shm_handle = 0;
453 uint32_t shm_size = 0;
454 if (enter.succeeded() &&
455 enter.object()->GetTransferBuffer(id, &shm_handle, &shm_size)) {
[email protected]246fc492012-08-27 20:28:18456 transfer_buffer->set_shmem(
457 TransportSHMHandleFromInt(dispatcher(), shm_handle),
458 shm_size);
[email protected]eeb4e4a2011-07-19 16:22:06459 }
460}
461
462void PPB_Graphics3D_Proxy::OnMsgSwapBuffers(const HostResource& context) {
[email protected]79d23c72011-08-08 19:40:40463 EnterHostFromHostResourceForceCallback<PPB_Graphics3D_API> enter(
464 context, callback_factory_,
[email protected]eeb4e4a2011-07-19 16:22:06465 &PPB_Graphics3D_Proxy::SendSwapBuffersACKToPlugin, context);
[email protected]eeb4e4a2011-07-19 16:22:06466 if (enter.succeeded())
[email protected]79d23c72011-08-08 19:40:40467 enter.SetResult(enter.object()->SwapBuffers(enter.callback()));
[email protected]eeb4e4a2011-07-19 16:22:06468}
[email protected]b096d032013-03-08 03:08:01469
470void PPB_Graphics3D_Proxy::OnMsgInsertSyncPoint(const HostResource& context,
471 uint32* sync_point) {
472 *sync_point = 0;
473 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context);
474 if (enter.succeeded())
475 *sync_point = enter.object()->InsertSyncPoint();
476}
[email protected]11494c5c2012-11-13 02:50:57477#endif // !defined(OS_NACL)
[email protected]eeb4e4a2011-07-19 16:22:06478
479void PPB_Graphics3D_Proxy::OnMsgSwapBuffersACK(const HostResource& resource,
480 int32_t pp_error) {
481 EnterPluginFromHostResource<PPB_Graphics3D_API> enter(resource);
482 if (enter.succeeded())
483 static_cast<Graphics3D*>(enter.object())->SwapBuffersACK(pp_error);
484}
485
[email protected]11494c5c2012-11-13 02:50:57486#if !defined(OS_NACL)
[email protected]eeb4e4a2011-07-19 16:22:06487void PPB_Graphics3D_Proxy::SendSwapBuffersACKToPlugin(
488 int32_t result,
489 const HostResource& context) {
490 dispatcher()->Send(new PpapiMsg_PPBGraphics3D_SwapBuffersACK(
[email protected]ac4b54d2011-10-20 23:09:28491 API_ID_PPB_GRAPHICS_3D, context, result));
[email protected]eeb4e4a2011-07-19 16:22:06492}
[email protected]11494c5c2012-11-13 02:50:57493#endif // !defined(OS_NACL)
[email protected]eeb4e4a2011-07-19 16:22:06494
495} // namespace proxy
[email protected]4d2efd22011-08-18 21:58:02496} // namespace ppapi
[email protected]eeb4e4a2011-07-19 16:22:06497