diff options
author | fsamuel@chromium.org <fsamuel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-08 12:30:13 +0000 |
---|---|---|
committer | fsamuel@chromium.org <fsamuel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-08 12:30:13 +0000 |
commit | aaa11b3c9bb3d4f786f41c22aeb55abdc119a5d0 (patch) | |
tree | 91296cbf293597f25e131f1c66679bc27cf02df2 /ppapi/proxy/ppb_graphics_3d_proxy.cc | |
parent | c8332f2737d0a0f9f3de94b0100e5a890b78dc4b (diff) | |
download | chromium_src-aaa11b3c9bb3d4f786f41c22aeb55abdc119a5d0.zip chromium_src-aaa11b3c9bb3d4f786f41c22aeb55abdc119a5d0.tar.gz chromium_src-aaa11b3c9bb3d4f786f41c22aeb55abdc119a5d0.tar.bz2 |
Factor out the command buffer implementation in ppb_graphics_3d_proxy so that it is more general (does not depend on a dispatcher) and can be used elsewhere.
BUG=none
TEST=manually
Review URL: http://codereview.chromium.org/9420028
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@125596 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 | 233 |
1 files changed, 4 insertions, 229 deletions
diff --git a/ppapi/proxy/ppb_graphics_3d_proxy.cc b/ppapi/proxy/ppb_graphics_3d_proxy.cc index a62f3c7..718aeb6 100644 --- a/ppapi/proxy/ppb_graphics_3d_proxy.cc +++ b/ppapi/proxy/ppb_graphics_3d_proxy.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -8,6 +8,7 @@ #include "ppapi/c/pp_errors.h" #include "ppapi/proxy/enter_proxy.h" #include "ppapi/proxy/plugin_dispatcher.h" +#include "ppapi/proxy/ppapi_command_buffer_proxy.h" #include "ppapi/proxy/ppapi_messages.h" #include "ppapi/thunk/enter.h" #include "ppapi/thunk/resource_creation_api.h" @@ -25,233 +26,6 @@ namespace { const int32 kCommandBufferSize = 1024 * 1024; const int32 kTransferBufferSize = 1024 * 1024; -class CommandBuffer : public gpu::CommandBuffer { - public: - CommandBuffer(const HostResource& resource, PluginDispatcher* dispatcher); - virtual ~CommandBuffer(); - - // gpu::CommandBuffer implementation: - virtual bool Initialize(); - 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, - size_t size, - int32 id_request); - virtual void DestroyTransferBuffer(int32 id); - virtual gpu::Buffer GetTransferBuffer(int32 handle); - virtual void SetToken(int32 token); - virtual void SetParseError(gpu::error::Error error); - virtual void SetContextLostReason(gpu::error::ContextLostReason reason); - - private: - bool Send(IPC::Message* msg); - void UpdateState(const gpu::CommandBuffer::State& state); - - typedef base::hash_map<int32, gpu::Buffer> TransferBufferMap; - TransferBufferMap transfer_buffers_; - - State last_state_; - - HostResource resource_; - PluginDispatcher* dispatcher_; - - DISALLOW_COPY_AND_ASSIGN(CommandBuffer); -}; - -CommandBuffer::CommandBuffer(const HostResource& resource, - PluginDispatcher* dispatcher) - : resource_(resource), - dispatcher_(dispatcher) { -} - -CommandBuffer::~CommandBuffer() { - // Delete all the locally cached shared memory objects, closing the handle - // in this process. - for (TransferBufferMap::iterator it = transfer_buffers_.begin(); - it != transfer_buffers_.end(); ++it) { - delete it->second.shared_memory; - it->second.shared_memory = NULL; - } -} - -bool CommandBuffer::Initialize() { - return Send(new PpapiHostMsg_PPBGraphics3D_InitCommandBuffer( - API_ID_PPB_GRAPHICS_3D, resource_)); -} - -gpu::CommandBuffer::State CommandBuffer::GetState() { - // Send will flag state with lost context if IPC fails. - if (last_state_.error == gpu::error::kNoError) { - gpu::CommandBuffer::State state; - if (Send(new PpapiHostMsg_PPBGraphics3D_GetState( - API_ID_PPB_GRAPHICS_3D, resource_, &state))) - UpdateState(state); - } - - return last_state_; -} - -gpu::CommandBuffer::State CommandBuffer::GetLastState() { - return last_state_; -} - -void CommandBuffer::Flush(int32 put_offset) { - if (last_state_.error != gpu::error::kNoError) - return; - - IPC::Message* message = new PpapiHostMsg_PPBGraphics3D_AsyncFlush( - API_ID_PPB_GRAPHICS_3D, resource_, put_offset); - - // Do not let a synchronous flush hold up this message. If this handler is - // deferred until after the synchronous flush completes, it will overwrite the - // cached last_state_ with out-of-date data. - message->set_unblock(true); - Send(message); -} - -gpu::CommandBuffer::State CommandBuffer::FlushSync(int32 put_offset, - int32 last_known_get) { - if (last_known_get == last_state_.get_offset) { - // Send will flag state with lost context if IPC fails. - if (last_state_.error == gpu::error::kNoError) { - gpu::CommandBuffer::State state; - if (Send(new PpapiHostMsg_PPBGraphics3D_Flush( - API_ID_PPB_GRAPHICS_3D, resource_, put_offset, - last_known_get, &state))) - UpdateState(state); - } - } else { - Flush(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(); -} - -int32 CommandBuffer::CreateTransferBuffer(size_t size, int32 id_request) { - if (last_state_.error == gpu::error::kNoError) { - int32 id; - if (Send(new PpapiHostMsg_PPBGraphics3D_CreateTransferBuffer( - API_ID_PPB_GRAPHICS_3D, resource_, size, &id))) { - return id; - } - } - - return -1; -} - -int32 CommandBuffer::RegisterTransferBuffer( - base::SharedMemory* shared_memory, - size_t size, - int32 id_request) { - // Not implemented in proxy. - NOTREACHED(); - return -1; -} - -void CommandBuffer::DestroyTransferBuffer(int32 id) { - if (last_state_.error != gpu::error::kNoError) - return; - - // Remove the transfer buffer from the client side4 cache. - TransferBufferMap::iterator it = transfer_buffers_.find(id); - DCHECK(it != transfer_buffers_.end()); - - // Delete the shared memory object, closing the handle in this process. - delete it->second.shared_memory; - - transfer_buffers_.erase(it); - - Send(new PpapiHostMsg_PPBGraphics3D_DestroyTransferBuffer( - API_ID_PPB_GRAPHICS_3D, resource_, id)); -} - -gpu::Buffer CommandBuffer::GetTransferBuffer(int32 id) { - if (last_state_.error != gpu::error::kNoError) - return gpu::Buffer(); - - // Check local cache to see if there is already a client side shared memory - // object for this id. - TransferBufferMap::iterator it = transfer_buffers_.find(id); - if (it != transfer_buffers_.end()) { - return it->second; - } - - // Assuming we are in the renderer process, the service is responsible for - // duplicating the handle. This might not be true for NaCl. - base::SharedMemoryHandle handle; - uint32 size; - if (!Send(new PpapiHostMsg_PPBGraphics3D_GetTransferBuffer( - API_ID_PPB_GRAPHICS_3D, resource_, id, &handle, &size))) { - return gpu::Buffer(); - } - - // Cache the transfer buffer shared memory object client side. - scoped_ptr<base::SharedMemory> shared_memory( - new base::SharedMemory(handle, false)); - - // Map the shared memory on demand. - if (!shared_memory->memory()) { - if (!shared_memory->Map(size)) { - return gpu::Buffer(); - } - } - - gpu::Buffer buffer; - buffer.ptr = shared_memory->memory(); - buffer.size = size; - buffer.shared_memory = shared_memory.release(); - transfer_buffers_[id] = buffer; - - return buffer; -} - -void CommandBuffer::SetToken(int32 token) { - NOTREACHED(); -} - -void CommandBuffer::SetParseError(gpu::error::Error error) { - NOTREACHED(); -} - -void CommandBuffer::SetContextLostReason( - gpu::error::ContextLostReason reason) { - NOTREACHED(); -} - -bool CommandBuffer::Send(IPC::Message* msg) { - DCHECK(last_state_.error == gpu::error::kNoError); - - if (dispatcher_->Send(msg)) - return true; - - last_state_.error = gpu::error::kLostContext; - return false; -} - -void CommandBuffer::UpdateState(const gpu::CommandBuffer::State& state) { - // Handle wraparound. It works as long as we don't have more than 2B state - // updates in flight across which reordering occurs. - if (state.generation - last_state_.generation < 0x80000000U) - last_state_ = state; -} - base::SharedMemoryHandle TransportSHMHandleFromInt(Dispatcher* dispatcher, int shm_handle) { // TODO(piman): Change trusted interface to return a PP_FileHandle, those @@ -301,7 +75,8 @@ bool Graphics3D::Init() { if (!dispatcher) return false; - command_buffer_.reset(new CommandBuffer(host_resource(), dispatcher)); + command_buffer_.reset( + new PpapiCommandBufferProxy(host_resource(), dispatcher)); if (!command_buffer_->Initialize()) return false; |