summaryrefslogtreecommitdiffstats
path: root/chrome/renderer/command_buffer_proxy.cc
diff options
context:
space:
mode:
authorapatrick@google.com <apatrick@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-22 23:28:15 +0000
committerapatrick@google.com <apatrick@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-22 23:28:15 +0000
commit7477ea6f6a173b586622fd276433a346760ffbf4 (patch)
tree678229a49ae5c4bb1a54a61374466cdddf57db59 /chrome/renderer/command_buffer_proxy.cc
parente4f7cec0a45a803faf00875a070090b165ff1fc5 (diff)
downloadchromium_src-7477ea6f6a173b586622fd276433a346760ffbf4.zip
chromium_src-7477ea6f6a173b586622fd276433a346760ffbf4.tar.gz
chromium_src-7477ea6f6a173b586622fd276433a346760ffbf4.tar.bz2
Added Pepper 3D device that instantiates the GPU plugin and sends GLES2 commands to it via a command buffer.
Added API for managing buffers to Pepper 3D device. Removed DCHECK from WebPluginImpl::SetWindow that checks against a windowless plugin being given a window handle. Please check this! Now an initially windowless plugin instance gets a handle when it requests a Pepper 3D context. Perhaps the window handle should be concealed from the underlying plugin isntance. Removed enable_gpu gyp variable and C macro. GPU code is always built on windows but not mac or linux. It is enabled at runtime with the --enable-gpu-plugin switch. Redesigned CommandBuffer interface so it exposes shared memory through a Buffer. This was necessary because Pepper has no notion of shared memory handles. The Buffer exposes the shared memory as both a handle (through base::SharedMemory) and the mapped address and size. Refactored CommandBufferEngine so mapped shared memory addresses and sizes are returned with a single call rather than two separate calls. Added 3D demo to pepper test plugin. TEST=try servers BUG=none Review URL: http://codereview.chromium.org/367002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@35185 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer/command_buffer_proxy.cc')
-rw-r--r--chrome/renderer/command_buffer_proxy.cc70
1 files changed, 55 insertions, 15 deletions
diff --git a/chrome/renderer/command_buffer_proxy.cc b/chrome/renderer/command_buffer_proxy.cc
index 262bb8e..b78fa84 100644
--- a/chrome/renderer/command_buffer_proxy.cc
+++ b/chrome/renderer/command_buffer_proxy.cc
@@ -8,6 +8,9 @@
#include "chrome/common/plugin_messages.h"
#include "chrome/renderer/command_buffer_proxy.h"
#include "chrome/renderer/plugin_channel_host.h"
+#include "gpu/command_buffer/common/cmd_buffer_common.h"
+
+using gpu::Buffer;
CommandBufferProxy::CommandBufferProxy(
PluginChannelHost* channel,
@@ -18,6 +21,14 @@ CommandBufferProxy::CommandBufferProxy(
}
CommandBufferProxy::~CommandBufferProxy() {
+ // 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 CommandBufferProxy::Send(IPC::Message* msg) {
@@ -30,10 +41,10 @@ bool CommandBufferProxy::Send(IPC::Message* msg) {
return false;
}
-base::SharedMemory* CommandBufferProxy::Initialize(int32 size) {
+bool CommandBufferProxy::Initialize(int32 size) {
DCHECK(!ring_buffer_.get());
- // Initialize the service. Assuming we are in the renderer process, the GPU
+ // 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;
@@ -42,18 +53,22 @@ base::SharedMemory* CommandBufferProxy::Initialize(int32 size) {
ring_buffer_.reset(new base::SharedMemory(handle, false));
if (ring_buffer_->Map(size * sizeof(int32))) {
size_ = size;
- return ring_buffer_.get();
+ return true;
}
ring_buffer_.reset();
}
- return NULL;
+ return false;
}
-base::SharedMemory* CommandBufferProxy::GetRingBuffer() {
+Buffer CommandBufferProxy::GetRingBuffer() {
// Return locally cached ring buffer.
- return ring_buffer_.get();
+ Buffer buffer;
+ buffer.ptr = ring_buffer_->memory();
+ buffer.size = size_ * sizeof(gpu::CommandBufferEntry);
+ buffer.shared_memory = ring_buffer_.get();
+ return buffer;
}
int32 CommandBufferProxy::GetSize() {
@@ -107,30 +122,55 @@ int32 CommandBufferProxy::CreateTransferBuffer(size_t size) {
void CommandBufferProxy::DestroyTransferBuffer(int32 id) {
// Remove the transfer buffer from the client side4 cache.
- transfer_buffers_.erase(id);
+ 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 CommandBufferMsg_DestroyTransferBuffer(route_id_, id));
}
-base::SharedMemory* CommandBufferProxy::GetTransferBuffer(int32 id) {
+Buffer CommandBufferProxy::GetTransferBuffer(int32 id) {
// 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.get();
+ 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;
- if (!Send(new CommandBufferMsg_GetTransferBuffer(route_id_, id, &handle)))
- return NULL;
+ size_t size;
+ if (!Send(new CommandBufferMsg_GetTransferBuffer(route_id_,
+ id,
+ &handle,
+ &size))) {
+ return Buffer();
+ }
// Cache the transfer buffer shared memory object client side.
- base::SharedMemory* transfer_buffer =
+ base::SharedMemory* shared_memory =
new base::SharedMemory(handle, false, base::GetCurrentProcessHandle());
- transfer_buffers_[id].reset(transfer_buffer);
- return transfer_buffer;
+ // Map the shared memory on demand.
+ if (!shared_memory->memory()) {
+ if (!shared_memory->Map(shared_memory->max_size())) {
+ delete shared_memory;
+ return Buffer();
+ }
+ }
+
+ Buffer buffer;
+ buffer.ptr = shared_memory->memory();
+ buffer.size = size;
+ buffer.shared_memory = shared_memory;
+ transfer_buffers_[id] = buffer;
+
+ return buffer;
}
int32 CommandBufferProxy::GetToken() {