[cairo-commit] 5 commits - src/cairo.c src/cairo-gstate.c src/cairoint.h src/cairo-path.c test/nil-surface.c

Behdad Esfahbod behdad at kemper.freedesktop.org
Wed Mar 21 12:45:05 PDT 2007


 src/cairo-gstate.c |   18 ++++++++++++++++++
 src/cairo-path.c   |    7 ++++---
 src/cairo.c        |   32 +++++++++++++++++---------------
 src/cairoint.h     |    3 +++
 test/nil-surface.c |   25 +++++++++++++++++++++++++
 5 files changed, 67 insertions(+), 18 deletions(-)

New commits:
diff-tree 820341b4c503fbd5ca3b8f6c3e5ff6eca5562b98 (from ef8515b4a6b468e589639e794a959cb37d592359)
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Wed Mar 21 15:44:18 2007 -0400

    [test/nil-surface] Test that cairo_get_target() returns non-NULL

diff --git a/test/nil-surface.c b/test/nil-surface.c
index 9f10d0e..bbabfd9 100644
--- a/test/nil-surface.c
+++ b/test/nil-surface.c
@@ -148,6 +148,12 @@ draw (cairo_t *cr, int width, int height
 	return CAIRO_TEST_FAILURE;
     }
 
+    /* Test that get_target returns something valid */
+    if (cairo_get_target (cr2) == NULL) {
+	cairo_test_log ("Error: cairo_get_target() returned NULL\n");
+	return CAIRO_TEST_FAILURE;
+    }
+
     /* Test that push_group doesn't crash */
     cairo_push_group (cr2);
     cairo_stroke (cr2);
diff-tree ef8515b4a6b468e589639e794a959cb37d592359 (from 52341f7e855c93fc8e58895c3a318c43c3d58474)
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Wed Mar 21 15:29:18 2007 -0400

    cairo_push/pop_group(), bail out if cairo_t is in error status
    
    Fixes the new test added to test/nil-surface to not crash

diff --git a/src/cairo.c b/src/cairo.c
index 6fafae3..22e15fd 100644
--- a/src/cairo.c
+++ b/src/cairo.c
@@ -478,6 +478,9 @@ cairo_push_group_with_content (cairo_t *
     cairo_rectangle_int16_t extents;
     cairo_surface_t *parent_surface, *group_surface = NULL;
 
+    if (cr->status)
+	return;
+
     parent_surface = _cairo_gstate_get_target (cr->gstate);
     /* Get the extents that we'll use in creating our new group surface */
     _cairo_surface_get_extents (parent_surface, &extents);
@@ -544,6 +547,9 @@ cairo_pop_group (cairo_t *cr)
     cairo_pattern_t *group_pattern = NULL;
     cairo_matrix_t group_matrix;
 
+    if (cr->status)
+	return (cairo_pattern_t*) &cairo_pattern_nil.base;
+
     /* Grab the active surfaces */
     group_surface = _cairo_gstate_get_target (cr->gstate);
     parent_target = _cairo_gstate_get_parent_target (cr->gstate);
@@ -612,9 +618,6 @@ cairo_pop_group_to_source (cairo_t *cr)
     cairo_pattern_t *group_pattern;
 
     group_pattern = cairo_pop_group (cr);
-    if (!group_pattern)
-        return;
-
     cairo_set_source (cr, group_pattern);
     cairo_pattern_destroy (group_pattern);
 }
diff-tree 52341f7e855c93fc8e58895c3a318c43c3d58474 (from 9cea8a4bb26f7de2ac56e318c72e7d048b8b6c0f)
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Wed Mar 21 15:21:05 2007 -0400

    [test/nil-surface] Test cairo_create(NULL).  Crashing in cairo_push_group!

diff --git a/test/nil-surface.c b/test/nil-surface.c
index c672e64..9f10d0e 100644
--- a/test/nil-surface.c
+++ b/test/nil-surface.c
@@ -136,6 +136,25 @@ draw (cairo_t *cr, int width, int height
 
     cairo_destroy (cr2);
 
+    /*
+     * 5. Create a cairo_t for the NULL surface.
+     */
+    cr2 = cairo_create (NULL);
+
+    if (cairo_status (cr2) != CAIRO_STATUS_NULL_POINTER) {
+	cairo_test_log ("Error: Received status of \"%s\" rather than expected \"%s\"\n",
+			cairo_status_to_string (cairo_status (cr2)),
+			cairo_status_to_string (CAIRO_STATUS_NULL_POINTER));
+	return CAIRO_TEST_FAILURE;
+    }
+
+    /* Test that push_group doesn't crash */
+    cairo_push_group (cr2);
+    cairo_stroke (cr2);
+    cairo_pop_group (cr2);
+
+    cairo_destroy (cr2);
+
     return CAIRO_TEST_SUCCESS;
 }
 
diff-tree 9cea8a4bb26f7de2ac56e318c72e7d048b8b6c0f (from 39ae64ff0391c40077b63d214727ca0c25e03e37)
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Wed Mar 21 15:03:02 2007 -0400

    [cairo.c] Don't access gstate members directly

diff --git a/src/cairo-gstate.c b/src/cairo-gstate.c
index d639cfd..377871e 100644
--- a/src/cairo-gstate.c
+++ b/src/cairo-gstate.c
@@ -556,6 +556,24 @@ _cairo_gstate_set_dash (cairo_gstate_t *
     return CAIRO_STATUS_SUCCESS;
 }
 
