stroke: Remove redundant code for computing culling extents

Same code repeated!

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
This commit is contained in:
Chris Wilson 2012-10-03 17:38:21 +01:00
parent 8020e0bc8c
commit d6a0567684
2 changed files with 35 additions and 72 deletions

View file

@ -88,6 +88,36 @@ typedef struct cairo_stroker {
cairo_box_t bounds;
} cairo_stroker_t;
static void
_cairo_stroker_limit (cairo_stroker_t *stroker,
const cairo_path_fixed_t *path,
const cairo_box_t *boxes,
int num_boxes)
{
double dx, dy;
cairo_fixed_t fdx, fdy;
stroker->has_bounds = TRUE;
_cairo_boxes_get_extents (boxes, num_boxes, &stroker->bounds);
/* Extend the bounds in each direction to account for the maximum area
* we might generate trapezoids, to capture line segments that are outside
* of the bounds but which might generate rendering that's within bounds.
*/
_cairo_stroke_style_max_distance_from_path (&stroker->style, path,
stroker->ctm, &dx, &dy);
fdx = _cairo_fixed_from_double (dx);
fdy = _cairo_fixed_from_double (dy);
stroker->bounds.p1.x -= fdx;
stroker->bounds.p2.x += fdx;
stroker->bounds.p1.y -= fdy;
stroker->bounds.p2.y += fdy;
}
static cairo_status_t
_cairo_stroker_init (cairo_stroker_t *stroker,
const cairo_path_fixed_t *path,
@ -122,64 +152,13 @@ _cairo_stroker_init (cairo_stroker_t *stroker,
stroker->add_external_edge = NULL;
stroker->has_bounds = num_limits;
if (stroker->has_bounds) {
/* Extend the bounds in each direction to account for the maximum area
* we might generate trapezoids, to capture line segments that are
* outside of the bounds but which might generate rendering that's
* within bounds.
*/
double dx, dy;
cairo_fixed_t fdx, fdy;
int i;
stroker->bounds = limits[0];
for (i = 1; i < num_limits; i++)
_cairo_box_add_box (&stroker->bounds, &limits[i]);
_cairo_stroke_style_max_distance_from_path (stroke_style, path, ctm, &dx, &dy);
fdx = _cairo_fixed_from_double (dx);
fdy = _cairo_fixed_from_double (dy);
stroker->bounds.p1.x -= fdx;
stroker->bounds.p2.x += fdx;
stroker->bounds.p1.y -= fdy;
stroker->bounds.p2.y += fdy;
}
stroker->has_bounds = FALSE;
if (num_limits)
_cairo_stroker_limit (stroker, path, limits, num_limits);
return CAIRO_STATUS_SUCCESS;
}
static void
_cairo_stroker_limit (cairo_stroker_t *stroker,
const cairo_path_fixed_t *path,
const cairo_box_t *boxes,
int num_boxes)
{
double dx, dy;
cairo_fixed_t fdx, fdy;
stroker->has_bounds = TRUE;
_cairo_boxes_get_extents (boxes, num_boxes, &stroker->bounds);
/* Extend the bounds in each direction to account for the maximum area
* we might generate trapezoids, to capture line segments that are outside
* of the bounds but which might generate rendering that's within bounds.
*/
_cairo_stroke_style_max_distance_from_path (&stroker->style, path,
stroker->ctm, &dx, &dy);
fdx = _cairo_fixed_from_double (dx);
fdy = _cairo_fixed_from_double (dy);
stroker->bounds.p1.x -= fdx;
stroker->bounds.p2.x += fdx;
stroker->bounds.p1.y -= fdy;
stroker->bounds.p2.y += fdy;
}
static void
_cairo_stroker_fini (cairo_stroker_t *stroker)
{
@ -1339,10 +1318,6 @@ _cairo_path_fixed_stroke_dashed_to_polygon (const cairo_path_fixed_t *path,
stroker.add_external_edge = _cairo_polygon_add_external_edge,
stroker.closure = polygon;
if (polygon->num_limits)
_cairo_stroker_limit (&stroker, path,
polygon->limits, polygon->num_limits);
status = _cairo_path_fixed_interpret (path,
_cairo_stroker_move_to,
stroker.dash.dashed ?

View file

@ -85,22 +85,10 @@ _cairo_boxes_get_extents (const cairo_box_t *boxes,
int num_boxes,
cairo_box_t *extents)
{
int n;
assert (num_boxes > 0);
*extents = *boxes;
for (n = 1; n < num_boxes; n++) {
if (boxes[n].p1.x < extents->p1.x)
extents->p1.x = boxes[n].p1.x;
if (boxes[n].p2.x > extents->p2.x)
extents->p2.x = boxes[n].p2.x;
if (boxes[n].p1.y < extents->p1.y)
extents->p1.y = boxes[n].p1.y;
if (boxes[n].p2.y > extents->p2.y)
extents->p2.y = boxes[n].p2.y;
}
while (--num_boxes)
_cairo_box_add_box (extents, ++boxes);
}
/* XXX We currently have a confusing mix of boxes and rectangles as