diff options
author | apatrick@chromium.org <apatrick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-15 00:53:02 +0000 |
---|---|---|
committer | apatrick@chromium.org <apatrick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-15 00:53:02 +0000 |
commit | bc36e991df2bbf3f572a1444d7b56000453de6eb (patch) | |
tree | 06b03a4039a769780b6f0f0cdf59765cd8965645 | |
parent | 71eed7550a96fe126ebacace48315ce16bcdf31c (diff) | |
download | chromium_src-bc36e991df2bbf3f572a1444d7b56000453de6eb.zip chromium_src-bc36e991df2bbf3f572a1444d7b56000453de6eb.tar.gz chromium_src-bc36e991df2bbf3f572a1444d7b56000453de6eb.tar.bz2 |
Resubmitting r36268 with a fix for mac:
Implemented PGL library, an EGL like API for Pepper. Updated Pepper test plugin to use it.
TEST=trybots
BUG=none
Review URL: http://codereview.chromium.org/552007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@36318 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | gpu/gpu.gyp | 24 | ||||
-rw-r--r-- | gpu/pgl/command_buffer_pepper.cc (renamed from webkit/tools/pepper_test_plugin/command_buffer_pepper.cc) | 68 | ||||
-rw-r--r-- | gpu/pgl/command_buffer_pepper.h (renamed from webkit/tools/pepper_test_plugin/command_buffer_pepper.h) | 18 | ||||
-rw-r--r-- | gpu/pgl/pgl.cc | 161 | ||||
-rw-r--r-- | gpu/pgl/pgl.h | 23 | ||||
-rw-r--r-- | webkit/tools/pepper_test_plugin/DEPS | 1 | ||||
-rw-r--r-- | webkit/tools/pepper_test_plugin/pepper_test_plugin.gyp | 3 | ||||
-rw-r--r-- | webkit/tools/pepper_test_plugin/plugin_object.cc | 68 | ||||
-rw-r--r-- | webkit/tools/pepper_test_plugin/plugin_object.h | 17 |
9 files changed, 276 insertions, 107 deletions
diff --git a/gpu/gpu.gyp b/gpu/gpu.gyp index 8a51c05..3185f5b 100644 --- a/gpu/gpu.gyp +++ b/gpu/gpu.gyp @@ -361,6 +361,30 @@ 'command_buffer/client/gles2_demo_cc.cc', ], }, + { + 'target_name': 'pgl', + 'type': 'static_library', + 'dependencies': [ + 'command_buffer_client', + 'gles2_c_lib', + '../third_party/npapi/npapi.gyp:npapi', + ], + 'include_dirs': [ + '..', + '../third_party/npapi/bindings', + ], + 'all_dependent_settings': { + 'include_dirs': [ + '../third_party/npapi/bindings', + ], + }, + 'sources': [ + 'pgl/command_buffer_pepper.cc', + 'pgl/command_buffer_pepper.h', + 'pgl/pgl.cc', + 'pgl/pgl.h', + ], + }, ], 'conditions': [ ['OS == "win"', diff --git a/webkit/tools/pepper_test_plugin/command_buffer_pepper.cc b/gpu/pgl/command_buffer_pepper.cc index 148d342..3ee5406 100644 --- a/webkit/tools/pepper_test_plugin/command_buffer_pepper.cc +++ b/gpu/pgl/command_buffer_pepper.cc @@ -1,76 +1,54 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// 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 "webkit/tools/pepper_test_plugin/command_buffer_pepper.h" +#include "gpu/pgl/command_buffer_pepper.h" #include "base/logging.h" using base::SharedMemory; using gpu::Buffer; -CommandBufferPepper::CommandBufferPepper(NPP npp, NPNetscapeFuncs* browser) +CommandBufferPepper::CommandBufferPepper(NPP npp, + NPDevice* device, + NPDeviceContext3D* context) : npp_(npp), - browser_(browser), - extensions_(NULL), - device_(NULL) { + device_(device), + context_(context) { } CommandBufferPepper::~CommandBufferPepper() { - if (device_) { - device_->destroyContext(npp_, &context_); - device_ = NULL; - } } +// Not implemented in CommandBufferPepper. 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; - } - } - + NOTREACHED(); return false; } Buffer CommandBufferPepper::GetRingBuffer() { Buffer buffer; - buffer.ptr = context_.commandBuffer; - buffer.size = context_.commandBufferEntries * sizeof(int32); + buffer.ptr = context_->commandBuffer; + buffer.size = context_->commandBufferEntries * sizeof(int32); return buffer; } int32 CommandBufferPepper::GetSize() { - return context_.commandBufferEntries; + return context_->commandBufferEntries; } int32 CommandBufferPepper::SyncOffsets(int32 put_offset) { - context_.putOffset = put_offset; - if (NPERR_NO_ERROR != device_->flushContext(npp_, &context_, NULL, NULL)) + context_->putOffset = put_offset; + if (NPERR_NO_ERROR != device_->flushContext(npp_, context_, NULL, NULL)) return -1; - return context_.getOffset; + return context_->getOffset; } int32 CommandBufferPepper::GetGetOffset() { int32 value; if (NPERR_NO_ERROR != device_->getStateContext( npp_, - &context_, + context_, NPDeviceContext3DState_GetOffset, &value)) { return -1; @@ -88,7 +66,7 @@ int32 CommandBufferPepper::GetPutOffset() { int32 value; if (NPERR_NO_ERROR != device_->getStateContext( npp_, - &context_, + context_, NPDeviceContext3DState_PutOffset, &value)) { return -1; @@ -99,19 +77,19 @@ int32 CommandBufferPepper::GetPutOffset() { int32 CommandBufferPepper::CreateTransferBuffer(size_t size) { int32 id; - if (NPERR_NO_ERROR != device_->createBuffer(npp_, &context_, size, &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); + device_->destroyBuffer(npp_, context_, id); } Buffer CommandBufferPepper::GetTransferBuffer(int32 id) { NPDeviceBuffer np_buffer; - if (NPERR_NO_ERROR != device_->mapBuffer(npp_, &context_, id, &np_buffer)) + if (NPERR_NO_ERROR != device_->mapBuffer(npp_, context_, id, &np_buffer)) return Buffer(); Buffer buffer; @@ -124,7 +102,7 @@ int32 CommandBufferPepper::GetToken() { int32 value; if (NPERR_NO_ERROR != device_->getStateContext( npp_, - &context_, + context_, NPDeviceContext3DState_Token, &value)) { return -1; @@ -142,7 +120,7 @@ int32 CommandBufferPepper::ResetParseError() { int32 value; if (NPERR_NO_ERROR != device_->getStateContext( npp_, - &context_, + context_, NPDeviceContext3DState_ParseError, &value)) { return -1; @@ -160,7 +138,7 @@ bool CommandBufferPepper::GetErrorStatus() { int32 value; if (NPERR_NO_ERROR != device_->getStateContext( npp_, - &context_, + context_, NPDeviceContext3DState_ErrorStatus, &value)) { return value != 0; diff --git a/webkit/tools/pepper_test_plugin/command_buffer_pepper.h b/gpu/pgl/command_buffer_pepper.h index 017e4bc..ab114e3 100644 --- a/webkit/tools/pepper_test_plugin/command_buffer_pepper.h +++ b/gpu/pgl/command_buffer_pepper.h @@ -1,9 +1,9 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// 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. -#ifndef WEBKIT_TOOLS_PEPPER_TEST_PLUGIN_COMMAND_BUFFER_PEPPER_H_ -#define WEBKIT_TOOLS_PEPPER_TEST_PLUGIN_COMMAND_BUFFER_PEPPER_H_ +#ifndef GPU_PGL_COMMAND_BUFFER_PEPPER_H +#define GPU_PGL_COMMAND_BUFFER_PEPPER_H #include "gpu/command_buffer/common/command_buffer.h" #include "third_party/npapi/bindings/npapi.h" @@ -12,12 +12,12 @@ // 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); + CommandBufferPepper(NPP npp, + NPDevice* device, + NPDeviceContext3D* device_context); virtual ~CommandBufferPepper(); // CommandBuffer implementation. @@ -40,12 +40,10 @@ class CommandBufferPepper : public gpu::CommandBuffer { private: NPP npp_; - NPNetscapeFuncs* browser_; - NPExtensions* extensions_; NPDevice* device_; - NPDeviceContext3D context_; + NPDeviceContext3D* context_; }; -#endif // WEBKIT_TOOLS_PEPPER_TEST_PLUGIN_COMMAND_BUFFER_PEPPER_H_ +#endif // GPU_PGL_COMMAND_BUFFER_PEPPER_H diff --git a/gpu/pgl/pgl.cc b/gpu/pgl/pgl.cc new file mode 100644 index 0000000..320dfff --- /dev/null +++ b/gpu/pgl/pgl.cc @@ -0,0 +1,161 @@ +// 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 "gpu/command_buffer/client/gles2_cmd_helper.h" +#include "gpu/command_buffer/client/gles2_implementation.h" +#include "gpu/command_buffer/client/gles2_lib.h" +#include "gpu/pgl/command_buffer_pepper.h" +#include "gpu/pgl/pgl.h" + +#if defined(_MSC_VER) +#define THREAD_LOCAL __declspec(thread) +#else +#define THREAD_LOCAL __thread +#endif + +namespace { +const int32 kTransferBufferSize = 512 * 1024; + +class PGLContextImpl { + public: + PGLContextImpl(NPP npp, + NPDevice* device, + NPDeviceContext3D* device_context); + ~PGLContextImpl(); + + // Initlaize a PGL context with a transfer buffer of a particular size. + bool Initialize(int32 transfer_buffer_size); + + // Destroy all resources associated with the PGL context. + void Destroy(); + + // Make a PGL context current for the calling thread. + static bool MakeCurrent(PGLContextImpl* pgl_context); + + // Display all content rendered since last call to SwapBuffers. + bool SwapBuffers(); + + private: + PGLContextImpl(const PGLContextImpl&); + void operator=(const PGLContextImpl&); + + NPP npp_; + NPDevice* device_; + NPDeviceContext3D* device_context_; + CommandBufferPepper* command_buffer_; + gpu::gles2::GLES2CmdHelper* gles2_helper_; + int32 transfer_buffer_id_; + gpu::gles2::GLES2Implementation* gles2_implementation_; +}; + +THREAD_LOCAL PGLContextImpl* g_current_pgl_context; + +PGLContextImpl::PGLContextImpl(NPP npp, + NPDevice* device, + NPDeviceContext3D* device_context) + : npp_(npp), + device_(device), + device_context_(device_context), + command_buffer_(NULL), + gles2_helper_(NULL), + transfer_buffer_id_(0), + gles2_implementation_(NULL) { +} + +PGLContextImpl::~PGLContextImpl() { + Destroy(); +} + +bool PGLContextImpl::Initialize(int32 transfer_buffer_size) { + // Create and initialize the objects required to issue GLES2 calls. + command_buffer_ = new CommandBufferPepper( + npp_, device_, device_context_); + gles2_helper_ = new gpu::gles2::GLES2CmdHelper(command_buffer_); + if (gles2_helper_->Initialize()) { + transfer_buffer_id_ = + command_buffer_->CreateTransferBuffer(kTransferBufferSize); + gpu::Buffer transfer_buffer = + command_buffer_->GetTransferBuffer(transfer_buffer_id_); + if (transfer_buffer.ptr) { + gles2_implementation_ = new gpu::gles2::GLES2Implementation( + gles2_helper_, + transfer_buffer.size, + transfer_buffer.ptr, + transfer_buffer_id_); + return true; + } + } + + // Tear everything down if initialization failed. + Destroy(); + return false; +} + +void PGLContextImpl::Destroy() { + delete gles2_implementation_; + gles2_implementation_ = NULL; + + if (command_buffer_ && transfer_buffer_id_ != 0) { + command_buffer_->DestroyTransferBuffer(transfer_buffer_id_); + transfer_buffer_id_ = 0; + } + + delete gles2_helper_; + gles2_helper_ = NULL; + + delete command_buffer_; + command_buffer_ = NULL; +} + +bool PGLContextImpl::MakeCurrent(PGLContextImpl* pgl_context) { + g_current_pgl_context = pgl_context; + if (pgl_context) + gles2::g_gl_impl = pgl_context->gles2_implementation_; + else + gles2::g_gl_impl = NULL; + + return true; +} + +bool PGLContextImpl::SwapBuffers() { + gles2_implementation_->SwapBuffers(); + return true; +} +} // namespace anonymous + +extern "C" { + +PGLContext pglCreateContext(NPP npp, + NPDevice* device, + NPDeviceContext3D* device_context) { + PGLContextImpl* pgl_context = new PGLContextImpl( + npp, device, device_context); + if (pgl_context->Initialize(kTransferBufferSize)) { + return pgl_context; + } + + delete pgl_context; + return NULL; +} + +PGLBoolean pglMakeCurrent(PGLContext pgl_context) { + return PGLContextImpl::MakeCurrent(static_cast<PGLContextImpl*>(pgl_context)); +} + +PGLBoolean pglSwapBuffers() { + if (!g_current_pgl_context) + return false; + + return g_current_pgl_context->SwapBuffers(); +} + +PGLBoolean pglDestroyContext(PGLContext pgl_context) { + if (!pgl_context) + return false; + + delete pgl_context; + return true; +} + +} // extern "C" diff --git a/gpu/pgl/pgl.h b/gpu/pgl/pgl.h new file mode 100644 index 0000000..6914aae --- /dev/null +++ b/gpu/pgl/pgl.h @@ -0,0 +1,23 @@ +// 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. + +#ifndef GPU_PGL_PGL_H +#define GPU_PGL_PGL_H + +#include "npapi.h" +#include "npapi_extensions.h" + +extern "C" { +typedef void* PGLContext; +typedef bool PGLBoolean; + +PGLContext pglCreateContext(NPP npp, + NPDevice* device, + NPDeviceContext3D* device_context); +PGLBoolean pglMakeCurrent(PGLContext pgl_context); +PGLBoolean pglSwapBuffers(); +PGLBoolean pglDestroyContext(PGLContext pgl_context); +} // extern "C" + +#endif // GPU_PGL_PGL_H diff --git a/webkit/tools/pepper_test_plugin/DEPS b/webkit/tools/pepper_test_plugin/DEPS index 03c7a2d..fcae681 100644 --- a/webkit/tools/pepper_test_plugin/DEPS +++ b/webkit/tools/pepper_test_plugin/DEPS @@ -1,3 +1,4 @@ include_rules = [ "+gpu/command_buffer", + "+gpu/pgl", ] diff --git a/webkit/tools/pepper_test_plugin/pepper_test_plugin.gyp b/webkit/tools/pepper_test_plugin/pepper_test_plugin.gyp index 7a8320a..1cdc8d3 100644 --- a/webkit/tools/pepper_test_plugin/pepper_test_plugin.gyp +++ b/webkit/tools/pepper_test_plugin/pepper_test_plugin.gyp @@ -17,8 +17,6 @@ 'INFOPLIST_FILE': 'Info.plist', }, 'sources': [ - 'command_buffer_pepper.cc', - 'command_buffer_pepper.h', 'main.cc', 'plugin_object.cc', 'plugin_object.h', @@ -34,6 +32,7 @@ 'msvs_guid': 'EE00E36E-9E8C-4DFB-925E-FBE32CEDB91A', 'dependencies': [ '../../../gpu/gpu.gyp:gles2_demo_lib', + '../../../gpu/gpu.gyp:pgl', ], 'sources': [ 'pepper_test_plugin.def', diff --git a/webkit/tools/pepper_test_plugin/plugin_object.cc b/webkit/tools/pepper_test_plugin/plugin_object.cc index af199a7..aa6422d 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,6 +288,8 @@ template <int F, typename T> void SineWaveCallback( context->config.userData = reinterpret_cast<void *>(t); } +const int32 kCommandBufferSize = 1024 * 1024; + } // namespace @@ -296,7 +298,12 @@ template <int F, typename T> void SineWaveCallback( PluginObject::PluginObject(NPP npp) : npp_(npp), test_object_(browser->createobject(npp, GetTestClass())), - device2d_(NULL) { + device2d_(NULL), + device3d_(NULL), +#if !defined(INDEPENDENT_PLUGIN) + pgl_context_(NULL), +#endif + deviceaudio_(NULL) { memset(&context_audio_, 0, sizeof(context_audio_)); } @@ -337,6 +344,9 @@ 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_); } @@ -359,12 +369,20 @@ void PluginObject::SetWindow(const NPWindow& window) { device2d_->flushContext(npp_, &context, callback, NULL); } else { #if !defined(INDEPENDENT_PLUGIN) - if (!command_buffer_.get()) { - if (!InitializeCommandBuffer()) - return; + 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_); } - gles2_implementation_->Viewport(0, 0, window.width, window.height); + // Reset the viewport to new window size. + pglMakeCurrent(pgl_context_); + glViewport(0, 0, window.width, window.height); + pglMakeCurrent(NULL); // Schedule the first call to Draw. browser->pluginthreadasynccall(npp_, Draw3DCallback, this); @@ -388,44 +406,12 @@ void PluginObject::SetWindow(const NPWindow& window) { void PluginObject::Draw3D() { #if !defined(INDEPENDENT_PLUGIN) // Render some stuff. - gles2::g_gl_impl = gles2_implementation_.get(); + pglMakeCurrent(pgl_context_); GLFromCPPTestFunction(); - gles2::GetGLContext()->SwapBuffers(); - helper_->Flush(); - gles2::g_gl_impl = NULL; + pglSwapBuffers(); + pglMakeCurrent(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 0850f54..1d9970d 100644 --- a/webkit/tools/pepper_test_plugin/plugin_object.h +++ b/webkit/tools/pepper_test_plugin/plugin_object.h @@ -30,8 +30,7 @@ #include "base/scoped_ptr.h" #include "webkit/glue/plugins/nphostapi.h" #if !defined(INDEPENDENT_PLUGIN) -#include "gpu/command_buffer/client/gles2_implementation.h" -#include "webkit/tools/pepper_test_plugin/command_buffer_pepper.h" +#include "gpu/pgl/pgl.h" #endif extern NPNetscapeFuncs* browser; @@ -51,23 +50,23 @@ class PluginObject { void Draw3D(); private: - bool InitializeCommandBuffer(); - NPObject header_; NPP npp_; NPObject* test_object_; int dimensions_; NPDevice* device2d_; + NPDevice* device3d_; + +#if !defined(INDEPENDENT_PLUGIN) + PGLContext pgl_context_; +#endif + NPDevice* deviceaudio_; + NPDeviceContext3D context3d_; NPDeviceContextAudio context_audio_; -#if !defined(INDEPENDENT_PLUGIN) - scoped_ptr<CommandBufferPepper> command_buffer_; - scoped_ptr<gpu::gles2::GLES2CmdHelper> helper_; - scoped_ptr<gpu::gles2::GLES2Implementation> gles2_implementation_; -#endif int width_; int height_; |