a93c5b0
From 1a9c35461dc93979dbc45a201a6670eb049bb285 Mon Sep 17 00:00:00 2001
a93c5b0
From: Adam Jackson <ajax@redhat.com>
a93c5b0
Date: Mon, 10 Oct 2016 14:12:40 -0400
a93c5b0
Subject: [PATCH 2/2] Use eglGetPlatformDisplay{,EXT} if available
a93c5b0
a93c5b0
Calling eglGetDisplay forces libEGL to guess what kind of pointer you
a93c5b0
passed it. Different EGL libraries will do different things here, and in
a93c5b0
particular glvnd will do something different than Mesa. Since we do have
a93c5b0
an API that allows us to explicitly type the display, use it.
a93c5b0
a93c5b0
The explicit call to eglGetProcAddress is working around a bug in
a93c5b0
libepoxy 1.3, which does not understand the EGL concept of client
a93c5b0
extensions. Since it does not, the normal epoxy resolver for
a93c5b0
eglGetPlatformDisplayEXT would not find any provider for that entry
a93c5b0
point, and crash when you attempted to call it.
a93c5b0
a93c5b0
Signed-off-by: Adam Jackson <ajax@redhat.com>
a93c5b0
---
a93c5b0
 gdk/wayland/gdkglcontext-wayland.c | 37 ++++++++++++++++++++++++++++++++++++-
a93c5b0
 gtk/inspector/general.c            | 32 +++++++++++++++++++++++++++++++-
a93c5b0
 2 files changed, 67 insertions(+), 2 deletions(-)
a93c5b0
a93c5b0
diff --git a/gdk/wayland/gdkglcontext-wayland.c b/gdk/wayland/gdkglcontext-wayland.c
a93c5b0
index ae1354e..6573688 100644
a93c5b0
--- a/gdk/wayland/gdkglcontext-wayland.c
a93c5b0
+++ b/gdk/wayland/gdkglcontext-wayland.c
a93c5b0
@@ -274,6 +274,40 @@ gdk_wayland_gl_context_init (GdkWaylandGLContext *self)
a93c5b0
 {
a93c5b0
 }
a93c5b0
 
a93c5b0
+static EGLDisplay
a93c5b0
+gdk_wayland_get_display (GdkWaylandDisplay *display_wayland)
a93c5b0
+{
a93c5b0
+  EGLDisplay dpy = NULL;
a93c5b0
+
a93c5b0
+  if (epoxy_has_egl_extension (NULL, "EGL_KHR_platform_base"))
a93c5b0
+    {
a93c5b0
+      PFNEGLGETPLATFORMDISPLAYPROC getPlatformDisplay =
a93c5b0
+	(void *) eglGetProcAddress ("eglGetPlatformDisplay");
a93c5b0
+
a93c5b0
+      if (getPlatformDisplay)
a93c5b0
+	dpy = getPlatformDisplay (EGL_PLATFORM_WAYLAND_EXT,
a93c5b0
+				  display_wayland->wl_display,
a93c5b0
+				  NULL);
a93c5b0
+      if (dpy)
a93c5b0
+	return dpy;
a93c5b0
+    }
a93c5b0
+
a93c5b0
+  if (epoxy_has_egl_extension (NULL, "EGL_EXT_platform_base"))
a93c5b0
+    {
a93c5b0
+      PFNEGLGETPLATFORMDISPLAYEXTPROC getPlatformDisplay =
a93c5b0
+	(void *) eglGetProcAddress ("eglGetPlatformDisplayEXT");
a93c5b0
+
a93c5b0
+      if (getPlatformDisplay)
a93c5b0
+	dpy = getPlatformDisplay (EGL_PLATFORM_WAYLAND_EXT,
a93c5b0
+				  display_wayland->wl_display,
a93c5b0
+				  NULL);
a93c5b0
+      if (dpy)
a93c5b0
+	return dpy;
a93c5b0
+    }
a93c5b0
+
a93c5b0
+  return eglGetDisplay ((EGLNativeDisplayType) display_wayland->wl_display);
a93c5b0
+}
a93c5b0
+
a93c5b0
 gboolean
