rendercheck: Makefile.am rendercheck.h tests.c t_tsrccoords2.c

Eric Anholt anholt at kemper.freedesktop.org
Sat Feb 3 03:33:56 EET 2007


 Makefile.am     |    1 
 rendercheck.h   |    4 +
 t_tsrccoords2.c |  173 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 tests.c         |    9 ++
 4 files changed, 187 insertions(+)

New commits:
diff-tree 70d94216cc7b6ecd15cc628646516aef10972035 (from 160d69f593f4054d1973b27a24bf24323774c346)
Author: Eric Anholt <eric at anholt.net>
Date:   Fri Feb 2 17:04:10 2007 -0800

    Add another transformed source coordinates test.
    
    This one takes a whole image and rotates it to the left when drawing it to
    the destination.  Reveals an off-by-one error in i915 Render acceleration.

diff --git a/Makefile.am b/Makefile.am
index 03b1e1b..fe66ba3 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -15,6 +15,7 @@ rendercheck_SOURCES = \
 	t_repeat.c \
 	t_srccoords.c \
 	t_tsrccoords.c \
+	t_tsrccoords2.c \
 	t_triangles.c
 
 INCLUDES = $(RC_CFLAGS)
diff --git a/rendercheck.h b/rendercheck.h
index ada9a8e..40a36f6 100644
--- a/rendercheck.h
+++ b/rendercheck.h
@@ -150,6 +150,10 @@ Bool
 trans_coords_test(Display *dpy, picture_info *win, picture_info *white,
     Bool test_mask);
 
+Bool
+trans_srccoords_test_2(Display *dpy, picture_info *win, picture_info *white,
+    Bool test_mask);
+
 Bool linear_gradient_test(Display *dpy, picture_info *win,
                           picture_info *dst, int op, picture_info *dst_color);
 
