OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 "ppapi/c/pp_errors.h" | 8 #include "ppapi/c/pp_errors.h" |
9 #include "ppapi/proxy/enter_proxy.h" | 9 #include "ppapi/proxy/enter_proxy.h" |
10 #include "ppapi/proxy/plugin_dispatcher.h" | 10 #include "ppapi/proxy/plugin_dispatcher.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 namespace { | 24 namespace { |
25 const int32 kCommandBufferSize = 1024 * 1024; | 25 const int32 kCommandBufferSize = 1024 * 1024; |
26 const int32 kTransferBufferSize = 1024 * 1024; | 26 const int32 kTransferBufferSize = 1024 * 1024; |
27 | 27 |
28 class CommandBuffer : public gpu::CommandBuffer { | 28 class CommandBuffer : public gpu::CommandBuffer { |
29 public: | 29 public: |
30 CommandBuffer(const HostResource& resource, PluginDispatcher* dispatcher); | 30 CommandBuffer(const HostResource& resource, PluginDispatcher* dispatcher); |
31 virtual ~CommandBuffer(); | 31 virtual ~CommandBuffer(); |
32 | 32 |
33 // gpu::CommandBuffer implementation: | 33 // gpu::CommandBuffer implementation: |
34 virtual bool Initialize(int32 size); | 34 virtual bool Initialize(); |
35 virtual bool Initialize(base::SharedMemory* buffer, int32 size); | |
36 virtual gpu::Buffer GetRingBuffer(); | |
37 virtual State GetState(); | 35 virtual State GetState(); |
38 virtual State GetLastState(); | 36 virtual State GetLastState(); |
39 virtual void Flush(int32 put_offset); | 37 virtual void Flush(int32 put_offset); |
40 virtual State FlushSync(int32 put_offset, int32 last_known_get); | 38 virtual State FlushSync(int32 put_offset, int32 last_known_get); |
| 39 virtual void SetGetBuffer(int32 transfer_buffer_id); |
41 virtual void SetGetOffset(int32 get_offset); | 40 virtual void SetGetOffset(int32 get_offset); |
42 virtual int32 CreateTransferBuffer(size_t size, int32 id_request); | 41 virtual int32 CreateTransferBuffer(size_t size, int32 id_request); |
43 virtual int32 RegisterTransferBuffer(base::SharedMemory* shared_memory, | 42 virtual int32 RegisterTransferBuffer(base::SharedMemory* shared_memory, |
44 size_t size, | 43 size_t size, |
45 int32 id_request); | 44 int32 id_request); |
46 virtual void DestroyTransferBuffer(int32 id); | 45 virtual void DestroyTransferBuffer(int32 id); |
47 virtual gpu::Buffer GetTransferBuffer(int32 handle); | 46 virtual gpu::Buffer GetTransferBuffer(int32 handle); |
48 virtual void SetToken(int32 token); | 47 virtual void SetToken(int32 token); |
49 virtual void SetParseError(gpu::error::Error error); | 48 virtual void SetParseError(gpu::error::Error error); |
50 virtual void SetContextLostReason(gpu::error::ContextLostReason reason); | 49 virtual void SetContextLostReason(gpu::error::ContextLostReason reason); |
51 | 50 |
52 private: | 51 private: |
53 bool Send(IPC::Message* msg); | 52 bool Send(IPC::Message* msg); |
54 void UpdateState(const gpu::CommandBuffer::State& state); | 53 void UpdateState(const gpu::CommandBuffer::State& state); |
55 | 54 |
56 int32 num_entries_; | |
57 scoped_ptr<base::SharedMemory> ring_buffer_; | |
58 | |
59 typedef base::hash_map<int32, gpu::Buffer> TransferBufferMap; | 55 typedef base::hash_map<int32, gpu::Buffer> TransferBufferMap; |
60 TransferBufferMap transfer_buffers_; | 56 TransferBufferMap transfer_buffers_; |
61 | 57 |
62 State last_state_; | 58 State last_state_; |
63 | 59 |
64 HostResource resource_; | 60 HostResource resource_; |
65 PluginDispatcher* dispatcher_; | 61 PluginDispatcher* dispatcher_; |
66 | 62 |
67 DISALLOW_COPY_AND_ASSIGN(CommandBuffer); | 63 DISALLOW_COPY_AND_ASSIGN(CommandBuffer); |
68 }; | 64 }; |
69 | 65 |
70 CommandBuffer::CommandBuffer(const HostResource& resource, | 66 CommandBuffer::CommandBuffer(const HostResource& resource, |
71 PluginDispatcher* dispatcher) | 67 PluginDispatcher* dispatcher) |
72 : num_entries_(0), | 68 : resource_(resource), |
73 resource_(resource), | |
74 dispatcher_(dispatcher) { | 69 dispatcher_(dispatcher) { |
75 } | 70 } |
76 | 71 |
77 CommandBuffer::~CommandBuffer() { | 72 CommandBuffer::~CommandBuffer() { |
78 // Delete all the locally cached shared memory objects, closing the handle | 73 // Delete all the locally cached shared memory objects, closing the handle |
79 // in this process. | 74 // in this process. |
80 for (TransferBufferMap::iterator it = transfer_buffers_.begin(); | 75 for (TransferBufferMap::iterator it = transfer_buffers_.begin(); |
81 it != transfer_buffers_.end(); ++it) { | 76 it != transfer_buffers_.end(); ++it) { |
82 delete it->second.shared_memory; | 77 delete it->second.shared_memory; |
83 it->second.shared_memory = NULL; | 78 it->second.shared_memory = NULL; |
84 } | 79 } |
85 } | 80 } |
86 | 81 |
87 bool CommandBuffer::Initialize(int32 size) { | 82 bool CommandBuffer::Initialize() { |
88 DCHECK(!ring_buffer_.get()); | 83 return Send(new PpapiHostMsg_PPBGraphics3D_InitCommandBuffer( |
89 | 84 API_ID_PPB_GRAPHICS_3D, resource_)); |
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( | |
95 API_ID_PPB_GRAPHICS_3D, resource_, size, &handle)) && | |
96 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 | |
109 bool CommandBuffer::Initialize(base::SharedMemory* buffer, int32 size) { | |
110 // Not implemented in proxy. | |
111 NOTREACHED(); | |
112 return false; | |
113 } | |
114 | |
115 gpu::Buffer CommandBuffer::GetRingBuffer() { | |
116 // Return locally cached ring buffer. | |
117 gpu::Buffer buffer; | |
118 if (ring_buffer_.get()) { | |
119 buffer.ptr = ring_buffer_->memory(); | |
120 buffer.size = num_entries_ * sizeof(gpu::CommandBufferEntry); | |
121 buffer.shared_memory = ring_buffer_.get(); | |
122 } else { | |
123 buffer.ptr = NULL; | |
124 buffer.size = 0; | |
125 buffer.shared_memory = NULL; | |
126 } | |
127 return buffer; | |
128 } | 85 } |
129 | 86 |
130 gpu::CommandBuffer::State CommandBuffer::GetState() { | 87 gpu::CommandBuffer::State CommandBuffer::GetState() { |
131 // Send will flag state with lost context if IPC fails. | 88 // Send will flag state with lost context if IPC fails. |
132 if (last_state_.error == gpu::error::kNoError) { | 89 if (last_state_.error == gpu::error::kNoError) { |
133 gpu::CommandBuffer::State state; | 90 gpu::CommandBuffer::State state; |
134 if (Send(new PpapiHostMsg_PPBGraphics3D_GetState( | 91 if (Send(new PpapiHostMsg_PPBGraphics3D_GetState( |
135 API_ID_PPB_GRAPHICS_3D, resource_, &state))) | 92 API_ID_PPB_GRAPHICS_3D, resource_, &state))) |
136 UpdateState(state); | 93 UpdateState(state); |
137 } | 94 } |
(...skipping 30 matching lines...) Expand all Loading... |
168 last_known_get, &state))) | 125 last_known_get, &state))) |
169 UpdateState(state); | 126 UpdateState(state); |
170 } | 127 } |
171 } else { | 128 } else { |
172 Flush(put_offset); | 129 Flush(put_offset); |
173 } | 130 } |
174 | 131 |
175 return last_state_; | 132 return last_state_; |
176 } | 133 } |
177 | 134 |
| 135 void CommandBuffer::SetGetBuffer(int32 transfer_buffer_id) { |
| 136 if (last_state_.error == gpu::error::kNoError) { |
| 137 Send(new PpapiHostMsg_PPBGraphics3D_SetGetBuffer( |
| 138 API_ID_PPB_GRAPHICS_3D, resource_, transfer_buffer_id)); |
| 139 } |
| 140 } |
| 141 |
178 void CommandBuffer::SetGetOffset(int32 get_offset) { | 142 void CommandBuffer::SetGetOffset(int32 get_offset) { |
179 // Not implemented in proxy. | 143 // Not implemented in proxy. |
180 NOTREACHED(); | 144 NOTREACHED(); |
181 } | 145 } |
182 | 146 |
183 int32 CommandBuffer::CreateTransferBuffer(size_t size, int32 id_request) { | 147 int32 CommandBuffer::CreateTransferBuffer(size_t size, int32 id_request) { |
184 if (last_state_.error == gpu::error::kNoError) { | 148 if (last_state_.error == gpu::error::kNoError) { |
185 int32 id; | 149 int32 id; |
186 if (Send(new PpapiHostMsg_PPBGraphics3D_CreateTransferBuffer( | 150 if (Send(new PpapiHostMsg_PPBGraphics3D_CreateTransferBuffer( |
187 API_ID_PPB_GRAPHICS_3D, resource_, size, &id))) { | 151 API_ID_PPB_GRAPHICS_3D, resource_, size, &id))) { |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 Graphics3D::~Graphics3D() { | 295 Graphics3D::~Graphics3D() { |
332 DestroyGLES2Impl(); | 296 DestroyGLES2Impl(); |
333 } | 297 } |
334 | 298 |
335 bool Graphics3D::Init() { | 299 bool Graphics3D::Init() { |
336 PluginDispatcher* dispatcher = PluginDispatcher::GetForResource(this); | 300 PluginDispatcher* dispatcher = PluginDispatcher::GetForResource(this); |
337 if (!dispatcher) | 301 if (!dispatcher) |
338 return false; | 302 return false; |
339 | 303 |
340 command_buffer_.reset(new CommandBuffer(host_resource(), dispatcher)); | 304 command_buffer_.reset(new CommandBuffer(host_resource(), dispatcher)); |
341 if (!command_buffer_->Initialize(kCommandBufferSize)) | 305 if (!command_buffer_->Initialize()) |
342 return false; | 306 return false; |
343 | 307 |
344 return CreateGLES2Impl(kCommandBufferSize, kTransferBufferSize); | 308 return CreateGLES2Impl(kCommandBufferSize, kTransferBufferSize); |
345 } | 309 } |
346 | 310 |
347 PP_Bool Graphics3D::InitCommandBuffer(int32_t size) { | 311 PP_Bool Graphics3D::InitCommandBuffer() { |
348 return PP_FALSE; | 312 return PP_FALSE; |
349 } | 313 } |
350 | 314 |
351 PP_Bool Graphics3D::GetRingBuffer(int* shm_handle, uint32_t* shm_size) { | 315 PP_Bool Graphics3D::SetGetBuffer(int32_t /* transfer_buffer_id */) { |
352 return PP_FALSE; | 316 return PP_FALSE; |
353 } | 317 } |
354 | 318 |
355 PP_Graphics3DTrustedState Graphics3D::GetState() { | 319 PP_Graphics3DTrustedState Graphics3D::GetState() { |
356 return GetErrorState(); | 320 return GetErrorState(); |
357 } | 321 } |
358 | 322 |
359 PP_Bool Graphics3D::Flush(int32_t put_offset) { | 323 PP_Bool Graphics3D::Flush(int32_t put_offset) { |
360 return PP_FALSE; | 324 return PP_FALSE; |
361 } | 325 } |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 return graphics_3d->GetReference(); | 406 return graphics_3d->GetReference(); |
443 } | 407 } |
444 | 408 |
445 bool PPB_Graphics3D_Proxy::OnMessageReceived(const IPC::Message& msg) { | 409 bool PPB_Graphics3D_Proxy::OnMessageReceived(const IPC::Message& msg) { |
446 bool handled = true; | 410 bool handled = true; |
447 IPC_BEGIN_MESSAGE_MAP(PPB_Graphics3D_Proxy, msg) | 411 IPC_BEGIN_MESSAGE_MAP(PPB_Graphics3D_Proxy, msg) |
448 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_Create, | 412 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_Create, |
449 OnMsgCreate) | 413 OnMsgCreate) |
450 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_InitCommandBuffer, | 414 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_InitCommandBuffer, |
451 OnMsgInitCommandBuffer) | 415 OnMsgInitCommandBuffer) |
| 416 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_SetGetBuffer, |
| 417 OnMsgSetGetBuffer) |
452 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_GetState, | 418 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_GetState, |
453 OnMsgGetState) | 419 OnMsgGetState) |
454 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_Flush, | 420 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_Flush, |
455 OnMsgFlush) | 421 OnMsgFlush) |
456 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_AsyncFlush, | 422 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_AsyncFlush, |
457 OnMsgAsyncFlush) | 423 OnMsgAsyncFlush) |
458 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_CreateTransferBuffer, | 424 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_CreateTransferBuffer, |
459 OnMsgCreateTransferBuffer) | 425 OnMsgCreateTransferBuffer) |
460 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_DestroyTransferBuffer, | 426 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_DestroyTransferBuffer, |
461 OnMsgDestroyTransferBuffer) | 427 OnMsgDestroyTransferBuffer) |
(...skipping 19 matching lines...) Expand all Loading... |
481 | 447 |
482 thunk::EnterResourceCreation enter(instance); | 448 thunk::EnterResourceCreation enter(instance); |
483 if (enter.succeeded()) { | 449 if (enter.succeeded()) { |
484 result->SetHostResource( | 450 result->SetHostResource( |
485 instance, | 451 instance, |
486 enter.functions()->CreateGraphics3DRaw(instance, 0, &attribs.front())); | 452 enter.functions()->CreateGraphics3DRaw(instance, 0, &attribs.front())); |
487 } | 453 } |
488 } | 454 } |
489 | 455 |
490 void PPB_Graphics3D_Proxy::OnMsgInitCommandBuffer( | 456 void PPB_Graphics3D_Proxy::OnMsgInitCommandBuffer( |
491 const HostResource& context, | 457 const HostResource& context) { |
492 int32 size, | |
493 base::SharedMemoryHandle* ring_buffer) { | |
494 *ring_buffer = base::SharedMemory::NULLHandle(); | |
495 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); | 458 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); |
496 if (enter.failed()) | 459 if (enter.failed()) |
497 return; | 460 return; |
498 | 461 |
499 if (!enter.object()->InitCommandBuffer(size)) | 462 if (!enter.object()->InitCommandBuffer()) |
500 return; | 463 return; |
| 464 } |
501 | 465 |
502 int shm_handle; | 466 void PPB_Graphics3D_Proxy::OnMsgSetGetBuffer( |
503 uint32_t shm_size; | 467 const HostResource& context, |
504 if (!enter.object()->GetRingBuffer(&shm_handle, &shm_size)) | 468 int32 transfer_buffer_id) { |
505 return; | 469 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); |
506 *ring_buffer = TransportSHMHandleFromInt(dispatcher(), shm_handle); | 470 if (enter.succeeded()) |
| 471 enter.object()->SetGetBuffer(transfer_buffer_id); |
507 } | 472 } |
508 | 473 |
509 void PPB_Graphics3D_Proxy::OnMsgGetState(const HostResource& context, | 474 void PPB_Graphics3D_Proxy::OnMsgGetState(const HostResource& context, |
510 gpu::CommandBuffer::State* state) { | 475 gpu::CommandBuffer::State* state) { |
511 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); | 476 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); |
512 if (enter.failed()) | 477 if (enter.failed()) |
513 return; | 478 return; |
514 PP_Graphics3DTrustedState pp_state = enter.object()->GetState(); | 479 PP_Graphics3DTrustedState pp_state = enter.object()->GetState(); |
515 *state = GPUStateFromPPState(pp_state); | 480 *state = GPUStateFromPPState(pp_state); |
516 } | 481 } |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
589 void PPB_Graphics3D_Proxy::SendSwapBuffersACKToPlugin( | 554 void PPB_Graphics3D_Proxy::SendSwapBuffersACKToPlugin( |
590 int32_t result, | 555 int32_t result, |
591 const HostResource& context) { | 556 const HostResource& context) { |
592 dispatcher()->Send(new PpapiMsg_PPBGraphics3D_SwapBuffersACK( | 557 dispatcher()->Send(new PpapiMsg_PPBGraphics3D_SwapBuffersACK( |
593 API_ID_PPB_GRAPHICS_3D, context, result)); | 558 API_ID_PPB_GRAPHICS_3D, context, result)); |
594 } | 559 } |
595 | 560 |
596 } // namespace proxy | 561 } // namespace proxy |
597 } // namespace ppapi | 562 } // namespace ppapi |
598 | 563 |
OLD | NEW |