diff options
author | alokp@chromium.org <alokp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-26 18:54:29 +0000 |
---|---|---|
committer | alokp@chromium.org <alokp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-26 18:54:29 +0000 |
commit | d20dd3d2b4e62d45b1ecae10d4e9cf743d6b21ed (patch) | |
tree | ccfc2ebf64ff833a0a0966e4c13d0f4351cd3637 /webkit/tools/pepper_test_plugin | |
parent | 225e07f9674952435e87682addb09f3d7c82d457 (diff) | |
download | chromium_src-d20dd3d2b4e62d45b1ecae10d4e9cf743d6b21ed.zip chromium_src-d20dd3d2b4e62d45b1ecae10d4e9cf743d6b21ed.tar.gz chromium_src-d20dd3d2b4e62d45b1ecae10d4e9cf743d6b21ed.tar.bz2 |
Added a test for pepper3d. It ensures that we can successfully load a pepper 3d plugin and render.
Review URL: http://codereview.chromium.org/1073003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@42793 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/tools/pepper_test_plugin')
-rw-r--r-- | webkit/tools/pepper_test_plugin/pepper_3d_test.cc | 198 | ||||
-rw-r--r-- | webkit/tools/pepper_test_plugin/pepper_3d_test.h | 56 | ||||
-rw-r--r-- | webkit/tools/pepper_test_plugin/pepper_test_factory.cc | 23 | ||||
-rw-r--r-- | webkit/tools/pepper_test_plugin/pepper_test_plugin.cc | 25 |
4 files changed, 302 insertions, 0 deletions
diff --git a/webkit/tools/pepper_test_plugin/pepper_3d_test.cc b/webkit/tools/pepper_test_plugin/pepper_3d_test.cc new file mode 100644 index 0000000..60d57f9 --- /dev/null +++ b/webkit/tools/pepper_test_plugin/pepper_3d_test.cc @@ -0,0 +1,198 @@ +// 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/pepper_3d_test.h" + +namespace { +const int32 kCommandBufferSize = 1024 * 1024; +} // namespace + +namespace NPAPIClient { + +Pepper3DTest::Pepper3DTest(NPP id, NPNetscapeFuncs *host_functions) + : PluginTest(id, host_functions), + pepper_extensions_(NULL), + device_3d_(NULL), + pgl_context_(PGL_NO_CONTEXT) { + memset(&context_3d_, 0, sizeof(context_3d_)); + + esInitContext(&es_context_); + memset(&es_data_, 0, sizeof(es_data_)); + es_context_.userData = &es_data_; +} + +Pepper3DTest::~Pepper3DTest() { +} + +NPError Pepper3DTest::New(uint16 mode, int16 argc, const char* argn[], + const char* argv[], NPSavedData* saved) { + return PluginTest::New(mode, argc, argn, argv, saved); +} + +NPError Pepper3DTest::Destroy() { + DestroyContext(); + pglTerminate(); + return NPERR_NO_ERROR; +} + +NPError Pepper3DTest::SetWindow(NPWindow* window) { + // Create context if needed. + CreateContext(); + + es_context_.width = window->width; + es_context_.height = window->height; + + return NPERR_NO_ERROR; +} + +void Pepper3DTest::RepaintCallback(NPP npp, NPDeviceContext3D* /* context */) { + Pepper3DTest* plugin = static_cast<Pepper3DTest*>(npp->pdata); + plugin->Paint(); +} + +void Pepper3DTest::CreateContext() { + if (pgl_context_ != PGL_NO_CONTEXT) + return; + + HostFunctions()->getvalue(id(), NPNVPepperExtensions, &pepper_extensions_); + if (pepper_extensions_ == NULL) { + SetError("Could not acquire pepper extensions"); + SignalTestCompleted(); + return; + } + + device_3d_ = pepper_extensions_->acquireDevice(id(), NPPepper3DDevice); + if (device_3d_ == NULL) { + SetError("Could not acquire 3D device"); + SignalTestCompleted(); + return; + } + + // Initialize a 3D context. + NPDeviceContext3DConfig config; + config.commandBufferSize = kCommandBufferSize; + if (device_3d_->initializeContext(id(), &config, &context_3d_) + != NPERR_NO_ERROR) { + SetError("Could not initialize 3D context"); + SignalTestCompleted(); + return; + } + context_3d_.repaintCallback = RepaintCallback; + + // Initialize PGL and create a PGL context. + if (!pglInitialize()) { + SetError("Could not initialize PGL"); + SignalTestCompleted(); + return; + } + pgl_context_ = pglCreateContext(id(), device_3d_, &context_3d_); + if (pgl_context_ == PGL_NO_CONTEXT) { + SetError("Could not initialize PGL context"); + SignalTestCompleted(); + return; + } + + // Initialize OpenGL. + MakeContextCurrent(); + InitGL(); + pglMakeCurrent(PGL_NO_CONTEXT); +} + +void Pepper3DTest::DestroyContext() { + if (pgl_context_ == PGL_NO_CONTEXT) + return; + + MakeContextCurrent(); + ReleaseGL(); + if (!pglDestroyContext(pgl_context_)) { + SetError("Could not destroy PGL context"); + } + pgl_context_ = PGL_NO_CONTEXT; + + if (device_3d_->destroyContext(id(), &context_3d_) != NPERR_NO_ERROR) { + SetError("Could not destroy 3D context"); + } +} + +void Pepper3DTest::MakeContextCurrent() { + DCHECK(pgl_context_ != PGL_NO_CONTEXT); + + if (!pglMakeCurrent(pgl_context_)) { + SetError("Could not make PGL context current"); + } +} + +void Pepper3DTest::Paint() { + MakeContextCurrent(); + DrawGL(); + TestGL(); + SwapBuffers(); + pglMakeCurrent(PGL_NO_CONTEXT); + + // Painting once is enough to check correctness. + SignalTestCompleted(); +} + +void Pepper3DTest::SwapBuffers() { + if (!pglSwapBuffers()) { + SetError("Could not swap buffers"); + } +} + +void Pepper3DTest::InitGL() { + if (!stInit(&es_context_)) { + SetError("Could not initialize OpenGL resources"); + } +} + +void Pepper3DTest::ReleaseGL() { + stShutDown(&es_context_); +} + +void Pepper3DTest::DrawGL() { + stDraw(&es_context_); +} + +void Pepper3DTest::TestGL() { + // NW quadrant is red. + GLint x = es_context_.width / 4; + GLint y = (3 * es_context_.height) / 4; + GLubyte red_color[3] = {255, 0, 0}; + TestPixel(x, y, red_color); + + // NE quadrant is green. + x = (3 * es_context_.width) / 4; + y = (3 * es_context_.height) / 4; + GLubyte green_color[3] = {0, 255, 0}; + TestPixel(x, y, green_color); + + // SW quadrant is blue. + x = es_context_.width / 4; + y = es_context_.height / 4; + GLubyte blue_color[3] = {0, 0, 255}; + TestPixel(x, y, blue_color); + + // SE quadrant is yellow. + x = (3 * es_context_.width) / 4; + y = es_context_.height / 4; + GLubyte yellow_color[3] = {255, 255, 0}; + TestPixel(x, y, yellow_color); + + // Mid-point is black. + x = es_context_.width / 2; + y = es_context_.height / 2; + GLubyte black_color[3] = {0, 0, 0}; + TestPixel(x, y, black_color); +} + +void Pepper3DTest::TestPixel(int x, int y, const GLubyte expected_color[3]) { + GLubyte pixel_color[4]; + glReadPixels(x, y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel_color); + + ExpectIntegerEqual(pixel_color[0], expected_color[0]); + ExpectIntegerEqual(pixel_color[1], expected_color[1]); + ExpectIntegerEqual(pixel_color[2], expected_color[2]); +} + +} // namespace NPAPIClient diff --git a/webkit/tools/pepper_test_plugin/pepper_3d_test.h b/webkit/tools/pepper_test_plugin/pepper_3d_test.h new file mode 100644 index 0000000..f9801d7 --- /dev/null +++ b/webkit/tools/pepper_test_plugin/pepper_3d_test.h @@ -0,0 +1,56 @@ +// 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_GLUE_PLUGINS_TEST_PLUGIN_PEPPER_3D_TEST_H +#define WEBKIT_GLUE_PLUGINS_TEST_PLUGIN_PEPPER_3D_TEST_H + +#include "gpu/pgl/pgl.h" +#include "third_party/gles2_book/Chapter_11/Stencil_Test/Stencil_Test.h" +#include "webkit/glue/plugins/test/plugin_test.h" + +namespace NPAPIClient { + +// This class contains a list of windowed plugin tests. Please add additional +// tests to this class. +class Pepper3DTest : public PluginTest { + public: + Pepper3DTest(NPP id, NPNetscapeFuncs *host_functions); + ~Pepper3DTest(); + + // Pepper tests run in windowless plugin mode. + virtual bool IsWindowless() const { return true; } + + // NPAPI functions. + virtual NPError New(uint16 mode, int16 argc, const char* argn[], + const char* argv[], NPSavedData* saved); + virtual NPError Destroy(); + virtual NPError SetWindow(NPWindow* window); + + private: + static void RepaintCallback(NPP, NPDeviceContext3D*); + + void CreateContext(); + void DestroyContext(); + void MakeContextCurrent(); + void Paint(); + void SwapBuffers(); + + void InitGL(); + void ReleaseGL(); + void DrawGL(); + void TestGL(); + void TestPixel(int x, int y, const GLubyte expected_color[3]); + + NPExtensions* pepper_extensions_; + NPDevice* device_3d_; + NPDeviceContext3D context_3d_; + PGLContext pgl_context_; + + ESContext es_context_; + STUserData es_data_; +}; + +} // namespace NPAPIClient + +#endif // WEBKIT_GLUE_PLUGINS_TEST_PLUGIN_PEPPER_3D_TEST_H diff --git a/webkit/tools/pepper_test_plugin/pepper_test_factory.cc b/webkit/tools/pepper_test_plugin/pepper_test_factory.cc new file mode 100644 index 0000000..1e22d0b --- /dev/null +++ b/webkit/tools/pepper_test_plugin/pepper_test_factory.cc @@ -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. + +#include "webkit/glue/plugins/test/plugin_test_factory.h" + +#include "webkit/tools/pepper_test_plugin/pepper_3d_test.h" + +namespace NPAPIClient { + +PluginTest* CreatePluginTest(const std::string& test_name, + NPP instance, + NPNetscapeFuncs* host_functions) { + PluginTest* new_test = NULL; + + if (test_name == "pepper_3d") { + new_test = new Pepper3DTest(instance, host_functions); + } + + return new_test; +} + +} // namespace NPAPIClient diff --git a/webkit/tools/pepper_test_plugin/pepper_test_plugin.cc b/webkit/tools/pepper_test_plugin/pepper_test_plugin.cc new file mode 100644 index 0000000..4560a79 --- /dev/null +++ b/webkit/tools/pepper_test_plugin/pepper_test_plugin.cc @@ -0,0 +1,25 @@ +// 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. + +#if defined(__GNUC__) && __GNUC__ >= 4 +#define EXPORT __attribute__((visibility ("default"))) +#else +#define EXPORT +#endif + +#include "webkit/glue/plugins/test/plugin_client.h" + +extern "C" { +EXPORT NPError API_CALL NP_GetEntryPoints(NPPluginFuncs* pFuncs) { + return NPAPIClient::PluginClient::GetEntryPoints(pFuncs); +} + +EXPORT NPError API_CALL NP_Initialize(NPNetscapeFuncs* pFuncs) { + return NPAPIClient::PluginClient::Initialize(pFuncs); +} + +EXPORT NPError API_CALL NP_Shutdown() { + return NPAPIClient::PluginClient::Shutdown(); +} +} // extern "C" |