Chromium Code Reviews| 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 70 | 70 |
| 71 } // namespace | 71 } // namespace |
| 72 | 72 |
| 73 class PepperCommandBuffer : public gpu::CommandBuffer { | 73 class PepperCommandBuffer : public gpu::CommandBuffer { |
| 74 public: | 74 public: |
| 75 PepperCommandBuffer(const HostResource& resource, | 75 PepperCommandBuffer(const HostResource& resource, |
| 76 PluginDispatcher* dispatcher); | 76 PluginDispatcher* dispatcher); |
| 77 virtual ~PepperCommandBuffer(); | 77 virtual ~PepperCommandBuffer(); |
| 78 | 78 |
| 79 // CommandBuffer implementation: | 79 // CommandBuffer implementation: |
| 80 virtual bool Initialize(int32 size); | 80 virtual bool Initialize(); |
| 81 virtual bool Initialize(base::SharedMemory* buffer, int32 size); | |
| 82 virtual gpu::Buffer GetRingBuffer(); | |
| 83 virtual State GetState(); | 81 virtual State GetState(); |
| 84 virtual State GetLastState(); | 82 virtual State GetLastState(); |
| 85 virtual void Flush(int32 put_offset); | 83 virtual void Flush(int32 put_offset); |
| 86 virtual State FlushSync(int32 put_offset, int32 last_known_get); | 84 virtual State FlushSync(int32 put_offset, int32 last_known_get); |
| 85 virtual void SetGetBuffer(int32 shm_id); | |
| 87 virtual void SetGetOffset(int32 get_offset); | 86 virtual void SetGetOffset(int32 get_offset); |
| 88 virtual int32 CreateTransferBuffer(size_t size, int32 id_request); | 87 virtual int32 CreateTransferBuffer(size_t size, int32 id_request); |
| 89 virtual int32 RegisterTransferBuffer(base::SharedMemory* shared_memory, | 88 virtual int32 RegisterTransferBuffer(base::SharedMemory* shared_memory, |
| 90 size_t size, | 89 size_t size, |
| 91 int32 id_request); | 90 int32 id_request); |
| 92 virtual void DestroyTransferBuffer(int32 id); | 91 virtual void DestroyTransferBuffer(int32 id); |
| 93 virtual gpu::Buffer GetTransferBuffer(int32 handle); | 92 virtual gpu::Buffer GetTransferBuffer(int32 handle); |
| 94 virtual void SetToken(int32 token); | 93 virtual void SetToken(int32 token); |
| 95 virtual void SetParseError(gpu::error::Error error); | 94 virtual void SetParseError(gpu::error::Error error); |
| 96 virtual void SetContextLostReason(gpu::error::ContextLostReason reason); | 95 virtual void SetContextLostReason(gpu::error::ContextLostReason reason); |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 125 // Delete all the locally cached shared memory objects, closing the handle | 124 // Delete all the locally cached shared memory objects, closing the handle |
| 126 // in this process. | 125 // in this process. |
| 127 for (TransferBufferMap::iterator it = transfer_buffers_.begin(); | 126 for (TransferBufferMap::iterator it = transfer_buffers_.begin(); |
| 128 it != transfer_buffers_.end(); | 127 it != transfer_buffers_.end(); |
| 129 ++it) { | 128 ++it) { |
| 130 delete it->second.shared_memory; | 129 delete it->second.shared_memory; |
| 131 it->second.shared_memory = NULL; | 130 it->second.shared_memory = NULL; |
| 132 } | 131 } |
| 133 } | 132 } |
| 134 | 133 |
| 135 bool PepperCommandBuffer::Initialize(int32 size) { | 134 bool PepperCommandBuffer::Initialize() { |
| 136 DCHECK(!ring_buffer_.get()); | 135 return Send(new PpapiHostMsg_PPBContext3D_Initialize( |
| 137 | 136 API_ID_PPB_CONTEXT_3D, resource_)); |
| 138 // Initialize the service. Assuming we are sandboxed, the GPU | |
| 139 // process is responsible for duplicating the handle. This might not be true | |
| 140 // for NaCl. | |
| 141 base::SharedMemoryHandle handle; | |
| 142 if (Send(new PpapiHostMsg_PPBContext3D_Initialize( | |
| 143 API_ID_PPB_CONTEXT_3D, resource_, size, &handle)) && | |
| 144 base::SharedMemory::IsHandleValid(handle)) { | |
| 145 ring_buffer_.reset(new base::SharedMemory(handle, false)); | |
| 146 if (ring_buffer_->Map(size)) { | |
| 147 num_entries_ = size / sizeof(gpu::CommandBufferEntry); | |
| 148 return true; | |
| 149 } | |
| 150 | |
| 151 ring_buffer_.reset(); | |
| 152 } | |
| 153 | |
| 154 return false; | |
| 155 } | |
| 156 | |
| 157 bool PepperCommandBuffer::Initialize(base::SharedMemory* buffer, int32 size) { | |
| 158 // Not implemented in proxy. | |
| 159 NOTREACHED(); | |
| 160 return false; | |
| 161 } | |
| 162 | |
| 163 gpu::Buffer PepperCommandBuffer::GetRingBuffer() { | |
| 164 // Return locally cached ring buffer. | |
| 165 gpu::Buffer buffer; | |
| 166 buffer.ptr = ring_buffer_->memory(); | |
| 167 buffer.size = num_entries_ * sizeof(gpu::CommandBufferEntry); | |
| 168 buffer.shared_memory = ring_buffer_.get(); | |
| 169 return buffer; | |
| 170 } | 137 } |
| 171 | 138 |
| 172 gpu::CommandBuffer::State PepperCommandBuffer::GetState() { | 139 gpu::CommandBuffer::State PepperCommandBuffer::GetState() { |
| 173 // Send will flag state with lost context if IPC fails. | 140 // Send will flag state with lost context if IPC fails. |
| 174 if (last_state_.error == gpu::error::kNoError) { | 141 if (last_state_.error == gpu::error::kNoError) { |
| 175 gpu::CommandBuffer::State state; | 142 gpu::CommandBuffer::State state; |
| 176 if (Send(new PpapiHostMsg_PPBContext3D_GetState( | 143 if (Send(new PpapiHostMsg_PPBContext3D_GetState( |
| 177 API_ID_PPB_CONTEXT_3D, resource_, &state))) | 144 API_ID_PPB_CONTEXT_3D, resource_, &state))) |
| 178 UpdateState(state); | 145 UpdateState(state); |
| 179 } | 146 } |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 210 last_known_get, &state))) | 177 last_known_get, &state))) |
| 211 UpdateState(state); | 178 UpdateState(state); |
| 212 } | 179 } |
| 213 } else { | 180 } else { |
| 214 Flush(put_offset); | 181 Flush(put_offset); |
| 215 } | 182 } |
| 216 | 183 |
| 217 return last_state_; | 184 return last_state_; |
| 218 } | 185 } |
| 219 | 186 |
| 187 void PepperCommandBuffer::SetGetBuffer(int32 shm_id) { | |
| 188 if (last_state_.error == gpu::error::kNoError) { | |
| 189 Send(new PpapiHostMsg_PPBContext3D_SetGetBuffer( | |
|
piman
2011/11/20 01:19:16
Note: I can see that this message is not handled,
| |
| 190 API_ID_PPB_CONTEXT_3D, resource_, shm_id)); | |
| 191 } | |
| 192 } | |
| 193 | |
| 220 void PepperCommandBuffer::SetGetOffset(int32 get_offset) { | 194 void PepperCommandBuffer::SetGetOffset(int32 get_offset) { |
| 221 // Not implemented in proxy. | 195 // Not implemented in proxy. |
| 222 NOTREACHED(); | 196 NOTREACHED(); |
| 223 } | 197 } |
| 224 | 198 |
| 225 int32 PepperCommandBuffer::CreateTransferBuffer(size_t size, int32 id_request) { | 199 int32 PepperCommandBuffer::CreateTransferBuffer(size_t size, int32 id_request) { |
| 226 if (last_state_.error == gpu::error::kNoError) { | 200 if (last_state_.error == gpu::error::kNoError) { |
| 227 int32 id; | 201 int32 id; |
| 228 if (Send(new PpapiHostMsg_PPBContext3D_CreateTransferBuffer( | 202 if (Send(new PpapiHostMsg_PPBContext3D_CreateTransferBuffer( |
| 229 API_ID_PPB_CONTEXT_3D, resource_, size, &id))) { | 203 API_ID_PPB_CONTEXT_3D, resource_, size, &id))) { |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 348 return this; | 322 return this; |
| 349 } | 323 } |
| 350 | 324 |
| 351 bool Context3D::CreateImplementation() { | 325 bool Context3D::CreateImplementation() { |
| 352 PluginDispatcher* dispatcher = PluginDispatcher::GetForResource(this); | 326 PluginDispatcher* dispatcher = PluginDispatcher::GetForResource(this); |
| 353 if (!dispatcher) | 327 if (!dispatcher) |
| 354 return false; | 328 return false; |
| 355 | 329 |
| 356 command_buffer_.reset(new PepperCommandBuffer(host_resource(), dispatcher)); | 330 command_buffer_.reset(new PepperCommandBuffer(host_resource(), dispatcher)); |
| 357 | 331 |
| 358 if (!command_buffer_->Initialize(kCommandBufferSize)) | 332 if (!command_buffer_->Initialize()) |
| 359 return false; | 333 return false; |
| 360 | 334 |
| 361 helper_.reset(new gpu::gles2::GLES2CmdHelper(command_buffer_.get())); | 335 helper_.reset(new gpu::gles2::GLES2CmdHelper(command_buffer_.get())); |
| 362 if (!helper_->Initialize(kCommandBufferSize)) | 336 if (!helper_->Initialize(kCommandBufferSize)) |
| 363 return false; | 337 return false; |
| 364 | 338 |
| 365 transfer_buffer_id_ = | 339 transfer_buffer_id_ = |
| 366 command_buffer_->CreateTransferBuffer(kTransferBufferSize, -1); | 340 command_buffer_->CreateTransferBuffer(kTransferBufferSize, -1); |
| 367 if (transfer_buffer_id_ < 0) | 341 if (transfer_buffer_id_ < 0) |
| 368 return false; | 342 return false; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 437 read_ = read_surface; | 411 read_ = read_surface; |
| 438 return PP_OK; | 412 return PP_OK; |
| 439 } | 413 } |
| 440 | 414 |
| 441 int32_t Context3D::GetBoundSurfaces(PP_Resource* draw, PP_Resource* read) { | 415 int32_t Context3D::GetBoundSurfaces(PP_Resource* draw, PP_Resource* read) { |
| 442 *draw = draw_ ? draw_->pp_resource() : 0; | 416 *draw = draw_ ? draw_->pp_resource() : 0; |
| 443 *read = read_ ? read_->pp_resource() : 0; | 417 *read = read_ ? read_->pp_resource() : 0; |
| 444 return PP_OK; | 418 return PP_OK; |
| 445 } | 419 } |
| 446 | 420 |
| 447 PP_Bool Context3D::InitializeTrusted(int32_t size) { | 421 PP_Bool Context3D::InitializeTrusted() { |
| 448 // Trusted interface not implemented in the proxy. | 422 // Trusted interface not implemented in the proxy. |
| 449 return PP_FALSE; | 423 return PP_FALSE; |
| 450 } | 424 } |
| 451 | 425 |
| 452 PP_Bool Context3D::GetRingBuffer(int* shm_handle, | 426 PP_Bool Context3D::SetGetBuffer(int32_t shm_id) { |
| 453 uint32_t* shm_size) { | |
| 454 // Trusted interface not implemented in the proxy. | 427 // Trusted interface not implemented in the proxy. |
| 455 return PP_FALSE; | 428 return PP_FALSE; |
| 456 } | 429 } |
| 457 | 430 |
| 458 PP_Context3DTrustedState Context3D::GetState() { | 431 PP_Context3DTrustedState Context3D::GetState() { |
| 459 // Trusted interface not implemented in the proxy. | 432 // Trusted interface not implemented in the proxy. |
| 460 return GetErrorState(); | 433 return GetErrorState(); |
| 461 } | 434 } |
| 462 | 435 |
| 463 PP_Bool Context3D::Flush(int32_t put_offset) { | 436 PP_Bool Context3D::Flush(int32_t put_offset) { |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 607 EnterHostFromHostResource<PPB_Context3D_API> enter(context); | 580 EnterHostFromHostResource<PPB_Context3D_API> enter(context); |
| 608 if (enter.succeeded()) { | 581 if (enter.succeeded()) { |
| 609 *result = enter.object()->BindSurfaces(draw.host_resource(), | 582 *result = enter.object()->BindSurfaces(draw.host_resource(), |
| 610 read.host_resource()); | 583 read.host_resource()); |
| 611 } else { | 584 } else { |
| 612 *result = PP_ERROR_BADRESOURCE; | 585 *result = PP_ERROR_BADRESOURCE; |
| 613 } | 586 } |
| 614 } | 587 } |
| 615 | 588 |
| 616 void PPB_Context3D_Proxy::OnMsgInitialize( | 589 void PPB_Context3D_Proxy::OnMsgInitialize( |
| 617 const HostResource& context, | 590 const HostResource& context) { |
| 618 int32 size, | 591 EnterHostFromHostResource<PPB_Context3D_API> enter(context); |
| 619 base::SharedMemoryHandle* ring_buffer) { | |
| 620 *ring_buffer = base::SharedMemory::NULLHandle(); | |
| 621 EnterHostFromHostResource<PPB_Context3D_API> enter(context); | |
| 622 if (enter.failed()) | 592 if (enter.failed()) |
| 623 return; | 593 return; |
| 624 | 594 |
| 625 if (!enter.object()->InitializeTrusted(size)) | 595 if (!enter.object()->InitializeTrusted()) |
| 626 return; | 596 return; |
| 627 | |
| 628 int shm_handle; | |
| 629 uint32_t shm_size; | |
| 630 if (!enter.object()->GetRingBuffer(&shm_handle, &shm_size)) | |
| 631 return; | |
| 632 *ring_buffer = TransportSHMHandleFromInt(dispatcher(), shm_handle); | |
| 633 } | 597 } |
| 634 | 598 |
| 635 void PPB_Context3D_Proxy::OnMsgGetState(const HostResource& context, | 599 void PPB_Context3D_Proxy::OnMsgGetState(const HostResource& context, |
| 636 gpu::CommandBuffer::State* state) { | 600 gpu::CommandBuffer::State* state) { |
| 637 EnterHostFromHostResource<PPB_Context3D_API> enter(context); | 601 EnterHostFromHostResource<PPB_Context3D_API> enter(context); |
| 638 if (enter.failed()) | 602 if (enter.failed()) |
| 639 return; | 603 return; |
| 640 PP_Context3DTrustedState pp_state = enter.object()->GetState(); | 604 PP_Context3DTrustedState pp_state = enter.object()->GetState(); |
| 641 *state = GPUStateFromPPState(pp_state); | 605 *state = GPUStateFromPPState(pp_state); |
| 642 } | 606 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 692 uint32_t shm_size = 0; | 656 uint32_t shm_size = 0; |
| 693 if (enter.succeeded() && | 657 if (enter.succeeded() && |
| 694 enter.object()->GetTransferBuffer(id, &shm_handle, &shm_size)) { | 658 enter.object()->GetTransferBuffer(id, &shm_handle, &shm_size)) { |
| 695 *transfer_buffer = TransportSHMHandleFromInt(dispatcher(), shm_handle); | 659 *transfer_buffer = TransportSHMHandleFromInt(dispatcher(), shm_handle); |
| 696 *size = shm_size; | 660 *size = shm_size; |
| 697 } | 661 } |
| 698 } | 662 } |
| 699 | 663 |
| 700 } // namespace proxy | 664 } // namespace proxy |
| 701 } // namespace ppapi | 665 } // namespace ppapi |
| OLD | NEW |