mcst-linux-kernel/patches-2024.06.26/gl4es-1.1.4/0178-Add-glX-function-stubs...

253 lines
13 KiB
Diff

From 59c2ba4279f01a99cbcaf1b71aad805a0c8693bd Mon Sep 17 00:00:00 2001
From: JohnnyonFlame <johnnyonflame@hotmail.com>
Date: Sun, 5 Sep 2021 17:50:02 -0300
Subject: [PATCH 178/233] Add glX function stubs to be used with NOX11 targets.
Can be enabled with GLX_STUBS, Works around Shovel Knight assert failures
during startup.
---
CMakeLists.txt | 7 +++++
src/CMakeLists.txt | 1 +
src/glx/glx.h | 23 ++++++++++------
src/glx/glx_stubs.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++
src/glx/lookup.c | 10 +++----
5 files changed, 105 insertions(+), 13 deletions(-)
create mode 100644 src/glx/glx_stubs.c
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3cc3bfea..23ed054a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -26,6 +26,7 @@ option(NO_LOADER "disable library loader (useful for static library with NOEGL,
option(NO_INIT_CONSTRUCTOR "disable automatic initialization (useful for static library, use include/gl4esinit.h)" ${NO_INIT_CONSTRUCTOR})
option(USE_ANDROID_LOG "Set to ON to use Android log instead of stdio" ${USE_ANDROID_LOG})
option(EGL_WRAPPER "Set to ON to build EGL wrapper" ${EGL_WRAPPER})
+option(GLX_STUBS "Set to ON to build GLX function stubs" ${GLX_STUBS})
include(CheckSymbolExists)
check_symbol_exists(backtrace "execinfo.h" HAS_BACKTRACE)
@@ -93,6 +94,8 @@ endif()
if(GOA_CLONE)
add_definitions(-DGOA_CLONE)
add_definitions(-mcpu=cortex-a35 -mfpu=neon-vfpv3 -march=armv8-a+crc+simd+crypto -mfloat-abi=hard -ftree-vectorize -fsingle-precision-constant -ffast-math)
+ set(EGL_WRAPPER ON)
+ set(GLX_STUBS ON)
endif()
# Android
@@ -163,6 +166,10 @@ if(NO_INIT_CONSTRUCTOR)
add_definitions(-DNO_INIT_CONSTRUCTOR)
endif()
+if(GLX_STUBS)
+ add_definitions(-DGLX_STUBS)
+endif()
+
#DEFAULT_ES=2
if(DEFAULT_ES EQUAL 2)
add_definitions(-DDEFAULT_ES=2)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 7af91140..388a90f9 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -145,6 +145,7 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Linux" AND NOT NO_LOADER)
${CMAKE_CURRENT_SOURCE_DIR}/glx/hardext.c
${CMAKE_CURRENT_SOURCE_DIR}/glx/gbm.c
${CMAKE_CURRENT_SOURCE_DIR}/glx/glx.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/glx/glx_stubs.c
${CMAKE_CURRENT_SOURCE_DIR}/glx/lookup.c
${CMAKE_CURRENT_SOURCE_DIR}/glx/rpi.c
${CMAKE_CURRENT_SOURCE_DIR}/glx/streaming.c
diff --git a/src/glx/glx.h b/src/glx/glx.h
index b45c66eb..95e8dedd 100644
--- a/src/glx/glx.h
+++ b/src/glx/glx.h
@@ -238,8 +238,15 @@ struct __GLXFBConfigRec {
double minBlue, maxBlue;
double minAlpha, maxAlpha;
};
+
+#ifdef NOX11
+// Declare stub types
+typedef void *XVisualInfo, *GLXContext, *Font, *Window, *Pixmap;
+typedef unsigned int GLXPixmap, GLXPbuffer;
+#endif
+
typedef struct __GLXFBConfigRec *GLXFBConfig;
-#ifndef NOX11
+#if !defined(NOX11) || defined(GLX_STUBS)
GLXContext gl4es_glXCreateContext(Display *dpy,
XVisualInfo *visual,
GLXContext shareList,
@@ -250,11 +257,11 @@ GLXContext gl4es_glXCreateContextAttribsARB(Display *display, GLXFBConfig config
const int *attrib_list);
void gl4es_glXSwapIntervalEXT(Display *display, int drawable, int interval);
-#endif //NOX11
+#endif // !defined(NOX11) || defined(GLX_STUBS)
void gl4es_glXSwapInterval(int interval);
// GLX 1.1?
-#ifndef NOX11
+#if !defined(NOX11) || defined(GLX_STUBS)
Bool gl4es_glXIsDirect(Display * display, GLXContext ctx);
Bool gl4es_glXMakeCurrent(Display *display, GLXDrawable drawable, GLXContext context);
Bool gl4es_glXQueryExtension(Display *display, int *errorBase, int *eventBase);
@@ -262,18 +269,18 @@ Bool gl4es_glXQueryVersion(Display *display, int *major, int *minor);
const char *gl4es_glXGetClientString(Display *display, int name);
const char *gl4es_glXQueryExtensionsString(Display *display, int screen);
const char *gl4es_glXQueryServerString(Display *display, int screen, int name);
-#endif //NOX11
+#endif
GLXDrawable gl4es_glXGetCurrentDrawable();
-#ifndef NOX11
+#if !defined(NOX11) || defined(GLX_STUBS)
int gl4es_glXGetConfig(Display *display, XVisualInfo *visual, int attribute, int *value);
void gl4es_glXCopyContext(Display *display, GLXContext src, GLXContext dst, GLuint mask);
void gl4es_glXDestroyContext(Display *display, GLXContext ctx);
void gl4es_glXSwapBuffers(Display *display, GLXDrawable drawable);
void gl4es_glXUseXFont(Font font, int first, int count, int listBase);
-#endif //NOX11
+#endif // !defined(NOX11) || defined(GLX_STUBS)
void gl4es_glXWaitGL();
void gl4es_glXWaitX();
-#ifndef NOX11
+#if !defined(NOX11) || defined(GLX_STUBS)
XVisualInfo *gl4es_glXChooseVisual(Display *display, int screen, int *attributes);
int gl4es_glXQueryDrawable(Display *dpy, GLXDrawable draw, int attribute, unsigned int *value);
@@ -304,6 +311,6 @@ GLXPixmap gl4es_glXCreateGLXPixmap(Display *display, XVisualInfo * visual, Pixma
void gl4es_glXDestroyGLXPixmap(Display *display, void *pixmap);
GLXContext gl4es_glXCreateContextAttribs(Display *dpy, GLXFBConfig config, GLXContext share_context, Bool direct, const int *attrib_list);
-#endif // NOX11
+#endif // !defined(NOX11) || defined(GLX_STUBS)
#endif // _GLX_GLX_H
diff --git a/src/glx/glx_stubs.c b/src/glx/glx_stubs.c
new file mode 100644
index 00000000..4ba4de5c
--- /dev/null
+++ b/src/glx/glx_stubs.c
@@ -0,0 +1,77 @@
+#include "glx.h"
+#include "../gl/init.h"
+#include "../gl/logs.h"
+
+
+#if defined(NOX11) && defined(GLX_STUBS)
+//#define WARN_GLX_STUB() LOGD("Warning, stubbed %s\n", __FUNCTION__); return NULL;
+#define WARN_GLX_STUB() return NULL;
+
+GLXContext gl4es_glXCreateContext(Display *display, XVisualInfo *visual, GLXContext shareList, Bool isDirect){ WARN_GLX_STUB(); }
+GLXContext gl4es_glXCreateContextAttribsARB(Display *display, GLXFBConfig config, GLXContext share_context, Bool direct, const int *attrib_list){ WARN_GLX_STUB(); }
+void gl4es_glXDestroyContext(Display *display, GLXContext ctx){ WARN_GLX_STUB(); }
+Display *gl4es_glXGetCurrentDisplay(){ WARN_GLX_STUB(); }
+XVisualInfo *gl4es_glXChooseVisual(Display *display, int screen, int *attributes){ WARN_GLX_STUB(); }
+Bool gl4es_glXMakeCurrent(Display *display, GLXDrawable drawable, GLXContext context){ WARN_GLX_STUB(); }
+Bool gl4es_glXMakeContextCurrent(Display *display, int drawable, int readable, GLXContext context){ WARN_GLX_STUB(); }
+void gl4es_glXSwapBuffers(Display *display, GLXDrawable drawable){ WARN_GLX_STUB(); }
+int gl4es_glXGetConfig(Display *display, XVisualInfo *visual, int attribute, int *value){ WARN_GLX_STUB(); }
+int gl4es_glXQueryContext( Display *dpy, GLXContext ctx, int attribute, int *value){ WARN_GLX_STUB(); }
+GLXContext gl4es_glXGetCurrentContext(){ WARN_GLX_STUB(); }
+GLXFBConfig *gl4es_glXChooseFBConfig(Display *display, int screen, const int *attrib_list, int *count){ WARN_GLX_STUB(); }
+GLXFBConfig *gl4es_glXChooseFBConfigSGIX(Display *display, int screen, const int *attrib_list, int *count){ WARN_GLX_STUB(); }
+GLXFBConfig *gl4es_glXGetFBConfigs(Display *display, int screen, int *count){ WARN_GLX_STUB(); }
+int gl4es_glXGetFBConfigAttrib(Display *display, GLXFBConfig config, int attribute, int *value){ WARN_GLX_STUB(); }
+XVisualInfo *gl4es_glXGetVisualFromFBConfig(Display *display, GLXFBConfig config){ WARN_GLX_STUB(); }
+GLXContext gl4es_glXCreateNewContext(Display *display, GLXFBConfig config, int render_type, GLXContext share_list, Bool is_direct){ WARN_GLX_STUB(); }
+void gl4es_glXSwapIntervalEXT(Display *display, int drawable, int interval){ WARN_GLX_STUB(); }
+void gl4es_glXCopyContext(Display *display, GLXContext src, GLXContext dst, GLuint mask){ WARN_GLX_STUB(); }
+Window gl4es_glXCreateWindow(Display *display, GLXFBConfig config, Window win, int *attrib_list){ WARN_GLX_STUB(); }
+void gl4es_glXDestroyWindow(Display *display, void *win){ WARN_GLX_STUB(); }
+GLXDrawable gl4es_glXGetCurrentDrawable(){ WARN_GLX_STUB(); }
+Bool gl4es_glXIsDirect(Display * display, GLXContext ctx){ WARN_GLX_STUB(); }
+void gl4es_glXUseXFont(Font font, int first, int count, int listBase){ WARN_GLX_STUB(); }
+int gl4es_glXQueryDrawable(Display *dpy, GLXDrawable draw, int attribute, unsigned int *value){ WARN_GLX_STUB(); }
+void gl4es_glXDestroyPbuffer(Display * dpy, GLXPbuffer pbuf){ WARN_GLX_STUB(); }
+GLXPbuffer gl4es_glXCreatePbuffer(Display * dpy, GLXFBConfig config, const int * attrib_list){ WARN_GLX_STUB(); }
+GLXPixmap gl4es_glXCreateGLXPixmap(Display *display, XVisualInfo * visual, Pixmap pixmap){ WARN_GLX_STUB(); }
+GLXPixmap gl4es_glXCreatePixmap(Display * dpy, GLXFBConfig config, Pixmap pixmap, const int * attrib_list){ WARN_GLX_STUB(); }
+void gl4es_glXDestroyGLXPixmap(Display *display, void *pixmap){ WARN_GLX_STUB(); }
+void gl4es_glXDestroyPixmap(Display *display, void *pixmap){ WARN_GLX_STUB(); }
+GLXContext gl4es_glXCreateContextAttribs(Display *dpy, GLXFBConfig config, GLXContext share_context, Bool direct, const int *attrib_list){ WARN_GLX_STUB(); }
+void gl4es_glXSwapIntervalMESA(int interval){ WARN_GLX_STUB(); }
+void gl4es_glXSwapIntervalSGI(int interval){ WARN_GLX_STUB(); }
+
+AliasExport(GLXContext,glXCreateContext,,(Display *display, XVisualInfo *visual, GLXContext shareList, Bool isDirect));
+AliasExport(GLXContext,glXCreateContextAttribs,ARB,(Display *display, GLXFBConfig config, GLXContext share_context, Bool direct, const int *attrib_list));
+AliasExport(void,glXDestroyContext,,(Display *display, GLXContext ctx));
+AliasExport(Display*,glXGetCurrentDisplay,,());
+AliasExport(XVisualInfo*,glXChooseVisual,,(Display *display, int screen, int *attributes));
+AliasExport(Bool,glXMakeCurrent,,(Display *display, GLXDrawable drawable, GLXContext context));
+AliasExport(Bool,glXMakeContextCurrent,,(Display *display, int drawable, int readable, GLXContext context));
+AliasExport(void,glXSwapBuffers,,(Display *display, GLXDrawable drawable));
+AliasExport(int,glXGetConfig,,(Display *display, XVisualInfo *visual, int attribute, int *value));
+AliasExport(int,glXQueryContext,,( Display *dpy, GLXContext ctx, int attribute, int *value));
+AliasExport(GLXContext,glXGetCurrentContext,,());
+AliasExport(GLXFBConfig*,glXChooseFBConfig,,(Display *display, int screen, const int *attrib_list, int *count));
+AliasExport(GLXFBConfig*,glXChooseFBConfig,SGIX,(Display *display, int screen, const int *attrib_list, int *count));
+AliasExport(GLXFBConfig*,glXGetFBConfigs,,(Display *display, int screen, int *count));
+AliasExport(int,glXGetFBConfigAttrib,,(Display *display, GLXFBConfig config, int attribute, int *value));
+AliasExport(XVisualInfo*,glXGetVisualFromFBConfig,,(Display *display, GLXFBConfig config));
+AliasExport(GLXContext,glXCreateNewContext,,(Display *display, GLXFBConfig config, int render_type, GLXContext share_list, Bool is_direct));
+AliasExport(void,glXSwapIntervalEXT,,(Display *display, int drawable, int interval));
+AliasExport(void,glXCopyContext,,(Display *display, GLXContext src, GLXContext dst, GLuint mask));
+AliasExport(Window,glXCreateWindow,,(Display *display, GLXFBConfig config, Window win, int *attrib_list));
+AliasExport(void,glXDestroyWindow,,(Display *display, void *win));
+AliasExport(GLXDrawable,glXGetCurrentDrawable,,());
+AliasExport(Bool,glXIsDirect,,(Display * display, GLXContext ctx));
+AliasExport(void,glXUseXFont,,(Font font, int first, int count, int listBase));
+AliasExport(int,glXQueryDrawable,,(Display *dpy, GLXDrawable draw, int attribute, unsigned int *value));
+AliasExport(void,glXDestroyPbuffer,,(Display * dpy, GLXPbuffer pbuf));
+AliasExport(GLXPbuffer,glXCreatePbuffer,,(Display * dpy, GLXFBConfig config, const int * attrib_list));
+AliasExport(GLXPixmap,glXCreateGLXPixmap,,(Display *display, XVisualInfo * visual, Pixmap pixmap));
+AliasExport(GLXPixmap,glXCreatePixmap,,(Display * dpy, GLXFBConfig config, Pixmap pixmap, const int * attrib_list));
+AliasExport(void,glXDestroyGLXPixmap,,(Display *display, void *pixmap));
+AliasExport(void,glXDestroyPixmap,,(Display *display, void *pixmap));
+AliasExport(GLXContext,glXCreateContextAttribs,,(Display *dpy, GLXFBConfig config, GLXContext share_context, Bool direct, const int *attrib_list));
+#endif
\ No newline at end of file
diff --git a/src/glx/lookup.c b/src/glx/lookup.c
index f21cbed7..e558439e 100644
--- a/src/glx/lookup.c
+++ b/src/glx/lookup.c
@@ -15,7 +15,7 @@ void glXStub(void *x, ...) {
void *gl4es_glXGetProcAddress(const char *name) __attribute__((visibility("default")));
void *gl4es_glXGetProcAddress(const char *name) {
-#ifndef NOX11
+#if !defined(NOX11) || defined(GLX_STUBS)
// glX calls
_EX(glXChooseVisual);
_EX(glXCopyContext);
@@ -33,10 +33,10 @@ void *gl4es_glXGetProcAddress(const char *name) {
_EX(glXQueryServerString);
_EX(glXSwapBuffers);
_EX(glXSwapIntervalEXT);
-#endif //NOX11
+#endif
MAP("glXSwapIntervalMESA", gl4es_glXSwapInterval);
MAP("glXSwapIntervalSGI", gl4es_glXSwapInterval);
-#ifndef NOX11
+#if !defined(NOX11) || defined(GLX_STUBS)
_EX(glXUseXFont);
_EX(glXWaitGL);
_EX(glXWaitX);
@@ -63,10 +63,10 @@ void *gl4es_glXGetProcAddress(const char *name) {
STUB(glXGetCurrentReadDrawable);
STUB(glXGetSelectedEvent);
STUB(glXSelectEvent);
-
+
_EX(glXCreateContextAttribs);
_ARB(glXCreateContextAttribs);
-#endif //NOX11
+#endif
_EX(glXGetProcAddress);
_ARB(glXGetProcAddress);
--
2.11.0