tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

GLLibraryLoader.h (1281B)


      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 <array>
      9 
     10 #include "GLDefs.h"
     11 #include "nscore.h"
     12 #include "prlink.h"
     13 #include "mozilla/Assertions.h"
     14 
     15 namespace mozilla {
     16 namespace gl {
     17 
     18 struct SymLoadStruct final {
     19  PRFuncPtr* symPointer;
     20  std::array<const char*, 6> symNames;
     21 };
     22 
     23 void ClearSymbols(const SymLoadStruct* firstStruct);
     24 
     25 class SymbolLoader final {
     26 public:
     27  typedef PRFuncPtr(GLAPIENTRY* GetProcAddressT)(const char*);
     28 
     29  GetProcAddressT mPfn = nullptr;  // Try this first, if not null.
     30  PRLibrary* mLib = nullptr;
     31 
     32  explicit SymbolLoader(void*(GLAPIENTRY* pfn)(const char*))
     33      : mPfn(GetProcAddressT(pfn)) {
     34    MOZ_ASSERT(mPfn);
     35  }
     36 
     37  explicit SymbolLoader(const GetProcAddressT pfn) : mPfn(pfn) {
     38    MOZ_ASSERT(mPfn);
     39  }
     40 
     41  explicit SymbolLoader(PRLibrary& lib) : mLib(&lib) { MOZ_ASSERT(mLib); }
     42 
     43  PRFuncPtr GetProcAddress(const char*) const;
     44  bool LoadSymbols(const SymLoadStruct* firstStruct,
     45                   bool warnOnFailures = true) const;
     46 };
     47 
     48 }  // namespace gl
     49 }  // namespace mozilla
     50 
     51 #endif  // GLLIBRARYLOADER_H_