diff options
author | apatrick@chromium.org <apatrick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-14 21:50:00 +0000 |
---|---|---|
committer | apatrick@chromium.org <apatrick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-14 21:50:00 +0000 |
commit | a1de87d247f02b4ca61e609804d075b7fe0717cb (patch) | |
tree | 7c061457d8d2388c8f31d388b5c4eebef2978905 /webkit/tools/pepper_test_plugin | |
parent | e18f419b689ca8f560c1c02abb987ff25f2038b5 (diff) | |
download | chromium_src-a1de87d247f02b4ca61e609804d075b7fe0717cb.zip chromium_src-a1de87d247f02b4ca61e609804d075b7fe0717cb.tar.gz chromium_src-a1de87d247f02b4ca61e609804d075b7fe0717cb.tar.bz2 |
Revert 36268 - Implemented PGL library, an EGL like API for Pepper. Updated Pepper test plugin to use it.
TEST=none yet
BUG=none
Review URL: http://codereview.chromium.org/545052
TBR=alokp@chromium.org
Review URL: http://codereview.chromium.org/550048
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@36270 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/tools/pepper_test_plugin')
-rw-r--r-- | webkit/tools/pepper_test_plugin/DEPS | 1 | ||||
-rw-r--r-- | webkit/tools/pepper_test_plugin/command_buffer_pepper.cc | 175 | ||||
-rw-r--r-- | webkit/tools/pepper_test_plugin/command_buffer_pepper.h | 51 | ||||
-rw-r--r-- | webkit/tools/pepper_test_plugin/pepper_test_plugin.gyp | 3 | ||||
-rw-r--r-- | webkit/tools/pepper_test_plugin/plugin_object.cc | 66 | ||||
-rw-r--r-- | webkit/tools/pepper_test_plugin/plugin_object.h | 12 |
6 files changed, 276 insertions, 32 deletions
diff --git a/webkit/tools/pepper_test_plugin/DEPS b/webkit/tools/pepper_test_plugin/DEPS index fcae681..03c7a2d 100644 --- a/webkit/tools/pepper_test_plugin/DEPS +++ b/webkit/tools/pepper_test_plugin/DEPS @@ -1,4 +1,3 @@ include_rules = [ "+gpu/command_buffer", - "+gpu/pgl", ] 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..148d342 --- /dev/null +++ b/webkit/tools/pepper_test_plugin/command_buffer_pepper.cc @@ -0,0 +1,175 @@ +// 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" +#include "base/logging.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; +} + +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..017e4bc --- /dev/null +++ b/webkit/tools/pepper_test_plugin/command_buffer_pepper.h @@ -0,0 +1,51 @@ +// 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 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/pepper_test_plugin.gyp b/webkit/tools/pepper_test_plugin/pepper_test_plugin.gyp index b1c339e..7a8320a 100644 --- a/webkit/tools/pepper_test_plugin/pepper_test_plugin.gyp +++ b/webkit/tools/pepper_test_plugin/pepper_test_plugin.gyp @@ -8,7 +8,6 @@ { 'target_name': 'pepper_test_plugin', 'dependencies': [ - '../../../gpu/gpu.gyp:pgl', '../../../third_party/npapi/npapi.gyp:npapi', ], 'include_dirs': [ @@ -18,6 +17,8 @@ 'INFOPLIST_FILE': 'Info.plist', }, 'sources': [ + 'command_buffer_pepper.cc', + 'command_buffer_pepper.h', 'main.cc', 'plugin_object.cc', 'plugin_object.h', diff --git a/webkit/tools/pepper_test_plugin/plugin_object.cc b/webkit/tools/pepper_test_plugin/plugin_object.cc index 7f109ac..af199a7 100644 --- a/webkit/tools/pepper_test_plugin/plugin_object.cc +++ b/webkit/tools/pepper_test_plugin/plugin_object.cc @@ -34,8 +34,8 @@ #define CHECK(x) #else #include "base/logging.h" +#include "gpu/command_buffer/client/gles2_lib.h" #include "gpu/command_buffer/client/gles2_demo_cc.h" -#include "gpu/command_buffer/common/gles2/gl2.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" @@ -288,8 +288,6 @@ template <int F, typename T> void SineWaveCallback( context->config.userData = reinterpret_cast<void *>(t); } -const int32 kCommandBufferSize = 1024 * 1024; - } // namespace @@ -298,10 +296,7 @@ const int32 kCommandBufferSize = 1024 * 1024; PluginObject::PluginObject(NPP npp) : npp_(npp), test_object_(browser->createobject(npp, GetTestClass())), - device2d_(NULL), - device3d_(NULL), - deviceaudio_(NULL), - pgl_context_(NULL) { + device2d_(NULL) { memset(&context_audio_, 0, sizeof(context_audio_)); } @@ -342,9 +337,6 @@ void PluginObject::New(NPMIMEType pluginType, device2d_ = extensions->acquireDevice(npp_, NPPepper2DDevice); CHECK(device2d_); - device3d_ = extensions->acquireDevice(npp_, NPPepper3DDevice); - CHECK(device3d_); - deviceaudio_ = extensions->acquireDevice(npp_, NPPepperAudioDevice); CHECK(deviceaudio_); } @@ -367,20 +359,12 @@ void PluginObject::SetWindow(const NPWindow& window) { device2d_->flushContext(npp_, &context, callback, NULL); } else { #if !defined(INDEPENDENT_PLUGIN) - if (!pgl_context_) { - // Initialize a 3D context. - NPDeviceContext3DConfig config; - config.commandBufferEntries = kCommandBufferSize; - device3d_->initializeContext(npp_, &config, &context3d_); - - // Create a PGL context. - pgl_context_ = pglCreateContext(npp_, device3d_, &context3d_); + if (!command_buffer_.get()) { + if (!InitializeCommandBuffer()) + return; } - // Reset the viewport to new window size. - pglMakeCurrent(pgl_context_); - glViewport(0, 0, window.width, window.height); - pglMakeCurrent(NULL); + gles2_implementation_->Viewport(0, 0, window.width, window.height); // Schedule the first call to Draw. browser->pluginthreadasynccall(npp_, Draw3DCallback, this); @@ -404,12 +388,44 @@ void PluginObject::SetWindow(const NPWindow& window) { void PluginObject::Draw3D() { #if !defined(INDEPENDENT_PLUGIN) // Render some stuff. - pglMakeCurrent(pgl_context_); + gles2::g_gl_impl = gles2_implementation_.get(); GLFromCPPTestFunction(); - pglSwapBuffers(); - pglMakeCurrent(NULL); + gles2::GetGLContext()->SwapBuffers(); + helper_->Flush(); + gles2::g_gl_impl = NULL; // Schedule another call to Draw. browser->pluginthreadasynccall(npp_, Draw3DCallback, this); #endif } + +bool PluginObject::InitializeCommandBuffer() { +#if !defined(INDEPENDENT_PLUGIN) + static const 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; + } + } + + helper_.reset(); + } + + command_buffer_.reset(); +#endif + + return false; +} diff --git a/webkit/tools/pepper_test_plugin/plugin_object.h b/webkit/tools/pepper_test_plugin/plugin_object.h index 0da3722b..0850f54 100644 --- a/webkit/tools/pepper_test_plugin/plugin_object.h +++ b/webkit/tools/pepper_test_plugin/plugin_object.h @@ -30,7 +30,8 @@ #include "base/scoped_ptr.h" #include "webkit/glue/plugins/nphostapi.h" #if !defined(INDEPENDENT_PLUGIN) -#include "gpu/pgl/pgl.h" +#include "gpu/command_buffer/client/gles2_implementation.h" +#include "webkit/tools/pepper_test_plugin/command_buffer_pepper.h" #endif extern NPNetscapeFuncs* browser; @@ -50,21 +51,22 @@ class PluginObject { void Draw3D(); private: + bool InitializeCommandBuffer(); + NPObject header_; NPP npp_; NPObject* test_object_; int dimensions_; NPDevice* device2d_; - NPDevice* device3d_; NPDevice* deviceaudio_; - NPDeviceContext3D context3d_; NPDeviceContextAudio context_audio_; - #if !defined(INDEPENDENT_PLUGIN) - PGLContext pgl_context_; + scoped_ptr<CommandBufferPepper> command_buffer_; + scoped_ptr<gpu::gles2::GLES2CmdHelper> helper_; + scoped_ptr<gpu::gles2::GLES2Implementation> gles2_implementation_; #endif int width_; |