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
macos/v1.5.9
Emmanuele Bassi 8 years ago
commit 7782509bdb
  1. 1
      include/epoxy/egl.h
  2. 1
      include/epoxy/glx.h
  3. 16
      src/dispatch_common.c
  4. 2
      src/dispatch_common.h
  5. 21
      src/dispatch_egl.c
  6. 26
      src/dispatch_glx.c

@ -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

@ -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

@ -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 *

@ -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);

@ -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 */
}

@ -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 */
}

Loading…
Cancel
Save