[PATCH xserver] glamor: Use eglGetPlatformDisplay{,EXT} if we can

Adam Jackson ajax at redhat.com
Wed Oct 5 16:34:34 UTC 2016


eglGetDisplay forces the implementation to guess which kind of display
it's been handed. glvnd does something different from Mesa, and in
general it's impossible for the library to get this right. Add a new
inline that gets the logic right, and works around a quirk in epoxy.

Signed-off-by: Adam Jackson <ajax at redhat.com>
---
 glamor/Makefile.am            |  4 ++-
 glamor/glamor_egl.c           |  8 ++---
 glamor/glamor_egl.h           | 82 +++++++++++++++++++++++++++++++++++++++++++
 hw/xwayland/xwayland-glamor.c |  8 ++---
 4 files changed, 93 insertions(+), 9 deletions(-)
 create mode 100644 glamor/glamor_egl.h

diff --git a/glamor/Makefile.am b/glamor/Makefile.am
index c631c53..8c79994 100644
--- a/glamor/Makefile.am
+++ b/glamor/Makefile.am
@@ -54,6 +54,8 @@ libglamor_la_SOURCES += \
 	glamor_xv.c
 endif
 
-libglamor_egl_stubs_la_SOURCES = glamor_egl_stubs.c
+libglamor_egl_stubs_la_SOURCES = \
+	glamor_egl_stubs.c \
+	glamor_egl.h
 
 sdk_HEADERS = glamor.h
diff --git a/glamor/glamor_egl.c b/glamor/glamor_egl.c
index 2b9e0e1..9cc0f8d 100644
--- a/glamor/glamor_egl.c
+++ b/glamor/glamor_egl.c
@@ -43,9 +43,7 @@
 #include <drm_fourcc.h>
 #endif
 
-#define MESA_EGL_NO_X11_HEADERS
-#include <epoxy/gl.h>
-#include <epoxy/egl.h>
+#include "glamor_egl.h"
 
 #include "glamor.h"
 #include "glamor_priv.h"
@@ -768,7 +766,9 @@ glamor_egl_init(ScrnInfoPtr scrn, int fd)
         ErrorF("couldn't get display device\n");
         goto error;
     }
-    glamor_egl->display = eglGetDisplay(glamor_egl->gbm);
+
+    glamor_egl->display = glamor_egl_get_display(EGL_PLATFORM_GBM_MESA,
+                                                 glamor_egl->gbm);
 #else
     glamor_egl->display = eglGetDisplay((EGLNativeDisplayType) (intptr_t) fd);
 #endif
diff --git a/glamor/glamor_egl.h b/glamor/glamor_egl.h
new file mode 100644
index 0000000..147aae6
--- /dev/null
+++ b/glamor/glamor_egl.h
@@ -0,0 +1,82 @@
+/*
+ * Copyright © 2016 Red Hat, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ *	Adam Jackson <ajax at redhat.com>
+ */
+
+#ifndef GLAMOR_EGL_H
+#define GLAMOR_EGL_H
+
+#define MESA_EGL_NO_X11_HEADERS
+#include <epoxy/gl.h>
+#include <epoxy/egl.h>
+
+/*
+ * Create an EGLDisplay from a native display type. This is a little quirky
+ * for a few reasons.
+ *
+ * 1: GetPlatformDisplayEXT and GetPlatformDisplay are the API you want to
+ * use, but have different function signatures in the third argument; this
+ * happens not to matter for us, at the moment, but it means epoxy won't alias
+ * them together.
+ *
+ * 2: epoxy 1.3 and earlier don't understand EGL client extensions, which
+ * means you can't call "eglGetPlatformDisplayEXT" directly, as the resolver
+ * will crash.
+ *
+ * 3: You can't tell whether you have EGL 1.5 at this point, because
+ * eglQueryString(EGL_VERSION) is a property of the display, which we don't
+ * have yet. So you have to query for extensions no matter what. Fortunately
+ * epoxy_has_egl_extension _does_ let you query for client extensions, so
+ * we don't have to write our own extension string parsing.
+ */
+static inline EGLDisplay
+glamor_egl_get_display(EGLint type, void *native)
+{
+    EGLDisplay dpy = NULL;
+
+    /* If we're EGL 1.5, the KHR extension will be there, try that */
+    if (epoxy_has_egl_extension(NULL, "EGL_KHR_platform_base")) {
+        PFNEGLGETPLATFORMDISPLAYPROC getPlatformDisplay =
+            (void *) eglGetProcAddress("eglGetPlatformDisplay");
+        if (getPlatformDisplay)
+            dpy = getPlatformDisplay(type, native, NULL);
+        if (dpy)
+            return dpy;
+    }
+
+    /* Okay, maybe the EXT extension works */
+    if (epoxy_has_egl_extension(NULL, "EGL_EXT_platform_base")) {
+        PFNEGLGETPLATFORMDISPLAYEXTPROC getPlatformDisplayEXT =
+            (void *) eglGetProcAddress("eglGetPlatformDisplayEXT");
+        if (getPlatformDisplayEXT)
+            dpy = getPlatformDisplayEXT(type, native, NULL);
+        if (dpy)
+            return dpy;
+    }
+
+    /* Welp, everything is awful. */
+    return eglGetDisplay(native);
+}
+
+#endif
diff --git a/hw/xwayland/xwayland-glamor.c b/hw/xwayland/xwayland-glamor.c
index 068c224..b3d0aab 100644
--- a/hw/xwayland/xwayland-glamor.c
+++ b/hw/xwayland/xwayland-glamor.c
@@ -31,8 +31,7 @@
 
 #define MESA_EGL_NO_X11_HEADERS
 #include <gbm.h>
-#include <epoxy/egl.h>
-#include <epoxy/gl.h>
+#include <glamor_egl.h>
 
 #include <glamor.h>
 #include <glamor_context.h>
@@ -292,9 +291,10 @@ xwl_drm_init_egl(struct xwl_screen *xwl_screen)
         return;
     }
 
-    xwl_screen->egl_display = eglGetDisplay(xwl_screen->gbm);
+    xwl_screen->egl_display = glamor_egl_get_display(EGL_PLATFORM_GBM_MESA,
+                                                     xwl_screen->gbm);
     if (xwl_screen->egl_display == EGL_NO_DISPLAY) {
-        ErrorF("eglGetDisplay() failed\n");
+        ErrorF("glamor_egl_get_display() failed\n");
         return;
     }
 
-- 
2.9.3



More information about the xorg-devel mailing list