[cairo-commit] 2 commits - perf/cairo-perf.c perf/cairo-perf.h perf/Makefile.am perf/rectangles.c perf/rounded-rectangles.c test/fallback-resolution.c test/fallback-resolution-ppi150-ref.png test/fallback-resolution-ppi300-ref.png test/fallback-resolution-ppi37.5-ref.png test/fallback-resolution-ppi600-ref.png test/fallback-resolution-ppi72-ref.png test/fallback-resolution-ppi75-ref.png

Chris Wilson ickle at kemper.freedesktop.org
Sun Sep 28 13:08:55 PDT 2008


 perf/Makefile.am                         |    1 
 perf/cairo-perf.c                        |    1 
 perf/cairo-perf.h                        |    1 
 perf/rectangles.c                        |   22 +++++-
 perf/rounded-rectangles.c                |  111 +++++++++++++++++++++++++++++++
 test/fallback-resolution-ppi150-ref.png  |binary
 test/fallback-resolution-ppi300-ref.png  |binary
 test/fallback-resolution-ppi37.5-ref.png |binary
 test/fallback-resolution-ppi600-ref.png  |binary
 test/fallback-resolution-ppi72-ref.png   |binary
 test/fallback-resolution-ppi75-ref.png   |binary
 test/fallback-resolution.c               |   40 ++++++++++-
 12 files changed, 173 insertions(+), 3 deletions(-)

New commits:
commit 4f449107afba8ca96cd16e8dec283db124105dc8
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Sun Sep 28 21:05:36 2008 +0100

    [test/fallback-resolution] Exercise a couple of outstanding bugs.
    
    Use dashes to exercise bugs:
      https://bugs.freedesktop.org/show_bug.cgi?id=9189
      https://bugs.freedesktop.org/show_bug.cgi?id=17223
    Note bug 17223 indicates that this is still relevant for win32 printing
    where fallbacks are used if the dash offset is non-zero.
    
    And use a pattern to exercise the (fixed) regression:
      https://bugs.launchpad.net/inkscape/+bug/234546

diff --git a/test/fallback-resolution-ppi150-ref.png b/test/fallback-resolution-ppi150-ref.png
index 4d3723e..8a69481 100644
Binary files a/test/fallback-resolution-ppi150-ref.png and b/test/fallback-resolution-ppi150-ref.png differ
diff --git a/test/fallback-resolution-ppi300-ref.png b/test/fallback-resolution-ppi300-ref.png
index 54de6cc..66ed3eb 100644
Binary files a/test/fallback-resolution-ppi300-ref.png and b/test/fallback-resolution-ppi300-ref.png differ
diff --git a/test/fallback-resolution-ppi37.5-ref.png b/test/fallback-resolution-ppi37.5-ref.png
index 3b0cc16..fe87bc1 100644
Binary files a/test/fallback-resolution-ppi37.5-ref.png and b/test/fallback-resolution-ppi37.5-ref.png differ
diff --git a/test/fallback-resolution-ppi600-ref.png b/test/fallback-resolution-ppi600-ref.png
index 291a453..c5694a3 100644
Binary files a/test/fallback-resolution-ppi600-ref.png and b/test/fallback-resolution-ppi600-ref.png differ
diff --git a/test/fallback-resolution-ppi72-ref.png b/test/fallback-resolution-ppi72-ref.png
index 5d72f87..b9b3803 100644
Binary files a/test/fallback-resolution-ppi72-ref.png and b/test/fallback-resolution-ppi72-ref.png differ
diff --git a/test/fallback-resolution-ppi75-ref.png b/test/fallback-resolution-ppi75-ref.png
index 7d68781..03aa6c2 100644
Binary files a/test/fallback-resolution-ppi75-ref.png and b/test/fallback-resolution-ppi75-ref.png differ
diff --git a/test/fallback-resolution.c b/test/fallback-resolution.c
index 6f814a8..4e78577 100644
--- a/test/fallback-resolution.c
+++ b/test/fallback-resolution.c
@@ -53,7 +53,7 @@
  */
 
 #define INCHES_TO_POINTS(in) ((in) * 72.0)
-#define SIZE INCHES_TO_POINTS(1)
+#define SIZE INCHES_TO_POINTS(2)
 
 /* cairo_set_tolerance() is not respected by the PS/PDF backends currently */
 #define SET_TOLERANCE 0
