1 #include <assert.h> 2 #include <stdlib.h> 3 #include <stdio.h> 4 #include "utils.h" 5 6 int 7 main () 8 { 9 pixman_region32_t r1; 10 pixman_region32_t r2; 11 pixman_region32_t r3; 12 pixman_box32_t boxes[] = { 13 { 10, 10, 20, 20 }, 14 { 30, 30, 30, 40 }, 15 { 50, 45, 60, 44 }, 16 }; 17 pixman_box32_t boxes2[] = { 18 { 2, 6, 7, 6 }, 19 { 4, 1, 6, 7 }, 20 }; 21 pixman_box32_t boxes3[] = { 22 { 2, 6, 7, 6 }, 23 { 4, 1, 6, 1 }, 24 }; 25 int i, j; 26 pixman_box32_t *b; 27 pixman_image_t *image, *fill; 28 pixman_color_t white = { 29 0xffff, 30 0xffff, 31 0xffff, 32 0xffff 33 }; 34 35 prng_srand (0); 36 37 /* This used to go into an infinite loop before pixman-region.c 38 * was fixed to not use explict "short" variables 39 */ 40 pixman_region32_init_rect (&r1, 0, 0, 20, 64000); 41 pixman_region32_init_rect (&r2, 0, 0, 20, 64000); 42 pixman_region32_init_rect (&r3, 0, 0, 20, 64000); 43 44 pixman_region32_subtract (&r1, &r2, &r3); 45 46 47 /* This would produce a region containing an empty 48 * rectangle in it. Such regions are considered malformed, 49 * but using an empty rectangle for initialization should 50 * work. 51 */ 52 pixman_region32_init_rects (&r1, boxes, 3); 53 54 b = pixman_region32_rectangles (&r1, &i); 55 56 assert (i == 1); 57 58 while (i--) 59 { 60 assert (b[i].x1 < b[i].x2); 61 assert (b[i].y1 < b[i].y2); 62 } 63 64 /* This would produce a rectangle containing the bounding box 65 * of the two rectangles. The correct result is to eliminate 66 * the broken rectangle. 67 */ 68 pixman_region32_init_rects (&r1, boxes2, 2); 69 70 b = pixman_region32_rectangles (&r1, &i); 71 72 assert (i == 1); 73 74 assert (b[0].x1 == 4); 75 assert (b[0].y1 == 1); 76 assert (b[0].x2 == 6); 77 assert (b[0].y2 == 7); 78 79 /* This should produce an empty region */ 80 pixman_region32_init_rects (&r1, boxes3, 2); 81 82 b = pixman_region32_rectangles (&r1, &i); 83 84 assert (i == 0); 85 86 fill = pixman_image_create_solid_fill (&white); 87 for (i = 0; i < 100; i++) 88 { 89 int image_size = 128; 90 91 pixman_region32_init (&r1); 92 93 /* Add some random rectangles */ 94 for (j = 0; j < 64; j++) 95 pixman_region32_union_rect (&r1, &r1, 96 prng_rand_n (image_size), 97 prng_rand_n (image_size), 98 prng_rand_n (25), 99 prng_rand_n (25)); 100 101 /* Clip to image size */ 102 pixman_region32_init_rect (&r2, 0, 0, image_size, image_size); 103 pixman_region32_intersect (&r1, &r1, &r2); 104 pixman_region32_fini (&r2); 105 106 /* render region to a1 mask */ 107 image = pixman_image_create_bits (PIXMAN_a1, image_size, image_size, NULL, 0); 108 pixman_image_set_clip_region32 (image, &r1); 109 pixman_image_composite32 (PIXMAN_OP_SRC, 110 fill, NULL, image, 111 0, 0, 0, 0, 0, 0, 112 image_size, image_size); 113 pixman_region32_init_from_image (&r2, image); 114 115 pixman_image_unref (image); 116 117 assert (pixman_region32_equal (&r1, &r2)); 118 pixman_region32_fini (&r1); 119 pixman_region32_fini (&r2); 120 121 } 122 pixman_image_unref (fill); 123 124 return 0; 125 } 126