static cairo_int_status_t clip_and_composite_polygon (const cairo_spans_compositor_t *compositor, cairo_composite_rectangles_t *extents, cairo_polygon_t *polygon, cairo_fill_rule_t fill_rule, cairo_antialias_t antialias) { cairo_int_status_t status; /* XXX simply uses polygon limits.point extemities, tessellation? */ status = trim_extents_to_polygon (extents, polygon); if (unlikely (status)) return status; if (_cairo_polygon_is_empty (polygon)) { cairo_boxes_t boxes; if (extents->is_bounded) return CAIRO_STATUS_SUCCESS; _cairo_boxes_init (&boxes); extents->bounded.width = extents->bounded.height = 0; return fixup_unbounded_boxes (compositor, extents, &boxes); } if (extents->is_bounded && extents->clip->path) { cairo_polygon_t clipper; cairo_antialias_t clip_antialias; cairo_fill_rule_t clip_fill_rule; status = _cairo_clip_get_polygon (extents->clip, &clipper, &clip_fill_rule, &clip_antialias); if (likely (status == CAIRO_INT_STATUS_SUCCESS)) { cairo_clip_t *old_clip; if (clip_antialias == antialias) { /* refresh limits after trimming extents */ _cairo_polygon_limit_to_clip(polygon, extents->clip); status = _cairo_polygon_intersect (polygon, fill_rule, &clipper, clip_fill_rule); _cairo_polygon_fini (&clipper); if (unlikely (status)) return status; old_clip = extents->clip; extents->clip = _cairo_clip_copy_region (extents->clip); _cairo_clip_destroy (old_clip); } else { _cairo_polygon_fini (&clipper); } } } return composite_polygon (compositor, extents, polygon, fill_rule, antialias); }
static cairo_int_status_t fixup_unbounded_polygon (const cairo_spans_compositor_t *compositor, const cairo_composite_rectangles_t *extents, cairo_boxes_t *boxes) { cairo_polygon_t polygon, intersect; cairo_composite_rectangles_t composite; cairo_fill_rule_t fill_rule; cairo_antialias_t antialias; cairo_int_status_t status; TRACE((stderr, "%s\n", __FUNCTION__)); /* Can we treat the clip as a regular clear-polygon and use it to fill? */ status = _cairo_clip_get_polygon (extents->clip, &polygon, &fill_rule, &antialias); if (status == CAIRO_INT_STATUS_UNSUPPORTED) return status; status= _cairo_polygon_init_boxes (&intersect, boxes); if (unlikely (status)) goto cleanup_polygon; status = _cairo_polygon_intersect (&polygon, fill_rule, &intersect, CAIRO_FILL_RULE_WINDING); _cairo_polygon_fini (&intersect); if (unlikely (status)) goto cleanup_polygon; status = _cairo_composite_rectangles_init_for_polygon (&composite, extents->surface, CAIRO_OPERATOR_CLEAR, &_cairo_pattern_clear.base, &polygon, NULL); if (unlikely (status)) goto cleanup_polygon; status = composite_polygon (compositor, &composite, &polygon, fill_rule, antialias); _cairo_composite_rectangles_fini (&composite); cleanup_polygon: _cairo_polygon_fini (&polygon); return status; }
static cairo_status_t _cairo_path_fixed_fill_rectilinear_tessellate_to_boxes (const cairo_path_fixed_t *path, cairo_fill_rule_t fill_rule, cairo_antialias_t antialias, cairo_boxes_t *boxes) { cairo_polygon_t polygon; cairo_status_t status; _cairo_polygon_init (&polygon, boxes->limits, boxes->num_limits); boxes->num_limits = 0; /* tolerance will be ignored as the path is rectilinear */ status = _cairo_path_fixed_fill_rectilinear_to_polygon (path, antialias, &polygon); if (likely (status == CAIRO_STATUS_SUCCESS)) { status = _cairo_bentley_ottmann_tessellate_rectilinear_polygon_to_boxes (&polygon, fill_rule, boxes); } _cairo_polygon_fini (&polygon); return status; }
/* Compute outline of a given spline using the pen. The trapezoids needed to fill that outline will be added to traps */ cairo_status_t _cairo_pen_stroke_spline (cairo_pen_t *pen, cairo_spline_t *spline, double tolerance, cairo_traps_t *traps) { cairo_status_t status; cairo_polygon_t polygon; /* If the line width is so small that the pen is reduced to a single point, then we have nothing to do. */ if (pen->num_vertices <= 1) return CAIRO_STATUS_SUCCESS; _cairo_polygon_init (&polygon); status = _cairo_spline_decompose (spline, tolerance); if (status) return status; status = _cairo_pen_stroke_spline_half (pen, spline, CAIRO_DIRECTION_FORWARD, &polygon); if (status) return status; status = _cairo_pen_stroke_spline_half (pen, spline, CAIRO_DIRECTION_REVERSE, &polygon); if (status) return status; _cairo_polygon_close (&polygon); _cairo_traps_tessellate_polygon (traps, &polygon, CAIRO_FILL_RULE_WINDING); _cairo_polygon_fini (&polygon); return CAIRO_STATUS_SUCCESS; }
cairo_status_t _cairo_path_fixed_stroke_extents (const cairo_path_fixed_t *path, const cairo_stroke_style_t *stroke_style, const cairo_matrix_t *ctm, const cairo_matrix_t *ctm_inverse, double tolerance, cairo_rectangle_int_t *extents) { cairo_polygon_t polygon; cairo_status_t status; cairo_stroke_style_t style; /* When calculating extents for vector surfaces, ensure lines thinner * than the fixed point resolution are not optimized away. */ double min_line_width = _cairo_fixed_to_double (CAIRO_FIXED_EPSILON*2); if (stroke_style->line_width < min_line_width) { style = *stroke_style; style.line_width = min_line_width; stroke_style = &style; } _cairo_polygon_init (&polygon, NULL, 0); status = _cairo_path_fixed_stroke_to_polygon (path, stroke_style, ctm, ctm_inverse, tolerance, &polygon); _cairo_box_round_to_rectangle (&polygon.extents, extents); _cairo_polygon_fini (&polygon); return status; }
cairo_status_t _cairo_path_fixed_fill_to_traps (const cairo_path_fixed_t *path, cairo_fill_rule_t fill_rule, double tolerance, cairo_traps_t *traps) { cairo_polygon_t polygon; cairo_status_t status; if (path->is_empty_fill) return CAIRO_STATUS_SUCCESS; _cairo_polygon_init (&polygon); _cairo_polygon_limit (&polygon, traps->limits, traps->num_limits); status = _cairo_path_fixed_fill_to_polygon (path, tolerance, &polygon); if (unlikely (status || polygon.num_edges == 0)) goto CLEANUP; if (path->is_rectilinear) { status = _cairo_bentley_ottmann_tessellate_rectilinear_polygon (traps, &polygon, fill_rule); } else { status = _cairo_bentley_ottmann_tessellate_polygon (traps, &polygon, fill_rule); } CLEANUP: _cairo_polygon_fini (&polygon); return status; }
cairo_int_status_t _cairo_path_fixed_stroke_to_traps (const cairo_path_fixed_t *path, const cairo_stroke_style_t *stroke_style, const cairo_matrix_t *ctm, const cairo_matrix_t *ctm_inverse, double tolerance, cairo_traps_t *traps) { cairo_int_status_t status; cairo_polygon_t polygon; _cairo_polygon_init (&polygon, traps->limits, traps->num_limits); status = _cairo_path_fixed_stroke_to_polygon (path, stroke_style, ctm, ctm_inverse, tolerance, &polygon); if (unlikely (status)) goto BAIL; status = _cairo_polygon_status (&polygon); if (unlikely (status)) goto BAIL; status = _cairo_bentley_ottmann_tessellate_polygon (traps, &polygon, CAIRO_FILL_RULE_WINDING); BAIL: _cairo_polygon_fini (&polygon); return status; }
static cairo_int_status_t _cairo_spans_compositor_stroke (const cairo_compositor_t *_compositor, cairo_composite_rectangles_t *extents, const cairo_path_fixed_t *path, const cairo_stroke_style_t *style, const cairo_matrix_t *ctm, const cairo_matrix_t *ctm_inverse, double tolerance, cairo_antialias_t antialias) { const cairo_spans_compositor_t *compositor = (cairo_spans_compositor_t*)_compositor; cairo_int_status_t status; status = CAIRO_INT_STATUS_UNSUPPORTED; if (_cairo_path_fixed_stroke_is_rectilinear (path)) { cairo_boxes_t boxes; _cairo_boxes_init (&boxes); if (! _cairo_clip_contains_rectangle (extents->clip, &extents->mask)) _cairo_boxes_limit (&boxes, extents->clip->boxes, extents->clip->num_boxes); status = _cairo_path_fixed_stroke_rectilinear_to_boxes (path, style, ctm, antialias, &boxes); if (likely (status == CAIRO_INT_STATUS_SUCCESS)) status = clip_and_composite_boxes (compositor, extents, &boxes); _cairo_boxes_fini (&boxes); } if (status == CAIRO_INT_STATUS_UNSUPPORTED) { cairo_polygon_t polygon; if (extents->mask.width > extents->unbounded.width || extents->mask.height > extents->unbounded.height) { _cairo_polygon_init_with_clip (&polygon, extents->clip); } else { _cairo_polygon_init_with_clip (&polygon, NULL); } status = _cairo_path_fixed_stroke_to_polygon (path, style, ctm, ctm_inverse, tolerance, &polygon); if (likely (status == CAIRO_INT_STATUS_SUCCESS)) { status = clip_and_composite_polygon (compositor, extents, &polygon, CAIRO_FILL_RULE_WINDING, antialias); } _cairo_polygon_fini (&polygon); } return status; }
cairo_status_t _cairo_polygon_intersect_with_boxes (cairo_polygon_t *polygon, cairo_fill_rule_t *winding, cairo_box_t *boxes, int num_boxes) { cairo_polygon_t b; cairo_status_t status; int n; if (num_boxes == 0) { polygon->num_edges = 0; return CAIRO_STATUS_SUCCESS; } for (n = 0; n < num_boxes; n++) { if (polygon->extents.p1.x >= boxes[n].p1.x && polygon->extents.p2.x <= boxes[n].p2.x && polygon->extents.p1.y >= boxes[n].p1.y && polygon->extents.p2.y <= boxes[n].p2.y) { return CAIRO_STATUS_SUCCESS; } } _cairo_polygon_init (&b, NULL, 0); for (n = 0; n < num_boxes; n++) { if (boxes[n].p2.x > polygon->extents.p1.x && boxes[n].p1.x < polygon->extents.p2.x && boxes[n].p2.y > polygon->extents.p1.y && boxes[n].p1.y < polygon->extents.p2.y) { cairo_point_t p1, p2; p1.y = boxes[n].p1.y; p2.y = boxes[n].p2.y; p2.x = p1.x = boxes[n].p1.x; _cairo_polygon_add_external_edge (&b, &p1, &p2); p2.x = p1.x = boxes[n].p2.x; _cairo_polygon_add_external_edge (&b, &p2, &p1); } } status = _cairo_polygon_intersect (polygon, *winding, &b, CAIRO_FILL_RULE_WINDING); _cairo_polygon_fini (&b); *winding = CAIRO_FILL_RULE_WINDING; return status; }
cairo_int_status_t _cairo_gl_msaa_compositor_draw_clip (cairo_gl_context_t *ctx, cairo_gl_composite_t *setup, cairo_clip_t *clip, cairo_traps_t *traps) { cairo_int_status_t status; cairo_polygon_t polygon; cairo_antialias_t antialias; cairo_fill_rule_t fill_rule; if (! clip) return CAIRO_INT_STATUS_UNSUPPORTED; if (clip->num_boxes == 1 && ! clip->path) return _cairo_gl_msaa_compositor_draw_quad (ctx, setup, &clip->boxes[0]); if (traps->num_traps == 0) { status = _cairo_clip_get_polygon (clip, &polygon, &fill_rule, &antialias); if (unlikely (status)) return status; /* We ignore the antialias mode of the clip here, since the user requested * unantialiased rendering of their path and we expect that this stencil * based rendering of the clip to be a reasonable approximation to * the intersection between that clip and the path. * * In other words, what the user expects when they try to perform * a geometric intersection between an unantialiased polygon and an * antialiased polygon is open to interpretation. And we choose the fast * option. */ status = _cairo_bentley_ottmann_tessellate_polygon (traps, &polygon, fill_rule); _cairo_polygon_fini (&polygon); if (unlikely (status)) return status; } status = _draw_traps (ctx, setup, traps); return status; }
static cairo_int_status_t _draw_clip (cairo_gl_context_t *ctx, cairo_gl_composite_t *setup, cairo_clip_t *clip) { cairo_int_status_t status; cairo_traps_t traps; cairo_polygon_t polygon; cairo_antialias_t antialias; cairo_fill_rule_t fill_rule; status = _cairo_clip_get_polygon (clip, &polygon, &fill_rule, &antialias); if (unlikely (status)) return status; /* We ignore the antialias mode of the clip here, since the user requested * unantialiased rendering of their path and we expect that this stencil * based rendering of the clip to be a reasonable approximation to * the intersection between that clip and the path. * * In other words, what the user expects when they try to perform * a geometric intersection between an unantialiased polygon and an * antialiased polygon is open to interpretation. And we choose the fast * option. */ _cairo_traps_init (&traps); status = _cairo_bentley_ottmann_tessellate_polygon (&traps, &polygon, fill_rule); _cairo_polygon_fini (&polygon); if (unlikely (status)) return status; status = _draw_traps (ctx, setup, &traps); _cairo_traps_fini (&traps); return status; }
static cairo_int_status_t _clip_to_traps (cairo_clip_t *clip, cairo_traps_t *traps) { cairo_int_status_t status; cairo_polygon_t polygon; cairo_antialias_t antialias; cairo_fill_rule_t fill_rule; _cairo_traps_init (traps); if (clip->num_boxes == 1 && clip->path == NULL) { cairo_boxes_t boxes; _cairo_boxes_init_for_array (&boxes, clip->boxes, clip->num_boxes); return _cairo_traps_init_boxes (traps, &boxes); } status = _cairo_clip_get_polygon (clip, &polygon, &fill_rule, &antialias); if (unlikely (status)) return status; /* We ignore the antialias mode of the clip here, since the user requested * unantialiased rendering of their path and we expect that this stencil * based rendering of the clip to be a reasonable approximation to * the intersection between that clip and the path. * * In other words, what the user expects when they try to perform * a geometric intersection between an unantialiased polygon and an * antialiased polygon is open to interpretation. And we choose the fast * option. */ _cairo_traps_init (traps); status = _cairo_bentley_ottmann_tessellate_polygon (traps, &polygon, fill_rule); _cairo_polygon_fini (&polygon); return status; }
cairo_status_t _cairo_path_fixed_stroke_extents (const cairo_path_fixed_t *path, const cairo_stroke_style_t *stroke_style, const cairo_matrix_t *ctm, const cairo_matrix_t *ctm_inverse, double tolerance, cairo_rectangle_int_t *extents) { cairo_polygon_t polygon; cairo_status_t status; _cairo_polygon_init (&polygon, NULL, 0); status = _cairo_path_fixed_stroke_to_polygon (path, stroke_style, ctm, ctm_inverse, tolerance, &polygon); _cairo_box_round_to_rectangle (&polygon.extents, extents); _cairo_polygon_fini (&polygon); return status; }
static void _cairo_filler_fini (cairo_filler_t *filler) { _cairo_polygon_fini (&filler->polygon); }
cairo_int_status_t _cairo_clip_get_polygon (const cairo_clip_t *clip, cairo_polygon_t *polygon, cairo_fill_rule_t *fill_rule, cairo_antialias_t *antialias) { cairo_status_t status; cairo_clip_path_t *clip_path; if (_cairo_clip_is_all_clipped (clip)) { _cairo_polygon_init (polygon, NULL, 0); return CAIRO_INT_STATUS_SUCCESS; } /* If there is no clip, we need an infinite polygon */ assert (clip && (clip->path || clip->num_boxes)); if (clip->path == NULL) { *fill_rule = CAIRO_FILL_RULE_WINDING; *antialias = CAIRO_ANTIALIAS_DEFAULT; return _cairo_polygon_init_box_array (polygon, clip->boxes, clip->num_boxes); } /* check that residual is all of the same type/tolerance */ if (! can_convert_to_polygon (clip)) return CAIRO_INT_STATUS_UNSUPPORTED; if (clip->num_boxes < 2) _cairo_polygon_init_with_clip (polygon, clip); else _cairo_polygon_init_with_clip (polygon, NULL); clip_path = clip->path; *fill_rule = clip_path->fill_rule; *antialias = clip_path->antialias; status = _cairo_path_fixed_fill_to_polygon (&clip_path->path, clip_path->tolerance, polygon); if (unlikely (status)) goto err; if (clip->num_boxes > 1) { status = _cairo_polygon_intersect_with_boxes (polygon, fill_rule, clip->boxes, clip->num_boxes); if (unlikely (status)) goto err; } polygon->limits = NULL; polygon->num_limits = 0; while ((clip_path = clip_path->prev) != NULL) { cairo_polygon_t next; _cairo_polygon_init (&next, NULL, 0); status = _cairo_path_fixed_fill_to_polygon (&clip_path->path, clip_path->tolerance, &next); if (likely (status == CAIRO_STATUS_SUCCESS)) status = _cairo_polygon_intersect (polygon, *fill_rule, &next, clip_path->fill_rule); _cairo_polygon_fini (&next); if (unlikely (status)) goto err; *fill_rule = CAIRO_FILL_RULE_WINDING; } return CAIRO_STATUS_SUCCESS; err: _cairo_polygon_fini (polygon); return status; }
static cairo_int_status_t clip_and_composite_polygon (const cairo_spans_compositor_t *compositor, cairo_composite_rectangles_t *extents, cairo_polygon_t *polygon, cairo_fill_rule_t fill_rule, cairo_antialias_t antialias) { cairo_int_status_t status; TRACE ((stderr, "%s\n", __FUNCTION__)); /* XXX simply uses polygon limits.point extemities, tessellation? */ status = trim_extents_to_polygon (extents, polygon); if (unlikely (status)) return status; if (_cairo_polygon_is_empty (polygon)) { cairo_boxes_t boxes; if (extents->is_bounded) return CAIRO_STATUS_SUCCESS; _cairo_boxes_init (&boxes); extents->bounded.width = extents->bounded.height = 0; return fixup_unbounded_boxes (compositor, extents, &boxes); } if (extents->is_bounded && extents->clip->path) { cairo_polygon_t clipper; cairo_antialias_t clip_antialias; cairo_fill_rule_t clip_fill_rule; TRACE((stderr, "%s - combining shape with clip polygon\n", __FUNCTION__)); status = _cairo_clip_get_polygon (extents->clip, &clipper, &clip_fill_rule, &clip_antialias); if (likely (status == CAIRO_INT_STATUS_SUCCESS)) { cairo_clip_t *old_clip; if (clip_antialias == antialias) { status = _cairo_polygon_intersect (polygon, fill_rule, &clipper, clip_fill_rule); _cairo_polygon_fini (&clipper); if (unlikely (status)) return status; old_clip = extents->clip; extents->clip = _cairo_clip_copy_region (extents->clip); _cairo_clip_destroy (old_clip); status = trim_extents_to_polygon (extents, polygon); if (unlikely (status)) return status; fill_rule = CAIRO_FILL_RULE_WINDING; } else { _cairo_polygon_fini (&clipper); } } } return composite_polygon (compositor, extents, polygon, fill_rule, antialias); }
static cairo_int_status_t _cairo_spans_compositor_fill (const cairo_compositor_t *_compositor, cairo_composite_rectangles_t *extents, const cairo_path_fixed_t *path, cairo_fill_rule_t fill_rule, double tolerance, cairo_antialias_t antialias) { const cairo_spans_compositor_t *compositor = (cairo_spans_compositor_t*)_compositor; cairo_int_status_t status; TRACE((stderr, "%s op=%d, antialias=%d\n", __FUNCTION__, extents->op, antialias)); status = CAIRO_INT_STATUS_UNSUPPORTED; if (_cairo_path_fixed_fill_is_rectilinear (path)) { cairo_boxes_t boxes; TRACE((stderr, "%s - rectilinear\n", __FUNCTION__)); _cairo_boxes_init (&boxes); if (! _cairo_clip_contains_rectangle (extents->clip, &extents->mask)) _cairo_boxes_limit (&boxes, extents->clip->boxes, extents->clip->num_boxes); status = _cairo_path_fixed_fill_rectilinear_to_boxes (path, fill_rule, antialias, &boxes); if (likely (status == CAIRO_INT_STATUS_SUCCESS)) status = clip_and_composite_boxes (compositor, extents, &boxes); _cairo_boxes_fini (&boxes); } if (status == CAIRO_INT_STATUS_UNSUPPORTED) { cairo_polygon_t polygon; TRACE((stderr, "%s - polygon\n", __FUNCTION__)); if (extents->mask.width > extents->unbounded.width || extents->mask.height > extents->unbounded.height) { cairo_box_t limits; TRACE((stderr, "%s - clipping to bounds\n", __FUNCTION__)); _cairo_box_from_rectangle (&limits, &extents->unbounded); _cairo_polygon_init (&polygon, &limits, 1); } else { _cairo_polygon_init (&polygon, NULL, 0); } status = _cairo_path_fixed_fill_to_polygon (path, tolerance, &polygon); if (status == CAIRO_INT_STATUS_SUCCESS && extents->clip->num_boxes > 1) { TRACE((stderr, "%s - polygon intersect with %d clip boxes\n", __FUNCTION__, extents->clip->num_boxes)); status = _cairo_polygon_intersect_with_boxes (&polygon, &fill_rule, extents->clip->boxes, extents->clip->num_boxes); } if (likely (status == CAIRO_INT_STATUS_SUCCESS)) { cairo_clip_t *saved_clip = extents->clip; if (extents->is_bounded) { TRACE((stderr, "%s - polygon discard clip boxes\n", __FUNCTION__)); extents->clip = _cairo_clip_copy_path (extents->clip); extents->clip = _cairo_clip_intersect_box(extents->clip, &polygon.extents); } status = clip_and_composite_polygon (compositor, extents, &polygon, fill_rule, antialias); if (extents->is_bounded) { _cairo_clip_destroy (extents->clip); extents->clip = saved_clip; } } _cairo_polygon_fini (&polygon); TRACE((stderr, "%s - polygon status=%d\n", __FUNCTION__, status)); } return status; }
static cairo_int_status_t _cairo_spans_compositor_fill (const cairo_compositor_t *_compositor, cairo_composite_rectangles_t *extents, const cairo_path_fixed_t *path, cairo_fill_rule_t fill_rule, double tolerance, cairo_antialias_t antialias) { const cairo_spans_compositor_t *compositor = (cairo_spans_compositor_t*)_compositor; cairo_int_status_t status; status = CAIRO_INT_STATUS_UNSUPPORTED; if (_cairo_path_fixed_fill_is_rectilinear (path)) { cairo_boxes_t boxes; _cairo_boxes_init (&boxes); if (! _cairo_clip_contains_rectangle (extents->clip, &extents->mask)) _cairo_boxes_limit (&boxes, extents->clip->boxes, extents->clip->num_boxes); status = _cairo_path_fixed_fill_rectilinear_to_boxes (path, fill_rule, antialias, &boxes); if (likely (status == CAIRO_INT_STATUS_SUCCESS)) status = clip_and_composite_boxes (compositor, extents, &boxes); _cairo_boxes_fini (&boxes); } if (status == CAIRO_INT_STATUS_UNSUPPORTED) { cairo_polygon_t polygon; if (extents->mask.width > extents->unbounded.width || extents->mask.height > extents->unbounded.height) { cairo_box_t limits; _cairo_box_from_rectangle (&limits, &extents->unbounded); _cairo_polygon_init (&polygon, &limits, 1); } else { _cairo_polygon_init (&polygon, NULL, 0); } status = _cairo_path_fixed_fill_to_polygon (path, tolerance, &polygon); if (likely (status == CAIRO_INT_STATUS_SUCCESS)) { status = _cairo_polygon_intersect_with_boxes (&polygon, &fill_rule, extents->clip->boxes, extents->clip->num_boxes); } if (likely (status == CAIRO_INT_STATUS_SUCCESS)) { if (extents->is_bounded) { if (extents->clip->boxes != &extents->clip->embedded_box) free (extents->clip->boxes); extents->clip->num_boxes = 1; extents->clip->boxes = &extents->clip->embedded_box; extents->clip->boxes[0] = polygon.extents; } status = clip_and_composite_polygon (compositor, extents, &polygon, fill_rule, antialias); } _cairo_polygon_fini (&polygon); } return status; }
static cairo_region_t * _cairo_path_fixed_fill_rectilinear_tessellate_to_region (const cairo_path_fixed_t *path, cairo_fill_rule_t fill_rule, const cairo_rectangle_int_t *extents) { cairo_box_t box; cairo_polygon_t polygon; cairo_traps_t traps; cairo_status_t status; cairo_region_t *region; /* first try to bypass fill-to-polygon */ _cairo_traps_init (&traps); status = _cairo_path_fixed_fill_rectilinear_to_traps (path, fill_rule, &traps); if (_cairo_status_is_error (status)) goto CLEANUP_TRAPS; if (status == CAIRO_STATUS_SUCCESS) { status = _cairo_traps_extract_region (&traps, ®ion); goto CLEANUP_TRAPS; } /* path is not rectangular, try extracting clipped rectilinear edges */ _cairo_polygon_init (&polygon); if (extents != NULL) { _cairo_box_from_rectangle (&box, extents); _cairo_polygon_limit (&polygon, &box, 1); } /* tolerance will be ignored as the path is rectilinear */ status = _cairo_path_fixed_fill_to_polygon (path, 0., &polygon); if (unlikely (status)) goto CLEANUP_POLYGON; if (polygon.num_edges == 0) { region = cairo_region_create (); } else { status = _cairo_bentley_ottmann_tessellate_rectilinear_polygon (&traps, &polygon, fill_rule); if (likely (status == CAIRO_STATUS_SUCCESS)) status = _cairo_traps_extract_region (&traps, ®ion); } CLEANUP_POLYGON: _cairo_polygon_fini (&polygon); CLEANUP_TRAPS: _cairo_traps_fini (&traps); if (unlikely (status)) { /* XXX _cairo_region_create_in_error() */ region = cairo_region_create (); if (likely (region->status) == CAIRO_STATUS_SUCCESS) region->status = status; } return region; }
static cairo_surface_t * get_clip_surface (const cairo_spans_compositor_t *compositor, cairo_surface_t *dst, const cairo_clip_t *clip, const cairo_rectangle_int_t *extents) { cairo_composite_rectangles_t composite; cairo_surface_t *surface; cairo_box_t box; cairo_polygon_t polygon; const cairo_clip_path_t *clip_path; cairo_antialias_t antialias; cairo_fill_rule_t fill_rule; cairo_int_status_t status; assert (clip->path); surface = _cairo_surface_create_similar_solid (dst, CAIRO_CONTENT_ALPHA, extents->width, extents->height, CAIRO_COLOR_TRANSPARENT); _cairo_box_from_rectangle (&box, extents); _cairo_polygon_init (&polygon, &box, 1); clip_path = clip->path; status = _cairo_path_fixed_fill_to_polygon (&clip_path->path, clip_path->tolerance, &polygon); if (unlikely (status)) goto cleanup_polygon; antialias = clip_path->antialias; fill_rule = clip_path->fill_rule; if (clip->boxes) { cairo_polygon_t intersect; cairo_boxes_t tmp; _cairo_boxes_init_for_array (&tmp, clip->boxes, clip->num_boxes); status= _cairo_polygon_init_boxes (&intersect, &tmp); if (unlikely (status)) goto cleanup_polygon; status = _cairo_polygon_intersect (&polygon, fill_rule, &intersect, CAIRO_FILL_RULE_WINDING); _cairo_polygon_fini (&intersect); if (unlikely (status)) goto cleanup_polygon; fill_rule = CAIRO_FILL_RULE_WINDING; } polygon.limits = NULL; polygon.num_limits = 0; clip_path = clip_path->prev; while (clip_path) { if (clip_path->antialias == antialias) { cairo_polygon_t next; _cairo_polygon_init (&next, NULL, 0); status = _cairo_path_fixed_fill_to_polygon (&clip_path->path, clip_path->tolerance, &next); if (likely (status == CAIRO_INT_STATUS_SUCCESS)) status = _cairo_polygon_intersect (&polygon, fill_rule, &next, clip_path->fill_rule); _cairo_polygon_fini (&next); if (unlikely (status)) goto cleanup_polygon; fill_rule = CAIRO_FILL_RULE_WINDING; } clip_path = clip_path->prev; } _cairo_polygon_translate (&polygon, -extents->x, -extents->y); status = _cairo_composite_rectangles_init_for_polygon (&composite, surface, CAIRO_OPERATOR_ADD, &_cairo_pattern_white.base, &polygon, NULL); if (unlikely (status)) goto cleanup_polygon; status = composite_polygon (compositor, &composite, &polygon, fill_rule, antialias); _cairo_composite_rectangles_fini (&composite); _cairo_polygon_fini (&polygon); if (unlikely (status)) goto error; _cairo_polygon_init (&polygon, &box, 1); clip_path = clip->path; antialias = clip_path->antialias == CAIRO_ANTIALIAS_DEFAULT ? CAIRO_ANTIALIAS_NONE : CAIRO_ANTIALIAS_DEFAULT; clip_path = clip_path->prev; while (clip_path) { if (clip_path->antialias == antialias) { if (polygon.num_edges == 0) { status = _cairo_path_fixed_fill_to_polygon (&clip_path->path, clip_path->tolerance, &polygon); fill_rule = clip_path->fill_rule; polygon.limits = NULL; polygon.num_limits = 0; } else { cairo_polygon_t next; _cairo_polygon_init (&next, NULL, 0); status = _cairo_path_fixed_fill_to_polygon (&clip_path->path, clip_path->tolerance, &next); if (likely (status == CAIRO_INT_STATUS_SUCCESS)) status = _cairo_polygon_intersect (&polygon, fill_rule, &next, clip_path->fill_rule); _cairo_polygon_fini (&next); fill_rule = CAIRO_FILL_RULE_WINDING; } if (unlikely (status)) goto error; } clip_path = clip_path->prev; } if (polygon.num_edges) { _cairo_polygon_translate (&polygon, -extents->x, -extents->y); status = _cairo_composite_rectangles_init_for_polygon (&composite, surface, CAIRO_OPERATOR_IN, &_cairo_pattern_white.base, &polygon, NULL); if (unlikely (status)) goto cleanup_polygon; status = composite_polygon (compositor, &composite, &polygon, fill_rule, antialias); _cairo_composite_rectangles_fini (&composite); _cairo_polygon_fini (&polygon); if (unlikely (status)) goto error; } return surface; cleanup_polygon: _cairo_polygon_fini (&polygon); error: cairo_surface_destroy (surface); return _cairo_int_surface_create_in_error (status); }
static cairo_status_t _cairo_stroker_add_cap (cairo_stroker_t *stroker, cairo_stroke_face_t *f) { cairo_status_t status; if (stroker->style->line_cap == CAIRO_LINE_CAP_BUTT) return CAIRO_STATUS_SUCCESS; switch (stroker->style->line_cap) { case CAIRO_LINE_CAP_ROUND: { int i; int start, stop; cairo_slope_t slope; cairo_point_t tri[3]; cairo_pen_t *pen = &stroker->pen; slope = f->dev_vector; start = _cairo_pen_find_active_cw_vertex_index (pen, &slope); slope.dx = -slope.dx; slope.dy = -slope.dy; stop = _cairo_pen_find_active_cw_vertex_index (pen, &slope); tri[0] = f->point; tri[1] = f->cw; for (i=start; i != stop; i = (i+1) % pen->num_vertices) { tri[2] = f->point; _translate_point (&tri[2], &pen->vertices[i].point); status = _cairo_traps_tessellate_triangle (stroker->traps, tri); if (unlikely (status)) return status; tri[1] = tri[2]; } tri[2] = f->ccw; return _cairo_traps_tessellate_triangle (stroker->traps, tri); } case CAIRO_LINE_CAP_SQUARE: { double dx, dy; cairo_slope_t fvector; cairo_point_t occw, ocw; cairo_polygon_t polygon; dx = f->usr_vector.x; dy = f->usr_vector.y; dx *= stroker->style->line_width / 2.0; dy *= stroker->style->line_width / 2.0; cairo_matrix_transform_distance (stroker->ctm, &dx, &dy); fvector.dx = _cairo_fixed_from_double (dx); fvector.dy = _cairo_fixed_from_double (dy); occw.x = f->ccw.x + fvector.dx; occw.y = f->ccw.y + fvector.dy; ocw.x = f->cw.x + fvector.dx; ocw.y = f->cw.y + fvector.dy; _cairo_polygon_init (&polygon); _cairo_polygon_move_to (&polygon, &f->cw); _cairo_polygon_line_to (&polygon, &ocw); _cairo_polygon_line_to (&polygon, &occw); _cairo_polygon_line_to (&polygon, &f->ccw); _cairo_polygon_close (&polygon); status = _cairo_polygon_status (&polygon); if (status == CAIRO_STATUS_SUCCESS) { status = _cairo_bentley_ottmann_tessellate_polygon (stroker->traps, &polygon, CAIRO_FILL_RULE_WINDING); } _cairo_polygon_fini (&polygon); return status; } case CAIRO_LINE_CAP_BUTT: default: return CAIRO_STATUS_SUCCESS; } }
static cairo_status_t _rectilinear_clip_to_boxes (const cairo_path_fixed_t *path, cairo_fill_rule_t fill_rule, cairo_box_t **boxes, int *num_boxes, int *size_boxes) { cairo_polygon_t polygon; cairo_traps_t traps; cairo_status_t status; _cairo_traps_init (&traps); _cairo_traps_limit (&traps, *boxes, *num_boxes); _cairo_polygon_init (&polygon); _cairo_polygon_limit (&polygon, *boxes, *num_boxes); status = _cairo_path_fixed_fill_rectilinear_to_traps (path, fill_rule, &traps); if (unlikely (_cairo_status_is_error (status))) goto CLEANUP; if (status == CAIRO_STATUS_SUCCESS) goto BOXES; /* tolerance will be ignored as the path is rectilinear */ status = _cairo_path_fixed_fill_to_polygon (path, 0., &polygon); if (unlikely (status)) goto CLEANUP; if (polygon.num_edges == 0) { *num_boxes = 0; } else { status = _cairo_bentley_ottmann_tessellate_rectilinear_polygon (&traps, &polygon, fill_rule); if (likely (status == CAIRO_STATUS_SUCCESS)) { int i; BOXES: i = *size_boxes; if (i < 0) i = -i; if (traps.num_traps > i) { cairo_box_t *new_boxes; int new_size; new_size = pot (traps.num_traps); new_boxes = _cairo_malloc_ab (new_size, sizeof (cairo_box_t)); if (unlikely (new_boxes == NULL)) { status = _cairo_error (CAIRO_STATUS_NO_MEMORY); goto CLEANUP; } if (*size_boxes > 0) free (*boxes); *boxes = new_boxes; *size_boxes = new_size; } for (i = 0; i < traps.num_traps; i++) { (*boxes)[i].p1.x = traps.traps[i].left.p1.x; (*boxes)[i].p1.y = traps.traps[i].top; (*boxes)[i].p2.x = traps.traps[i].right.p1.x; (*boxes)[i].p2.y = traps.traps[i].bottom; } *num_boxes = i; } } CLEANUP: _cairo_polygon_fini (&polygon); _cairo_traps_fini (&traps); return status; }
static cairo_int_status_t clip_and_composite_boxes (const cairo_spans_compositor_t *compositor, cairo_composite_rectangles_t *extents, cairo_boxes_t *boxes) { cairo_int_status_t status; cairo_polygon_t polygon; TRACE ((stderr, "%s\n", __FUNCTION__)); status = trim_extents_to_boxes (extents, boxes); if (unlikely (status)) return status; if (boxes->num_boxes == 0) { if (extents->is_bounded) return CAIRO_STATUS_SUCCESS; return fixup_unbounded_boxes (compositor, extents, boxes); } /* Can we reduce drawing through a clip-mask to simply drawing the clip? */ if (extents->clip->path != NULL && extents->is_bounded) { cairo_polygon_t polygon; cairo_fill_rule_t fill_rule; cairo_antialias_t antialias; cairo_clip_t *clip; clip = _cairo_clip_copy (extents->clip); clip = _cairo_clip_intersect_boxes (clip, boxes); if (_cairo_clip_is_all_clipped (clip)) return CAIRO_INT_STATUS_NOTHING_TO_DO; status = _cairo_clip_get_polygon (clip, &polygon, &fill_rule, &antialias); _cairo_clip_path_destroy (clip->path); clip->path = NULL; if (likely (status == CAIRO_INT_STATUS_SUCCESS)) { cairo_clip_t *saved_clip = extents->clip; extents->clip = clip; status = clip_and_composite_polygon (compositor, extents, &polygon, fill_rule, antialias); clip = extents->clip; extents->clip = saved_clip; _cairo_polygon_fini (&polygon); } _cairo_clip_destroy (clip); if (status != CAIRO_INT_STATUS_UNSUPPORTED) return status; } if (boxes->is_pixel_aligned) { status = composite_aligned_boxes (compositor, extents, boxes); if (status != CAIRO_INT_STATUS_UNSUPPORTED) return status; } status = composite_boxes (compositor, extents, boxes); if (status != CAIRO_INT_STATUS_UNSUPPORTED) return status; status = _cairo_polygon_init_boxes (&polygon, boxes); if (unlikely (status)) return status; status = composite_polygon (compositor, extents, &polygon, CAIRO_FILL_RULE_WINDING, CAIRO_ANTIALIAS_DEFAULT); _cairo_polygon_fini (&polygon); return status; }
static cairo_int_status_t _cairo_spans_compositor_stroke (const cairo_compositor_t *_compositor, cairo_composite_rectangles_t *extents, const cairo_path_fixed_t *path, const cairo_stroke_style_t *style, const cairo_matrix_t *ctm, const cairo_matrix_t *ctm_inverse, double tolerance, cairo_antialias_t antialias) { const cairo_spans_compositor_t *compositor = (cairo_spans_compositor_t*)_compositor; cairo_int_status_t status; TRACE_ (_cairo_debug_print_path (stderr, path)); status = CAIRO_INT_STATUS_UNSUPPORTED; if (_cairo_path_fixed_stroke_is_rectilinear (path)) { cairo_boxes_t boxes; _cairo_boxes_init (&boxes); if (! _cairo_clip_contains_rectangle (extents->clip, &extents->mask)) _cairo_boxes_limit (&boxes, extents->clip->boxes, extents->clip->num_boxes); status = _cairo_path_fixed_stroke_rectilinear_to_boxes (path, style, ctm, antialias, &boxes); if (likely (status == CAIRO_INT_STATUS_SUCCESS)) status = clip_and_composite_boxes (compositor, extents, &boxes); _cairo_boxes_fini (&boxes); } if (status == CAIRO_INT_STATUS_UNSUPPORTED) { cairo_polygon_t polygon; cairo_fill_rule_t fill_rule = CAIRO_FILL_RULE_WINDING; if (extents->mask.width > extents->unbounded.width || extents->mask.height > extents->unbounded.height) { cairo_box_t limits; _cairo_box_from_rectangle (&limits, &extents->unbounded); _cairo_polygon_init (&polygon, &limits, 1); } else { _cairo_polygon_init (&polygon, NULL, 0); } status = _cairo_path_fixed_stroke_to_polygon (path, style, ctm, ctm_inverse, tolerance, &polygon); TRACE_ (_cairo_debug_print_polygon (stderr, &polygon)); if (status == CAIRO_INT_STATUS_SUCCESS && extents->clip->num_boxes > 1) { status = _cairo_polygon_intersect_with_boxes (&polygon, &fill_rule, extents->clip->boxes, extents->clip->num_boxes); } if (likely (status == CAIRO_INT_STATUS_SUCCESS)) { cairo_clip_t *saved_clip = extents->clip; if (extents->is_bounded) { extents->clip = _cairo_clip_copy_path (extents->clip); extents->clip = _cairo_clip_intersect_box(extents->clip, &polygon.extents); } status = clip_and_composite_polygon (compositor, extents, &polygon, fill_rule, antialias); if (extents->is_bounded) { _cairo_clip_destroy (extents->clip); extents->clip = saved_clip; } } _cairo_polygon_fini (&polygon); } return status; }