reformat code
This commit is contained in:
parent
2432c6fbdf
commit
720de00eb7
1 changed files with 58 additions and 67 deletions
|
@ -1,23 +1,20 @@
|
||||||
#include "nvapi.h"
|
#include "nvapi.h"
|
||||||
|
|
||||||
// TODO: remove
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <libloaderapi.h>
|
# include <libloaderapi.h>
|
||||||
#elif __linux__
|
#elif __linux__
|
||||||
#include <dlfcn.h>
|
# include <dlfcn.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/////
|
/////
|
||||||
|
|
||||||
static void* lib;
|
static void * lib;
|
||||||
|
|
||||||
static bool load_success;
|
static bool load_success;
|
||||||
|
|
||||||
typedef void* (*nvapi_QueryInterface_t)(int);
|
typedef void * (*nvapi_QueryInterface_t)(int);
|
||||||
typedef int (*NvAPI_EnumPhysicalGPUs_t)(void*, void*);
|
typedef int (*NvAPI_EnumPhysicalGPUs_t)(void *, void *);
|
||||||
typedef int (*NvAPI_GPU_SetForcePstate_t)(void*, int, int);
|
typedef int (*NvAPI_GPU_SetForcePstate_t)(void *, int, int);
|
||||||
typedef int (*NvAPI_Initialize_t)();
|
typedef int (*NvAPI_Initialize_t)();
|
||||||
typedef int (*NvAPI_Unload_t)();
|
typedef int (*NvAPI_Unload_t)();
|
||||||
|
|
||||||
|
@ -31,7 +28,7 @@ static NvAPI_Unload_t NvAPI_Unload;
|
||||||
|
|
||||||
void nvapi_init() {
|
void nvapi_init() {
|
||||||
// load library
|
// load library
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
if (!lib) {
|
if (!lib) {
|
||||||
lib = LoadLibrary("nvapi64.dll");
|
lib = LoadLibrary("nvapi64.dll");
|
||||||
}
|
}
|
||||||
|
@ -39,7 +36,7 @@ void nvapi_init() {
|
||||||
if (!lib) {
|
if (!lib) {
|
||||||
lib = LoadLibrary("nvapi.dll");
|
lib = LoadLibrary("nvapi.dll");
|
||||||
}
|
}
|
||||||
#elif __linux__
|
#elif __linux__
|
||||||
if (!lib) {
|
if (!lib) {
|
||||||
lib = dlopen("libnvidia-api.so.1", RTLD_LAZY);
|
lib = dlopen("libnvidia-api.so.1", RTLD_LAZY);
|
||||||
}
|
}
|
||||||
|
@ -47,19 +44,15 @@ void nvapi_init() {
|
||||||
if (!lib) {
|
if (!lib) {
|
||||||
lib = dlopen("libnvidia-api.so", RTLD_LAZY);
|
lib = dlopen("libnvidia-api.so", RTLD_LAZY);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// lookup QueryInterface
|
// lookup QueryInterface
|
||||||
if (lib) {
|
if (lib) {
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
if (!nvapi_QueryInterface) {
|
|
||||||
nvapi_QueryInterface = (nvapi_QueryInterface_t) GetProcAddress(lib, "nvapi_QueryInterface");
|
nvapi_QueryInterface = (nvapi_QueryInterface_t) GetProcAddress(lib, "nvapi_QueryInterface");
|
||||||
}
|
#elif __linux__
|
||||||
#elif __linux__
|
|
||||||
if (!nvapi_QueryInterface) {
|
|
||||||
nvapi_QueryInterface = (nvapi_QueryInterface_t) dlsym(lib, "nvapi_QueryInterface");
|
nvapi_QueryInterface = (nvapi_QueryInterface_t) dlsym(lib, "nvapi_QueryInterface");
|
||||||
}
|
#endif
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// resolve functions
|
// resolve functions
|
||||||
|
@ -83,15 +76,13 @@ void nvapi_free() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// free library
|
// free library
|
||||||
#ifdef _WIN32
|
|
||||||
if (lib) {
|
if (lib) {
|
||||||
|
#ifdef _WIN32
|
||||||
FreeLibrary(lib);
|
FreeLibrary(lib);
|
||||||
}
|
#elif __linux__
|
||||||
#elif __linux__
|
|
||||||
if (lib) {
|
|
||||||
dlclose(lib);
|
dlclose(lib);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
// invalidate pointers
|
// invalidate pointers
|
||||||
lib = nullptr;
|
lib = nullptr;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue