summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEmmanuele Bassi <ebassi@gnome.org>2017-02-06 15:59:24 +0000
committerEmmanuele Bassi <ebassi@gnome.org>2017-02-06 15:59:24 +0000
commit7782509bdbb429cf884d5a1dc28fa9132075ae6a (patch)
treea169508cd452071c64787a0b172a8c5255d9dd13 /src
parentec93dcd5a13de753b853141780ba6021ff371cc6 (diff)
parent075172f485fe7d4006f84237eef49a586b92c380 (diff)
downloadlibepoxy-7782509bdbb429cf884d5a1dc28fa9132075ae6a.tar.gz
Add API to allow for platform detection
On Linux and other Unix variants we may not have access to GLX and EGL at run time. Dependent libraries can only discover this by using dlsym() on various symbols, because as soon as they attempt to call those symbols through Epoxy, Epoxy will abort. This means that a bunch of code needs to be copy-pasted between projects, with the high chance of somebody getting it wrong. Epoxy already has all the internals needed to detect whether GLX and EGL are available, so exposing a simple API is a better alternative. Fixes #73
Diffstat (limited to 'src')
-rw-r--r--src/dispatch_common.c16
-rw-r--r--src/dispatch_common.h2
-rw-r--r--src/dispatch_egl.c21
-rw-r--r--src/dispatch_glx.c26
4 files changed, 62 insertions, 3 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
@@ -569,15 +569,27 @@ epoxy_conservative_has_gl_extension(const char *ext)
}
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 b41f54b..e3277f7 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);
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 */
+}
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 */
+}