Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / gfx / gl / GLLibraryLoader.cpp
blobe73f312d29a59a5aba458c5e12ab01d940574cea
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 <regex>
9 #include "mozilla/gfx/Logging.h"
10 #include "nsDebug.h"
12 #ifdef WIN32
13 # include <windows.h>
14 #endif
16 namespace mozilla {
17 namespace gl {
19 void ClearSymbols(const SymLoadStruct* const firstStruct) {
20 for (auto itr = firstStruct; itr->symPointer; ++itr) {
21 *itr->symPointer = nullptr;
25 bool SymbolLoader::LoadSymbols(const SymLoadStruct* const firstStruct,
26 const bool warnOnFailures) const {
27 bool ok = true;
29 for (auto itr = firstStruct; itr->symPointer; ++itr) {
30 *itr->symPointer = nullptr;
32 for (const auto& s : itr->symNames) {
33 if (!s) break;
35 const auto p = GetProcAddress(s);
36 if (p) {
37 *itr->symPointer = p;
38 break;
42 if (!*itr->symPointer) {
43 if (warnOnFailures) {
44 printf_stderr("Can't find symbol '%s'.\n", itr->symNames[0]);
46 ok = false;
50 return ok;
53 // -
55 PRFuncPtr SymbolLoader::GetProcAddress(const char* const name) const {
56 #ifdef DEBUG
57 static const std::regex kRESymbol("[a-z].*");
58 if (!std::regex_match(name, kRESymbol)) {
59 gfxCriticalError() << "Bad symbol name : " << name;
61 #endif
63 PRFuncPtr ret = nullptr;
64 if (!ret && mLib) {
65 ret = PR_FindFunctionSymbol(mLib, name);
67 if (!ret && mPfn) {
68 ret = mPfn(name);
70 return ret;
73 } // namespace gl
74 } // namespace mozilla