static cairo_perf_ticks_t do_composite_checker (cairo_t *cr, int width, int height) { /* Compute zoom so that the src_pattern covers the whole output image. */ double xscale = width / (double) SRC_SIZE; double yscale = height / (double) SRC_SIZE; cairo_perf_timer_start (); cairo_identity_matrix (cr); /* Fill the surface with our background. */ cairo_set_source (cr, checkerboard); cairo_paint (cr); /* Draw the scaled image on top. */ cairo_scale (cr, xscale, yscale); cairo_set_source (cr, src_pattern); cairo_paint (cr); cairo_perf_timer_stop (); return cairo_perf_timer_elapsed (); }
static cairo_time_t do_curve_fill (cairo_t *cr, int width, int height, int loops) { state = 0xc0ffee; cairo_perf_timer_start (); while (loops--) { double x0 = uniform_random (0, width); double x1 = uniform_random (0, width); double x2 = uniform_random (0, width); double x3 = uniform_random (0, width); double xm = uniform_random (0, width); double xn = uniform_random (0, width); double y0 = uniform_random (0, height); double y1 = uniform_random (0, height); double y2 = uniform_random (0, height); double y3 = uniform_random (0, height); double ym = uniform_random (0, height); double yn = uniform_random (0, height); cairo_move_to (cr, xm, ym); cairo_curve_to (cr, x1, y1, x2, y2, xn, yn); cairo_curve_to (cr, x3, y3, x0, y0, xm, ym); cairo_close_path (cr); cairo_fill(cr); } cairo_perf_timer_stop (); return cairo_perf_timer_elapsed (); }
static cairo_time_t do_stroke (cairo_t *cr, int width, int height, int loops) { cairo_arc (cr, width/2.0, height/2.0, width/3.0, 0, 2 * M_PI); cairo_close_path (cr); cairo_set_line_width (cr, width/5.0); cairo_perf_timer_start (); cairo_perf_set_thread_aware (cr, FALSE); while (loops--) { if (loops == 0) cairo_perf_set_thread_aware (cr, TRUE); cairo_stroke_preserve (cr); } cairo_perf_timer_stop (); cairo_new_path (cr); return cairo_perf_timer_elapsed (); }
static cairo_perf_ticks_t do_long_dashed_lines (cairo_t *cr, int width, int height, int loops) { double dash[2] = { 2.0, 2.0 }; int i; cairo_save (cr); cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); cairo_paint (cr); cairo_set_source_rgb (cr, 1.0, 0.0, 0.0); cairo_set_dash (cr, dash, 2, 0.0); cairo_new_path (cr); cairo_set_line_width (cr, 1.0); for (i = 0; i < height-1; i++) { double y0 = (double) i + 0.5; cairo_move_to (cr, 0.0, y0); cairo_line_to (cr, width, y0); } cairo_perf_timer_start (); while (loops--) cairo_stroke_preserve (cr); cairo_perf_timer_stop (); cairo_restore (cr); return cairo_perf_timer_elapsed (); }
static cairo_time_t do_text (cairo_t *cr, int width, int height, int loops) { const char text[] = "the jay, pig, fox, zebra and my wolves quack"; int len = strlen (text); double x, y; int i = 0, j = 0; cairo_set_font_size (cr, 9); cairo_perf_timer_start (); cairo_perf_set_thread_aware (cr, FALSE); while (loops--) { if (loops == 0) cairo_perf_set_thread_aware (cr, TRUE); do { cairo_move_to (cr, 0, j++ * 10); cairo_show_text (cr, text + i); cairo_get_current_point (cr, &x, &y); while (x < width && cairo_status (cr) == CAIRO_STATUS_SUCCESS) { cairo_show_text (cr, text); cairo_get_current_point (cr, &x, &y); } if (++i >= len) i = 0; } while (y < height && cairo_status (cr) == CAIRO_STATUS_SUCCESS); } cairo_perf_timer_stop (); return cairo_perf_timer_elapsed (); }
static cairo_time_t box_outline_aa_stroke (cairo_t *cr, int width, int height, int loops) { cairo_set_source_rgb (cr, 0, 0, 1); /* blue */ cairo_paint (cr); cairo_translate (cr, .5, .5); cairo_rectangle (cr, 1.5, 1.5, width - 3, height - 3); cairo_set_line_width (cr, 1.0); cairo_set_source_rgb (cr, 1, 0, 0); /* red */ cairo_perf_timer_start (); cairo_perf_set_thread_aware (cr, FALSE); while (loops--) { if (loops == 0) cairo_perf_set_thread_aware (cr, TRUE); cairo_stroke_preserve (cr); } cairo_perf_timer_stop (); cairo_new_path (cr); return cairo_perf_timer_elapsed (); }
static cairo_perf_ticks_t box_outline_fill (cairo_t *cr, int width, int height, int loops) { cairo_set_source_rgb (cr, 0, 0, 1); /* blue */ cairo_paint (cr); cairo_rectangle (cr, 1.0, 1.0, width - 2, height - 2); cairo_rectangle (cr, 2.0, 2.0, width - 4, height - 4); cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD); cairo_set_source_rgb (cr, 0, 1, 0); /* green */ cairo_perf_timer_start (); while (loops--) cairo_fill_preserve (cr); cairo_perf_timer_stop (); cairo_new_path (cr); return cairo_perf_timer_elapsed (); }
static cairo_time_t draw (cairo_t *cr, int width, int height, int loops) { int t_height = height/2; int t_width = t_height / m_1_sqrt_3; cairo_set_source_rgb (cr, 1, 1, 1); cairo_paint (cr); cairo_set_source_rgb (cr, 0, 0, 0); cairo_set_line_width (cr, 1.); cairo_perf_timer_start (); cairo_perf_set_thread_aware (cr, FALSE); while (loops--) { if (loops == 0) cairo_perf_set_thread_aware (cr, TRUE); cairo_save (cr); T (cr, t_width); cairo_translate (cr, 0, height); cairo_scale (cr, 1, -1); T (cr, t_width); cairo_stroke (cr); cairo_restore (cr); } cairo_perf_timer_stop (); return cairo_perf_timer_elapsed (); }
static cairo_time_t box_outline_aa_fill (cairo_t *cr, int width, int height, int loops) { cairo_set_source_rgb (cr, 0, 0, 1); /* blue */ cairo_paint (cr); cairo_translate (cr, .5, .5); cairo_rectangle (cr, 1.0, 1.0, width - 2, height - 2); cairo_rectangle (cr, 2.0, 2.0, width - 4, height - 4); cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD); cairo_set_source_rgb (cr, 0, 1, 0); /* green */ cairo_perf_timer_start (); cairo_perf_set_thread_aware (cr, FALSE); while (loops--) { if (loops == 0) cairo_perf_set_thread_aware (cr, TRUE); cairo_fill_preserve (cr); } cairo_perf_timer_stop (); cairo_new_path (cr); return cairo_perf_timer_elapsed (); }
static cairo_time_t do_curve_stroke (cairo_t *cr, int width, int height, int loops) { state = 0xc0ffee; cairo_set_line_width (cr, 2.); cairo_perf_timer_start (); cairo_perf_set_thread_aware (cr, FALSE); while (loops--) { if (loops == 0) cairo_perf_set_thread_aware (cr, TRUE); double x1 = uniform_random (0, width); double x2 = uniform_random (0, width); double x3 = uniform_random (0, width); double y1 = uniform_random (0, height); double y2 = uniform_random (0, height); double y3 = uniform_random (0, height); cairo_move_to (cr, uniform_random (0, width), uniform_random (0, height)); cairo_curve_to (cr, x1, y1, x2, y2, x3, y3); cairo_stroke(cr); } cairo_perf_timer_stop (); return cairo_perf_timer_elapsed (); }
static cairo_time_t do_unaligned_clip (cairo_t *cr, int width, int height, int loops) { cairo_perf_timer_start (); cairo_perf_set_thread_aware (cr, FALSE); while (loops--) { if (loops == 0) cairo_perf_set_thread_aware (cr, TRUE); cairo_save (cr); /* First a triangular clip that obviously isn't along device-pixel * boundaries. */ cairo_move_to (cr, 50, 50); cairo_line_to (cr, 50, 90); cairo_line_to (cr, 90, 90); cairo_close_path (cr); cairo_clip (cr); /* Then a rectangular clip that would be but for the non-integer * scaling. */ cairo_scale (cr, 1.1, 1.1); cairo_rectangle (cr, 55, 55, 35, 35); cairo_clip (cr); /* And paint something to force the clip to be evaluated. */ cairo_paint (cr); cairo_restore (cr); } cairo_perf_timer_stop (); return cairo_perf_timer_elapsed (); }
static cairo_time_t do_pattern_create_radial (cairo_t *cr, int width, int height, int loops) { cairo_perf_timer_start (); cairo_perf_set_thread_aware (cr, FALSE); while (loops--) { cairo_pattern_t *pattern; int i; if (loops == 0) cairo_perf_set_thread_aware (cr, TRUE); for (i = 0; i < RADIALS_COUNT; i++) { pattern = cairo_pattern_create_radial (radials[i].cx0, radials[i].cy0, radials[i].radius0, radials[i].cx1, radials[i].cy1, radials[i].radius1); cairo_pattern_destroy (pattern); } } cairo_perf_timer_stop (); return cairo_perf_timer_elapsed (); }
static cairo_time_t do_wide_fills (cairo_t *cr, int width, int height, int loops) { int count; /* lots and lots of overlapping stroke-like fills */ state = 0xc0ffee; for (count = 0; count < 1000; count++) { cairo_save (cr); cairo_translate (cr, uniform_random (0, width), uniform_random (0, height)); cairo_rotate (cr, uniform_random (-M_PI,M_PI)); cairo_rectangle (cr, 0, 0, uniform_random (0, width), 5); cairo_restore (cr); } cairo_perf_timer_start (); while (loops--) cairo_fill_preserve (cr); cairo_perf_timer_stop (); cairo_new_path (cr); return cairo_perf_timer_elapsed (); }
static cairo_time_t do_strokes (cairo_t *cr, int width, int height, int loops) { /* a pair of overlapping rectangles */ rounded_rectangle (cr, 2, 2, width/2. + 10, height/2. + 10, 10); rounded_rectangle (cr, width/2. - 10, height/2. - 10, width/2. - 2, height/2. - 2, 10); cairo_set_line_width (cr, 2.); cairo_perf_timer_start (); cairo_perf_set_thread_aware (cr, FALSE); while (loops--) { if (loops == 0) cairo_perf_set_thread_aware (cr, TRUE); cairo_stroke_preserve (cr); } cairo_perf_timer_stop (); cairo_new_path (cr); return cairo_perf_timer_elapsed (); }
static cairo_time_t draw_spiral_stroke (cairo_t *cr, align_t align, int width, int height, int loops) { const int step = 3; int side = width < height ? width : height; cairo_save (cr); cairo_set_source_rgb (cr, 0, 0, 0); cairo_paint (cr); cairo_translate (cr, 1, 1); cairo_set_source_rgb (cr, 1, 0, 0); cairo_set_line_width (cr, 4.); cairo_set_line_join (cr, CAIRO_LINE_JOIN_MITER); cairo_set_line_cap (cr, CAIRO_LINE_CAP_BUTT); cairo_new_path (cr); switch (align) { case PIXALIGN: cairo_move_to (cr, 0,0); break; case NONALIGN: cairo_move_to (cr, 0.1415926, 0.7182818); break; } while (side >= step) { cairo_rel_line_to (cr, 0, side); side -= step; if (side <= 0) break; cairo_rel_line_to (cr, side, 0); side -= step; if (side <= 0) break; cairo_rel_line_to (cr, 0, -side); side -= step; if (side <= 0) break; cairo_rel_line_to (cr, -side, 0); side -= step; if (side <= 0) break; } cairo_perf_timer_start (); cairo_perf_set_thread_aware (cr, FALSE); while (loops--) { if (loops == 0) cairo_perf_set_thread_aware (cr, TRUE); cairo_stroke_preserve (cr); } cairo_perf_timer_stop (); cairo_restore (cr); return cairo_perf_timer_elapsed (); }
static cairo_perf_ticks_t do_world_map (cairo_t *cr, int width, int height, int loops) { const wm_element_t *e; double cx, cy; cairo_set_line_width (cr, 0.2); cairo_perf_timer_start (); while (loops--) { cairo_set_source_rgb (cr, .68, .85, .90); /* lightblue */ cairo_rectangle (cr, 0, 0, 800, 400); cairo_fill (cr); e = &countries[0]; while (1) { switch (e->type) { case WM_NEW_PATH: case WM_END: cairo_set_source_rgb (cr, .75, .75, .75); /* silver */ cairo_fill_preserve (cr); cairo_set_source_rgb (cr, .50, .50, .50); /* gray */ cairo_stroke (cr); cairo_move_to (cr, e->x, e->y); break; case WM_MOVE_TO: cairo_close_path (cr); cairo_move_to (cr, e->x, e->y); break; case WM_LINE_TO: cairo_line_to (cr, e->x, e->y); break; case WM_HLINE_TO: cairo_get_current_point (cr, &cx, &cy); cairo_line_to (cr, e->x, cy); break; case WM_VLINE_TO: cairo_get_current_point (cr, &cx, &cy); cairo_line_to (cr, cx, e->y); break; case WM_REL_LINE_TO: cairo_rel_line_to (cr, e->x, e->y); break; } if (e->type == WM_END) break; e++; } cairo_new_path (cr); } cairo_perf_timer_stop (); return cairo_perf_timer_elapsed (); }
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); /* red */ } else { outer_width = width; outer_height = height; cairo_set_source_rgb (cr, 0.0, 1.0, 0.0); /* green */ } 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 do_rectangle (cairo_t *cr, int width, int height) { cairo_perf_timer_start (); cairo_rectangle (cr, 0, 0, width, height); cairo_fill (cr); cairo_perf_timer_stop (); return cairo_perf_timer_elapsed (); }
static cairo_perf_ticks_t do_paint_with_alpha (cairo_t *cr, int width, int height, int loops) { cairo_perf_timer_start (); while (loops--) cairo_paint_with_alpha (cr, 0.5); cairo_perf_timer_stop (); return cairo_perf_timer_elapsed (); }
static cairo_perf_ticks_t do_subimage_copy (cairo_t *cr, int width, int height) { cairo_rectangle (cr, 2, 2, 4, 4); cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); cairo_perf_timer_start (); cairo_fill (cr); cairo_perf_timer_stop (); return cairo_perf_timer_elapsed (); }
static cairo_perf_ticks_t do_fill (cairo_t *cr, int width, int height) { cairo_arc (cr, width/2.0, height/2.0, width/3.0, 0, 2 * M_PI); cairo_perf_timer_start (); cairo_fill (cr); cairo_perf_timer_stop (); return cairo_perf_timer_elapsed (); }
static cairo_time_t do_rectangle (cairo_t *cr, int width, int height, int loops) { cairo_perf_timer_start (); cairo_perf_set_thread_aware (cr, FALSE); while (loops--) { if (loops == 0) cairo_perf_set_thread_aware (cr, TRUE); rounded_rectangle (cr, 0, 0, width, height, 3.0); cairo_fill (cr); } cairo_perf_timer_stop (); return cairo_perf_timer_elapsed (); }
static cairo_time_t draw_random_curve (cairo_t *cr, cairo_fill_rule_t fill_rule, int width, int height, int loops) { double x[3*NUM_SEGMENTS]; double y[3*NUM_SEGMENTS]; int i; cairo_save (cr); cairo_set_source_rgb (cr, 0, 0, 0); cairo_paint (cr); for (i = 0; i < 3*NUM_SEGMENTS; i++) { x[i] = uniform_random (0, width); y[i] = uniform_random (0, height); } state = 0x12345678; cairo_translate (cr, 1, 1); cairo_set_fill_rule (cr, fill_rule); cairo_set_source_rgb (cr, 1, 0, 0); cairo_new_path (cr); cairo_move_to (cr, 0, 0); for (i = 0; i < NUM_SEGMENTS; i++) { cairo_curve_to (cr, x[3*i+0], y[3*i+0], x[3*i+1], y[3*i+1], x[3*i+2], y[3*i+2]); } cairo_close_path (cr); cairo_perf_timer_start (); cairo_perf_set_thread_aware (cr, FALSE); while (loops--) { if (loops == 0) cairo_perf_set_thread_aware (cr, TRUE); cairo_fill_preserve (cr); } cairo_perf_timer_stop (); cairo_restore (cr); return cairo_perf_timer_elapsed (); }
static cairo_time_t diagonal (cairo_t *cr, int width, int height, int loops) { cairo_move_to (cr, 0, 0); cairo_line_to (cr, width, height); cairo_perf_timer_start (); while (loops--) cairo_stroke_preserve (cr); cairo_perf_timer_stop (); cairo_new_path (cr); return cairo_perf_timer_elapsed (); }
static cairo_perf_ticks_t zrusin_another_fill (cairo_t *cr, int width, int height, int loops) { zrusin_another_path (cr); cairo_set_source_rgb (cr, 0.0, 0.0, 0.8); /* blue */ cairo_perf_timer_start (); while (loops--) cairo_fill_preserve (cr); cairo_perf_timer_stop (); cairo_new_path (cr); return cairo_perf_timer_elapsed (); }
static cairo_perf_ticks_t do_rectangles (cairo_t *cr, int width, int height) { int i; cairo_perf_timer_start (); for (i = 0; i < RECTANGLE_COUNT; i++) { cairo_rectangle (cr, rects[i].x, rects[i].y, rects[i].width, rects[i].height); cairo_fill (cr); } cairo_perf_timer_stop (); return cairo_perf_timer_elapsed (); }
static cairo_perf_ticks_t mosaic_perform(cairo_t *cr, unsigned flags, int width, int height, int loops) { struct mosaic_region_iter iter; /* Scale to fit the window.*/ 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); /* Iterate over all closed regions in the mosaic filling or * tessellating them as dictated by the flags. */ cairo_perf_timer_start (); while (loops--) { mosaic_region_iter_init (&iter, flags & MOSAIC_CURVE_TO); 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_time_t vertical (cairo_t *cr, int width, int height, int loops) { double w = width/2 + .5; cairo_move_to (cr, w, 0); cairo_line_to (cr, w, height); cairo_perf_timer_start (); while (loops--) cairo_stroke_preserve (cr); cairo_perf_timer_stop (); cairo_new_path (cr); return cairo_perf_timer_elapsed (); }
static cairo_time_t nearly_horizontal (cairo_t *cr, int width, int height, int loops) { double h = height/2; cairo_move_to (cr, 0, h); cairo_line_to (cr, width, h+1); cairo_perf_timer_start (); while (loops--) cairo_stroke_preserve (cr); cairo_perf_timer_stop (); cairo_new_path (cr); return cairo_perf_timer_elapsed (); }
static cairo_perf_ticks_t do_fill (cairo_t *cr, int width, int height, int loops) { cairo_arc (cr, width/2.0, height/2.0, width/3.0, 0, 2 * M_PI); cairo_perf_timer_start (); while (loops--) cairo_fill_preserve (cr); cairo_perf_timer_stop (); cairo_new_path (cr); return cairo_perf_timer_elapsed (); }