Module Name: xsrc
Committed By: mrg
Date: Mon Nov 2 04:46:30 UTC 2020
Modified Files:
xsrc/external/mit/libepoxy/dist/src: dispatch_common.c
dispatch_common.h
Removed Files:
xsrc/external/mit/libepoxy/dist: .gitignore
xsrc/external/mit/libepoxy/dist/test: egl_and_glx_different_pointers.c
Log Message:
merge libepoxy 1.5.4.
To generate a diff of this commit:
cvs rdiff -u -r1.1.1.1 -r0 xsrc/external/mit/libepoxy/dist/.gitignore
cvs rdiff -u -r1.4 -r1.5 \
xsrc/external/mit/libepoxy/dist/src/dispatch_common.c
cvs rdiff -u -r1.7 -r1.8 \
xsrc/external/mit/libepoxy/dist/src/dispatch_common.h
cvs rdiff -u -r1.1.1.1 -r0 \
xsrc/external/mit/libepoxy/dist/test/egl_and_glx_different_pointers.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: xsrc/external/mit/libepoxy/dist/src/dispatch_common.c
diff -u xsrc/external/mit/libepoxy/dist/src/dispatch_common.c:1.4 xsrc/external/mit/libepoxy/dist/src/dispatch_common.c:1.5
--- xsrc/external/mit/libepoxy/dist/src/dispatch_common.c:1.4 Tue Jul 9 21:55:21 2019
+++ xsrc/external/mit/libepoxy/dist/src/dispatch_common.c Mon Nov 2 04:46:29 2020
@@ -41,7 +41,7 @@
* \section features_sec Features
*
* - Automatically initializes as new GL functions are used.
- * - GL 4.4 core and compatibility context support.
+ * - GL 4.6 core and compatibility context support.
* - GLES 1/2/3 context support.
* - Knows about function aliases so (e.g.) `glBufferData()` can be
* used with `GL_ARB_vertex_buffer_object` implementations, along
@@ -173,30 +173,33 @@
#include "dispatch_common.h"
-#ifdef __APPLE__
+#if defined(__APPLE__)
#define GLX_LIB "/opt/X11/lib/libGL.1.dylib"
-#elif defined(ANDROID)
+#define OPENGL_LIB "/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL"
+#define GLES1_LIB "libGLESv1_CM.so"
+#define GLES2_LIB "libGLESv2.so"
+#elif defined(__ANDROID__)
#define GLX_LIB "libGLESv2.so"
-#else
-#ifdef __NetBSD__
+#elif __NetBSD__
#define GLX_LIB "libGL.so"
-#else
-#define GLX_LIB "libGL.so.1"
-#endif
#endif
#if defined(ANDROID) || defined(__NetBSD__)
#define EGL_LIB "libEGL.so"
#define GLES1_LIB "libGLESv1_CM.so"
#define GLES2_LIB "libGLESv2.so"
-#elif defined _WIN32
+#elif defined(_WIN32)
#define EGL_LIB "libEGL.dll"
#define GLES1_LIB "libGLES_CM.dll"
#define GLES2_LIB "libGLESv2.dll"
+#define OPENGL_LIB "OPENGL32"
#else
+#define GLVND_GLX_LIB "libGLX.so.1"
+#define GLX_LIB "libGL.so.1"
#define EGL_LIB "libEGL.so.1"
#define GLES1_LIB "libGLESv1_CM.so.1"
#define GLES2_LIB "libGLESv2.so.2"
+#define OPENGL_LIB "libOpenGL.so.0"
#endif
#ifdef __GNUC__
@@ -230,13 +233,18 @@ struct api {
pthread_mutex_t mutex;
#endif
- /* dlopen() return value for libGL.so.1. */
+ /*
+ * dlopen() return value for the GLX API. This is libGLX.so.1 if the
+ * runtime is glvnd-enabled, else libGL.so.1
+ */
void *glx_handle;
/*
- * dlopen() return value for OS X's GL library.
+ * dlopen() return value for the desktop GL library.
*
- * On linux, glx_handle is used instead.
+ * On Windows this is OPENGL32. On OSX this is classic libGL. On Linux
+ * this is either libOpenGL (if the runtime is glvnd-enabled) or
+ * classic libGL.so.1
*/
void *gl_handle;
@@ -290,14 +298,13 @@ library_init(void)
}
static bool
-get_dlopen_handle(void **handle, const char *lib_name, bool exit_on_fail)
+get_dlopen_handle(void **handle, const char *lib_name, bool exit_on_fail, bool load)
{
if (*handle)
return true;
if (!library_initialized) {
- fprintf(stderr,
- "Attempting to dlopen() while in the dynamic linker.\n");
+ fputs("Attempting to dlopen() while in the dynamic linker.\n", stderr);
abort();
}
@@ -306,11 +313,15 @@ get_dlopen_handle(void **handle, const c
#else
pthread_mutex_lock(&api.mutex);
if (!*handle) {
- *handle = dlopen(lib_name, RTLD_LAZY | RTLD_LOCAL);
+ int flags = RTLD_LAZY | RTLD_LOCAL;
+ if (!load)
+ flags |= RTLD_NOLOAD;
+
+ *handle = dlopen(lib_name, flags);
if (!*handle) {
if (exit_on_fail) {
fprintf(stderr, "Couldn't open %s: %s\n", lib_name, dlerror());
- exit(1);
+ abort();
} else {
(void)dlerror();
}
@@ -323,15 +334,11 @@ get_dlopen_handle(void **handle, const c
}
static void *
-do_dlsym(void **handle, const char *lib_name, const char *name,
- bool exit_on_fail)
+do_dlsym(void **handle, const char *name, bool exit_on_fail)
{
void *result;
const char *error = "";
- if (!get_dlopen_handle(handle, lib_name, exit_on_fail))
- return NULL;
-
#ifdef _WIN32
result = GetProcAddress(*handle, name);
#else
@@ -340,8 +347,8 @@ do_dlsym(void **handle, const char *lib_
error = dlerror();
#endif
if (!result && exit_on_fail) {
- fprintf(stderr,"%s() not found in %s: %s\n", name, lib_name, error);
- exit(1);
+ fprintf(stderr, "%s() not found: %s\n", name, error);
+ abort();
}
return result;
@@ -393,10 +400,10 @@ epoxy_is_desktop_gl(void)
}
static int
-epoxy_internal_gl_version(int error_version)
+epoxy_internal_gl_version(GLenum version_string, int error_version)
{
- const char *version = (const char *)glGetString(GL_VERSION);
- GLint major, minor;
+ const char *version = (const char *)glGetString(version_string);
+ GLint major, minor, factor;
int scanf_count;
if (!version)
@@ -411,9 +418,15 @@ epoxy_internal_gl_version(int error_vers
if (scanf_count != 2) {
fprintf(stderr, "Unable to interpret GL_VERSION string: %s\n",
version);
- exit(1);
+ abort();
}
- return 10 * major + minor;
+
+ if (minor >= 10)
+ factor = 100;
+ else
+ factor = 10;
+
+ return factor * major + minor;
}
/**
@@ -434,7 +447,7 @@ epoxy_internal_gl_version(int error_vers
int
epoxy_gl_version(void)
{
- return epoxy_internal_gl_version(0);
+ return epoxy_internal_gl_version(GL_VERSION, 0);
}
int
@@ -443,9 +456,52 @@ epoxy_conservative_gl_version(void)
if (api.begin_count)
return 100;
- return epoxy_internal_gl_version(100);
+ return epoxy_internal_gl_version(GL_VERSION, 100);
+}
+
+/**
+ * @brief Returns the version of the GL Shading Language we are using
+ *
+ * The version is encoded as:
+ *
+ * ```
+ *
+ * version = major * 100 + minor
+ *
+ * ```
+ *
+ * So it can be easily used for version comparisons.
+ *
+ * @return The encoded version of the GL Shading Language we are using
+ */
+int
+epoxy_glsl_version(void)
+{
+ if (epoxy_gl_version() >= 20 ||
+ epoxy_has_gl_extension ("GL_ARB_shading_language_100"))
+ return epoxy_internal_gl_version(GL_SHADING_LANGUAGE_VERSION, 0);
+
+ return 0;
}
+/**
+ * @brief Checks for the presence of an extension in an OpenGL extension string
+ *
+ * @param extension_list The string containing the list of extensions to check
+ * @param ext The name of the GL extension
+ * @return `true` if the extension is available'
+ *
+ * @note If you are looking to check whether a normal GL, EGL or GLX extension
+ * is supported by the client, this probably isn't the function you want.
+ *
+ * Some parts of the spec for OpenGL and friends will return an OpenGL formatted
+ * extension string that is separate from the usual extension strings for the
+ * spec. This function provides easy parsing of those strings.
+ *
+ * @see epoxy_has_gl_extension()
+ * @see epoxy_has_egl_extension()
+ * @see epoxy_has_glx_extension()
+ */
bool
epoxy_extension_in_string(const char *extension_list, const char *ext)
{
@@ -500,6 +556,31 @@ epoxy_internal_has_gl_extension(const ch
}
}
+bool
+epoxy_load_glx(bool exit_if_fails, bool load)
+{
+#if PLATFORM_HAS_GLX
+# ifdef GLVND_GLX_LIB
+ /* prefer the glvnd library if it exists */
+ if (!api.glx_handle)
+ get_dlopen_handle(&api.glx_handle, GLVND_GLX_LIB, false, load);
+# endif
+ if (!api.glx_handle)
+ get_dlopen_handle(&api.glx_handle, GLX_LIB, exit_if_fails, load);
+#endif
+ return api.glx_handle != NULL;
+}
+
+void *
+epoxy_conservative_glx_dlsym(const char *name, bool exit_if_fails)
+{
+#if PLATFORM_HAS_GLX
+ if (epoxy_load_glx(exit_if_fails, exit_if_fails))
+ return do_dlsym(&api.glx_handle, name, exit_if_fails);
+#endif
+ return NULL;
+}
+
/**
* Tests whether the currently bound context is EGL or GLX, trying to
* avoid loading libraries unless necessary.
@@ -510,16 +591,9 @@ epoxy_current_context_is_glx(void)
#if !PLATFORM_HAS_GLX
return false;
#else
- /* If the application hasn't explicitly called some of our GLX
- * or EGL code but has presumably set up a context on its own,
- * then we need to figure out how to getprocaddress anyway.
- *
- * If there's a public GetProcAddress loaded in the
- * application's namespace, then use that.
- */
void *sym;
- sym = dlsym(NULL, "glXGetCurrentContext");
+ sym = epoxy_conservative_glx_dlsym("glXGetCurrentContext", false);
if (sym) {
if (glXGetCurrentContext())
return true;
@@ -528,7 +602,7 @@ epoxy_current_context_is_glx(void)
}
#if PLATFORM_HAS_EGL
- sym = dlsym(NULL, "eglGetCurrentContext");
+ sym = epoxy_conservative_egl_dlsym("eglGetCurrentContext", false);
if (sym) {
if (epoxy_egl_get_current_gl_context_api() != EGL_NONE)
return false;
@@ -537,21 +611,6 @@ epoxy_current_context_is_glx(void)
}
#endif /* PLATFORM_HAS_EGL */
- /* OK, couldn't find anything in the app's address space.
- * Presumably they dlopened with RTLD_LOCAL, which hides it
- * from us. Just go dlopen()ing likely libraries and try them.
- */
- sym = do_dlsym(&api.glx_handle, GLX_LIB, "glXGetCurrentContext", false);
- if (sym && glXGetCurrentContext())
- return true;
-
-#if PLATFORM_HAS_EGL
- sym = do_dlsym(&api.egl_handle, EGL_LIB, "eglGetCurrentContext",
- false);
- if (sym && epoxy_egl_get_current_gl_context_api() != EGL_NONE)
- return false;
-#endif /* PLATFORM_HAS_EGL */
-
return false;
#endif /* PLATFORM_HAS_GLX */
}
@@ -582,10 +641,24 @@ epoxy_conservative_has_gl_extension(cons
return epoxy_internal_has_gl_extension(ext, true);
}
+bool
+epoxy_load_egl(bool exit_if_fails, bool load)
+{
+#if PLATFORM_HAS_EGL
+ return get_dlopen_handle(&api.egl_handle, EGL_LIB, exit_if_fails, load);
+#else
+ return false;
+#endif
+}
+
void *
epoxy_conservative_egl_dlsym(const char *name, bool exit_if_fails)
{
- return do_dlsym(&api.egl_handle, EGL_LIB, name, exit_if_fails);
+#if PLATFORM_HAS_EGL
+ if (epoxy_load_egl(exit_if_fails, exit_if_fails))
+ return do_dlsym(&api.egl_handle, name, exit_if_fails);
+#endif
+ return NULL;
}
void *
@@ -595,30 +668,37 @@ epoxy_egl_dlsym(const char *name)
}
void *
-epoxy_conservative_glx_dlsym(const char *name, bool exit_if_fails)
+epoxy_glx_dlsym(const char *name)
{
- return do_dlsym(&api.glx_handle, GLX_LIB, name, exit_if_fails);
+ return epoxy_conservative_glx_dlsym(name, true);
}
-void *
-epoxy_glx_dlsym(const char *name)
+static void
+epoxy_load_gl(void)
{
- return epoxy_conservative_glx_dlsym(name, true);
+ if (api.gl_handle)
+ return;
+
+#if defined(_WIN32) || defined(__APPLE__)
+ get_dlopen_handle(&api.gl_handle, OPENGL_LIB, true, true);
+#else
+
+#if defined(OPENGL_LIB)
+ if (!api.gl_handle)
+ get_dlopen_handle(&api.gl_handle, OPENGL_LIB, false, true);
+#endif
+
+ get_dlopen_handle(&api.glx_handle, GLX_LIB, true, true);
+ api.gl_handle = api.glx_handle;
+#endif
}
void *
epoxy_gl_dlsym(const char *name)
{
-#ifdef _WIN32
- return do_dlsym(&api.gl_handle, "OPENGL32", name, true);
-#elif defined(__APPLE__)
- return do_dlsym(&api.gl_handle,
- "/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL",
- name, true);
-#else
- /* There's no library for desktop GL support independent of GLX. */
- return epoxy_glx_dlsym(name);
-#endif
+ epoxy_load_gl();
+
+ return do_dlsym(&api.gl_handle, name, true);
}
void *
@@ -627,7 +707,8 @@ epoxy_gles1_dlsym(const char *name)
if (epoxy_current_context_is_glx()) {
return epoxy_get_proc_address(name);
} else {
- return do_dlsym(&api.gles1_handle, GLES1_LIB, name, true);
+ get_dlopen_handle(&api.gles1_handle, GLES1_LIB, true, true);
+ return do_dlsym(&api.gles1_handle, name, true);
}
}
@@ -637,7 +718,8 @@ epoxy_gles2_dlsym(const char *name)
if (epoxy_current_context_is_glx()) {
return epoxy_get_proc_address(name);
} else {
- return do_dlsym(&api.gles2_handle, GLES2_LIB, name, true);
+ get_dlopen_handle(&api.gles2_handle, GLES2_LIB, true, true);
+ return do_dlsym(&api.gles2_handle, name, true);
}
}
@@ -657,10 +739,12 @@ epoxy_gles3_dlsym(const char *name)
if (epoxy_current_context_is_glx()) {
return epoxy_get_proc_address(name);
} else {
- void *func = do_dlsym(&api.gles2_handle, GLES2_LIB, name, false);
+ if (get_dlopen_handle(&api.gles2_handle, GLES2_LIB, false, true)) {
+ void *func = do_dlsym(&api.gles2_handle, name, false);
- if (func)
- return func;
+ if (func)
+ return func;
+ }
return epoxy_get_proc_address(name);
}
@@ -675,7 +759,7 @@ epoxy_get_core_proc_address(const char *
{
#ifdef _WIN32
int core_symbol_support = 11;
-#elif defined(ANDROID)
+#elif defined(__ANDROID__)
/**
* All symbols must be resolved through eglGetProcAddress
* on Android
@@ -735,22 +819,22 @@ epoxy_get_bootstrap_proc_address(const c
* non-X11 ES2 context from loading a bunch of X11 junk).
*/
#if PLATFORM_HAS_EGL
- get_dlopen_handle(&api.egl_handle, EGL_LIB, false);
+ get_dlopen_handle(&api.egl_handle, EGL_LIB, false, true);
if (api.egl_handle) {
+ int version = 0;
switch (epoxy_egl_get_current_gl_context_api()) {
case EGL_OPENGL_API:
return epoxy_gl_dlsym(name);
case EGL_OPENGL_ES_API:
- /* We can't resolve the GL version, because
- * epoxy_glGetString() is one of the two things calling
- * us. Try the GLES2 implementation first, and fall back
- * to GLES1 otherwise.
- */
- get_dlopen_handle(&api.gles2_handle, GLES2_LIB, false);
- if (api.gles2_handle)
- return epoxy_gles2_dlsym(name);
- else
- return epoxy_gles1_dlsym(name);
+ if (eglQueryContext(eglGetCurrentDisplay(),
+ eglGetCurrentContext(),
+ EGL_CONTEXT_CLIENT_VERSION,
+ &version)) {
+ if (version >= 2)
+ return epoxy_gles2_dlsym(name);
+ else
+ return epoxy_gles1_dlsym(name);
+ }
}
}
#endif /* PLATFORM_HAS_EGL */
@@ -784,7 +868,7 @@ epoxy_get_proc_address(const char *name)
#elif PLATFORM_HAS_GLX
if (epoxy_current_context_is_glx())
return glXGetProcAddressARB((const GLubyte *)name);
- errx(1, "Couldn't find current GLX or EGL context.\n");
+ assert(0 && "Couldn't find current GLX or EGL context.\n");
#endif
return NULL;
@@ -820,3 +904,28 @@ WRAPPER(epoxy_glEnd)(void)
PFNGLBEGINPROC epoxy_glBegin = epoxy_glBegin_wrapped;
PFNGLENDPROC epoxy_glEnd = epoxy_glEnd_wrapped;
+
+epoxy_resolver_failure_handler_t epoxy_resolver_failure_handler;
+
+/**
+ * Sets the function that will be called every time Epoxy fails to
+ * resolve a symbol.
+ *
+ * @param handler The new handler function
+ * @return The previous handler function
+ */
+epoxy_resolver_failure_handler_t
+epoxy_set_resolver_failure_handler(epoxy_resolver_failure_handler_t handler)
+{
+#ifdef _WIN32
+ return InterlockedExchangePointer((void**)&epoxy_resolver_failure_handler,
+ handler);
+#else
+ epoxy_resolver_failure_handler_t old;
+ pthread_mutex_lock(&api.mutex);
+ old = epoxy_resolver_failure_handler;
+ epoxy_resolver_failure_handler = handler;
+ pthread_mutex_unlock(&api.mutex);
+ return old;
+#endif
+}
Index: xsrc/external/mit/libepoxy/dist/src/dispatch_common.h
diff -u xsrc/external/mit/libepoxy/dist/src/dispatch_common.h:1.7 xsrc/external/mit/libepoxy/dist/src/dispatch_common.h:1.8
--- xsrc/external/mit/libepoxy/dist/src/dispatch_common.h:1.7 Wed Jul 10 07:10:48 2019
+++ xsrc/external/mit/libepoxy/dist/src/dispatch_common.h Mon Nov 2 04:46:29 2020
@@ -28,7 +28,7 @@
#define PLATFORM_HAS_GLX ENABLE_GLX
#define PLATFORM_HAS_WGL 1
#elif defined(__APPLE__)
-#define PLATFORM_HAS_EGL ENABLE_EGL
+#define PLATFORM_HAS_EGL 0
#define PLATFORM_HAS_GLX ENABLE_GLX
#define PLATFORM_HAS_WGL 0
#elif defined(ANDROID)
@@ -56,6 +56,13 @@
#include "epoxy/glx.h"
#endif
#if PLATFORM_HAS_EGL
+# if !ENABLE_X11
+/* Mesa uses this symbol to avoid including X11 headers when including
+ * EGL.h; since X11 was explicitly disabled at configuration time, we
+ * should do the same
+ */
+# define MESA_EGL_NO_X11_HEADERS 1
+# endif
#include "epoxy/egl.h"
#endif
#if PLATFORM_HAS_WGL
@@ -88,10 +95,11 @@
#define WRAPPER(x) x ## _wrapped
#define GEN_GLOBAL_REWRITE_PTR(name, args, passthrough) \
- static void EPOXY_CALLSPEC \
+ static void EPOXY_CALLSPEC \
name##_global_rewrite_ptr args \
{ \
- name = (void *)name##_resolver(); \
+ if (name == (void *)name##_global_rewrite_ptr) \
+ name = (void *)name##_resolver(); \
name passthrough; \
}
@@ -99,7 +107,8 @@
static ret EPOXY_CALLSPEC \
name##_global_rewrite_ptr args \
{ \
- name = (void *)name##_resolver(); \
+ if (name == (void *)name##_global_rewrite_ptr) \
+ name = (void *)name##_resolver(); \
return name passthrough; \
}
@@ -175,13 +184,16 @@ bool epoxy_conservative_has_wgl_extensio
void *epoxy_conservative_egl_dlsym(const char *name, bool exit_if_fails);
void *epoxy_conservative_glx_dlsym(const char *name, bool exit_if_fails);
-bool epoxy_extension_in_string(const char *extension_list, const char *ext);
+bool epoxy_load_glx(bool exit_if_fails, bool load);
+bool epoxy_load_egl(bool exit_if_fails, bool load);
#define glBegin_unwrapped epoxy_glBegin_unwrapped
#define glEnd_unwrapped epoxy_glEnd_unwrapped
extern void UNWRAPPED_PROTO(glBegin_unwrapped)(GLenum primtype);
extern void UNWRAPPED_PROTO(glEnd_unwrapped)(void);
+extern epoxy_resolver_failure_handler_t epoxy_resolver_failure_handler;
+
#if USING_DISPATCH_TABLE
void gl_init_dispatch_table(void);
void gl_switch_to_dispatch_table(void);