diff options
author | jcivelli@chromium.org <jcivelli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-04 00:43:15 +0000 |
---|---|---|
committer | jcivelli@chromium.org <jcivelli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-04 00:43:15 +0000 |
commit | 0b537a44c49a3ce217d7e21befd84224d089d588 (patch) | |
tree | d674da2bfd5189f1b23fe359dd760e9188ba7299 /chrome/plugin | |
parent | bb837f9287259862c94155cc59cfc9e1bdfe1258 (diff) | |
download | chromium_src-0b537a44c49a3ce217d7e21befd84224d089d588.zip chromium_src-0b537a44c49a3ce217d7e21befd84224d089d588.tar.gz chromium_src-0b537a44c49a3ce217d7e21befd84224d089d588.tar.bz2 |
Revert 76840 - Removed GPU plugin.
Pepper 3D v2 does not use the GPU plugin. It is integrated with the accelerated compositor.
TEST=PPAPI 3D v2 still works, trybots
BUG=none
Review URL: http://codereview.chromium.org/6588090
TBR=apatrick@chromium.org
Review URL: http://codereview.chromium.org/6614030
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@76845 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/plugin')
-rw-r--r-- | chrome/plugin/command_buffer_stub.cc | 195 | ||||
-rw-r--r-- | chrome/plugin/command_buffer_stub.h | 84 | ||||
-rw-r--r-- | chrome/plugin/command_buffer_stub_win.cc | 73 | ||||
-rw-r--r-- | chrome/plugin/plugin_main.cc | 2 | ||||
-rw-r--r-- | chrome/plugin/webplugin_delegate_stub.cc | 38 | ||||
-rw-r--r-- | chrome/plugin/webplugin_delegate_stub.h | 9 |
6 files changed, 400 insertions, 1 deletions
diff --git a/chrome/plugin/command_buffer_stub.cc b/chrome/plugin/command_buffer_stub.cc new file mode 100644 index 0000000..9aea1ee --- /dev/null +++ b/chrome/plugin/command_buffer_stub.cc @@ -0,0 +1,195 @@ +// 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 "chrome/plugin/command_buffer_stub.h" + +#include "base/callback.h" +#include "base/scoped_open_process.h" +#include "base/shared_memory.h" +#include "chrome/common/gpu_messages.h" +#include "chrome/common/plugin_messages.h" +#include "chrome/plugin/plugin_channel.h" + +using gpu::Buffer; + +CommandBufferStub::CommandBufferStub(PluginChannel* channel, + int plugin_host_route_id, + gfx::PluginWindowHandle window) + : channel_(channel), + plugin_host_route_id_(plugin_host_route_id), + window_(window) { + route_id_ = channel->GenerateRouteID(); + channel->AddRoute(route_id_, this, NULL); +} + +CommandBufferStub::~CommandBufferStub() { + Destroy(); + channel_->RemoveRoute(route_id_); +} + +bool CommandBufferStub::OnMessageReceived(const IPC::Message& message) { + bool handled = true; + IPC_BEGIN_MESSAGE_MAP(CommandBufferStub, message) + IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_Initialize, OnInitialize); + IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_GetState, OnGetState); + IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_AsyncGetState, OnAsyncGetState); + IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_Flush, OnFlush); + IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_AsyncFlush, OnAsyncFlush); + IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_CreateTransferBuffer, + OnCreateTransferBuffer); + IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_DestroyTransferBuffer, + OnDestroyTransferBuffer); + IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_GetTransferBuffer, + OnGetTransferBuffer); +#if defined(OS_MACOSX) + IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_SetWindowSize, OnSetWindowSize); +#endif + IPC_MESSAGE_UNHANDLED(handled = false) + IPC_END_MESSAGE_MAP() + DCHECK(handled); + return handled; +} + +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::NotifyRepaint() { + Send(new GpuCommandBufferMsg_NotifyRepaint(route_id_)); +} + +void CommandBufferStub::OnInitialize(base::SharedMemoryHandle ring_buffer, + int32 size, + bool* result) { + // TODO(apatrick): Pepper3D v1 is not used anymore. This function is never + // called. Delete the GPU plugin. + NOTREACHED(); + *result = false; +} + +void CommandBufferStub::OnGetState(gpu::CommandBuffer::State* state) { + *state = command_buffer_->GetState(); +} + +void CommandBufferStub::OnAsyncGetState() { + gpu::CommandBuffer::State state = command_buffer_->GetState(); + Send(new GpuCommandBufferMsg_UpdateState(route_id_, state)); +} + +void CommandBufferStub::OnFlush(int32 put_offset, + gpu::CommandBuffer::State* state) { + *state = command_buffer_->FlushSync(put_offset); +} + +void CommandBufferStub::OnAsyncFlush(int32 put_offset) { + gpu::CommandBuffer::State state = command_buffer_->FlushSync(put_offset); + Send(new GpuCommandBufferMsg_UpdateState(route_id_, state)); +} + +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, + uint32* size) { + *transfer_buffer = base::SharedMemoryHandle(); + *size = 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; + + Buffer buffer = command_buffer_->GetTransferBuffer(id); + if (buffer.shared_memory) { + buffer.shared_memory->ShareToProcess(peer_handle, transfer_buffer); + *size = buffer.shared_memory->created_size(); + } + + base::CloseProcessHandle(peer_handle); +} + +void CommandBufferStub::Destroy() { + processor_.reset(); + command_buffer_.reset(); + + DestroyPlatformSpecific(); +} + +#if !defined(OS_WIN) +bool CommandBufferStub::InitializePlatformSpecific() { + return true; +} + +void CommandBufferStub::DestroyPlatformSpecific() { +} +#endif // defined(OS_WIN) + +#if defined(OS_MACOSX) +void CommandBufferStub::OnSetWindowSize(const gfx::Size& size) { + // Try using the IOSurface version first. + bool notify_repaint = false; + uint64 new_backing_store = processor_->SetWindowSizeForIOSurface(size); + if (new_backing_store) { + Send(new PluginHostMsg_AcceleratedSurfaceSetIOSurface( + plugin_host_route_id_, + window_, + size.width(), + size.height(), + new_backing_store)); + notify_repaint = true; + } else { + // If |new_backing_store| is 0, it might mean that the IOSurface APIs are + // not available. In this case, see if TransportDIBs are supported. + TransportDIB::Handle transport_dib = + processor_->SetWindowSizeForTransportDIB(size); + if (TransportDIB::is_valid(transport_dib)) { + Send(new PluginHostMsg_AcceleratedSurfaceSetTransportDIB( + plugin_host_route_id_, + window_, + size.width(), + size.height(), + transport_dib)); + notify_repaint = true; + } + } + if (notify_repaint) { + // Indicate to the client that at least one repaint is needed. + NotifyRepaint(); + } +} + +void CommandBufferStub::SwapBuffersCallback() { + Send(new PluginHostMsg_AcceleratedSurfaceBuffersSwapped( + plugin_host_route_id_, window_, processor_->GetSurfaceId())); +} + +void CommandBufferStub::AllocTransportDIB(const size_t size, + TransportDIB::Handle* dib_handle) { + Send(new PluginHostMsg_AllocTransportDIB(plugin_host_route_id_, + size, + dib_handle)); +} + +void CommandBufferStub::FreeTransportDIB(TransportDIB::Id dib_id) { + Send(new PluginHostMsg_FreeTransportDIB(plugin_host_route_id_, + dib_id)); +} +#endif diff --git a/chrome/plugin/command_buffer_stub.h b/chrome/plugin/command_buffer_stub.h new file mode 100644 index 0000000..a2667f1 --- /dev/null +++ b/chrome/plugin/command_buffer_stub.h @@ -0,0 +1,84 @@ +// 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_ +#pragma once + +#if defined(ENABLE_GPU) + +#include "app/surface/transport_dib.h" +#include "base/ref_counted.h" +#include "gpu/command_buffer/common/command_buffer.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" +#include "ui/gfx/native_widget_types.h" + +class PluginChannel; + +class CommandBufferService; + +class CommandBufferStub : public IPC::Channel::Listener, + public IPC::Message::Sender { + public: + CommandBufferStub(PluginChannel* channel, + int plugin_host_route_id, + gfx::PluginWindowHandle window); + + virtual ~CommandBufferStub(); + + // IPC::Channel::Listener implementation: + virtual bool 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_; } + + // Notify the client that it must repaint due to the window becoming invalid + // or a lost context. + void NotifyRepaint(); + + private: + // Message handlers: + void OnInitialize(base::SharedMemoryHandle ring_buffer, + int32 size, + bool* result); + void OnGetState(gpu::CommandBuffer::State* state); + void OnAsyncGetState(); + void OnFlush(int32 put_offset, gpu::CommandBuffer::State* state); + void OnAsyncFlush(int32 put_offset); + void OnCreateTransferBuffer(int32 size, int32* id); + void OnDestroyTransferBuffer(int32 id); + void OnGetTransferBuffer(int32 id, + base::SharedMemoryHandle* transfer_buffer, + uint32* size); + + // Destroy all owned objects. + void Destroy(); + + bool InitializePlatformSpecific(); + void DestroyPlatformSpecific(); + +#if defined(OS_MACOSX) + void OnSetWindowSize(const gfx::Size& size); + void SwapBuffersCallback(); + void AllocTransportDIB(const size_t size, TransportDIB::Handle* dib_handle); + void FreeTransportDIB(TransportDIB::Id dib_id); +#endif + + scoped_refptr<PluginChannel> channel_; + int plugin_host_route_id_; + gfx::PluginWindowHandle window_; + int route_id_; + scoped_ptr<gpu::CommandBufferService> command_buffer_; + scoped_ptr<gpu::GPUProcessor> processor_; +}; + +#endif // ENABLE_GPU + +#endif // CHROME_PLUGIN_COMMAND_BUFFER_STUB_H_ diff --git a/chrome/plugin/command_buffer_stub_win.cc b/chrome/plugin/command_buffer_stub_win.cc new file mode 100644 index 0000000..11369a6 --- /dev/null +++ b/chrome/plugin/command_buffer_stub_win.cc @@ -0,0 +1,73 @@ +// Copyright (c) 2010 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 <windows.h> + +#include "chrome/plugin/command_buffer_stub.h" + +namespace { +const wchar_t* kPreviousWndProcProperty = L"CommandBufferStubPrevWndProc"; +const wchar_t* kCommandBufferStubProperty = L"CommandBufferStub"; + +// Message handler for the GPU plugin's child window. Used to intercept +// WM_PAINT events and forward repaint notifications to the client. +LRESULT WINAPI WndProc(HWND handle, + UINT message, + WPARAM w_param, + LPARAM l_param) { + WNDPROC previous_wnd_proc = reinterpret_cast<WNDPROC>( + ::GetProp(handle, kPreviousWndProcProperty)); + CommandBufferStub* stub = reinterpret_cast<CommandBufferStub*>( + ::GetProp(handle, kCommandBufferStubProperty)); + + switch (message) { + case WM_ERASEBKGND: + // Do not clear background. Avoids flickering. + return 1; + case WM_PAINT: + // Validate the whole window to prevent another WM_PAINT message. + ValidateRect(handle, NULL); + + // Notify client that the window is invalid and needs to be repainted. + stub->NotifyRepaint(); + + return 1; + default: + return CallWindowProc(previous_wnd_proc, + handle, + message, + w_param, + l_param); + } +} +} // namespace anonymous + +bool CommandBufferStub::InitializePlatformSpecific() { + // Subclass window. + WNDPROC previous_wnd_proc = reinterpret_cast<WNDPROC>( + ::GetWindowLongPtr(window_, GWLP_WNDPROC)); + ::SetProp(window_, + kPreviousWndProcProperty, + reinterpret_cast<HANDLE>(previous_wnd_proc)); + ::SetWindowLongPtr(window_, + GWLP_WNDPROC, + reinterpret_cast<LONG_PTR>(WndProc)); + + // Record pointer to this in window. + ::SetProp(window_, + kCommandBufferStubProperty, + reinterpret_cast<HANDLE>(this)); + + return true; +} + +void CommandBufferStub::DestroyPlatformSpecific() { + // Restore window. + WNDPROC previous_wnd_proc = reinterpret_cast<WNDPROC>( + ::GetProp(window_, kPreviousWndProcProperty)); + ::SetWindowLongPtr(window_, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>( + previous_wnd_proc)); + ::RemoveProp(window_, kPreviousWndProcProperty); + ::RemoveProp(window_, kCommandBufferStubProperty); +} diff --git a/chrome/plugin/plugin_main.cc b/chrome/plugin/plugin_main.cc index d8264fe..5c94e52 100644 --- a/chrome/plugin/plugin_main.cc +++ b/chrome/plugin/plugin_main.cc @@ -17,6 +17,7 @@ #include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/default_plugin.h" +#include "chrome/common/gpu_plugin.h" #include "chrome/common/hi_res_timer_manager.h" #include "chrome/common/logging_chrome.h" #include "chrome/common/main_function_params.h" @@ -173,6 +174,7 @@ int PluginMain(const MainFunctionParams& parameters) { #endif chrome::RegisterInternalDefaultPlugin(); + chrome::RegisterInternalGPUPlugin(); MessageLoop::current()->Run(); } diff --git a/chrome/plugin/webplugin_delegate_stub.cc b/chrome/plugin/webplugin_delegate_stub.cc index 0624e3e..75a3dc8 100644 --- a/chrome/plugin/webplugin_delegate_stub.cc +++ b/chrome/plugin/webplugin_delegate_stub.cc @@ -28,6 +28,10 @@ #include "printing/native_metafile.h" #endif // defined(OS_WIN) +#if defined(ENABLE_GPU) +#include "app/gfx/gl/gl_context.h" +#endif + using WebKit::WebBindings; using WebKit::WebCursorInfo; using webkit::npapi::WebPlugin; @@ -68,6 +72,13 @@ WebPluginDelegateStub::~WebPluginDelegateStub() { in_destructor_ = true; child_process_logging::SetActiveURL(page_url_); +#if defined(ENABLE_GPU) + // Make sure there is no command buffer before destroying the window handle. + // The GPU service code might otherwise asynchronously perform an operation + // using the window handle. + command_buffer_stub_.reset(); +#endif + if (channel_->in_send()) { // The delegate or an npobject is in the callstack, so don't delete it // right away. @@ -133,6 +144,10 @@ bool WebPluginDelegateStub::OnMessageReceived(const IPC::Message& msg) { OnHandleURLRequestReply) IPC_MESSAGE_HANDLER(PluginMsg_HTTPRangeRequestReply, OnHTTPRangeRequestReply) + IPC_MESSAGE_HANDLER(PluginMsg_CreateCommandBuffer, + OnCreateCommandBuffer) + IPC_MESSAGE_HANDLER(PluginMsg_DestroyCommandBuffer, + OnDestroyCommandBuffer) #if defined(OS_MACOSX) IPC_MESSAGE_HANDLER(PluginMsg_SetFakeAcceleratedSurfaceWindowHandle, OnSetFakeAcceleratedSurfaceWindowHandle) @@ -401,6 +416,29 @@ void WebPluginDelegateStub::OnInstallMissingPlugin() { delegate_->InstallMissingPlugin(); } +void WebPluginDelegateStub::OnCreateCommandBuffer(int* route_id) { + *route_id = 0; +#if defined(ENABLE_GPU) + // Fail to create the command buffer if some GL implementation cannot be + // initialized. + if (!gfx::GLContext::InitializeOneOff()) + return; + + command_buffer_stub_.reset(new CommandBufferStub( + channel_, + instance_id_, + delegate_->windowed_handle())); + + *route_id = command_buffer_stub_->route_id(); +#endif // ENABLE_GPU +} + +void WebPluginDelegateStub::OnDestroyCommandBuffer() { +#if defined(ENABLE_GPU) + command_buffer_stub_.reset(); +#endif +} + void WebPluginDelegateStub::CreateSharedBuffer( uint32 size, base::SharedMemory* shared_buf, diff --git a/chrome/plugin/webplugin_delegate_stub.h b/chrome/plugin/webplugin_delegate_stub.h index b56bca7..e769a84 100644 --- a/chrome/plugin/webplugin_delegate_stub.h +++ b/chrome/plugin/webplugin_delegate_stub.h @@ -12,10 +12,10 @@ #include "base/ref_counted.h" #include "base/shared_memory.h" #include "base/task.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" -#include "ui/gfx/native_widget_types.h" #include "ui/gfx/rect.h" class PluginChannel; @@ -103,6 +103,8 @@ class WebPluginDelegateStub : public IPC::Channel::Listener, const GURL& url, int notify_id); void OnHTTPRangeRequestReply(unsigned long resource_id, int range_request_id); + void OnCreateCommandBuffer(int* route_id); + void OnDestroyCommandBuffer(); void CreateSharedBuffer(uint32 size, base::SharedMemory* shared_buf, @@ -121,12 +123,17 @@ class WebPluginDelegateStub : public IPC::Channel::Listener, 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_; + #if defined(OS_MACOSX) // If this is a GPU-accelerated plug-in, we need to be able to receive a fake // window handle which is used for subsequent communication back to the // browser. void OnSetFakeAcceleratedSurfaceWindowHandle(gfx::PluginWindowHandle window); #endif + #endif DISALLOW_IMPLICIT_CONSTRUCTORS(WebPluginDelegateStub); |