Blob Blame History Raw
From f8b473bc44b01eeeca9ebada47ff1165c27f9deb Mon Sep 17 00:00:00 2001
From: Adam Jackson <ajax@redhat.com>
Date: Wed, 12 Jul 2017 13:26:05 -0400
Subject: [PATCH 4/5] dispatch: Be more paranoid about detecting GLX or not

This code attempts not to dlopen anything if it can find the appropriate
winsys symbols in the global namespace. That's nice. However we normally
do dlopen(RTLD_LOCAL) when we open lib{GLX,EGL} so those symbols will
_not_ in fact be in the global namespace. The code also prefers checking
GLX to EGL, which means even if we initialize EGL through epoxy, and
even if we're using glvnd, we'll still dlopen libGL the first time we
hit epoxy_is_desktop_gl().

There's a couple of ways to skin this cat, let's take the easy one. If
either-but-not-both of the glx or egl handles in the global API state
are initialized, then we know we're already in one or the other. If
neither or both are initialized, then the current heuristic should work
fine.

Note that epoxy_is_desktop_gl() is only bothering to check for GLX to
work around PowerVR's broken GLES. One suspects a better way to do that
would be to check GL_VENDOR or GL_RENDERER and avoid probing the window
system at all.

Signed-off-by: Adam Jackson <ajax@redhat.com>
(cherry picked from commit 7c4817f2eed2faf0353c1ceb5f38b500f6aff7cf)
---
 src/dispatch_common.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/src/dispatch_common.c b/src/dispatch_common.c
index 48bd3f5..87bd98a 100644
--- a/src/dispatch_common.c
+++ b/src/dispatch_common.c
@@ -522,6 +522,16 @@ epoxy_current_context_is_glx(void)
 #if !PLATFORM_HAS_GLX
     return false;
 #else
+    void *sym;
+
+    /* If we've been called already, don't load more */
+    if (!api.egl_handle != !api.glx_handle) {
+	if (api.glx_handle)
+	    return true;
+	else if (api.egl_handle)
+	    return false;
+    }
+
     /* If the application hasn't explicitly called some of our GLX
      * or EGL code but has presumably set up a context on its own,
      * then we need to figure out how to getprocaddress anyway.
@@ -529,7 +539,6 @@ epoxy_current_context_is_glx(void)
      * If there's a public GetProcAddress loaded in the
      * application's namespace, then use that.
      */
-    void *sym;
 
     sym = dlsym(NULL, "glXGetCurrentContext");
     if (sym) {
-- 
2.13.5