diff --git a/t_tsrccoords2.c b/t_tsrccoords2.c
new file mode 100644
index 0000000..1bb3974
--- /dev/null
+++ b/t_tsrccoords2.c
@@ -0,0 +1,173 @@
+/*
+ * Copyright © 2007 Eric Anholt
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of Eric Anholt not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission.  Eric Anholt makes no
+ * representations about the suitability of this software for any purpose.  It
+ * is provided "as is" without express or implied warranty.
+ *
+ * ERIC ANHOLT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL ERIC ANHOLT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "rendercheck.h"
+
+/* Originally a bullseye, this pattern has been modified so that flipping
+ * will result in errors as well.
+ */
+static int target_colors[5][5] = {
+	{1, 1, 1, 1, 1},
+	{1, 0, 0, 0, 1},
+	{1, 1, 1, 0, 1},
+	{1, 0, 0, 1, 1},
+	{1, 1, 1, 1, 1},
+};
+
+static picture_info *create_target_picture(Display *dpy)
+{
+	picture_info *p;
+	int i;
+
+	p = malloc(sizeof(picture_info));
+
+	p->d = XCreatePixmap(dpy, RootWindow(dpy, 0), 5, 5, 32);
+	p->format = XRenderFindStandardFormat(dpy, PictStandardARGB32);
+	p->pict = XRenderCreatePicture(dpy, p->d, p->format, 0, NULL);
+	p->name = "target picture";
+
+	for (i = 0; i < 25; i++) {
+		int x = i % 5;
+		int y = i / 5;
+		color4d *c = &colors[target_colors[y][x]];
+
+		argb_fill(dpy, p, x, y, 1, 1, c->a, c->r, c->g, c->b);
+	}
+
+	return p;
+}
+
+static void destroy_target_picture(Display *dpy, picture_info *p)
+{
+	XRenderFreePicture(dpy, p->pict);
+	XFreePixmap(dpy, p->d);
+	free(p);
+}
+
+
+/* Test source or mask coordinates by drawing from a 5x5 picture into the 0,0
+ * pixel, rotated 90 degrees to the left.
+ */
+Bool
+trans_srccoords_test_2(Display *dpy, picture_info *win, picture_info *white,
+    Bool test_mask)
+{
+	color4d expected, tested;
+	int i;
+	XRenderPictureAttributes pa;
+	Bool failed = FALSE;
+	int tested_colors[5][5];
+	picture_info *src;
+	XTransform t;
+
+	src = create_target_picture(dpy);
+	if (src == NULL) {
+		fprintf(stderr, "couldn't allocate picture for test\n");
+		return FALSE;
+	}
+
+	/* Transform that rotates right from the destination coords to the
+	 * src coords.
+	 */
+	t.matrix[0][0] = XDoubleToFixed(0);
+	t.matrix[0][1] = XDoubleToFixed(-1);
+	t.matrix[0][2] = XDoubleToFixed(5);
+	t.matrix[1][0] = XDoubleToFixed(1);
+	t.matrix[1][1] = XDoubleToFixed(0);
+	t.matrix[1][2] = XDoubleToFixed(0);
+	t.matrix[2][0] = XDoubleToFixed(0);
+	t.matrix[2][1] = XDoubleToFixed(0);
+	t.matrix[2][2] = XDoubleToFixed(1);
+	XRenderSetPictureTransform(dpy, src->pict, &t);
+
+	if (!test_mask) {
+		XRenderComposite(dpy, PictOpSrc, src->pict, 0,
+		    win->pict, 0, 0, 0, 0, 0, 0, 5, 5);
+	} else {
+		/* Using PictOpSrc, color 0 (white), and component
+		 * alpha, the mask color should be written to the
+		 * destination.
+		 */
+		pa.component_alpha = TRUE;
+		XRenderChangePicture(dpy, src->pict, CPComponentAlpha,
+		    &pa);
+		XRenderComposite(dpy, PictOpSrc, white->pict, src->pict,
+		    win->pict, 0, 0, 0, 0, 0, 0, 5, 5);
+		pa.component_alpha = FALSE;
+		XRenderChangePicture(dpy, src->pict, CPComponentAlpha,
+		    &pa);
+	}
+
+	for (i = 0; i < 25; i++) {
+		char name[20];
+		int x = i % 5, y = i / 5, srcx, srcy;
+
+		get_pixel(dpy, win, x, y, &tested);
+
+		/* Map from our destination coordinates to where they are
+		 * in the source picture.  Rotate right.
+		 */
+		srcx = 4 - y;
+		srcy = x;
+		expected = colors[target_colors[srcy][srcx]];
+		color_correct(win, &expected);
+		if (tested.r == 1.0) {
+			if (tested.g == 1.0 && tested.b == 1.0)
+				tested_colors[y][x] = 0;
+			else if (tested.g == 0.0 && tested.b == 0.0)
+				tested_colors[y][x] = 1;
+			else tested_colors[y][x] = 9;
+		} else
+			tested_colors[y][x] = 9;
+
+		if (test_mask)
+			snprintf(name, 20, "mask coords");
+		else
+			snprintf(name, 20, "src coords");
+		if (!eval_diff(name, &expected, &tested, x, y, is_verbose))
+			failed = TRUE;
+	}
+	if (failed) {
+		int x, y;
+
+		printf("expected vs tested:\n");
+		for (y = 0; y < 5; y++) {
+			for (x = 0; x < 5; x++) {
+				int srcx = 4 - y;
+				int srcy = x;
+
+				printf("%d", target_colors[srcy][srcx]);
+			}
+			printf(" ");
+			for (x = 0; x < 5; x++)
+				printf("%d", tested_colors[y][x]);
+			printf("\n");
+		}
+	}
+
+	destroy_target_picture(dpy, src);
+
+	return !failed;
+}
diff --git a/tests.c b/tests.c
index 5f8fead..ff41bbd 100644
--- a/tests.c
+++ b/tests.c
@@ -472,6 +472,10 @@ do {								\
 		printf("Beginning transformed src coords test\n");
 		ok = trans_coords_test(dpy, win, argb32white, FALSE);
 		RECORD_RESULTS();
+
+		printf("Beginning transformed src coords test 2\n");
+		ok = trans_srccoords_test_2(dpy, win, argb32white, FALSE);
+		RECORD_RESULTS();
 		if (group_ok)
 			success_mask |= TEST_TSRCCOORDS;
 	}
@@ -482,6 +486,11 @@ do {								\
 		printf("Beginning transformed mask coords test\n");
 		ok = trans_coords_test(dpy, win, argb32white, TRUE);
 		RECORD_RESULTS();
+
+		printf("Beginning transformed mask coords test 2\n");
+		ok = trans_srccoords_test_2(dpy, win, argb32white, TRUE);
+		RECORD_RESULTS();
+
 		if (group_ok)
 			success_mask |= TEST_TMASKCOORDS;
 	}



More information about the xorg-commit mailing list