summaryrefslogtreecommitdiff
path: root/0002-Use-eglGetPlatformDisplay-EXT-if-available.patch
blob: c337f7c09a13ae102648188f57368966d48502e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
From 1a9c35461dc93979dbc45a201a6670eb049bb285 Mon Sep 17 00:00:00 2001
From: Adam Jackson <ajax@redhat.com>
Date: Mon, 10 Oct 2016 14:12:40 -0400
Subject: [PATCH 2/2] Use eglGetPlatformDisplay{,EXT} if available

Calling eglGetDisplay forces libEGL to guess what kind of pointer you
passed it. Different EGL libraries will do different things here, and in
particular glvnd will do something different than Mesa. Since we do have
an API that allows us to explicitly type the display, use it.

The explicit call to eglGetProcAddress is working around a bug in
libepoxy 1.3, which does not understand the EGL concept of client
extensions. Since it does not, the normal epoxy resolver for
eglGetPlatformDisplayEXT would not find any provider for that entry
point, and crash when you attempted to call it.

Signed-off-by: Adam Jackson <ajax@redhat.com>
---
 gdk/wayland/gdkglcontext-wayland.c | 37 ++++++++++++++++++++++++++++++++++++-
 gtk/inspector/general.c            | 32 +++++++++++++++++++++++++++++++-
 2 files changed, 67 insertions(+), 2 deletions(-)

diff --git a/gdk/wayland/gdkglcontext-wayland.c b/gdk/wayland/gdkglcontext-wayland.c
index ae1354e..6573688 100644
--- a/gdk/wayland/gdkglcontext-wayland.c
+++ b/gdk/wayland/gdkglcontext-wayland.c
@@ -274,6 +274,40 @@ gdk_wayland_gl_context_init (GdkWaylandGLContext *self)
 {
 }
 
+static EGLDisplay
+gdk_wayland_get_display (GdkWaylandDisplay *display_wayland)
+{
+  EGLDisplay dpy = NULL;
+
+  if (epoxy_has_egl_extension (NULL, "EGL_KHR_platform_base"))
+    {
+      PFNEGLGETPLATFORMDISPLAYPROC getPlatformDisplay =
+	(void *) eglGetProcAddress ("eglGetPlatformDisplay");
+
+      if (getPlatformDisplay)
+	dpy = getPlatformDisplay (EGL_PLATFORM_WAYLAND_EXT,
+				  display_wayland->wl_display,
+				  NULL);
+      if (dpy)
+	return dpy;
+    }
+
+  if (epoxy_has_egl_extension (NULL, "EGL_EXT_platform_base"))
+    {
+      PFNEGLGETPLATFORMDISPLAYEXTPROC getPlatformDisplay =
+	(void *) eglGetProcAddress ("eglGetPlatformDisplayEXT");
+
+      if (getPlatformDisplay)
+	dpy = getPlatformDisplay (EGL_PLATFORM_WAYLAND_EXT,
+				  display_wayland->wl_display,
+				  NULL);
+      if (dpy)
+	return dpy;
+    }
+
+  return eglGetDisplay ((EGLNativeDisplayType) display_wayland->wl_display);
+}
+
 gboolean
 gdk_wayland_display_init_gl (GdkDisplay *display)
 {
@@ -284,7 +318,8 @@ gdk_wayland_display_init_gl (GdkDisplay *display)
   if (display_wayland->have_egl)
     return TRUE;
 
-  dpy = eglGetDisplay ((EGLNativeDisplayType)display_wayland->wl_display);
+  dpy = gdk_wayland_get_display (display_wayland);
+
   if (dpy == NULL)
     return FALSE;
 
diff --git a/gtk/inspector/general.c b/gtk/inspector/general.c
index 77d0a76..f32f7fe 100644
--- a/gtk/inspector/general.c
+++ b/gtk/inspector/general.c
@@ -214,6 +214,36 @@ append_egl_extension_row (GtkInspectorGeneral *gen,
 {
   add_check_row (gen, GTK_LIST_BOX (gen->priv->gl_box), ext, epoxy_has_egl_extension (dpy, ext), 0);
 }
+
+static EGLDisplay
+wayland_get_display (struct wl_display *wl_dpy)
+{
+  EGLDisplay dpy = NULL;
+
+  if (epoxy_has_egl_extension (NULL, "EGL_KHR_platform_base"))
+    {
+      PFNEGLGETPLATFORMDISPLAYPROC getPlatformDisplay =
+        (void *) eglGetProcAddress ("eglGetPlatformDisplay");
+
+      if (getPlatformDisplay)
+        dpy = getPlatformDisplay (EGL_PLATFORM_WAYLAND_EXT, wl_dpy, NULL);
+      if (dpy)
+        return dpy;
+    }
+
+  if (epoxy_has_egl_extension (NULL, "EGL_EXT_platform_base"))
+    {
+      PFNEGLGETPLATFORMDISPLAYEXTPROC getPlatformDisplay =
+        (void *) eglGetProcAddress ("eglGetPlatformDisplayEXT");
+
+      if (getPlatformDisplay)
+        dpy = getPlatformDisplay (EGL_PLATFORM_WAYLAND_EXT, wl_dpy, NULL);
+      if (dpy)
+        return dpy;
+    }
+
+  return eglGetDisplay ((EGLNativeDisplayType) wl_dpy);
+}
 #endif
 
 
@@ -254,7 +284,7 @@ init_gl (GtkInspectorGeneral *gen)
       EGLint major, minor;
       gchar *version;
 
-      dpy = eglGetDisplay ((EGLNativeDisplayType)gdk_wayland_display_get_wl_display (display));
+      dpy = wayland_get_display (gdk_wayland_display_get_wl_display (display));
 
       if (!eglInitialize (dpy, &major, &minor))
         return;
-- 
2.9.3

bgstack15