static cairo_int_status_t
_draw_trap (cairo_gl_context_t		*ctx,
	    cairo_gl_composite_t	*setup,
	    cairo_trapezoid_t		*trap)
{
    cairo_point_t quad[4];

    quad[0].x = _cairo_edge_compute_intersection_x_for_y (&trap->left.p1,
							  &trap->left.p2,
							  trap->top);
    quad[0].y = trap->top;

    quad[1].x = _cairo_edge_compute_intersection_x_for_y (&trap->left.p1,
						      &trap->left.p2,
						      trap->bottom);
    quad[1].y = trap->bottom;

    quad[2].x = _cairo_edge_compute_intersection_x_for_y (&trap->right.p1,
						      &trap->right.p2,
						      trap->bottom);
    quad[2].y = trap->bottom;

    quad[3].x = _cairo_edge_compute_intersection_x_for_y (&trap->right.p1,
						      &trap->right.p2,
						      trap->top);
    quad[3].y = trap->top;
    return _cairo_gl_composite_emit_quad_as_tristrip (ctx, setup, quad);
}
Beispiel #2
0
static void
assert_last_edge_is_valid(cairo_polygon_t *polygon,
			  const cairo_box_t *limit)
{
    cairo_edge_t *edge;
    cairo_fixed_t x;

    edge = &polygon->edges[polygon->num_edges-1];

    XASSERT (edge->bottom > edge->top);
    XASSERT (edge->top >= limit->p1.y);
    XASSERT (edge->bottom <= limit->p2.y);

    x = _cairo_edge_compute_intersection_x_for_y (&edge->line.p1,
						  &edge->line.p2,
						  edge->top);
    XASSERT (x >= limit->p1.x);
    XASSERT (x <= limit->p2.x);

    x = _cairo_edge_compute_intersection_x_for_y (&edge->line.p1,
						  &edge->line.p2,
						  edge->bottom);
    XASSERT (x >= limit->p1.x);
    XASSERT (x <= limit->p2.x);
}
Beispiel #3
0
static void
_add_edge (cairo_polygon_t *polygon,
	   const cairo_point_t *p1,
	   const cairo_point_t *p2,
	   int top, int bottom,
	   int dir)
{
    cairo_edge_t *edge;

    XASSERT (top < bottom);

    if (unlikely (polygon->num_edges == polygon->edges_size)) {
	if (! _cairo_polygon_grow (polygon))
	    return;
    }

    edge = &polygon->edges[polygon->num_edges++];
    edge->line.p1 = *p1;
    edge->line.p2 = *p2;
    edge->top = top;
    edge->bottom = bottom;
    edge->dir = dir;

    if (top < polygon->extents.p1.y)
	polygon->extents.p1.y = top;
    if (bottom > polygon->extents.p2.y)
	polygon->extents.p2.y = bottom;

    if (p1->x < polygon->extents.p1.x || p1->x > polygon->extents.p2.x) {
	cairo_fixed_t x = p1->x;
	if (top != p1->y)
	    x = _cairo_edge_compute_intersection_x_for_y (p1, p2, top);
	if (x < polygon->extents.p1.x)
	    polygon->extents.p1.x = x;
	if (x > polygon->extents.p2.x)
	    polygon->extents.p2.x = x;
    }

    if (p2->x < polygon->extents.p1.x || p2->x > polygon->extents.p2.x) {
	cairo_fixed_t x = p2->x;
	if (bottom != p2->y)
	    x = _cairo_edge_compute_intersection_x_for_y (p1, p2, bottom);
	if (x < polygon->extents.p1.x)
	    polygon->extents.p1.x = x;
	if (x > polygon->extents.p2.x)
	    polygon->extents.p2.x = x;
    }
}
static void
_add_clipped_edge (struct reduce *r,
		   const cairo_point_t *p1,
		   const cairo_point_t *p2,
		   int y1, int y2)
{
    cairo_fixed_t x;

    x = _cairo_edge_compute_intersection_x_for_y (p1, p2, y1);
    if (x < r->extents.p1.x)
	r->extents.p1.x = x;

    x = _cairo_edge_compute_intersection_x_for_y (p1, p2, y2);
    if (x > r->extents.p2.x)
	r->extents.p2.x = x;

    if (y1 < r->extents.p1.y)
	r->extents.p1.y = y1;

    if (y2 > r->extents.p2.y)
	r->extents.p2.y = y2;

    r->inside = TRUE;
}
Beispiel #5
0
static cairo_fixed_t
_line_compute_intersection_x_for_y (const cairo_line_t *line,
				    cairo_fixed_t y)
{
    return _cairo_edge_compute_intersection_x_for_y (&line->p1, &line->p2, y);
}
Beispiel #6
0
static void
_add_clipped_edge (cairo_polygon_t *polygon,
		   const cairo_point_t *p1,
		   const cairo_point_t *p2,
		   const int top, const int bottom,
		   const int dir)
{
    cairo_point_t bot_left, top_right;
    cairo_fixed_t top_y, bot_y;
    int n;

    for (n = 0; n < polygon->num_limits; n++) {
	const cairo_box_t *limits = &polygon->limits[n];
	cairo_fixed_t pleft, pright;

	if (top >= limits->p2.y)
	    continue;
	if (bottom <= limits->p1.y)
	    continue;

	bot_left.x = limits->p1.x;
	bot_left.y = limits->p2.y;

	top_right.x = limits->p2.x;
	top_right.y = limits->p1.y;

	/* The useful region */
	top_y = MAX (top, limits->p1.y);
	bot_y = MIN (bottom, limits->p2.y);

	/* The projection of the edge on the horizontal axis */
	pleft = MIN (p1->x, p2->x);
	pright = MAX (p1->x, p2->x);

	if (limits->p1.x <= pleft && pright <= limits->p2.x) {
	    /* Projection of the edge completely contained in the box:
	     * clip vertically by restricting top and bottom */

	    _add_edge (polygon, p1, p2, top_y, bot_y, dir);
	    assert_last_edge_is_valid (polygon, limits);
	} else if (pright <= limits->p1.x) {
	    /* Projection of the edge to the left of the box:
	     * replace with the left side of the box (clipped top/bottom) */

	    _add_edge (polygon, &limits->p1, &bot_left, top_y, bot_y, dir);
	    assert_last_edge_is_valid (polygon, limits);
	} else if (limits->p2.x <= pleft) {
	    /* Projection of the edge to the right of the box:
	     * replace with the right side of the box (clipped top/bottom) */

	    _add_edge (polygon, &top_right, &limits->p2, top_y, bot_y, dir);
	    assert_last_edge_is_valid (polygon, limits);
	} else {
	    /* The edge and the box intersect in a generic way */
	    cairo_fixed_t left_y, right_y;
	    cairo_bool_t top_left_to_bottom_right;

	    /*
	     * The edge intersects the lines corresponding to the left
	     * and right sides of the limit box at left_y and right_y,
	     * but we need to add edges for the range from top_y to
	     * bot_y.
	     *
	     * For both intersections, there are three cases:
	     *
	     *  1) It is outside the vertical range of the limit
	     *     box. In this case we can simply further clip the
	     *     edge we will be emitting (i.e. restrict its
	     *     top/bottom limits to those of the limit box).
	     *
	     *  2) It is inside the vertical range of the limit
	     *     box. In this case, we need to add the vertical edge
	     *     connecting the correct vertex to the intersection,
	     *     in order to preserve the winding count.
	     *
	     *  3) It is exactly on the box. In this case, do nothing.
	     *
	     * These operations restrict the active range (stored in
	     * top_y/bot_y) so that the p1-p2 edge is completely
	     * inside the box if it is clipped to this vertical range.
	     */

	    top_left_to_bottom_right = (p1->x <= p2->x) == (p1->y <= p2->y);
	    if (top_left_to_bottom_right) {
		if (pleft >= limits->p1.x) {
		    left_y = top_y;
		} else {
		    left_y = _cairo_edge_compute_intersection_y_for_x (p1, p2,
								       limits->p1.x);
		    if (_cairo_edge_compute_intersection_x_for_y (p1, p2, left_y) < limits->p1.x)
			left_y++;
		}

		left_y = MIN (left_y, bot_y);
		if (top_y < left_y) {
		    _add_edge (polygon, &limits->p1, &bot_left,
			       top_y, left_y, dir);
		    assert_last_edge_is_valid (polygon, limits);
		    top_y = left_y;
		}

		if (pright <= limits->p2.x) {
		    right_y = bot_y;
		} else {
		    right_y = _cairo_edge_compute_intersection_y_for_x (p1, p2,
									limits->p2.x);
		    if (_cairo_edge_compute_intersection_x_for_y (p1, p2, right_y) > limits->p2.x)
			right_y--;
		}

		right_y = MAX (right_y, top_y);
		if (bot_y > right_y) {
		    _add_edge (polygon, &top_right, &limits->p2,
			       right_y, bot_y, dir);
		    assert_last_edge_is_valid (polygon, limits);
		    bot_y = right_y;
		}
	    } else {
		if (pright <= limits->p2.x) {
		    right_y = top_y;
		} else {
		    right_y = _cairo_edge_compute_intersection_y_for_x (p1, p2,
									limits->p2.x);
		    if (_cairo_edge_compute_intersection_x_for_y (p1, p2, right_y) > limits->p2.x)
			right_y++;
		}

		right_y = MIN (right_y, bot_y);
		if (top_y < right_y) {
		    _add_edge (polygon, &top_right, &limits->p2,
			       top_y, right_y, dir);
		    assert_last_edge_is_valid (polygon, limits);
		    top_y = right_y;
		}

		if (pleft >= limits->p1.x) {
		    left_y = bot_y;
		} else {
		    left_y = _cairo_edge_compute_intersection_y_for_x (p1, p2,
								       limits->p1.x);
		    if (_cairo_edge_compute_intersection_x_for_y (p1, p2, left_y) < limits->p1.x)
			left_y--;
		}

		left_y = MAX (left_y, top_y);
		if (bot_y > left_y) {
		    _add_edge (polygon, &limits->p1, &bot_left,
			       left_y, bot_y, dir);
		    assert_last_edge_is_valid (polygon, limits);
		    bot_y = left_y;
		}
	    }

	    if (top_y != bot_y) {
		_add_edge (polygon, p1, p2, top_y, bot_y, dir);
		assert_last_edge_is_valid (polygon, limits);
	    }
	}
    }
}