Index: ppapi/proxy/ppb_graphics_3d_proxy.cc |
=================================================================== |
--- ppapi/proxy/ppb_graphics_3d_proxy.cc (revision 113511) |
+++ ppapi/proxy/ppb_graphics_3d_proxy.cc (working copy) |
@@ -31,12 +31,13 @@ |
virtual ~CommandBuffer(); |
// gpu::CommandBuffer implementation: |
- virtual bool Initialize(); |
+ virtual bool Initialize(int32 size); |
+ virtual bool Initialize(base::SharedMemory* buffer, int32 size); |
+ virtual gpu::Buffer GetRingBuffer(); |
virtual State GetState(); |
virtual State GetLastState(); |
virtual void Flush(int32 put_offset); |
virtual State FlushSync(int32 put_offset, int32 last_known_get); |
- virtual void SetGetBuffer(int32 transfer_buffer_id); |
virtual void SetGetOffset(int32 get_offset); |
virtual int32 CreateTransferBuffer(size_t size, int32 id_request); |
virtual int32 RegisterTransferBuffer(base::SharedMemory* shared_memory, |
@@ -52,6 +53,9 @@ |
bool Send(IPC::Message* msg); |
void UpdateState(const gpu::CommandBuffer::State& state); |
+ int32 num_entries_; |
+ scoped_ptr<base::SharedMemory> ring_buffer_; |
+ |
typedef base::hash_map<int32, gpu::Buffer> TransferBufferMap; |
TransferBufferMap transfer_buffers_; |
@@ -65,7 +69,8 @@ |
CommandBuffer::CommandBuffer(const HostResource& resource, |
PluginDispatcher* dispatcher) |
- : resource_(resource), |
+ : num_entries_(0), |
+ resource_(resource), |
dispatcher_(dispatcher) { |
} |
@@ -79,11 +84,49 @@ |
} |
} |
-bool CommandBuffer::Initialize() { |
- return Send(new PpapiHostMsg_PPBGraphics3D_InitCommandBuffer( |
- API_ID_PPB_GRAPHICS_3D, resource_)); |
+bool CommandBuffer::Initialize(int32 size) { |
+ DCHECK(!ring_buffer_.get()); |
+ |
+ // Initialize the service. Assuming we are sandboxed, the GPU |
+ // process is responsible for duplicating the handle. This might not be true |
+ // for NaCl. |
+ base::SharedMemoryHandle handle; |
+ if (Send(new PpapiHostMsg_PPBGraphics3D_InitCommandBuffer( |
+ API_ID_PPB_GRAPHICS_3D, resource_, size, &handle)) && |
+ base::SharedMemory::IsHandleValid(handle)) { |
+ ring_buffer_.reset(new base::SharedMemory(handle, false)); |
+ if (ring_buffer_->Map(size)) { |
+ num_entries_ = size / sizeof(gpu::CommandBufferEntry); |
+ return true; |
+ } |
+ |
+ ring_buffer_.reset(); |
+ } |
+ |
+ return false; |
} |
+bool CommandBuffer::Initialize(base::SharedMemory* buffer, int32 size) { |
+ // Not implemented in proxy. |
+ NOTREACHED(); |
+ return false; |
+} |
+ |
+gpu::Buffer CommandBuffer::GetRingBuffer() { |
+ // Return locally cached ring buffer. |
+ gpu::Buffer buffer; |
+ if (ring_buffer_.get()) { |
+ buffer.ptr = ring_buffer_->memory(); |
+ buffer.size = num_entries_ * sizeof(gpu::CommandBufferEntry); |
+ buffer.shared_memory = ring_buffer_.get(); |
+ } else { |
+ buffer.ptr = NULL; |
+ buffer.size = 0; |
+ buffer.shared_memory = NULL; |
+ } |
+ return buffer; |
+} |
+ |
gpu::CommandBuffer::State CommandBuffer::GetState() { |
// Send will flag state with lost context if IPC fails. |
if (last_state_.error == gpu::error::kNoError) { |
@@ -132,13 +175,6 @@ |
return last_state_; |
} |
-void CommandBuffer::SetGetBuffer(int32 transfer_buffer_id) { |
- if (last_state_.error == gpu::error::kNoError) { |
- Send(new PpapiHostMsg_PPBGraphics3D_SetGetBuffer( |
- API_ID_PPB_GRAPHICS_3D, resource_, transfer_buffer_id)); |
- } |
-} |
- |
void CommandBuffer::SetGetOffset(int32 get_offset) { |
// Not implemented in proxy. |
NOTREACHED(); |
@@ -302,17 +338,17 @@ |
return false; |
command_buffer_.reset(new CommandBuffer(host_resource(), dispatcher)); |
- if (!command_buffer_->Initialize()) |
+ if (!command_buffer_->Initialize(kCommandBufferSize)) |
return false; |
return CreateGLES2Impl(kCommandBufferSize, kTransferBufferSize); |
} |
-PP_Bool Graphics3D::InitCommandBuffer() { |
+PP_Bool Graphics3D::InitCommandBuffer(int32_t size) { |
return PP_FALSE; |
} |
-PP_Bool Graphics3D::SetGetBuffer(int32_t /* transfer_buffer_id */) { |
+PP_Bool Graphics3D::GetRingBuffer(int* shm_handle, uint32_t* shm_size) { |
return PP_FALSE; |
} |
@@ -413,8 +449,6 @@ |
OnMsgCreate) |
IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_InitCommandBuffer, |
OnMsgInitCommandBuffer) |
- IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_SetGetBuffer, |
- OnMsgSetGetBuffer) |
IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_GetState, |
OnMsgGetState) |
IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_Flush, |
@@ -454,21 +488,22 @@ |
} |
void PPB_Graphics3D_Proxy::OnMsgInitCommandBuffer( |
- const HostResource& context) { |
+ const HostResource& context, |
+ int32 size, |
+ base::SharedMemoryHandle* ring_buffer) { |
+ *ring_buffer = base::SharedMemory::NULLHandle(); |
EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); |
if (enter.failed()) |
return; |
- if (!enter.object()->InitCommandBuffer()) |
+ if (!enter.object()->InitCommandBuffer(size)) |
return; |
-} |
-void PPB_Graphics3D_Proxy::OnMsgSetGetBuffer( |
- const HostResource& context, |
- int32 transfer_buffer_id) { |
- EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); |
- if (enter.succeeded()) |
- enter.object()->SetGetBuffer(transfer_buffer_id); |
+ int shm_handle; |
+ uint32_t shm_size; |
+ if (!enter.object()->GetRingBuffer(&shm_handle, &shm_size)) |
+ return; |
+ *ring_buffer = TransportSHMHandleFromInt(dispatcher(), shm_handle); |
} |
void PPB_Graphics3D_Proxy::OnMsgGetState(const HostResource& context, |