blob: ddacde6160653308006bf2ffbbbc12234f304db0 [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
48PP_Graphics3DTrustedState GetErrorState() {
49 PP_Graphics3DTrustedState error_state = { 0 };
50 error_state.error = PPB_GRAPHICS3D_TRUSTED_ERROR_GENERICERROR;
51 return error_state;
52}
53
54gpu::CommandBuffer::State GPUStateFromPPState(
55 const PP_Graphics3DTrustedState& s) {
56 gpu::CommandBuffer::State state;
57 state.num_entries = s.num_entries;
58 state.get_offset = s.get_offset;
59 state.put_offset = s.put_offset;
60 state.token = s.token;
61 state.error = static_cast<gpu::error::Error>(s.error);
62 state.generation = s.generation;
63 return state;
64}
65
[email protected]eeb4e4a2011-07-19 16:22:0666} // namespace
67
[email protected]84b44c552012-10-15 20:58:1768// This class just wraps a CommandBuffer and optionally locks around every
69// method. This is used to ensure that we have the Proxy lock any time we enter
70// PpapiCommandBufferProxy.
71//
72// Note, for performance reasons, most of this code is not truly thread
73// safe in the sense of multiple threads concurrently rendering to the same
74// Graphics3D context; this isn't allowed, and will likely either crash or
75// result in undefined behavior. It is assumed that the thread which creates
76// the Graphics3D context will be the thread on which subsequent gl rendering
77// will be done.
78//
79// TODO(nfullagar): At some point, allow multiple threads to concurrently render
80// each to its own context. First step is to allow a single thread (either main
81// thread or background thread) to render to a single Graphics3D context.
82class Graphics3D::LockingCommandBuffer : public gpu::CommandBuffer {
83 public:
84 explicit LockingCommandBuffer(gpu::CommandBuffer* gpu_command_buffer)
85 : gpu_command_buffer_(gpu_command_buffer), need_to_lock_(true) {
86 }
87 virtual ~LockingCommandBuffer() {
88 }
89 void set_need_to_lock(bool need_to_lock) { need_to_lock_ = need_to_lock; }
90 bool need_to_lock() const { return need_to_lock_; }
91
92 private:
93 // MaybeLock acquires the proxy lock on construction if and only if
94 // need_to_lock is true. If it acquired the lock, it releases it on
95 // destruction. If need_to_lock is false, then the lock must already be held.
96 struct MaybeLock {
97 explicit MaybeLock(bool need_to_lock) : locked_(need_to_lock) {
98 if (need_to_lock)
99 ppapi::ProxyLock::Acquire();
100 else
101 ppapi::ProxyLock::AssertAcquired();
102 }
103 ~MaybeLock() {
104 if (locked_)
105 ppapi::ProxyLock::Release();
106 }
107 private:
108 bool locked_;
109 };
110
111 // gpu::CommandBuffer implementation:
112 virtual bool Initialize() OVERRIDE {
113 MaybeLock lock(need_to_lock_);
114 return gpu_command_buffer_->Initialize();
115 }
116 virtual State GetState() OVERRIDE {
117 MaybeLock lock(need_to_lock_);
118 return gpu_command_buffer_->GetState();
119 }
120 virtual State GetLastState() OVERRIDE {
121 // During a normal scene, the vast majority of calls are to GetLastState().
122 // We don't allow multi-threaded rendering on the same contex, so for
123 // performance reasons, avoid the global lock for this entry point. We can
124 // get away with this here because the underlying implementation of
125 // GetLastState() is trivial and does not involve global or shared state
126 // between other contexts.
127 // TODO(nfullagar): We can probably skip MaybeLock for other methods, but
128 // the performance gain may not be worth it.
129 //
130 // MaybeLock lock(need_to_lock_);
131 return gpu_command_buffer_->GetLastState();
132 }
[email protected]a597c622013-01-25 05:08:38133 virtual int32 GetLastToken() OVERRIDE {
134 return GetLastState().token;
135 }
[email protected]84b44c552012-10-15 20:58:17136 virtual void Flush(int32 put_offset) OVERRIDE {
137 MaybeLock lock(need_to_lock_);
138 gpu_command_buffer_->Flush(put_offset);
139 }
140 virtual State FlushSync(int32 put_offset, int32 last_known_get) OVERRIDE {
141 MaybeLock lock(need_to_lock_);
142 return gpu_command_buffer_->FlushSync(put_offset, last_known_get);
143 }
144 virtual void SetGetBuffer(int32 transfer_buffer_id) OVERRIDE {
145 MaybeLock lock(need_to_lock_);
146 gpu_command_buffer_->SetGetBuffer(transfer_buffer_id);
147 }
148 virtual void SetGetOffset(int32 get_offset) OVERRIDE {
149 MaybeLock lock(need_to_lock_);
150 gpu_command_buffer_->SetGetOffset(get_offset);
151 }
[email protected]67c80782012-12-21 01:16:52152 virtual gpu::Buffer CreateTransferBuffer(size_t size,
153 int32* id) OVERRIDE {
[email protected]84b44c552012-10-15 20:58:17154 MaybeLock lock(need_to_lock_);
[email protected]67c80782012-12-21 01:16:52155 return gpu_command_buffer_->CreateTransferBuffer(size, id);
[email protected]84b44c552012-10-15 20:58:17156 }
157 virtual void DestroyTransferBuffer(int32 id) OVERRIDE {
158 MaybeLock lock(need_to_lock_);
159 gpu_command_buffer_->DestroyTransferBuffer(id);
160 }
[email protected]67c80782012-12-21 01:16:52161 virtual gpu::Buffer GetTransferBuffer(int32 id) OVERRIDE {
[email protected]84b44c552012-10-15 20:58:17162 MaybeLock lock(need_to_lock_);
[email protected]67c80782012-12-21 01:16:52163 return gpu_command_buffer_->GetTransferBuffer(id);
[email protected]84b44c552012-10-15 20:58:17164 }
165 virtual void SetToken(int32 token) OVERRIDE {
166 MaybeLock lock(need_to_lock_);
167 gpu_command_buffer_->SetToken(token);
168 }
169 virtual void SetParseError(gpu::error::Error error) OVERRIDE {
170 MaybeLock lock(need_to_lock_);
171 gpu_command_buffer_->SetParseError(error);
172 }
173 virtual void SetContextLostReason(
174 gpu::error::ContextLostReason reason) OVERRIDE {
175 MaybeLock lock(need_to_lock_);
176 gpu_command_buffer_->SetContextLostReason(reason);
177 }
[email protected]b096d032013-03-08 03:08:01178 virtual uint32 InsertSyncPoint() OVERRIDE {
179 MaybeLock lock(need_to_lock_);
180 return gpu_command_buffer_->InsertSyncPoint();
181 }
[email protected]84b44c552012-10-15 20:58:17182
183 // Weak pointer - see class Graphics3D for the scopted_ptr.
184 gpu::CommandBuffer* gpu_command_buffer_;
185
186 bool need_to_lock_;
187};
188
[email protected]eeb4e4a2011-07-19 16:22:06189Graphics3D::Graphics3D(const HostResource& resource)
[email protected]84b44c552012-10-15 20:58:17190 : PPB_Graphics3D_Shared(resource),
191 num_already_locked_calls_(0) {
[email protected]eeb4e4a2011-07-19 16:22:06192}
193
194Graphics3D::~Graphics3D() {
195 DestroyGLES2Impl();
196}
197
[email protected]9ed07f82012-05-29 21:54:55198bool Graphics3D::Init(gpu::gles2::GLES2Implementation* share_gles2) {
[email protected]7f8b26b2011-08-18 15:41:01199 PluginDispatcher* dispatcher = PluginDispatcher::GetForResource(this);
[email protected]eeb4e4a2011-07-19 16:22:06200 if (!dispatcher)
201 return false;
202
[email protected]aaa11b32012-03-08 12:30:13203 command_buffer_.reset(
204 new PpapiCommandBufferProxy(host_resource(), dispatcher));
[email protected]84b44c552012-10-15 20:58:17205 locking_command_buffer_.reset(
206 new LockingCommandBuffer(command_buffer_.get()));
207
208 ScopedNoLocking already_locked(this);
[email protected]503b3a22011-12-12 23:29:40209 if (!command_buffer_->Initialize())
[email protected]0e50fc4d2011-08-01 15:33:51210 return false;
[email protected]eeb4e4a2011-07-19 16:22:06211
[email protected]9ed07f82012-05-29 21:54:55212 return CreateGLES2Impl(kCommandBufferSize, kTransferBufferSize,
213 share_gles2);
[email protected]eeb4e4a2011-07-19 16:22:06214}
215
[email protected]503b3a22011-12-12 23:29:40216PP_Bool Graphics3D::InitCommandBuffer() {
[email protected]eeb4e4a2011-07-19 16:22:06217 return PP_FALSE;
218}
219
[email protected]503b3a22011-12-12 23:29:40220PP_Bool Graphics3D::SetGetBuffer(int32_t /* transfer_buffer_id */) {
[email protected]eeb4e4a2011-07-19 16:22:06221 return PP_FALSE;
222}
223
224PP_Graphics3DTrustedState Graphics3D::GetState() {
225 return GetErrorState();
226}
227
228PP_Bool Graphics3D::Flush(int32_t put_offset) {
229 return PP_FALSE;
230}
231
232PP_Graphics3DTrustedState Graphics3D::FlushSync(int32_t put_offset) {
233 return GetErrorState();
234}
235
236int32_t Graphics3D::CreateTransferBuffer(uint32_t size) {
237 return PP_FALSE;
238}
239
240PP_Bool Graphics3D::DestroyTransferBuffer(int32_t id) {
241 return PP_FALSE;
242}
243
244PP_Bool Graphics3D::GetTransferBuffer(int32_t id,
245 int* shm_handle,
246 uint32_t* shm_size) {
247 return PP_FALSE;
248}
249
250PP_Graphics3DTrustedState Graphics3D::FlushSyncFast(int32_t put_offset,
251 int32_t last_known_get) {
252 return GetErrorState();
253}
254
[email protected]b096d032013-03-08 03:08:01255uint32_t Graphics3D::InsertSyncPoint() {
256 NOTREACHED();
257 return 0;
258}
259
[email protected]eeb4e4a2011-07-19 16:22:06260gpu::CommandBuffer* Graphics3D::GetCommandBuffer() {
[email protected]84b44c552012-10-15 20:58:17261 return locking_command_buffer_.get();
[email protected]eeb4e4a2011-07-19 16:22:06262}
263
264int32 Graphics3D::DoSwapBuffers() {
[email protected]84b44c552012-10-15 20:58:17265 // gles2_impl()->SwapBuffers() results in CommandBuffer calls, and we already
266 // have the proxy lock.
267 ScopedNoLocking already_locked(this);
268
[email protected]561438abd2011-11-24 01:06:23269 gles2_impl()->SwapBuffers();
[email protected]eeb4e4a2011-07-19 16:22:06270 IPC::Message* msg = new PpapiHostMsg_PPBGraphics3D_SwapBuffers(
[email protected]ac4b54d2011-10-20 23:09:28271 API_ID_PPB_GRAPHICS_3D, host_resource());
[email protected]eeb4e4a2011-07-19 16:22:06272 msg->set_unblock(true);
[email protected]7f8b26b2011-08-18 15:41:01273 PluginDispatcher::GetForResource(this)->Send(msg);
[email protected]eeb4e4a2011-07-19 16:22:06274
[email protected]eeb4e4a2011-07-19 16:22:06275 return PP_OK_COMPLETIONPENDING;
276}
277
[email protected]84b44c552012-10-15 20:58:17278void Graphics3D::PushAlreadyLocked() {
279 ppapi::ProxyLock::AssertAcquired();
280 if (num_already_locked_calls_ == 0)
281 locking_command_buffer_->set_need_to_lock(false);
282 ++num_already_locked_calls_;
283}
284
285void Graphics3D::PopAlreadyLocked() {
286 // We must have Pushed before we can Pop.
287 DCHECK(!locking_command_buffer_->need_to_lock());
288 DCHECK_GT(num_already_locked_calls_, 0);
289 ppapi::ProxyLock::AssertAcquired();
290 --num_already_locked_calls_;
291 if (num_already_locked_calls_ == 0)
292 locking_command_buffer_->set_need_to_lock(true);
293}
294
[email protected]5c966022011-09-13 18:09:37295PPB_Graphics3D_Proxy::PPB_Graphics3D_Proxy(Dispatcher* dispatcher)
296 : InterfaceProxy(dispatcher),
[email protected]a2f53dc2013-04-30 01:06:35297 callback_factory_(this) {
[email protected]eeb4e4a2011-07-19 16:22:06298}
299
300PPB_Graphics3D_Proxy::~PPB_Graphics3D_Proxy() {
301}
302
303// static
[email protected]eeb4e4a2011-07-19 16:22:06304PP_Resource PPB_Graphics3D_Proxy::CreateProxyResource(
305 PP_Instance instance,
[email protected]eeb4e4a2011-07-19 16:22:06306 PP_Resource share_context,
307 const int32_t* attrib_list) {
308 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
309 if (!dispatcher)
310 return PP_ERROR_BADARGUMENT;
311
[email protected]9ed07f82012-05-29 21:54:55312 HostResource share_host;
313 gpu::gles2::GLES2Implementation* share_gles2 = NULL;
314 if (share_context != 0) {
315 EnterResourceNoLock<PPB_Graphics3D_API> enter(share_context, true);
316 if (enter.failed())
317 return PP_ERROR_BADARGUMENT;
318
319 PPB_Graphics3D_Shared* share_graphics =
320 static_cast<PPB_Graphics3D_Shared*>(enter.object());
321 share_host = share_graphics->host_resource();
322 share_gles2 = share_graphics->gles2_impl();
323 }
[email protected]eeb4e4a2011-07-19 16:22:06324
325 std::vector<int32_t> attribs;
326 if (attrib_list) {
327 for (const int32_t* attr = attrib_list;
[email protected]0e50fc4d2011-08-01 15:33:51328 attr[0] != PP_GRAPHICS3DATTRIB_NONE;
329 attr += 2) {
330 attribs.push_back(attr[0]);
331 attribs.push_back(attr[1]);
[email protected]eeb4e4a2011-07-19 16:22:06332 }
[email protected]eeb4e4a2011-07-19 16:22:06333 }
[email protected]0e50fc4d2011-08-01 15:33:51334 attribs.push_back(PP_GRAPHICS3DATTRIB_NONE);
[email protected]eeb4e4a2011-07-19 16:22:06335
336 HostResource result;
337 dispatcher->Send(new PpapiHostMsg_PPBGraphics3D_Create(
[email protected]9ed07f82012-05-29 21:54:55338 API_ID_PPB_GRAPHICS_3D, instance, share_host, attribs, &result));
[email protected]eeb4e4a2011-07-19 16:22:06339 if (result.is_null())
340 return 0;
341
[email protected]51e1aec2011-08-11 04:48:30342 scoped_refptr<Graphics3D> graphics_3d(new Graphics3D(result));
[email protected]9ed07f82012-05-29 21:54:55343 if (!graphics_3d->Init(share_gles2))
[email protected]eeb4e4a2011-07-19 16:22:06344 return 0;
[email protected]7f8b26b2011-08-18 15:41:01345 return graphics_3d->GetReference();
[email protected]eeb4e4a2011-07-19 16:22:06346}
347
348bool PPB_Graphics3D_Proxy::OnMessageReceived(const IPC::Message& msg) {
349 bool handled = true;
350 IPC_BEGIN_MESSAGE_MAP(PPB_Graphics3D_Proxy, msg)
[email protected]11494c5c2012-11-13 02:50:57351#if !defined(OS_NACL)
[email protected]eeb4e4a2011-07-19 16:22:06352 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_Create,
353 OnMsgCreate)
354 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_InitCommandBuffer,
355 OnMsgInitCommandBuffer)
[email protected]503b3a22011-12-12 23:29:40356 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_SetGetBuffer,
357 OnMsgSetGetBuffer)
[email protected]eeb4e4a2011-07-19 16:22:06358 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_GetState,
359 OnMsgGetState)
360 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_Flush,
361 OnMsgFlush)
362 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_AsyncFlush,
363 OnMsgAsyncFlush)
364 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_CreateTransferBuffer,
365 OnMsgCreateTransferBuffer)
366 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_DestroyTransferBuffer,
367 OnMsgDestroyTransferBuffer)
368 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_GetTransferBuffer,
369 OnMsgGetTransferBuffer)
370 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_SwapBuffers,
371 OnMsgSwapBuffers)
[email protected]b096d032013-03-08 03:08:01372 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_InsertSyncPoint,
373 OnMsgInsertSyncPoint)
[email protected]11494c5c2012-11-13 02:50:57374#endif // !defined(OS_NACL)
[email protected]eeb4e4a2011-07-19 16:22:06375
376 IPC_MESSAGE_HANDLER(PpapiMsg_PPBGraphics3D_SwapBuffersACK,
377 OnMsgSwapBuffersACK)
378 IPC_MESSAGE_UNHANDLED(handled = false)
379
380 IPC_END_MESSAGE_MAP()
381 // FIXME(brettw) handle bad messages!
382 return handled;
383}
384
[email protected]11494c5c2012-11-13 02:50:57385#if !defined(OS_NACL)
[email protected]eeb4e4a2011-07-19 16:22:06386void PPB_Graphics3D_Proxy::OnMsgCreate(PP_Instance instance,
[email protected]9ed07f82012-05-29 21:54:55387 HostResource share_context,
[email protected]eeb4e4a2011-07-19 16:22:06388 const std::vector<int32_t>& attribs,
389 HostResource* result) {
[email protected]48c1db72012-12-17 20:56:11390 if (attribs.empty() ||
391 attribs.back() != PP_GRAPHICS3DATTRIB_NONE ||
392 !(attribs.size() & 1))
[email protected]eeb4e4a2011-07-19 16:22:06393 return; // Bad message.
394
[email protected]5c966022011-09-13 18:09:37395 thunk::EnterResourceCreation enter(instance);
[email protected]9ed07f82012-05-29 21:54:55396
[email protected]eeb4e4a2011-07-19 16:22:06397 if (enter.succeeded()) {
398 result->SetHostResource(
[email protected]9ed07f82012-05-29 21:54:55399 instance,
400 enter.functions()->CreateGraphics3DRaw(instance,
401 share_context.host_resource(),
402 &attribs.front()));
[email protected]eeb4e4a2011-07-19 16:22:06403 }
404}
405
406void PPB_Graphics3D_Proxy::OnMsgInitCommandBuffer(
[email protected]503b3a22011-12-12 23:29:40407 const HostResource& context) {
[email protected]eeb4e4a2011-07-19 16:22:06408 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context);
409 if (enter.failed())
410 return;
411
[email protected]503b3a22011-12-12 23:29:40412 if (!enter.object()->InitCommandBuffer())
[email protected]eeb4e4a2011-07-19 16:22:06413 return;
[email protected]503b3a22011-12-12 23:29:40414}
[email protected]eeb4e4a2011-07-19 16:22:06415
[email protected]503b3a22011-12-12 23:29:40416void PPB_Graphics3D_Proxy::OnMsgSetGetBuffer(
417 const HostResource& context,
418 int32 transfer_buffer_id) {
419 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context);
420 if (enter.succeeded())
421 enter.object()->SetGetBuffer(transfer_buffer_id);
[email protected]eeb4e4a2011-07-19 16:22:06422}
423
424void PPB_Graphics3D_Proxy::OnMsgGetState(const HostResource& context,
[email protected]571b35e82012-05-19 00:04:35425 gpu::CommandBuffer::State* state,
426 bool* success) {
[email protected]eeb4e4a2011-07-19 16:22:06427 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context);
[email protected]571b35e82012-05-19 00:04:35428 if (enter.failed()) {
429 *success = false;
[email protected]eeb4e4a2011-07-19 16:22:06430 return;
[email protected]571b35e82012-05-19 00:04:35431 }
[email protected]eeb4e4a2011-07-19 16:22:06432 PP_Graphics3DTrustedState pp_state = enter.object()->GetState();
433 *state = GPUStateFromPPState(pp_state);
[email protected]571b35e82012-05-19 00:04:35434 *success = true;
[email protected]eeb4e4a2011-07-19 16:22:06435}
436
437void PPB_Graphics3D_Proxy::OnMsgFlush(const HostResource& context,
438 int32 put_offset,
439 int32 last_known_get,
[email protected]571b35e82012-05-19 00:04:35440 gpu::CommandBuffer::State* state,
441 bool* success) {
[email protected]eeb4e4a2011-07-19 16:22:06442 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context);
[email protected]571b35e82012-05-19 00:04:35443 if (enter.failed()) {
444 *success = false;
[email protected]eeb4e4a2011-07-19 16:22:06445 return;
[email protected]571b35e82012-05-19 00:04:35446 }
[email protected]eeb4e4a2011-07-19 16:22:06447 PP_Graphics3DTrustedState pp_state = enter.object()->FlushSyncFast(
448 put_offset, last_known_get);
449 *state = GPUStateFromPPState(pp_state);
[email protected]571b35e82012-05-19 00:04:35450 *success = true;
[email protected]eeb4e4a2011-07-19 16:22:06451}
452
453void PPB_Graphics3D_Proxy::OnMsgAsyncFlush(const HostResource& context,
454 int32 put_offset) {
455 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context);
456 if (enter.succeeded())
457 enter.object()->Flush(put_offset);
458}
459
460void PPB_Graphics3D_Proxy::OnMsgCreateTransferBuffer(
461 const HostResource& context,
[email protected]b31199e2012-12-12 00:48:29462 uint32 size,
[email protected]eeb4e4a2011-07-19 16:22:06463 int32* id) {
464 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context);
465 if (enter.succeeded())
466 *id = enter.object()->CreateTransferBuffer(size);
467 else
[email protected]67c80782012-12-21 01:16:52468 *id = -1;
[email protected]eeb4e4a2011-07-19 16:22:06469}
470
471void PPB_Graphics3D_Proxy::OnMsgDestroyTransferBuffer(
472 const HostResource& context,
473 int32 id) {
474 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context);
475 if (enter.succeeded())
476 enter.object()->DestroyTransferBuffer(id);
477}
478
479void PPB_Graphics3D_Proxy::OnMsgGetTransferBuffer(
480 const HostResource& context,
481 int32 id,
[email protected]246fc492012-08-27 20:28:18482 ppapi::proxy::SerializedHandle* transfer_buffer) {
483 transfer_buffer->set_null_shmem();
[email protected]eeb4e4a2011-07-19 16:22:06484
485 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context);
486 int shm_handle = 0;
487 uint32_t shm_size = 0;
488 if (enter.succeeded() &&
489 enter.object()->GetTransferBuffer(id, &shm_handle, &shm_size)) {
[email protected]246fc492012-08-27 20:28:18490 transfer_buffer->set_shmem(
491 TransportSHMHandleFromInt(dispatcher(), shm_handle),
492 shm_size);
[email protected]eeb4e4a2011-07-19 16:22:06493 }
494}
495
496void PPB_Graphics3D_Proxy::OnMsgSwapBuffers(const HostResource& context) {
[email protected]79d23c72011-08-08 19:40:40497 EnterHostFromHostResourceForceCallback<PPB_Graphics3D_API> enter(
498 context, callback_factory_,
[email protected]eeb4e4a2011-07-19 16:22:06499 &PPB_Graphics3D_Proxy::SendSwapBuffersACKToPlugin, context);
[email protected]eeb4e4a2011-07-19 16:22:06500 if (enter.succeeded())
[email protected]79d23c72011-08-08 19:40:40501 enter.SetResult(enter.object()->SwapBuffers(enter.callback()));
[email protected]eeb4e4a2011-07-19 16:22:06502}
[email protected]b096d032013-03-08 03:08:01503
504void PPB_Graphics3D_Proxy::OnMsgInsertSyncPoint(const HostResource& context,
505 uint32* sync_point) {
506 *sync_point = 0;
507 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context);
508 if (enter.succeeded())
509 *sync_point = enter.object()->InsertSyncPoint();
510}
[email protected]11494c5c2012-11-13 02:50:57511#endif // !defined(OS_NACL)
[email protected]eeb4e4a2011-07-19 16:22:06512
513void PPB_Graphics3D_Proxy::OnMsgSwapBuffersACK(const HostResource& resource,
514 int32_t pp_error) {
515 EnterPluginFromHostResource<PPB_Graphics3D_API> enter(resource);
516 if (enter.succeeded())
517 static_cast<Graphics3D*>(enter.object())->SwapBuffersACK(pp_error);
518}
519
[email protected]11494c5c2012-11-13 02:50:57520#if !defined(OS_NACL)
[email protected]eeb4e4a2011-07-19 16:22:06521void PPB_Graphics3D_Proxy::SendSwapBuffersACKToPlugin(
522 int32_t result,
523 const HostResource& context) {
524 dispatcher()->Send(new PpapiMsg_PPBGraphics3D_SwapBuffersACK(
[email protected]ac4b54d2011-10-20 23:09:28525 API_ID_PPB_GRAPHICS_3D, context, result));
[email protected]eeb4e4a2011-07-19 16:22:06526}
[email protected]11494c5c2012-11-13 02:50:57527#endif // !defined(OS_NACL)
[email protected]eeb4e4a2011-07-19 16:22:06528
529} // namespace proxy
[email protected]4d2efd22011-08-18 21:58:02530} // namespace ppapi
[email protected]eeb4e4a2011-07-19 16:22:06531