summaryrefslogtreecommitdiff
path: root/src/cairo-polygon.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/cairo-polygon.c')
-rw-r--r--src/cairo-polygon.c34
1 files changed, 21 insertions, 13 deletions
diff --git a/src/cairo-polygon.c b/src/cairo-polygon.c
index 1392bfa..202cb4d 100644
--- a/src/cairo-polygon.c
+++ b/src/cairo-polygon.c
@@ -39,6 +39,8 @@
void
_cairo_polygon_init (cairo_polygon_t *polygon)
{
+ VG (VALGRIND_MAKE_MEM_UNDEFINED (polygon, sizeof (cairo_polygon_t)));
+
polygon->status = CAIRO_STATUS_SUCCESS;
polygon->num_edges = 0;
@@ -54,6 +56,8 @@ _cairo_polygon_fini (cairo_polygon_t *polygon)
{
if (polygon->edges != polygon->edges_embedded)
free (polygon->edges);
+
+ VG (VALGRIND_MAKE_MEM_NOACCESS (polygon, sizeof (cairo_polygon_t)));
}
/* make room for at least one more edge */
@@ -64,6 +68,11 @@ _cairo_polygon_grow (cairo_polygon_t *polygon)
int old_size = polygon->edges_size;
int new_size = 4 * old_size;
+ if (CAIRO_INJECT_FAULT ()) {
+ polygon->status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
+ return FALSE;
+ }
+
if (polygon->edges == polygon->edges_embedded) {
new_edges = _cairo_malloc_ab (new_size, sizeof (cairo_edge_t));
if (new_edges != NULL)
@@ -73,7 +82,7 @@ _cairo_polygon_grow (cairo_polygon_t *polygon)
new_size, sizeof (cairo_edge_t));
}
- if (new_edges == NULL) {
+ if (unlikely (new_edges == NULL)) {
polygon->status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
return FALSE;
}
@@ -84,16 +93,17 @@ _cairo_polygon_grow (cairo_polygon_t *polygon)
return TRUE;
}
-static void
+void
_cairo_polygon_add_edge (cairo_polygon_t *polygon,
const cairo_point_t *p1,
- const cairo_point_t *p2)
+ const cairo_point_t *p2,
+ int dir)
{
cairo_edge_t *edge;
/* drop horizontal edges */
if (p1->y == p2->y)
- goto DONE;
+ return;
if (polygon->num_edges == polygon->edges_size) {
if (! _cairo_polygon_grow (polygon))
@@ -104,15 +114,12 @@ _cairo_polygon_add_edge (cairo_polygon_t *polygon,
if (p1->y < p2->y) {
edge->edge.p1 = *p1;
edge->edge.p2 = *p2;
- edge->clockWise = 1;
+ edge->dir = dir;
} else {
edge->edge.p1 = *p2;
edge->edge.p2 = *p1;
- edge->clockWise = 0;
+ edge->dir = -dir;
}
-
- DONE:
- _cairo_polygon_move_to (polygon, p2);
}
void
@@ -131,9 +138,9 @@ _cairo_polygon_line_to (cairo_polygon_t *polygon,
const cairo_point_t *point)
{
if (polygon->has_current_point)
- _cairo_polygon_add_edge (polygon, &polygon->current_point, point);
- else
- _cairo_polygon_move_to (polygon, point);
+ _cairo_polygon_add_edge (polygon, &polygon->current_point, point, 1);
+
+ _cairo_polygon_move_to (polygon, point);
}
void
@@ -142,7 +149,8 @@ _cairo_polygon_close (cairo_polygon_t *polygon)
if (polygon->has_current_point) {
_cairo_polygon_add_edge (polygon,
&polygon->current_point,
- &polygon->first_point);
+ &polygon->first_point,
+ 1);
polygon->has_current_point = FALSE;
}