summaryrefslogtreecommitdiffstats
path: root/chrome/plugin/command_buffer_stub.cc
diff options
context:
space:
mode:
authorapatrick@google.com <apatrick@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-12 00:11:25 +0000
committerapatrick@google.com <apatrick@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-12 00:11:25 +0000
commita7a27ace0760f1ed19016822a45c6ec5300e861c (patch)
treeb7641f10c9fb3130c0ae8f50e7223db2ae722cda /chrome/plugin/command_buffer_stub.cc
parent82017272e7272182443d7054911c4f890346353e (diff)
downloadchromium_src-a7a27ace0760f1ed19016822a45c6ec5300e861c.zip
chromium_src-a7a27ace0760f1ed19016822a45c6ec5300e861c.tar.gz
chromium_src-a7a27ace0760f1ed19016822a45c6ec5300e861c.tar.bz2
Added CommandBufferProxy, CommandBufferStub. Replaced NPAPI with IPC for synchronous messages. WebPluginDelegateImpl can instantiate a command buffer. Removed remaining dependencies on NPAPI.
TEST=none BUG=none Review URL: http://codereview.chromium.org/465040 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@34397 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/plugin/command_buffer_stub.cc')
-rw-r--r--chrome/plugin/command_buffer_stub.cc135
1 files changed, 135 insertions, 0 deletions
diff --git a/chrome/plugin/command_buffer_stub.cc b/chrome/plugin/command_buffer_stub.cc
new file mode 100644
index 0000000..632e868
--- /dev/null
+++ b/chrome/plugin/command_buffer_stub.cc
@@ -0,0 +1,135 @@
+// Copyright (c) 2009 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 "base/process_util.h"
+#include "base/shared_memory.h"
+#include "chrome/common/command_buffer_messages.h"
+#include "chrome/plugin/command_buffer_stub.h"
+#include "chrome/plugin/plugin_channel.h"
+
+CommandBufferStub::CommandBufferStub(PluginChannel* channel,
+ gfx::NativeView view)
+ : channel_(channel),
+ view_(view) {
+ route_id_ = channel->GenerateRouteID();
+ channel->AddRoute(route_id_, this, false);
+}
+
+CommandBufferStub::~CommandBufferStub() {
+ channel_->RemoveRoute(route_id_);
+}
+
+void CommandBufferStub::OnChannelError() {
+ NOTREACHED() << "CommandBufferService::OnChannelError called";
+}
+
+bool CommandBufferStub::Send(IPC::Message* message) {
+ if (!channel_) {
+ delete message;
+ return false;
+ }
+
+ return channel_->Send(message);
+}
+
+void CommandBufferStub::OnInitialize(int32 size,
+ base::SharedMemoryHandle* ring_buffer) {
+ DCHECK(!command_buffer_.get());
+
+ *ring_buffer = base::SharedMemory::NULLHandle();
+
+ // Assume service is responsible for duplicating the handle from the calling
+ // process.
+ base::ProcessHandle peer_handle;
+ if (base::OpenProcessHandle(channel_->peer_pid(), &peer_handle))
+ return;
+
+ command_buffer_.reset(new gpu::CommandBufferService);
+
+ // Initialize the CommandBufferService and GPUProcessor.
+ base::SharedMemory* shared_memory = command_buffer_->Initialize(size);
+ if (shared_memory) {
+ processor_ = new gpu::GPUProcessor(command_buffer_.get());
+ if (processor_->Initialize(view_)) {
+ command_buffer_->SetPutOffsetChangeCallback(
+ NewCallback(processor_.get(),
+ &gpu::GPUProcessor::ProcessCommands));
+ shared_memory->ShareToProcess(peer_handle, ring_buffer);
+ } else {
+ processor_ = NULL;
+ command_buffer_.reset();
+ }
+ }
+
+ base::CloseProcessHandle(peer_handle);
+}
+
+void CommandBufferStub::OnSyncOffsets(int32 put_offset, int32* get_offset) {
+ *get_offset = command_buffer_->SyncOffsets(put_offset);
+}
+
+void CommandBufferStub::OnGetGetOffset(int32* get_offset) {
+ *get_offset = command_buffer_->GetGetOffset();
+}
+
+void CommandBufferStub::OnGetPutOffset(int32* put_offset) {
+ *put_offset = command_buffer_->GetPutOffset();
+}
+
+void CommandBufferStub::OnCreateTransferBuffer(int32 size, int32* id) {
+ *id = command_buffer_->CreateTransferBuffer(size);
+}
+
+void CommandBufferStub::OnDestroyTransferBuffer(int32 id) {
+ command_buffer_->DestroyTransferBuffer(id);
+}
+
+void CommandBufferStub::OnGetTransferBuffer(int32 id,
+ base::SharedMemoryHandle* transfer_buffer) {
+ *transfer_buffer = 0;
+
+ // Assume service is responsible for duplicating the handle to the calling
+ // process.
+ base::ProcessHandle peer_handle;
+ if (base::OpenProcessHandle(channel_->peer_pid(), &peer_handle))
+ return;
+
+ base::SharedMemory* shared_memory = command_buffer_->GetTransferBuffer(id);
+ if (shared_memory) {
+ shared_memory->ShareToProcess(peer_handle, transfer_buffer);
+ }
+
+ base::CloseProcessHandle(peer_handle);
+}
+
+void CommandBufferStub::OnGetToken(int32* token) {
+ *token = command_buffer_->GetToken();
+}
+
+void CommandBufferStub::OnResetParseError(int32* parse_error) {
+ *parse_error = command_buffer_->ResetParseError();
+}
+
+void CommandBufferStub::OnGetErrorStatus(bool* error_status) {
+ *error_status = command_buffer_->GetErrorStatus();
+}
+
+void CommandBufferStub::OnMessageReceived(const IPC::Message& msg) {
+ IPC_BEGIN_MESSAGE_MAP(CommandBufferStub, msg)
+ IPC_MESSAGE_HANDLER(CommandBufferMsg_Initialize, OnInitialize);
+ IPC_MESSAGE_HANDLER(CommandBufferMsg_SyncOffsets, OnSyncOffsets);
+ IPC_MESSAGE_HANDLER(CommandBufferMsg_GetGetOffset, OnGetGetOffset);
+ IPC_MESSAGE_HANDLER(CommandBufferMsg_GetPutOffset, OnGetPutOffset);
+ IPC_MESSAGE_HANDLER(CommandBufferMsg_CreateTransferBuffer,
+ OnCreateTransferBuffer);
+ IPC_MESSAGE_HANDLER(CommandBufferMsg_DestroyTransferBuffer,
+ OnDestroyTransferBuffer);
+ IPC_MESSAGE_HANDLER(CommandBufferMsg_GetTransferBuffer,
+ OnGetTransferBuffer);
+ IPC_MESSAGE_HANDLER(CommandBufferMsg_GetToken, OnGetToken);
+ IPC_MESSAGE_HANDLER(CommandBufferMsg_ResetParseError, OnResetParseError);
+ IPC_MESSAGE_HANDLER(CommandBufferMsg_GetErrorStatus, OnGetErrorStatus);
+ IPC_MESSAGE_UNHANDLED_ERROR()
+ IPC_END_MESSAGE_MAP()
+}