[cairo-commit] 2 commits - src/cairo-ps-surface.c test/linear-gradient-subset.c test/linear-gradient-subset.ref.png test/Makefile.am test/Makefile.sources

Chris Wilson ickle at kemper.freedesktop.org
Sun Feb 7 11:40:10 PST 2010


 src/cairo-ps-surface.c              |   36 +---------
 test/Makefile.am                    |    1 
 test/Makefile.sources               |    1 
 test/linear-gradient-subset.c       |  127 ++++++++++++++++++++++++++++++++++++
 test/linear-gradient-subset.ref.png |binary
 5 files changed, 133 insertions(+), 32 deletions(-)

New commits:
commit 44b6370cb04d27e1ae3e50558a9085d318990938
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Sun Feb 7 19:36:29 2010 +0000

    ps: Propagate NOTHING_TO_DO
    
    The upper layers should know what to do if there is nothing to be done,
    so pass on that knowledge.

diff --git a/src/cairo-ps-surface.c b/src/cairo-ps-surface.c
index bbe44af..5fa4fd7 100644
--- a/src/cairo-ps-surface.c
+++ b/src/cairo-ps-surface.c
@@ -3420,12 +3420,8 @@ _cairo_ps_surface_paint (void			*abstract_surface,
     status = _cairo_composite_rectangles_init_for_paint (&extents,
 							 surface->width, surface->height,
 							 op, source, clip);
-    if (unlikely (status)) {
-	if (status == CAIRO_INT_STATUS_NOTHING_TO_DO)
-	    return CAIRO_STATUS_SUCCESS;
-
+    if (unlikely (status))
 	return status;
-    }
 
     if (! _cairo_rectangle_intersect (&extents.bounded, &surface->page_bbox))
 	return CAIRO_STATUS_SUCCESS;
@@ -3462,9 +3458,6 @@ _cairo_ps_surface_paint (void			*abstract_surface,
 	_cairo_output_stream_printf (stream, "Q\n");
     } else {
 	status = _cairo_ps_surface_emit_pattern (surface, source, &extents.bounded, op);
-	if (status == CAIRO_INT_STATUS_NOTHING_TO_DO)
-	    return CAIRO_STATUS_SUCCESS;
-
 	if (unlikely (status))
 	    return status;
 
@@ -3498,12 +3491,8 @@ _cairo_ps_surface_stroke (void			*abstract_surface,
 							  op, source,
 							  path, style, ctm,
 							  clip);
-    if (unlikely (status)) {
-	if (status == CAIRO_INT_STATUS_NOTHING_TO_DO)
-	    return CAIRO_STATUS_SUCCESS;
-
+    if (unlikely (status))
 	return status;
-    }
 
     if (! _cairo_rectangle_intersect (&extents.bounded, &surface->page_bbox))
 	return CAIRO_STATUS_SUCCESS;
@@ -3537,9 +3526,6 @@ _cairo_ps_surface_stroke (void			*abstract_surface,
 	return status;
 
     status = _cairo_ps_surface_emit_pattern (surface, source, &extents.bounded, op);
-    if (status == CAIRO_INT_STATUS_NOTHING_TO_DO)
-        return CAIRO_STATUS_SUCCESS;
-
     if (unlikely (status))
 	return status;
 
@@ -3569,12 +3555,8 @@ _cairo_ps_surface_fill (void		*abstract_surface,
 							surface->height,
 							op, source, path,
 							clip);
-    if (unlikely (status)) {
-	if (status == CAIRO_INT_STATUS_NOTHING_TO_DO)
-	    return CAIRO_STATUS_SUCCESS;
-
+    if (unlikely (status))
 	return status;
-    }
 
     if (! _cairo_rectangle_intersect (&extents.bounded, &surface->page_bbox))
 	return CAIRO_STATUS_SUCCESS;
@@ -3630,9 +3612,6 @@ _cairo_ps_surface_fill (void		*abstract_surface,
 	_cairo_pdf_operators_reset (&surface->pdf_operators);
     } else {
 	status = _cairo_ps_surface_emit_pattern (surface, source, &extents.bounded, op);
-	if (status == CAIRO_INT_STATUS_NOTHING_TO_DO)
-	    return CAIRO_STATUS_SUCCESS;
-
 	if (unlikely (status))
 	    return status;
 
@@ -3667,12 +3646,8 @@ _cairo_ps_surface_show_glyphs (void		     *abstract_surface,
 							  glyphs, num_glyphs,
 							  clip,
 							  &overlap);
-    if (unlikely (status)) {
-	if (status == CAIRO_INT_STATUS_NOTHING_TO_DO)
-	    return CAIRO_STATUS_SUCCESS;
-
+    if (unlikely (status))
 	return status;
-    }
 
     if (surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE)
 	return _cairo_ps_surface_analyze_operation (surface, op, source, &extents.bounded);
@@ -3689,9 +3664,6 @@ _cairo_ps_surface_show_glyphs (void		     *abstract_surface,
 	return status;
 
     status = _cairo_ps_surface_emit_pattern (surface, source, &extents.bounded, op);
-    if (status == CAIRO_INT_STATUS_NOTHING_TO_DO)
-        return CAIRO_STATUS_SUCCESS;
-
     if (unlikely (status))
 	return status;
 
commit a4793d1331845b85a9c1810035119dfbcffa5082
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Sun Feb 7 19:27:32 2010 +0000

    test: Add linear-gradient-subset
    
    It was observed that we never actually test the condition that the
    gradient is only defined for a portion of its range, i.e. the starting
    offset is >0 and the ending offset is <0. By definition the colour
    between 0 and start offset is the start color, so check that this
    behaviour is followed by all backends.

diff --git a/test/Makefile.am b/test/Makefile.am
index 1ac79fa..10e322a 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -602,6 +602,7 @@ REFERENCE_IMAGES = \
 	linear-gradient.quartz.ref.png \
 	linear-gradient.ref.png \
 	linear-gradient.xlib.ref.png \
+	linear-gradient-subset.ref.png \
 	linear-step-function.xfail.png \
 	linear-uniform.ref.png \
 	long-dashed-lines.ps2.ref.png \
diff --git a/test/Makefile.sources b/test/Makefile.sources
index f0f90a9..a8aa0e9 100644
--- a/test/Makefile.sources
+++ b/test/Makefile.sources
@@ -128,6 +128,7 @@ test_sources = \
 	line-width-zero.c				\
 	linear-gradient.c				\
 	linear-gradient-reflect.c			\
+	linear-gradient-subset.c			\
 	linear-step-function.c				\
 	linear-uniform.c				\
 	long-dashed-lines.c				\
diff --git a/test/linear-gradient-subset.c b/test/linear-gradient-subset.c
new file mode 100644
index 0000000..ce05e6e
--- /dev/null
+++ b/test/linear-gradient-subset.c
@@ -0,0 +1,127 @@
+/*
+ * Copyright © 2005 Red Hat, Inc.
+ *
+ * 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
+ * Red Hat, Inc. not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior
+ * permission. Red Hat, Inc. makes no representations about the
+ * suitability of this software for any purpose.  It is provided "as
+ * is" without express or implied warranty.
+ *
+ * RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL RED HAT, INC. 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.
+ *
+ * Author: Owen Taylor <otaylor at redhat.com>
+ */
+
+#include "cairo-test.h"
+#include "stdio.h"
+
+/* The test matrix is
+ *
+ * A) Horizontal   B) 5°          C) 45°          D) Vertical
+ * 1) Rotated 0°   2) Rotated 45° C) Rotated 90°
+ * a) 2 stop       b) 3 stop
+ *
+ *  A1a   B1a  C1a  D1a
+ *  A2a   B2a  C2a  D2a
+ *  A3a   B3a  C3a  D3a
+ *  A1b   B1b  C1b  D1b
+ *  A2b   B2b  C2b  D2b
+ *  A3b   B3b  C3b  D3b
+ */
+
+static const double gradient_angles[] = { 0, 45, 90 };
+#define N_GRADIENT_ANGLES 3
+static const double rotate_angles[] = { 0, 45, 90 };
+#define N_ROTATE_ANGLES 3
+static const int n_stops[] = { 2, 3 };
+#define N_N_STOPS 2
+
+#define UNIT_SIZE 6
+#define UNIT_SIZE 6
+#define PAD 1
+
+#define WIDTH  N_GRADIENT_ANGLES * UNIT_SIZE + (N_GRADIENT_ANGLES + 1) * PAD
+#define HEIGHT N_N_STOPS * N_ROTATE_ANGLES * UNIT_SIZE + (N_N_STOPS * N_ROTATE_ANGLES + 1) * PAD
+
+static void
+draw_unit (cairo_t *cr,
+	   double   gradient_angle,
+	   double   rotate_angle,
+	   int      n_stops)
+{
+    cairo_pattern_t *pattern;
+
+    cairo_rectangle (cr, 0, 0, 1, 1);
+    cairo_clip (cr);
+    cairo_new_path(cr);
+
+    cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
+    cairo_rectangle (cr, 0, 0, 1, 1);
+    cairo_fill (cr);
+
+    cairo_translate (cr, 0.5, 0.5);
+    cairo_scale (cr, 1 / 1.5, 1 / 1.5);
+    cairo_rotate (cr, rotate_angle);
+
+    pattern = cairo_pattern_create_linear (-0.5 * cos (gradient_angle),  -0.5 * sin (gradient_angle),
+					    0.5 * cos (gradient_angle),   0.5 * sin (gradient_angle));
+
+    if (n_stops == 2) {
+	cairo_pattern_add_color_stop_rgb (pattern, 0.2, 0.3, 0.3, 0.3);
+	cairo_pattern_add_color_stop_rgb (pattern, 0.8, 1.0, 1.0, 1.0);
+    } else {
+	cairo_pattern_add_color_stop_rgb (pattern, 0.2, 1.0, 0.0, 0.0);
+	cairo_pattern_add_color_stop_rgb (pattern, 0.5, 1.0, 1.0, 1.0);
+	cairo_pattern_add_color_stop_rgb (pattern, 0.8, 0.0, 0.0, 1.0);
+    }
+
+    cairo_set_source (cr, pattern);
+    cairo_pattern_destroy (pattern);
+    cairo_rectangle (cr, -0.5, -0.5, 1, 1);
+    cairo_fill (cr);
+}
+
+static cairo_test_status_t
+draw (cairo_t *cr, int width, int height)
+{
+    int i, j, k;
+
+    cairo_set_source_rgb (cr, 0.5, 0.5, 0.5);
+    cairo_paint (cr);
+
+    for (i = 0; i < N_GRADIENT_ANGLES; i++)
+	for (j = 0; j < N_ROTATE_ANGLES; j++)
+	  for (k = 0; k < N_N_STOPS; k++) {
+		cairo_save (cr);
+		cairo_translate (cr,
+				 PAD + (PAD + UNIT_SIZE) * i,
+				 PAD + (PAD + UNIT_SIZE) * (N_ROTATE_ANGLES * k + j));
+		cairo_scale (cr, UNIT_SIZE, UNIT_SIZE);
+
+		draw_unit (cr,
+			   gradient_angles[i] * M_PI / 180.,
+			   rotate_angles[j] * M_PI / 180.,
+			   n_stops[k]);
+		cairo_restore (cr);
+	    }
+
+    return CAIRO_TEST_SUCCESS;
+}
+
+CAIRO_TEST (linear_gradient_subset,
+	    "Tests the drawing of linear gradients",
+	    "gradient", /* keywords */
+	    NULL, /* requirements */
+	    WIDTH, HEIGHT,
+	    NULL, draw)
diff --git a/test/linear-gradient-subset.ref.png b/test/linear-gradient-subset.ref.png
new file mode 100644
index 0000000..e7fd923
Binary files /dev/null and b/test/linear-gradient-subset.ref.png differ


More information about the cairo-commit mailing list