Module: Mesa
Branch: master
Commit: 65c2abf6fdd51b0a80a72caa0c52cf3f4578e743
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=65c2abf6fdd51b0a80a72caa0c52cf3f4578e743

Author: Tim Rowley <timothy.o.row...@intel.com>
Date:   Thu May 12 18:12:55 2016 -0600

swr: [rasterizer] utility functions for shared libs

Reviewed-by: Bruce Cherniak <bruce.chern...@intel.com>

---

 src/gallium/drivers/swr/rasterizer/core/utils.h    | 65 +++++++++++++++++++++-
 .../drivers/swr/rasterizer/jitter/jit_api.h        |  1 +
 2 files changed, 64 insertions(+), 2 deletions(-)

diff --git a/src/gallium/drivers/swr/rasterizer/core/utils.h 
b/src/gallium/drivers/swr/rasterizer/core/utils.h
index bf53c69..a5b004c 100644
--- a/src/gallium/drivers/swr/rasterizer/core/utils.h
+++ b/src/gallium/drivers/swr/rasterizer/core/utils.h
@@ -867,7 +867,7 @@ struct TemplateArgUnroller
 };
 
 //////////////////////////////////////////////////////////////////////////
-/// Helper used to get an environment variable
+/// Helpers used to get / set environment variable
 //////////////////////////////////////////////////////////////////////////
 static INLINE std::string GetEnv(const std::string& variableName)
 {
@@ -882,4 +882,65 @@ static INLINE std::string GetEnv(const std::string& 
variableName)
 #endif
 
     return output;
-}
\ No newline at end of file
+}
+
+static INLINE void SetEnv(const std::string& variableName, const std::string& 
value)
+{
+#if defined(_WIN32)
+    SetEnvironmentVariableA(variableName.c_str(), value.c_str());
+#else
+    setenv(variableName.c_str(), value.c_str(), true);
+#endif
+}
+
+//////////////////////////////////////////////////////////////////////////
+/// Abstraction for dynamically loading modules and getting functions
+//////////////////////////////////////////////////////////////////////////
+#if defined(_WIN32)
+typedef HMODULE SWR_MODULE_HANDLE;
+#else
+#include <dlfcn.h>
+typedef void* SWR_MODULE_HANDLE;
+#endif
+
+static inline SWR_MODULE_HANDLE SWR_API LoadModule(const char* szModuleName)
+{
+#if defined(_WIN32)
+    return LoadLibraryA(szModuleName);
+#else
+    return dlopen(szModuleName, RTLD_LAZY | RTLD_LOCAL);
+#endif
+}
+
+static inline void SWR_API FreeModuleHandle(SWR_MODULE_HANDLE hModule)
+{
+    if (hModule)
+    {
+#if defined(_WIN32)
+        FreeLibrary((HMODULE)hModule);
+#else
+        dlclose(hModule);
+#endif
+    }
+}
+
+static inline void* SWR_API GetProcFromModule(SWR_MODULE_HANDLE hModule, const 
char* szProcName)
+{
+    if (hModule && szProcName)
+    {
+#if defined(_WIN32)
+        return GetProcAddress((HMODULE)hModule, szProcName);
+#else
+        return dlsym(hModule, szProcName);
+#endif
+    }
+
+    return nullptr;
+}
+ 
+template<typename T>
+static inline void GetProcFromModule(SWR_MODULE_HANDLE hModule, const char* 
szProcName, T& outFunc)
+{
+    outFunc = (T)GetProcFromModule(hModule, szProcName);
+}
+
diff --git a/src/gallium/drivers/swr/rasterizer/jitter/jit_api.h 
b/src/gallium/drivers/swr/rasterizer/jitter/jit_api.h
index 08261e7..f5c27f0 100644
--- a/src/gallium/drivers/swr/rasterizer/jitter/jit_api.h
+++ b/src/gallium/drivers/swr/rasterizer/jitter/jit_api.h
@@ -29,6 +29,7 @@
 ******************************************************************************/
 #pragma once
 #include "common/os.h"
+#include "core/utils.h"
 
 #include "fetch_jit.h"
 #include "streamout_jit.h"

_______________________________________________
mesa-commit mailing list
mesa-commit@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-commit

Reply via email to