compositor: Skip invisible strokes

If the pen is reduced to a single point, it is effectively invisible
when rasterised, so skip the stroke composition.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
This commit is contained in:
Chris Wilson 2012-08-25 08:39:30 +01:00
parent fc38d7375d
commit bdf83008f4
3 changed files with 22 additions and 21 deletions

View file

@ -139,6 +139,10 @@ _cairo_compositor_stroke (const cairo_compositor_t *compositor,
cairo_int_status_t status;
TRACE ((stderr, "%s\n", __FUNCTION__));
if (_cairo_pen_vertices_needed (tolerance, style->line_width/2, ctm) <= 1)
return CAIRO_INT_STATUS_NOTHING_TO_DO;
status = _cairo_composite_rectangles_init_for_stroke (&extents, surface,
op, source,
path, style, ctm,

View file

@ -41,11 +41,6 @@
#include "cairo-error-private.h"
#include "cairo-slope-private.h"
static int
_cairo_pen_vertices_needed (double tolerance,
double radius,
const cairo_matrix_t *matrix);
static void
_cairo_pen_compute_slopes (cairo_pen_t *pen);
@ -88,10 +83,12 @@ _cairo_pen_init (cairo_pen_t *pen,
* is reflecting
*/
for (i=0; i < pen->num_vertices; i++) {
double theta = 2 * M_PI * i / (double) pen->num_vertices;
double dx = radius * cos (reflect ? -theta : theta);
double dy = radius * sin (reflect ? -theta : theta);
cairo_pen_vertex_t *v = &pen->vertices[i];
double theta = 2 * M_PI * i / (double) pen->num_vertices, dx, dy;
if (reflect)
theta = -theta;
dx = radius * cos (theta);
dy = radius * sin (theta);
cairo_matrix_transform_distance (ctm, &dx, &dy);
v->point.x = _cairo_fixed_from_double (dx);
v->point.y = _cairo_fixed_from_double (dy);
@ -273,7 +270,7 @@ Note that this also equation works for M == m (a circle) as it
doesn't matter where on the circle the error is computed.
*/
static int
int
_cairo_pen_vertices_needed (double tolerance,
double radius,
const cairo_matrix_t *matrix)
@ -283,21 +280,16 @@ _cairo_pen_vertices_needed (double tolerance,
* compute major axis length for a pen with the specified radius.
* we don't need the minor axis length.
*/
double major_axis = _cairo_matrix_transformed_circle_major_axis (matrix,
radius);
int num_vertices;
double major_axis = _cairo_matrix_transformed_circle_major_axis (matrix,
radius);
/*
* compute number of vertices needed
*/
int num_vertices;
/* Where tolerance / M is > 1, we use 4 points */
if (tolerance >= major_axis) {
if (tolerance >= 2*major_axis) {
num_vertices = 1;
} else if (tolerance >= major_axis) {
num_vertices = 4;
} else {
double delta = acos (1 - tolerance / major_axis);
num_vertices = ceil (M_PI / delta);
num_vertices = ceil (2*M_PI / acos (1 - tolerance / major_axis));
/* number of vertices must be even */
if (num_vertices % 2)

View file

@ -1524,6 +1524,11 @@ cairo_private cairo_image_color_t
_cairo_image_analyze_color (cairo_image_surface_t *image);
/* cairo-pen.c */
cairo_private int
_cairo_pen_vertices_needed (double tolerance,
double radius,
const cairo_matrix_t *matrix);
cairo_private cairo_status_t
_cairo_pen_init (cairo_pen_t *pen,
double radius,