summaryrefslogtreecommitdiffstats
path: root/o3d/plugin/cross
diff options
context:
space:
mode:
authorapatrick@google.com <apatrick@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-10 00:41:08 +0000
committerapatrick@google.com <apatrick@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-10 00:41:08 +0000
commitf90ef342b3dcacd675f630caa63626573cfe032a (patch)
tree724d4466908a72d5bee0abd8ec0bb437acd26810 /o3d/plugin/cross
parent07f25e82ef962a56a791d115720f57957d84d782 (diff)
downloadchromium_src-f90ef342b3dcacd675f630caa63626573cfe032a.zip
chromium_src-f90ef342b3dcacd675f630caa63626573cfe032a.tar.gz
chromium_src-f90ef342b3dcacd675f630caa63626573cfe032a.tar.bz2
Switched from NPObject shared memory wrapper to Chrome shared memory in preparation for moving from NPAPI to Chrome IPC for synchronous messages.
Started work on an O3D configuration that will use Pepper 3D to connect to a remote GPU plugin. This is not building yet. Updated to latest NPAPI from nixysa. Review URL: http://codereview.chromium.org/371074 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31519 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d/plugin/cross')
-rw-r--r--o3d/plugin/cross/main.h2
-rw-r--r--o3d/plugin/cross/main_remote_cb.cc210
-rw-r--r--o3d/plugin/cross/np_v8_bridge.cc2
-rw-r--r--o3d/plugin/cross/o3d_glue.cc115
-rw-r--r--o3d/plugin/cross/o3d_glue.h11
5 files changed, 308 insertions, 32 deletions
diff --git a/o3d/plugin/cross/main.h b/o3d/plugin/cross/main.h
index d4e1d24..f8c8512 100644
--- a/o3d/plugin/cross/main.h
+++ b/o3d/plugin/cross/main.h
@@ -39,7 +39,7 @@
#include "core/cross/renderer_platform.h"
-#include <npupp.h>
+#include <npfunctions.h>
#include <stdio.h>
#include <fstream>
diff --git a/o3d/plugin/cross/main_remote_cb.cc b/o3d/plugin/cross/main_remote_cb.cc
new file mode 100644
index 0000000..e2346ed
--- /dev/null
+++ b/o3d/plugin/cross/main_remote_cb.cc
@@ -0,0 +1,210 @@
+/*
+ * Copyright 2009, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
+// This file implements the entry points for the windowless O3D plugin that
+// relies on a GPU plugin for output.
+
+#include "base/at_exit.h"
+#include "base/command_line.h"
+#include "base/logging.h"
+#include "base/scoped_ptr.h"
+#include "core/cross/command_buffer/renderer_cb.h"
+#include "core/cross/command_buffer/display_window_cb.h"
+#include "gpu_plugin/command_buffer.h"
+#include "gpu_plugin/np_utils/np_browser_stub.h"
+#include "gpu_plugin/np_utils/np_object_pointer.h"
+#include "gpu_plugin/np_utils/np_utils.h"
+#include "plugin/cross/main.h"
+
+using glue::_o3d::PluginObject;
+using glue::StreamManager;
+using o3d::Event;
+using gpu_plugin::NPObjectPointer;
+using gpu_plugin::NPInvoke;
+
+namespace {
+const uint32 kTimerInterval = 16;
+
+gpu_plugin::NPBrowser* g_browser;
+
+#if defined(OS_WIN)
+const wchar_t* const kLogFile = L"debug.log";
+#else
+const char* const kLogFile = "debug.log";
+#endif
+} // end anonymous namespace
+
+#if defined(O3D_INTERNAL_PLUGIN)
+namespace o3d {
+#else
+extern "C" {
+#endif
+
+NPError EXPORT_SYMBOL OSCALL NP_Initialize(NPNetscapeFuncs *browserFuncs) {
+ CommandLine::Init(0, NULL);
+ InitLogging(kLogFile,
+ logging::LOG_TO_BOTH_FILE_AND_SYSTEM_DEBUG_LOG,
+ logging::DONT_LOCK_LOG_FILE,
+ logging::APPEND_TO_OLD_LOG_FILE);
+
+ NPError retval = InitializeNPNApi(browserFuncs);
+ if (retval != NPERR_NO_ERROR) return retval;
+
+ g_browser = new gpu_plugin::NPBrowser(browserFuncs);
+
+ return NPERR_NO_ERROR;
+}
+
+NPError EXPORT_SYMBOL OSCALL NP_Shutdown(void) {
+ DLOG(INFO) << "NP_Shutdown";
+
+ CommandLine::Reset();
+
+ return NPERR_NO_ERROR;
+}
+
+} // namespace o3d / extern "C"
+
+namespace o3d {
+
+NPError PlatformNPPGetValue(NPP instance, NPPVariable variable, void *value) {
+ return NPERR_NO_ERROR;
+}
+
+void OnTimer(NPP instance, uint32 timer_id) {
+ PluginObject* plugin_object = static_cast<PluginObject*>(instance->pdata);
+ if (plugin_object) {
+ // If the GPU plugin object has been set and the renderer is not initialized
+ // then attempt to initialize it.
+ NPObjectPointer<NPObject> gpu_plugin_object(
+ plugin_object->GetGPUPluginObject());
+ if (gpu_plugin_object.Get() && !plugin_object->renderer()) {
+ NPObjectPointer<NPObject> command_buffer;
+ if (NPInvoke(plugin_object->npp(),
+ gpu_plugin_object,
+ "openCommandBuffer",
+ &command_buffer)) {
+ DisplayWindowCB default_display;
+ default_display.set_npp(plugin_object->npp());
+ default_display.set_command_buffer(command_buffer);
+ plugin_object->CreateRenderer(default_display);
+
+ // Get the GPU plugins size and resize the renderer.
+ int32 width;
+ int32 height;
+ if (NPInvoke(plugin_object->npp(),
+ gpu_plugin_object,
+ "getWidth",
+ &width) &&
+ NPInvoke(plugin_object->npp(),
+ gpu_plugin_object,
+ "getHeight",
+ &height)) {
+ plugin_object->renderer()->Resize(width, height);
+ plugin_object->client()->Init();
+ }
+ }
+ }
+
+ plugin_object->client()->Tick();
+ if (plugin_object->client()->render_mode() ==
+ o3d::Client::RENDERMODE_CONTINUOUS) {
+ plugin_object->client()->RenderClient(true);
+ }
+ }
+}
+
+NPError NPP_New(NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc,
+ char *argn[], char *argv[], NPSavedData *saved) {
+ NPError error = NPN_SetValue(
+ instance, NPPVpluginWindowBool, reinterpret_cast<void*>(false));
+ if (error != NPERR_NO_ERROR)
+ return error;
+
+ PluginObject* plugin_object = glue::_o3d::PluginObject::Create(
+ instance);
+ instance->pdata = plugin_object;
+ glue::_o3d::InitializeGlue(instance);
+ plugin_object->Init(argc, argn, argv);
+
+ gpu_plugin::NPBrowser::get()->ScheduleTimer(instance,
+ kTimerInterval,
+ true,
+ OnTimer);
+
+ return NPERR_NO_ERROR;
+}
+
+NPError NPP_Destroy(NPP instance, NPSavedData **save) {
+ PluginObject *plugin_object = static_cast<PluginObject*>(instance->pdata);
+ if (plugin_object) {
+ plugin_object->TearDown();
+ NPN_ReleaseObject(plugin_object);
+ instance->pdata = NULL;
+ }
+
+ return NPERR_NO_ERROR;
+}
+
+NPError NPP_SetWindow(NPP instance, NPWindow *window) {
+ return NPERR_NO_ERROR;
+}
+
+// Called when the browser has finished attempting to stream data to
+// a file as requested. If fname == NULL the attempt was not successful.
+void NPP_StreamAsFile(NPP instance, NPStream *stream, const char *fname) {
+ PluginObject *plugin_object = static_cast<PluginObject*>(instance->pdata);
+ StreamManager *stream_manager = plugin_object->stream_manager();
+ stream_manager->SetStreamFile(stream, fname);
+}
+
+int16 NPP_HandleEvent(NPP instance, void *event) {
+ return 0;
+}
+} // namespace o3d
+
+namespace glue {
+namespace _o3d {
+bool PluginObject::GetDisplayMode(int mode_id, o3d::DisplayMode *mode) {
+ return renderer()->GetDisplayMode(mode_id, mode);
+}
+
+// TODO: Where should this really live? It's platform-specific, but in
+// PluginObject, which mainly lives in cross/o3d_glue.h+cc.
+bool PluginObject::RequestFullscreenDisplay() {
+ return false;
+}
+
+void PluginObject::CancelFullscreenDisplay() {
+}
+} // namespace _o3d
+} // namespace glue
diff --git a/o3d/plugin/cross/np_v8_bridge.cc b/o3d/plugin/cross/np_v8_bridge.cc
index 2acdfd8..f898b6b 100644
--- a/o3d/plugin/cross/np_v8_bridge.cc
+++ b/o3d/plugin/cross/np_v8_bridge.cc
@@ -786,7 +786,7 @@ Local<Value> NPV8Bridge::NPToV8Variant(const NPVariant& np_variant) {
{
NPString np_string = NPVARIANT_TO_STRING(np_variant);
v8_result = Local<Value>::New(
- v8::String::New(np_string.utf8characters, np_string.utf8length));
+ v8::String::New(np_string.UTF8Characters, np_string.UTF8Length));
break;
}
case NPVariantType_Object:
diff --git a/o3d/plugin/cross/o3d_glue.cc b/o3d/plugin/cross/o3d_glue.cc
index c52e242..f2cfb4f 100644
--- a/o3d/plugin/cross/o3d_glue.cc
+++ b/o3d/plugin/cross/o3d_glue.cc
@@ -39,7 +39,10 @@
#include <algorithm>
#include "core/cross/renderer.h"
#include "core/cross/client_info.h"
+#include "core/cross/command_buffer/display_window_cb.h"
#include "gpu_plugin/np_utils/np_headers.h"
+#include "gpu_plugin/np_utils/np_object_pointer.h"
+#include "gpu_plugin/np_utils/np_utils.h"
#include "plugin/cross/o3d_glue.h"
#include "plugin/cross/config.h"
#include "plugin/cross/stream_manager.h"
@@ -50,6 +53,11 @@
#include "plugin_mac.h"
#endif
+using o3d::DisplayWindowCB;
+using gpu_plugin::NPObjectPointer;
+using gpu_plugin::NPVariantToValue;
+using gpu_plugin::ValueToNPVariant;
+
namespace glue {
namespace _o3d {
@@ -149,6 +157,9 @@ PluginObject::PluginObject(NPP npp)
draw_(true),
in_plugin_(false),
#endif
+#if defined(CB_SERVICE_REMOTE)
+ gpu_plugin_object_(NULL),
+#endif
np_v8_bridge_(&service_locator_, npp),
stream_manager_(new StreamManager(npp)),
cursor_type_(o3d::Cursor::DEFAULT),
@@ -400,7 +411,6 @@ bool PluginObject::SetRendererIsSoftware(bool state) {
#endif // OS_MACOSX
-
void PluginObject::RegisterType(const ObjectBase::Class *clientclass,
NPClass *npclass) {
client_to_np_class_map_[clientclass] = npclass;
@@ -472,26 +482,51 @@ void PluginObject::LogAssertHandlerFunction(const std::string& str) {
DLOG(ERROR) << "FATAL LOG ERROR: " << str;
}
+#if defined(CB_SERVICE_REMOTE)
+void PluginObject::SetGPUPluginObject(NPObject* gpu_plugin_object) {
+ if (gpu_plugin_object) {
+ NPN_RetainObject(gpu_plugin_object);
+ }
+
+ if (gpu_plugin_object_) {
+ NPN_ReleaseObject(gpu_plugin_object_);
+ }
+
+ gpu_plugin_object_ = gpu_plugin_object;
+}
+#endif
+
enum {
- PROP_CLIENT,
- PROP_GPU_CONFIG,
- NUM_PROPERTY_IDS
+ kPropClient,
+ kPropGpuConfig,
+ kNumPropertyIds
};
-static NPIdentifier property_ids[NUM_PROPERTY_IDS];
-static const NPUTF8 *property_names[NUM_PROPERTY_IDS] = {
+static NPIdentifier property_ids[kNumPropertyIds];
+static const NPUTF8 *property_names[kNumPropertyIds] = {
"client",
"gpuConfig",
};
enum {
- METHOD_EVAL,
- NUM_METHOD_IDS,
+ kMethodEval,
+
+#if defined(CB_SERVICE_REMOTE)
+ kMethodSetGPUPluginObject,
+ kMethodGetGPUPluginObject,
+#endif
+
+ kNumMethodIds,
};
-static NPIdentifier method_ids[NUM_METHOD_IDS];
-static const NPUTF8 *method_names[NUM_METHOD_IDS] = {
+static NPIdentifier method_ids[kNumMethodIds];
+static const NPUTF8 *method_names[kNumMethodIds] = {
"eval",
+
+#if defined(CB_SERVICE_REMOTE)
+ "setGPUPluginObject",
+ "getGPUPluginObject",
+#endif
};
static NPObject *PluginAllocate(NPP npp, NPClass *npclass) {
@@ -505,7 +540,7 @@ static void PluginDeallocate(NPObject *object) {
static bool PluginHasMethod(NPObject *header, NPIdentifier name) {
DebugScopedId id(name);
PluginObject *plugin_object = static_cast<PluginObject *>(header);
- for (int i = 0; i < NUM_METHOD_IDS; ++i) {
+ for (int i = 0; i < kNumMethodIds; ++i) {
if (name == method_ids[i]) {
return true;
}
@@ -516,31 +551,51 @@ static bool PluginHasMethod(NPObject *header, NPIdentifier name) {
}
static bool PluginInvoke(NPObject *header, NPIdentifier name,
- const NPVariant *args, uint32_t argCount,
+ const NPVariant *args, uint32_t arg_count,
NPVariant *np_result) {
DebugScopedId id(name);
PluginObject *plugin_object = static_cast<PluginObject *>(header);
- if (name == method_ids[METHOD_EVAL]) {
- return plugin_object->np_v8_bridge()->Evaluate(args, argCount, np_result);
- } else {
+ if (name == method_ids[kMethodEval]) {
+ return plugin_object->np_v8_bridge()->Evaluate(args, arg_count, np_result);
+ }
+#if defined(CB_SERVICE_REMOTE)
+ else if (name == method_ids[kMethodGetGPUPluginObject]) {
+ if (arg_count != 0)
+ return false;
+ ValueToNPVariant(plugin_object->GetGPUPluginObject(), np_result);
+ return true;
+ } else if (name == method_ids[kMethodSetGPUPluginObject]) {
+ if (arg_count != 1)
+ return false;
+ VOID_TO_NPVARIANT(*np_result);
+ NPObjectPointer<NPObject> gpu_plugin_object;
+ if (NPVariantToValue(&gpu_plugin_object, args[0])) {
+ plugin_object->SetGPUPluginObject(gpu_plugin_object.Get());
+ return true;
+ } else {
+ return false;
+ }
+ } // NOLINT
+#endif // CB_SERVICE_REMOTE
+ else { // NOLINT
NPObject *globals = plugin_object->globals_npobject();
- return globals->_class->invoke(globals, name, args, argCount, np_result);
+ return globals->_class->invoke(globals, name, args, arg_count, np_result);
}
}
static bool PluginInvokeDefault(NPObject *header, const NPVariant *args,
- uint32_t argCount, NPVariant *result) {
+ uint32_t arg_count, NPVariant *result) {
PluginObject *plugin_object = static_cast<PluginObject *>(header);
NPP npp = plugin_object->npp();
NPObject *globals = plugin_object->globals_npobject();
- return globals->_class->invokeDefault(globals, args, argCount, result);
+ return globals->_class->invokeDefault(globals, args, arg_count, result);
}
static bool PluginHasProperty(NPObject *header, NPIdentifier name) {
DebugScopedId id(name);
PluginObject *plugin_object = static_cast<PluginObject *>(header);
NPP npp = plugin_object->npp();
- for (unsigned int i = 0; i < NUM_PROPERTY_IDS; ++i) {
+ for (unsigned int i = 0; i < kNumPropertyIds; ++i) {
if (name == property_ids[i]) return true;
}
NPObject *globals = plugin_object->globals_npobject();
@@ -552,7 +607,7 @@ static bool PluginGetProperty(NPObject *header, NPIdentifier name,
DebugScopedId id(name);
PluginObject *plugin_object = static_cast<PluginObject *>(header);
NPP npp = plugin_object->npp();
- if (name == property_ids[PROP_GPU_CONFIG]) {
+ if (name == property_ids[kPropGpuConfig]) {
// Gets the GPU config (VendorID, DeviceID, name) as a string.
// NOTE: this should probably be removed before we ship.
o3d::GPUDevice device;
@@ -580,7 +635,7 @@ static bool PluginGetProperty(NPObject *header, NPIdentifier name,
return temp;
}
- if (name == property_ids[PROP_CLIENT]) {
+ if (name == property_ids[kPropClient]) {
NPObject *npobject = plugin_object->client_npobject();
GLUE_PROFILE_START(npp, "retainobject");
NPN_RetainObject(npobject);
@@ -597,7 +652,7 @@ static bool PluginSetProperty(NPObject *header, NPIdentifier name,
DebugScopedId id(name);
PluginObject *plugin_object = static_cast<PluginObject *>(header);
NPP npp = plugin_object->npp();
- if (name == property_ids[PROP_CLIENT]) {
+ if (name == property_ids[kPropClient]) {
return false;
}
NPObject *globals = plugin_object->globals_npobject();
@@ -606,18 +661,18 @@ static bool PluginSetProperty(NPObject *header, NPIdentifier name,
static bool PluginEnumerate(NPObject *header, NPIdentifier **value,
uint32_t *count) {
- *count = NUM_PROPERTY_IDS + NUM_METHOD_IDS + glue::GetStaticPropertyCount();
+ *count = kNumPropertyIds + kNumMethodIds + glue::GetStaticPropertyCount();
PluginObject *plugin_object = static_cast<PluginObject *>(header);
NPP npp = plugin_object->npp();
GLUE_PROFILE_START(npp, "memalloc");
*value = static_cast<NPIdentifier *>(
NPN_MemAlloc(*count * sizeof(NPIdentifier)));
GLUE_PROFILE_STOP(npp, "memalloc");
- memcpy(*value, property_ids, NUM_PROPERTY_IDS * sizeof(NPIdentifier));
- memcpy(*value + NUM_PROPERTY_IDS, method_ids,
- NUM_METHOD_IDS * sizeof(NPIdentifier));
+ memcpy(*value, property_ids, kNumPropertyIds * sizeof(NPIdentifier));
+ memcpy(*value + kNumPropertyIds, method_ids,
+ kNumMethodIds * sizeof(NPIdentifier));
glue::StaticEnumeratePropertyHelper(
- *value + NUM_PROPERTY_IDS + NUM_METHOD_IDS);
+ *value + kNumPropertyIds + kNumMethodIds);
return true;
}
@@ -646,8 +701,8 @@ PluginObject *PluginObject::Create(NPP npp) {
void InitializeGlue(NPP npp) {
GLUE_PROFILE_START(npp, "getstringidentifiers");
- NPN_GetStringIdentifiers(property_names, NUM_PROPERTY_IDS, property_ids);
- NPN_GetStringIdentifiers(method_names, NUM_METHOD_IDS, method_ids);
+ NPN_GetStringIdentifiers(property_names, kNumPropertyIds, property_ids);
+ NPN_GetStringIdentifiers(method_names, kNumMethodIds, method_ids);
GLUE_PROFILE_STOP(npp, "getstringidentifiers");
glue::InitializeGlue(npp);
}
@@ -896,7 +951,7 @@ void PluginObject::AsyncTick() {
}
void PluginObject::Tick() {
- DCHECK(pending_ticks_ > 0);
+ DCHECK_GT(pending_ticks_, 0);
--pending_ticks_;
client_->Tick();
diff --git a/o3d/plugin/cross/o3d_glue.h b/o3d/plugin/cross/o3d_glue.h
index 4d2a90c..fb8c5b7 100644
--- a/o3d/plugin/cross/o3d_glue.h
+++ b/o3d/plugin/cross/o3d_glue.h
@@ -456,6 +456,13 @@ class PluginObject: public NPObject {
void set_last_click_time(Time value) { last_click_time_ = value; }
#endif
+#if defined(CB_SERVICE_REMOTE)
+ void SetGPUPluginObject(NPObject* gpu_plugin_object);
+ NPObject* GetGPUPluginObject() {
+ return gpu_plugin_object_;
+ }
+#endif
+
private:
bool fullscreen_region_valid_;
int fullscreen_region_x_;
@@ -471,6 +478,10 @@ class PluginObject: public NPObject {
HCURSOR hCursor_;
bool painted_once_;
#endif // OS_WIN
+
+#if defined(CB_SERVICE_REMOTE)
+ NPObject* gpu_plugin_object_;
+#endif
};
} // namespace o3d