1#include <stdlib.h> 2#include "utils.h" 3 4#define SOURCE_WIDTH 320 5#define SOURCE_HEIGHT 240 6#define TEST_REPEATS 3 7 8static pixman_image_t * 9make_source (void) 10{ 11 size_t n_bytes = (SOURCE_WIDTH + 2) * (SOURCE_HEIGHT + 2) * 4; 12 uint32_t *data = malloc (n_bytes); 13 pixman_image_t *source; 14 15 prng_randmemset (data, n_bytes, 0); 16 17 source = pixman_image_create_bits ( 18 PIXMAN_a8r8g8b8, SOURCE_WIDTH + 2, SOURCE_HEIGHT + 2, 19 data, 20 (SOURCE_WIDTH + 2) * 4); 21 22 pixman_image_set_filter (source, PIXMAN_FILTER_BILINEAR, NULL, 0); 23 24 return source; 25} 26 27int 28main () 29{ 30 double scale; 31 pixman_image_t *src; 32 33 prng_srand (23874); 34 35 src = make_source (); 36 printf ("# %-6s %-22s %-14s %-12s\n", 37 "ratio", 38 "resolutions", 39 "time / ms", 40 "time per pixel / ns"); 41 for (scale = 0.1; scale < 10.005; scale += 0.01) 42 { 43 int i; 44 int dest_width = SOURCE_WIDTH * scale + 0.5; 45 int dest_height = SOURCE_HEIGHT * scale + 0.5; 46 int dest_byte_stride = (dest_width * 4 + 15) & ~15; 47 pixman_fixed_t s = (1 / scale) * 65536.0 + 0.5; 48 pixman_transform_t transform; 49 pixman_image_t *dest; 50 double t1, t2, t = -1; 51 uint32_t *dest_buf = aligned_malloc (16, dest_byte_stride * dest_height); 52 memset (dest_buf, 0, dest_byte_stride * dest_height); 53 54 pixman_transform_init_scale (&transform, s, s); 55 pixman_image_set_transform (src, &transform); 56 57 dest = pixman_image_create_bits ( 58 PIXMAN_a8r8g8b8, dest_width, dest_height, dest_buf, dest_byte_stride); 59 60 for (i = 0; i < TEST_REPEATS; i++) 61 { 62 t1 = gettime(); 63 pixman_image_composite ( 64 PIXMAN_OP_OVER, src, NULL, dest, 65 scale, scale, 0, 0, 0, 0, dest_width, dest_height); 66 t2 = gettime(); 67 if (t < 0 || t2 - t1 < t) 68 t = t2 - t1; 69 } 70 71 printf ("%6.2f : %4dx%-4d => %4dx%-4d : %12.4f : %12.4f\n", 72 scale, SOURCE_WIDTH, SOURCE_HEIGHT, dest_width, dest_height, 73 t * 1000, (t / (dest_width * dest_height)) * 1000000000); 74 75 pixman_image_unref (dest); 76 free (dest_buf); 77 } 78 79 return 0; 80} 81