#include #include #include #define NUM_RUNS 100 #define M_PI 3.14159265358979323846 static gboolean square = TRUE; void rounded_rectangle (cairo_t *cr, double x, double y, double w, double h, double radius) { cairo_move_to (cr, x+radius, y); cairo_arc (cr, x+w-radius, y+radius, radius, M_PI + M_PI / 2, M_PI * 2 ); cairo_arc (cr, x+w-radius, y+h-radius, radius, 0, M_PI / 2 ); cairo_arc (cr, x+radius, y+h-radius, radius, M_PI/2, M_PI ); cairo_arc (cr, x+radius, y+radius, radius, M_PI, 270 * M_PI / 180); } static void run_benchmark (GdkDrawable *drawable) { struct timeval before; struct timeval after; int i; int width; int height; cairo_t *cr; cairo_pattern_t *pattern; gdk_drawable_get_size (drawable, &width, &height); gettimeofday (&before, NULL); for (i=0; i < NUM_RUNS; i++) { cr = gdk_cairo_create (drawable); if (square) cairo_rectangle (cr, 0, 0, width, height); else rounded_rectangle (cr, 0, 0, width, height, 3.0); pattern = cairo_pattern_create_linear (0, 0, 0, height); cairo_pattern_add_color_stop_rgb (pattern, 0, 1, 0, 0); cairo_pattern_add_color_stop_rgb (pattern, 1, 0, 0, 0); cairo_set_source (cr, pattern); cairo_pattern_destroy (pattern); cairo_fill (cr); cairo_destroy (cr); } gdk_flush(); gettimeofday (&after, NULL); fprintf (stderr, "%g msec\n", (after.tv_sec - before.tv_sec) * 1000. + (after.tv_usec - before.tv_usec) / 1000.); } int main (int argc, char *argv[]) { GdkPixmap *pixmap; gtk_init (&argc, &argv); if (argc != 2) { g_printerr ("Usage: gradient-test [0/1] (0 == rounded, 1 == square)\n"); exit (1); } square = atoi (argv[1]); pixmap = gdk_pixmap_new (gdk_get_default_root_window (), 400, 300, -1); run_benchmark (pixmap); return 0; }