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.

Cc: Emil Velikov <emil.l.veli...@gmail.com>
---
 src/waffle/egl/wegl_display.c  | 17 +++++++++++++----
 src/waffle/egl/wegl_platform.c | 36 ++++++++++++++++++++++++++++++++++--
 src/waffle/egl/wegl_platform.h |  8 ++++++++
 3 files changed, 55 insertions(+), 6 deletions(-)

diff --git a/src/waffle/egl/wegl_display.c b/src/waffle/egl/wegl_display.c
index 7a7986c..5403cd1 100644
--- a/src/waffle/egl/wegl_display.c
+++ b/src/waffle/egl/wegl_display.c
@@ -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);
diff --git a/src/waffle/egl/wegl_platform.c b/src/waffle/egl/wegl_platform.c
index f52bdfa..5887cf5 100644
--- a/src/waffle/egl/wegl_platform.c
+++ b/src/waffle/egl/wegl_platform.c
@@ -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);
+}
diff --git a/src/waffle/egl/wegl_platform.h b/src/waffle/egl/wegl_platform.h
index 4573ec2..d6788eb 100644
--- a/src/waffle/egl/wegl_platform.h
+++ b/src/waffle/egl/wegl_platform.h
@@ -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);
-- 
2.10.1

_______________________________________________
waffle mailing list
waffle@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/waffle

Reply via email to