#include "cairo-perf.h"
typedef enum { LONG_LINES_UNCROPPED, LONG_LINES_CROPPED } long_lines_crop_t;
#define NUM_LINES 20
#define LONG_FACTOR 50.0
static cairo_perf_ticks_t
do_long_lines (cairo_t *cr, int width, int height, long_lines_crop_t crop)
{
int i;
double x, y, dx, dy, min_x, min_y, max_x, max_y;
double outer_width, outer_height;
cairo_save (cr);
cairo_translate (cr, width / 2, height / 2);
if (crop == LONG_LINES_UNCROPPED) {
outer_width = LONG_FACTOR * width;
outer_height = LONG_FACTOR * height;
cairo_set_source_rgb (cr, 1.0, 0.0, 0.0);
} else {
outer_width = width;
outer_height = height;
cairo_set_source_rgb (cr, 0.0, 1.0, 0.0);
}
min_x = x = - outer_width / 2.0;
min_y = y = - outer_height / 2.0;
max_x = outer_width / 2.0;
max_y = outer_width / 2.0;
dx = outer_width / NUM_LINES;
dy = outer_height / NUM_LINES;
cairo_perf_timer_start ();
for (i = 0; i < NUM_LINES; i++) {
cairo_move_to (cr, 0, 0);
cairo_line_to (cr, x, min_y);
cairo_stroke (cr);
cairo_move_to (cr, 0, 0);
cairo_line_to (cr, x, max_y);
cairo_stroke (cr);
cairo_move_to (cr, 0, 0);
cairo_line_to (cr, min_x, y);
cairo_stroke (cr);
cairo_move_to (cr, 0, 0);
cairo_line_to (cr, max_x, y);
cairo_stroke (cr);
x += dx;
y += dy;
}
cairo_perf_timer_stop ();
cairo_restore (cr);
return cairo_perf_timer_elapsed ();
}
static cairo_perf_ticks_t
long_lines_uncropped (cairo_t *cr, int width, int height)
{
return do_long_lines (cr, width, height, LONG_LINES_UNCROPPED);
}
static cairo_perf_ticks_t
long_lines_cropped (cairo_t *cr, int width, int height)
{
return do_long_lines (cr, width, height, LONG_LINES_CROPPED);
}
void
long_lines (cairo_perf_t *perf, cairo_t *cr, int width, int height)
{
cairo_perf_run (perf, "long-lines-uncropped", long_lines_uncropped);
cairo_perf_run (perf, "long-lines-cropped", long_lines_cropped);
}