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