OLD | NEW |
| (Empty) |
1 // Copyright 2010 The Ginsu Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can | |
3 // be found in the LICENSE file. | |
4 | |
5 #include "c_salt/module.h" | |
6 | |
7 #include <nacl/npupp.h> | |
8 #include <pgl/pgl.h> | |
9 | |
10 // These functions are called when module code is first loaded, and when the | |
11 // module code text gets unloaded. They must use C-style linkage. | |
12 | |
13 // TODO(dspringer): This file will disappear when we migrate to Pepper v2 API. | |
14 // It gets replaced by pp::Module. | |
15 | |
16 namespace c_salt { | |
17 // This singleton is a pointer to the module as loaded by the browser. When | |
18 // we move to Pepper V2, this singleton is managed by the browser and will | |
19 // disappear from this code. | |
20 Module* Module::module_singleton_ = NULL; | |
21 | |
22 Module::Module() : is_opengl_initialized_(false) { | |
23 } | |
24 | |
25 Module::~Module() { | |
26 // Perform any specialized shut-down procedures here. | |
27 if (is_opengl_initialized_) { | |
28 pglTerminate(); | |
29 is_opengl_initialized_ = false; | |
30 } | |
31 } | |
32 | |
33 bool Module::InitializeOpenGL() { | |
34 if (is_opengl_initialized_) return true; | |
35 is_opengl_initialized_ = pglInitialize() == PGL_TRUE ? true : false; | |
36 return is_opengl_initialized_; | |
37 } | |
38 | |
39 void Module::CleanUp() { | |
40 delete module_singleton_; | |
41 } | |
42 | |
43 Module& Module::GetModuleSingleton() { | |
44 if (module_singleton_ == NULL) { | |
45 module_singleton_ = CreateModule(); | |
46 } | |
47 // Crash on failure. | |
48 return *module_singleton_; | |
49 } | |
50 } // namespace c_salt | |
51 | |
52 // The browser bindings that get called to load and unload a Module. | |
53 extern "C" { | |
54 NPError NP_GetEntryPoints(NPPluginFuncs* plugin_funcs) { | |
55 // Defined in npp_gate.cc | |
56 extern NPError InitializePepperGateFunctions(NPPluginFuncs* plugin_funcs); | |
57 return InitializePepperGateFunctions(plugin_funcs); | |
58 } | |
59 | |
60 NPError NP_Initialize(NPNetscapeFuncs* browser_functions, | |
61 NPPluginFuncs* plugin_functions) { | |
62 NPError np_err = NP_GetEntryPoints(plugin_functions); | |
63 return np_err; | |
64 } | |
65 | |
66 NPError NP_Shutdown() { | |
67 c_salt::Module::CleanUp(); | |
68 return NPERR_NO_ERROR; | |
69 } | |
70 } // extern "C" | |
OLD | NEW |