[Piglit] [PATCH 5/5] EGL_EXT_platform_base: Add tests for Linux platform extensions

Chad Versace chad.versace at linux.intel.com
Sun Feb 9 13:31:16 PST 2014


Add tests for Linux platform extensions layered atop
EGL_EXT_platform_base:

    EGL_EXT_platform_x11
    EGL_EXT_platform_wayland
    EGL_MESA_platform_gbm

Signed-off-by: Chad Versace <chad.versace at linux.intel.com>
---
 tests/all.py                                       |   9 +
 tests/egl/spec/CMakeLists.txt                      |   1 +
 .../egl_ext_platform_base/CMakeLists.no_api.txt    |  20 ++
 .../egl/spec/egl_ext_platform_base/CMakeLists.txt  |   1 +
 tests/egl/spec/egl_ext_platform_base/common.h      |  91 ++++++
 .../egl_ext_platform_base/egl_ext_platform_base.c  | 240 +++++++++++++++
 tests/egl/spec/egl_ext_platform_base/gbm.c         | 270 +++++++++++++++++
 tests/egl/spec/egl_ext_platform_base/wayland.c     | 327 +++++++++++++++++++++
 tests/egl/spec/egl_ext_platform_base/x11.c         | 257 ++++++++++++++++
 9 files changed, 1216 insertions(+)
 create mode 100644 tests/egl/spec/egl_ext_platform_base/CMakeLists.no_api.txt
 create mode 100644 tests/egl/spec/egl_ext_platform_base/CMakeLists.txt
 create mode 100644 tests/egl/spec/egl_ext_platform_base/common.h
 create mode 100644 tests/egl/spec/egl_ext_platform_base/egl_ext_platform_base.c
 create mode 100644 tests/egl/spec/egl_ext_platform_base/gbm.c
 create mode 100644 tests/egl/spec/egl_ext_platform_base/wayland.c
 create mode 100644 tests/egl/spec/egl_ext_platform_base/x11.c

diff --git a/tests/all.py b/tests/all.py
index 68186d1..dc855f9 100644
--- a/tests/all.py
+++ b/tests/all.py
@@ -3733,6 +3733,15 @@ spec['EGL_EXT_client_extensions'] = egl_ext_client_extensions
 for i in [1, 2, 3]:
     egl_ext_client_extensions['conformance test {0}'.format(i)] = concurrent_test('egl_ext_client_extensions {0}'.format(i))
 
+egl_ext_platform_base = Group()
+spec['EGL_EXT_platform_base'] = egl_ext_platform_base
+for platform_list in [
+        'wayland', 'gbm', 'x11',
+        'wayland,gbm', 'wayland,x11', 'wayland,x11', 'gbm,x11',
+        'wayland,gbm,x11',
+        ]:
+    egl_ext_platform_base[platform_list] = concurrent_test('egl_ext_platform_base {0}'.format(platform_list))
+
 gles20 = Group()
 spec['!OpenGL ES 2.0'] = gles20
 gles20['glsl-fs-pointcoord'] = concurrent_test('glsl-fs-pointcoord_gles2')
diff --git a/tests/egl/spec/CMakeLists.txt b/tests/egl/spec/CMakeLists.txt
index 30e9900..425453d 100644
--- a/tests/egl/spec/CMakeLists.txt
+++ b/tests/egl/spec/CMakeLists.txt
@@ -1,3 +1,4 @@
 add_subdirectory (egl-1.4)
 add_subdirectory (egl_ext_client_extensions)
+add_subdirectory (egl_ext_platform_base)
 add_subdirectory (egl_khr_create_context)
