Merge pull request #168 from nwnk/even-more-gentle-glx-detection

Even more gentle glx detection
macos/v1.5.9
Emmanuele Bassi 7 years ago committed by GitHub
commit b80ea6a36a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 55
      src/dispatch_common.c

@ -305,7 +305,11 @@ get_dlopen_handle(void **handle, const char *lib_name, bool exit_on_fail)
#else #else
pthread_mutex_lock(&api.mutex); pthread_mutex_lock(&api.mutex);
if (!*handle) { if (!*handle) {
*handle = dlopen(lib_name, RTLD_LAZY | RTLD_LOCAL); int flags = RTLD_LAZY | RTLD_LOCAL;
if (!exit_on_fail)
flags |= RTLD_NOLOAD;
*handle = dlopen(lib_name, flags);
if (!*handle) { if (!*handle) {
if (exit_on_fail) { if (exit_on_fail) {
fprintf(stderr, "Couldn't open %s: %s\n", lib_name, dlerror()); fprintf(stderr, "Couldn't open %s: %s\n", lib_name, dlerror());
@ -572,23 +576,7 @@ epoxy_current_context_is_glx(void)
#else #else
void *sym; void *sym;
/* If we've been called already, don't load more */ sym = epoxy_conservative_glx_dlsym("glXGetCurrentContext", false);
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.
*
* If there's a public GetProcAddress loaded in the
* application's namespace, then use that.
*/
sym = dlsym(NULL, "glXGetCurrentContext");
if (sym) { if (sym) {
if (glXGetCurrentContext()) if (glXGetCurrentContext())
return true; return true;
@ -597,7 +585,7 @@ epoxy_current_context_is_glx(void)
} }
#if PLATFORM_HAS_EGL #if PLATFORM_HAS_EGL
sym = dlsym(NULL, "eglGetCurrentContext"); sym = epoxy_conservative_egl_dlsym("eglGetCurrentContext", false);
if (sym) { if (sym) {
if (epoxy_egl_get_current_gl_context_api() != EGL_NONE) if (epoxy_egl_get_current_gl_context_api() != EGL_NONE)
return false; return false;
@ -606,21 +594,6 @@ epoxy_current_context_is_glx(void)
} }
#endif /* PLATFORM_HAS_EGL */ #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 = epoxy_conservative_glx_dlsym("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; return false;
#endif /* PLATFORM_HAS_GLX */ #endif /* PLATFORM_HAS_GLX */
} }
@ -812,22 +785,22 @@ epoxy_get_bootstrap_proc_address(const char *name)
#if PLATFORM_HAS_EGL #if PLATFORM_HAS_EGL
get_dlopen_handle(&api.egl_handle, EGL_LIB, false); get_dlopen_handle(&api.egl_handle, EGL_LIB, false);
if (api.egl_handle) { if (api.egl_handle) {
int version = 0;
switch (epoxy_egl_get_current_gl_context_api()) { switch (epoxy_egl_get_current_gl_context_api()) {
case EGL_OPENGL_API: case EGL_OPENGL_API:
return epoxy_gl_dlsym(name); return epoxy_gl_dlsym(name);
case EGL_OPENGL_ES_API: case EGL_OPENGL_ES_API:
/* We can't resolve the GL version, because if (eglQueryContext(eglGetCurrentDisplay(),
* epoxy_glGetString() is one of the two things calling eglGetCurrentContext(),
* us. Try the GLES2 implementation first, and fall back EGL_CONTEXT_CLIENT_VERSION,
* to GLES1 otherwise. &version)) {
*/ if (version >= 2)
get_dlopen_handle(&api.gles2_handle, GLES2_LIB, false);
if (api.gles2_handle)
return epoxy_gles2_dlsym(name); return epoxy_gles2_dlsym(name);
else else
return epoxy_gles1_dlsym(name); return epoxy_gles1_dlsym(name);
} }
} }
}
#endif /* PLATFORM_HAS_EGL */ #endif /* PLATFORM_HAS_EGL */
/* Fall back to GLX */ /* Fall back to GLX */

Loading…
Cancel
Save