source: trunk/src/platform/nacl/nacl-module.cpp @ 2183

Last change on this file since 2183 was 1440, checked in by sam, 11 years ago

nacl: NaCl binaries no longer need a modified main() to work, the NaCl
instance object takes care of everything for us.

  • Property svn:keywords set to Id
File size: 1.8 KB
Line 
1// Copyright (c) 2011 The Native Client Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#if defined HAVE_CONFIG_H
6#   include "config.h"
7#endif
8
9#include <ppapi/cpp/instance.h>
10#include <ppapi/cpp/module.h>
11#include <ppapi/gles2/gl2ext_ppapi.h>
12
13#include "core.h"
14#include "lolgl.h" /* needed for GL_TRUE */
15
16#include "platform/nacl/nacl-instance.h"
17
18/// The Module class.  The browser calls the CreateInstance() method to create
19/// an instance of your NaCl module on the web page.  The browser creates a new
20/// instance for each <embed> tag with type="application/x-nacl".
21class NaClModule : public pp::Module
22{
23public:
24    NaClModule() : pp::Module() {}
25    virtual ~NaClModule()
26    {
27        glTerminatePPAPI();
28    }
29
30    /// Called by the browser when the module is first loaded and ready to run.
31    /// This is called once per module, not once per instance of the module on
32    /// the page.
33    virtual bool Init()
34    {
35        return glInitializePPAPI(get_browser_interface()) == GL_TRUE;
36    }
37
38    /// Create and return a Lol instance object.
39    /// @param[in] instance The browser-side instance.
40    /// @return the plugin-side instance.
41    virtual pp::Instance* CreateInstance(PP_Instance instance)
42    {
43        return new lol::NaClInstance(instance);
44    }
45};
46
47namespace pp
48{
49/// Factory function called by the browser when the module is first loaded.
50/// The browser keeps a singleton of this module.  It calls the
51/// CreateInstance() method on the object you return to make instances.  There
52/// is one instance per <embed> tag on the page.  This is the main binding
53/// point for your NaCl module with the browser.
54Module* CreateModule()
55{
56    return new NaClModule();
57}
58
59}  // namespace pp
60
Note: See TracBrowser for help on using the repository browser.