mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-29 16:26:39 +01:00
OpenGL (EGL): optimises code
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include "opengl.h"
|
||||
#include "common/debug.h"
|
||||
#include "common/library.h"
|
||||
#include "common/io.h"
|
||||
|
||||
#if __has_include(<GL/gl.h>)
|
||||
#include <GL/gl.h>
|
||||
@@ -34,8 +35,6 @@ void ffOpenGLHandleResult(FFOpenGLResult* result, __typeof__(&glGetString) ffglG
|
||||
|
||||
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)
|
||||
@@ -132,38 +131,7 @@ static const char* eglHandleDisplay(FFOpenGLResult* result, EGLData* data) {
|
||||
return error;
|
||||
}
|
||||
|
||||
static const char* eglHandleData(FFOpenGLResult* result, EGLData* data) {
|
||||
FF_DEBUG("Resolving glGetString via eglGetProcAddress()");
|
||||
data->ffglGetString = (__typeof__(&glGetString)) data->ffeglGetProcAddress("glGetString");
|
||||
if (!data->ffglGetString) {
|
||||
FF_DEBUG("eglGetProcAddress('glGetString') returned NULL");
|
||||
return "eglGetProcAddress(glGetString) returned NULL";
|
||||
}
|
||||
|
||||
#if EGL_VERSION_1_5
|
||||
PFNEGLGETPLATFORMDISPLAYEXTPROC ffeglGetPlatformDisplay = (PFNEGLGETPLATFORMDISPLAYEXTPROC) data->ffeglGetProcAddress("eglGetPlatformDisplay");
|
||||
if (ffeglGetPlatformDisplay) {
|
||||
FF_DEBUG("Trying eglGetPlatformDisplay(EGL_PLATFORM_SURFACELESS_MESA)");
|
||||
data->display = ffeglGetPlatformDisplay(EGL_PLATFORM_SURFACELESS_MESA, NULL, NULL);
|
||||
FF_DEBUG("eglGetPlatformDisplay() %s", data->display == EGL_NO_DISPLAY ? "failed" : "succeeded");
|
||||
} else {
|
||||
FF_DEBUG("eglGetPlatformDisplay is unavailable, falling back to eglGetDisplay");
|
||||
}
|
||||
|
||||
if (!ffeglGetPlatformDisplay || data->display == EGL_NO_DISPLAY)
|
||||
#endif
|
||||
|
||||
{
|
||||
FF_DEBUG("Trying eglGetDisplay(EGL_DEFAULT_DISPLAY)");
|
||||
data->display = data->ffeglGetDisplay(EGL_DEFAULT_DISPLAY);
|
||||
if (data->display == EGL_NO_DISPLAY) {
|
||||
FF_DEBUG("eglGetDisplay() returned EGL_NO_DISPLAY");
|
||||
return "eglGetDisplay returned EGL_NO_DISPLAY";
|
||||
}
|
||||
|
||||
FF_DEBUG("eglGetDisplay() succeeded");
|
||||
}
|
||||
|
||||
static const char* eglHandlePreDisplay(FFOpenGLResult* result, EGLData* data) {
|
||||
EGLint major, minor;
|
||||
if (data->ffeglInitialize(data->display, &major, &minor) == EGL_FALSE) {
|
||||
FF_DEBUG("eglInitialize() returned EGL_FALSE");
|
||||
@@ -185,8 +153,7 @@ const char* ffOpenGLDetectByEGL(FFOpenGLResult* result) {
|
||||
EGLData eglData;
|
||||
|
||||
FF_LIBRARY_LOAD_MESSAGE(egl, "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_MESSAGE(egl, eglGetProcAddress);
|
||||
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);
|
||||
@@ -198,12 +165,50 @@ const char* ffOpenGLDetectByEGL(FFOpenGLResult* result) {
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(egl, eglData, eglDestroySurface);
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(egl, eglData, eglTerminate);
|
||||
|
||||
FF_DEBUG("Resolving glGetString via eglGetProcAddress()");
|
||||
eglData.ffglGetString = (__typeof__(&glGetString)) ffeglGetProcAddress("glGetString");
|
||||
if (!eglData.ffglGetString) {
|
||||
FF_DEBUG("eglGetProcAddress('glGetString') returned NULL");
|
||||
return "eglGetProcAddress(glGetString) returned NULL";
|
||||
}
|
||||
|
||||
FF_DEBUG("Loaded EGL library and required symbols");
|
||||
|
||||
FF_SUPPRESS_IO();
|
||||
FF_DEBUG("Suppressed stdout/stderr during EGL probing");
|
||||
|
||||
const char* error = eglHandleData(result, &eglData);
|
||||
EGLDisplay display = EGL_NO_DISPLAY;
|
||||
#if EGL_VERSION_1_5
|
||||
PFNEGLGETPLATFORMDISPLAYEXTPROC ffeglGetPlatformDisplay = (PFNEGLGETPLATFORMDISPLAYEXTPROC) ffeglGetProcAddress("eglGetPlatformDisplay");
|
||||
if (!ffeglGetPlatformDisplay) {
|
||||
ffeglGetPlatformDisplay = (PFNEGLGETPLATFORMDISPLAYEXTPROC) ffeglGetProcAddress("eglGetPlatformDisplayEXT");
|
||||
}
|
||||
if (ffeglGetPlatformDisplay) {
|
||||
FF_DEBUG("Trying eglGetPlatformDisplay(EGL_PLATFORM_SURFACELESS_MESA)");
|
||||
display = ffeglGetPlatformDisplay(EGL_PLATFORM_SURFACELESS_MESA, EGL_DEFAULT_DISPLAY, NULL);
|
||||
FF_DEBUG("eglGetPlatformDisplay() %s", display == EGL_NO_DISPLAY ? "failed" : "succeeded");
|
||||
} else {
|
||||
FF_DEBUG("eglGetPlatformDisplay is unavailable, falling back to eglGetDisplay");
|
||||
}
|
||||
|
||||
if (display == EGL_NO_DISPLAY)
|
||||
#endif
|
||||
|
||||
{
|
||||
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(egl, eglGetDisplay);
|
||||
|
||||
FF_DEBUG("Trying eglGetDisplay(EGL_DEFAULT_DISPLAY)");
|
||||
display = ffeglGetDisplay(EGL_DEFAULT_DISPLAY);
|
||||
if (display == EGL_NO_DISPLAY) {
|
||||
FF_DEBUG("eglGetDisplay() returned EGL_NO_DISPLAY");
|
||||
return "eglGetDisplay returned EGL_NO_DISPLAY";
|
||||
}
|
||||
|
||||
FF_DEBUG("eglGetDisplay() succeeded");
|
||||
}
|
||||
eglData.display = display;
|
||||
|
||||
const char* error = eglHandlePreDisplay(result, &eglData);
|
||||
|
||||
FF_DEBUG("OpenGL detection via EGL returns: %s", error ?: "success");
|
||||
|
||||
return error;
|
||||
|
||||
Reference in New Issue
Block a user