Bug 1442275 - Stop using PR_LoadLibrary in gfx/. r=jgilbert draft
authorMasatoshi Kimura <VYV03354@nifty.ne.jp>
Sun, 25 Feb 2018 01:33:57 +0900
changeset 791082 a15f5f757ce4e6b48b904914ceb6b715877c570d
parent 791081 9155cc62101da835424735c2f18f59f6cac5ddb6
push id108682
push userVYV03354@nifty.ne.jp
push dateThu, 03 May 2018 12:46:41 +0000
reviewersjgilbert
bugs1442275
milestone61.0a1
Bug 1442275 - Stop using PR_LoadLibrary in gfx/. r=jgilbert MozReview-Commit-ID: LNZtr4NVFYj
gfx/gl/GLContextProviderWGL.cpp
gfx/gl/GLLibraryLoader.h
gfx/vr/gfxVROSVR.cpp
gfx/vr/gfxVROculus.cpp
--- a/gfx/gl/GLContextProviderWGL.cpp
+++ b/gfx/gl/GLContextProviderWGL.cpp
@@ -78,24 +78,25 @@ HasExtension(const char* aExtensions, co
 bool
 WGLLibrary::EnsureInitialized()
 {
     if (mInitialized)
         return true;
 
     mozilla::ScopedGfxFeatureReporter reporter("WGL");
 
-    std::string libGLFilename = "Opengl32.dll";
+    std::wstring libGLFilename = L"Opengl32.dll";
     // SU_SPIES_DIRECTORY is for AMD CodeXL/gDEBugger
-    if (PR_GetEnv("SU_SPIES_DIRECTORY")) {
-        libGLFilename = std::string(PR_GetEnv("SU_SPIES_DIRECTORY")) + "\\opengl32.dll";
+    if (_wgetenv(L"SU_SPIES_DIRECTORY")) {
+        libGLFilename = std::wstring(_wgetenv(L"SU_SPIES_DIRECTORY")) +
+                        L"\\opengl32.dll";
     }
 
     if (!mOGLLibrary) {
-        mOGLLibrary = PR_LoadLibrary(libGLFilename.c_str());
+        mOGLLibrary = LoadLibraryWithFlags(libGLFilename.c_str());
         if (!mOGLLibrary) {
             NS_WARNING("Couldn't load OpenGL library.");
             return false;
         }
     }
 
 #define SYMBOL(X) { (PRFuncPtr*)&mSymbols.f##X, { "wgl" #X, nullptr } }
 #define END_OF_SYMBOLS { nullptr, { nullptr } }
--- a/gfx/gl/GLLibraryLoader.h
+++ b/gfx/gl/GLLibraryLoader.h
@@ -4,17 +4,17 @@
 
 #ifndef GLLIBRARYLOADER_H_
 #define GLLIBRARYLOADER_H_
 
 #include <stdio.h>
 
 #include "GLDefs.h"
 #include "nscore.h"
-#include "prlink.h"
+#include "mozilla/SharedLibrary.h"
 
 namespace mozilla {
 namespace gl {
 
 class GLLibraryLoader
 {
 public:
     bool OpenLibrary(const char* library);
--- a/gfx/vr/gfxVROSVR.cpp
+++ b/gfx/vr/gfxVROSVR.cpp
@@ -1,21 +1,21 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include <math.h>
 
-#include "prlink.h"
 #include "prenv.h"
 #include "gfxPrefs.h"
 #include "nsString.h"
 #include "mozilla/Preferences.h"
+#include "mozilla/SharedLibrary.h"
 
 #include "mozilla/gfx/Quaternion.h"
 
 #ifdef XP_WIN
 #include "../layers/d3d11/CompositorD3D11.h"
 #include "../layers/d3d11/TextureD3D11.h"
 #endif
 
@@ -112,32 +112,38 @@ bool
 LoadOSVRRuntime()
 {
   static PRLibrary* osvrUtilLib = nullptr;
   static PRLibrary* osvrCommonLib = nullptr;
   static PRLibrary* osvrClientLib = nullptr;
   static PRLibrary* osvrClientKitLib = nullptr;
   //this looks up the path in the about:config setting, from greprefs.js or modules\libpref\init\all.js
   //we need all the libs to be valid
+#ifdef XP_WIN
+  constexpr static auto* pfnGetPathStringPref = mozilla::Preferences::GetString;
+  nsAutoString osvrUtilPath, osvrCommonPath, osvrClientPath, osvrClientKitPath;
+#else
+  constexpr static auto* pfnGetPathStringPref = mozilla::Preferences::GetCString;
   nsAutoCString osvrUtilPath, osvrCommonPath, osvrClientPath, osvrClientKitPath;
-  if (NS_FAILED(mozilla::Preferences::GetCString("gfx.vr.osvr.utilLibPath",
-                                                 osvrUtilPath)) ||
-      NS_FAILED(mozilla::Preferences::GetCString("gfx.vr.osvr.commonLibPath",
-                                                 osvrCommonPath)) ||
-      NS_FAILED(mozilla::Preferences::GetCString("gfx.vr.osvr.clientLibPath",
-                                                 osvrClientPath)) ||
-      NS_FAILED(mozilla::Preferences::GetCString("gfx.vr.osvr.clientKitLibPath",
-                                                 osvrClientKitPath))) {
+#endif
+  if (NS_FAILED(pfnGetPathStringPref("gfx.vr.osvr.utilLibPath",
+                                     osvrUtilPath, PrefValueKind::User)) ||
+      NS_FAILED(pfnGetPathStringPref("gfx.vr.osvr.commonLibPath",
+                                     osvrCommonPath, PrefValueKind::User)) ||
+      NS_FAILED(pfnGetPathStringPref("gfx.vr.osvr.clientLibPath",
+                                     osvrClientPath, PrefValueKind::User)) ||
+      NS_FAILED(pfnGetPathStringPref("gfx.vr.osvr.clientKitLibPath",
+                                     osvrClientKitPath, PrefValueKind::User))) {
     return false;
   }
 
-  osvrUtilLib = PR_LoadLibrary(osvrUtilPath.BeginReading());
-  osvrCommonLib = PR_LoadLibrary(osvrCommonPath.BeginReading());
-  osvrClientLib = PR_LoadLibrary(osvrClientPath.BeginReading());
-  osvrClientKitLib = PR_LoadLibrary(osvrClientKitPath.BeginReading());
+  osvrUtilLib = LoadLibraryWithFlags(osvrUtilPath.get());
+  osvrCommonLib = LoadLibraryWithFlags(osvrCommonPath.get());
+  osvrClientLib = LoadLibraryWithFlags(osvrClientPath.get());
+  osvrClientKitLib = LoadLibraryWithFlags(osvrClientKitPath.get());
 
   if (!osvrUtilLib) {
     printf_stderr("[OSVR] Failed to load OSVR Util library!\n");
     return false;
   }
   if (!osvrCommonLib) {
     printf_stderr("[OSVR] Failed to load OSVR Common library!\n");
     return false;
--- a/gfx/vr/gfxVROculus.cpp
+++ b/gfx/vr/gfxVROculus.cpp
@@ -6,22 +6,22 @@
 
 #ifndef XP_WIN
 #error "Oculus 1.3 runtime support only available for Windows"
 #endif
 
 #include <math.h>
 
 
-#include "prlink.h"
 #include "prenv.h"
 #include "gfxPrefs.h"
 #include "nsString.h"
 #include "mozilla/DebugOnly.h"
 #include "mozilla/Preferences.h"
+#include "mozilla/SharedLibrary.h"
 #include "mozilla/TimeStamp.h"
 #include "mozilla/gfx/DeviceManagerDx.h"
 #include "mozilla/layers/CompositorThread.h"
 #include "ipc/VRLayerParent.h"
 
 #include "mozilla/gfx/Quaternion.h"
 
 #include <d3d11.h>
@@ -615,61 +615,62 @@ VROculusSession::StartSession()
 
 bool
 VROculusSession::LoadOvrLib()
 {
   if (mOvrLib) {
     // Already loaded, early exit
     return true;
   }
-  nsTArray<nsCString> libSearchPaths;
-  nsCString libName;
-  nsCString searchPath;
+#if defined(_WIN32)
+  nsTArray<nsString> libSearchPaths;
+  nsString libName;
+  nsString searchPath;
 
-#if defined(_WIN32)
   static const char dirSep = '\\';
   static const int pathLen = 260;
   searchPath.SetCapacity(pathLen);
-  int realLen = ::GetSystemDirectoryA(searchPath.BeginWriting(), pathLen);
+  int realLen = ::GetSystemDirectoryW(char16ptr_t(searchPath.BeginWriting()),
+                                      pathLen);
   if (realLen != 0 && realLen < pathLen) {
     searchPath.SetLength(realLen);
     libSearchPaths.AppendElement(searchPath);
   }
   libName.AppendPrintf("LibOVRRT%d_%d.dll", BUILD_BITS, OVR_PRODUCT_VERSION);
-#else
-#error "Unsupported platform!"
-#endif
 
   // search the path/module dir
-  libSearchPaths.InsertElementsAt(0, 1, nsCString());
+  libSearchPaths.InsertElementsAt(0, 1, EmptyString());
 
   // If the env var is present, we override libName
-  if (PR_GetEnv("OVR_LIB_PATH")) {
-    searchPath = PR_GetEnv("OVR_LIB_PATH");
+  if (_wgetenv(L"OVR_LIB_PATH")) {
+    searchPath = _wgetenv(L"OVR_LIB_PATH");
     libSearchPaths.InsertElementsAt(0, 1, searchPath);
   }
 
-  if (PR_GetEnv("OVR_LIB_NAME")) {
-    libName = PR_GetEnv("OVR_LIB_NAME");
+  if (_wgetenv(L"OVR_LIB_NAME")) {
+    libName = _wgetenv(L"OVR_LIB_NAME");
   }
 
   for (uint32_t i = 0; i < libSearchPaths.Length(); ++i) {
-    nsCString& libPath = libSearchPaths[i];
-    nsCString fullName;
+    nsString& libPath = libSearchPaths[i];
+    nsString fullName;
     if (libPath.Length() == 0) {
       fullName.Assign(libName);
     } else {
-      fullName.AppendPrintf("%s%c%s", libPath.BeginReading(), dirSep, libName.BeginReading());
+      fullName.AppendPrintf("%s%c%s", libPath.get(), dirSep, libName.get());
     }
 
-    mOvrLib = PR_LoadLibrary(fullName.BeginReading());
+    mOvrLib = LoadLibraryWithFlags(fullName.get());
     if (mOvrLib) {
       break;
     }
   }
+#else
+#error "Unsupported platform!"
+#endif
 
   if (!mOvrLib) {
     return false;
   }
 
 #define REQUIRE_FUNCTION(_x) do { \
     *(void **)&_x = (void *) PR_FindSymbol(mOvrLib, #_x);                \
     if (!_x) { printf_stderr(#_x " symbol missing\n"); goto fail; }       \