[cairo-commit] 4 commits - src/cairo-analysis-surface.c src/cairo-clip.c src/cairo-glitz-surface.c src/cairo-paginated-surface.c src/cairo-surface.c test/get-path-extents.c test/.gitignore test/in-fill-trapezoid.c test/Makefile.am

Chris Wilson ickle at kemper.freedesktop.org
Thu Jan 17 03:54:53 PST 2008


 src/cairo-analysis-surface.c  |    5 ---
 src/cairo-clip.c              |    2 -
 src/cairo-glitz-surface.c     |   50 +++++++++++++++++--------------
 src/cairo-paginated-surface.c |    5 +--
 src/cairo-surface.c           |    7 +---
 test/.gitignore               |    1 
 test/Makefile.am              |    1 
 test/get-path-extents.c       |   35 ++++++++++++++++++++++
 test/in-fill-trapezoid.c      |   66 ++++++++++++++++++++++++++++++++++++++++++
 9 files changed, 136 insertions(+), 36 deletions(-)

New commits:
commit da9c43329ad09ccf48f8a71d28848f111af7ecb5
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Thu Jan 17 11:22:19 2008 +0000

    [test/in-fill-trapezoid] Add test to exercise _cairo_trap_contains().
    
    A simple test to provide coverage of _cairo_trap_contains(), though
    not yet seeking boundary conditions.

diff --git a/test/.gitignore b/test/.gitignore
index 2aaf613..0d4b86c 100644
--- a/test/.gitignore
+++ b/test/.gitignore
@@ -71,6 +71,7 @@ gradient-zero-stops
 imagediff
 infinite-join
 in-fill-empty-trapezoid
+in-fill-trapezoid
 invalid-matrix
 leaky-dash
 leaky-polygon
diff --git a/test/Makefile.am b/test/Makefile.am
index b110c8d..12d89ab 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -54,6 +54,7 @@ gradient-alpha$(EXEEXT)					\
 gradient-zero-stops$(EXEEXT)				\
 infinite-join$(EXEEXT)					\
 in-fill-empty-trapezoid$(EXEEXT)			\
+in-fill-trapezoid$(EXEEXT)			\
 invalid-matrix$(EXEEXT)					\
 leaky-dash$(EXEEXT)					\
 leaky-polygon$(EXEEXT)					\
diff --git a/test/in-fill-trapezoid.c b/test/in-fill-trapezoid.c
new file mode 100644
index 0000000..0e9f058
--- /dev/null
+++ b/test/in-fill-trapezoid.c
@@ -0,0 +1,66 @@
+/*
+ * Copyright © 2008 Chris Wilson
+ *
+ * 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 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.
+ *
+ * Author: Chris Wilson <chris at chris-wilson.co.uk>
+ */
+
+#include "cairo-test.h"
+
+static cairo_test_draw_function_t draw;
+
+cairo_test_t test = {
+    "in-fill-trapezoid",
+    "Test _cairo_trap_contains via cairo_in_fill",
+    0, 0,
+    draw
+};
+
+static cairo_test_status_t
+draw (cairo_t *cr, int width, int height)
+{
+    cairo_test_status_t ret = CAIRO_TEST_SUCCESS;
+
+    /* simple rectangle */
+    cairo_new_path (cr);
+    cairo_rectangle (cr, -10, -10, 20, 20);
+    if (! cairo_in_fill (cr, 0, 0)) {
+	cairo_test_log ("Error: Failed to find point inside rectangle\n");
+	ret = CAIRO_TEST_FAILURE;
+    }
+
+    /* simple circle */
+    cairo_new_path (cr);
+    cairo_arc (cr, 0, 0, 10, 0, 2 * M_PI);
+    if (! cairo_in_fill (cr, 0, 0)) {
+	cairo_test_log ("Error: Failed to find point inside circle\n");
+	ret = CAIRO_TEST_FAILURE;
+    }
+
+    return ret;
+}
+
+int
+main (void)
+{
+    return cairo_test (&test);
+}
commit f638e5ea355cf0268a4b099ce7b8b98c69df6b67
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Thu Jan 17 11:03:50 2008 +0000

    [cairo-region] Review status propagation.
    
    Check that the error status is propagated from _cairo_region_*.

diff --git a/src/cairo-clip.c b/src/cairo-clip.c
index 8d48b53..ae30515 100644
--- a/src/cairo-clip.c
+++ b/src/cairo-clip.c
@@ -721,7 +721,7 @@ _cairo_clip_copy_rectangle_list (cairo_clip_t *clip, cairo_gstate_t *gstate)
 	cairo_box_int_t *boxes;
         int i;
 
