polygon: Tweak the y-coordinates of the edge so that it is inside the clip

As we evaluate the line first using y-for-x to find the clipped
vertical range and then rasterise the line using x-for-y, we can incur
severe rounding errors that cause us to draw beyond the clipped region.
The first simple attempt at a fix is to tweak the clipped vertical range
such that the evaluated extents of the line are contained.

Reported-by: Taekyun Kim <tkq.kim@samsung.com>
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
This commit is contained in:
Chris Wilson 2011-12-06 14:45:27 +00:00
parent 19dd6e7e53
commit 291efa76de

View file

@ -423,6 +423,9 @@ _add_clipped_edge (cairo_polygon_t *polygon,
top_left_to_bottom_right = (p1->x < p2->x) == (p1->y < p2->y);
if (top_left_to_bottom_right) {
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,
@ -431,6 +434,9 @@ _add_clipped_edge (cairo_polygon_t *polygon,
top_y = left_y;
}
if (_cairo_edge_compute_intersection_x_for_y (p1, p2, right_y) > limits->p1.y)
right_y--;
right_y = MAX (right_y, top_y);
if (bot_y > right_y) {
_add_edge (polygon, &top_right, &limits->p2,
@ -439,6 +445,9 @@ _add_clipped_edge (cairo_polygon_t *polygon,
bot_y = right_y;
}
} else {
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,
@ -447,6 +456,9 @@ _add_clipped_edge (cairo_polygon_t *polygon,
top_y = right_y;
}
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,