@@ -65,21 +65,57 @@ draw (cairo_t *cr, double width, double height)
 {
     const char *text = "cairo";
     cairo_text_extents_t extents;
+    const double dash[2] = { 8, 16 };
+    cairo_pattern_t *pattern;
 
     cairo_save (cr);
 
     cairo_new_path (cr);
 
     cairo_set_line_width (cr, .05 * SIZE / 2.0);
+
+    cairo_arc (cr, SIZE / 2.0, SIZE / 2.0,
+	       0.875 * SIZE / 2.0,
+	       0, 2.0 * M_PI);
+    cairo_stroke (cr);
+
+    /* use dashes to demonstrate bugs:
+     *  https://bugs.freedesktop.org/show_bug.cgi?id=9189
+     *  https://bugs.freedesktop.org/show_bug.cgi?id=17223
+     */
+    cairo_save (cr);
+    cairo_set_dash (cr, dash, 2, 0);
     cairo_arc (cr, SIZE / 2.0, SIZE / 2.0,
 	       0.75 * SIZE / 2.0,
 	       0, 2.0 * M_PI);
     cairo_stroke (cr);
+    cairo_restore (cr);
 
+    cairo_save (cr);
+    cairo_rectangle (cr, 0, 0, SIZE/2, SIZE);
+    cairo_clip (cr);
     cairo_arc (cr, SIZE / 2.0, SIZE / 2.0,
 	       0.6 * SIZE / 2.0,
 	       0, 2.0 * M_PI);
     cairo_fill (cr);
+    cairo_restore (cr);
+
+    /* use a pattern to exercise bug:
+     *   https://bugs.launchpad.net/inkscape/+bug/234546
+     */
+    cairo_save (cr);
+    cairo_rectangle (cr, SIZE/2, 0, SIZE/2, SIZE);
+    cairo_clip (cr);
+    pattern = cairo_pattern_create_linear (SIZE/2, 0, SIZE, 0);
+    cairo_pattern_add_color_stop_rgba (pattern, 0, 0, 0, 0, 1.);
+    cairo_pattern_add_color_stop_rgba (pattern, 1, 0, 0, 0, 0.);
+    cairo_set_source (cr, pattern);
+    cairo_pattern_destroy (pattern);
+    cairo_arc (cr, SIZE / 2.0, SIZE / 2.0,
+	       0.6 * SIZE / 2.0,
+	       0, 2.0 * M_PI);
+    cairo_fill (cr);
+    cairo_restore (cr);
 
     cairo_set_source_rgb (cr, 1, 1, 1); /* white */
     cairo_set_font_size (cr, .25 * SIZE / 2.0);
@@ -193,7 +229,7 @@ check_result (cairo_test_context_t *ctx,
     if (status) {
 	cairo_test_log (ctx, "Error: Failed to compare images: %s\n",
 			cairo_status_to_string (status));
-	ret = TRUE;
+	ret = FALSE;
     } else if (result.pixels_changed &&
 	       result.max_diff > target->error_tolerance)
     {
commit 0a7d781ab020171e70bd1dc66ff1556106e5be3f
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Sun Sep 28 18:57:15 2008 +0100

    [perf] Add rounded rectangle perf case.
    
    Add the performance test case to compare the speed of filling a rounded
    rectangle (one with camphered corners) as opposed to an ordinary
    rectangle. Since the majority of the pixels are identical, ideally the two
    cases would take similar times (modulo the additional overhead in the more
    complex path).

diff --git a/perf/Makefile.am b/perf/Makefile.am
index 0f48fb2..46f053d 100644
--- a/perf/Makefile.am
+++ b/perf/Makefile.am
@@ -25,6 +25,7 @@ cairo_perf_SOURCES =		\
 	paint-with-alpha.c	\
 	pattern_create_radial.c \
 	rectangles.c		\
+	rounded-rectangles.c	\
 	stroke.c		\
 	subimage_copy.c		\
 	tessellate.c		\
diff --git a/perf/cairo-perf.c b/perf/cairo-perf.c
index 38c7119..0a1e370 100644
--- a/perf/cairo-perf.c
+++ b/perf/cairo-perf.c
@@ -454,6 +454,7 @@ const cairo_perf_case_t perf_cases[] = {
     { long_lines, 100, 100},
     { unaligned_clip, 100, 100},
     { rectangles, 512, 512},
+    { rounded_rectangles, 512, 512},
     { long_dashed_lines, 512, 512},
     { NULL }
 };
diff --git a/perf/cairo-perf.h b/perf/cairo-perf.h
index 753f045..222251d 100644
--- a/perf/cairo-perf.h
+++ b/perf/cairo-perf.h
@@ -110,6 +110,7 @@ CAIRO_PERF_DECL (mosaic);
 CAIRO_PERF_DECL (long_lines);
 CAIRO_PERF_DECL (unaligned_clip);
 CAIRO_PERF_DECL (rectangles);
+CAIRO_PERF_DECL (rounded_rectangles);
 CAIRO_PERF_DECL (long_dashed_lines);
 
 #endif
diff --git a/perf/rectangles.c b/perf/rectangles.c
index 9fa89f5..991391c 100644
--- a/perf/rectangles.c
+++ b/perf/rectangles.c
@@ -24,6 +24,12 @@
  */
 #include "cairo-perf.h"
 
+#if 0
+#define MODE cairo_perf_run
+#else
+#define MODE cairo_perf_cover_sources_and_operators
+#endif
+
 #define RECTANGLE_COUNT (1000)
 
 static struct
@@ -53,6 +59,19 @@ do_rectangles (cairo_t *cr, int width, int height)
     return cairo_perf_timer_elapsed ();
 }
 
+static cairo_perf_ticks_t
+do_rectangle (cairo_t *cr, int width, int height)
+{
+    cairo_perf_timer_start ();
+
+    cairo_rectangle (cr, 0, 0, width, height);
+    cairo_fill (cr);
+
+    cairo_perf_timer_stop ();
+
+    return cairo_perf_timer_elapsed ();
+}
+
 void
 rectangles (cairo_perf_t *perf, cairo_t *cr, int width, int height)
 {
@@ -67,5 +86,6 @@ rectangles (cairo_perf_t *perf, cairo_t *cr, int width, int height)
         rects[i].height = (rand () % (height / 10)) + 1;
     }
 
-    cairo_perf_run (perf, "rectangles", do_rectangles);
+    MODE (perf, "one-rectangle", do_rectangle);
+    MODE (perf, "rectangles", do_rectangles);
 }
diff --git a/perf/rounded-rectangles.c b/perf/rounded-rectangles.c
new file mode 100644
index 0000000..7d20825
--- /dev/null
+++ b/perf/rounded-rectangles.c
@@ -0,0 +1,111 @@
+/*
+ * Copyright © 2005 Owen Taylor
+ * Copyright © 2007 Dan Amelang
+ * Copyright © 2007 Chris Wilson
+ *
+ * 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
+ * the authors not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior
+ * permission. The authors make no representations about the
+ * suitability of this software for any purpose.  It is provided "as
+ * is" without express or implied warranty.
+ *
+ * THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL THE AUTHORS 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.
+ *
+ * Authors: Chris Wilson <chris at chris-wilson.co.uk>
+ */
+
+/* This perf case is derived from the bug report
+ *   Gradient on 'rounded rectangle' MUCH slower than normal rectangle
+ *   https://bugs.freedesktop.org/show_bug.cgi?id=4263.
+ */
+
+#include "cairo-perf.h"
+
+#define RECTANGLE_COUNT (1000)
+
+#if 0
+#define MODE cairo_perf_run
+#else
+#define MODE cairo_perf_cover_sources_and_operators
+#endif
+
+static struct
+{
+    double x;
+    double y;
+    double width;
+    double height;
+} rects[RECTANGLE_COUNT];
+
+static void
+rounded_rectangle (cairo_t *cr,
+		   double x, double y, double w, double h,
+		   double radius)
+{
+    cairo_move_to (cr, x+radius, y);
+    cairo_arc (cr, x+w-radius, y+radius,   radius, M_PI + M_PI / 2, M_PI * 2        );
+    cairo_arc (cr, x+w-radius, y+h-radius, radius, 0,               M_PI / 2        );
+    cairo_arc (cr, x+radius,   y+h-radius, radius, M_PI/2,          M_PI            );
+    cairo_arc (cr, x+radius,   y+radius,   radius, M_PI,            270 * M_PI / 180);
+}
+
+static cairo_perf_ticks_t
+do_rectangle (cairo_t *cr, int width, int height)
+{
+    cairo_perf_timer_start ();
+
+    rounded_rectangle (cr, 0, 0, width, height, 3.0);
+    cairo_fill (cr);
+
+    cairo_perf_timer_stop ();
+
+    return cairo_perf_timer_elapsed ();
+}
+
+static cairo_perf_ticks_t
+do_rectangles (cairo_t *cr, int width, int height)
+{
+    int i;
+
+    cairo_perf_timer_start ();
+
+    for (i = 0; i < RECTANGLE_COUNT; i++) {
+        rounded_rectangle (cr,
+		           rects[i].x, rects[i].y,
+                           rects[i].width, rects[i].height,
+			   3.0);
+        cairo_fill (cr);
+    }
+
+    cairo_perf_timer_stop ();
+
+    return cairo_perf_timer_elapsed ();
+}
+
+void
+rounded_rectangles (cairo_perf_t *perf, cairo_t *cr, int width, int height)
+{
+    int i;
+
+    srand (8478232);
+    for (i = 0; i < RECTANGLE_COUNT; i++) {
+        rects[i].x = rand () % width;
+        rects[i].y = rand () % height;
+        rects[i].width  = (rand () % (width / 10)) + 1;
+        rects[i].height = (rand () % (height / 10)) + 1;
+    }
+
+    MODE (perf, "one-rounded-rectangle", do_rectangle);
+    MODE (perf, "rounded-rectangles", do_rectangles);
+}


More information about the cairo-commit mailing list