Bumping gaia.json for 2 gaia revision(s) a=gaia-bump
[gecko.git] / gfx / gl / GLLibraryLoader.cpp
bloba66bd372b167efbd3509be884ce70fe816a1b061
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/. */
5 #include "GLLibraryLoader.h"
7 #include "nsDebug.h"
9 namespace mozilla {
10 namespace gl {
12 bool
13 GLLibraryLoader::OpenLibrary(const char *library)
15 PRLibSpec lspec;
16 lspec.type = PR_LibSpec_Pathname;
17 lspec.value.pathname = library;
19 mLibrary = PR_LoadLibraryWithFlags(lspec, PR_LD_LAZY | PR_LD_LOCAL);
20 if (!mLibrary)
21 return false;
23 return true;
26 bool
27 GLLibraryLoader::LoadSymbols(SymLoadStruct *firstStruct,
28 bool tryplatform,
29 const char *prefix,
30 bool warnOnFailure)
32 return LoadSymbols(mLibrary,
33 firstStruct,
34 tryplatform ? mLookupFunc : nullptr,
35 prefix,
36 warnOnFailure);
39 PRFuncPtr
40 GLLibraryLoader::LookupSymbol(PRLibrary *lib,
41 const char *sym,
42 PlatformLookupFunction lookupFunction)
44 PRFuncPtr res = 0;
46 // try finding it in the library directly, if we have one
47 if (lib) {
48 res = PR_FindFunctionSymbol(lib, sym);
51 // then try looking it up via the lookup symbol
52 if (!res && lookupFunction) {
53 res = lookupFunction(sym);
56 // finally just try finding it in the process
57 if (!res) {
58 PRLibrary *leakedLibRef;
59 res = PR_FindFunctionSymbolAndLibrary(sym, &leakedLibRef);
62 return res;
65 bool
66 GLLibraryLoader::LoadSymbols(PRLibrary *lib,
67 SymLoadStruct *firstStruct,
68 PlatformLookupFunction lookupFunction,
69 const char *prefix,
70 bool warnOnFailure)
72 char sbuf[MAX_SYMBOL_LENGTH * 2];
73 int failCount = 0;
75 SymLoadStruct *ss = firstStruct;
76 while (ss->symPointer) {
77 *ss->symPointer = 0;
79 for (int i = 0; i < MAX_SYMBOL_NAMES; i++) {
80 if (ss->symNames[i] == nullptr)
81 break;
83 const char *s = ss->symNames[i];
84 if (prefix && *prefix != 0) {
85 strcpy(sbuf, prefix);
86 strcat(sbuf, ss->symNames[i]);
87 s = sbuf;
90 PRFuncPtr p = LookupSymbol(lib, s, lookupFunction);
91 if (p) {
92 *ss->symPointer = p;
93 break;
97 if (*ss->symPointer == 0) {
98 if (warnOnFailure)
99 printf_stderr("Can't find symbol '%s'.\n", ss->symNames[0]);
101 failCount++;
104 ss++;
107 return failCount == 0 ? true : false;
110 } /* namespace gl */
111 } /* namespace mozilla */