diff --git a/tests/egl/spec/egl_ext_platform_base/CMakeLists.no_api.txt b/tests/egl/spec/egl_ext_platform_base/CMakeLists.no_api.txt
new file mode 100644
index 0000000..cc67511
--- /dev/null
+++ b/tests/egl/spec/egl_ext_platform_base/CMakeLists.no_api.txt
@@ -0,0 +1,20 @@
+link_libraries(piglitutil)
+
+if(PIGLIT_HAS_X11)
+	link_libraries(${X11_X11_LIB})
+endif()
+
+if(PIGLIT_HAS_WAYLAND)
+	link_libraries(${WAYLAND_LIBRARIES})
+endif()
+
+if(PIGLIT_HAS_GBM AND PIGLIT_HAS_UDEV)
+	link_libraries(${GBM_LIBRARIES} ${UDEV_LIBRARIES})
+endif()
+
+piglit_add_executable(egl_ext_platform_base
+	egl_ext_platform_base.c
+	x11.c wayland.c gbm.c
+)
+
+# vim: ft=cmake:
diff --git a/tests/egl/spec/egl_ext_platform_base/CMakeLists.txt b/tests/egl/spec/egl_ext_platform_base/CMakeLists.txt
new file mode 100644
index 0000000..144a306
--- /dev/null
+++ b/tests/egl/spec/egl_ext_platform_base/CMakeLists.txt
@@ -0,0 +1 @@
+piglit_include_target_api()
diff --git a/tests/egl/spec/egl_ext_platform_base/common.h b/tests/egl/spec/egl_ext_platform_base/common.h
new file mode 100644
index 0000000..2cf82fa
--- /dev/null
+++ b/tests/egl/spec/egl_ext_platform_base/common.h
@@ -0,0 +1,91 @@
+/* 
+ * Copyright 2014 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#pragma once
+
+#define EGL_EXT_platform_base 1 /* Inhibit definition of prototypes. */
+
+#include "piglit-util.h"
+#include "piglit-util-egl.h"
+
+#define EGL_PLATFORM_X11_EXT              0x31D5
+#define EGL_PLATFORM_X11_SCREEN_EXT       0x31D6
+#define EGL_PLATFORM_WAYLAND_EXT          0x31D8
+#define EGL_PLATFORM_GBM_MESA             0x31D7
+
+extern EGLDisplay (*eglGetPlatformDisplayEXT)(EGLenum platform, void *native_display, const EGLint *attrib_list);
+extern EGLSurface (*eglCreatePlatformWindowSurfaceEXT)(EGLDisplay dpy, EGLConfig config, void *native_window, const EGLint *attrib_list);
+extern EGLSurface (*eglCreatePlatformPixmapSurfaceEXT)(EGLDisplay dpy, EGLConfig config, void *native_pixmap, const EGLint *attrib_list);
+
+static const int window_width = 64;
+static const int window_height = 64;
+
+struct pgl_egl_resources {
+	EGLDisplay dpy;
+	EGLConfig config;
+	EGLSurface window;
+	EGLSurface pixmap;
+	void *platform_private;
+};
+
+static const EGLint pgl_egl_config_attrs[] = {
+	EGL_BUFFER_SIZE,        32,
+	EGL_RED_SIZE,            8,
+	EGL_GREEN_SIZE,          8,
+	EGL_BLUE_SIZE,           8,
+	EGL_ALPHA_SIZE,          8,
+
+	EGL_DEPTH_SIZE,         EGL_DONT_CARE,
+	EGL_STENCIL_SIZE,       EGL_DONT_CARE,
+
+	EGL_RENDERABLE_TYPE,    EGL_OPENGL_ES2_BIT,
+	EGL_SURFACE_TYPE,       EGL_WINDOW_BIT,
+	EGL_NONE,
+};
+
+void
+error(const char *fmt, ...);
+
+void
+pgl_x11_setup(enum piglit_result *out_result,
+	      struct pgl_egl_resources **out_egl);
+
+void
+pgl_x11_teardown(struct pgl_egl_resources *egl,
+		 enum piglit_result *out_result);
+
+void
+pgl_wl_setup(enum piglit_result *out_result,
+	     struct pgl_egl_resources **out_egl);
+
+void
+pgl_wl_teardown(struct pgl_egl_resources *egl,
+		enum piglit_result *out_result);
+
+void
+pgl_gbm_setup(enum piglit_result *out_result,
+	      struct pgl_egl_resources **out_egl);
+
+void
+pgl_gbm_teardown(struct pgl_egl_resources *egl,
+		 enum piglit_result *out_result);
diff --git a/tests/egl/spec/egl_ext_platform_base/egl_ext_platform_base.c b/tests/egl/spec/egl_ext_platform_base/egl_ext_platform_base.c
new file mode 100644
index 0000000..a2abfae
--- /dev/null
+++ b/tests/egl/spec/egl_ext_platform_base/egl_ext_platform_base.c
@@ -0,0 +1,240 @@
+/* 
+ * Copyright 2014 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+/**
+ * \file
+ * \brief Tests for EGL_EXT_platform_base and layered extensions.
+ *
+ * For each platform requested on the command line, the test will call the
+ * functions added by EGL_EXT_platform_base, validating the functions'
+ * behavior, then destroy all EGL resources for that platform. If for any
+ * platform the test fails to connect to a display, then the test skips.
+ *
+ * To catch errors in EGL's internal dispatch tables, the test creates all EGL
+ * resources for all requested platforms before proceeding to destroy the EGL
+ * resources.
+ */
+
+#include "common.h"
+
+#include <stdio.h>
+#include <unistd.h>
+
+#include "piglit-util.h"
+#include "piglit-util-egl.h"
+
+EGLDisplay (*eglGetPlatformDisplayEXT)(EGLenum platform, void *native_display, const EGLint *attrib_list);
+EGLSurface (*eglCreatePlatformWindowSurfaceEXT)(EGLDisplay dpy, EGLConfig config, void *native_window, const EGLint *attrib_list);
+EGLSurface (*eglCreatePlatformPixmapSurfaceEXT)(EGLDisplay dpy, EGLConfig config, void *native_pixmap, const EGLint *attrib_list);
+
+static const char *prog_name;
+
+void
+error(const char *fmt, ...)
+{
+    va_list ap;
+
+    va_start(ap, fmt);
+    printf("%s: error: ", prog_name);
+    vprintf(fmt, ap);
+    printf("\n");
+    va_end(ap);
+}
+
+static void
+print_usage(void)
+{
+	static const char *usage =
+		"usage: %1$s PLATFORM[,PLATFORM[,PLATFORM[...]]]\n"
+		"\n"
+		"PLATFORM must be one of 'x11', 'wayland', or 'gbm'.\n"
+		"\n"
+		"At least one platform must be given. The same platform may\n"
+		"be given multiple times.\n"
+		"\n"
+		"Examples:\n"
+		"    %1$s x11\n"
+		"    %1$s wayland\n"
+		"    %1$s gbm,x11,wayland\n"
+		"    %1$s x11,wayland,x11,gbm\n"
+		;
+	printf(usage, prog_name);
+}
+
+static void
+usage_error(void)
+{
+	printf("usage_error: %s\n", prog_name);
+	printf("\n");
+	print_usage();
+	piglit_report_result(PIGLIT_FAIL);
+}
+
+static bool
+streq(const char *a, const char *b)
+{
+	return strcmp(a, b) == 0;
+}
+
+static void
+parse_args(int argc, char **argv,
+	   const char ***out_platform_list)
+{
+	int i = 0;
+	const char **platform_list = NULL;
+
+	/* Discard common Piglit arguments. */
+	piglit_strip_arg(&argc, argv, "-auto");
+	piglit_strip_arg(&argc, argv, "-fbo");
+
+	/* Discard argv[0]. */
+	--argc;
+	++argv;
+
+	if (argc < 1) {
+		usage_error();
+	}
+
+	platform_list = piglit_split_string_to_array(argv[0], ",");
+	--argc;
+	++argv;
+
+	if (platform_list == NULL || platform_list[0] == NULL) {
+		usage_error();
+	}
+
+	/* Validate platform list. */
+	for (i = 0; platform_list[i] != NULL; ++i) {
+		if (!streq(platform_list[i], "x11") &&
+		    !streq(platform_list[i], "wayland") &&
+		    !streq(platform_list[i], "gbm")) {
+			usage_error();
+		}
+	}
+
+	*out_platform_list = platform_list;
+}
+
+static void
+init_egl_funcs(void)
+{
+	eglGetPlatformDisplayEXT = (void*) eglGetProcAddress("eglGetPlatformDisplayEXT");
+	eglCreatePlatformWindowSurfaceEXT = (void*) eglGetProcAddress("eglCreatePlatformWindowSurfaceEXT");
+	eglCreatePlatformPixmapSurfaceEXT = (void*) eglGetProcAddress("eglCreatePlatformPixmapSurfaceEXT");
+
+	if (!eglGetPlatformDisplayEXT ||
+	    !eglCreatePlatformWindowSurfaceEXT ||
+	    !eglCreatePlatformPixmapSurfaceEXT) {
+		printf("%s: error: failed to get all EGL_EXT_platform_base proc "
+		       "addresess\n", prog_name);
+		piglit_report_result(PIGLIT_FAIL);
+	}
+}
+
+static enum piglit_result
+test_platforms(const char **platforms)
+{
+	struct pgl_egl_resources **egl_resources = NULL;
+	int num_platforms = 0;
+	int i = 0;
+
+	/* Count number of platforms. */
+	for (i = 0; platforms[i] != NULL; ++i) {
+		++num_platforms;
+	}
+
+	egl_resources = calloc(num_platforms, sizeof(*egl_resources));
+	if (!egl_resources) {
+		printf("%s: error: out of memory\n", prog_name);
+		piglit_report_result(PIGLIT_FAIL);
+	}
+
+	/* Setup each platform. */
+	for (i = 0; i < num_platforms; ++i) {
+		enum piglit_result result = PIGLIT_SKIP;
+
+		if (streq(platforms[i], "x11")) {
+			pgl_x11_setup(&result, &egl_resources[i]);
+		} else if (streq(platforms[i], "wayland")) {
+			pgl_wl_setup(&result, &egl_resources[i]);
+		} else if (streq(platforms[i], "gbm")) {
+			pgl_gbm_setup(&result, &egl_resources[i]);
+		} else {
+			printf("%s: internal error: unexpected platform '%s'\n",
+			       prog_name, platforms[i]);
+			result = PIGLIT_FAIL;
+		}
+
+		if (result != PIGLIT_PASS) {
+			return result;
+		}
+	}
+
+	/* We intentionally setup all platforms before tearing any down. This
+	 * catches possible errors EGL's internal dispatch table.
+	 */
+
+	/* Teardown each platform. */
+	for (i = 0; i < num_platforms; ++i) {
+		enum piglit_result result = PIGLIT_SKIP;
+
+		if (egl_resources[i] == NULL) {
+			continue;
+		} else if (streq(platforms[i], "x11")) {
+			pgl_x11_teardown(egl_resources[i], &result);
+		} else if (streq(platforms[i], "wayland")) {
+			pgl_wl_teardown(egl_resources[i], &result);
+		} else if (streq(platforms[i], "gbm")) {
+			pgl_gbm_teardown(egl_resources[i], &result);
+		} else {
+			printf("%s: internal error: unexpected platform '%s'\n",
+			       prog_name, platforms[i]);
+			result = PIGLIT_FAIL;
+		}
+
+		if (result != PIGLIT_PASS) {
+			return result;
+		}
+	}
+
+	free(egl_resources);
+	return PIGLIT_PASS;
+}
+
+int
+main(int argc, char **argv)
+{
+	enum piglit_result result = PIGLIT_SKIP;
+	const char **platform_list = NULL;
+
+	prog_name = basename(argv[0]);
+
+	parse_args(argc, argv, &platform_list);
+	piglit_require_egl_extension(EGL_NO_DISPLAY, "EGL_EXT_platform_base");
+	init_egl_funcs();
+	result = test_platforms(platform_list);
+	piglit_report_result(result);
+
+	assert(!"unreachable");
+        return EXIT_FAILURE;
+}
diff --git a/tests/egl/spec/egl_ext_platform_base/gbm.c b/tests/egl/spec/egl_ext_platform_base/gbm.c
new file mode 100644
index 0000000..b403371
--- /dev/null
+++ b/tests/egl/spec/egl_ext_platform_base/gbm.c
@@ -0,0 +1,270 @@
+/* 
+ * Copyright 2014 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#include "common.h"
+
+#if !defined(PIGLIT_HAS_GBM) || !defined(PIGLIT_HAS_UDEV)
+
+void
+pgl_gbm_setup(enum piglit_result *out_result,
+	      struct pgl_egl_resources **out_egl)
+{
+	*out_result = PIGLIT_SKIP;
+	*out_egl = NULL;
+}
+
+void
+pgl_gbm_teardown(struct pgl_egl_resources *egl,
+		 enum piglit_result *out_result)
+{
+	*out_result = PIGLIT_SKIP;
+}
+
+#else /* !defined(PIGLIT_HAS_GBM) || !defined(PIGLIT_HAS_UDEV) */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <libudev.h>
+#include <gbm.h>
+
+struct pgl_gbm_resources {
+	struct gbm_device *dev;
+	enum gbm_bo_format format;
+	struct gbm_surface *surface;
+};
+
+static int
+get_default_fd_for_pattern(const char *pattern)
+{
+    struct udev *ud;
+    struct udev_enumerate *en;
+    struct udev_list_entry *entry;
+    const char *path, *filename;
+    struct udev_device *device;
+    int fd;
+
+    ud = udev_new();
+    en = udev_enumerate_new(ud);
+    udev_enumerate_add_match_subsystem(en, "drm");
+    udev_enumerate_add_match_sysname(en, pattern);
+    udev_enumerate_scan_devices(en);
+
+    udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(en)) {
+        path = udev_list_entry_get_name(entry);
+        device = udev_device_new_from_syspath(ud, path);
+        filename = udev_device_get_devnode(device);
+        fd = open(filename, O_RDWR | O_CLOEXEC);
+        udev_device_unref(device);
+        if (fd >= 0) {
+            return fd;
+        }
+    }
+
+    return -1;
+}
+
+static int
+get_fd(void)
+{
+	int fd = -1;
+
+	/* Prefer rendernodes to dri card. */
+	fd = get_default_fd_for_pattern("renderD[0-9]*");
+	if (fd >= 0) {
+		return fd;
+	}
+
+	fd = get_default_fd_for_pattern("card[0-9]*");
+	return fd;
+}
+
+void
+pgl_gbm_setup(enum piglit_result *out_result,
+	      struct pgl_egl_resources **out_egl)
+{
+	struct pgl_egl_resources *egl = NULL;
+	struct pgl_gbm_resources *gbm = NULL;
+
+	EGLDisplay egl_dpy_again = NULL;
+
+	int fd = -1;
+	bool ok = true;
+
+	EGLint egl_major = 0, egl_minor = 0, num_configs = 0;
+
+	/* Initialize outputs */
+	*out_egl = NULL;
+	*out_result = PIGLIT_FAIL;
+
+	egl = calloc(1, sizeof(*egl));
+	if (!egl) {
+		error("out of memory");
+		goto fail;
+	}
+
+	gbm = calloc(1, sizeof(*gbm));
+	if (!gbm) {
+		error("out of memory");
+		goto fail;
+	}
+
+	egl->platform_private = gbm;
+
+	fd = get_fd();
+	if (fd < 0) {
+		error("failed to open gbm fd");
+		goto skip;
+	}
+
+	gbm->dev = gbm_create_device(fd);
+	if (!gbm->dev) {
+		error("gbm_create_device failed");
+		goto skip;
+	}
+
+	egl->dpy = eglGetPlatformDisplayEXT(EGL_PLATFORM_GBM_MESA,
+					    gbm->dev, NULL);
+	if (!egl->dpy) {
+		error("eglGetPlatformDisplay failed for GBM");
+		goto fail;
+	}
+
+	/* From the EGL_EXT_platform_base spec, version 9:
+	 *
+	 *   Multiple calls made to eglGetPlatformDisplayEXT with the same
+	 *   <platform> and <native_display> will return the same EGLDisplay
+	 *   handle.
+	 */
+	egl_dpy_again = eglGetPlatformDisplayEXT(EGL_PLATFORM_GBM_MESA,
+					         gbm->dev, NULL);
+	if (egl->dpy != egl_dpy_again) {
+		error("eglGetPlatformDisplayEXT returned different EGLDisplay "
+		      "handles for same gbm_device");
+		goto fail;
+	}
+	
+	ok = eglInitialize(egl->dpy, &egl_major, &egl_minor);
+	if (!ok) {
+		error("eglInitialize failed for GBM");
+		goto fail;
+	}
+
+	ok = eglChooseConfig(egl->dpy, pgl_egl_config_attrs,
+			     &egl->config, 1, &num_configs);
+	if (!ok || num_configs == 0 || !egl->config) {
+		error("eglChooseConfig failed for GBM");
+		goto fail;
+	}
+
+	ok = eglGetConfigAttrib(egl->dpy, egl->config, EGL_NATIVE_VISUAL_ID,
+			        (EGLint*) &gbm->format);
+	if (!ok) {
+		error("eglGetConfigAttrib failed for X11");
+		goto fail;
+	}
+
+	gbm->surface = gbm_surface_create(gbm->dev, window_width, window_height,
+				          gbm->format, GBM_BO_USE_RENDERING);
+	if (!gbm->surface) {
+		error("gbm_surface_create failed");
+		goto fail;
+	}
+
+	egl->window = eglCreatePlatformWindowSurfaceEXT(egl->dpy, egl->config,
+						        gbm->surface, NULL);
+	if (!egl->window) {
+		error("eglCreatePlatformWindowSurface failed for GBM");
+		goto fail;
+	}
+
+	ok = eglCreatePlatformPixmapSurfaceEXT(egl->dpy, egl->config, NULL, NULL);
+	if (ok) {
+		error("eglCreatePlatformPixmapSurfaceEXT succeeded for"
+		      "GBM, but should have failed");
+		goto fail;
+	}
+	if (!piglit_check_egl_error(EGL_BAD_PARAMETER)) {
+		error("eglCreatePlatformPixmapSurfaceEXT should emit "
+		      "EGL_BAD_PARAMETER on GBM");
+		goto fail;
+	}
+
+	*out_result = PIGLIT_PASS;
+	*out_egl = egl;
+	return;
+
+skip:
+	pgl_gbm_teardown(egl, out_result);
+	*out_result = PIGLIT_SKIP;
+	return;
+
+fail:
+	pgl_gbm_teardown(egl, out_result);
+	*out_result = PIGLIT_FAIL;
+	return;
+}
+
+
+void
+pgl_gbm_teardown(struct pgl_egl_resources *egl,
+		 enum piglit_result *out_result)
+{
+	struct pgl_gbm_resources *gbm = NULL;
+	bool ok = true;
+
+	*out_result = PIGLIT_PASS;
+
+	if (egl) {
+		gbm = egl->platform_private;
+	}
+
+	if (egl && egl->window) {
+		ok = eglDestroySurface(egl->dpy, egl->window);
+		if (!ok) {
+			error("eglDestroySurface failed for GBM window");
+			*out_result = PIGLIT_FAIL;
+		}
+	}
+
+	if (gbm && gbm->surface) {
+		gbm_surface_destroy(gbm->surface);
+	}
+
+	if (egl && egl->dpy) {
+		ok = eglTerminate(egl->dpy);
+		if (!ok) {
+			error("eglTerminate failed for GBM");
+			*out_result = PIGLIT_FAIL;
+		}
+	}
+
+	if (gbm && gbm->dev) {
+		gbm_device_destroy(gbm->dev);
+	}
+
+	free(gbm);
+	free(egl);
+}
+	
+#endif /* !defined(PIGLIT_HAS_GBM) || !defined(PIGLIT_HAS_UDEV) */
diff --git a/tests/egl/spec/egl_ext_platform_base/wayland.c b/tests/egl/spec/egl_ext_platform_base/wayland.c
new file mode 100644
index 0000000..3999d73
--- /dev/null
+++ b/tests/egl/spec/egl_ext_platform_base/wayland.c
@@ -0,0 +1,327 @@
+/* 
+ * Copyright 2014 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#include "common.h"
+
+#ifndef PIGLIT_HAS_WAYLAND
+
+void
+pgl_wl_setup(enum piglit_result *out_result,
+	     struct pgl_egl_resources **out_egl)
+{
+	*out_result = PIGLIT_SKIP;
+	*out_egl = NULL;
+}
+
+void
+pgl_wl_teardown(struct pgl_egl_resources *egl,
+	        enum piglit_result *out_result)
+{
+	*out_result = PIGLIT_SKIP;
+}
+
+#else /* PIGLIT_HAS_WAYLAND */
+
+#include <wayland-client.h>
+#include <wayland-egl.h>
+
+struct pgl_wl_resources {
+	struct wl_display *dpy;
+	struct wl_registry *registry;
+	struct wl_compositor *compositor;
+	struct wl_shell *shell;
+	struct wl_surface *surface;
+	struct wl_shell_surface *shell_surface;
+	struct wl_egl_window *window;
+};
+
+static void
+registry_global_add(void *user_data, struct wl_registry *registry,
+		    uint32_t name, const char *interface, uint32_t version)
+{
+	struct pgl_wl_resources *wl = user_data;
+
+	if (!strncmp(interface, "wl_compositor", 14)) {
+		wl->compositor = wl_registry_bind(registry, name,
+					          &wl_compositor_interface, 1);
+	} else if (!strncmp(interface, "wl_shell", 9)) {
+		wl->shell = wl_registry_bind(registry, name,
+					    &wl_shell_interface, 1);
+	}
+}
+
+static void
+registry_global_remove(void *user_data, struct wl_registry *registry,
+		       uint32_t name)
+{
+	return;
+}
+
+static const struct wl_registry_listener registry_listener = {
+	registry_global_add,
+	registry_global_remove,
+};
+
+static void
+shell_surface_ping(void *user_data,
+		   struct wl_shell_surface *shell_surface,
+		   uint32_t serial)
+{
+    wl_shell_surface_pong(shell_surface, serial);
+}
+
+static void
+shell_surface_configure(void *user_data,
+		        struct wl_shell_surface *shell_surface,
+		        uint32_t edges, int32_t width, int32_t height)
+{
+	return;
+}
+
+static void
+shell_surface_popup_done(void *user_data,
+			 struct wl_shell_surface *shell_surface)
+{
+	return;
+}
+
+static const struct wl_shell_surface_listener shell_surface_listener = {
+	shell_surface_ping,
+	shell_surface_configure,
+	shell_surface_popup_done,
+};
+
+void
+pgl_wl_setup(enum piglit_result *out_result,
+	     struct pgl_egl_resources **out_egl)
+{
+	struct pgl_egl_resources *egl = NULL;
+	struct pgl_wl_resources *wl = NULL;
+
+	EGLDisplay egl_dpy_again = NULL;
+	EGLint egl_major = 0, egl_minor = 0, num_configs = 0;
+
+	int err = 0;
+	bool ok = true;
+
+	/* Initialize outputs. */
+	*out_egl = NULL;
+	*out_result = PIGLIT_FAIL;
+
+	egl = calloc(1, sizeof(*egl));
+	if (!egl) {
+		error("out of memory");
+		goto fail;
+	}
+
+	wl = calloc(1, sizeof(*wl));
+	if (!wl) {
+		error("out of memory");
+		goto fail;
+	}
+
+	egl->platform_private = wl;
+	
+	wl->dpy = wl_display_connect(NULL);
+	if (!wl->dpy) {
+		error("wl_display_connect failed");
+		goto skip;
+	}
+
+	wl->registry = wl_display_get_registry(wl->dpy);
+	if (!wl->registry) {
+		error("wl_display_get_registry failed");
+		goto fail;
+	}
+
+	err = wl_registry_add_listener(wl->registry,
+					 &registry_listener, wl);
+	if (err < 0) {
+		error("wl_registry_add_listener failed");
+		goto fail;
+	}
+
+	/* Block until the Wayland server has processed all pending requests and
+	 * has sent out pending events on all event queues. This should ensure
+	 * that the registry listener has received announcement of the shell and
+	 * compositor.
+	 */
+	err = wl_display_roundtrip(wl->dpy);
+	if (err < 0) {
+		error("wl_display_roundtrip failed");
+		goto fail;
+	}
+
+	if (!wl->compositor) {
+		error("failed to bind to the wayland compositor\n");
+		goto fail;
+	}
+
+	if (!wl->shell) {
+		error("failed to bind to the wayland shell\n");
+		goto fail;
+	}
+
+	egl->dpy = eglGetPlatformDisplayEXT(EGL_PLATFORM_WAYLAND_EXT,
+					    wl->dpy, NULL);
+	if (!egl->dpy) {
+		error("eglGetPlatformDisplayEXT failed for Wayland");
+		goto fail;
+	}
+
+	/* From the EGL_EXT_platform_base spec, version 9:
+	 *
+	 *   Multiple calls made to eglGetPlatformDisplayEXT with the same
+	 *   <platform> and <native_display> will return the same EGLDisplay
+	 *   handle.
+	 */
+	egl_dpy_again = eglGetPlatformDisplayEXT(EGL_PLATFORM_WAYLAND_EXT,
+					         wl->dpy, NULL);
+	if (egl->dpy != egl_dpy_again) {
+		error("eglGetPlatformDisplayEXT returned different EGLDisplay "
+		      "handles for same wl_display");
+		goto fail;
+	}
+
+	ok = eglInitialize(egl->dpy, &egl_major, &egl_minor);
+	if (!ok) {
+		error("eglInitialize failed for Wayland");
+		goto fail;
+	}
+
+	ok = eglChooseConfig(egl->dpy, pgl_egl_config_attrs,
+			     &egl->config, 1, &num_configs);
+	if (!ok || num_configs == 0 || !egl->config) {
+		error("eglChooseConfig failed for Wayland");
+		goto fail;
+	}
+
+	wl->surface = wl_compositor_create_surface(wl->compositor);
+	if (!wl->surface) {
+		error("wl_compositor_create_surface failed");
+		goto fail;
+	}
+
+	wl->shell_surface = wl_shell_get_shell_surface(wl->shell,
+							   wl->surface);
+	if (!wl->shell_surface) {
+		error("wl_shell_get_shell_surface failed");
+		goto fail;
+	}
+
+	err = wl_shell_surface_add_listener(wl->shell_surface,
+					      &shell_surface_listener, NULL);
+	if (err < 0) {
+		error("wl_shell_surface_add_listener failed");
+		goto fail;
+	}
+
+	wl->window = wl_egl_window_create(wl->surface, window_width, window_height);
+	if (!wl->window) {
+		error("wl_egl_window_create failed");
+		goto fail;
+	}
+
+	egl->window = eglCreatePlatformWindowSurfaceEXT(egl->dpy, egl->config,
+						        wl->window, NULL);
+	if (!egl->window) {
+		error("eglCreatePlatformWindowSurfaceEXT failed for Wayland");
+		goto fail;
+	}
+
+	ok = eglCreatePlatformPixmapSurfaceEXT(egl->dpy, egl->config, NULL, NULL);
+	if (ok) {
+		error("eglCreatePlatformPixmapSurfaceEXT succeeded for"
+		      "Wayland, but should have failed");
+		goto fail;
+	}
+	if (!piglit_check_egl_error(EGL_BAD_PARAMETER)) {
+		error("eglCreatePlatformPixmapSurfaceEXT should emit "
+		      "EGL_BAD_PARAMETER on Wayland");
+		goto fail;
+	}
+
+	*out_result = PIGLIT_PASS;
+	*out_egl = egl;
+	return;
+
+skip:
+	pgl_wl_teardown(egl, out_result);
+	*out_result = PIGLIT_SKIP;
+	return;
+
+fail:
+	pgl_wl_teardown(egl, out_result);
+	*out_result = PIGLIT_FAIL;
+	return;
+}
+
+void
+pgl_wl_teardown(struct pgl_egl_resources *egl,
+	        enum piglit_result *out_result)
+{
+	struct pgl_wl_resources *wl = NULL;
+	bool ok = true;
+
+	*out_result = PIGLIT_PASS;
+
+	if (egl) {
+		wl = egl->platform_private;
+	}
+
+	if (egl && egl->window) {
+		ok = eglDestroySurface(egl->dpy, egl->window);
+		if (!ok) {
+			error("eglDestroySurface failed for Wayland");
+			*out_result = PIGLIT_FAIL;
+		}
+	}
+
+	if (wl && wl->window) {
+		wl_egl_window_destroy(wl->window);
+	}
+
+	if (wl && wl->shell_surface) {
+		wl_shell_surface_destroy(wl->shell_surface);
+	}
+
+	if (wl && wl->surface) {
+		wl_surface_destroy(wl->surface);
+	}
+
+	if (egl && egl->dpy) {
+		ok = eglTerminate(egl->dpy);
+		if (!ok) {
+			error("eglTerminate failed for Wayland");
+			*out_result = PIGLIT_FAIL;
+		}
+	}
+
+	if (wl && wl->dpy) {
+		wl_display_disconnect(wl->dpy);
+	}
+
+	free(wl);
+	free(egl);
+}
+#endif /* PIGLIT_HAS_WAYLAND */
diff --git a/tests/egl/spec/egl_ext_platform_base/x11.c b/tests/egl/spec/egl_ext_platform_base/x11.c
new file mode 100644
index 0000000..ed8c52c
--- /dev/null
+++ b/tests/egl/spec/egl_ext_platform_base/x11.c
@@ -0,0 +1,257 @@
+/* 
+ * Copyright 2014 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#include "common.h"
+
+#ifndef PIGLIT_HAS_X11
+
+void
+pgl_x11_setup(enum piglit_result *out_result,
+	      struct pgl_egl_resources **out_egl)
+{
+	*out_result = PIGLIT_SKIP;
+	*out_egl = NULL;
+}
+
+void
+pgl_x11_teardown(struct pgl_egl_resources *egl,
+		 enum piglit_result *out_result)
+{
+	*out_result = PIGLIT_SKIP;
+}
+
+#else /* PIGLIT_HAS_X11 */
+
+#include <X11/Xlib.h>
+
+struct pgl_x11_resources {
+	Display *dpy;
+	XVisualInfo *vi;
+	Window window;
+	Pixmap pixmap;
+};
+
+void
+pgl_x11_setup(enum piglit_result *out_result,
+	      struct pgl_egl_resources **out_egl)
+{
+	struct pgl_egl_resources *egl = NULL;
+	struct pgl_x11_resources *x11 = NULL;
+	bool ok = true;
+
+	int num_visuals = 0;
+	Window x11_root = 0;
+        XVisualInfo x11_vi_template = {0};
+
+	EGLDisplay egl_dpy_again = NULL;
+	EGLint egl_major = 0, egl_minor = 0, num_configs = 0;
+
+	/* Initialize outputs. */
+	*out_egl = NULL;
+	*out_result = PIGLIT_FAIL;
+
+	egl = calloc(1, sizeof(*egl));
+	if (!egl) {
+		error("out of memory");
+		goto fail;
+	}
+
+	x11 = calloc(1, sizeof(*x11));
+	if (!x11) {
+		error("out of memory");
+		goto fail;
+	}
+
+	egl->platform_private = x11;
+	
+	x11->dpy = XOpenDisplay(NULL);
+	if (!x11->dpy) {
+		error("XOpenDisplay failed");
+		goto skip;
+	}
+
+	egl->dpy = eglGetPlatformDisplayEXT(EGL_PLATFORM_X11_EXT,
+					    x11->dpy, NULL);
+	if (!egl->dpy) {
+		error("eglGetPlatformDisplay failed for X11");
+		goto fail;
+	}
+
+	/* From the EGL_EXT_platform_base spec, version 9:
+	 *
+	 *   Multiple calls made to eglGetPlatformDisplayEXT with the same
+	 *   <platform> and <native_display> will return the same EGLDisplay
+	 *   handle.
+	 */
+	egl_dpy_again = eglGetPlatformDisplayEXT(EGL_PLATFORM_X11_EXT,
+					         x11->dpy, NULL);
+	if (egl->dpy != egl_dpy_again) {
+		error("eglGetPlatformDisplayEXT returned different EGLDisplay "
+		      "handles for same X11 Display");
+		goto fail;
+	}
+
+	ok = eglInitialize(egl->dpy, &egl_major, &egl_minor);
+	if (!ok) {
+		error("eglInitialize failed for X11");
+		goto fail;
+	}
+
+	ok = eglChooseConfig(egl->dpy, pgl_egl_config_attrs,
+			     &egl->config, 1, &num_configs);
+	if (!ok || num_configs == 0 || !egl->config) {
+		error("eglChooseConfig failed for X11");
+		goto fail;
+	}
+
+	memset(&x11_vi_template, 0, sizeof(x11_vi_template));
+	ok = eglGetConfigAttrib(egl->dpy, egl->config, EGL_NATIVE_VISUAL_ID,
+			        (EGLint*) &x11_vi_template.visualid);
+	if (!ok) {
+		error("eglGetConfigAttrib(EGL_NATIVE_VISUAL_ID) failed "
+		      "for X11");
+		goto fail;
+	}
+
+	x11->vi = XGetVisualInfo(x11->dpy, VisualIDMask, &x11_vi_template,
+			         &num_visuals);
+	if (!x11->vi || num_visuals == 0) {
+		error("XGetVisualInfo failed");
+		goto fail;
+	}
+
+
+	x11_root = RootWindow(x11->dpy, DefaultScreen(x11->dpy));
+	if (!x11_root) {
+		error("RootWindow() failed");
+		goto fail;
+	}
+
+        x11->window = XCreateWindow(x11->dpy, x11_root,
+				    0, 0, /*x, y*/
+				    window_width, window_height,
+				    0, /*border_width*/
+				    x11->vi->depth,
+				    InputOutput, /*class*/
+				    x11->vi->visual,
+				    0, /*attribute mask*/
+				    NULL); /*attributes*/
+	if (!x11->window) {
+		error("XCreateWindow failed");
+		goto fail;
+	}
+
+	egl->window = eglCreatePlatformWindowSurfaceEXT(egl->dpy, egl->config,
+						        &x11->window, NULL);
+	if (!egl->window) {
+		error("eglCreatePlatformWindowSurfaceEXT failed for X11");
+		goto fail;
+	}
+
+	x11->pixmap = XCreatePixmap(x11->dpy, x11_root,
+				    window_width, window_height,
+				    x11->vi->depth);
+	if (!x11->pixmap) {
+		error("XCreatePixmap failed");
+		goto fail;
+	}
+
+	egl->pixmap = eglCreatePlatformPixmapSurfaceEXT(egl->dpy, egl->config,
+							&x11->pixmap, NULL);
+	if (!egl->pixmap) {
+		error("eglCreatePlatformPixmapSurfaceEXT failed for X11");
+		goto fail;
+	}
+
+	*out_result = PIGLIT_PASS;
+	*out_egl = egl;
+	return;
+
+skip:
+	pgl_x11_teardown(egl, out_result);
+	*out_result = PIGLIT_SKIP;
+	return;
+
+fail:
+	pgl_x11_teardown(egl, out_result);
+	*out_result = PIGLIT_FAIL;
+	return;
+}
+
+void
+pgl_x11_teardown(struct pgl_egl_resources *egl,
+		 enum piglit_result *out_result)
+{
+	struct pgl_x11_resources *x11 = NULL;
+	bool ok = true;
+
+	*out_result = PIGLIT_PASS;
+
+	if (egl) {
+		x11 = egl->platform_private;
+	}
+
+	if (egl && egl->window) {
+		ok = eglDestroySurface(egl->dpy, egl->window);
+		if (!ok) {
+			error("eglDestroySurface failed for X11 window");
+			*out_result = PIGLIT_FAIL;
+		}
+	}
+
+	if (x11 && x11->window) {
+		XDestroyWindow(x11->dpy, x11->window);
+	}
+
+	if (egl && egl->pixmap) {
+		ok = eglDestroySurface(egl->dpy, egl->pixmap);
+		if (!ok) {
+			error("eglDestroySurface failed for X11 pixmap");
+			*out_result = PIGLIT_FAIL;
+		}
+	}
+
+	if (x11 && x11->pixmap) {
+		XFreePixmap(x11->dpy, x11->pixmap);
+	}
+
+	if (x11 && x11->vi) {
+		XFree(x11->vi);
+	}
+
+	if (egl && egl->dpy) {
+		ok = eglTerminate(egl->dpy);
+		if (!ok) {
+			error("eglTerminate failed for X11");
+			*out_result = PIGLIT_FAIL;
+		}
+	}
+
+	if (x11 && x11->dpy) {
+		XCloseDisplay(x11->dpy);
+	}
+
+	free(x11);
+	free(egl);
+}
+#endif /* PIGLIT_HAS_X11 */
-- 
1.8.5.3



More information about the Piglit mailing list