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_context_3d_proxy.h" | 5 #include "ppapi/proxy/ppb_context_3d_proxy.h" |
6 | 6 |
7 #include "base/hash_tables.h" | 7 #include "base/hash_tables.h" |
8 #include "gpu/command_buffer/client/gles2_cmd_helper.h" | 8 #include "gpu/command_buffer/client/gles2_cmd_helper.h" |
9 #include "gpu/command_buffer/client/gles2_implementation.h" | 9 #include "gpu/command_buffer/client/gles2_implementation.h" |
10 #include "ppapi/c/pp_errors.h" | 10 #include "ppapi/c/pp_errors.h" |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 } | 133 } |
134 | 134 |
135 bool PepperCommandBuffer::Initialize(int32 size) { | 135 bool PepperCommandBuffer::Initialize(int32 size) { |
136 DCHECK(!ring_buffer_.get()); | 136 DCHECK(!ring_buffer_.get()); |
137 | 137 |
138 // Initialize the service. Assuming we are sandboxed, the GPU | 138 // Initialize the service. Assuming we are sandboxed, the GPU |
139 // process is responsible for duplicating the handle. This might not be true | 139 // process is responsible for duplicating the handle. This might not be true |
140 // for NaCl. | 140 // for NaCl. |
141 base::SharedMemoryHandle handle; | 141 base::SharedMemoryHandle handle; |
142 if (Send(new PpapiHostMsg_PPBContext3D_Initialize( | 142 if (Send(new PpapiHostMsg_PPBContext3D_Initialize( |
143 INTERFACE_ID_PPB_CONTEXT_3D, resource_, size, &handle)) && | 143 API_ID_PPB_CONTEXT_3D, resource_, size, &handle)) && |
144 base::SharedMemory::IsHandleValid(handle)) { | 144 base::SharedMemory::IsHandleValid(handle)) { |
145 ring_buffer_.reset(new base::SharedMemory(handle, false)); | 145 ring_buffer_.reset(new base::SharedMemory(handle, false)); |
146 if (ring_buffer_->Map(size)) { | 146 if (ring_buffer_->Map(size)) { |
147 num_entries_ = size / sizeof(gpu::CommandBufferEntry); | 147 num_entries_ = size / sizeof(gpu::CommandBufferEntry); |
148 return true; | 148 return true; |
149 } | 149 } |
150 | 150 |
151 ring_buffer_.reset(); | 151 ring_buffer_.reset(); |
152 } | 152 } |
153 | 153 |
(...skipping 13 matching lines...) Expand all Loading... |
167 buffer.size = num_entries_ * sizeof(gpu::CommandBufferEntry); | 167 buffer.size = num_entries_ * sizeof(gpu::CommandBufferEntry); |
168 buffer.shared_memory = ring_buffer_.get(); | 168 buffer.shared_memory = ring_buffer_.get(); |
169 return buffer; | 169 return buffer; |
170 } | 170 } |
171 | 171 |
172 gpu::CommandBuffer::State PepperCommandBuffer::GetState() { | 172 gpu::CommandBuffer::State PepperCommandBuffer::GetState() { |
173 // Send will flag state with lost context if IPC fails. | 173 // Send will flag state with lost context if IPC fails. |
174 if (last_state_.error == gpu::error::kNoError) { | 174 if (last_state_.error == gpu::error::kNoError) { |
175 gpu::CommandBuffer::State state; | 175 gpu::CommandBuffer::State state; |
176 if (Send(new PpapiHostMsg_PPBContext3D_GetState( | 176 if (Send(new PpapiHostMsg_PPBContext3D_GetState( |
177 INTERFACE_ID_PPB_CONTEXT_3D, resource_, &state))) | 177 API_ID_PPB_CONTEXT_3D, resource_, &state))) |
178 UpdateState(state); | 178 UpdateState(state); |
179 } | 179 } |
180 | 180 |
181 return last_state_; | 181 return last_state_; |
182 } | 182 } |
183 | 183 |
184 gpu::CommandBuffer::State PepperCommandBuffer::GetLastState() { | 184 gpu::CommandBuffer::State PepperCommandBuffer::GetLastState() { |
185 return last_state_; | 185 return last_state_; |
186 } | 186 } |
187 | 187 |
188 void PepperCommandBuffer::Flush(int32 put_offset) { | 188 void PepperCommandBuffer::Flush(int32 put_offset) { |
189 if (last_state_.error != gpu::error::kNoError) | 189 if (last_state_.error != gpu::error::kNoError) |
190 return; | 190 return; |
191 | 191 |
192 IPC::Message* message = new PpapiHostMsg_PPBContext3D_AsyncFlush( | 192 IPC::Message* message = new PpapiHostMsg_PPBContext3D_AsyncFlush( |
193 INTERFACE_ID_PPB_CONTEXT_3D, resource_, put_offset); | 193 API_ID_PPB_CONTEXT_3D, resource_, put_offset); |
194 | 194 |
195 // Do not let a synchronous flush hold up this message. If this handler is | 195 // Do not let a synchronous flush hold up this message. If this handler is |
196 // deferred until after the synchronous flush completes, it will overwrite the | 196 // deferred until after the synchronous flush completes, it will overwrite the |
197 // cached last_state_ with out-of-date data. | 197 // cached last_state_ with out-of-date data. |
198 message->set_unblock(true); | 198 message->set_unblock(true); |
199 Send(message); | 199 Send(message); |
200 } | 200 } |
201 | 201 |
202 gpu::CommandBuffer::State PepperCommandBuffer::FlushSync( | 202 gpu::CommandBuffer::State PepperCommandBuffer::FlushSync( |
203 int32 put_offset, int32 last_known_get) { | 203 int32 put_offset, int32 last_known_get) { |
204 if (last_known_get == last_state_.get_offset) { | 204 if (last_known_get == last_state_.get_offset) { |
205 // Send will flag state with lost context if IPC fails. | 205 // Send will flag state with lost context if IPC fails. |
206 if (last_state_.error == gpu::error::kNoError) { | 206 if (last_state_.error == gpu::error::kNoError) { |
207 gpu::CommandBuffer::State state; | 207 gpu::CommandBuffer::State state; |
208 if (Send(new PpapiHostMsg_PPBContext3D_Flush( | 208 if (Send(new PpapiHostMsg_PPBContext3D_Flush( |
209 INTERFACE_ID_PPB_CONTEXT_3D, resource_, put_offset, | 209 API_ID_PPB_CONTEXT_3D, resource_, put_offset, |
210 last_known_get, &state))) | 210 last_known_get, &state))) |
211 UpdateState(state); | 211 UpdateState(state); |
212 } | 212 } |
213 } else { | 213 } else { |
214 Flush(put_offset); | 214 Flush(put_offset); |
215 } | 215 } |
216 | 216 |
217 return last_state_; | 217 return last_state_; |
218 } | 218 } |
219 | 219 |
220 void PepperCommandBuffer::SetGetOffset(int32 get_offset) { | 220 void PepperCommandBuffer::SetGetOffset(int32 get_offset) { |
221 // Not implemented in proxy. | 221 // Not implemented in proxy. |
222 NOTREACHED(); | 222 NOTREACHED(); |
223 } | 223 } |
224 | 224 |
225 int32 PepperCommandBuffer::CreateTransferBuffer(size_t size, int32 id_request) { | 225 int32 PepperCommandBuffer::CreateTransferBuffer(size_t size, int32 id_request) { |
226 if (last_state_.error == gpu::error::kNoError) { | 226 if (last_state_.error == gpu::error::kNoError) { |
227 int32 id; | 227 int32 id; |
228 if (Send(new PpapiHostMsg_PPBContext3D_CreateTransferBuffer( | 228 if (Send(new PpapiHostMsg_PPBContext3D_CreateTransferBuffer( |
229 INTERFACE_ID_PPB_CONTEXT_3D, resource_, size, &id))) { | 229 API_ID_PPB_CONTEXT_3D, resource_, size, &id))) { |
230 return id; | 230 return id; |
231 } | 231 } |
232 } | 232 } |
233 | 233 |
234 return -1; | 234 return -1; |
235 } | 235 } |
236 | 236 |
237 int32 PepperCommandBuffer::RegisterTransferBuffer( | 237 int32 PepperCommandBuffer::RegisterTransferBuffer( |
238 base::SharedMemory* shared_memory, | 238 base::SharedMemory* shared_memory, |
239 size_t size, | 239 size_t size, |
(...skipping 10 matching lines...) Expand all Loading... |
250 // Remove the transfer buffer from the client side4 cache. | 250 // Remove the transfer buffer from the client side4 cache. |
251 TransferBufferMap::iterator it = transfer_buffers_.find(id); | 251 TransferBufferMap::iterator it = transfer_buffers_.find(id); |
252 DCHECK(it != transfer_buffers_.end()); | 252 DCHECK(it != transfer_buffers_.end()); |
253 | 253 |
254 // Delete the shared memory object, closing the handle in this process. | 254 // Delete the shared memory object, closing the handle in this process. |
255 delete it->second.shared_memory; | 255 delete it->second.shared_memory; |
256 | 256 |
257 transfer_buffers_.erase(it); | 257 transfer_buffers_.erase(it); |
258 | 258 |
259 Send(new PpapiHostMsg_PPBContext3D_DestroyTransferBuffer( | 259 Send(new PpapiHostMsg_PPBContext3D_DestroyTransferBuffer( |
260 INTERFACE_ID_PPB_CONTEXT_3D, resource_, id)); | 260 API_ID_PPB_CONTEXT_3D, resource_, id)); |
261 } | 261 } |
262 | 262 |
263 gpu::Buffer PepperCommandBuffer::GetTransferBuffer(int32 id) { | 263 gpu::Buffer PepperCommandBuffer::GetTransferBuffer(int32 id) { |
264 if (last_state_.error != gpu::error::kNoError) | 264 if (last_state_.error != gpu::error::kNoError) |
265 return gpu::Buffer(); | 265 return gpu::Buffer(); |
266 | 266 |
267 // Check local cache to see if there is already a client side shared memory | 267 // Check local cache to see if there is already a client side shared memory |
268 // object for this id. | 268 // object for this id. |
269 TransferBufferMap::iterator it = transfer_buffers_.find(id); | 269 TransferBufferMap::iterator it = transfer_buffers_.find(id); |
270 if (it != transfer_buffers_.end()) { | 270 if (it != transfer_buffers_.end()) { |
271 return it->second; | 271 return it->second; |
272 } | 272 } |
273 | 273 |
274 // Assuming we are in the renderer process, the service is responsible for | 274 // Assuming we are in the renderer process, the service is responsible for |
275 // duplicating the handle. This might not be true for NaCl. | 275 // duplicating the handle. This might not be true for NaCl. |
276 base::SharedMemoryHandle handle; | 276 base::SharedMemoryHandle handle; |
277 uint32 size; | 277 uint32 size; |
278 if (!Send(new PpapiHostMsg_PPBContext3D_GetTransferBuffer( | 278 if (!Send(new PpapiHostMsg_PPBContext3D_GetTransferBuffer( |
279 INTERFACE_ID_PPB_CONTEXT_3D, resource_, id, &handle, &size))) { | 279 API_ID_PPB_CONTEXT_3D, resource_, id, &handle, &size))) { |
280 return gpu::Buffer(); | 280 return gpu::Buffer(); |
281 } | 281 } |
282 | 282 |
283 // Cache the transfer buffer shared memory object client side. | 283 // Cache the transfer buffer shared memory object client side. |
284 scoped_ptr<base::SharedMemory> shared_memory( | 284 scoped_ptr<base::SharedMemory> shared_memory( |
285 new base::SharedMemory(handle, false)); | 285 new base::SharedMemory(handle, false)); |
286 | 286 |
287 // Map the shared memory on demand. | 287 // Map the shared memory on demand. |
288 if (!shared_memory->memory()) { | 288 if (!shared_memory->memory()) { |
289 if (!shared_memory->Map(size)) { | 289 if (!shared_memory->Map(size)) { |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 if (pp_read && !read_surface) | 406 if (pp_read && !read_surface) |
407 return PP_ERROR_BADRESOURCE; | 407 return PP_ERROR_BADRESOURCE; |
408 HostResource host_draw = | 408 HostResource host_draw = |
409 draw_surface ? draw_surface->host_resource() : HostResource(); | 409 draw_surface ? draw_surface->host_resource() : HostResource(); |
410 HostResource host_read = | 410 HostResource host_read = |
411 read_surface ? read_surface->host_resource() : HostResource(); | 411 read_surface ? read_surface->host_resource() : HostResource(); |
412 | 412 |
413 int32_t result; | 413 int32_t result; |
414 PluginDispatcher::GetForResource(this)->Send( | 414 PluginDispatcher::GetForResource(this)->Send( |
415 new PpapiHostMsg_PPBContext3D_BindSurfaces( | 415 new PpapiHostMsg_PPBContext3D_BindSurfaces( |
416 INTERFACE_ID_PPB_CONTEXT_3D, | 416 API_ID_PPB_CONTEXT_3D, |
417 host_resource(), host_draw, host_read, &result)); | 417 host_resource(), host_draw, host_read, &result)); |
418 if (result != PP_OK) | 418 if (result != PP_OK) |
419 return result; | 419 return result; |
420 | 420 |
421 if (draw_surface != draw_) { | 421 if (draw_surface != draw_) { |
422 if (draw_) | 422 if (draw_) |
423 draw_->set_context(NULL); | 423 draw_->set_context(NULL); |
424 if (draw_surface) { | 424 if (draw_surface) { |
425 draw_surface->set_context(this); | 425 draw_surface->set_context(this); |
426 // Resize the backing texture to the size of the instance when it is | 426 // Resize the backing texture to the size of the instance when it is |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
540 std::vector<int32_t> attribs; | 540 std::vector<int32_t> attribs; |
541 if (attrib_list) { | 541 if (attrib_list) { |
542 for (const int32_t* attr = attrib_list; attr; ++attr) | 542 for (const int32_t* attr = attrib_list; attr; ++attr) |
543 attribs.push_back(*attr); | 543 attribs.push_back(*attr); |
544 } else { | 544 } else { |
545 attribs.push_back(0); | 545 attribs.push_back(0); |
546 } | 546 } |
547 | 547 |
548 HostResource result; | 548 HostResource result; |
549 dispatcher->Send(new PpapiHostMsg_PPBContext3D_Create( | 549 dispatcher->Send(new PpapiHostMsg_PPBContext3D_Create( |
550 INTERFACE_ID_PPB_CONTEXT_3D, instance, config, attribs, &result)); | 550 API_ID_PPB_CONTEXT_3D, instance, config, attribs, &result)); |
551 | 551 |
552 if (result.is_null()) | 552 if (result.is_null()) |
553 return 0; | 553 return 0; |
554 scoped_refptr<Context3D> context_3d(new Context3D(result)); | 554 scoped_refptr<Context3D> context_3d(new Context3D(result)); |
555 if (!context_3d->CreateImplementation()) | 555 if (!context_3d->CreateImplementation()) |
556 return 0; | 556 return 0; |
557 return context_3d->GetReference(); | 557 return context_3d->GetReference(); |
558 } | 558 } |
559 | 559 |
560 bool PPB_Context3D_Proxy::OnMessageReceived(const IPC::Message& msg) { | 560 bool PPB_Context3D_Proxy::OnMessageReceived(const IPC::Message& msg) { |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
692 uint32_t shm_size = 0; | 692 uint32_t shm_size = 0; |
693 if (enter.succeeded() && | 693 if (enter.succeeded() && |
694 enter.object()->GetTransferBuffer(id, &shm_handle, &shm_size)) { | 694 enter.object()->GetTransferBuffer(id, &shm_handle, &shm_size)) { |
695 *transfer_buffer = TransportSHMHandleFromInt(dispatcher(), shm_handle); | 695 *transfer_buffer = TransportSHMHandleFromInt(dispatcher(), shm_handle); |
696 *size = shm_size; | 696 *size = shm_size; |
697 } | 697 } |
698 } | 698 } |
699 | 699 |
700 } // namespace proxy | 700 } // namespace proxy |
701 } // namespace ppapi | 701 } // namespace ppapi |
OLD | NEW |