diff options
author | apatrick@google.com <apatrick@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-22 23:28:15 +0000 |
---|---|---|
committer | apatrick@google.com <apatrick@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-22 23:28:15 +0000 |
commit | 7477ea6f6a173b586622fd276433a346760ffbf4 (patch) | |
tree | 678229a49ae5c4bb1a54a61374466cdddf57db59 /webkit | |
parent | e4f7cec0a45a803faf00875a070090b165ff1fc5 (diff) | |
download | chromium_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 'webkit')
-rw-r--r-- | webkit/glue/plugins/npapi_extension_thunk.cc | 61 | ||||
-rw-r--r-- | webkit/glue/plugins/plugin_constants_win.h | 2 | ||||
-rw-r--r-- | webkit/glue/plugins/plugin_list.cc | 2 | ||||
-rw-r--r-- | webkit/glue/plugins/plugin_list.h | 2 | ||||
-rw-r--r-- | webkit/glue/plugins/plugin_list_win.cc | 2 | ||||
-rw-r--r-- | webkit/glue/plugins/webplugin_3d_device_delegate.h | 14 | ||||
-rw-r--r-- | webkit/glue/webplugin_impl.cc | 4 | ||||
-rw-r--r-- | webkit/tools/pepper_test_plugin/DEPS | 3 | ||||
-rw-r--r-- | webkit/tools/pepper_test_plugin/command_buffer_pepper.cc | 180 | ||||
-rw-r--r-- | webkit/tools/pepper_test_plugin/command_buffer_pepper.h | 52 | ||||
-rw-r--r-- | webkit/tools/pepper_test_plugin/main.cc | 2 | ||||
-rw-r--r-- | webkit/tools/pepper_test_plugin/pepper_test_plugin.gyp | 7 | ||||
-rw-r--r-- | webkit/tools/pepper_test_plugin/plugin_object.cc | 120 | ||||
-rw-r--r-- | webkit/tools/pepper_test_plugin/plugin_object.h | 16 | ||||
-rw-r--r-- | webkit/tools/pepper_test_plugin/test_page.html | 2 | ||||
-rw-r--r-- | webkit/webkit.gyp | 1 |
16 files changed, 440 insertions, 30 deletions
diff --git a/webkit/glue/plugins/npapi_extension_thunk.cc b/webkit/glue/plugins/npapi_extension_thunk.cc index e07bff2..eee6c80 100644 --- a/webkit/glue/plugins/npapi_extension_thunk.cc +++ b/webkit/glue/plugins/npapi_extension_thunk.cc @@ -114,6 +114,26 @@ static NPError Device2DDestroyContext(NPP id, return NPERR_GENERIC_ERROR; } +static NPError Device2DCreateBuffer(NPP id, + NPDeviceContext* context, + size_t size, + int32* buffer_id) { + return NPERR_GENERIC_ERROR; +} + +static NPError Device2DDestroyBuffer(NPP id, + NPDeviceContext* context, + int32 buffer_id) { + return NPERR_GENERIC_ERROR; +} + +static NPError Device2DMapBuffer(NPP id, + NPDeviceContext* context, + int32 buffer_id, + NPDeviceBuffer* buffer) { + return NPERR_GENERIC_ERROR; +} + // 3D device API --------------------------------------------------------------- static NPError Device3DQueryCapability(NPP id, int32 capability, int32* value) { @@ -196,6 +216,41 @@ static NPError Device3DDestroyContext(NPP id, return NPERR_GENERIC_ERROR; } +static NPError Device3DCreateBuffer(NPP id, + NPDeviceContext* context, + size_t size, + int32* buffer_id) { + scoped_refptr<NPAPI::PluginInstance> plugin = FindInstance(id); + if (plugin) { + return plugin->webplugin()->delegate()->Device3DCreateBuffer( + static_cast<NPDeviceContext3D*>(context), size, buffer_id); + } + return NPERR_GENERIC_ERROR; +} + +static NPError Device3DDestroyBuffer(NPP id, + NPDeviceContext* context, + int32 buffer_id) { + scoped_refptr<NPAPI::PluginInstance> plugin = FindInstance(id); + if (plugin) { + return plugin->webplugin()->delegate()->Device3DDestroyBuffer( + static_cast<NPDeviceContext3D*>(context), buffer_id); + } + return NPERR_GENERIC_ERROR; +} + +static NPError Device3DMapBuffer(NPP id, + NPDeviceContext* context, + int32 buffer_id, + NPDeviceBuffer* buffer) { + scoped_refptr<NPAPI::PluginInstance> plugin = FindInstance(id); + if (plugin) { + return plugin->webplugin()->delegate()->Device3DMapBuffer( + static_cast<NPDeviceContext3D*>(context), buffer_id, buffer); + } + return NPERR_GENERIC_ERROR; +} + // ----------------------------------------------------------------------------- static NPDevice* AcquireDevice(NPP id, NPDeviceID device_id) { @@ -207,6 +262,9 @@ static NPDevice* AcquireDevice(NPP id, NPDeviceID device_id) { Device2DGetStateContext, Device2DFlushContext, Device2DDestroyContext, + Device2DCreateBuffer, + Device2DDestroyBuffer, + Device2DMapBuffer, }; static NPDevice device_3d = { Device3DQueryCapability, @@ -216,6 +274,9 @@ static NPDevice* AcquireDevice(NPP id, NPDeviceID device_id) { Device3DGetStateContext, Device3DFlushContext, Device3DDestroyContext, + Device3DCreateBuffer, + Device3DDestroyBuffer, + Device3DMapBuffer, }; switch (device_id) { diff --git a/webkit/glue/plugins/plugin_constants_win.h b/webkit/glue/plugins/plugin_constants_win.h index b708706..9913e5d 100644 --- a/webkit/glue/plugins/plugin_constants_win.h +++ b/webkit/glue/plugins/plugin_constants_win.h @@ -36,4 +36,6 @@ #define kJavaPlugin1 L"npjp2.dll" #define kJavaPlugin2 L"npdeploytk.dll" +#define kGPUPluginMimeType "application/vnd.google.chrome.gpu-plugin" + #endif // WEBKIT_GLUE_PLUGIN_PLUGIN_LIST_H_ diff --git a/webkit/glue/plugins/plugin_list.cc b/webkit/glue/plugins/plugin_list.cc index 2109951..ec4a80b 100644 --- a/webkit/glue/plugins/plugin_list.cc +++ b/webkit/glue/plugins/plugin_list.cc @@ -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. diff --git a/webkit/glue/plugins/plugin_list.h b/webkit/glue/plugins/plugin_list.h index 822ac05..ec82fd0 100644 --- a/webkit/glue/plugins/plugin_list.h +++ b/webkit/glue/plugins/plugin_list.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. diff --git a/webkit/glue/plugins/plugin_list_win.cc b/webkit/glue/plugins/plugin_list_win.cc index b762a8f..25a3be4 100644 --- a/webkit/glue/plugins/plugin_list_win.cc +++ b/webkit/glue/plugins/plugin_list_win.cc @@ -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. diff --git a/webkit/glue/plugins/webplugin_3d_device_delegate.h b/webkit/glue/plugins/webplugin_3d_device_delegate.h index 78dbe0e..42dc300 100644 --- a/webkit/glue/plugins/webplugin_3d_device_delegate.h +++ b/webkit/glue/plugins/webplugin_3d_device_delegate.h @@ -46,6 +46,20 @@ class WebPlugin3DDeviceDelegate { virtual NPError Device3DDestroyContext(NPDeviceContext3D* context) { return NPERR_GENERIC_ERROR; } + virtual NPError Device3DCreateBuffer(NPDeviceContext3D* context, + size_t size, + int32* id) { + return NPERR_GENERIC_ERROR; + } + virtual NPError Device3DDestroyBuffer(NPDeviceContext3D* context, + int32 id) { + return NPERR_GENERIC_ERROR; + } + virtual NPError Device3DMapBuffer(NPDeviceContext3D* context, + int32 id, + NPDeviceBuffer* buffer) { + return NPERR_GENERIC_ERROR; + } protected: WebPlugin3DDeviceDelegate() {} diff --git a/webkit/glue/webplugin_impl.cc b/webkit/glue/webplugin_impl.cc index 2cc4962..8c1ffa9 100644 --- a/webkit/glue/webplugin_impl.cc +++ b/webkit/glue/webplugin_impl.cc @@ -74,7 +74,7 @@ namespace { // specified in the response header. class MultiPartResponseClient : public WebURLLoaderClient { public: - MultiPartResponseClient(WebPluginResourceClient* resource_client) + explicit MultiPartResponseClient(WebPluginResourceClient* resource_client) : resource_client_(resource_client) { Clear(); } @@ -398,7 +398,7 @@ WebPluginImpl::~WebPluginImpl() { void WebPluginImpl::SetWindow(gfx::PluginWindowHandle window) { if (window) { - DCHECK(!windowless_); // Make sure not called twice. + DCHECK(!windowless_); window_ = window; if (page_delegate_) { // Tell the view delegate that the plugin window was created, so that it diff --git a/webkit/tools/pepper_test_plugin/DEPS b/webkit/tools/pepper_test_plugin/DEPS new file mode 100644 index 0000000..03c7a2d --- /dev/null +++ b/webkit/tools/pepper_test_plugin/DEPS @@ -0,0 +1,3 @@ +include_rules = [ + "+gpu/command_buffer", +] diff --git a/webkit/tools/pepper_test_plugin/command_buffer_pepper.cc b/webkit/tools/pepper_test_plugin/command_buffer_pepper.cc new file mode 100644 index 0000000..d7fbf7a --- /dev/null +++ b/webkit/tools/pepper_test_plugin/command_buffer_pepper.cc @@ -0,0 +1,180 @@ +// 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 "webkit/tools/pepper_test_plugin/command_buffer_pepper.h" + +using base::SharedMemory; +using gpu::Buffer; + +CommandBufferPepper::CommandBufferPepper(NPP npp, NPNetscapeFuncs* browser) + : npp_(npp), + browser_(browser), + extensions_(NULL), + device_(NULL) { +} + +CommandBufferPepper::~CommandBufferPepper() { + if (device_) { + device_->destroyContext(npp_, &context_); + device_ = NULL; + } +} + +bool CommandBufferPepper::Initialize(int32 size) { + if (device_) + return false; + + // Get the pepper extensions. + browser_->getvalue(npp_, + NPNVPepperExtensions, + reinterpret_cast<void*>(&extensions_)); + CHECK(extensions_); + + // Acquire a 3D device. + device_ = extensions_->acquireDevice(npp_, NPPepper3DDevice); + if (device_) { + NPDeviceContext3DConfig config; + config.commandBufferEntries = size; + if (NPERR_NO_ERROR == device_->initializeContext(npp_, + &config, + &context_)) { + return true; + } + } + + return false; +} + +Buffer CommandBufferPepper::GetRingBuffer() { + Buffer buffer; + buffer.ptr = context_.commandBuffer; + buffer.size = context_.commandBufferEntries * sizeof(int32); + return buffer; +} + +int32 CommandBufferPepper::GetSize() { + return context_.commandBufferEntries; +} + +int32 CommandBufferPepper::SyncOffsets(int32 put_offset) { + context_.putOffset = put_offset; + if (NPERR_NO_ERROR != device_->flushContext(npp_, &context_, NULL, NULL)) + return -1; + + return context_.getOffset; +} + +int32 CommandBufferPepper::GetGetOffset() { + int32 value; + if (NPERR_NO_ERROR != device_->getStateContext( + npp_, + &context_, + NPDeviceContext3DState_GetOffset, + &value)) { + return -1; + } + + return value; +} + +void CommandBufferPepper::SetGetOffset(int32 get_offset) { + // Not implemented by proxy. + NOTREACHED(); +} + +int32 CommandBufferPepper::GetPutOffset() { + int32 value; + if (NPERR_NO_ERROR != device_->getStateContext( + npp_, + &context_, + NPDeviceContext3DState_PutOffset, + &value)) { + return -1; + } + + return value; +} + +void CommandBufferPepper::SetPutOffsetChangeCallback( + Callback0::Type* callback) { + // Not implemented by proxy. + NOTREACHED(); +} + +int32 CommandBufferPepper::CreateTransferBuffer(size_t size) { + int32 id; + if (NPERR_NO_ERROR != device_->createBuffer(npp_, &context_, size, &id)) + return -1; + + return id; +} + +void CommandBufferPepper::DestroyTransferBuffer(int32 id) { + device_->destroyBuffer(npp_, &context_, id); +} + +Buffer CommandBufferPepper::GetTransferBuffer(int32 id) { + NPDeviceBuffer np_buffer; + if (NPERR_NO_ERROR != device_->mapBuffer(npp_, &context_, id, &np_buffer)) + return Buffer(); + + Buffer buffer; + buffer.ptr = np_buffer.ptr; + buffer.size = np_buffer.size; + return buffer; +} + +int32 CommandBufferPepper::GetToken() { + int32 value; + if (NPERR_NO_ERROR != device_->getStateContext( + npp_, + &context_, + NPDeviceContext3DState_Token, + &value)) { + return -1; + } + + return value; +} + +void CommandBufferPepper::SetToken(int32 token) { + // Not implemented by proxy. + NOTREACHED(); +} + +int32 CommandBufferPepper::ResetParseError() { + int32 value; + if (NPERR_NO_ERROR != device_->getStateContext( + npp_, + &context_, + NPDeviceContext3DState_ParseError, + &value)) { + return -1; + } + + return value; +} + +void CommandBufferPepper::SetParseError(int32 parse_error) { + // Not implemented by proxy. + NOTREACHED(); +} + +bool CommandBufferPepper::GetErrorStatus() { + int32 value; + if (NPERR_NO_ERROR != device_->getStateContext( + npp_, + &context_, + NPDeviceContext3DState_ErrorStatus, + &value)) { + return value != 0; + } + + return true; +} + +void CommandBufferPepper::RaiseErrorStatus() { + // Not implemented by proxy. + NOTREACHED(); +} diff --git a/webkit/tools/pepper_test_plugin/command_buffer_pepper.h b/webkit/tools/pepper_test_plugin/command_buffer_pepper.h new file mode 100644 index 0000000..5fc2486 --- /dev/null +++ b/webkit/tools/pepper_test_plugin/command_buffer_pepper.h @@ -0,0 +1,52 @@ +// 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 WEBKIT_TOOLS_PEPPER_TEST_PLUGIN_COMMAND_BUFFER_PEPPER_H_ +#define WEBKIT_TOOLS_PEPPER_TEST_PLUGIN_COMMAND_BUFFER_PEPPER_H_ + +#include "gpu/command_buffer/common/command_buffer.h" +#include "third_party/npapi/bindings/npapi.h" +#include "third_party/npapi/bindings/npruntime.h" +#include "webkit/glue/plugins/nphostapi.h" + +// A CommandBuffer proxy implementation that uses the Pepper API to access +// the command buffer. +// TODO(apatrick): move this into a library that can be used by any pepper +// plugin. + +class CommandBufferPepper : public gpu::CommandBuffer { + public: + CommandBufferPepper(NPP npp, NPNetscapeFuncs* browser); + virtual ~CommandBufferPepper(); + + // CommandBuffer implementation. + virtual bool Initialize(int32 size); + virtual gpu::Buffer GetRingBuffer(); + virtual int32 GetSize(); + virtual int32 SyncOffsets(int32 put_offset); + virtual int32 GetGetOffset(); + virtual void SetGetOffset(int32 get_offset); + virtual int32 GetPutOffset(); + virtual void SetPutOffsetChangeCallback(Callback0::Type* callback); + virtual int32 CreateTransferBuffer(size_t size); + virtual void DestroyTransferBuffer(int32 id); + virtual gpu::Buffer GetTransferBuffer(int32 handle); + virtual int32 GetToken(); + virtual void SetToken(int32 token); + virtual int32 ResetParseError(); + virtual void SetParseError(int32 parse_error); + virtual bool GetErrorStatus(); + virtual void RaiseErrorStatus(); + + private: + NPP npp_; + NPNetscapeFuncs* browser_; + NPExtensions* extensions_; + NPDevice* device_; + NPDeviceContext3D context_; +}; + +#endif // WEBKIT_TOOLS_PEPPER_TEST_PLUGIN_COMMAND_BUFFER_PEPPER_H_ + + diff --git a/webkit/tools/pepper_test_plugin/main.cc b/webkit/tools/pepper_test_plugin/main.cc index 1b7da69..ef9a64b 100644 --- a/webkit/tools/pepper_test_plugin/main.cc +++ b/webkit/tools/pepper_test_plugin/main.cc @@ -171,6 +171,8 @@ NPError NPP_New(NPMIMEType pluginType, browser->createobject(instance, PluginObject::GetPluginClass())); instance->pdata = obj; event_handler = new EventHandler(instance); + + obj->New(pluginType, argc, argn, argv); } return NPERR_NO_ERROR; diff --git a/webkit/tools/pepper_test_plugin/pepper_test_plugin.gyp b/webkit/tools/pepper_test_plugin/pepper_test_plugin.gyp index 168fe53..aa3908a 100644 --- a/webkit/tools/pepper_test_plugin/pepper_test_plugin.gyp +++ b/webkit/tools/pepper_test_plugin/pepper_test_plugin.gyp @@ -16,6 +16,9 @@ ['OS=="win"', { 'product_name': 'pepper_test_plugin', 'msvs_guid': 'EE00E36E-9E8C-4DFB-925E-FBE32CEDB91A', + 'dependencies': [ + '../../../gpu/gpu.gyp:gles2_demo_lib', + ], 'sources': [ 'pepper_test_plugin.def', 'pepper_test_plugin.rc', @@ -23,6 +26,8 @@ }] ], 'sources': [ + 'command_buffer_pepper.cc', + 'command_buffer_pepper.h', 'main.cc', 'plugin_object.cc', 'plugin_object.h', @@ -32,11 +37,11 @@ 'event_handler.h' ], 'run_as': { - 'working_directory': '.', 'action': [ '<(PRODUCT_DIR)/<(EXECUTABLE_PREFIX)chrome<(EXECUTABLE_SUFFIX)', '--no-sandbox', '--internal-pepper', + '--enable-gpu-plugin', '--load-plugin=$(TargetPath)', 'file://$(ProjectDir)test_page.html', ], diff --git a/webkit/tools/pepper_test_plugin/plugin_object.cc b/webkit/tools/pepper_test_plugin/plugin_object.cc index d7eaa09..59212ac 100644 --- a/webkit/tools/pepper_test_plugin/plugin_object.cc +++ b/webkit/tools/pepper_test_plugin/plugin_object.cc @@ -29,6 +29,8 @@ #include <string> #include "base/logging.h" +#include "gpu/command_buffer/client/gles2_lib.h" +#include "gpu/command_buffer/client/gles2_demo_cc.h" #include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkCanvas.h" #include "third_party/skia/include/effects/SkGradientShader.h" @@ -247,13 +249,6 @@ PluginObject::PluginObject(NPP npp) : npp_(npp), test_object_(browser->createobject(npp, GetTestClass())), device2d_(NULL) { - if (!extensions) { - browser->getvalue(npp_, NPNVPepperExtensions, - reinterpret_cast<void*>(&extensions)); - CHECK(extensions); - } - device2d_ = extensions->acquireDevice(npp, NPPepper2DDevice); - CHECK(device2d_); } PluginObject::~PluginObject() { @@ -266,24 +261,105 @@ NPClass* PluginObject::GetPluginClass() { return &plugin_class; } +namespace { +void Draw3DCallback(void* data) { + static_cast<PluginObject*>(data)->Draw3D(); +} +} + +void PluginObject::New(NPMIMEType pluginType, + int16 argc, + char* argn[], + char* argv[]) { + // Default to 2D rendering. + dimensions_ = 2; + + for (int i = 0; i < argc; ++i) { + if (strcmp(argn[i], "dimensions") == 0) + dimensions_ = atoi(argv[i]); + } + + if (!extensions) { + browser->getvalue(npp_, NPNVPepperExtensions, + reinterpret_cast<void*>(&extensions)); + CHECK(extensions); + } + device2d_ = extensions->acquireDevice(npp_, NPPepper2DDevice); + CHECK(device2d_); +} + void PluginObject::SetWindow(const NPWindow& window) { - size_.set_width(window.width); - size_.set_height(window.height); + if (dimensions_ == 2) { + size_.set_width(window.width); + size_.set_height(window.height); + + NPDeviceContext2DConfig config; + NPDeviceContext2D context; + device2d_->initializeContext(npp_, &config, &context); + + SkBitmap bitmap; + bitmap.setConfig(SkBitmap::kARGB_8888_Config, window.width, window.height); + bitmap.setPixels(context.region); + + SkCanvas canvas(bitmap); + DrawSampleBitmap(canvas, window.width, window.height); + + // TODO(brettw) figure out why this cast is necessary, the functions seem to + // match. Could be a calling convention mismatch? + NPDeviceFlushContextCallbackPtr callback = + reinterpret_cast<NPDeviceFlushContextCallbackPtr>(&FlushCallback); + device2d_->flushContext(npp_, &context, callback, NULL); + } else { + if (!command_buffer_.get()) { + if (!InitializeCommandBuffer()) + return; + } + + gles2_implementation_->Viewport(0, 0, window.width, window.height); + + // Schedule the first call to Draw. + browser->pluginthreadasynccall(npp_, Draw3DCallback, this); + } +} + +void PluginObject::Draw3D() { + // Render some stuff. + gles2::g_gl_impl = gles2_implementation_.get(); + GLFromCPPTestFunction(); + gles2::GetGLContext()->SwapBuffers(); + helper_->Flush(); + gles2::g_gl_impl = NULL; + + // Schedule another call to Draw. + browser->pluginthreadasynccall(npp_, Draw3DCallback, this); +} - NPDeviceContext2DConfig config; - NPDeviceContext2D context; - device2d_->initializeContext(npp_, &config, &context); +bool PluginObject::InitializeCommandBuffer() { + const static int32 kCommandBufferSize = 512 * 1024; + command_buffer_.reset(new CommandBufferPepper(npp_, browser)); + if (command_buffer_->Initialize(kCommandBufferSize)) { + helper_.reset(new gpu::gles2::GLES2CmdHelper(command_buffer_.get())); + if (helper_->Initialize()) { + + const int32 kTransferBufferSize = 512 * 1024; + int32 transfer_buffer_id = + command_buffer_->CreateTransferBuffer(kTransferBufferSize); + gpu::Buffer transfer_buffer = + command_buffer_->GetTransferBuffer(transfer_buffer_id); + if (transfer_buffer.ptr) { + gles2_implementation_.reset(new gpu::gles2::GLES2Implementation( + helper_.get(), + transfer_buffer.size, + transfer_buffer.ptr, + transfer_buffer_id)); + return true; + } + } - SkBitmap bitmap; - bitmap.setConfig(SkBitmap::kARGB_8888_Config, window.width, window.height); - bitmap.setPixels(context.region); + helper_.reset(); + } - SkCanvas canvas(bitmap); - DrawSampleBitmap(canvas, window.width, window.height); + command_buffer_.reset(); - // TODO(brettw) figure out why this cast is necessary, the functions seem to - // match. Could be a calling convention mismatch? - NPDeviceFlushContextCallbackPtr callback = - reinterpret_cast<NPDeviceFlushContextCallbackPtr>(&FlushCallback); - device2d_->flushContext(npp_, &context, callback, NULL); + return false; } diff --git a/webkit/tools/pepper_test_plugin/plugin_object.h b/webkit/tools/pepper_test_plugin/plugin_object.h index 1dcbb80..4dcff15 100644 --- a/webkit/tools/pepper_test_plugin/plugin_object.h +++ b/webkit/tools/pepper_test_plugin/plugin_object.h @@ -28,13 +28,16 @@ #include "base/basictypes.h" #include "base/gfx/size.h" +#include "base/scoped_ptr.h" +#include "gpu/command_buffer/client/gles2_implementation.h" +#include "webkit/tools/pepper_test_plugin/command_buffer_pepper.h" #include "webkit/glue/plugins/nphostapi.h" extern NPNetscapeFuncs* browser; class PluginObject { public: - PluginObject(NPP npp); + explicit PluginObject(NPP npp); ~PluginObject(); static NPClass* GetPluginClass(); @@ -42,15 +45,26 @@ class PluginObject { NPObject* header() { return &header_; } NPP npp() const { return npp_; } + void New(NPMIMEType pluginType, int16 argc, char* argn[], char* argv[]); void SetWindow(const NPWindow& window); + void Draw3D(); private: + bool InitializeCommandBuffer(); + NPObject header_; NPP npp_; NPObject* test_object_; + int dimensions_; NPDevice* device2d_; + // TODO(apatrick): this destruction order causes the plugin to crash on + // shutdown. + scoped_ptr<CommandBufferPepper> command_buffer_; + scoped_ptr<gpu::gles2::GLES2Implementation> gles2_implementation_; + scoped_ptr<gpu::gles2::GLES2CmdHelper> helper_; + gfx::Size size_; DISALLOW_COPY_AND_ASSIGN(PluginObject); diff --git a/webkit/tools/pepper_test_plugin/test_page.html b/webkit/tools/pepper_test_plugin/test_page.html index c25dbd2..f9bf2b8 100644 --- a/webkit/tools/pepper_test_plugin/test_page.html +++ b/webkit/tools/pepper_test_plugin/test_page.html @@ -25,7 +25,7 @@ This page embeds a file declared as the pepper test plugins MIME type so that it <table> <tr> <td valign="top" width="50%"> -<object id="plugin" type="pepper-application/x-pepper-test-plugin" width="400" height="400" /> +<object id="plugin" type="pepper-application/x-pepper-test-plugin" width="400" height="400" dimensions="2" /> </td> <td valign="top" style="background-color:Silver" width="50%"> <div id="event_text_box" style="width:400px; height:400px; overflow:auto"> diff --git a/webkit/webkit.gyp b/webkit/webkit.gyp index adc6687..2d95286 100644 --- a/webkit/webkit.gyp +++ b/webkit/webkit.gyp @@ -452,6 +452,7 @@ ], 'dependencies': [ '../build/win/system.gyp:cygwin', + '../gpu/gpu.gyp:gpu_plugin', 'default_plugin/default_plugin.gyp:default_plugin', ], 'sources!': [ |