[cairo-commit] 3 commits - test/coverage.c test/reference

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Sat Dec 31 17:30:32 UTC 2022


 test/coverage.c                                         |  122 ++++++++--------
 test/reference/coverage-column-triangles.ref.png        |binary
 test/reference/coverage-column-triangles.xfail.png      |binary
 test/reference/coverage-column-triangles.xlib.xfail.png |binary
 4 files changed, 62 insertions(+), 60 deletions(-)

New commits:
commit 52e964da69abe87327b77fe4e47b0da239d0e1cf
Merge: 7de261b0b 8d74c4d01
Author: Uli Schlachter <psychon at znc.in>
Date:   Sat Dec 31 17:30:29 2022 +0000

    Merge branch 'speed-up-coverage-column-triangles' into 'master'
    
    Speed up coverage-column-triangles test
    
    Closes #498
    
    See merge request cairo/cairo!379

commit 8d74c4d0198326f2d216e3c8c0b18e121cdb1436
Author: Uli Schlachter <psychon at znc.in>
Date:   Fri Dec 30 16:36:22 2022 +0100

    Speed up coverage-column-triangles test
    
    This commit changes the height of the coverage-column-triangles test by
    using a smaller height for the test. Previously the image was 40 pixels
    in height and the test took 517 seconds for me. Now, the image has a
    height of 4 pixels and the test takes 55 seconds.
    
    This is possible since column_triangles() does the same thing for each y
    coordinate. Thus, previously this test just did the same thing 40 times.
    
    Times are measured with the backends I happened to have enabled locally:
    script, xcb, xlib, image, recording.
    
    Thanks a lot to Christian Rohlfs for coming up with this idea in
    https://gitlab.freedesktop.org/cairo/cairo/-/issues/498#note_1700197
    
    Possibly-fixes: https://gitlab.freedesktop.org/cairo/cairo/-/issues/498
    Signed-off-by: Uli Schlachter <psychon at znc.in>

diff --git a/test/coverage.c b/test/coverage.c
index f6626f3d0..0749fa22a 100644
--- a/test/coverage.c
+++ b/test/coverage.c
@@ -491,7 +491,8 @@ CAIRO_TEST (coverage_column_triangles,
 	    "Check the fidelity of the rasterisation.",
 	    NULL, /* keywords */
 	    "target=raster", /* requirements */
-	    WIDTH, HEIGHT,
+	    /* Smaller height since this test does not vary by y-coordinate */
+	    WIDTH, 4,
 	    NULL, column_triangles)
 CAIRO_TEST (coverage_triangles,
 	    "Check the fidelity of the rasterisation.",
diff --git a/test/reference/coverage-column-triangles.ref.png b/test/reference/coverage-column-triangles.ref.png
index aa61031b7..24ccc9f2a 100644
Binary files a/test/reference/coverage-column-triangles.ref.png and b/test/reference/coverage-column-triangles.ref.png differ
diff --git a/test/reference/coverage-column-triangles.xfail.png b/test/reference/coverage-column-triangles.xfail.png
index 566b41544..9af5253c5 100644
Binary files a/test/reference/coverage-column-triangles.xfail.png and b/test/reference/coverage-column-triangles.xfail.png differ
diff --git a/test/reference/coverage-column-triangles.xlib.xfail.png b/test/reference/coverage-column-triangles.xlib.xfail.png
index f433b7a84..18e4af2da 100644
Binary files a/test/reference/coverage-column-triangles.xlib.xfail.png and b/test/reference/coverage-column-triangles.xlib.xfail.png differ
commit 35f2610f4d6410e2737b27f444a00ab540df0907
Author: Uli Schlachter <psychon at znc.in>
Date:   Fri Dec 30 09:29:10 2022 +0100

    coverage.c: Use width/height arguments
    
    The tests in coverage.c have #defines for WIDTH and HEIGHT, but also
    have function arguments for these numbers. This commit changes the tests
    to use the function arguments instead of the defines.
    
    One complication is the rhombus test that already had a factor 2 between
    these two numbers. A new variable is added to get back the previous
    value.
    
    Signed-off-by: Uli Schlachter <psychon at znc.in>

diff --git a/test/coverage.c b/test/coverage.c
index 86216df31..f6626f3d0 100644
--- a/test/coverage.c
+++ b/test/coverage.c
@@ -50,9 +50,9 @@ hars_petruska_f54_1_random (void)
 }
 
 static double