-	if (_cairo_region_get_boxes (&clip->region, &n_boxes, &boxes) != CAIRO_STATUS_SUCCESS)
+	if (_cairo_region_get_boxes (&clip->region, &n_boxes, &boxes))
 	    return (cairo_rectangle_list_t*) &_cairo_rectangles_nil;
 
 	if (n_boxes) {
diff --git a/src/cairo-glitz-surface.c b/src/cairo-glitz-surface.c
index 04084e1..5144895 100644
--- a/src/cairo-glitz-surface.c
+++ b/src/cairo-glitz-surface.c
@@ -146,36 +146,39 @@ _CAIRO_MASK_FORMAT (cairo_format_masks_t *masks, cairo_format_t *format)
     return FALSE;
 }
 
-static glitz_box_t *
-_cairo_glitz_get_boxes_from_region (cairo_region_t *region, int *nboxes)
+static cairo_status_t
+_cairo_glitz_get_boxes_from_region (cairo_region_t *region, glitz_box_t **boxes, int *nboxes)
 {
     cairo_box_int_t *cboxes;
-    glitz_box_t *gboxes;
+    cairo_status_t status;
     int n, i;
 
-    if (_cairo_region_get_boxes (region, &n, &cboxes) != CAIRO_STATUS_SUCCESS)
-        return NULL;
+    status = _cairo_region_get_boxes (region, &n, &cboxes);
+    if (status)
+	return status;
 
-    *nboxes = n;
-    if (n == 0)
-        return NULL;
+    if (n == 0) {
+	status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
+	goto done;
+    }
 
-    gboxes = _cairo_malloc_ab (n, sizeof(glitz_box_t));
-    if (gboxes == NULL) {
-	_cairo_error_throw (CAIRO_STATUS_NO_MEMORY);
-        goto done;
+    *boxes = _cairo_malloc_ab (n, sizeof(glitz_box_t));
+    if (*boxes == NULL) {
+	status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
+	goto done;
     }
 
     for (i = 0; i < n; i++) {
-        gboxes[i].x1 = cboxes[i].p1.x;
-        gboxes[i].y1 = cboxes[i].p1.y;
-        gboxes[i].x2 = cboxes[i].p2.x;
-        gboxes[i].y2 = cboxes[i].p2.y;
+        (*boxes)[i].x1 = cboxes[i].p1.x;
+        (*boxes)[i].y1 = cboxes[i].p1.y;
+        (*boxes)[i].x2 = cboxes[i].p2.x;
+        (*boxes)[i].y2 = cboxes[i].p2.y;
     }
 
+    *nboxes = n;
 done:
     _cairo_region_boxes_fini (region, cboxes);
-    return gboxes;
+    return status;
 }
 
 static cairo_status_t
@@ -292,12 +295,13 @@ _cairo_glitz_surface_get_image (cairo_glitz_surface_t   *surface,
     /* restore the clip, if any */
     if (surface->has_clip) {
 	glitz_box_t *box;
+	cairo_status_t status;
         int n;
 
-        box = _cairo_glitz_get_boxes_from_region (&surface->clip, &n);
-        if (box == NULL && n != 0) {
+        status = _cairo_glitz_get_boxes_from_region (&surface->clip, &box, &n);
+        if (status) {
             free (pixels);
-            return _cairo_error (CAIRO_STATUS_NO_MEMORY);
+            return status;
         }
 
 	glitz_surface_set_clip_region (surface->surface, 0, 0, box, n);
@@ -1463,11 +1467,11 @@ _cairo_glitz_surface_set_clip_region (void		*abstract_surface,
             return status;
         }
 
-        box = _cairo_glitz_get_boxes_from_region (&surface->clip, &n);
-        if (box == NULL && n != 0) {
+	status = _cairo_glitz_get_boxes_from_region (&surface->clip, &box, &n);
+	if (status) {
             _cairo_region_fini (&surface->clip);
 	    surface->has_clip = FALSE;
-            return _cairo_error (CAIRO_STATUS_NO_MEMORY);
+            return status;
         }
 
 	glitz_surface_set_clip_region (surface->surface, 0, 0, box, n);
diff --git a/src/cairo-surface.c b/src/cairo-surface.c
index 8860c95..010195f 100644
--- a/src/cairo-surface.c
+++ b/src/cairo-surface.c
@@ -2189,12 +2189,9 @@ _cairo_surface_composite_fixup_unbounded_internal (cairo_surface_t         *dst,
     has_drawn_region = TRUE;
     has_clear_region = TRUE;
 
-    if (_cairo_region_subtract (&clear_region, &clear_region, &drawn_region)
-	!= CAIRO_STATUS_SUCCESS)
-    {
-        status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
+    status = _cairo_region_subtract (&clear_region, &clear_region, &drawn_region);
+    if (status)
         goto CLEANUP_REGIONS;
-    }
 
     status = _cairo_surface_fill_region (dst, CAIRO_OPERATOR_SOURCE,
                                          CAIRO_COLOR_TRANSPARENT,
commit 248f0060e5317f53a688ea0e0aea2997824fa996
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Thu Jan 17 10:10:55 2008 +0000

    [cairo-analysis-surface] Return the nil surface rather than NULL.
    
    On error return a nil surface that represents the error rather than
    making the assumption of a NO_MEMORY error in the caller.

diff --git a/src/cairo-analysis-surface.c b/src/cairo-analysis-surface.c
index 357e79a..509b5f2 100644
--- a/src/cairo-analysis-surface.c
+++ b/src/cairo-analysis-surface.c
@@ -597,7 +597,7 @@ _cairo_analysis_surface_create (cairo_surface_t		*target,
 
     surface = malloc (sizeof (cairo_analysis_surface_t));
     if (surface == NULL)
-	goto FAIL;
+	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
 
     /* I believe the content type here is truly arbitrary. I'm quite
      * sure nothing will ever use this value. */
@@ -622,9 +622,6 @@ _cairo_analysis_surface_create (cairo_surface_t		*target,
     surface->current_clip.height = height;
 
     return &surface->base;
-FAIL:
-    _cairo_error_throw (CAIRO_STATUS_NO_MEMORY);
-    return NULL;
 }
 
 cairo_region_t *
diff --git a/src/cairo-paginated-surface.c b/src/cairo-paginated-surface.c
index 98ec061..49d488c 100644
--- a/src/cairo-paginated-surface.c
+++ b/src/cairo-paginated-surface.c
@@ -294,9 +294,8 @@ _paint_page (cairo_paginated_surface_t *surface)
 
     analysis = _cairo_analysis_surface_create (surface->target,
 					       surface->width, surface->height);
-    if (analysis == NULL)
-	return _cairo_surface_set_error (surface->target,
-		                         CAIRO_STATUS_NO_MEMORY);
+    if (analysis->status)
+	return _cairo_surface_set_error (surface->target, analysis->status);
 
     surface->backend->set_paginated_mode (surface->target, CAIRO_PAGINATED_MODE_ANALYZE);
     status = _cairo_meta_surface_replay_and_create_regions (surface->meta, analysis);
commit dd13a00541ebd85bb7687add8b76fa3fb1d82b95
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Thu Jan 17 10:09:22 2008 +0000

    [test/get-path-extents] Check extents of degenerate paths.
    
    Ensure that degenerate paths have zero extents.

diff --git a/test/get-path-extents.c b/test/get-path-extents.c
index 917039e..ba2b116 100644
--- a/test/get-path-extents.c
+++ b/test/get-path-extents.c
@@ -121,6 +121,41 @@ draw (cairo_t *cr, int width, int height)
         !check_extents (phase, cr2, STROKE, EQUALS, 0, 0, 0, 0))
 	ret = CAIRO_TEST_FAILURE;
 
+    cairo_save (cr2);
+
+    cairo_new_path (cr2);
+    cairo_move_to (cr2, 200, 400);
+    cairo_rel_line_to (cr2, 0., 0.);
+    phase = "Degenerate line";
+    if (!check_extents (phase, cr2, FILL, EQUALS, 0, 0, 0, 0) ||
+        !check_extents (phase, cr2, STROKE, EQUALS, 0, 0, 0, 0))
+	ret = CAIRO_TEST_FAILURE;
+
+    cairo_new_path (cr2);
+    cairo_move_to (cr2, 200, 400);
+    cairo_rel_curve_to (cr2, 0., 0., 0., 0., 0., 0.);
+    phase = "Degenerate curve";
+    if (!check_extents (phase, cr2, FILL, EQUALS, 0, 0, 0, 0) ||
+        !check_extents (phase, cr2, STROKE, EQUALS, 0, 0, 0, 0))
+	ret = CAIRO_TEST_FAILURE;
+
+    cairo_new_path (cr2);
+    cairo_arc (cr2, 200, 400, 0., 0, 2 * M_PI);
+    phase = "Degenerate arc (R=0)";
+    if (!check_extents (phase, cr2, FILL, EQUALS, 0, 0, 0, 0) ||
+        !check_extents (phase, cr2, STROKE, EQUALS, 0, 0, 0, 0))
+	ret = CAIRO_TEST_FAILURE;
+
+    cairo_new_path (cr2);
+    cairo_arc (cr2, 200, 400, 10., 0, 0);
+    phase = "Degenerate arc (Θ=0)";
+    if (!check_extents (phase, cr2, FILL, EQUALS, 0, 0, 0, 0) ||
+        !check_extents (phase, cr2, STROKE, EQUALS, 0, 0, 0, 0))
+	ret = CAIRO_TEST_FAILURE;
+
+    cairo_new_path (cr2);
+    cairo_restore (cr2);
+
     /* http://bugs.freedesktop.org/show_bug.cgi?id=7965 */
     phase = "A vertical, open path";
     cairo_save (cr2);


More information about the cairo-commit mailing list