1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
|
// 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 "base/at_exit.h"
#include "base/logging.h"
#include "gpu/demos/framework/plugin.h"
#include "gpu/pgl/pgl.h"
#include "third_party/npapi/bindings/nphostapi.h"
#if __GNUC__ >= 4
#define EXPORT __attribute__ ((visibility("default")))
#else
// We use .def file to export symbols on OS_WIN. We could potentially use
// __declspec(dllexport) but API_CALL always adds something to the function
// signature even inside extern "C" {}
#define EXPORT
#endif // GNUC
namespace {
// AtExitManager is used by singleton classes to delete themselves when
// the program terminates. There should be only one instance of this class
// per thread;
base::AtExitManager* g_at_exit_manager;
} // namespace
namespace gpu {
namespace demos {
// NPP entry points.
NPError NPP_New(NPMIMEType pluginType,
NPP instance,
uint16 mode,
int16 argc, char* argn[], char* argv[],
NPSavedData* saved) {
if (g_browser->version < NPVERS_HAS_PLUGIN_THREAD_ASYNC_CALL) {
return NPERR_INCOMPATIBLE_VERSION_ERROR;
}
Plugin* plugin = static_cast<Plugin*>(
g_browser->createobject(instance, Plugin::GetPluginClass()));
instance->pdata = plugin;
plugin->New(pluginType, argc, argn, argv);
return NPERR_NO_ERROR;
}
NPError NPP_Destroy(NPP instance, NPSavedData** save) {
Plugin* plugin = static_cast<Plugin*>(instance->pdata);
if (plugin) g_browser->releaseobject(plugin);
return NPERR_NO_ERROR;
}
NPError NPP_SetWindow(NPP instance, NPWindow* window) {
Plugin* plugin = static_cast<Plugin*>(instance->pdata);
if (plugin) plugin->SetWindow(*window);
return NPERR_NO_ERROR;
}
NPError NPP_NewStream(NPP instance,
NPMIMEType type,
NPStream* stream,
NPBool seekable,
uint16* stype) {
*stype = NP_ASFILEONLY;
return NPERR_NO_ERROR;
}
NPError NPP_DestroyStream(NPP instance, NPStream* stream, NPReason reason) {
return NPERR_NO_ERROR;
}
void NPP_StreamAsFile(NPP instance, NPStream* stream, const char* fname) {
}
int32 NPP_Write(NPP instance,
NPStream* stream,
int32 offset,
int32 len,
void* buffer) {
return 0;
}
int32 NPP_WriteReady(NPP instance, NPStream* stream) {
return 0;
}
void NPP_Print(NPP instance, NPPrint* platformPrint) {
}
int16 NPP_HandleEvent(NPP instance, void* event) {
Plugin* plugin = static_cast<Plugin*>(instance->pdata);
if (plugin)
return plugin->HandleEvent(*static_cast<NPPepperEvent*>(event));
return 0;
}
void NPP_URLNotify(NPP instance, const char* url, NPReason reason,
void* notify_data) {
}
NPError NPP_GetValue(NPP instance, NPPVariable variable, void* value) {
NPError err = NPERR_NO_ERROR;
switch (variable) {
#if defined(OS_LINUX)
case NPPVpluginNameString:
*(static_cast<const char**>(value)) = "Pepper GPU Demo";
break;
case NPPVpluginDescriptionString:
*(static_cast<const char**>(value)) = "Pepper plug-in for GPU demo.";
break;
case NPPVpluginNeedsXEmbed:
*(static_cast<NPBool*>(value)) = true;
break;
#endif
case NPPVpluginScriptableNPObject: {
void** v = static_cast<void**>(value);
Plugin* plugin = static_cast<Plugin*>(instance->pdata);
// Return value is expected to be retained
g_browser->retainobject(plugin);
*v = plugin;
break;
}
default:
LOG(INFO) << "Unhandled variable to NPP_GetValue\n";
err = NPERR_GENERIC_ERROR;
break;
}
return err;
}
NPError NPP_SetValue(NPP instance, NPNVariable variable, void* value) {
return NPERR_GENERIC_ERROR;
}
} // namespace demos
} // namespace gpu
// NP entry points
extern "C" {
EXPORT NPError API_CALL NP_GetEntryPoints(NPPluginFuncs* plugin_funcs) {
plugin_funcs->version = NPVERS_HAS_PLUGIN_THREAD_ASYNC_CALL;
plugin_funcs->size = sizeof(plugin_funcs);
plugin_funcs->newp = gpu::demos::NPP_New;
plugin_funcs->destroy = gpu::demos::NPP_Destroy;
plugin_funcs->setwindow = gpu::demos::NPP_SetWindow;
plugin_funcs->newstream = gpu::demos::NPP_NewStream;
plugin_funcs->destroystream = gpu::demos::NPP_DestroyStream;
plugin_funcs->asfile = gpu::demos::NPP_StreamAsFile;
plugin_funcs->writeready = gpu::demos::NPP_WriteReady;
plugin_funcs->write = gpu::demos::NPP_Write;
plugin_funcs->print = gpu::demos::NPP_Print;
plugin_funcs->event = gpu::demos::NPP_HandleEvent;
plugin_funcs->urlnotify = gpu::demos::NPP_URLNotify;
plugin_funcs->getvalue = gpu::demos::NPP_GetValue;
plugin_funcs->setvalue = gpu::demos::NPP_SetValue;
return NPERR_NO_ERROR;
}
EXPORT NPError API_CALL NP_Initialize(NPNetscapeFuncs* browser_funcs
#if defined(OS_LINUX)
, NPPluginFuncs* plugin_funcs
#endif // OS_LINUX
) {
g_at_exit_manager = new base::AtExitManager();
gpu::demos::g_browser = browser_funcs;
pglInitialize();
#if defined(OS_LINUX)
NP_GetEntryPoints(plugin_funcs);
#endif // OS_LINUX
return NPERR_NO_ERROR;
}
EXPORT void API_CALL NP_Shutdown() {
pglTerminate();
delete g_at_exit_manager;
}
#if defined(OS_LINUX)
EXPORT NPError API_CALL NP_GetValue(NPP instance, NPPVariable variable,
void* value) {
return gpu::demos::NPP_GetValue(instance, variable, value);
}
EXPORT const char* API_CALL NP_GetMIMEDescription() {
return "pepper-application/x-gpu-demo::Pepper GPU Demo";
}
#endif // OS_LINUX
} // extern "C"
|