diff options
author | dglazkov@chromium.org <dglazkov@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-06 20:21:44 +0000 |
---|---|---|
committer | dglazkov@chromium.org <dglazkov@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-06 20:21:44 +0000 |
commit | bd45bd252aeb8babac62547a5c605fbf64287cd3 (patch) | |
tree | 97cbf2f8bec035b6cf77c723a4b3b89c61338d79 /ppapi/proxy/ppb_graphics_3d_proxy.cc | |
parent | 32b6bae0bccbf704fbd07085e6334af7c90957f2 (diff) | |
download | chromium_src-bd45bd252aeb8babac62547a5c605fbf64287cd3.zip chromium_src-bd45bd252aeb8babac62547a5c605fbf64287cd3.tar.gz chromium_src-bd45bd252aeb8babac62547a5c605fbf64287cd3.tar.bz2 |
Revert 113250 - Add CommandBuffer::SetGetBuffer
As well as remove CommandBuffer::GetRingBuffer and
change CommandBuffer::Initialize
Before this change the service allocated and managed the command buffer.
After this change the client uses CreateTransferBuffer, GetTransferBuffer,
end potentially DeleteTransferBufffer to manage the command buffer.
Another CL will actually make the client delete the command buffer
on demand.
TEST=unit tests and run some samples and a NaCl 3D game
BUG=103989
Review URL: http://codereview.chromium.org/8566059
TBR=gman@chromium.org
Review URL: http://codereview.chromium.org/8827005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@113255 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/proxy/ppb_graphics_3d_proxy.cc')
-rw-r--r-- | ppapi/proxy/ppb_graphics_3d_proxy.cc | 89 |
1 files changed, 62 insertions, 27 deletions
diff --git a/ppapi/proxy/ppb_graphics_3d_proxy.cc b/ppapi/proxy/ppb_graphics_3d_proxy.cc index b5a2dee..8203e8d 100644 --- a/ppapi/proxy/ppb_graphics_3d_proxy.cc +++ b/ppapi/proxy/ppb_graphics_3d_proxy.cc @@ -31,12 +31,13 @@ class CommandBuffer : public gpu::CommandBuffer { 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 @@ class CommandBuffer : public gpu::CommandBuffer { 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 @@ class CommandBuffer : public gpu::CommandBuffer { CommandBuffer::CommandBuffer(const HostResource& resource, PluginDispatcher* dispatcher) - : resource_(resource), + : num_entries_(0), + resource_(resource), dispatcher_(dispatcher) { } @@ -79,9 +84,47 @@ CommandBuffer::~CommandBuffer() { } } -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() { @@ -132,13 +175,6 @@ gpu::CommandBuffer::State CommandBuffer::FlushSync(int32 put_offset, 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 @@ bool Graphics3D::Init() { 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 @@ bool PPB_Graphics3D_Proxy::OnMessageReceived(const IPC::Message& msg) { 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::OnMsgCreate(PP_Instance instance, } 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, |