[Piglit] [PATCH] Add a test for eglMakeCurrent.
Chia-I Wu
olvaffe at gmail.com
Sat Oct 23 02:15:12 PDT 2010
This test calls eglMakeCurrent in all kinds of orders as well as testing
destroying a current context/surface.
---
tests/egl/CMakeLists.txt | 2 +
tests/egl/egl-make-current.c | 172 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 174 insertions(+), 0 deletions(-)
create mode 100644 tests/egl/egl-make-current.c
diff --git a/tests/egl/CMakeLists.txt b/tests/egl/CMakeLists.txt
index 1667340..c6dc1cd 100644
--- a/tests/egl/CMakeLists.txt
+++ b/tests/egl/CMakeLists.txt
@@ -25,4 +25,6 @@ IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
target_link_libraries(egl-nok-swap-region pthread X11)
add_executable (egl-nok-texture-from-pixmap egl-util.c egl-nok-texture-from-pixmap.c)
target_link_libraries(egl-nok-texture-from-pixmap pthread X11)
+ add_executable (egl-make-current egl-make-current.c)
+ target_link_libraries(egl-make-current pthread X11)
ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
diff --git a/tests/egl/egl-make-current.c b/tests/egl/egl-make-current.c
new file mode 100644
index 0000000..023231d
--- /dev/null
+++ b/tests/egl/egl-make-current.c
@@ -0,0 +1,172 @@
+/*
+ * Copyright (C) 2010 LunarG Inc.
+ *
+ * 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.
+ *
+ * Authors:
+ * Chia-I Wu <olv at lunarg.com>
+ */
+
+/** @file egl-make-curren.c
+ *
+ * Test eglMakeCurrent
+ */
+
+#include <EGL/egl.h>
+#include "piglit-util.h"
+
+static int automatic;
+
+static void
+make_current(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx,
+ EGLBoolean test_inverse)
+{
+ EGLSurface cur_draw, cur_read;
+ EGLContext cur_ctx;
+
+ cur_draw = eglGetCurrentSurface(EGL_DRAW);
+ cur_read = eglGetCurrentSurface(EGL_READ);
+ cur_ctx = eglGetCurrentContext();
+
+ /* make current, undo, and make current */
+ if (!eglMakeCurrent(dpy, draw, read, ctx) ||
+ (test_inverse && !eglMakeCurrent(dpy, cur_draw, cur_read, cur_ctx)) ||
+ (test_inverse && !eglMakeCurrent(dpy, draw, read, ctx))) {
+ fprintf(stderr, "eglMakeCurrent() failed\n");
+ piglit_report_result(PIGLIT_FAILURE);
+ }
+
+ cur_draw = eglGetCurrentSurface(EGL_DRAW);
+ cur_read = eglGetCurrentSurface(EGL_READ);
+ cur_ctx = eglGetCurrentContext();
+
+ if (cur_draw != draw || cur_read != read || cur_ctx != ctx) {
+ fprintf(stderr, "eglMakeCurrent() failed\n");
+ piglit_report_result(PIGLIT_FAILURE);
+ }
+}
+
+static void
+test_run(void)
+{
+ EGLDisplay dpy;
+ EGLConfig cfg;
+ EGLContext ctx1, ctx2, ctx3;
+ EGLSurface pbuf1, pbuf2, pbuf3;
+ EGLint count;
+ const EGLint cfg_attribs[] = {
+ EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
+ EGL_NONE
+ };
+ const EGLint pbuf_attribs[] = {
+ EGL_WIDTH, 1, EGL_HEIGHT, 1,
+ EGL_NONE
+ };
+
+ dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
+ if (dpy == EGL_NO_DISPLAY) {
+ fprintf(stderr, "eglGetDisplay() failed\n");
+ piglit_report_result(PIGLIT_FAILURE);
+ }
+
+ if (!eglInitialize(dpy, NULL, NULL)) {
+ fprintf(stderr, "eglInitialize() failed\n");
+ piglit_report_result(PIGLIT_FAILURE);
+ }
+
+ /* skip unless pbuffer is supported */
+ if (!eglChooseConfig(dpy, cfg_attribs, &cfg, 1, &count) ||
+ count == 0) {
+ eglTerminate(dpy);
+ piglit_report_result(PIGLIT_SKIP);
+ }
+
+ ctx1 = eglCreateContext(dpy, cfg, EGL_NO_CONTEXT, NULL);
+ ctx2 = eglCreateContext(dpy, cfg, EGL_NO_CONTEXT, NULL);
+ ctx3 = eglCreateContext(dpy, cfg, EGL_NO_CONTEXT, NULL);
+ if (ctx1 == EGL_NO_CONTEXT || ctx2 == EGL_NO_CONTEXT ||
+ ctx3 == EGL_NO_CONTEXT) {
+ fprintf(stderr, "eglCreateContext() failed\n");
+ eglTerminate(dpy);
+ piglit_report_result(PIGLIT_FAILURE);
+ }
+
+ pbuf1 = eglCreatePbufferSurface(dpy, cfg, pbuf_attribs);
+ pbuf2 = eglCreatePbufferSurface(dpy, cfg, pbuf_attribs);
+ pbuf3 = eglCreatePbufferSurface(dpy, cfg, pbuf_attribs);
+ if (pbuf1 == EGL_NO_SURFACE || pbuf2 == EGL_NO_SURFACE ||
+ pbuf3 == EGL_NO_SURFACE) {
+ fprintf(stderr, "eglCreatePbuferSurface() failed\n");
+ eglTerminate(dpy);
+ piglit_report_result(PIGLIT_FAILURE);
+ }
+
+ /* test basic switches */
+ make_current(dpy, pbuf1, pbuf2, ctx1, EGL_TRUE);
+ make_current(dpy, pbuf3, pbuf3, ctx2, EGL_TRUE);
+ make_current(dpy, EGL_NO_SURFACE, EGL_NO_SURFACE,
+ EGL_NO_CONTEXT, EGL_TRUE);
+ make_current(dpy, pbuf3, pbuf3, ctx2, EGL_TRUE);
+ make_current(dpy, pbuf1, pbuf2, ctx1, EGL_TRUE);
+ make_current(dpy, EGL_NO_SURFACE, EGL_NO_SURFACE,
+ EGL_NO_CONTEXT, EGL_TRUE);
+
+ /* test step by step switch */
+ make_current(dpy, pbuf1, pbuf2, ctx1, EGL_TRUE);
+ make_current(dpy, pbuf3, pbuf2, ctx1, EGL_TRUE);
+ make_current(dpy, pbuf3, pbuf3, ctx1, EGL_TRUE);
+ make_current(dpy, pbuf3, pbuf3, ctx2, EGL_TRUE);
+ make_current(dpy, EGL_NO_SURFACE, EGL_NO_SURFACE,
+ EGL_NO_CONTEXT, EGL_TRUE);
+
+ /* test negative cases? */
+
+ /* test destroying current context/surface */
+ make_current(dpy, pbuf1, pbuf2, ctx1, EGL_FALSE);
+ eglDestroySurface(dpy, pbuf1);
+ make_current(dpy, pbuf2, pbuf2, ctx1, EGL_FALSE);
+ eglDestroyContext(dpy, ctx1);
+ make_current(dpy, pbuf2, pbuf3, ctx2, EGL_FALSE);
+ eglDestroySurface(dpy, pbuf2);
+ eglDestroyContext(dpy, ctx2);
+ make_current(dpy, pbuf3, pbuf3, ctx3, EGL_FALSE);
+
+ eglMakeCurrent(dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
+ eglTerminate(dpy);
+
+ piglit_report_result(PIGLIT_SUCCESS);
+}
+
+int
+main(int argc, char *argv[])
+{
+ int i;
+
+ for (i = 1; i < argc; ++i) {
+ if (!strcmp(argv[i], "-auto"))
+ automatic = 1;
+ else
+ fprintf(stderr, "Unknown option: %s\n", argv[i]);
+ }
+
+ test_run();
+
+ return EXIT_SUCCESS;
+}
--
1.7.1
More information about the Piglit
mailing list