diff options
author | marha <marha@users.sourceforge.net> | 2015-04-20 21:25:25 +0200 |
---|---|---|
committer | marha <marha@users.sourceforge.net> | 2015-04-20 21:25:25 +0200 |
commit | 4ba9be2882d9f1567809edb0a31fcdf11320d41f (patch) | |
tree | f796ab7a5044f9dd99aac7cb9a7c836857987635 /pixman/test | |
parent | 82c8df11062f72a7d467e26cedbbd8b322ff7a70 (diff) | |
download | vcxsrv-4ba9be2882d9f1567809edb0a31fcdf11320d41f.tar.gz vcxsrv-4ba9be2882d9f1567809edb0a31fcdf11320d41f.tar.bz2 vcxsrv-4ba9be2882d9f1567809edb0a31fcdf11320d41f.zip |
randrproto xkeyboard-config fontconfig libX11 libXdmcp libXmu pixman xkbcomp xserver mesa git update 20 Apr 2015
xserver commit b1029716e41e252f149b82124a149da180607c96
xkeyboard-config commit 7d00bcc2d9c3944bbdfcbe472ee3299729dc7687
libX11 commit 748d47e69f5c12d8557d56a8a8ec166588da7b93
libXdmcp commit b10f382e3aa2e86cd5a2bc27d6758da55f0ab1f6
xkbcomp commit 1ae525b3d236b59e6437b2b5433d460e18370973
pixman commit 58e21d3e45c5227c2ca9ac00cf044f22a7975180
randrproto commit 98da0d6e48b7d124d6788ea568e9f9e3dc204322
libXmu commit 4459e6940fe3fdf26a8d5d4c71989498bc400a62
fontconfig commit 07be485a0a84995ce69bf60e3b1bb22cb35f6b0e
mesa commit c1485f4b7d044724b3dbc1011f3c3a8a53132010
Diffstat (limited to 'pixman/test')
-rw-r--r-- | pixman/test/check-formats.c | 192 | ||||
-rw-r--r-- | pixman/test/lowlevel-blt-bench.c | 299 | ||||
-rw-r--r-- | pixman/test/utils.c | 463 | ||||
-rw-r--r-- | pixman/test/utils.h | 12 |
4 files changed, 612 insertions, 354 deletions
diff --git a/pixman/test/check-formats.c b/pixman/test/check-formats.c index 8eb263b77..4e2633c41 100644 --- a/pixman/test/check-formats.c +++ b/pixman/test/check-formats.c @@ -104,198 +104,6 @@ check_op (pixman_op_t op, return retval; } -static const pixman_op_t op_list[] = -{ - PIXMAN_OP_CLEAR, - PIXMAN_OP_SRC, - PIXMAN_OP_DST, - PIXMAN_OP_OVER, - PIXMAN_OP_OVER_REVERSE, - PIXMAN_OP_IN, - PIXMAN_OP_IN_REVERSE, - PIXMAN_OP_OUT, - PIXMAN_OP_OUT_REVERSE, - PIXMAN_OP_ATOP, - PIXMAN_OP_ATOP_REVERSE, - PIXMAN_OP_XOR, - PIXMAN_OP_ADD, - PIXMAN_OP_SATURATE, - - PIXMAN_OP_DISJOINT_CLEAR, - PIXMAN_OP_DISJOINT_SRC, - PIXMAN_OP_DISJOINT_DST, - PIXMAN_OP_DISJOINT_OVER, - PIXMAN_OP_DISJOINT_OVER_REVERSE, - PIXMAN_OP_DISJOINT_IN, - PIXMAN_OP_DISJOINT_IN_REVERSE, - PIXMAN_OP_DISJOINT_OUT, - PIXMAN_OP_DISJOINT_OUT_REVERSE, - PIXMAN_OP_DISJOINT_ATOP, - PIXMAN_OP_DISJOINT_ATOP_REVERSE, - PIXMAN_OP_DISJOINT_XOR, - - PIXMAN_OP_CONJOINT_CLEAR, - PIXMAN_OP_CONJOINT_SRC, - PIXMAN_OP_CONJOINT_DST, - PIXMAN_OP_CONJOINT_OVER, - PIXMAN_OP_CONJOINT_OVER_REVERSE, - PIXMAN_OP_CONJOINT_IN, - PIXMAN_OP_CONJOINT_IN_REVERSE, - PIXMAN_OP_CONJOINT_OUT, - PIXMAN_OP_CONJOINT_OUT_REVERSE, - PIXMAN_OP_CONJOINT_ATOP, - PIXMAN_OP_CONJOINT_ATOP_REVERSE, - PIXMAN_OP_CONJOINT_XOR, - - PIXMAN_OP_MULTIPLY, - PIXMAN_OP_SCREEN, - PIXMAN_OP_OVERLAY, - PIXMAN_OP_DARKEN, - PIXMAN_OP_LIGHTEN, - PIXMAN_OP_COLOR_DODGE, - PIXMAN_OP_COLOR_BURN, - PIXMAN_OP_HARD_LIGHT, - PIXMAN_OP_SOFT_LIGHT, - PIXMAN_OP_DIFFERENCE, - PIXMAN_OP_EXCLUSION, - PIXMAN_OP_HSL_HUE, - PIXMAN_OP_HSL_SATURATION, - PIXMAN_OP_HSL_COLOR, - PIXMAN_OP_HSL_LUMINOSITY -}; - -static const pixman_format_code_t format_list[] = -{ - PIXMAN_a8r8g8b8, - PIXMAN_x8r8g8b8, - PIXMAN_a8b8g8r8, - PIXMAN_x8b8g8r8, - PIXMAN_b8g8r8a8, - PIXMAN_b8g8r8x8, - PIXMAN_r8g8b8a8, - PIXMAN_r8g8b8x8, - PIXMAN_x14r6g6b6, - PIXMAN_x2r10g10b10, - PIXMAN_a2r10g10b10, - PIXMAN_x2b10g10r10, - PIXMAN_a2b10g10r10, - PIXMAN_a8r8g8b8_sRGB, - PIXMAN_r8g8b8, - PIXMAN_b8g8r8, - PIXMAN_r5g6b5, - PIXMAN_b5g6r5, - PIXMAN_a1r5g5b5, - PIXMAN_x1r5g5b5, - PIXMAN_a1b5g5r5, - PIXMAN_x1b5g5r5, - PIXMAN_a4r4g4b4, - PIXMAN_x4r4g4b4, - PIXMAN_a4b4g4r4, - PIXMAN_x4b4g4r4, - PIXMAN_a8, - PIXMAN_r3g3b2, - PIXMAN_b2g3r3, - PIXMAN_a2r2g2b2, - PIXMAN_a2b2g2r2, - PIXMAN_x4a4, - PIXMAN_a4, - PIXMAN_r1g2b1, - PIXMAN_b1g2r1, - PIXMAN_a1r1g1b1, - PIXMAN_a1b1g1r1, - PIXMAN_a1, -}; - -static pixman_format_code_t -format_from_string (const char *s) -{ - int i; - - for (i = 0; i < ARRAY_LENGTH (format_list); ++i) - { - if (strcasecmp (format_name (format_list[i]), s) == 0) - return format_list[i]; - } - - return PIXMAN_null; -} - -static void -emit (const char *s, int *n_chars) -{ - *n_chars += printf ("%s,", s); - if (*n_chars > 60) - { - printf ("\n "); - *n_chars = 0; - } - else - { - printf (" "); - (*n_chars)++; - } -} - -static void -list_formats (void) -{ - int n_chars; - int i; - - printf ("Formats:\n "); - - n_chars = 0; - for (i = 0; i < ARRAY_LENGTH (format_list); ++i) - emit (format_name (format_list[i]), &n_chars); - - printf ("\n\n"); -} - -static void -list_operators (void) -{ - char short_name [128] = { 0 }; - int i, n_chars; - - printf ("Operators:\n "); - - n_chars = 0; - for (i = 0; i < ARRAY_LENGTH (op_list); ++i) - { - pixman_op_t op = op_list[i]; - int j; - - snprintf (short_name, sizeof (short_name) - 1, "%s", - operator_name (op) + strlen ("PIXMAN_OP_")); - - for (j = 0; short_name[j] != '\0'; ++j) - short_name[j] = tolower (short_name[j]); - - emit (short_name, &n_chars); - } - - printf ("\n\n"); -} - -static pixman_op_t -operator_from_string (const char *s) -{ - char full_name[128] = { 0 }; - int i; - - snprintf (full_name, (sizeof full_name) - 1, "PIXMAN_OP_%s", s); - - for (i = 0; i < ARRAY_LENGTH (op_list); ++i) - { - pixman_op_t op = op_list[i]; - - if (strcasecmp (operator_name (op), full_name) == 0) - return op; - } - - return PIXMAN_OP_NONE; -} - int main (int argc, char **argv) { diff --git a/pixman/test/lowlevel-blt-bench.c b/pixman/test/lowlevel-blt-bench.c index 3da094a2b..aff460874 100644 --- a/pixman/test/lowlevel-blt-bench.c +++ b/pixman/test/lowlevel-blt-bench.c @@ -367,14 +367,14 @@ bench_RT (pixman_op_t op, } void -bench_composite (char * testname, - int src_fmt, - int src_flags, - int op, - int mask_fmt, - int mask_flags, - int dst_fmt, - double npix) +bench_composite (const char *testname, + int src_fmt, + int src_flags, + int op, + int mask_fmt, + int mask_flags, + int dst_fmt, + double npix) { pixman_image_t * src_img; pixman_image_t * dst_img; @@ -587,7 +587,7 @@ bench_composite (char * testname, #define PIXMAN_OP_OUT_REV (PIXMAN_OP_OUT_REVERSE) -struct +struct test_entry { char *testname; int src_fmt; @@ -596,8 +596,11 @@ struct int mask_fmt; int mask_flags; int dst_fmt; -} -tests_tbl[] = +}; + +typedef struct test_entry test_entry_t; + +static const test_entry_t tests_tbl[] = { { "add_8_8_8", PIXMAN_a8, 0, PIXMAN_OP_ADD, PIXMAN_a8, 0, PIXMAN_a8 }, { "add_n_8_8", PIXMAN_a8r8g8b8, 1, PIXMAN_OP_ADD, PIXMAN_a8, 0, PIXMAN_a8 }, @@ -719,6 +722,260 @@ tests_tbl[] = { "rpixbuf", PIXMAN_x8b8g8r8, 0, PIXMAN_OP_SRC, PIXMAN_a8b8g8r8, 0, PIXMAN_a8b8g8r8 }, }; +static const test_entry_t special_patterns[] = +{ + { "add_n_2x10", PIXMAN_a2r10g10b10, 1, PIXMAN_OP_ADD, PIXMAN_null, 0, PIXMAN_x2r10g10b10 }, + { "add_n_2a10", PIXMAN_a2r10g10b10, 1, PIXMAN_OP_ADD, PIXMAN_null, 0, PIXMAN_a2r10g10b10 }, + { "src_n_2x10", PIXMAN_a2r10g10b10, 1, PIXMAN_OP_SRC, PIXMAN_null, 0, PIXMAN_x2r10g10b10 }, + { "src_n_2a10", PIXMAN_a2r10g10b10, 1, PIXMAN_OP_SRC, PIXMAN_null, 0, PIXMAN_a2r10g10b10 }, + { "src_0888_8888_rev", PIXMAN_b8g8r8, 0, PIXMAN_OP_SRC, PIXMAN_null, 0, PIXMAN_x8r8g8b8 }, + { "src_0888_0565_rev", PIXMAN_b8g8r8, 0, PIXMAN_OP_SRC, PIXMAN_null, 0, PIXMAN_r5g6b5 }, + { "src_n_8", PIXMAN_a8, 1, PIXMAN_OP_SRC, PIXMAN_null, 0, PIXMAN_a8 }, + { "pixbuf", PIXMAN_x8b8g8r8, 0, PIXMAN_OP_SRC, PIXMAN_a8b8g8r8, 0, PIXMAN_a8r8g8b8 }, + { "rpixbuf", PIXMAN_x8b8g8r8, 0, PIXMAN_OP_SRC, PIXMAN_a8b8g8r8, 0, PIXMAN_a8b8g8r8 }, +}; + +/* Returns the sub-string's end pointer in string. */ +static const char * +copy_sub_string (char *buf, + const char *string, + const char *scan_from, + const char *end) +{ + const char *delim; + size_t n; + + delim = strchr (scan_from, '_'); + if (!delim) + delim = end; + + n = delim - string; + strncpy(buf, string, n); + buf[n] = '\0'; + + return delim; +} + +static pixman_op_t +parse_longest_operator (char *buf, const char **strp, const char *end) +{ + const char *p = *strp; + const char *sub_end; + const char *best_end = p; + pixman_op_t best_op = PIXMAN_OP_NONE; + pixman_op_t op; + + while (p < end) + { + sub_end = copy_sub_string (buf, *strp, p, end); + op = operator_from_string (buf); + p = sub_end + 1; + + if (op != PIXMAN_OP_NONE) + { + best_end = p; + best_op = op; + } + } + + *strp = best_end; + return best_op; +} + +static pixman_format_code_t +parse_format (char *buf, const char **p, const char *end) +{ + pixman_format_code_t format; + const char *delim; + + if (*p >= end) + return PIXMAN_null; + + delim = copy_sub_string (buf, *p, *p, end); + format = format_from_string (buf); + + if (format != PIXMAN_null) + *p = delim + 1; + + return format; +} + +static int +parse_test_pattern (test_entry_t *test, const char *pattern) +{ + const char *p = pattern; + const char *end = pattern + strlen (pattern); + char buf[1024]; + pixman_format_code_t format[3]; + int i; + + if (strlen (pattern) > sizeof (buf) - 1) + return -1; + + /* Special cases that the parser cannot produce. */ + for (i = 0; i < ARRAY_LENGTH (special_patterns); i++) + { + if (strcmp (pattern, special_patterns[i].testname) == 0) + { + *test = special_patterns[i]; + return 0; + } + } + + /* Extract operator, may contain delimiters, + * so take the longest string that matches. + */ + test->op = parse_longest_operator (buf, &p, end); + if (test->op == PIXMAN_OP_NONE) + return -1; + + /* extract up to three pixel formats */ + format[0] = parse_format (buf, &p, end); + format[1] = parse_format (buf, &p, end); + format[2] = parse_format (buf, &p, end); + + if (format[0] == PIXMAN_null || format[1] == PIXMAN_null) + return -1; + + /* recognize CA flag */ + test->mask_flags = 0; + if (p < end) + { + if (strcmp (p, "ca") == 0) + test->mask_flags |= CA_FLAG; + else + return -1; /* trailing garbage */ + } + + test->src_fmt = format[0]; + if (format[2] == PIXMAN_null) + { + test->mask_fmt = PIXMAN_null; + test->dst_fmt = format[1]; + } + else + { + test->mask_fmt = format[1]; + test->dst_fmt = format[2]; + } + + test->src_flags = 0; + if (test->src_fmt == PIXMAN_solid) + { + test->src_fmt = PIXMAN_a8r8g8b8; + test->src_flags |= SOLID_FLAG; + } + + if (test->mask_fmt == PIXMAN_solid) + { + if (test->mask_flags & CA_FLAG) + test->mask_fmt = PIXMAN_a8r8g8b8; + else + test->mask_fmt = PIXMAN_a8; + + test->mask_flags |= SOLID_FLAG; + } + + return 0; +} + +static int +check_int (int got, int expected, const char *name, const char *field) +{ + if (got == expected) + return 0; + + printf ("%s: %s failure: expected %d, got %d.\n", + name, field, expected, got); + + return 1; +} + +static int +check_format (int got, int expected, const char *name, const char *field) +{ + if (got == expected) + return 0; + + printf ("%s: %s failure: expected %s (%#x), got %s (%#x).\n", + name, field, + format_name (expected), expected, + format_name (got), got); + + return 1; +} + +static void +parser_self_test (void) +{ + const test_entry_t *ent; + test_entry_t test; + int fails = 0; + int i; + + for (i = 0; i < ARRAY_LENGTH (tests_tbl); i++) + { + ent = &tests_tbl[i]; + + if (parse_test_pattern (&test, ent->testname) < 0) + { + printf ("parsing failed for '%s'\n", ent->testname); + fails++; + continue; + } + + fails += check_format (test.src_fmt, ent->src_fmt, + ent->testname, "src_fmt"); + fails += check_format (test.mask_fmt, ent->mask_fmt, + ent->testname, "mask_fmt"); + fails += check_format (test.dst_fmt, ent->dst_fmt, + ent->testname, "dst_fmt"); + fails += check_int (test.src_flags, ent->src_flags, + ent->testname, "src_flags"); + fails += check_int (test.mask_flags, ent->mask_flags, + ent->testname, "mask_flags"); + fails += check_int (test.op, ent->op, ent->testname, "op"); + } + + if (fails) + { + printf ("Parser self-test failed.\n"); + exit (EXIT_FAILURE); + } + + printf ("Parser self-test complete.\n"); +} + +static void +run_one_test (const char *pattern, double bandwidth_) +{ + test_entry_t test; + + if (parse_test_pattern (&test, pattern) < 0) + { + printf ("Error: Could not parse the test pattern '%s'.\n", pattern); + return; + } + + bench_composite (pattern, + test.src_fmt, + test.src_flags, + test.op, + test.mask_fmt, + test.mask_flags, + test.dst_fmt, + bandwidth_ / 8); +} + +static void +run_default_tests (double bandwidth_) +{ + int i; + + for (i = 0; i < ARRAY_LENGTH (tests_tbl); i++) + run_one_test (tests_tbl[i].testname, bandwidth_); +} + int main (int argc, char *argv[]) { @@ -754,6 +1011,8 @@ main (int argc, char *argv[]) return 1; } + parser_self_test (); + src = aligned_malloc (4096, BUFSIZE * 3); memset (src, 0xCC, BUFSIZE * 3); dst = src + (BUFSIZE / 4); @@ -801,19 +1060,13 @@ main (int argc, char *argv[]) } printf ("---\n"); - for (i = 0; i < ARRAY_LENGTH (tests_tbl); i++) + if (strcmp (pattern, "all") == 0) { - if (strcmp (pattern, "all") == 0 || strcmp (tests_tbl[i].testname, pattern) == 0) - { - bench_composite (tests_tbl[i].testname, - tests_tbl[i].src_fmt, - tests_tbl[i].src_flags, - tests_tbl[i].op, - tests_tbl[i].mask_fmt, - tests_tbl[i].mask_flags, - tests_tbl[i].dst_fmt, - bandwidth/8); - } + run_default_tests (bandwidth); + } + else + { + run_one_test (pattern, bandwidth); } free (src); diff --git a/pixman/test/utils.c b/pixman/test/utils.c index ab3424f9e..5663aecbe 100644 --- a/pixman/test/utils.c +++ b/pixman/test/utils.c @@ -5,6 +5,7 @@ #include <signal.h> #include <stdlib.h> #include <float.h> +#include <ctype.h> #ifdef HAVE_GETTIMEOFDAY #include <sys/time.h> @@ -948,164 +949,348 @@ initialize_palette (pixman_indexed_t *palette, uint32_t depth, int is_rgb) } } -const char * -operator_name (pixman_op_t op) +struct operator_entry { + pixman_op_t op; + const char *name; + pixman_bool_t is_alias; +}; + +typedef struct operator_entry operator_entry_t; + +static const operator_entry_t op_list[] = { - switch (op) - { - case PIXMAN_OP_CLEAR: return "PIXMAN_OP_CLEAR"; - case PIXMAN_OP_SRC: return "PIXMAN_OP_SRC"; - case PIXMAN_OP_DST: return "PIXMAN_OP_DST"; - case PIXMAN_OP_OVER: return "PIXMAN_OP_OVER"; - case PIXMAN_OP_OVER_REVERSE: return "PIXMAN_OP_OVER_REVERSE"; - case PIXMAN_OP_IN: return "PIXMAN_OP_IN"; - case PIXMAN_OP_IN_REVERSE: return "PIXMAN_OP_IN_REVERSE"; - case PIXMAN_OP_OUT: return "PIXMAN_OP_OUT"; - case PIXMAN_OP_OUT_REVERSE: return "PIXMAN_OP_OUT_REVERSE"; - case PIXMAN_OP_ATOP: return "PIXMAN_OP_ATOP"; - case PIXMAN_OP_ATOP_REVERSE: return "PIXMAN_OP_ATOP_REVERSE"; - case PIXMAN_OP_XOR: return "PIXMAN_OP_XOR"; - case PIXMAN_OP_ADD: return "PIXMAN_OP_ADD"; - case PIXMAN_OP_SATURATE: return "PIXMAN_OP_SATURATE"; - - case PIXMAN_OP_DISJOINT_CLEAR: return "PIXMAN_OP_DISJOINT_CLEAR"; - case PIXMAN_OP_DISJOINT_SRC: return "PIXMAN_OP_DISJOINT_SRC"; - case PIXMAN_OP_DISJOINT_DST: return "PIXMAN_OP_DISJOINT_DST"; - case PIXMAN_OP_DISJOINT_OVER: return "PIXMAN_OP_DISJOINT_OVER"; - case PIXMAN_OP_DISJOINT_OVER_REVERSE: return "PIXMAN_OP_DISJOINT_OVER_REVERSE"; - case PIXMAN_OP_DISJOINT_IN: return "PIXMAN_OP_DISJOINT_IN"; - case PIXMAN_OP_DISJOINT_IN_REVERSE: return "PIXMAN_OP_DISJOINT_IN_REVERSE"; - case PIXMAN_OP_DISJOINT_OUT: return "PIXMAN_OP_DISJOINT_OUT"; - case PIXMAN_OP_DISJOINT_OUT_REVERSE: return "PIXMAN_OP_DISJOINT_OUT_REVERSE"; - case PIXMAN_OP_DISJOINT_ATOP: return "PIXMAN_OP_DISJOINT_ATOP"; - case PIXMAN_OP_DISJOINT_ATOP_REVERSE: return "PIXMAN_OP_DISJOINT_ATOP_REVERSE"; - case PIXMAN_OP_DISJOINT_XOR: return "PIXMAN_OP_DISJOINT_XOR"; - - case PIXMAN_OP_CONJOINT_CLEAR: return "PIXMAN_OP_CONJOINT_CLEAR"; - case PIXMAN_OP_CONJOINT_SRC: return "PIXMAN_OP_CONJOINT_SRC"; - case PIXMAN_OP_CONJOINT_DST: return "PIXMAN_OP_CONJOINT_DST"; - case PIXMAN_OP_CONJOINT_OVER: return "PIXMAN_OP_CONJOINT_OVER"; - case PIXMAN_OP_CONJOINT_OVER_REVERSE: return "PIXMAN_OP_CONJOINT_OVER_REVERSE"; - case PIXMAN_OP_CONJOINT_IN: return "PIXMAN_OP_CONJOINT_IN"; - case PIXMAN_OP_CONJOINT_IN_REVERSE: return "PIXMAN_OP_CONJOINT_IN_REVERSE"; - case PIXMAN_OP_CONJOINT_OUT: return "PIXMAN_OP_CONJOINT_OUT"; - case PIXMAN_OP_CONJOINT_OUT_REVERSE: return "PIXMAN_OP_CONJOINT_OUT_REVERSE"; - case PIXMAN_OP_CONJOINT_ATOP: return "PIXMAN_OP_CONJOINT_ATOP"; - case PIXMAN_OP_CONJOINT_ATOP_REVERSE: return "PIXMAN_OP_CONJOINT_ATOP_REVERSE"; - case PIXMAN_OP_CONJOINT_XOR: return "PIXMAN_OP_CONJOINT_XOR"; - - case PIXMAN_OP_MULTIPLY: return "PIXMAN_OP_MULTIPLY"; - case PIXMAN_OP_SCREEN: return "PIXMAN_OP_SCREEN"; - case PIXMAN_OP_OVERLAY: return "PIXMAN_OP_OVERLAY"; - case PIXMAN_OP_DARKEN: return "PIXMAN_OP_DARKEN"; - case PIXMAN_OP_LIGHTEN: return "PIXMAN_OP_LIGHTEN"; - case PIXMAN_OP_COLOR_DODGE: return "PIXMAN_OP_COLOR_DODGE"; - case PIXMAN_OP_COLOR_BURN: return "PIXMAN_OP_COLOR_BURN"; - case PIXMAN_OP_HARD_LIGHT: return "PIXMAN_OP_HARD_LIGHT"; - case PIXMAN_OP_SOFT_LIGHT: return "PIXMAN_OP_SOFT_LIGHT"; - case PIXMAN_OP_DIFFERENCE: return "PIXMAN_OP_DIFFERENCE"; - case PIXMAN_OP_EXCLUSION: return "PIXMAN_OP_EXCLUSION"; - case PIXMAN_OP_HSL_HUE: return "PIXMAN_OP_HSL_HUE"; - case PIXMAN_OP_HSL_SATURATION: return "PIXMAN_OP_HSL_SATURATION"; - case PIXMAN_OP_HSL_COLOR: return "PIXMAN_OP_HSL_COLOR"; - case PIXMAN_OP_HSL_LUMINOSITY: return "PIXMAN_OP_HSL_LUMINOSITY"; - - case PIXMAN_OP_NONE: - return "<invalid operator 'none'>"; - }; +#define ENTRY(op) \ + { PIXMAN_OP_##op, "PIXMAN_OP_" #op, FALSE } +#define ALIAS(op, nam) \ + { PIXMAN_OP_##op, nam, TRUE } + + /* operator_name () will return the first hit in this table, + * so keep the list properly ordered between entries and aliases. + * Aliases are not listed by list_operators (). + */ - return "<unknown operator>"; -} + ENTRY (CLEAR), + ENTRY (SRC), + ENTRY (DST), + ENTRY (OVER), + ENTRY (OVER_REVERSE), + ALIAS (OVER_REVERSE, "overrev"), + ENTRY (IN), + ENTRY (IN_REVERSE), + ALIAS (IN_REVERSE, "inrev"), + ENTRY (OUT), + ENTRY (OUT_REVERSE), + ALIAS (OUT_REVERSE, "outrev"), + ENTRY (ATOP), + ENTRY (ATOP_REVERSE), + ALIAS (ATOP_REVERSE, "atoprev"), + ENTRY (XOR), + ENTRY (ADD), + ENTRY (SATURATE), + + ENTRY (DISJOINT_CLEAR), + ENTRY (DISJOINT_SRC), + ENTRY (DISJOINT_DST), + ENTRY (DISJOINT_OVER), + ENTRY (DISJOINT_OVER_REVERSE), + ENTRY (DISJOINT_IN), + ENTRY (DISJOINT_IN_REVERSE), + ENTRY (DISJOINT_OUT), + ENTRY (DISJOINT_OUT_REVERSE), + ENTRY (DISJOINT_ATOP), + ENTRY (DISJOINT_ATOP_REVERSE), + ENTRY (DISJOINT_XOR), + + ENTRY (CONJOINT_CLEAR), + ENTRY (CONJOINT_SRC), + ENTRY (CONJOINT_DST), + ENTRY (CONJOINT_OVER), + ENTRY (CONJOINT_OVER_REVERSE), + ENTRY (CONJOINT_IN), + ENTRY (CONJOINT_IN_REVERSE), + ENTRY (CONJOINT_OUT), + ENTRY (CONJOINT_OUT_REVERSE), + ENTRY (CONJOINT_ATOP), + ENTRY (CONJOINT_ATOP_REVERSE), + ENTRY (CONJOINT_XOR), + + ENTRY (MULTIPLY), + ENTRY (SCREEN), + ENTRY (OVERLAY), + ENTRY (DARKEN), + ENTRY (LIGHTEN), + ENTRY (COLOR_DODGE), + ENTRY (COLOR_BURN), + ENTRY (HARD_LIGHT), + ENTRY (SOFT_LIGHT), + ENTRY (DIFFERENCE), + ENTRY (EXCLUSION), + ENTRY (HSL_HUE), + ENTRY (HSL_SATURATION), + ENTRY (HSL_COLOR), + ENTRY (HSL_LUMINOSITY), + + ALIAS (NONE, "<invalid operator 'none'>") + +#undef ENTRY +#undef ALIAS +}; -const char * -format_name (pixman_format_code_t format) +struct format_entry { - switch (format) - { + pixman_format_code_t format; + const char *name; + pixman_bool_t is_alias; +}; + +typedef struct format_entry format_entry_t; + +static const format_entry_t format_list[] = +{ +#define ENTRY(f) \ + { PIXMAN_##f, #f, FALSE } +#define ALIAS(f, nam) \ + { PIXMAN_##f, nam, TRUE } + + /* format_name () will return the first hit in this table, + * so keep the list properly ordered between entries and aliases. + * Aliases are not listed by list_formats (). + */ + /* 32bpp formats */ - case PIXMAN_a8r8g8b8: return "a8r8g8b8"; - case PIXMAN_x8r8g8b8: return "x8r8g8b8"; - case PIXMAN_a8b8g8r8: return "a8b8g8r8"; - case PIXMAN_x8b8g8r8: return "x8b8g8r8"; - case PIXMAN_b8g8r8a8: return "b8g8r8a8"; - case PIXMAN_b8g8r8x8: return "b8g8r8x8"; - case PIXMAN_r8g8b8a8: return "r8g8b8a8"; - case PIXMAN_r8g8b8x8: return "r8g8b8x8"; - case PIXMAN_x14r6g6b6: return "x14r6g6b6"; - case PIXMAN_x2r10g10b10: return "x2r10g10b10"; - case PIXMAN_a2r10g10b10: return "a2r10g10b10"; - case PIXMAN_x2b10g10r10: return "x2b10g10r10"; - case PIXMAN_a2b10g10r10: return "a2b10g10r10"; + ENTRY (a8r8g8b8), + ALIAS (a8r8g8b8, "8888"), + ENTRY (x8r8g8b8), + ALIAS (x8r8g8b8, "x888"), + ENTRY (a8b8g8r8), + ENTRY (x8b8g8r8), + ENTRY (b8g8r8a8), + ENTRY (b8g8r8x8), + ENTRY (r8g8b8a8), + ENTRY (r8g8b8x8), + ENTRY (x14r6g6b6), + ENTRY (x2r10g10b10), + ALIAS (x2r10g10b10, "2x10"), + ENTRY (a2r10g10b10), + ALIAS (a2r10g10b10, "2a10"), + ENTRY (x2b10g10r10), + ENTRY (a2b10g10r10), /* sRGB formats */ - case PIXMAN_a8r8g8b8_sRGB: return "a8r8g8b8_sRGB"; + ENTRY (a8r8g8b8_sRGB), /* 24bpp formats */ - case PIXMAN_r8g8b8: return "r8g8b8"; - case PIXMAN_b8g8r8: return "b8g8r8"; - -/* 16bpp formats */ - case PIXMAN_r5g6b5: return "r5g6b5"; - case PIXMAN_b5g6r5: return "b5g6r5"; - - case PIXMAN_a1r5g5b5: return "a1r5g5b5"; - case PIXMAN_x1r5g5b5: return "x1r5g5b5"; - case PIXMAN_a1b5g5r5: return "a1b5g5r5"; - case PIXMAN_x1b5g5r5: return "x1b5g5r5"; - case PIXMAN_a4r4g4b4: return "a4r4g4b4"; - case PIXMAN_x4r4g4b4: return "x4r4g4b4"; - case PIXMAN_a4b4g4r4: return "a4b4g4r4"; - case PIXMAN_x4b4g4r4: return "x4b4g4r4"; + ENTRY (r8g8b8), + ALIAS (r8g8b8, "0888"), + ENTRY (b8g8r8), + +/* 16 bpp formats */ + ENTRY (r5g6b5), + ALIAS (r5g6b5, "0565"), + ENTRY (b5g6r5), + + ENTRY (a1r5g5b5), + ALIAS (a1r5g5b5, "1555"), + ENTRY (x1r5g5b5), + ENTRY (a1b5g5r5), + ENTRY (x1b5g5r5), + ENTRY (a4r4g4b4), + ALIAS (a4r4g4b4, "4444"), + ENTRY (x4r4g4b4), + ENTRY (a4b4g4r4), + ENTRY (x4b4g4r4), /* 8bpp formats */ - case PIXMAN_a8: return "a8"; - case PIXMAN_r3g3b2: return "r3g3b2"; - case PIXMAN_b2g3r3: return "b2g3r3"; - case PIXMAN_a2r2g2b2: return "a2r2g2b2"; - case PIXMAN_a2b2g2r2: return "a2b2g2r2"; - -#if 0 - case PIXMAN_x4c4: return "x4c4"; - case PIXMAN_g8: return "g8"; -#endif - case PIXMAN_c8: return "x4c4 / c8"; - case PIXMAN_x4g4: return "x4g4 / g8"; + ENTRY (a8), + ALIAS (a8, "8"), + ENTRY (r3g3b2), + ENTRY (b2g3r3), + ENTRY (a2r2g2b2), + ALIAS (a2r2g2b2, "2222"), + ENTRY (a2b2g2r2), + + ALIAS (c8, "x4c4 / c8"), + /* ENTRY (c8), */ + ALIAS (g8, "x4g4 / g8"), + /* ENTRY (g8), */ + + ENTRY (x4a4), + + /* These format codes are identical to c8 and g8, respectively. */ + /* ENTRY (x4c4), */ + /* ENTRY (x4g4), */ + +/* 4 bpp formats */ + ENTRY (a4), + ENTRY (r1g2b1), + ENTRY (b1g2r1), + ENTRY (a1r1g1b1), + ENTRY (a1b1g1r1), + + ALIAS (c4, "c4"), + /* ENTRY (c4), */ + ALIAS (g4, "g4"), + /* ENTRY (g4), */ + +/* 1bpp formats */ + ENTRY (a1), + + ALIAS (g1, "g1"), + /* ENTRY (g1), */ - case PIXMAN_x4a4: return "x4a4"; +/* YUV formats */ + ALIAS (yuy2, "yuy2"), + /* ENTRY (yuy2), */ + ALIAS (yv12, "yv12"), + /* ENTRY (yv12), */ + +/* Fake formats, not in pixman_format_code_t enum */ + ALIAS (null, "null"), + ALIAS (solid, "solid"), + ALIAS (solid, "n"), + ALIAS (pixbuf, "pixbuf"), + ALIAS (rpixbuf, "rpixbuf"), + ALIAS (unknown, "unknown"), + +#undef ENTRY +#undef ALIAS +}; -/* 4bpp formats */ - case PIXMAN_a4: return "a4"; - case PIXMAN_r1g2b1: return "r1g2b1"; - case PIXMAN_b1g2r1: return "b1g2r1"; - case PIXMAN_a1r1g1b1: return "a1r1g1b1"; - case PIXMAN_a1b1g1r1: return "a1b1g1r1"; +pixman_format_code_t +format_from_string (const char *s) +{ + int i; - case PIXMAN_c4: return "c4"; - case PIXMAN_g4: return "g4"; + for (i = 0; i < ARRAY_LENGTH (format_list); ++i) + { + const format_entry_t *ent = &format_list[i]; -/* 1bpp formats */ - case PIXMAN_a1: return "a1"; + if (strcasecmp (ent->name, s) == 0) + return ent->format; + } - case PIXMAN_g1: return "g1"; + return PIXMAN_null; +} -/* YUV formats */ - case PIXMAN_yuy2: return "yuy2"; - case PIXMAN_yv12: return "yv12"; - }; +static void +emit (const char *s, int *n_chars) +{ + *n_chars += printf ("%s,", s); + if (*n_chars > 60) + { + printf ("\n "); + *n_chars = 0; + } + else + { + printf (" "); + (*n_chars)++; + } +} - /* Fake formats. - * - * This is separate switch to prevent GCC from complaining - * that the values are not in the pixman_format_code_t enum. - */ - switch ((uint32_t)format) +void +list_formats (void) +{ + int n_chars; + int i; + + printf ("Formats:\n "); + + n_chars = 0; + for (i = 0; i < ARRAY_LENGTH (format_list); ++i) { - case PIXMAN_null: return "null"; - case PIXMAN_solid: return "solid"; - case PIXMAN_pixbuf: return "pixbuf"; - case PIXMAN_rpixbuf: return "rpixbuf"; - case PIXMAN_unknown: return "unknown"; - }; + const format_entry_t *ent = &format_list[i]; + + if (ent->is_alias) + continue; + + emit (ent->name, &n_chars); + } + + printf ("\n\n"); +} + +void +list_operators (void) +{ + char short_name [128] = { 0 }; + int i, n_chars; + + printf ("Operators:\n "); + + n_chars = 0; + for (i = 0; i < ARRAY_LENGTH (op_list); ++i) + { + const operator_entry_t *ent = &op_list[i]; + int j; + + if (ent->is_alias) + continue; + + snprintf (short_name, sizeof (short_name) - 1, "%s", + ent->name + strlen ("PIXMAN_OP_")); + + for (j = 0; short_name[j] != '\0'; ++j) + short_name[j] = tolower (short_name[j]); + + emit (short_name, &n_chars); + } + + printf ("\n\n"); +} + +pixman_op_t +operator_from_string (const char *s) +{ + int i; + + for (i = 0; i < ARRAY_LENGTH (op_list); ++i) + { + const operator_entry_t *ent = &op_list[i]; + + if (ent->is_alias) + { + if (strcasecmp (ent->name, s) == 0) + return ent->op; + } + else + { + if (strcasecmp (ent->name + strlen ("PIXMAN_OP_"), s) == 0) + return ent->op; + } + } + + return PIXMAN_OP_NONE; +} + +const char * +operator_name (pixman_op_t op) +{ + int i; + + for (i = 0; i < ARRAY_LENGTH (op_list); ++i) + { + const operator_entry_t *ent = &op_list[i]; + + if (ent->op == op) + return ent->name; + } + + return "<unknown operator>"; +} + +const char * +format_name (pixman_format_code_t format) +{ + int i; + + for (i = 0; i < ARRAY_LENGTH (format_list); ++i) + { + const format_entry_t *ent = &format_list[i]; + + if (ent->format == format) + return ent->name; + } return "<unknown format>"; }; diff --git a/pixman/test/utils.h b/pixman/test/utils.h index 6804334bb..fc105243b 100644 --- a/pixman/test/utils.h +++ b/pixman/test/utils.h @@ -187,6 +187,18 @@ convert_linear_to_srgb (double component); void initialize_palette (pixman_indexed_t *palette, uint32_t depth, int is_rgb); +pixman_format_code_t +format_from_string (const char *s); + +void +list_formats (void); + +void +list_operators (void); + +pixman_op_t +operator_from_string (const char *s); + const char * operator_name (pixman_op_t op); |