[Piglit] [PATCH 08/13] util/egl: Add piglit_egl_get_default_display()

Chad Versace chad.versace at linux.intel.com
Wed Mar 26 10:40:24 PDT 2014


This function gets the default display for the given platform.

If the given platform platform is EGL_NONE, the the function wraps
eglGetDisplay().  Otherwise, it wraps eglGetPlatformDisplayEXT().  If
EGL does not support the platform extension for the given platform, then
it returns EGL_NO_DISPLAY.

This is useful for EGL tests that need to create a display for
a specific platform.

Signed-off-by: Chad Versace <chad.versace at linux.intel.com>
---
 tests/util/piglit-util-egl.c | 55 ++++++++++++++++++++++++++++++++++++++++++++
 tests/util/piglit-util-egl.h | 14 +++++++++++
 2 files changed, 69 insertions(+)

diff --git a/tests/util/piglit-util-egl.c b/tests/util/piglit-util-egl.c
index 5ce09d9..8d48f30 100644
--- a/tests/util/piglit-util-egl.c
+++ b/tests/util/piglit-util-egl.c
@@ -76,6 +76,61 @@ piglit_check_egl_error(EGLint expected_error)
 	return false;
 }
 
+EGLDisplay
+piglit_egl_get_default_display(EGLenum platform)
+{
+	static bool once = true;
+
+	static bool has_base = false;
+	static bool has_x11 = false;
+	static bool has_wayland = false;
+	static bool has_gbm = false;
+
+	static EGLDisplay (*peglGetPlatformDisplayEXT)(EGLenum platform, void *native_display, const EGLint *attrib_list);
+
+	if (platform == EGL_NONE) {
+		return eglGetDisplay(EGL_DEFAULT_DISPLAY);
+	}
+
+	if (once) {
+		once = false;
+
+		has_base = piglit_is_egl_extension_supported(EGL_NO_DISPLAY, "EGL_EXT_platform_base");
+		has_x11 = piglit_is_egl_extension_supported(EGL_NO_DISPLAY, "EGL_EXT_platform_x11");
+		has_wayland = piglit_is_egl_extension_supported(EGL_NO_DISPLAY, "EGL_EXT_platform_wayland");
+		has_gbm = piglit_is_egl_extension_supported(EGL_NO_DISPLAY, "EGL_EXT_platform_gbm");
+
+		peglGetPlatformDisplayEXT = (void*) eglGetProcAddress("eglGetPlaformDisplayEXT");
+	}
+
+	if (!has_base) {
+		return EGL_NO_DISPLAY;
+	}
+
+	switch (platform) {
+	case EGL_PLATFORM_X11_EXT:
+		if (!has_x11) {
+			return EGL_NO_DISPLAY;
+		}
+		break;
+	case EGL_PLATFORM_WAYLAND_EXT:
+		if (!has_wayland) {
+			return EGL_NO_DISPLAY;
+		}
+		break;
+	case EGL_PLATFORM_GBM_MESA:
+		if (!has_gbm) {
+			return EGL_NO_DISPLAY;
+		}
+		break;
+	default:
+		fprintf(stderr, "%s: unrecognized platform %#x\n", __func__, platform);
+		return EGL_NO_DISPLAY;
+	}
+
+	return peglGetPlatformDisplayEXT(platform, EGL_DEFAULT_DISPLAY, NULL);
+}
+
 bool
 piglit_is_egl_extension_supported(EGLDisplay egl_dpy, const char *name)
 {
diff --git a/tests/util/piglit-util-egl.h b/tests/util/piglit-util-egl.h
index d8fa0d2..4a6eecf 100644
--- a/tests/util/piglit-util-egl.h
+++ b/tests/util/piglit-util-egl.h
@@ -55,6 +55,20 @@ bool
 piglit_check_egl_error(EGLint expected_error);
 
 /**
+ * \brief Get default display for given platform.
+ *
+ * If \a platform is EGL_NONE, the this function wraps eglGetDisplay().
+ * Otherwise, it wraps eglGetPlatformDisplayEXT().
+ *
+ * On failure, return EGL_NO_DISPLAY.
+ *
+ * If EGL does not support the platform extension for the given \a platform,
+ * then return EGL_NO_DISPLAY.
+ */
+EGLDisplay
+piglit_egl_get_default_display(EGLenum platform);
+
+/**
  * \brief Checks whether an EGL extension is supported.
  */
 bool piglit_is_egl_extension_supported(EGLDisplay egl_dpy, const char *name);
-- 
1.8.5.3



More information about the Piglit mailing list