[Mesa-dev] [PATCH] glx: Add test for GLX_EXT_buffer_age

Adel Gadllah adel.gadllah at gmail.com
Fri Feb 21 17:08:49 PST 2014


Add a test case for the GLX_EXT_buffer_age extension.
---
 tests/all.py                |   1 +
 tests/glx/CMakeLists.gl.txt |   1 +
 tests/glx/glx-buffer-age.c  | 115 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 117 insertions(+)
 create mode 100644 tests/glx/glx-buffer-age.c

diff --git a/tests/all.py b/tests/all.py
index 9f68690..85d313f 100644
--- a/tests/all.py
+++ b/tests/all.py
@@ -705,6 +705,7 @@ add_plain_test(glx, 'glx-swap-pixmap-bad')
 add_plain_test(glx, 'glx-swap-singlebuffer')
 add_plain_test(glx, 'glx-make-current')
 add_plain_test(glx, 'glx-make-glxdrawable-current')
+add_plain_test(glx, 'glx-buffer-age')
 add_concurrent_test(glx, 'glx-pixmap-life')
 add_concurrent_test(glx, 'glx-pixmap13-life')
 add_concurrent_test(glx, 'glx-pixmap-multi')
diff --git a/tests/glx/CMakeLists.gl.txt b/tests/glx/CMakeLists.gl.txt
index 7f3a713..eeb1d7a 100644
--- a/tests/glx/CMakeLists.gl.txt
+++ b/tests/glx/CMakeLists.gl.txt
@@ -70,6 +70,7 @@ IF(PIGLIT_BUILD_GLX_TESTS)
 
 	piglit_add_executable (glx-copy-sub-buffer glx-copy-sub-buffer.c)
 	piglit_add_executable (glx-query-drawable glx-query-drawable.c)
+	piglit_add_executable (glx-buffer-age glx-buffer-age.c)
 
 	piglit_add_executable (glx-string-sanity glx-string-sanity.c)
 ENDIF(PIGLIT_BUILD_GLX_TESTS)
diff --git a/tests/glx/glx-buffer-age.c b/tests/glx/glx-buffer-age.c
new file mode 100644
index 0000000..8c19ef0
--- /dev/null
+++ b/tests/glx/glx-buffer-age.c
@@ -0,0 +1,115 @@
+/*
+ * Copyright Christopher James Halse Rogers <christopher.halse.rogers at canonical.com>
+ * Copyright 2010 Red Hat, Inc.
+ * Adel Gadllah <adel.gadllah at gmail.com>
+ *
+ * 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:
+ *    Christopher James Halse Rogers <christopher.halse.rogers at canonical.com>
+ *    Adam Jackson <ajax at redhat.com>
+ *    Adel Gadllah <adel.gadllah at gmail.com>
+ *
+ * Derived from glx-copy-sub-buffer.c
+ *
+ */
+
+/** @file glx-buffer-age.c
+ *
+ * Test that GLX_EXT_buffer_age works as advertised
+ */
+
+#include "piglit-util-gl-common.h"
+#include "piglit-glx-util.h"
+
+#ifndef GLX_BACK_BUFFER_AGE_EXT
+#define GLX_BACK_BUFFER_AGE_EXT 0x20F4
+#endif
+
+int piglit_width = 100, piglit_height = 100;
+static Display *dpy;
+static Window window;
+static XVisualInfo *visinfo;
+
+enum piglit_result
+draw(Display *dpy)
+{
+    GLXContext ctx;
+    GLboolean pass;
+    unsigned int age;
+    int i;
+    static GLfloat colors[3][4] = {{1.0, 0.0, 0.0, 1.0},
+                                   {0.0, 1.0, 0.0, 1.0},
+                                   {0.0, 0.0, 1.0, 1.0}};
+    GLfloat probe[4];
+    enum piglit_result result;
+
+    ctx = piglit_get_glx_context(dpy, visinfo);
+    glXMakeCurrent(dpy, window, ctx);
+    piglit_dispatch_default_init(PIGLIT_DISPATCH_GL);
+
+    for (i = 0; i < 3; i++) {
+        glClearColor(colors[i][0], colors[i][1], colors[i][2], colors[i][3]);
+        glClear(GL_COLOR_BUFFER_BIT);
+        glXSwapBuffers(dpy, window);
+    }
+
+    glXQueryDrawable(dpy, window, GLX_BACK_BUFFER_AGE_EXT, &age);
+
+    if (age == 0 || age > 3) {
+        result = PIGLIT_SKIP;
+        goto out;
+    }
+
+    glReadBuffer(GL_BACK);
+    pass = piglit_probe_pixel_rgba_silent(0, 0, colors[3 - age], probe);
+    result = pass ? PIGLIT_PASS : PIGLIT_FAIL;
+
+out:
+    glXMakeCurrent(dpy, None, NULL);
+    glXDestroyContext(dpy, ctx);
+
+    return result;
+}
+
+
+int
+main(int argc, char **argv)
+{
+    int i;
+
+    for(i = 1; i < argc; i++) {
+        if (!strcmp(argv[i], "-auto"))
+            piglit_automatic = 1;
+        else
+            fprintf(stderr, "Unknown option: %s\n", argv[i]);
+    }
+
+    dpy = piglit_get_glx_display();
+    piglit_require_glx_extension(dpy, "EXT_buffer_age");
+    visinfo = piglit_get_glx_visual(dpy);
+    window = piglit_get_glx_window(dpy, visinfo);
+
+    XMapWindow(dpy, window);
+
+    piglit_glx_event_loop(dpy, draw);
+
+    return 0;
+}
-- 
1.8.5.3



More information about the mesa-dev mailing list