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 "gpu/command_buffer/client/gles2_implementation.h" | 7 #include "gpu/command_buffer/client/gles2_implementation.h" |
8 #include "gpu/command_buffer/common/command_buffer.h" | 8 #include "gpu/command_buffer/common/command_buffer.h" |
9 #include "ppapi/c/pp_errors.h" | 9 #include "ppapi/c/pp_errors.h" |
10 #include "ppapi/proxy/enter_proxy.h" | 10 #include "ppapi/proxy/enter_proxy.h" |
(...skipping 10 matching lines...) Expand all Loading... | |
21 using ppapi::thunk::ResourceCreationAPI; | 21 using ppapi::thunk::ResourceCreationAPI; |
22 | 22 |
23 namespace ppapi { | 23 namespace ppapi { |
24 namespace proxy { | 24 namespace proxy { |
25 | 25 |
26 namespace { | 26 namespace { |
27 | 27 |
28 const int32 kCommandBufferSize = 1024 * 1024; | 28 const int32 kCommandBufferSize = 1024 * 1024; |
29 const int32 kTransferBufferSize = 1024 * 1024; | 29 const int32 kTransferBufferSize = 1024 * 1024; |
30 | 30 |
31 base::SharedMemoryHandle TransportSHMHandle(Dispatcher* dispatcher, | 31 base::SharedMemoryHandle TransportSHMHandle( |
32 base::SharedMemory* shm) { | 32 Dispatcher* dispatcher, |
33 base::PlatformFile source = | 33 const base::SharedMemoryHandle& handle) { |
34 IPC::PlatformFileForTransitToPlatformFile(shm->handle()); | 34 base::PlatformFile source = IPC::PlatformFileForTransitToPlatformFile(handle); |
35 // Don't close the handle, it doesn't belong to us. | 35 // Don't close the handle, it doesn't belong to us. |
36 return dispatcher->ShareHandleWithRemote(source, false); | 36 return dispatcher->ShareHandleWithRemote(source, false); |
37 } | 37 } |
38 | 38 |
39 gpu::CommandBuffer::State GetErrorState() { | 39 gpu::CommandBuffer::State GetErrorState() { |
40 gpu::CommandBuffer::State error_state; | 40 gpu::CommandBuffer::State error_state; |
41 error_state.error = gpu::error::kGenericError; | 41 error_state.error = gpu::error::kGenericError; |
42 return error_state; | 42 return error_state; |
43 } | 43 } |
44 | 44 |
45 } // namespace | 45 } // namespace |
46 | 46 |
47 Graphics3D::Graphics3D(const HostResource& resource) | 47 Graphics3D::Graphics3D(const HostResource& resource) |
48 : PPB_Graphics3D_Shared(resource) { | 48 : PPB_Graphics3D_Shared(resource) { |
49 } | 49 } |
50 | 50 |
51 Graphics3D::~Graphics3D() { | 51 Graphics3D::~Graphics3D() { |
52 DestroyGLES2Impl(); | 52 DestroyGLES2Impl(); |
53 } | 53 } |
54 | 54 |
55 bool Graphics3D::Init(gpu::gles2::GLES2Implementation* share_gles2) { | 55 bool Graphics3D::Init(gpu::gles2::GLES2Implementation* share_gles2, |
56 const SerializedHandle& shared_state) { | |
56 PluginDispatcher* dispatcher = PluginDispatcher::GetForResource(this); | 57 PluginDispatcher* dispatcher = PluginDispatcher::GetForResource(this); |
57 if (!dispatcher) | 58 if (!dispatcher) |
58 return false; | 59 return false; |
59 | 60 |
60 command_buffer_.reset( | 61 command_buffer_.reset( |
61 new PpapiCommandBufferProxy(host_resource(), dispatcher)); | 62 new PpapiCommandBufferProxy(host_resource(), dispatcher, shared_state)); |
62 | 63 |
63 return CreateGLES2Impl(kCommandBufferSize, kTransferBufferSize, | 64 return CreateGLES2Impl(kCommandBufferSize, kTransferBufferSize, |
64 share_gles2); | 65 share_gles2); |
65 } | 66 } |
66 | 67 |
67 PP_Bool Graphics3D::SetGetBuffer(int32_t /* transfer_buffer_id */) { | 68 PP_Bool Graphics3D::SetGetBuffer(int32_t /* transfer_buffer_id */) { |
68 return PP_FALSE; | 69 return PP_FALSE; |
69 } | 70 } |
70 | 71 |
71 PP_Bool Graphics3D::Flush(int32_t put_offset) { | 72 PP_Bool Graphics3D::Flush(int32_t put_offset) { |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
160 for (const int32_t* attr = attrib_list; | 161 for (const int32_t* attr = attrib_list; |
161 attr[0] != PP_GRAPHICS3DATTRIB_NONE; | 162 attr[0] != PP_GRAPHICS3DATTRIB_NONE; |
162 attr += 2) { | 163 attr += 2) { |
163 attribs.push_back(attr[0]); | 164 attribs.push_back(attr[0]); |
164 attribs.push_back(attr[1]); | 165 attribs.push_back(attr[1]); |
165 } | 166 } |
166 } | 167 } |
167 attribs.push_back(PP_GRAPHICS3DATTRIB_NONE); | 168 attribs.push_back(PP_GRAPHICS3DATTRIB_NONE); |
168 | 169 |
169 HostResource result; | 170 HostResource result; |
170 dispatcher->Send(new PpapiHostMsg_PPBGraphics3D_Create( | 171 ppapi::proxy::SerializedHandle shared_state; |
171 API_ID_PPB_GRAPHICS_3D, instance, share_host, attribs, &result)); | 172 //( |
173 // ppapi::proxy::SerializedHandle::SHARED_MEMORY); | |
piman
2014/09/08 21:02:04
nit: bogus comment?
Peng
2014/09/08 21:12:22
Done.
| |
174 dispatcher->Send(new PpapiHostMsg_PPBGraphics3D_Create(API_ID_PPB_GRAPHICS_3D, | |
175 instance, share_host, attribs, &result, &shared_state)); | |
176 | |
172 if (result.is_null()) | 177 if (result.is_null()) |
173 return 0; | 178 return 0; |
174 | 179 |
175 scoped_refptr<Graphics3D> graphics_3d(new Graphics3D(result)); | 180 scoped_refptr<Graphics3D> graphics_3d(new Graphics3D(result)); |
176 if (!graphics_3d->Init(share_gles2)) | 181 if (!graphics_3d->Init(share_gles2, shared_state)) |
177 return 0; | 182 return 0; |
178 return graphics_3d->GetReference(); | 183 return graphics_3d->GetReference(); |
179 } | 184 } |
180 | 185 |
181 bool PPB_Graphics3D_Proxy::OnMessageReceived(const IPC::Message& msg) { | 186 bool PPB_Graphics3D_Proxy::OnMessageReceived(const IPC::Message& msg) { |
182 bool handled = true; | 187 bool handled = true; |
183 IPC_BEGIN_MESSAGE_MAP(PPB_Graphics3D_Proxy, msg) | 188 IPC_BEGIN_MESSAGE_MAP(PPB_Graphics3D_Proxy, msg) |
184 #if !defined(OS_NACL) | 189 #if !defined(OS_NACL) |
185 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_Create, | 190 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_Create, |
186 OnMsgCreate) | 191 OnMsgCreate) |
(...skipping 24 matching lines...) Expand all Loading... | |
211 | 216 |
212 IPC_END_MESSAGE_MAP() | 217 IPC_END_MESSAGE_MAP() |
213 // FIXME(brettw) handle bad messages! | 218 // FIXME(brettw) handle bad messages! |
214 return handled; | 219 return handled; |
215 } | 220 } |
216 | 221 |
217 #if !defined(OS_NACL) | 222 #if !defined(OS_NACL) |
218 void PPB_Graphics3D_Proxy::OnMsgCreate(PP_Instance instance, | 223 void PPB_Graphics3D_Proxy::OnMsgCreate(PP_Instance instance, |
219 HostResource share_context, | 224 HostResource share_context, |
220 const std::vector<int32_t>& attribs, | 225 const std::vector<int32_t>& attribs, |
221 HostResource* result) { | 226 HostResource* result, |
227 SerializedHandle* shared_state) { | |
228 shared_state->set_null_shmem(); | |
222 if (attribs.empty() || | 229 if (attribs.empty() || |
223 attribs.back() != PP_GRAPHICS3DATTRIB_NONE || | 230 attribs.back() != PP_GRAPHICS3DATTRIB_NONE || |
224 !(attribs.size() & 1)) | 231 !(attribs.size() & 1)) |
225 return; // Bad message. | 232 return; // Bad message. |
226 | 233 |
227 thunk::EnterResourceCreation enter(instance); | 234 thunk::EnterResourceCreation enter(instance); |
228 | 235 |
229 if (enter.succeeded()) { | 236 if (!enter.succeeded()) |
230 result->SetHostResource( | 237 return; |
238 | |
239 base::SharedMemoryHandle handle = IPC::InvalidPlatformFileForTransit(); | |
240 result->SetHostResource( | |
231 instance, | 241 instance, |
232 enter.functions()->CreateGraphics3DRaw(instance, | 242 enter.functions()->CreateGraphics3DRaw(instance, |
233 share_context.host_resource(), | 243 share_context.host_resource(), |
234 &attribs.front())); | 244 &attribs.front(), |
245 &handle)); | |
246 if (!result->is_null()) { | |
247 shared_state->set_shmem(TransportSHMHandle(dispatcher(), handle), | |
248 sizeof(gpu::CommandBuffer::State)); | |
235 } | 249 } |
236 } | 250 } |
237 | 251 |
238 void PPB_Graphics3D_Proxy::OnMsgSetGetBuffer( | 252 void PPB_Graphics3D_Proxy::OnMsgSetGetBuffer( |
239 const HostResource& context, | 253 const HostResource& context, |
240 int32 transfer_buffer_id) { | 254 int32 transfer_buffer_id) { |
241 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); | 255 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); |
242 if (enter.succeeded()) | 256 if (enter.succeeded()) |
243 enter.object()->SetGetBuffer(transfer_buffer_id); | 257 enter.object()->SetGetBuffer(transfer_buffer_id); |
244 } | 258 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
277 int32 put_offset) { | 291 int32 put_offset) { |
278 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); | 292 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); |
279 if (enter.succeeded()) | 293 if (enter.succeeded()) |
280 enter.object()->Flush(put_offset); | 294 enter.object()->Flush(put_offset); |
281 } | 295 } |
282 | 296 |
283 void PPB_Graphics3D_Proxy::OnMsgCreateTransferBuffer( | 297 void PPB_Graphics3D_Proxy::OnMsgCreateTransferBuffer( |
284 const HostResource& context, | 298 const HostResource& context, |
285 uint32 size, | 299 uint32 size, |
286 int32* id, | 300 int32* id, |
287 ppapi::proxy::SerializedHandle* transfer_buffer) { | 301 SerializedHandle* transfer_buffer) { |
288 transfer_buffer->set_null_shmem(); | 302 transfer_buffer->set_null_shmem(); |
289 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); | 303 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); |
290 if (enter.succeeded()) { | 304 if (enter.succeeded()) { |
291 scoped_refptr<gpu::Buffer> buffer = | 305 scoped_refptr<gpu::Buffer> buffer = |
292 enter.object()->CreateTransferBuffer(size, id); | 306 enter.object()->CreateTransferBuffer(size, id); |
293 if (!buffer.get()) | 307 if (!buffer.get()) |
294 return; | 308 return; |
295 gpu::SharedMemoryBufferBacking* backing = | 309 gpu::SharedMemoryBufferBacking* backing = |
296 static_cast<gpu::SharedMemoryBufferBacking*>(buffer->backing()); | 310 static_cast<gpu::SharedMemoryBufferBacking*>(buffer->backing()); |
297 DCHECK(backing && backing->shared_memory()); | 311 DCHECK(backing && backing->shared_memory()); |
298 transfer_buffer->set_shmem( | 312 transfer_buffer->set_shmem( |
299 TransportSHMHandle(dispatcher(), backing->shared_memory()), | 313 TransportSHMHandle(dispatcher(), backing->shared_memory()->handle()), |
300 buffer->size()); | 314 buffer->size()); |
301 } else { | 315 } else { |
302 *id = -1; | 316 *id = -1; |
303 } | 317 } |
304 } | 318 } |
305 | 319 |
306 void PPB_Graphics3D_Proxy::OnMsgDestroyTransferBuffer( | 320 void PPB_Graphics3D_Proxy::OnMsgDestroyTransferBuffer( |
307 const HostResource& context, | 321 const HostResource& context, |
308 int32 id) { | 322 int32 id) { |
309 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); | 323 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
356 int32_t result, | 370 int32_t result, |
357 const HostResource& context) { | 371 const HostResource& context) { |
358 dispatcher()->Send(new PpapiMsg_PPBGraphics3D_SwapBuffersACK( | 372 dispatcher()->Send(new PpapiMsg_PPBGraphics3D_SwapBuffersACK( |
359 API_ID_PPB_GRAPHICS_3D, context, result)); | 373 API_ID_PPB_GRAPHICS_3D, context, result)); |
360 } | 374 } |
361 #endif // !defined(OS_NACL) | 375 #endif // !defined(OS_NACL) |
362 | 376 |
363 } // namespace proxy | 377 } // namespace proxy |
364 } // namespace ppapi | 378 } // namespace ppapi |
365 | 379 |
OLD | NEW |