a93c5b0
 gdk_wayland_display_init_gl (GdkDisplay *display)
a93c5b0
 {
a93c5b0
@@ -284,7 +318,8 @@ gdk_wayland_display_init_gl (GdkDisplay *display)
a93c5b0
   if (display_wayland->have_egl)
a93c5b0
     return TRUE;
a93c5b0
 
a93c5b0
-  dpy = eglGetDisplay ((EGLNativeDisplayType)display_wayland->wl_display);
a93c5b0
+  dpy = gdk_wayland_get_display (display_wayland);
a93c5b0
+
a93c5b0
   if (dpy == NULL)
a93c5b0
     return FALSE;
a93c5b0
 
a93c5b0
diff --git a/gtk/inspector/general.c b/gtk/inspector/general.c
a93c5b0
index 77d0a76..f32f7fe 100644
a93c5b0
--- a/gtk/inspector/general.c
a93c5b0
+++ b/gtk/inspector/general.c
a93c5b0
@@ -214,6 +214,36 @@ append_egl_extension_row (GtkInspectorGeneral *gen,
a93c5b0
 {
a93c5b0
   add_check_row (gen, GTK_LIST_BOX (gen->priv->gl_box), ext, epoxy_has_egl_extension (dpy, ext), 0);
a93c5b0
 }
a93c5b0
+
a93c5b0
+static EGLDisplay
a93c5b0
+wayland_get_display (struct wl_display *wl_dpy)
a93c5b0
+{
a93c5b0
+  EGLDisplay dpy = NULL;
a93c5b0
+
a93c5b0
+  if (epoxy_has_egl_extension (NULL, "EGL_KHR_platform_base"))
a93c5b0
+    {
a93c5b0
+      PFNEGLGETPLATFORMDISPLAYPROC getPlatformDisplay =
a93c5b0
+        (void *) eglGetProcAddress ("eglGetPlatformDisplay");
a93c5b0
+
a93c5b0
+      if (getPlatformDisplay)
a93c5b0
+        dpy = getPlatformDisplay (EGL_PLATFORM_WAYLAND_EXT, wl_dpy, NULL);
a93c5b0
+      if (dpy)
a93c5b0
+        return dpy;
a93c5b0
+    }
a93c5b0
+
a93c5b0
+  if (epoxy_has_egl_extension (NULL, "EGL_EXT_platform_base"))
a93c5b0
+    {
a93c5b0
+      PFNEGLGETPLATFORMDISPLAYEXTPROC getPlatformDisplay =
a93c5b0
+        (void *) eglGetProcAddress ("eglGetPlatformDisplayEXT");
a93c5b0
+
a93c5b0
+      if (getPlatformDisplay)
a93c5b0
+        dpy = getPlatformDisplay (EGL_PLATFORM_WAYLAND_EXT, wl_dpy, NULL);
a93c5b0
+      if (dpy)
a93c5b0
+        return dpy;
a93c5b0
+    }
a93c5b0
+
a93c5b0
+  return eglGetDisplay ((EGLNativeDisplayType) wl_dpy);
a93c5b0
+}
a93c5b0
 #endif
a93c5b0
 
a93c5b0
 
a93c5b0
@@ -254,7 +284,7 @@ init_gl (GtkInspectorGeneral *gen)
a93c5b0
       EGLint major, minor;
a93c5b0
       gchar *version;
a93c5b0
 
a93c5b0
-      dpy = eglGetDisplay ((EGLNativeDisplayType)gdk_wayland_display_get_wl_display (display));
a93c5b0
+      dpy = wayland_get_display (gdk_wayland_display_get_wl_display (display));
a93c5b0
 
a93c5b0
       if (!eglInitialize (dpy, &major, &minor))
a93c5b0
         return;
a93c5b0
-- 
a93c5b0
2.9.3
a93c5b0