Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try even harder to not load GLX #133

Merged
merged 3 commits into from
Jul 13, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 23 additions & 12 deletions src/dispatch_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -510,14 +522,23 @@ 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.
*
* If there's a public GetProcAddress loaded in the
* application's namespace, then use that.
*/
void *sym;

sym = dlsym(NULL, "glXGetCurrentContext");
if (sym) {
Expand All @@ -541,7 +562,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;

Expand Down Expand Up @@ -594,16 +615,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)
{
/* prefer the glvnd library if it exists */
if (!api.glx_handle)
get_dlopen_handle(&api.glx_handle, GLVND_GLX_LIB, false);

return do_dlsym(&api.glx_handle, GLX_LIB, name, exit_if_fails);
}

void *
epoxy_glx_dlsym(const char *name)
{
Expand Down