Commit fce5cce3 authored by chadversary's avatar chadversary

egl: Use eglGetPlatformDisplay when possible (v2)

Tested against Mesa master@8c78fdb with `ninja check-func` on Linux for
x11_egl, wayland, and gbm. However, the new codepaths were not tested
because Mesa does not yet support the needed eglGetPlatformDisplay
extensions.

v2:
  - For x11_egl, pass a `Display*` to eglGetPlatformDisplay, not a
    `Display**`. (for emil)
  - Rebase on other v2 patches.
Reviewed-by: Emil Velikov's avatarEmil Velikov <emil.l.velikov@gmail.com>
parent 53feb936
......@@ -104,10 +104,19 @@ wegl_display_init(struct wegl_display *dpy,
if (!ok)
goto fail;
dpy->egl = plat->eglGetDisplay((EGLNativeDisplayType) native_display);
if (!dpy->egl) {
wegl_emit_error(plat, "eglGetDisplay");
goto fail;
if (wegl_platform_can_use_eglGetPlatformDisplay(plat)) {
dpy->egl = plat->eglGetPlatformDisplay(plat->egl_platform,
native_display, NULL);
if (!dpy->egl) {
wegl_emit_error(plat, "eglGetPlatformDisplay");
goto fail;
}
} else {
dpy->egl = plat->eglGetDisplay((EGLNativeDisplayType) native_display);
if (!dpy->egl) {
wegl_emit_error(plat, "eglGetDisplay");
goto fail;
}
}
ok = plat->eglInitialize(dpy->egl, &dpy->major_version, &dpy->minor_version);
......
......@@ -66,8 +66,10 @@ wegl_platform_teardown(struct wegl_platform *self)
bool ok = true;
int error = 0;
if (self->egl_platform != EGL_PLATFORM_ANDROID_KHR)
if (!wegl_platform_can_use_eglGetPlatformDisplay(self)
&& self->egl_platform != EGL_PLATFORM_ANDROID_KHR) {
unsetenv("EGL_PLATFORM");
}
if (self->eglHandle) {
error = dlclose(self->eglHandle);
......@@ -168,10 +170,40 @@ wegl_platform_init(struct wegl_platform *self, EGLenum egl_platform)
self->client_extensions =
self->eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);
setup_env(self);
if (!wegl_platform_can_use_eglGetPlatformDisplay(self))
setup_env(self);
error:
// On failure the caller of wegl_platform_init will trigger it's own
// destruction which will execute wegl_platform_teardown.
return ok;
}
bool
wegl_platform_can_use_eglGetPlatformDisplay(const struct wegl_platform *plat)
{
const char *ext;
if (!plat->eglGetPlatformDisplay)
return false;
switch (plat->egl_platform) {
case EGL_PLATFORM_ANDROID_KHR:
ext = "EGL_KHR_platform_android";
break;
case EGL_PLATFORM_GBM_KHR:
ext = "EGL_KHR_platform_gbm";
break;
case EGL_PLATFORM_WAYLAND_KHR:
ext = "EGL_KHR_platform_wayland";
break;
case EGL_PLATFORM_X11_KHR:
ext = "EGL_KHR_platform_x11";
break;
default:
assert(!"bad egl_platform enum");
return false;
}
return waffle_is_extension_in_string(plat->client_extensions, ext);
}
......@@ -103,3 +103,11 @@ wegl_platform_teardown(struct wegl_platform *self);
bool
wegl_platform_init(struct wegl_platform *self, EGLenum egl_platform);
// Can eglGetPlatformDisplay can be used for this platform?
//
// True if libEGL exposes the eglGetPlatformDisplay function; and if EGL
// supports the needed platform extension.
bool
wegl_platform_can_use_eglGetPlatformDisplay(const struct wegl_platform *plat);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment