summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ppapi/ppapi_proxy.gypi2
-rw-r--r--ppapi/proxy/ppapi_command_buffer_proxy.cc210
-rw-r--r--ppapi/proxy/ppapi_command_buffer_proxy.h65
-rw-r--r--ppapi/proxy/ppb_graphics_3d_proxy.cc233
-rw-r--r--ppapi/proxy/ppb_graphics_3d_proxy.h2
5 files changed, 282 insertions, 230 deletions
diff --git a/ppapi/ppapi_proxy.gypi b/ppapi/ppapi_proxy.gypi
index b35b129..44d245c 100644
--- a/ppapi/ppapi_proxy.gypi
+++ b/ppapi/ppapi_proxy.gypi
@@ -57,6 +57,8 @@
'proxy/plugin_var_tracker.h',
'proxy/ppapi_messages.cc',
'proxy/ppapi_messages.h',
+ 'proxy/ppapi_command_buffer_proxy.h',
+ 'proxy/ppapi_command_buffer_proxy.cc',
'proxy/ppapi_param_traits.cc',
'proxy/ppapi_param_traits.h',
'proxy/ppb_audio_input_proxy.cc',
diff --git a/ppapi/proxy/ppapi_command_buffer_proxy.cc b/ppapi/proxy/ppapi_command_buffer_proxy.cc
new file mode 100644
index 0000000..a457bc4
--- /dev/null
+++ b/ppapi/proxy/ppapi_command_buffer_proxy.cc
@@ -0,0 +1,210 @@
+// 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.
+
+#include "ppapi/proxy/ppapi_command_buffer_proxy.h"
+
+#include "ppapi/proxy/ppapi_messages.h"
+#include "ppapi/proxy/proxy_channel.h"
+#include "ppapi/shared_impl/api_id.h"
+#include "ppapi/shared_impl/host_resource.h"
+
+namespace ppapi {
+namespace proxy {
+
+PpapiCommandBufferProxy::PpapiCommandBufferProxy(
+ const ppapi::HostResource& resource,
+ ProxyChannel* channel)
+ : resource_(resource),
+ channel_(channel) {
+}
+
+PpapiCommandBufferProxy::~PpapiCommandBufferProxy() {
+ // 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 PpapiCommandBufferProxy::Initialize() {
+ return Send(new PpapiHostMsg_PPBGraphics3D_InitCommandBuffer(
+ ppapi::API_ID_PPB_GRAPHICS_3D, resource_));
+}
+
+gpu::CommandBuffer::State PpapiCommandBufferProxy::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(
+ ppapi::API_ID_PPB_GRAPHICS_3D, resource_, &state))) {
+ UpdateState(state);
+ }
+ }
+
+ return last_state_;
+}
+
+gpu::CommandBuffer::State PpapiCommandBufferProxy::GetLastState() {
+ return last_state_;
+}
+
+void PpapiCommandBufferProxy::Flush(int32 put_offset) {
+ if (last_state_.error != gpu::error::kNoError)
+ return;
+
+ IPC::Message* message = new PpapiHostMsg_PPBGraphics3D_AsyncFlush(
+ ppapi::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 PpapiCommandBufferProxy::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(
+ ppapi::API_ID_PPB_GRAPHICS_3D, resource_, put_offset,
+ last_known_get, &state))) {
+ UpdateState(state);
+ }
+ }
+ } else {
+ Flush(put_offset);
+ }
+ return last_state_;
+}
+
+void PpapiCommandBufferProxy::SetGetBuffer(int32 transfer_buffer_id) {
+ if (last_state_.error == gpu::error::kNoError) {
+ Send(new PpapiHostMsg_PPBGraphics3D_SetGetBuffer(
+ ppapi::API_ID_PPB_GRAPHICS_3D, resource_, transfer_buffer_id));
+ }
+}
+
+void PpapiCommandBufferProxy::SetGetOffset(int32 get_offset) {
+ // Not implemented in proxy.
+ NOTREACHED();
+}
+
+int32 PpapiCommandBufferProxy::CreateTransferBuffer(
+ size_t size,
+ int32 id_request) {
+ if (last_state_.error == gpu::error::kNoError) {
+ int32 id;
+ if (Send(new PpapiHostMsg_PPBGraphics3D_CreateTransferBuffer(
+ ppapi::API_ID_PPB_GRAPHICS_3D, resource_, size, &id))) {
+ return id;
+ }
+ }
+ return -1;
+}
+
+int32 PpapiCommandBufferProxy::RegisterTransferBuffer(
+ base::SharedMemory* shared_memory,
+ size_t size,
+ int32 id_request) {
+ // Not implemented in proxy.
+ NOTREACHED();
+ return -1;
+}
+
+void PpapiCommandBufferProxy::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(
+ ppapi::API_ID_PPB_GRAPHICS_3D, resource_, id));
+}
+
+gpu::Buffer PpapiCommandBufferProxy::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(
+ ppapi::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 PpapiCommandBufferProxy::SetToken(int32 token) {
+ NOTREACHED();
+}
+
+void PpapiCommandBufferProxy::SetParseError(gpu::error::Error error) {
+ NOTREACHED();
+}
+
+void PpapiCommandBufferProxy::SetContextLostReason(
+ gpu::error::ContextLostReason reason) {
+ NOTREACHED();
+}
+
+bool PpapiCommandBufferProxy::Send(IPC::Message* msg) {
+ DCHECK(last_state_.error == gpu::error::kNoError);
+
+ if (channel_->Send(msg))
+ return true;
+
+ last_state_.error = gpu::error::kLostContext;
+ return false;
+}
+
+void PpapiCommandBufferProxy::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;
+}
+
+} // namespace proxy
+} // namespace ppapi
+
diff --git a/ppapi/proxy/ppapi_command_buffer_proxy.h b/ppapi/proxy/ppapi_command_buffer_proxy.h
new file mode 100644
index 0000000..2d66c14
--- /dev/null
+++ b/ppapi/proxy/ppapi_command_buffer_proxy.h
@@ -0,0 +1,65 @@
+// 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.
+
+#ifndef PPAPI_PROXY_COMMAND_BUFFER_PROXY_H_
+#define PPAPI_PROXY_COMMAND_BUFFER_PROXY_H_
+#pragma once
+
+#include "base/hash_tables.h"
+#include "gpu/command_buffer/common/command_buffer.h"
+#include "ppapi/proxy/ppapi_proxy_export.h"
+#include "ppapi/shared_impl/host_resource.h"
+
+namespace IPC {
+class Message;
+}
+
+namespace ppapi {
+namespace proxy {
+
+class ProxyChannel;
+
+class PPAPI_PROXY_EXPORT PpapiCommandBufferProxy : public gpu::CommandBuffer {
+ public:
+ PpapiCommandBufferProxy(const HostResource& resource,
+ ProxyChannel* channel);
+ virtual ~PpapiCommandBufferProxy();
+
+ // 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_;
+ ProxyChannel* channel_;
+
+ DISALLOW_COPY_AND_ASSIGN(PpapiCommandBufferProxy);
+};
+
+} // namespace proxy
+} // namespace ppapi
+
+#endif // PPAPI_PROXY_COMMAND_BUFFER_PROXY_H_
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;
diff --git a/ppapi/proxy/ppb_graphics_3d_proxy.h b/ppapi/proxy/ppb_graphics_3d_proxy.h
index acad89c..310e0c2 100644
--- a/ppapi/proxy/ppb_graphics_3d_proxy.h
+++ b/ppapi/proxy/ppb_graphics_3d_proxy.h
@@ -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.