From acdd6d8bf88a5381800affaaf59fd4c5300b6cd6 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Fri, 3 Feb 2017 15:35:38 +0000 Subject: Drop additional stdbool.h include directives --- src/dispatch_common.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/dispatch_common.h b/src/dispatch_common.h index 40d4bbc..2cc566a 100644 --- a/src/dispatch_common.h +++ b/src/dispatch_common.h @@ -23,8 +23,6 @@ #include "config.h" -#include - #ifdef _WIN32 #define PLATFORM_HAS_EGL 0 #define PLATFORM_HAS_GLX 0 -- cgit v1.2.1 From 30b8a4cd2d115eab93ca39709c956f48aa8dadbe Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Fri, 3 Feb 2017 16:13:45 +0000 Subject: Add conservative functions for checking platform symbols MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When checking whether GLX or EGL are available on the system, we don't want to use the internal API that forces an exit() on missing libraries and symbols — as that would defeat the point. Instead, we should have safe functions to call internally that simply return a NULL pointer, so we can bail out ourselves in a controlled fashion. --- src/dispatch_common.c | 16 ++++++++++++++-- src/dispatch_common.h | 2 ++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/dispatch_common.c b/src/dispatch_common.c index 17d0c5e..b521b1b 100644 --- a/src/dispatch_common.c +++ b/src/dispatch_common.c @@ -568,16 +568,28 @@ epoxy_conservative_has_gl_extension(const char *ext) return epoxy_internal_has_gl_extension(ext, true); } +void * +epoxy_conservative_egl_dlsym(const char *name, bool exit_if_fails) +{ + return do_dlsym(&api.egl_handle, EGL_LIB, name, exit_if_fails); +} + void * epoxy_egl_dlsym(const char *name) { - return do_dlsym(&api.egl_handle, EGL_LIB, name, true); + return epoxy_conservative_egl_dlsym(name, true); +} + +void * +epoxy_conservative_glx_dlsym(const char *name, bool exit_if_fails) +{ + return do_dlsym(&api.glx_handle, GLX_LIB, name, exit_if_fails); } void * epoxy_glx_dlsym(const char *name) { - return do_dlsym(&api.glx_handle, GLX_LIB, name, true); + return epoxy_conservative_glx_dlsym(name, true); } void * diff --git a/src/dispatch_common.h b/src/dispatch_common.h index 2cc566a..9d38a78 100644 --- a/src/dispatch_common.h +++ b/src/dispatch_common.h @@ -162,6 +162,8 @@ bool epoxy_conservative_has_glx_extension(const char *name); int epoxy_conservative_egl_version(void); bool epoxy_conservative_has_egl_extension(const char *name); bool epoxy_conservative_has_wgl_extension(const char *name); +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); -- cgit v1.2.1 From d94b9c28b53b1bf99f4a497486af681d8bc95d95 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Fri, 3 Feb 2017 16:16:13 +0000 Subject: 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 */ +} -- cgit v1.2.1 From 075172f485fe7d4006f84237eef49a586b92c380 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Fri, 3 Feb 2017 16:19:30 +0000 Subject: Add epoxy_has_egl() Similar to `epoxy_has_glx()`, but for the EGL windowing system API. --- include/epoxy/egl.h | 1 + src/dispatch_egl.c | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/include/epoxy/egl.h b/include/epoxy/egl.h index 2550acc..d5083da 100644 --- a/include/epoxy/egl.h +++ b/include/epoxy/egl.h @@ -47,6 +47,7 @@ EPOXY_BEGIN_DECLS EPOXY_PUBLIC bool epoxy_has_egl_extension(EGLDisplay dpy, const char *extension); EPOXY_PUBLIC int epoxy_egl_version(EGLDisplay dpy); +EPOXY_PUBLIC bool epoxy_has_egl(void); EPOXY_END_DECLS diff --git a/src/dispatch_egl.c b/src/dispatch_egl.c index 7f970d9..a85a016 100644 --- a/src/dispatch_egl.c +++ b/src/dispatch_egl.c @@ -92,3 +92,24 @@ epoxy_has_egl_extension(EGLDisplay dpy, const char *ext) { return epoxy_extension_in_string(eglQueryString(dpy, EGL_EXTENSIONS), ext) || epoxy_extension_in_string(eglQueryString(NULL, EGL_EXTENSIONS), ext); } + +/** + * @brief Checks whether EGL is available. + * + * @return `true` if EGL is available + */ +bool +epoxy_has_egl(void) +{ +#if !PLATFORM_HAS_EGL + return false; +#else + EGLDisplay* (* pf_eglGetCurrentDisplay) (void); + + pf_eglGetCurrentDisplay = epoxy_conservative_egl_dlsym("eglGetCurrentDisplay", false); + if (pf_eglGetCurrentDisplay) + return true; + + return false; +#endif /* PLATFORM_HAS_EGL */ +} -- cgit v1.2.1