diff --git a/include/epoxy/glx_common.h b/include/epoxy/glx_common.h index c23ec72..4ad08c7 100644 --- a/include/epoxy/glx_common.h +++ b/include/epoxy/glx_common.h @@ -34,7 +34,7 @@ #include #include -bool epoxy_has_glx_extension(const char *extension); +bool epoxy_has_glx_extension(Display *dpy, int screen, const char *extension); int epoxy_glx_version(Display *dpy, int screen); #endif /* EPOXY_GLX_COMMON_H */ diff --git a/src/dispatch_common.c b/src/dispatch_common.c index a32b30b..31885fb 100644 --- a/src/dispatch_common.c +++ b/src/dispatch_common.c @@ -212,17 +212,29 @@ epoxy_has_egl_extension(const char *ext) } #endif -PUBLIC bool -epoxy_has_glx_extension(const char *ext) +/** + * If we can determine the GLX extension support from the current + * context, then return that, otherwise give the answer that will just + * send us on to get_proc_address(). + */ +bool +epoxy_conservative_has_glx_extension(const char *ext) { Display *dpy = glXGetCurrentDisplay(); - int screen = 0; + GLXContext ctx = glXGetCurrentContext(); + int screen; - if (!dpy) { - fprintf(stderr, "waffle needs a display!"); /* XXX */ - return false; - } + if (!dpy || !ctx) + return true; + glXQueryContext(dpy, ctx, GLX_SCREEN, &screen); + + return epoxy_has_glx_extension(dpy, screen, ext); +} + +PUBLIC 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 diff --git a/src/dispatch_common.h b/src/dispatch_common.h index ed3fa5b..8256134 100644 --- a/src/dispatch_common.h +++ b/src/dispatch_common.h @@ -50,6 +50,7 @@ bool epoxy_is_glx(void); void *epoxy_get_proc_address(const char *name); int epoxy_conservative_glx_version(void); +bool epoxy_conservative_has_glx_extension(const char *name); void *epoxy_dlsym(const char *name); void epoxy_glx_autoinit(void); void epoxy_platform_autoinit(void); diff --git a/src/gen_dispatch.py b/src/gen_dispatch.py index 8b9cc54..b052305 100755 --- a/src/gen_dispatch.py +++ b/src/gen_dispatch.py @@ -308,7 +308,7 @@ class Generator(object): apis = extension.get('supported').split('|') if 'glx' in apis: human_name = 'GLX extension \\"{0}\\"'.format(extname) - condition = 'epoxy_has_glx_extension("{0}")'.format(extname) + condition = 'epoxy_conservative_has_glx_extension("{0}")'.format(extname) loader = self.gpa_loader self.process_require_statements(extension, condition, loader, human_name) if 'gl' in apis: diff --git a/test/Makefile.am b/test/Makefile.am index e282f3f..81263b0 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -38,8 +38,6 @@ TESTS = \ headerguards \ $() -XFAIL_TESTS = glx_has_extension_nocontext - check_PROGRAMS = $(TESTS) glx_public_api_LDFLAGS = $(X11_LIBS) $(EPOXY) libglx_common.la diff --git a/test/glx_has_extension_nocontext.c b/test/glx_has_extension_nocontext.c index 5aeaa4e..2f87ac3 100644 --- a/test/glx_has_extension_nocontext.c +++ b/test/glx_has_extension_nocontext.c @@ -46,10 +46,10 @@ main(int argc, char **argv) dpy = get_display_or_skip(); - if (!epoxy_has_glx_extension("GLX_ARB_get_proc_address")) + if (!epoxy_has_glx_extension(dpy, 0, "GLX_ARB_get_proc_address")) errx(1, "Implementation reported absence of GLX_ARB_get_proc_address"); - if (epoxy_has_glx_extension("GLX_ARB_ham_sandwich")) + if (epoxy_has_glx_extension(dpy, 0, "GLX_ARB_ham_sandwich")) errx(1, "Implementation reported presence of GLX_ARB_ham_sandwich"); return pass != true; diff --git a/test/glx_public_api.c b/test/glx_public_api.c index e89a4a4..e38d260 100644 --- a/test/glx_public_api.c +++ b/test/glx_public_api.c @@ -91,14 +91,14 @@ test_glx_version(void) static bool test_glx_extension_supported(void) { - if (!epoxy_has_glx_extension("GLX_ARB_get_proc_address")) { + if (!epoxy_has_glx_extension(dpy, 0, "GLX_ARB_get_proc_address")) { fprintf(stderr, "Incorrectly reported no support for GLX_ARB_get_proc_address " "(should always be present in Linux ABI)\n"); return false; } - if (epoxy_has_glx_extension("GLX_EXT_ham_sandwich")) { + if (epoxy_has_glx_extension(dpy, 0, "GLX_EXT_ham_sandwich")) { fprintf(stderr, "Incorrectly reported support for GLX_EXT_ham_sandwich\n"); return false;