x11: require EGL 1.5 and use eglGetPlatformDisplay()

eglGetPlatform() is a broken API, since it takes a windowing specific
argument, yet is supposed to work for multiple APIs at the same time. On
Linux, it can take both a X11 "Display" and a "wl_display". Obviously
there is no way to specify what kind of display the argument is (it's
just a void*).

Mesa has _eglNativePlatformDetectNativeDisplay, which does funny stuff
to try to guess the display type, including trying to call mincore() to
determine whether the pointer can be accessed at all. I guess this
recently accidentally broke (as a bug), but on the other hand, maybe
it's time to do this properly.

The fix is using eglGetPlaformDisplay(). This requires EGL 1.5, plus
Mesa needs to support the associated platform extension
(EGL_KHR_platform_x11).

Since I see no reasonable way to do this in a compatible way, just
require that EGL 1.5 is available. The problem is that EGL 1.4 seems to
require you to create a display to query EGL version and extension, and
you have a chicken-and-egg problem. It's very stupid. Maybe you could
jump through some more hoops to get something compatible, but fuck that.
Users on "too old" Mesa will fall back to GLX (which we keep around for
a regrettable company known by the name of Nvidia).

I think Wayland and GBM should do the same. They're sufficiently
bleeding-edge that you can expect them to have EGL 1.5. On the other
hand, the cursed RPI code will have to stay with a eglGetDisplay().

Speculative fix for #7154.

(Rant about EGL follows. Actually I deleted it.)
This commit is contained in:
wm4 2019-11-16 20:54:42 +01:00
parent 73c3dc0a7b
commit aacc1942fb
2 changed files with 12 additions and 8 deletions

View File

@ -21,11 +21,6 @@
#include <EGL/egl.h>
#include <EGL/eglext.h>
#ifndef EGL_VERSION_1_5
#define EGL_CONTEXT_OPENGL_PROFILE_MASK 0x30FD
#define EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT 0x00000001
#endif
#include "common/common.h"
#include "video/out/x11_common.h"
#include "context.h"
@ -109,7 +104,8 @@ static bool mpegl_init(struct ra_ctx *ctx)
if (!vo_x11_init(vo))
goto uninit;
p->egl_display = eglGetDisplay(vo->x11->display);
p->egl_display = eglGetPlatformDisplay(EGL_PLATFORM_X11_KHR,
vo->x11->display, NULL);
if (!eglInitialize(p->egl_display, NULL, NULL)) {
MP_MSG(ctx, msgl, "Could not initialize EGL.\n");
goto uninit;

12
wscript
View File

@ -646,12 +646,20 @@ video_output_features = [
'func': check_libs(['GL', 'GL Xdamage'],
check_cc(fragment=load_fragment('gl_x11.c'),
use=['x11', 'libdl', 'pthreads']))
} , {
'name': '--egl15',
'desc': 'EGL 1.5',
'groups': [ 'gl' ],
'func': compose_checks(
check_pkg_config('egl'),
check_statement(['EGL/egl.h'], 'int x[EGL_VERSION_1_5]')
),
} , {
'name': '--egl-x11',
'desc': 'OpenGL X11 EGL Backend',
'deps': 'x11',
'deps': 'x11 && egl15',
'groups': [ 'gl' ],
'func': check_pkg_config('egl'),
'func': check_true,
} , {
'name': '--egl-drm',
'desc': 'OpenGL DRM EGL Backend',