From d94b9c28b53b1bf99f4a497486af681d8bc95d95 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Fri, 3 Feb 2017 16:16:13 +0000 Subject: [PATCH] Add epoxy_has_glx() Libraries and applications that depend on Epoxy currently have no way to safely degrade functionality if they are used on a platform without GLX support; the only way to achieve that is to perform a symbol check themselves, by essentially copying what Epoxy already does. By exposing `epoxy_has_glx()`, those libraries and applications now have the chance of querying Epoxy itself and gracefully handle failure. --- include/epoxy/glx.h | 1 + src/dispatch_glx.c | 26 +++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/include/epoxy/glx.h b/include/epoxy/glx.h index c911b7c..a06b13d 100644 --- a/include/epoxy/glx.h +++ b/include/epoxy/glx.h @@ -50,6 +50,7 @@ EPOXY_BEGIN_DECLS EPOXY_PUBLIC bool epoxy_has_glx_extension(Display *dpy, int screen, const char *extension); EPOXY_PUBLIC int epoxy_glx_version(Display *dpy, int screen); +EPOXY_PUBLIC bool epoxy_has_glx(Display *dpy); EPOXY_END_DECLS diff --git a/src/dispatch_glx.c b/src/dispatch_glx.c index a74725e..c2b632c 100644 --- a/src/dispatch_glx.c +++ b/src/dispatch_glx.c @@ -133,7 +133,7 @@ epoxy_conservative_has_glx_extension(const char *ext) */ bool epoxy_has_glx_extension(Display *dpy, int screen, const char *ext) - { +{ /* No, you can't just use glXGetClientString or * glXGetServerString() here. Those each tell you about one half * of what's needed for an extension to be supported, and @@ -142,3 +142,27 @@ epoxy_has_glx_extension(Display *dpy, int screen, const char *ext) */ return epoxy_extension_in_string(glXQueryExtensionsString(dpy, screen), ext); } + +/** + * @brief Checks whether GLX is available. + * + * @param dpy The X11 display + * + * @return `true` if GLX is available + */ +bool +epoxy_has_glx(Display *dpy) +{ +#if !PLATFORM_HAS_GLX + return false; +#else + Bool (* pf_glXQueryExtension) (Display *, int *, int *); + int error_base, event_base; + + pf_glXQueryExtension = epoxy_conservative_glx_dlsym("glXQueryExtension", false); + if (pf_glXQueryExtension && pf_glXQueryExtension(dpy, &error_base, &event_base)) + return true; + + return false; +#endif /* !PLATFORM_HAS_GLX */ +}