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 | |
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')
15 files changed, 170 insertions, 87 deletions
diff --git a/ppapi/c/trusted/ppb_graphics_3d_trusted.h b/ppapi/c/trusted/ppb_graphics_3d_trusted.h index 353b6dd..d6a6481 100644 --- a/ppapi/c/trusted/ppb_graphics_3d_trusted.h +++ b/ppapi/c/trusted/ppb_graphics_3d_trusted.h @@ -59,10 +59,12 @@ struct PPB_Graphics3DTrusted { const int32_t* attrib_list); // Initializes the command buffer with the given size. - PP_Bool (*InitCommandBuffer)(PP_Resource context_id); + PP_Bool (*InitCommandBuffer)(PP_Resource context_id, int32_t size); - // Sets the buffer used for commands. - PP_Bool (*SetGetBuffer)(PP_Resource context, int32_t transfer_buffer_id); + // Gets the ring buffer for the command buffer. + PP_Bool (*GetRingBuffer)(PP_Resource context_id, + int* shm_handle, + uint32_t* shm_size); // Returns the current state. struct PP_Graphics3DTrustedState (*GetState)(PP_Resource context); diff --git a/ppapi/native_client/src/shared/ppapi_proxy/browser_ppb_graphics_3d_rpc_server.cc b/ppapi/native_client/src/shared/ppapi_proxy/browser_ppb_graphics_3d_rpc_server.cc index f678be1..62ea1eb 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/browser_ppb_graphics_3d_rpc_server.cc +++ b/ppapi/native_client/src/shared/ppapi_proxy/browser_ppb_graphics_3d_rpc_server.cc @@ -244,26 +244,40 @@ void PpbGraphics3DRpcServer::PPB_Graphics3DTrusted_InitCommandBuffer( NaClSrpcRpc* rpc, NaClSrpcClosure* done, PP_Resource resource_id, + int32_t size, int32_t* success) { DebugPrintf("PPB_Graphics3DTrusted_InitCommandBuffer(...) resource_id: %d\n", resource_id); NaClSrpcClosureRunner runner(done); rpc->result = NACL_SRPC_RESULT_APP_ERROR; + if ((size > kMaxAllowedBufferSize) || (size < 0)) + return; *success = ppapi_proxy::PPBGraphics3DTrustedInterface()->InitCommandBuffer( - resource_id); + resource_id, size); rpc->result = NACL_SRPC_RESULT_OK; } -void PpbGraphics3DRpcServer::PPB_Graphics3DTrusted_SetGetBuffer( + +void PpbGraphics3DRpcServer::PPB_Graphics3DTrusted_GetRingBuffer( NaClSrpcRpc* rpc, NaClSrpcClosure* done, PP_Resource resource_id, - int32_t transfer_buffer_id) { - DebugPrintf("PPB_Graphics3DTrusted_SetGetBuffer\n"); + NaClSrpcImcDescType* shm_desc, + int32_t* shm_size) { + DebugPrintf("PPB_Graphics3DTrusted_GetRingBuffer\n"); + nacl::DescWrapperFactory factory; + nacl::scoped_ptr<nacl::DescWrapper> desc_wrapper; NaClSrpcClosureRunner runner(done); rpc->result = NACL_SRPC_RESULT_APP_ERROR; - ppapi_proxy::PPBGraphics3DTrustedInterface()->SetGetBuffer( - resource_id, transfer_buffer_id); + + int native_handle = 0; + uint32_t native_size = 0; + ppapi_proxy::PPBGraphics3DTrustedInterface()->GetRingBuffer( + resource_id, &native_handle, &native_size); + desc_wrapper.reset(factory.ImportShmHandle( + (NaClHandle)native_handle, native_size)); + *shm_desc = desc_wrapper->desc(); + *shm_size = native_size; rpc->result = NACL_SRPC_RESULT_OK; } diff --git a/ppapi/native_client/src/shared/ppapi_proxy/command_buffer_nacl.cc b/ppapi/native_client/src/shared/ppapi_proxy/command_buffer_nacl.cc index 4a83a04..e151312 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/command_buffer_nacl.cc +++ b/ppapi/native_client/src/shared/ppapi_proxy/command_buffer_nacl.cc @@ -25,18 +25,38 @@ CommandBufferNacl::~CommandBufferNacl() { iface_core_->ReleaseResource(graphics_3d_); } -bool CommandBufferNacl::Initialize() { +bool CommandBufferNacl::Initialize(int32 size) { DebugPrintf("CommandBufferNacl::Initialize\n"); int32_t success; NaClSrpcChannel* channel = ppapi_proxy::GetMainSrpcChannel(); NaClSrpcError retval = PpbGraphics3DRpcClient::PPB_Graphics3DTrusted_InitCommandBuffer( - channel, graphics_3d_, &success); + channel, graphics_3d_, size, &success); DebugPrintf("CommandBufferNaCl::Initialize returned success=%s\n", (PP_TRUE == success) ? "TRUE" : "FALSE"); return NACL_SRPC_RESULT_OK == retval && PP_TRUE == success; } +gpu::Buffer CommandBufferNacl::GetRingBuffer() { + DebugPrintf("CommandBufferNacl::GetRingBuffer\n"); + if (!buffer_.ptr) { + DebugPrintf("CommandBufferNacl::GetRingBuffer: Fetching\n"); + int shm_handle = -1; + int32_t shm_size = 0; + + NaClSrpcChannel* channel = ppapi_proxy::GetMainSrpcChannel(); + NaClSrpcError retval = + PpbGraphics3DRpcClient::PPB_Graphics3DTrusted_GetRingBuffer( + channel, graphics_3d_, &shm_handle, &shm_size); + if (NACL_SRPC_RESULT_OK != retval) { + shm_handle = -1; + } + buffer_ = BufferFromShm(shm_handle, shm_size); + } + + return buffer_; +} + gpu::CommandBuffer::State CommandBufferNacl::GetState() { DebugPrintf("CommandBufferNacl::GetState\n"); PP_Graphics3DTrustedState state; @@ -90,13 +110,6 @@ gpu::CommandBuffer::State CommandBufferNacl::FlushSync(int32 put_offset, return last_state_; } -void CommandBufferNacl::SetGetBuffer(int32 transfer_buffer_id) { - DebugPrintf("CommandBufferNacl::SetGetBuffer\n"); - NaClSrpcChannel* channel = ppapi_proxy::GetMainSrpcChannel(); - PpbGraphics3DRpcClient::PPB_Graphics3DTrusted_SetGetBuffer( - channel, graphics_3d_, transfer_buffer_id); -} - void CommandBufferNacl::SetGetOffset(int32 get_offset) { DebugPrintf("CommandBufferNacl::SetGetOffset\n"); // Not implemented by proxy. diff --git a/ppapi/native_client/src/shared/ppapi_proxy/command_buffer_nacl.h b/ppapi/native_client/src/shared/ppapi_proxy/command_buffer_nacl.h index 20e3836..a699241 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/command_buffer_nacl.h +++ b/ppapi/native_client/src/shared/ppapi_proxy/command_buffer_nacl.h @@ -22,12 +22,16 @@ class CommandBufferNacl : public gpu::CommandBuffer { virtual ~CommandBufferNacl(); // CommandBuffer implementation. - virtual bool Initialize(); + virtual bool Initialize(int32 size); + virtual bool Initialize(base::SharedMemory* buffer, int32 size) { + // TODO(neb): support for nacl if neccessary + return false; + } + 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* buffer, diff --git a/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_graphics_3d.cc b/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_graphics_3d.cc index ead08dd..c77902b 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_graphics_3d.cc +++ b/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_graphics_3d.cc @@ -212,9 +212,12 @@ bool PluginGraphics3D::InitFromBrowserResource(PP_Resource res) { // Create and initialize the objects required to issue GLES2 calls. command_buffer_.reset(new CommandBufferNacl(res, PluginCore::GetInterface())); - if (command_buffer_->Initialize()) { + if (command_buffer_->Initialize(kRingBufferSize)) { gles2_helper_.reset(new gpu::gles2::GLES2CmdHelper(command_buffer_.get())); - if (gles2_helper_->Initialize(kRingBufferSize)) { + gpu::Buffer buffer = command_buffer_->GetRingBuffer(); + DebugPrintf("PluginGraphics3D::InitFromBrowserResource: buffer size: %d\n", + buffer.size); + if (gles2_helper_->Initialize(buffer.size)) { // Request id -1 to signify 'don't care' int32 transfer_buffer_id = command_buffer_->CreateTransferBuffer(kTransferBufferSize, -1); diff --git a/ppapi/native_client/src/shared/ppapi_proxy/ppb_graphics_3d.srpc b/ppapi/native_client/src/shared/ppapi_proxy/ppb_graphics_3d.srpc index 0cb9b57..fe0b499 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/ppb_graphics_3d.srpc +++ b/ppapi/native_client/src/shared/ppapi_proxy/ppb_graphics_3d.srpc @@ -77,15 +77,16 @@ # Initialize the command buffer. {'name': 'PPB_Graphics3DTrusted_InitCommandBuffer', 'inputs': [['resource_id', 'PP_Resource'], + ['size', 'int32_t'] ], 'outputs': [['success', 'int32_t']] # PP_Bool }, - # Set the buffer used for commands. - {'name': 'PPB_Graphics3DTrusted_SetGetBuffer', - 'inputs': [['resource_id', 'PP_Resource'], - ['shm_id', 'int32_t'], - ], - 'outputs': [] + # Get the ring buffer. + {'name': 'PPB_Graphics3DTrusted_GetRingBuffer', + 'inputs': [['resource_id', 'PP_Resource']], + 'outputs': [['shm_desc', 'handle'], + ['shm_size', 'int32_t'] + ] }, # Get command buffer state. {'name': 'PPB_Graphics3DTrusted_GetState', @@ -141,6 +142,6 @@ ['shm_size', 'int32_t'] ] }, - # End of PPB_Graphics3DTrusted + # End of PPB_Graphics3DTrusted ] } diff --git a/ppapi/native_client/src/shared/ppapi_proxy/ppb_rpc_client.cc b/ppapi/native_client/src/shared/ppapi_proxy/ppb_rpc_client.cc index e5739ba..20ebd55 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/ppb_rpc_client.cc +++ b/ppapi/native_client/src/shared/ppapi_proxy/ppb_rpc_client.cc @@ -1435,6 +1435,7 @@ NaClSrpcError PpbGraphics3DRpcClient::PPB_Graphics3DTrusted_CreateRaw( NaClSrpcError PpbGraphics3DRpcClient::PPB_Graphics3DTrusted_InitCommandBuffer( NaClSrpcChannel* channel, PP_Resource resource_id, + int32_t size, int32_t* success) { VCHECK(ppapi_proxy::PPBCoreInterface()->IsMainThread(), ("%s: PPAPI calls are not supported off the main thread\n", @@ -1442,26 +1443,29 @@ NaClSrpcError PpbGraphics3DRpcClient::PPB_Graphics3DTrusted_InitCommandBuffer( NaClSrpcError retval; retval = NaClSrpcInvokeBySignature( channel, - "PPB_Graphics3DTrusted_InitCommandBuffer:i:i", + "PPB_Graphics3DTrusted_InitCommandBuffer:ii:i", resource_id, + size, success ); return retval; } -NaClSrpcError PpbGraphics3DRpcClient::PPB_Graphics3DTrusted_SetGetBuffer( +NaClSrpcError PpbGraphics3DRpcClient::PPB_Graphics3DTrusted_GetRingBuffer( NaClSrpcChannel* channel, PP_Resource resource_id, - int32_t transfer_buffer_id) { + NaClSrpcImcDescType* shm_desc, + int32_t* shm_size) { VCHECK(ppapi_proxy::PPBCoreInterface()->IsMainThread(), ("%s: PPAPI calls are not supported off the main thread\n", __FUNCTION__)); NaClSrpcError retval; retval = NaClSrpcInvokeBySignature( channel, - "PPB_Graphics3DTrusted_SetGetBuffer:ii:", + "PPB_Graphics3DTrusted_GetRingBuffer:i:hi", resource_id, - transfer_buffer_id + shm_desc, + shm_size ); return retval; } diff --git a/ppapi/native_client/src/shared/ppapi_proxy/ppb_rpc_server.cc b/ppapi/native_client/src/shared/ppapi_proxy/ppb_rpc_server.cc index b40fd2d..54187d0 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/ppb_rpc_server.cc +++ b/ppapi/native_client/src/shared/ppapi_proxy/ppb_rpc_server.cc @@ -1160,22 +1160,23 @@ static void PPB_Graphics3DTrusted_InitCommandBufferDispatcher( rpc, done, inputs[0]->u.ival, + inputs[1]->u.ival, &(outputs[0]->u.ival) ); } -static void PPB_Graphics3DTrusted_SetGetBufferDispatcher( +static void PPB_Graphics3DTrusted_GetRingBufferDispatcher( NaClSrpcRpc* rpc, NaClSrpcArg** inputs, NaClSrpcArg** outputs, NaClSrpcClosure* done ) { - UNREFERENCED_PARAMETER(outputs); - PpbGraphics3DRpcServer::PPB_Graphics3DTrusted_SetGetBuffer( + PpbGraphics3DRpcServer::PPB_Graphics3DTrusted_GetRingBuffer( rpc, done, inputs[0]->u.ival, - inputs[1]->u.ival + &(outputs[0]->u.hval), + &(outputs[1]->u.ival) ); } @@ -2618,8 +2619,8 @@ NaClSrpcHandlerDesc PpbRpcs::srpc_methods[] = { { "PPB_Graphics3D_GetError:i:i", PPB_Graphics3D_GetErrorDispatcher }, { "PPB_Graphics3D_SwapBuffers:ii:i", PPB_Graphics3D_SwapBuffersDispatcher }, { "PPB_Graphics3DTrusted_CreateRaw:iiI:i", PPB_Graphics3DTrusted_CreateRawDispatcher }, - { "PPB_Graphics3DTrusted_InitCommandBuffer:i:i", PPB_Graphics3DTrusted_InitCommandBufferDispatcher }, - { "PPB_Graphics3DTrusted_SetGetBuffer:ii:", PPB_Graphics3DTrusted_SetGetBufferDispatcher }, + { "PPB_Graphics3DTrusted_InitCommandBuffer:ii:i", PPB_Graphics3DTrusted_InitCommandBufferDispatcher }, + { "PPB_Graphics3DTrusted_GetRingBuffer:i:hi", PPB_Graphics3DTrusted_GetRingBufferDispatcher }, { "PPB_Graphics3DTrusted_GetState:i:C", PPB_Graphics3DTrusted_GetStateDispatcher }, { "PPB_Graphics3DTrusted_Flush:ii:", PPB_Graphics3DTrusted_FlushDispatcher }, { "PPB_Graphics3DTrusted_FlushSync:ii:C", PPB_Graphics3DTrusted_FlushSyncDispatcher }, diff --git a/ppapi/native_client/src/shared/ppapi_proxy/trusted/srpcgen/ppb_rpc.h b/ppapi/native_client/src/shared/ppapi_proxy/trusted/srpcgen/ppb_rpc.h index 588be46..25feea6 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/trusted/srpcgen/ppb_rpc.h +++ b/ppapi/native_client/src/shared/ppapi_proxy/trusted/srpcgen/ppb_rpc.h @@ -590,12 +590,14 @@ class PpbGraphics3DRpcServer { NaClSrpcRpc* rpc, NaClSrpcClosure* done, PP_Resource resource_id, + int32_t size, int32_t* success); - static void PPB_Graphics3DTrusted_SetGetBuffer( + static void PPB_Graphics3DTrusted_GetRingBuffer( NaClSrpcRpc* rpc, NaClSrpcClosure* done, PP_Resource resource_id, - int32_t shm_id); + NaClSrpcImcDescType* shm_desc, + int32_t* shm_size); static void PPB_Graphics3DTrusted_GetState( NaClSrpcRpc* rpc, NaClSrpcClosure* done, diff --git a/ppapi/native_client/src/shared/ppapi_proxy/untrusted/srpcgen/ppb_rpc.h b/ppapi/native_client/src/shared/ppapi_proxy/untrusted/srpcgen/ppb_rpc.h index 1eee263..aa2f7d0 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/untrusted/srpcgen/ppb_rpc.h +++ b/ppapi/native_client/src/shared/ppapi_proxy/untrusted/srpcgen/ppb_rpc.h @@ -515,11 +515,13 @@ class PpbGraphics3DRpcClient { static NaClSrpcError PPB_Graphics3DTrusted_InitCommandBuffer( NaClSrpcChannel* channel, PP_Resource resource_id, + int32_t size, int32_t* success); - static NaClSrpcError PPB_Graphics3DTrusted_SetGetBuffer( + static NaClSrpcError PPB_Graphics3DTrusted_GetRingBuffer( NaClSrpcChannel* channel, PP_Resource resource_id, - int32_t shm_id); + NaClSrpcImcDescType* shm_desc, + int32_t* shm_size); static NaClSrpcError PPB_Graphics3DTrusted_GetState( NaClSrpcChannel* channel, PP_Resource resource_id, diff --git a/ppapi/proxy/ppapi_messages.h b/ppapi/proxy/ppapi_messages.h index 7e277db..d6f0515 100644 --- a/ppapi/proxy/ppapi_messages.h +++ b/ppapi/proxy/ppapi_messages.h @@ -781,11 +781,10 @@ IPC_SYNC_MESSAGE_ROUTED2_1(PpapiHostMsg_PPBGraphics3D_Create, PP_Instance /* instance */, std::vector<int32_t> /* attrib_list */, ppapi::HostResource /* result */) -IPC_SYNC_MESSAGE_ROUTED1_0(PpapiHostMsg_PPBGraphics3D_InitCommandBuffer, - ppapi::HostResource /* context */) -IPC_SYNC_MESSAGE_ROUTED2_0(PpapiHostMsg_PPBGraphics3D_SetGetBuffer, +IPC_SYNC_MESSAGE_ROUTED2_1(PpapiHostMsg_PPBGraphics3D_InitCommandBuffer, ppapi::HostResource /* context */, - int32 /* transfer_buffer_id */) + int32 /* size */, + base::SharedMemoryHandle /* ring_buffer */) IPC_SYNC_MESSAGE_ROUTED1_1(PpapiHostMsg_PPBGraphics3D_GetState, ppapi::HostResource /* context */, gpu::CommandBuffer::State /* state */) 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, diff --git a/ppapi/proxy/ppb_graphics_3d_proxy.h b/ppapi/proxy/ppb_graphics_3d_proxy.h index bb54b61..472c2a7 100644 --- a/ppapi/proxy/ppb_graphics_3d_proxy.h +++ b/ppapi/proxy/ppb_graphics_3d_proxy.h @@ -36,8 +36,8 @@ class Graphics3D : public Resource, public Graphics3DImpl { } // Graphics3DTrusted API. These are not implemented in the proxy. - virtual PP_Bool InitCommandBuffer() OVERRIDE; - virtual PP_Bool SetGetBuffer(int32_t shm_id) OVERRIDE; + virtual PP_Bool InitCommandBuffer(int32_t size) OVERRIDE; + virtual PP_Bool GetRingBuffer(int* shm_handle, uint32_t* shm_size) OVERRIDE; virtual PP_Graphics3DTrustedState GetState() OVERRIDE; virtual PP_Bool Flush(int32_t put_offset) OVERRIDE; virtual PP_Graphics3DTrustedState FlushSync(int32_t put_offset) OVERRIDE; @@ -79,9 +79,9 @@ class PPB_Graphics3D_Proxy : public InterfaceProxy { void OnMsgCreate(PP_Instance instance, const std::vector<int32_t>& attribs, HostResource* result); - void OnMsgInitCommandBuffer(const HostResource& context); - void OnMsgSetGetBuffer(const HostResource& context, - int32 id); + void OnMsgInitCommandBuffer(const HostResource& context, + int32 size, + base::SharedMemoryHandle* ring_buffer); void OnMsgGetState(const HostResource& context, gpu::CommandBuffer::State* state); void OnMsgFlush(const HostResource& context, diff --git a/ppapi/thunk/ppb_graphics_3d_api.h b/ppapi/thunk/ppb_graphics_3d_api.h index 4e1980a..73e8178 100644 --- a/ppapi/thunk/ppb_graphics_3d_api.h +++ b/ppapi/thunk/ppb_graphics_3d_api.h @@ -25,8 +25,9 @@ class PPAPI_THUNK_EXPORT PPB_Graphics3D_API { virtual int32_t SwapBuffers(PP_CompletionCallback callback) = 0; // Graphics3DTrusted API. - virtual PP_Bool InitCommandBuffer() = 0; - virtual PP_Bool SetGetBuffer(int32_t shm_id) = 0; + virtual PP_Bool InitCommandBuffer(int32_t size) = 0; + virtual PP_Bool GetRingBuffer(int* shm_handle, + uint32_t* shm_size) = 0; virtual PP_Graphics3DTrustedState GetState() = 0; virtual int32_t CreateTransferBuffer(uint32_t size) = 0; virtual PP_Bool DestroyTransferBuffer(int32_t id) = 0; diff --git a/ppapi/thunk/ppb_graphics_3d_trusted_thunk.cc b/ppapi/thunk/ppb_graphics_3d_trusted_thunk.cc index bea32ab..5cc9661 100644 --- a/ppapi/thunk/ppb_graphics_3d_trusted_thunk.cc +++ b/ppapi/thunk/ppb_graphics_3d_trusted_thunk.cc @@ -30,18 +30,20 @@ PP_Resource CreateRaw(PP_Instance instance, instance, share_context, attrib_list); } -PP_Bool InitCommandBuffer(PP_Resource context) { +PP_Bool InitCommandBuffer(PP_Resource context, int32_t size) { EnterGraphics3D enter(context, true); if (enter.failed()) return PP_FALSE; - return enter.object()->InitCommandBuffer(); + return enter.object()->InitCommandBuffer(size); } -PP_Bool SetGetBuffer(PP_Resource context, int32_t transfer_buffer_id) { +PP_Bool GetRingBuffer(PP_Resource context, + int* shm_handle, + uint32_t* shm_size) { EnterGraphics3D enter(context, true); if (enter.failed()) return PP_FALSE; - return enter.object()->SetGetBuffer(transfer_buffer_id); + return enter.object()->GetRingBuffer(shm_handle, shm_size); } PP_Graphics3DTrustedState GetState(PP_Resource context) { @@ -101,7 +103,7 @@ PP_Graphics3DTrustedState FlushSyncFast(PP_Resource context, const PPB_Graphics3DTrusted g_ppb_graphics_3d_trusted_thunk = { &CreateRaw, &InitCommandBuffer, - &SetGetBuffer, + &GetRingBuffer, &GetState, &CreateTransferBuffer, &DestroyTransferBuffer, |