-random_offset (int range, int precise)
+random_offset (int range, int precise, int width)
 {
-    double x = hars_petruska_f54_1_random() / (double) UINT32_MAX * range / WIDTH;
+    double x = hars_petruska_f54_1_random() / (double) UINT32_MAX * range / width;
     if (precise)
 	x = floor (x * PRECISION) / PRECISION;
     return x;
@@ -69,9 +69,9 @@ rectangles (cairo_t *cr, int width, int height)
     cairo_paint (cr);
 
 #if GENERATE_REFERENCE
-    for (x = 0; x < WIDTH; x++) {
-	cairo_set_source_rgba (cr, 1, 1, 1, x * x * 1.0 / (WIDTH * WIDTH));
-	cairo_rectangle (cr, x, 0, 1, HEIGHT);
+    for (x = 0; x < width; x++) {
+	cairo_set_source_rgba (cr, 1, 1, 1, x * x * 1.0 / (width * width));
+	cairo_rectangle (cr, x, 0, 1, height);
 	cairo_fill (cr);
     }
 #else
@@ -84,11 +84,11 @@ rectangles (cairo_t *cr, int width, int height)
 	case 2: cairo_set_source_rgb (cr, 0.0, 0.0, 1.0); break;
 	}
 
-	for (x = 0; x < WIDTH; x++) {
-	    for (y = 0; y < HEIGHT; y++) {
-		double dx = random_offset (WIDTH - x, TRUE);
-		double dy = random_offset (WIDTH - x, TRUE);
-		cairo_rectangle (cr, x + dx, y + dy, x / (double) WIDTH, x / (double) WIDTH);
+	for (x = 0; x < width; x++) {
+	    for (y = 0; y < height; y++) {
+		double dx = random_offset (width - x, TRUE, width);
+		double dy = random_offset (width - x, TRUE, width);
+		cairo_rectangle (cr, x + dx, y + dy, x / (double) width, x / (double) width);
 	    }
 	}
 	cairo_fill (cr);
@@ -102,15 +102,16 @@ static cairo_test_status_t
 rhombus (cairo_t *cr, int width, int height)
 {
     int x, y;
+    int internal_size = width / 2;
 
     cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
     cairo_paint (cr);
 
 #if GENERATE_REFERENCE
-    for (y = 0; y < WIDTH; y++) {
-	for (x = 0; x < WIDTH; x++) {
+    for (y = 0; y < internal_size; y++) {
+	for (x = 0; x < internal_size; x++) {
 	    cairo_set_source_rgba (cr, 1, 1, 1,
-				   x * y / (2. * WIDTH * WIDTH));
+				   x * y / (2. * internal_size * internal_size));
 	    cairo_rectangle (cr, 2*x, 2*y, 2, 2);
 	    cairo_fill (cr);
 	}
@@ -119,10 +120,10 @@ rhombus (cairo_t *cr, int width, int height)
     cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
     cairo_set_source_rgb (cr, 1, 1, 1);
 
-    for (y = 0; y < WIDTH; y++) {
-	double yf = y / (double) WIDTH;
-	for (x = 0; x < WIDTH; x++) {
-	    double xf = x / (double) WIDTH;
+    for (y = 0; y < internal_size; y++) {
+	double yf = y / (double) internal_size;
+	for (x = 0; x < internal_size; x++) {
+	    double xf = x / (double) internal_size;
 
 	    cairo_move_to (cr,
 			   2*x + 1 - xf,
@@ -157,9 +158,9 @@ intersecting_quads (cairo_t *cr, int width, int height)
     cairo_paint (cr);
 
 #if GENERATE_REFERENCE
-    for (x = 0; x < WIDTH; x++) {
-	cairo_set_source_rgba (cr, 1, 1, 1, x * x * 0.5 / (WIDTH * WIDTH));
-	cairo_rectangle (cr, x, 0, 1, HEIGHT);
+    for (x = 0; x < width; x++) {
+	cairo_set_source_rgba (cr, 1, 1, 1, x * x * 0.5 / (width * width));
+	cairo_rectangle (cr, x, 0, 1, height);
 	cairo_fill (cr);
     }
 #else
@@ -172,11 +173,11 @@ intersecting_quads (cairo_t *cr, int width, int height)
 	case 2: cairo_set_source_rgb (cr, 0.0, 0.0, 1.0); break;
 	}
 
-	for (x = 0; x < WIDTH; x++) {
-	    double step = x / (double) WIDTH;
-	    for (y = 0; y < HEIGHT; y++) {
-		double dx = random_offset (WIDTH - x, TRUE);
-		double dy = random_offset (WIDTH - x, TRUE);
+	for (x = 0; x < width; x++) {
+	    double step = x / (double) width;
+	    for (y = 0; y < height; y++) {
+		double dx = random_offset (width - x, TRUE, width);
+		double dy = random_offset (width - x, TRUE, width);
 		cairo_move_to (cr, x + dx, y + dy);
 		cairo_rel_line_to (cr, step, step);
 		cairo_rel_line_to (cr, 0, -step);
@@ -202,9 +203,9 @@ intersecting_triangles (cairo_t *cr, int width, int height)
     cairo_paint (cr);
 
 #if GENERATE_REFERENCE
-    for (x = 0; x < WIDTH; x++) {
-	cairo_set_source_rgba (cr, 1, 1, 1, x * x * 0.75 / (WIDTH * WIDTH));
-	cairo_rectangle (cr, x, 0, 1, HEIGHT);
+    for (x = 0; x < width; x++) {
+	cairo_set_source_rgba (cr, 1, 1, 1, x * x * 0.75 / (width * width));
+	cairo_rectangle (cr, x, 0, 1, height);
 	cairo_fill (cr);
     }
 #else
@@ -217,11 +218,11 @@ intersecting_triangles (cairo_t *cr, int width, int height)
 	case 2: cairo_set_source_rgb (cr, 0.0, 0.0, 1.0); break;
 	}
 
-	for (x = 0; x < WIDTH; x++) {
-	    double step = x / (double) WIDTH;
-	    for (y = 0; y < HEIGHT; y++) {
-		double dx = random_offset (WIDTH - x, TRUE);
-		double dy = random_offset (WIDTH - x, TRUE);
+	for (x = 0; x < width; x++) {
+	    double step = x / (double) width;
+	    for (y = 0; y < height; y++) {
+		double dx = random_offset (width - x, TRUE, width);
+		double dy = random_offset (width - x, TRUE, width);
 
 		/* left */
 		cairo_move_to (cr, x + dx, y + dy);
@@ -254,9 +255,9 @@ triangles (cairo_t *cr, int width, int height)
     cairo_paint (cr);
 
 #if GENERATE_REFERENCE
-    for (x = 0; x < WIDTH; x++) {
-	cairo_set_source_rgba (cr, 1, 1, 1, x * x * 0.5 / (WIDTH * WIDTH));
-	cairo_rectangle (cr, x, 0, 1, HEIGHT);
+    for (x = 0; x < width; x++) {
+	cairo_set_source_rgba (cr, 1, 1, 1, x * x * 0.5 / (width * width));
+	cairo_rectangle (cr, x, 0, 1, height);
 	cairo_fill (cr);
     }
 #else
@@ -269,13 +270,13 @@ triangles (cairo_t *cr, int width, int height)
 	case 2: cairo_set_source_rgb (cr, 0.0, 0.0, 1.0); break;
 	}
 
-	for (x = 0; x < WIDTH; x++) {
-	    for (y = 0; y < HEIGHT; y++) {
-		double dx = random_offset (WIDTH - x, TRUE);
-		double dy = random_offset (WIDTH - x, TRUE);
+	for (x = 0; x < width; x++) {
+	    for (y = 0; y < height; y++) {
+		double dx = random_offset (width - x, TRUE, width);
+		double dy = random_offset (width - x, TRUE, width);
 		cairo_move_to (cr, x + dx, y + dy);
-		cairo_rel_line_to (cr, x / (double) WIDTH, 0);
-		cairo_rel_line_to (cr, 0, x / (double) WIDTH);
+		cairo_rel_line_to (cr, x / (double) width, 0);
+		cairo_rel_line_to (cr, 0, x / (double) width);
 		cairo_close_path (cr);
 	    }
 	}
@@ -344,9 +345,9 @@ column_triangles (cairo_t *cr, int width, int height)
     cairo_paint (cr);
 
 #if GENERATE_REFERENCE
-    for (x = 0; x < WIDTH; x++) {
-	cairo_set_source_rgba (cr, 1, 1, 1, x * 0.5 / WIDTH);
-	cairo_rectangle (cr, x, 0, 1, HEIGHT);
+    for (x = 0; x < width; x++) {
+	cairo_set_source_rgba (cr, 1, 1, 1, x * 0.5 / width);
+	cairo_rectangle (cr, x, 0, 1, height);
 	cairo_fill (cr);
     }
 #else
@@ -359,11 +360,11 @@ column_triangles (cairo_t *cr, int width, int height)
 	case 2: cairo_set_source_rgb (cr, 0.0, 0.0, 1.0); break;
 	}
 
-	for (x = 0; x < WIDTH; x++) {
-	    double step = x / (double) (2 * WIDTH);
-	    for (y = 0; y < HEIGHT; y++) {
+	for (x = 0; x < width; x++) {
+	    double step = x / (double) (2 * width);
+	    for (y = 0; y < height; y++) {
 		for (i = 0; i < PRECISION; i++) {
-		    double dy = random_offset (WIDTH - x, FALSE);
+		    double dy = random_offset (width - x, FALSE, width);
 
 		    /*
 		     * We want to test some sharing of edges to further
@@ -375,7 +376,7 @@ column_triangles (cairo_t *cr, int width, int height)
 		     *  s ---  .      ---
 		     *  t  |   |\      |
 		     *  e  |   | \     |
-		     *  p ---  ....    |  2 * step = x / WIDTH
+		     *  p ---  ....    |  2 * step = x / width
 		     *          \ |    |
 		     *           \|    |
 		     *            .   ---
@@ -383,8 +384,8 @@ column_triangles (cairo_t *cr, int width, int height)
 		     *     1 / PRECISION
 		     *
 		     * Each column contains two triangles of width one quantum and
-		     * total height of (x / WIDTH), thus the total area covered by all
-		     * columns in each pixel is .5 * (x / WIDTH).
+		     * total height of (x / width), thus the total area covered by all
+		     * columns in each pixel is .5 * (x / width).
 		     */
 
 		    cairo_move_to (cr, x + i / (double) PRECISION, y + dy);
@@ -413,9 +414,9 @@ row_triangles (cairo_t *cr, int width, int height)
     cairo_paint (cr);
 
 #if GENERATE_REFERENCE
-    for (x = 0; x < WIDTH; x++) {
-	cairo_set_source_rgba (cr, 1, 1, 1, x * 0.5 / WIDTH);
-	cairo_rectangle (cr, x, 0, 1, HEIGHT);
+    for (x = 0; x < width; x++) {
+	cairo_set_source_rgba (cr, 1, 1, 1, x * 0.5 / width);
+	cairo_rectangle (cr, x, 0, 1, height);
 	cairo_fill (cr);
     }
 #else
@@ -428,11 +429,11 @@ row_triangles (cairo_t *cr, int width, int height)
 	case 2: cairo_set_source_rgb (cr, 0.0, 0.0, 1.0); break;
 	}
 
-	for (x = 0; x < WIDTH; x++) {
-	    double step = x / (double) (2 * WIDTH);
-	    for (y = 0; y < HEIGHT; y++) {
+	for (x = 0; x < width; x++) {
+	    double step = x / (double) (2 * width);
+	    for (y = 0; y < height; y++) {
 		for (i = 0; i < PRECISION; i++) {
-		    double dx = random_offset (WIDTH - x, FALSE);
+		    double dx = random_offset (width - x, FALSE, width);
 
 		    /* See column_triangles() for a transposed description
 		     * of this geometry.


More information about the cairo-commit mailing list