OpenGL (EGL): optimises code

This commit is contained in:
Carter Li
2026-06-18 19:48:47 +08:00
committed by 李通洲
parent bd40d8756e
commit 508a50f803
+43 -38
View File
@@ -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;