diff options
author | apatrick@google.com <apatrick@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-20 20:46:44 +0000 |
---|---|---|
committer | apatrick@google.com <apatrick@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-20 20:46:44 +0000 |
commit | e80a54bfd7997d02d1995ddfb96f2e55ec2fc771 (patch) | |
tree | e95c06b549f23f64194c89dee96c34f86f2c67cf /o3d/gpu_plugin | |
parent | 4a0c3e6196e8fe61bf06338429662301f45b8f97 (diff) | |
download | chromium_src-e80a54bfd7997d02d1995ddfb96f2e55ec2fc771.zip chromium_src-e80a54bfd7997d02d1995ddfb96f2e55ec2fc771.tar.gz chromium_src-e80a54bfd7997d02d1995ddfb96f2e55ec2fc771.tar.bz2 |
Added GPU rendering plugin, an internal out-of-process plugin for rendering 3D graphics with the GPU.
Does nothing at all yet.
Only enabled if --enable-gpu-plugin is on the command line and only in Windows build.
GPU plugin builds on Linux and Mac but is not functional or enabled yet.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/174158
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@23874 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d/gpu_plugin')
-rw-r--r-- | o3d/gpu_plugin/gpu_plugin.cc | 82 | ||||
-rw-r--r-- | o3d/gpu_plugin/gpu_plugin.gyp | 46 | ||||
-rw-r--r-- | o3d/gpu_plugin/gpu_plugin.h | 32 | ||||
-rw-r--r-- | o3d/gpu_plugin/gpu_plugin_unittest.cc | 70 |
4 files changed, 230 insertions, 0 deletions
diff --git a/o3d/gpu_plugin/gpu_plugin.cc b/o3d/gpu_plugin/gpu_plugin.cc new file mode 100644 index 0000000..a8654ce --- /dev/null +++ b/o3d/gpu_plugin/gpu_plugin.cc @@ -0,0 +1,82 @@ +// Copyright (c) 2006-2008 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 "o3d/gpu_plugin/gpu_plugin.h" +#include "webkit/glue/plugins/nphostapi.h" + +namespace o3d { +namespace gpu_plugin { + +// Definitions of NPAPI plugin entry points. + +namespace { +NPNetscapeFuncs* g_browser_funcs; + +NPError NPP_New(NPMIMEType pluginType, NPP instance, + uint16 mode, int16 argc, char* argn[], + char* argv[], NPSavedData* saved) { + return NPERR_NO_ERROR; +} + +NPError NPP_Destroy(NPP instance, NPSavedData** save) { + return NPERR_NO_ERROR; +} + +NPError NPP_SetWindow(NPP instance, NPWindow* window) { + return NPERR_NO_ERROR; +} + +int16 NPP_HandleEvent(NPP instance, void* event) { + return 0; +} + +NPError NPP_GetValue(NPP instance, NPPVariable variable, void *value) { + return NPERR_NO_ERROR; +} + +NPError NPP_SetValue(NPP instance, NPNVariable variable, void *value) { + return NPERR_NO_ERROR; +} +} + +NPError API_CALL NP_GetEntryPoints(NPPluginFuncs* funcs) { + funcs->newp = NPP_New; + funcs->destroy = NPP_Destroy; + funcs->setwindow = NPP_SetWindow; + funcs->event = NPP_HandleEvent; + funcs->getvalue = NPP_GetValue; + funcs->setvalue = NPP_SetValue; + return NPERR_NO_ERROR; +} + +#if defined(OS_LINUX) +NPError API_CALL NP_Initialize(NPNetscapeFuncs *browser_funcs, + NPPluginFuncs* plugin_funcs) { +#else +NPError API_CALL NP_Initialize(NPNetscapeFuncs *browser_funcs) { +#endif + if (!browser_funcs) + return NPERR_INVALID_FUNCTABLE_ERROR; + + if (g_browser_funcs) + return NPERR_GENERIC_ERROR; + +#if defined(OS_LINUX) + NP_GetEntryPoints(plugin_funcs); +#endif + + g_browser_funcs = browser_funcs; + return NPERR_NO_ERROR; +} + +NPError API_CALL NP_Shutdown() { + if (!g_browser_funcs) + return NPERR_GENERIC_ERROR; + + g_browser_funcs = NULL; + return NPERR_NO_ERROR; +} + +} // namespace gpu_plugin +} // namespace o3d diff --git a/o3d/gpu_plugin/gpu_plugin.gyp b/o3d/gpu_plugin/gpu_plugin.gyp new file mode 100644 index 0000000..6ab3335 --- /dev/null +++ b/o3d/gpu_plugin/gpu_plugin.gyp @@ -0,0 +1,46 @@ +# 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. + +{ + 'includes': [ + '../build/common.gypi', + ], + 'targets': [ + { + 'target_name': 'gpu_plugin', + 'type': '<(library)', + 'dependencies': [ + '../../base/base.gyp:base', + ], + 'include_dirs': [ + '../..', + '../../third_party/npapi', + ], + 'sources': [ + 'gpu_plugin.cc', + 'gpu_plugin.h', + ], + }, + + # This is a standalone executable until O3D is fully moved over to using + # gyp. At that point these can become part of the regular O3D unit tests. + { + 'target_name': 'gpu_plugin_unittests', + 'type': 'executable', + 'dependencies': [ + 'gpu_plugin', + '../../testing/gmock.gyp:gmock', + '../../testing/gmock.gyp:gmockmain', + '../../testing/gtest.gyp:gtest', + ], + 'include_dirs': [ + '../..', + '../../third_party/npapi', + ], + 'sources': [ + 'gpu_plugin_unittest.cc', + ], + }, + ] +} diff --git a/o3d/gpu_plugin/gpu_plugin.h b/o3d/gpu_plugin/gpu_plugin.h new file mode 100644 index 0000000..1fa2279 --- /dev/null +++ b/o3d/gpu_plugin/gpu_plugin.h @@ -0,0 +1,32 @@ +// Copyright (c) 2006-2008 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 O3D_GPU_PLUGIN_GPU_PLUGIN_H__ +#define O3D_GPU_PLUGIN_GPU_PLUGIN_H__ + +#include "third_party/npapi/bindings/npapi.h" + +typedef struct _NPPluginFuncs NPPluginFuncs; +typedef struct _NPNetscapeFuncs NPNetscapeFuncs; + +namespace o3d { +namespace gpu_plugin { + +// Declarations of NPAPI plugin entry points. + +NPError API_CALL NP_GetEntryPoints(NPPluginFuncs* funcs); + +#if defined(OS_LINUX) +NPError API_CALL NP_Initialize(NPNetscapeFuncs *browser_funcs, + NPPluginFuncs* plugin_funcs); +#else +NPError API_CALL NP_Initialize(NPNetscapeFuncs* browser_funcs); +#endif + +NPError API_CALL NP_Shutdown(); + +} // namespace gpu_plugin +} // namespace o3d + +#endif // O3D_GPU_PLUGIN_GPU_PLUGIN_H__ diff --git a/o3d/gpu_plugin/gpu_plugin_unittest.cc b/o3d/gpu_plugin/gpu_plugin_unittest.cc new file mode 100644 index 0000000..b7a74c6 --- /dev/null +++ b/o3d/gpu_plugin/gpu_plugin_unittest.cc @@ -0,0 +1,70 @@ +// Copyright (c) 2006-2008 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 "o3d/gpu_plugin/gpu_plugin.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "webkit/glue/plugins/nphostapi.h" + +#if defined(OS_LINUX) +#define INITIALIZE_PLUGIN_FUNCS , &plugin_funcs_ +#else +#define INITIALIZE_PLUGIN_FUNCS +#endif + +namespace o3d { +namespace gpu_plugin { + +class GPUPluginTest : public testing::Test { + protected: + virtual void SetUp() { + memset(&browser_funcs_, 0, sizeof(browser_funcs_)); + memset(&plugin_funcs_, 0, sizeof(plugin_funcs_)); + } + + NPNetscapeFuncs browser_funcs_; + NPPluginFuncs plugin_funcs_; +}; + +TEST_F(GPUPluginTest, GetEntryPointsSetsNeededFunctionPointers) { +#if defined(OS_LINUX) + NPError error = NP_Initialize(&browser_funcs_, &plugin_funcs_); + NP_Shutdown(); +#else + NPError error = NP_GetEntryPoints(&plugin_funcs_); +#endif + + EXPECT_EQ(NPERR_NO_ERROR, error); + EXPECT_TRUE(NULL != plugin_funcs_.newp); + EXPECT_TRUE(NULL != plugin_funcs_.destroy); + EXPECT_TRUE(NULL != plugin_funcs_.setwindow); + EXPECT_TRUE(NULL != plugin_funcs_.event); + EXPECT_TRUE(NULL != plugin_funcs_.getvalue); + EXPECT_TRUE(NULL != plugin_funcs_.setvalue); +} + +TEST_F(GPUPluginTest, CanInitializeAndShutdownPlugin) { + EXPECT_EQ(NPERR_NO_ERROR, + NP_Initialize(&browser_funcs_ INITIALIZE_PLUGIN_FUNCS)); + EXPECT_EQ(NPERR_NO_ERROR, NP_Shutdown()); +} + +TEST_F(GPUPluginTest, InitializeFailsIfBrowserFuncsIsNull) { + EXPECT_EQ(NPERR_INVALID_FUNCTABLE_ERROR, + NP_Initialize(NULL INITIALIZE_PLUGIN_FUNCS)); +} + +TEST_F(GPUPluginTest, InitializeFailsIfAlreadyInitialized) { + EXPECT_EQ(NPERR_NO_ERROR, + NP_Initialize(&browser_funcs_ INITIALIZE_PLUGIN_FUNCS)); + EXPECT_EQ(NPERR_GENERIC_ERROR, + NP_Initialize(&browser_funcs_ INITIALIZE_PLUGIN_FUNCS)); + EXPECT_EQ(NPERR_NO_ERROR, NP_Shutdown()); +} + +TEST_F(GPUPluginTest, ShutdownFailsIfNotInitialized) { + EXPECT_EQ(NPERR_GENERIC_ERROR, NP_Shutdown()); +} + +} // namespace gpu_plugin +} // namespace o3d |