diff options
Diffstat (limited to 'chrome/plugin')
-rw-r--r-- | chrome/plugin/command_buffer_stub.cc | 135 | ||||
-rw-r--r-- | chrome/plugin/command_buffer_stub.h | 60 | ||||
-rw-r--r-- | chrome/plugin/webplugin_delegate_stub.cc | 17 | ||||
-rw-r--r-- | chrome/plugin/webplugin_delegate_stub.h | 11 |
4 files changed, 220 insertions, 3 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() +} diff --git a/chrome/plugin/command_buffer_stub.h b/chrome/plugin/command_buffer_stub.h new file mode 100644 index 0000000..2a167c3 --- /dev/null +++ b/chrome/plugin/command_buffer_stub.h @@ -0,0 +1,60 @@ +// 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. + +#ifndef CHROME_PLUGIN_COMMAND_BUFFER_STUB_H_ +#define CHROME_PLUGIN_COMMAND_BUFFER_STUB_H_ + +#if defined(ENABLE_GPU) + +#include "app/gfx/native_widget_types.h" +#include "base/ref_counted.h" +#include "gpu/command_buffer/service/command_buffer_service.h" +#include "gpu/command_buffer/service/gpu_processor.h" +#include "ipc/ipc_channel.h" +#include "ipc/ipc_message.h" + +class PluginChannel; + +class CommandBufferService; + +class CommandBufferStub : public IPC::Channel::Listener, + public IPC::Message::Sender { + public: + CommandBufferStub(PluginChannel* channel, gfx::NativeView view); + + virtual ~CommandBufferStub(); + + // IPC::Channel::Listener implementation: + virtual void OnMessageReceived(const IPC::Message& message); + virtual void OnChannelError(); + + // IPC::Message::Sender implementation: + virtual bool Send(IPC::Message* msg); + + int route_id() const { return route_id_; } + + private: + // Message handlers: + void OnInitialize(int32 size, base::SharedMemoryHandle* ring_buffer); + void OnSyncOffsets(int32 put_offset, int32* get_offset); + void OnGetGetOffset(int32* get_offset); + void OnGetPutOffset(int32* put_offset); + void OnCreateTransferBuffer(int32 size, int32* id); + void OnDestroyTransferBuffer(int32 id); + void OnGetTransferBuffer(int32 id, + base::SharedMemoryHandle* transfer_buffer); + void OnGetToken(int32* token); + void OnResetParseError(int32* parse_error); + void OnGetErrorStatus(bool* error_status); + + scoped_refptr<PluginChannel> channel_; + gfx::NativeView view_; + int route_id_; + scoped_ptr<gpu::CommandBufferService> command_buffer_; + scoped_refptr<gpu::GPUProcessor> processor_; +}; + +#endif // ENABLE_GPU + +#endif // CHROME_PLUGIN_COMMAND_BUFFER_STUB_H_ diff --git a/chrome/plugin/webplugin_delegate_stub.cc b/chrome/plugin/webplugin_delegate_stub.cc index d0fe483..c6bd74f 100644 --- a/chrome/plugin/webplugin_delegate_stub.cc +++ b/chrome/plugin/webplugin_delegate_stub.cc @@ -130,6 +130,8 @@ void WebPluginDelegateStub::OnMessageReceived(const IPC::Message& msg) { IPC_MESSAGE_HANDLER(PluginMsg_InstallMissingPlugin, OnInstallMissingPlugin) IPC_MESSAGE_HANDLER(PluginMsg_HandleURLRequestReply, OnHandleURLRequestReply) + IPC_MESSAGE_HANDLER(PluginMsg_CreateCommandBuffer, + OnCreateCommandBuffer) IPC_MESSAGE_UNHANDLED_ERROR() IPC_END_MESSAGE_MAP() @@ -302,8 +304,9 @@ void WebPluginDelegateStub::OnUpdateGeometry( ); } -void WebPluginDelegateStub::OnGetPluginScriptableObject(int* route_id, - intptr_t* npobject_ptr) { +void WebPluginDelegateStub::OnGetPluginScriptableObject( + int* route_id, + intptr_t* npobject_ptr) { NPObject* object = delegate_->GetPluginScriptableObject(); if (!object) { *route_id = MSG_ROUTING_NONE; @@ -357,6 +360,16 @@ void WebPluginDelegateStub::OnInstallMissingPlugin() { delegate_->InstallMissingPlugin(); } +void WebPluginDelegateStub::OnCreateCommandBuffer(int* route_id) { +#if defined(ENABLE_GPU) + command_buffer_stub_.reset(new CommandBufferStub( + static_cast<PluginChannel*>(PluginChannelBase::GetCurrentChannel()), + delegate_->windowed_handle())); + + *route_id = command_buffer_stub_->route_id(); +#endif +} + void WebPluginDelegateStub::CreateSharedBuffer( size_t size, base::SharedMemory* shared_buf, diff --git a/chrome/plugin/webplugin_delegate_stub.h b/chrome/plugin/webplugin_delegate_stub.h index 79b36bf..d5d3ab0 100644 --- a/chrome/plugin/webplugin_delegate_stub.h +++ b/chrome/plugin/webplugin_delegate_stub.h @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// 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. @@ -12,6 +12,7 @@ #include "base/shared_memory.h" #include "base/task.h" #include "chrome/common/transport_dib.h" +#include "chrome/plugin/command_buffer_stub.h" #include "googleurl/src/gurl.h" #include "ipc/ipc_channel.h" #include "third_party/npapi/bindings/npapi.h" @@ -93,6 +94,8 @@ class WebPluginDelegateStub : public IPC::Channel::Listener, void OnHandleURLRequestReply( const PluginMsg_URLRequestReply_Params& params); + void OnCreateCommandBuffer(int* route_id); + void CreateSharedBuffer(size_t size, base::SharedMemory* shared_buf, base::SharedMemoryHandle* remote_handle); @@ -109,6 +112,12 @@ class WebPluginDelegateStub : public IPC::Channel::Listener, // The url of the main frame hosting the plugin. GURL page_url_; +#if defined(ENABLE_GPU) + // If this is the GPU plugin, the stub object that forwards to the + // command buffer service. + scoped_ptr<CommandBufferStub> command_buffer_stub_; +#endif + DISALLOW_IMPLICIT_CONSTRUCTORS(WebPluginDelegateStub); }; |