From 91c9ecebd963c7af1f0ef3d1333ca0a723bdd6d4 Mon Sep 17 00:00:00 2001 From: Adam Jackson Date: Wed, 12 Jul 2017 13:59:44 -0400 Subject: [PATCH 1/3] dispatch: Don't reference glvnd #defines on non-glvnd systems Broke the build on OSX, oops. Resolves: https://github.com/anholt/libepoxy/issues/132 Signed-off-by: Adam Jackson --- src/dispatch_common.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/dispatch_common.c b/src/dispatch_common.c index bbbf913..a7c2f74 100644 --- a/src/dispatch_common.c +++ b/src/dispatch_common.c @@ -597,9 +597,11 @@ epoxy_egl_dlsym(const char *name) void * epoxy_conservative_glx_dlsym(const char *name, bool exit_if_fails) { +#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); +#endif return do_dlsym(&api.glx_handle, GLX_LIB, name, exit_if_fails); } From f81274b12470a0ce8678465112998708f63c3559 Mon Sep 17 00:00:00 2001 From: Adam Jackson Date: Wed, 12 Jul 2017 14:03:35 -0400 Subject: [PATCH 2/3] dispatch: Use epoxy_conservative_glx_dlsym when probing GLX This path should also only load libGLX.so if possible. Signed-off-by: Adam Jackson --- src/dispatch_common.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/dispatch_common.c b/src/dispatch_common.c index a7c2f74..48bd3f5 100644 --- a/src/dispatch_common.c +++ b/src/dispatch_common.c @@ -500,6 +500,18 @@ epoxy_internal_has_gl_extension(const char *ext, bool invalid_op_mode) } } +void * +epoxy_conservative_glx_dlsym(const char *name, bool exit_if_fails) +{ +#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); +#endif + + return do_dlsym(&api.glx_handle, GLX_LIB, name, exit_if_fails); +} + /** * Tests whether the currently bound context is EGL or GLX, trying to * avoid loading libraries unless necessary. @@ -541,7 +553,7 @@ epoxy_current_context_is_glx(void) * 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); + sym = epoxy_conservative_glx_dlsym("glXGetCurrentContext", false); if (sym && glXGetCurrentContext()) return true; @@ -594,18 +606,6 @@ epoxy_egl_dlsym(const char *name) return epoxy_conservative_egl_dlsym(name, true); } -void * -epoxy_conservative_glx_dlsym(const char *name, bool exit_if_fails) -{ -#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); -#endif - - return do_dlsym(&api.glx_handle, GLX_LIB, name, exit_if_fails); -} - void * epoxy_glx_dlsym(const char *name) { From 7c4817f2eed2faf0353c1ceb5f38b500f6aff7cf Mon Sep 17 00:00:00 2001 From: Adam Jackson Date: Wed, 12 Jul 2017 13:26:05 -0400 Subject: [PATCH 3/3] dispatch: Be more paranoid about detecting GLX or not This code attempts not to dlopen anything if it can find the appropriate winsys symbols in the global namespace. That's nice. However we normally do dlopen(RTLD_LOCAL) when we open lib{GLX,EGL} so those symbols will _not_ in fact be in the global namespace. The code also prefers checking GLX to EGL, which means even if we initialize EGL through epoxy, and even if we're using glvnd, we'll still dlopen libGL the first time we hit epoxy_is_desktop_gl(). There's a couple of ways to skin this cat, let's take the easy one. If either-but-not-both of the glx or egl handles in the global API state are initialized, then we know we're already in one or the other. If neither or both are initialized, then the current heuristic should work fine. Note that epoxy_is_desktop_gl() is only bothering to check for GLX to work around PowerVR's broken GLES. One suspects a better way to do that would be to check GL_VENDOR or GL_RENDERER and avoid probing the window system at all. Signed-off-by: Adam Jackson --- src/dispatch_common.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/dispatch_common.c b/src/dispatch_common.c index 48bd3f5..87bd98a 100644 --- a/src/dispatch_common.c +++ b/src/dispatch_common.c @@ -522,6 +522,16 @@ epoxy_current_context_is_glx(void) #if !PLATFORM_HAS_GLX return false; #else + void *sym; + + /* If we've been called already, don't load more */ + if (!api.egl_handle != !api.glx_handle) { + if (api.glx_handle) + return true; + else if (api.egl_handle) + return false; + } + /* 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. @@ -529,7 +539,6 @@ epoxy_current_context_is_glx(void) * If there's a public GetProcAddress loaded in the * application's namespace, then use that. */ - void *sym; sym = dlsym(NULL, "glXGetCurrentContext"); if (sym) {