#include "cairo-perf.h"
#define MOSAIC_FILL 1
#define MOSAIC_TESSELLATE 0
#define MOSAIC_CURVE_TO 2
#define MOSAIC_LINE_TO 0
struct mosaic_region {
unsigned rgb;
unsigned ncurves;
};
struct mosaic_region_iter {
int do_curves;
struct mosaic_region const *region;
double const *points;
};
#include "mosaic.h"
static void
mosaic_region_iter_init (struct mosaic_region_iter *iter, int do_curves)
{
iter->region = mosaic_regions;
iter->points = mosaic_curve_points;
iter->do_curves = do_curves;
}
static int
mosaic_next_path (cairo_t *cr, struct mosaic_region_iter *iter)
{
double const *points = iter->points;
unsigned i;
unsigned ncurves = iter->region->ncurves;
if (0 == ncurves) {
return 0;
}
cairo_new_path (cr);
cairo_move_to (cr, points[0], points[1]);
points += 2;
for (i=0; i < ncurves; i++, points += 6) {
if (iter->do_curves) {
cairo_curve_to (cr,
points[0], points[1],
points[2], points[3],
points[4], points[5]);
}
else {
cairo_line_to (cr,
points[4], points[5]);
}
}
cairo_close_path (cr);
{
unsigned rgb = iter->region->rgb;
double r = ((rgb >> 16) & 255) / 255.0;
double g = ((rgb >> 8) & 255) / 255.0;
double b = ((rgb >> 0) & 255) / 255.0;
cairo_set_source_rgb (cr, r, g, b);
}
iter->points = iter->points + 2*(1 + 3*iter->region->ncurves);
iter->region++;
return 1;
}
static cairo_perf_ticks_t
mosaic_perform(cairo_t *cr, unsigned flags, int width, int height)
{
struct mosaic_region_iter iter;
double minx = -40.7;
double maxx = 955.1;
double miny = -88.4;
double maxy = 884.5;
cairo_identity_matrix (cr);
if (flags & MOSAIC_FILL) {
cairo_set_source_rgb (cr, 1, 1, 1);
cairo_rectangle (cr, 0, 0, width, height);
cairo_fill (cr);
}
cairo_scale (cr, width / (maxx - minx) , height / (maxy - miny));
cairo_translate (cr, -minx, -miny);
mosaic_region_iter_init (&iter, flags & MOSAIC_CURVE_TO);
cairo_perf_timer_start ();
while (mosaic_next_path (cr, &iter)) {
if (flags & MOSAIC_FILL) {
cairo_fill (cr);
}
else {
double x, y;
cairo_get_current_point (cr, &x, &y);
cairo_in_fill (cr, x, y);
}
}
cairo_perf_timer_stop ();
return cairo_perf_timer_elapsed ();
}
static cairo_perf_ticks_t
mosaic_fill_curves (cairo_t *cr, int width, int height)
{
return mosaic_perform (cr, MOSAIC_FILL | MOSAIC_CURVE_TO, width, height);
}
static cairo_perf_ticks_t
mosaic_fill_lines (cairo_t *cr, int width, int height)
{
return mosaic_perform (cr, MOSAIC_FILL | MOSAIC_LINE_TO, width, height);
}
static cairo_perf_ticks_t
mosaic_tessellate_lines (cairo_t *cr, int width, int height)
{
return mosaic_perform (cr, MOSAIC_TESSELLATE | MOSAIC_LINE_TO, width, height);
}
static cairo_perf_ticks_t
mosaic_tessellate_curves (cairo_t *cr, int width, int height)
{
return mosaic_perform (cr, MOSAIC_TESSELLATE | MOSAIC_CURVE_TO, width, height);
}
void
mosaic (cairo_perf_t *perf, cairo_t *cr, int width, int height)
{
cairo_perf_run (perf, "mosaic_fill_curves", mosaic_fill_curves);
cairo_perf_run (perf, "mosaic_fill_lines", mosaic_fill_lines);
cairo_perf_run (perf, "mosaic_tessellate_curves", mosaic_tessellate_curves);
cairo_perf_run (perf, "mosaic_tessellate_lines", mosaic_tessellate_lines);
}