diff --git a/CMakeLists.txt b/CMakeLists.txt index a63ca1288..02cea2256 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -61,7 +61,7 @@ cmake_dependent_option(ENABLE_IMAGEMAGICK7 "Enable imagemagick 7" ON "LINUX OR B cmake_dependent_option(ENABLE_IMAGEMAGICK6 "Enable imagemagick 6" ON "LINUX OR BSD OR APPLE OR SunOS" OFF) cmake_dependent_option(ENABLE_CHAFA "Enable chafa" ON "ENABLE_IMAGEMAGICK6 OR ENABLE_IMAGEMAGICK7" OFF) cmake_dependent_option(ENABLE_ZLIB "Enable zlib" ON "ENABLE_IMAGEMAGICK6 OR ENABLE_IMAGEMAGICK7" OFF) -cmake_dependent_option(ENABLE_EGL "Enable egl" ON "LINUX OR BSD OR SunOS" OFF) +cmake_dependent_option(ENABLE_EGL "Enable egl" ON "LINUX OR BSD OR WIN32 OR SunOS" OFF) cmake_dependent_option(ENABLE_GLX "Enable glx" ON "LINUX OR BSD OR SunOS" OFF) cmake_dependent_option(ENABLE_OSMESA "Enable osmesa" ON "LINUX OR BSD OR SunOS" OFF) cmake_dependent_option(ENABLE_OPENCL "Enable opencl" ON "LINUX OR BSD OR WIN32 OR ANDROID OR SunOS" OFF) @@ -307,6 +307,7 @@ set(LIBFASTFETCH_SRC src/detection/media/media.c src/detection/netio/netio.c src/detection/opencl/opencl.c + src/detection/opengl/opengl_shared.c src/detection/os/os.c src/detection/packages/packages.c src/detection/physicalmemory/physicalmemory.c diff --git a/src/detection/opengl/opengl.h b/src/detection/opengl/opengl.h index b8d5ce787..466dcf256 100644 --- a/src/detection/opengl/opengl.h +++ b/src/detection/opengl/opengl.h @@ -11,4 +11,7 @@ typedef struct FFOpenGLResult FFstrbuf library; } FFOpenGLResult; +#define FF_OPENGL_BUFFER_WIDTH 1 +#define FF_OPENGL_BUFFER_HEIGHT 1 + const char* ffDetectOpenGL(FFOpenGLOptions* options, FFOpenGLResult* result); diff --git a/src/detection/opengl/opengl_apple.c b/src/detection/opengl/opengl_apple.c index db3be29d2..c6b56f07f 100644 --- a/src/detection/opengl/opengl_apple.c +++ b/src/detection/opengl/opengl_apple.c @@ -6,24 +6,18 @@ #include #include // This brings in CGL, not GL -static void glHandleResult(FFOpenGLResult* result) -{ - ffStrbufAppendS(&result->version, (const char*) glGetString(GL_VERSION)); - ffStrbufAppendS(&result->renderer, (const char*) glGetString(GL_RENDERER)); - ffStrbufAppendS(&result->vendor, (const char*) glGetString(GL_VENDOR)); - ffStrbufAppendS(&result->slv, (const char*) glGetString(GL_SHADING_LANGUAGE_VERSION)); - - GLint major, minor; - CGLGetVersion(&major, &minor); - ffStrbufAppendF(&result->library, "CGL %d.%d", major, minor); -} +void ffOpenGLHandleResult(FFOpenGLResult* result, __typeof__(&glGetString) ffglGetString); static const char* cglHandleContext(FFOpenGLResult* result, CGLContextObj context) { if(CGLSetCurrentContext(context) != kCGLNoError) return "CGLSetCurrentContext() failed"; - glHandleResult(result); + ffOpenGLHandleResult(result, &glGetString); + + GLint major, minor; + CGLGetVersion(&major, &minor); + ffStrbufSetF(&result->library, "CGL %d.%d", major, minor); return NULL; } diff --git a/src/detection/opengl/opengl_linux.c b/src/detection/opengl/opengl_linux.c index bd0d50e41..4a417bace 100644 --- a/src/detection/opengl/opengl_linux.c +++ b/src/detection/opengl/opengl_linux.c @@ -10,147 +10,17 @@ #include -#define FF_OPENGL_BUFFER_WIDTH 1 -#define FF_OPENGL_BUFFER_HEIGHT 1 - -typedef struct GLData -{ - FF_LIBRARY_SYMBOL(glGetString) -} GLData; - -static void glHandleResult(FFOpenGLResult* result, const GLData* data) -{ - ffStrbufAppendS(&result->version, (const char*) data->ffglGetString(GL_VERSION)); - ffStrbufAppendS(&result->renderer, (const char*) data->ffglGetString(GL_RENDERER)); - ffStrbufAppendS(&result->vendor, (const char*) data->ffglGetString(GL_VENDOR)); - ffStrbufAppendS(&result->slv, (const char*) data->ffglGetString(GL_SHADING_LANGUAGE_VERSION)); -} +void ffOpenGLHandleResult(FFOpenGLResult* result, __typeof__(&glGetString) ffglGetString); #endif // FF_HAVE_GL -#ifdef FF_HAVE_EGL -#include "common/io/io.h" - -#include - -typedef struct EGLData -{ - GLData glData; - - FF_LIBRARY_SYMBOL(eglGetProcAddress) - FF_LIBRARY_SYMBOL(eglGetDisplay) - FF_LIBRARY_SYMBOL(eglQueryString) - FF_LIBRARY_SYMBOL(eglInitialize) - FF_LIBRARY_SYMBOL(eglBindAPI) - FF_LIBRARY_SYMBOL(eglGetConfigs) - FF_LIBRARY_SYMBOL(eglCreatePbufferSurface) - FF_LIBRARY_SYMBOL(eglCreateContext) - FF_LIBRARY_SYMBOL(eglMakeCurrent) - FF_LIBRARY_SYMBOL(eglDestroyContext) - FF_LIBRARY_SYMBOL(eglDestroySurface) - FF_LIBRARY_SYMBOL(eglTerminate) - - EGLDisplay display; - EGLConfig config; - EGLSurface surface; - EGLContext context; -} EGLData; - -static const char* eglHandleContext(FFOpenGLResult* result, EGLData* data) -{ - if(data->ffeglMakeCurrent(data->display, data->surface, data->surface, data->context) != EGL_TRUE) - return "eglMakeCurrent returned EGL_FALSE"; - - glHandleResult(result, &data->glData); - ffStrbufSetF(&result->library, "EGL %s", data->ffeglQueryString(data->display, EGL_VERSION)); - return NULL; -} - -static const char* eglHandleSurface(FFOpenGLResult* result, EGLData* data) -{ - data->context = data->ffeglCreateContext(data->display, data->config, EGL_NO_CONTEXT, (EGLint[]){EGL_NONE}); - if(data->context == EGL_NO_CONTEXT) - return "eglCreateContext returned EGL_NO_CONTEXT"; - - const char* error = eglHandleContext(result, data); - data->ffeglDestroyContext(data->display, data->context); - return error; -} - -static const char* eglHandleDisplay(FFOpenGLResult* result, EGLData* data) -{ - if(data->ffeglBindAPI(EGL_OPENGL_API) != EGL_TRUE) - return "eglBindAPI returned EGL_FALSE"; - - EGLint eglConfigCount; - data->ffeglGetConfigs(data->display, &data->config, 1, &eglConfigCount); - if(eglConfigCount == 0) - return "eglGetConfigs returned 0 configs"; - - data->surface = data->ffeglCreatePbufferSurface(data->display, data->config, (EGLint[]){ - EGL_WIDTH, FF_OPENGL_BUFFER_WIDTH, - EGL_HEIGHT, FF_OPENGL_BUFFER_HEIGHT, - EGL_NONE - }); - - if(data->surface == EGL_NO_SURFACE) - return "eglCreatePbufferSurface returned EGL_NO_SURFACE"; - - const char* error = eglHandleSurface(result, data); - data->ffeglDestroySurface(data->display, data->surface); - return error; -} - -static const char* eglHandleData(FFOpenGLResult* result, EGLData* data) -{ - data->glData.ffglGetString = (__typeof__(data->glData.ffglGetString)) data->ffeglGetProcAddress("glGetString"); - if(!data->glData.ffglGetString) - return "eglGetProcAddress(glGetString) returned NULL"; - - data->display = data->ffeglGetDisplay(EGL_DEFAULT_DISPLAY); - if(data->display == EGL_NO_DISPLAY) - return "eglGetDisplay returned EGL_NO_DISPLAY"; - - EGLint major, minor; - if(data->ffeglInitialize(data->display, &major, &minor) == EGL_FALSE) - return "eglInitialize returned EGL_FALSE"; - - const char* error = eglHandleDisplay(result, data); - data->ffeglTerminate(data->display); - return error; -} - -static const char* eglPrint(FFOpenGLResult* result) -{ - EGLData eglData; - - FF_LIBRARY_LOAD(egl, &instance.config.library.libEGL, "dlopen egl failed", "libEGL" FF_LIBRARY_EXTENSION, 1); - FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(egl, eglData, eglGetProcAddress); - FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(egl, eglData, eglGetDisplay); - FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(egl, eglData, eglQueryString); - FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(egl, eglData, eglInitialize); - FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(egl, eglData, eglBindAPI); - FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(egl, eglData, eglGetConfigs); - FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(egl, eglData, eglCreatePbufferSurface); - FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(egl, eglData, eglCreateContext); - FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(egl, eglData, eglMakeCurrent); - FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(egl, eglData, eglDestroyContext); - FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(egl, eglData, eglDestroySurface); - FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(egl, eglData, eglTerminate); - - FF_SUPPRESS_IO(); - return eglHandleData(result, &eglData); -} - -#endif //FF_HAVE_EGL #ifdef FF_HAVE_GLX #include typedef struct GLXData { - GLData glData; - + FF_LIBRARY_SYMBOL(glGetString) FF_LIBRARY_SYMBOL(glXGetProcAddress) FF_LIBRARY_SYMBOL(glXQueryVersion) FF_LIBRARY_SYMBOL(XOpenDisplay) @@ -176,7 +46,7 @@ static const char* glxHandleContext(FFOpenGLResult* result, GLXData* data) { if(data->ffglXMakeCurrent(data->display, data->glxPixmap, data->context) != True) return "glXMakeCurrent returned False"; - glHandleResult(result, &data->glData); + ffOpenGLHandleResult(result, data->ffglGetString); int major, minor; if (data->ffglXQueryVersion(data->display, &major, &minor)) @@ -233,8 +103,8 @@ static const char* glxHandleDisplay(FFOpenGLResult* result, GLXData* data) static const char* glxHandleData(FFOpenGLResult* result, GLXData* data) { - data->glData.ffglGetString = (__typeof__(data->glData.ffglGetString)) data->ffglXGetProcAddress((const GLubyte*) "glGetString"); - if(data->glData.ffglGetString == NULL) + data->ffglGetString = (__typeof__(data->ffglGetString)) data->ffglXGetProcAddress((const GLubyte*) "glGetString"); + if(data->ffglGetString == NULL) return "glXGetProcAddress(glGetString) returned NULL"; data->display = data->ffXOpenDisplay(NULL); @@ -246,7 +116,7 @@ static const char* glxHandleData(FFOpenGLResult* result, GLXData* data) return error; } -static const char* glxPrint(FFOpenGLResult* result) +static const char* detectByGlx(FFOpenGLResult* result) { GLXData data; @@ -279,8 +149,7 @@ static const char* glxPrint(FFOpenGLResult* result) typedef struct OSMesaData { - GLData glData; - + FF_LIBRARY_SYMBOL(glGetString) FF_LIBRARY_SYMBOL(OSMesaGetProcAddress) FF_LIBRARY_SYMBOL(OSMesaCreateContext) FF_LIBRARY_SYMBOL(OSMesaMakeCurrent) @@ -296,16 +165,15 @@ static const char* osMesaHandleContext(FFOpenGLResult* result, OSMesaData* data) if(data->ffOSMesaMakeCurrent(data->context, buffer, GL_UNSIGNED_BYTE, FF_OPENGL_BUFFER_WIDTH, FF_OPENGL_BUFFER_HEIGHT) != GL_TRUE) return "OSMesaMakeCurrent returned GL_FALSE"; - glHandleResult(result, &data->glData); + ffOpenGLHandleResult(result, data->ffglGetString); ffStrbufSetF(&result->library, "OSMesa %d.%d.%d", OSMESA_MAJOR_VERSION, OSMESA_MINOR_VERSION, OSMESA_PATCH_VERSION); return NULL; } static const char* osMesaHandleData(FFOpenGLResult* result, OSMesaData* data) { - //The case to void* is required here, because OSMESAproc can't be cast to (__typeof__(data->glData.ffglGetString)) without a warning, even though it is the actual type. - data->glData.ffglGetString = (__typeof__(data->glData.ffglGetString)) (void*) data->ffOSMesaGetProcAddress("glGetString"); - if(data->glData.ffglGetString == NULL) + data->ffglGetString = (void*) data->ffOSMesaGetProcAddress("glGetString"); + if(data->ffglGetString == NULL) return "OSMesaGetProcAddress(glGetString) returned NULL"; data->context = data->ffOSMesaCreateContext(OSMESA_RGBA, NULL); @@ -317,7 +185,7 @@ static const char* osMesaHandleData(FFOpenGLResult* result, OSMesaData* data) return error; } -static const char* osMesaPrint(FFOpenGLResult* result) +static const char* detectByOsMesa(FFOpenGLResult* result) { OSMesaData data; @@ -339,7 +207,7 @@ const char* ffDetectOpenGL(FFOpenGLOptions* options, FFOpenGLResult* result) if(options->library == FF_OPENGL_LIBRARY_GLX) { #ifdef FF_HAVE_GLX - return glxPrint(result); + return detectByGlx(result); #else return "fastfetch was compiled without glx support"; #endif @@ -348,7 +216,8 @@ const char* ffDetectOpenGL(FFOpenGLOptions* options, FFOpenGLResult* result) if(options->library == FF_OPENGL_LIBRARY_EGL) { #ifdef FF_HAVE_EGL - return eglPrint(result); + const char* ffOpenGLDetectByEGL(FFOpenGLResult* result); + return ffOpenGLDetectByEGL(result); #else return "fastfetch was compiled without egl support"; #endif @@ -357,7 +226,7 @@ const char* ffDetectOpenGL(FFOpenGLOptions* options, FFOpenGLResult* result) if(options->library == FF_OPENGL_LIBRARY_OSMESA) { #ifdef FF_HAVE_OSMESA - return osMesaPrint(result); + return detectByOsMesa(result); #else return "fastfetch was compiled without osmesa support"; #endif @@ -366,12 +235,13 @@ const char* ffDetectOpenGL(FFOpenGLOptions* options, FFOpenGLResult* result) const char* error = ""; // not NULL dummy value #ifdef FF_HAVE_EGL - error = eglPrint(result); + const char* ffOpenGLDetectByEGL(FFOpenGLResult* result); + error = ffOpenGLDetectByEGL(result); #endif #ifdef FF_HAVE_GLX if(error != NULL) - error = glxPrint(result); + error = detectByGlx(result); #endif //We don't use osmesa in auto mode here, because it is a software implementation, diff --git a/src/detection/opengl/opengl_shared.c b/src/detection/opengl/opengl_shared.c new file mode 100644 index 000000000..f8e190dc3 --- /dev/null +++ b/src/detection/opengl/opengl_shared.c @@ -0,0 +1,148 @@ +#include "opengl.h" +#include "common/library.h" + +#if __has_include() +#include +#elif __has_include() +#define GL_SILENCE_DEPRECATION 1 +#include +#else +#define FF_HAVE_NO_GL 1 +#endif + +#ifndef FF_HAVE_NO_GL + +#ifndef GL_SHADING_LANGUAGE_VERSION // For WGL + #define GL_SHADING_LANGUAGE_VERSION 0x8B8C +#endif + +void ffOpenGLHandleResult(FFOpenGLResult* result, __typeof__(&glGetString) ffglGetString) +{ + ffStrbufAppendS(&result->version, (const char*) ffglGetString(GL_VERSION)); + ffStrbufAppendS(&result->renderer, (const char*) ffglGetString(GL_RENDERER)); + ffStrbufAppendS(&result->vendor, (const char*) ffglGetString(GL_VENDOR)); + ffStrbufAppendS(&result->slv, (const char*) ffglGetString(GL_SHADING_LANGUAGE_VERSION)); +} + +#if defined(FF_HAVE_EGL) || __has_include() +#include "common/io/io.h" + +#include + +typedef struct EGLData +{ + FF_LIBRARY_SYMBOL(glGetString) + FF_LIBRARY_SYMBOL(eglGetProcAddress) + FF_LIBRARY_SYMBOL(eglGetDisplay) + FF_LIBRARY_SYMBOL(eglQueryString) + FF_LIBRARY_SYMBOL(eglInitialize) + FF_LIBRARY_SYMBOL(eglBindAPI) + FF_LIBRARY_SYMBOL(eglGetConfigs) + FF_LIBRARY_SYMBOL(eglCreatePbufferSurface) + FF_LIBRARY_SYMBOL(eglCreateContext) + FF_LIBRARY_SYMBOL(eglMakeCurrent) + FF_LIBRARY_SYMBOL(eglDestroyContext) + FF_LIBRARY_SYMBOL(eglDestroySurface) + FF_LIBRARY_SYMBOL(eglTerminate) + + EGLDisplay display; + EGLConfig config; + EGLSurface surface; + EGLContext context; +} EGLData; + +static const char* eglHandleContext(FFOpenGLResult* result, EGLData* data) +{ + if(data->ffeglMakeCurrent(data->display, data->surface, data->surface, data->context) != EGL_TRUE) + return "eglMakeCurrent returned EGL_FALSE"; + + ffOpenGLHandleResult(result, data->ffglGetString); + ffStrbufSetF(&result->library, "EGL %s", data->ffeglQueryString(data->display, EGL_VERSION)); + return NULL; +} + +static const char* eglHandleSurface(FFOpenGLResult* result, EGLData* data) +{ + data->context = data->ffeglCreateContext(data->display, data->config, EGL_NO_CONTEXT, (EGLint[]){EGL_NONE}); + if(data->context == EGL_NO_CONTEXT) + return "eglCreateContext returned EGL_NO_CONTEXT"; + + const char* error = eglHandleContext(result, data); + data->ffeglDestroyContext(data->display, data->context); + return error; +} + +static const char* eglHandleDisplay(FFOpenGLResult* result, EGLData* data) +{ + if(data->ffeglBindAPI( + #ifdef _WIN32 + EGL_OPENGL_ES_API + #else + EGL_OPENGL_API + #endif + ) != EGL_TRUE) + return "eglBindAPI returned EGL_FALSE"; + + EGLint eglConfigCount; + data->ffeglGetConfigs(data->display, &data->config, 1, &eglConfigCount); + if(eglConfigCount == 0) + return "eglGetConfigs returned 0 configs"; + + data->surface = data->ffeglCreatePbufferSurface(data->display, data->config, (EGLint[]){ + EGL_WIDTH, FF_OPENGL_BUFFER_WIDTH, + EGL_HEIGHT, FF_OPENGL_BUFFER_HEIGHT, + EGL_NONE + }); + + if(data->surface == EGL_NO_SURFACE) + return "eglCreatePbufferSurface returned EGL_NO_SURFACE"; + + const char* error = eglHandleSurface(result, data); + data->ffeglDestroySurface(data->display, data->surface); + return error; +} + +static const char* eglHandleData(FFOpenGLResult* result, EGLData* data) +{ + data->ffglGetString = (__typeof__(&glGetString)) data->ffeglGetProcAddress("glGetString"); + if(!data->ffglGetString) + return "eglGetProcAddress(glGetString) returned NULL"; + + data->display = data->ffeglGetDisplay(EGL_DEFAULT_DISPLAY); + if(data->display == EGL_NO_DISPLAY) + return "eglGetDisplay returned EGL_NO_DISPLAY"; + + EGLint major, minor; + if(data->ffeglInitialize(data->display, &major, &minor) == EGL_FALSE) + return "eglInitialize returned EGL_FALSE"; + + const char* error = eglHandleDisplay(result, data); + data->ffeglTerminate(data->display); + return error; +} + +const char* ffOpenGLDetectByEGL(FFOpenGLResult* result) +{ + EGLData eglData; + + FF_LIBRARY_LOAD(egl, &instance.config.library.libEGL, "dlopen egl failed", "libEGL" FF_LIBRARY_EXTENSION, 1); + FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(egl, eglData, eglGetProcAddress); + FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(egl, eglData, eglGetDisplay); + FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(egl, eglData, eglQueryString); + FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(egl, eglData, eglInitialize); + FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(egl, eglData, eglBindAPI); + FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(egl, eglData, eglGetConfigs); + FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(egl, eglData, eglCreatePbufferSurface); + FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(egl, eglData, eglCreateContext); + FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(egl, eglData, eglMakeCurrent); + FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(egl, eglData, eglDestroyContext); + FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(egl, eglData, eglDestroySurface); + FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(egl, eglData, eglTerminate); + + FF_SUPPRESS_IO(); + return eglHandleData(result, &eglData); +} + +#endif //FF_HAVE_EGL + +#endif //FF_HAVE_NO_GL diff --git a/src/detection/opengl/opengl_windows.c b/src/detection/opengl/opengl_windows.c index 0ad0d4572..3984c9309 100644 --- a/src/detection/opengl/opengl_windows.c +++ b/src/detection/opengl/opengl_windows.c @@ -4,9 +4,6 @@ #include #include -#ifndef GL_SHADING_LANGUAGE_VERSION // For WGL - #define GL_SHADING_LANGUAGE_VERSION 0x8B8C -#endif typedef struct WGLData { @@ -19,20 +16,14 @@ typedef struct WGLData FF_LIBRARY_SYMBOL(wglDeleteContext) } WGLData; -static void glHandleResult(WGLData* wglData) -{ - ffStrbufAppendS(&wglData->result->version, (const char*) wglData->ffglGetString(GL_VERSION)); - ffStrbufAppendS(&wglData->result->renderer, (const char*) wglData->ffglGetString(GL_RENDERER)); - ffStrbufAppendS(&wglData->result->vendor, (const char*) wglData->ffglGetString(GL_VENDOR)); - ffStrbufAppendS(&wglData->result->slv, (const char*) wglData->ffglGetString(GL_SHADING_LANGUAGE_VERSION)); - ffStrbufSetStatic(&wglData->result->library, "WGL 1.0"); -} +void ffOpenGLHandleResult(FFOpenGLResult* result, __typeof__(&glGetString) ffglGetString); static const char* wglHandleContext(WGLData* wglData, HDC hdc, HGLRC context) { if(wglData->ffwglMakeCurrent(hdc, context) == FALSE) return "wglMakeCurrent() failed"; - glHandleResult(wglData); + ffOpenGLHandleResult(wglData->result, wglData->ffglGetString); + ffStrbufSetStatic(&wglData->result->library, "WGL 1.0"); return NULL; } @@ -88,16 +79,16 @@ static LRESULT CALLBACK wglHandleWndProc(HWND hWnd, UINT message, WPARAM wParam, } } -const char* ffDetectOpenGL(FF_MAYBE_UNUSED FFOpenGLOptions* options, FFOpenGLResult* result) +static const char* wglDetectOpenGL(FFOpenGLResult* result) { FF_LIBRARY_LOAD(opengl32, NULL, "dlopen opengl32" FF_LIBRARY_EXTENSION " failed", "opengl32" FF_LIBRARY_EXTENSION, 1); WGLData data = { .result = result }; - FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(opengl32, data, glGetString); FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(opengl32, data, wglMakeCurrent); FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(opengl32, data, wglCreateContext); FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(opengl32, data, wglDeleteContext); + FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(opengl32, data, glGetString); MSG msg = {0}; WNDCLASSW wc = { @@ -110,10 +101,28 @@ const char* ffDetectOpenGL(FF_MAYBE_UNUSED FFOpenGLOptions* options, FFOpenGLRes if(!RegisterClassW(&wc)) return "RegisterClassW() failed"; - HWND hWnd = CreateWindowW(wc.lpszClassName, L"ogl_version_check", 0, 0, 0, 1, 1, NULL, NULL, NULL, &data); + HWND hWnd = CreateWindowW(wc.lpszClassName, L"ogl_version_check", 0, 0, 0, FF_OPENGL_BUFFER_WIDTH, FF_OPENGL_BUFFER_HEIGHT, NULL, NULL, NULL, &data); while(GetMessageW(&msg, hWnd, 0, 0) > 0) DispatchMessage(&msg); return data.error; } + + +const char* ffDetectOpenGL(FFOpenGLOptions* options, FFOpenGLResult* result) +{ + if (options->library == FF_OPENGL_LIBRARY_AUTO) + return wglDetectOpenGL(result); + else if (options->library == FF_OPENGL_LIBRARY_EGL) + { + #if __has_include() + const char* ffOpenGLDetectByEGL(FFOpenGLResult* result); + return ffOpenGLDetectByEGL(result); + #else + return "fastfetch was compiled without egl support"; + #endif + } + else + return "Unsupported OpenGL library"; +} diff --git a/src/modules/opengl/opengl.c b/src/modules/opengl/opengl.c index e7bbff3ee..d5d56b834 100644 --- a/src/modules/opengl/opengl.c +++ b/src/modules/opengl/opengl.c @@ -52,7 +52,6 @@ bool ffParseOpenGLCommandOptions(FFOpenGLOptions* options, const char* key, cons if (ffOptionParseModuleArgs(key, subKey, value, &options->moduleArgs)) return true; - #if defined(__linux__) || defined(__FreeBSD__) if (ffStrEqualsIgnCase(subKey, "library")) { options->library = (FFOpenGLLibrary) ffOptionParseEnum(key, value, (FFKeyValuePair[]) { @@ -64,7 +63,6 @@ bool ffParseOpenGLCommandOptions(FFOpenGLOptions* options, const char* key, cons }); return true; } - #endif return false; } @@ -82,7 +80,6 @@ void ffParseOpenGLJsonObject(FFOpenGLOptions* options, yyjson_val* module) if (ffJsonConfigParseModuleArgs(key, val, &options->moduleArgs)) continue; - #if defined(__linux__) || defined(__FreeBSD__) if (ffStrEqualsIgnCase(key, "library")) { int value; @@ -99,7 +96,6 @@ void ffParseOpenGLJsonObject(FFOpenGLOptions* options, yyjson_val* module) options->library = (FFOpenGLLibrary) value; continue; } - #endif ffPrintError(FF_OPENGL_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "Unknown JSON key %s", key); } @@ -112,7 +108,6 @@ void ffGenerateOpenGLJsonConfig(FFOpenGLOptions* options, yyjson_mut_doc* doc, y ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs); - #if defined(__linux__) || defined(__FreeBSD__) if (options->library != defaultOptions.library) { switch (options->library) @@ -131,7 +126,6 @@ void ffGenerateOpenGLJsonConfig(FFOpenGLOptions* options, yyjson_mut_doc* doc, y break; } } - #endif } void ffGenerateOpenGLJsonResult(FF_MAYBE_UNUSED FFOpenGLOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) @@ -191,9 +185,7 @@ void ffInitOpenGLOptions(FFOpenGLOptions* options) ); ffOptionInitModuleArg(&options->moduleArgs); - #if defined(__linux__) || defined(__FreeBSD__) options->library = FF_OPENGL_LIBRARY_AUTO; - #endif } void ffDestroyOpenGLOptions(FFOpenGLOptions* options) diff --git a/src/modules/opengl/option.h b/src/modules/opengl/option.h index ca60b7da3..8c9db6309 100644 --- a/src/modules/opengl/option.h +++ b/src/modules/opengl/option.h @@ -4,7 +4,6 @@ #include "common/option.h" -#if defined(__linux__) || defined(__FreeBSD__) || defined(__sun) typedef enum FFOpenGLLibrary { FF_OPENGL_LIBRARY_AUTO, @@ -12,14 +11,11 @@ typedef enum FFOpenGLLibrary FF_OPENGL_LIBRARY_GLX, FF_OPENGL_LIBRARY_OSMESA } FFOpenGLLibrary; -#endif typedef struct FFOpenGLOptions { FFModuleBaseInfo moduleInfo; FFModuleArgs moduleArgs; - #if defined(__linux__) || defined(__FreeBSD__) || defined(__sun) FFOpenGLLibrary library; - #endif } FFOpenGLOptions; diff --git a/src/options/library.c b/src/options/library.c index 36aa4033b..a80f4b6c6 100644 --- a/src/options/library.c +++ b/src/options/library.c @@ -27,6 +27,8 @@ const char* ffOptionsParseLibraryJsonConfig(FFOptionsLibrary* options, yyjson_va ffStrbufSetS(&options->libChafa, yyjson_get_str(val)); else if (ffStrEqualsIgnCase(key, "z")) ffStrbufSetS(&options->libZ, yyjson_get_str(val)); + else if (ffStrEqualsIgnCase(key, "egl")) + ffStrbufSetS(&options->libEGL, yyjson_get_str(val)); #ifdef __ANDROID__ else if (ffStrEqualsIgnCase(key, "freetype")) @@ -54,8 +56,6 @@ const char* ffOptionsParseLibraryJsonConfig(FFOptionsLibrary* options, yyjson_va ffStrbufSetS(&options->libXFConf, yyjson_get_str(val)); else if (ffStrEqualsIgnCase(key, "rpm")) ffStrbufSetS(&options->librpm, yyjson_get_str(val)); - else if (ffStrEqualsIgnCase(key, "egl")) - ffStrbufSetS(&options->libEGL, yyjson_get_str(val)); else if (ffStrEqualsIgnCase(key, "glx")) ffStrbufSetS(&options->libGLX, yyjson_get_str(val)); else if (ffStrEqualsIgnCase(key, "osmesa")) @@ -94,6 +94,8 @@ bool ffOptionsParseLibraryCommandLine(FFOptionsLibrary* options, const char* key ffOptionParseString(key, value, &options->libChafa); else if(ffStrEqualsIgnCase(subkey, "z")) ffOptionParseString(key, value, &options->libZ); + else if(ffStrEqualsIgnCase(subkey, "egl")) + ffOptionParseString(key, value, &options->libEGL); #ifdef __ANDROID__ else if(ffStrEqualsIgnCase(subkey, "freetype")) @@ -121,8 +123,6 @@ bool ffOptionsParseLibraryCommandLine(FFOptionsLibrary* options, const char* key ffOptionParseString(key, value, &options->libXFConf); else if(ffStrEqualsIgnCase(subkey, "rpm")) ffOptionParseString(key, value, &options->librpm); - else if(ffStrEqualsIgnCase(subkey, "egl")) - ffOptionParseString(key, value, &options->libEGL); else if(ffStrEqualsIgnCase(subkey, "glx")) ffOptionParseString(key, value, &options->libGLX); else if(ffStrEqualsIgnCase(subkey, "osmesa")) @@ -184,7 +184,10 @@ void ffOptionsGenerateLibraryJsonConfig(FFOptionsLibrary* options, yyjson_mut_do if (!ffStrbufEqual(&options->libZ, &defaultOptions.libZ)) yyjson_mut_obj_add_strbuf(doc, obj, "z", &options->libZ); -#if defined(__linux__) || defined(__FreeBSD__) + if (!ffStrbufEqual(&options->libEGL, &defaultOptions.libEGL)) + yyjson_mut_obj_add_strbuf(doc, obj, "egl", &options->libEGL); + +#if defined(__linux__) || defined(__FreeBSD__) || defined(__sun) if (!ffStrbufEqual(&options->libWayland, &defaultOptions.libWayland)) yyjson_mut_obj_add_strbuf(doc, obj, "wayland", &options->libWayland); @@ -215,9 +218,6 @@ void ffOptionsGenerateLibraryJsonConfig(FFOptionsLibrary* options, yyjson_mut_do if (!ffStrbufEqual(&options->librpm, &defaultOptions.librpm)) yyjson_mut_obj_add_strbuf(doc, obj, "rpm", &options->librpm); - if (!ffStrbufEqual(&options->libEGL, &defaultOptions.libEGL)) - yyjson_mut_obj_add_strbuf(doc, obj, "egl", &options->libEGL); - if (!ffStrbufEqual(&options->libGLX, &defaultOptions.libGLX)) yyjson_mut_obj_add_strbuf(doc, obj, "glx", &options->libGLX); diff --git a/src/options/library.h b/src/options/library.h index cc65302b5..55f2be4e2 100644 --- a/src/options/library.h +++ b/src/options/library.h @@ -10,6 +10,7 @@ typedef struct FFOptionsLibrary FFstrbuf libImageMagick; FFstrbuf libChafa; FFstrbuf libZ; + FFstrbuf libEGL; #ifdef __ANDROID__ FFstrbuf libfreetype; @@ -26,7 +27,6 @@ typedef struct FFOptionsLibrary FFstrbuf libDBus; FFstrbuf libXFConf; FFstrbuf librpm; - FFstrbuf libEGL; FFstrbuf libGLX; FFstrbuf libOSMesa; FFstrbuf libPulse;