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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
|
commit 5f2329c58c1b
Author: myfreeweb <greg@unrelenting.technology>
Date: Wed Dec 18 20:25:00 2019 +0000
Bug 1556301 - Wayland-EGL/GLES support in glxtest
This allows GfxInfoX11 to get GLES3 and Mesa version from Wayland-EGL, which
allows automatic enablement of acceleration to work without Xwayland.
This also fixes bug 1578598 - WebRender did not work correctly
without this GL version information.
Differential Revision: https://phabricator.services.mozilla.com/D57474
---
toolkit/xre/glxtest.cpp | 132 +++++++++++++++++++++++++++++++++++--
widget/gtk/mozwayland/mozwayland.h | 1 +
2 files changed, 126 insertions(+), 7 deletions(-)
diff --git toolkit/xre/glxtest.cpp toolkit/xre/glxtest.cpp
index 7b33a5c2b08f0..a1e6036cb6002 100644
--- toolkit/xre/glxtest.cpp
+++ toolkit/xre/glxtest.cpp
@@ -36,6 +36,11 @@
#include "mozilla/Unused.h"
+#ifdef MOZ_WAYLAND
+#include "nsAppRunner.h" // for IsWaylandDisabled
+#include "mozilla/widget/mozwayland.h"
+#endif
+
// stuff from glx.h
typedef struct __GLXcontextRec* GLXContext;
typedef XID GLXPixmap;
@@ -74,6 +79,15 @@ typedef uint32_t GLenum;
#define GLX_RENDERER_ID_MESA 0x818E
// clang-format on
+// stuff from egl.h
+#define EGL_BLUE_SIZE 0x3022
+#define EGL_GREEN_SIZE 0x3023
+#define EGL_RED_SIZE 0x3024
+#define EGL_NONE 0x3038
+#define EGL_VENDOR 0x3053
+#define EGL_CONTEXT_CLIENT_VERSION 0x3098
+#define EGL_NO_CONTEXT nullptr
+
namespace mozilla {
namespace widget {
// the read end of the pipe, which will be used by GfxInfo
@@ -118,7 +132,10 @@ static int x_error_handler(Display*, XErrorEvent* ev) {
// care about leaking memory
extern "C" {
-static int get_egl_status(char* buf, int bufsize) {
+typedef void* EGLNativeDisplayType;
+
+static int get_egl_status(char* buf, int bufsize,
+ EGLNativeDisplayType native_dpy, bool gles_test) {
void* libegl = dlopen("libEGL.so.1", RTLD_LAZY);
if (!libegl) {
libegl = dlopen("libEGL.so", RTLD_LAZY);
@@ -164,7 +181,7 @@ static int get_egl_status(char* buf, int bufsize) {
return 0;
}
- EGLDisplay dpy = eglGetDisplay(nullptr);
+ EGLDisplay dpy = eglGetDisplay(native_dpy);
if (!dpy) {
dlclose(libegl);
return 0;
@@ -177,9 +194,87 @@ static int get_egl_status(char* buf, int bufsize) {
}
int length = 0;
+
+ if (gles_test) {
+ typedef void* EGLConfig;
+ typedef void* EGLContext;
+ typedef void* EGLSurface;
+
+ typedef EGLBoolean (*PFNEGLCHOOSECONFIGPROC)(
+ EGLDisplay dpy, EGLint const* attrib_list, EGLConfig* configs,
+ EGLint config_size, EGLint* num_config);
+ PFNEGLCHOOSECONFIGPROC eglChooseConfig =
+ cast<PFNEGLCHOOSECONFIGPROC>(eglGetProcAddress("eglChooseConfig"));
+
+ typedef EGLContext (*PFNEGLCREATECONTEXTPROC)(
+ EGLDisplay dpy, EGLConfig config, EGLContext share_context,
+ EGLint const* attrib_list);
+ PFNEGLCREATECONTEXTPROC eglCreateContext =
+ cast<PFNEGLCREATECONTEXTPROC>(eglGetProcAddress("eglCreateContext"));
+
+ typedef EGLSurface (*PFNEGLCREATEPBUFFERSURFACEPROC)(
+ EGLDisplay dpy, EGLConfig config, EGLint const* attrib_list);
+ PFNEGLCREATEPBUFFERSURFACEPROC eglCreatePbufferSurface =
+ cast<PFNEGLCREATEPBUFFERSURFACEPROC>(
+ eglGetProcAddress("eglCreatePbufferSurface"));
+
+ typedef EGLBoolean (*PFNEGLMAKECURRENTPROC)(
+ EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext context);
+ PFNEGLMAKECURRENTPROC eglMakeCurrent =
+ cast<PFNEGLMAKECURRENTPROC>(eglGetProcAddress("eglMakeCurrent"));
+
+ void* libgles = dlopen("libGLESv2.so.2", RTLD_LAZY);
+ if (!libgles) {
+ libgles = dlopen("libGLESv2.so", RTLD_LAZY);
+ }
+ if (!libgles) {
+ fatal_error("Unable to load libGLESv2");
+ }
+
+ typedef GLubyte* (*PFNGLGETSTRING)(GLenum);
+ PFNGLGETSTRING glGetString =
+ cast<PFNGLGETSTRING>(eglGetProcAddress("glGetString"));
+
+ if (!glGetString) {
+ // Implementations disagree about whether eglGetProcAddress or dlsym
+ // should be used for getting functions from the actual API, see
+ // https://github.com/anholt/libepoxy/commit/14f24485e33816139398d1bd170d617703473738
+ glGetString = cast<PFNGLGETSTRING>(dlsym(libgles, "glGetString"));
+ }
+
+ if (!glGetString) {
+ fatal_error("GLESv2 glGetString not found");
+ }
+
+ EGLint config_attrs[] = {EGL_RED_SIZE, 8, EGL_GREEN_SIZE, 8,
+ EGL_BLUE_SIZE, 8, EGL_NONE};
+ EGLConfig config;
+ EGLint num_config;
+ eglChooseConfig(dpy, config_attrs, &config, 1, &num_config);
+ EGLint ctx_attrs[] = {EGL_CONTEXT_CLIENT_VERSION, 3, EGL_NONE};
+ EGLContext ectx = eglCreateContext(dpy, config, EGL_NO_CONTEXT, ctx_attrs);
+ EGLSurface pbuf = eglCreatePbufferSurface(dpy, config, nullptr);
+ eglMakeCurrent(dpy, pbuf, pbuf, ectx);
+
+ const GLubyte* versionString = glGetString(GL_VERSION);
+ const GLubyte* vendorString = glGetString(GL_VENDOR);
+ const GLubyte* rendererString = glGetString(GL_RENDERER);
+
+ if (!versionString || !vendorString || !rendererString)
+ fatal_error("glGetString returned null");
+
+ length = snprintf(buf, bufsize,
+ "VENDOR\n%s\nRENDERER\n%s\nVERSION\n%s\nTFP\nTRUE\n",
+ vendorString, rendererString, versionString);
+ if (length >= bufsize) {
+ fatal_error("GL strings length too large for buffer size");
+ }
+ }
+
const char* driDriver = eglGetDisplayDriverName(dpy);
if (driDriver) {
- length = snprintf(buf, bufsize, "DRI_DRIVER\n%s\n", driDriver);
+ length +=
+ snprintf(buf + length, bufsize - length, "DRI_DRIVER\n%s\n", driDriver);
}
eglTerminate(dpy);
@@ -187,7 +282,7 @@ static int get_egl_status(char* buf, int bufsize) {
return length;
}
-void glxtest() {
+static void close_logging() {
// we want to redirect to /dev/null stdout, stderr, and while we're at it,
// any PR logging file descriptors. To that effect, we redirect all positive
// file descriptors up to what open() returns here. In particular, 1 is stdout
@@ -199,8 +294,32 @@ void glxtest() {
if (getenv("MOZ_AVOID_OPENGL_ALTOGETHER"))
fatal_error(
"The MOZ_AVOID_OPENGL_ALTOGETHER environment variable is defined");
+}
+
+#ifdef MOZ_WAYLAND
+bool wayland_egltest() {
+ // NOTE: returns false to fall back to X11 when the Wayland socket doesn't
+ // exist but fails with fatal_error if something actually went wrong
+ struct wl_display* dpy = wl_display_connect(nullptr);
+ if (!dpy) return false;
+
+ enum { bufsize = 2048 };
+ char buf[bufsize];
+
+ int length = get_egl_status(buf, bufsize, (EGLNativeDisplayType)dpy, true);
+ if (length >= bufsize) {
+ fatal_error("GL strings length too large for buffer size");
+ }
- ///// Open libGL and load needed symbols /////
+ ///// Finally write data to the pipe
+ mozilla::Unused << write(write_end_of_the_pipe, buf, length);
+
+ return true;
+}
+#endif
+
+void glxtest() {
+ ///// Open libGL and load needed symbols /////
#if defined(__OpenBSD__) || defined(__NetBSD__)
# define LIBGL_FILENAME "libGL.so"
#else
@@ -401,7 +520,7 @@ void glxtest() {
// If we failed to get the driver name from X, try via EGL_MESA_query_driver.
// We are probably using Wayland.
if (!gotDriDriver) {
- length += get_egl_status(buf + length, bufsize - length);
+ length += get_egl_status(buf + length, bufsize - length, nullptr, false);
if (length >= bufsize) {
fatal_error("GL strings length too large for buffer size");
}
@@ -431,7 +550,12 @@ bool fire_glxtest_process() {
if (pid == 0) {
close(pfd[0]);
write_end_of_the_pipe = pfd[1];
- glxtest();
+ close_logging();
+ // TODO: --display command line argument is not properly handled
+#ifdef MOZ_WAYLAND
+ if (IsWaylandDisabled() || !wayland_egltest())
+#endif
+ glxtest();
close(pfd[1]);
_exit(0);
}
diff --git widget/gtk/mozwayland/mozwayland.h widget/gtk/mozwayland/mozwayland.h
index b31742fb2bc33..8aa0ce6f4665a 100644
--- widget/gtk/mozwayland/mozwayland.h
+++ widget/gtk/mozwayland/mozwayland.h
@@ -20,6 +20,7 @@
extern "C" {
#endif
+MOZ_EXPORT struct wl_display* wl_display_connect(const char* name);
MOZ_EXPORT int wl_display_roundtrip_queue(struct wl_display* display,
struct wl_event_queue* queue);
MOZ_EXPORT uint32_t wl_proxy_get_version(struct wl_proxy* proxy);
|