|
1 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
|
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
4 |
|
5 #ifndef GLLIBRARYLOADER_H_ |
|
6 #define GLLIBRARYLOADER_H_ |
|
7 |
|
8 #include <stdio.h> |
|
9 |
|
10 #ifdef WIN32 |
|
11 #include <windows.h> |
|
12 #endif |
|
13 |
|
14 #include "GLDefs.h" |
|
15 #include "nscore.h" |
|
16 #include "prlink.h" |
|
17 |
|
18 namespace mozilla { |
|
19 namespace gl { |
|
20 |
|
21 class GLLibraryLoader |
|
22 { |
|
23 public: |
|
24 bool OpenLibrary(const char *library); |
|
25 |
|
26 typedef PRFuncPtr (GLAPIENTRY * PlatformLookupFunction) (const char *); |
|
27 |
|
28 enum { |
|
29 MAX_SYMBOL_NAMES = 6, |
|
30 MAX_SYMBOL_LENGTH = 128 |
|
31 }; |
|
32 |
|
33 typedef struct { |
|
34 PRFuncPtr *symPointer; |
|
35 const char *symNames[MAX_SYMBOL_NAMES]; |
|
36 } SymLoadStruct; |
|
37 |
|
38 bool LoadSymbols(SymLoadStruct *firstStruct, |
|
39 bool tryplatform = false, |
|
40 const char *prefix = nullptr, |
|
41 bool warnOnFailure = true); |
|
42 |
|
43 /* |
|
44 * Static version of the functions in this class |
|
45 */ |
|
46 static PRFuncPtr LookupSymbol(PRLibrary *lib, |
|
47 const char *symname, |
|
48 PlatformLookupFunction lookupFunction = nullptr); |
|
49 static bool LoadSymbols(PRLibrary *lib, |
|
50 SymLoadStruct *firstStruct, |
|
51 PlatformLookupFunction lookupFunction = nullptr, |
|
52 const char *prefix = nullptr, |
|
53 bool warnOnFailure = true); |
|
54 protected: |
|
55 GLLibraryLoader() { |
|
56 mLibrary = nullptr; |
|
57 mLookupFunc = nullptr; |
|
58 } |
|
59 |
|
60 PRLibrary *mLibrary; |
|
61 PlatformLookupFunction mLookupFunc; |
|
62 }; |
|
63 |
|
64 } /* namespace gl */ |
|
65 } /* namespace mozilla */ |
|
66 |
|
67 #endif /* GLLIBRARYLOADER_H_ */ |