+void
+_cairo_gstate_get_dash (cairo_gstate_t *gstate,
+			double         *dashes,
+			int            *num_dashes,
+			double         *offset)
+{
+    if (dashes)
+	memcpy (dashes,
+		gstate->stroke_style.dash,
+		sizeof (double) * gstate->stroke_style.num_dashes);
+
+    if (num_dashes)
+	*num_dashes = gstate->stroke_style.num_dashes;
+
+    if (offset)
+	*offset = gstate->stroke_style.dash_offset;
+}
+
 cairo_status_t
 _cairo_gstate_set_miter_limit (cairo_gstate_t *gstate, double limit)
 {
diff --git a/src/cairo.c b/src/cairo.c
index 2165045..6fafae3 100644
--- a/src/cairo.c
+++ b/src/cairo.c
@@ -476,10 +476,11 @@ cairo_push_group_with_content (cairo_t *
 {
     cairo_status_t status;
     cairo_rectangle_int16_t extents;
-    cairo_surface_t *group_surface = NULL;
+    cairo_surface_t *parent_surface, *group_surface = NULL;
 
+    parent_surface = _cairo_gstate_get_target (cr->gstate);
     /* Get the extents that we'll use in creating our new group surface */
-    _cairo_surface_get_extents (_cairo_gstate_get_target (cr->gstate), &extents);
+    _cairo_surface_get_extents (parent_surface, &extents);
     status = _cairo_clip_intersect_to_rectangle (_cairo_gstate_get_clip (cr->gstate), &extents);
     if (status != CAIRO_STATUS_SUCCESS)
 	goto bail;
@@ -498,8 +499,8 @@ cairo_push_group_with_content (cairo_t *
      * device offsets, so we want to set our own surface offsets from /that/,
      * and not from the device origin. */
     cairo_surface_set_device_offset (group_surface,
-                                     cr->gstate->target->device_transform.x0 - extents.x,
-                                     cr->gstate->target->device_transform.y0 - extents.y);
+                                     parent_surface->device_transform.x0 - extents.x,
+                                     parent_surface->device_transform.y0 - extents.y);
 
     /* create a new gstate for the redirect */
     cairo_save (cr);
@@ -1032,7 +1033,11 @@ cairo_set_dash (cairo_t	     *cr,
 int
 cairo_get_dash_count (cairo_t *cr)
 {
-    return cr->gstate->stroke_style.num_dashes;
+    int num_dashes;
+
+    _cairo_gstate_get_dash (cr->gstate, NULL, &num_dashes, NULL);
+
+    return num_dashes;
 }
 
 /**
@@ -1052,13 +1057,7 @@ cairo_get_dash (cairo_t *cr,
 		double  *dashes,
 		double  *offset)
 {
-    if (dashes)
-	memcpy (dashes,
-		cr->gstate->stroke_style.dash,
-		sizeof (double) * cr->gstate->stroke_style.num_dashes);
-
-    if (offset)
-	*offset = cr->gstate->stroke_style.dash_offset;
+    _cairo_gstate_get_dash (cr->gstate, dashes, NULL, offset);
 }
 
 /**
diff --git a/src/cairoint.h b/src/cairoint.h
index d54292e..4538bec 100644
--- a/src/cairoint.h
+++ b/src/cairoint.h
@@ -1313,6 +1313,9 @@ _cairo_gstate_get_line_join (cairo_gstat
 cairo_private cairo_status_t
 _cairo_gstate_set_dash (cairo_gstate_t *gstate, const double *dash, int num_dashes, double offset);
 
+cairo_private void
+_cairo_gstate_get_dash (cairo_gstate_t *gstate, double *dash, int *num_dashes, double *offset);
+
 cairo_private cairo_status_t
 _cairo_gstate_set_miter_limit (cairo_gstate_t *gstate, double limit);
 
diff-tree 39ae64ff0391c40077b63d214727ca0c25e03e37 (from bd275c19782700f2cfc6905f348e4d4b3f15d311)
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Wed Mar 21 14:56:34 2007 -0400

    [cairo-path] Don't access gstate members directly

diff --git a/src/cairo-path.c b/src/cairo-path.c
index 7c2374c..d79454c 100644
--- a/src/cairo-path.c
+++ b/src/cairo-path.c
@@ -36,7 +36,6 @@
 
 #include "cairo-path-private.h"
 #include "cairo-path-fixed-private.h"
-#include "cairo-gstate-private.h"
 
 const cairo_path_t _cairo_path_nil = { CAIRO_STATUS_NO_MEMORY, NULL, 0 };
 
@@ -275,7 +274,8 @@ _cpp_curve_to_flatten (void		*closure,
     if (status == CAIRO_INT_STATUS_DEGENERATE)
 	return CAIRO_STATUS_SUCCESS;
 
-    status = _cairo_spline_decompose (&spline, cpp->gstate->tolerance);
+    status = _cairo_spline_decompose (&spline,
+				      _cairo_gstate_get_tolerance (cpp->gstate));
     if (status)
       goto out;
 
@@ -360,7 +360,8 @@ _cairo_path_create_internal (cairo_path_
 	return (cairo_path_t*) &_cairo_path_nil;
 
     path->num_data = _cairo_path_count (path, path_fixed,
-					gstate->tolerance, flatten);
+					_cairo_gstate_get_tolerance (gstate),
+					flatten);
 
     path->data = malloc (path->num_data * sizeof (cairo_path_data_t));
     if (path->data == NULL) {


More information about the cairo-commit mailing list