diff options
author | Chris Wilson <chris@chris-wilson.co.uk> | 2013-11-13 15:27:05 +0000 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2013-11-14 12:07:47 +0000 |
commit | 7358ba83a3d4ab37459b4e510704bd0be4438dcd (patch) | |
tree | a6feae5fca638d90a478bc70f0046bbf7d01543f /test | |
parent | f08f9cb28efa1b82f196695c66c3ec3a2b63361c (diff) |
tests: Add render-composite-solid-mask
Another reference test to exercise simple composite pathways clearly.
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Diffstat (limited to 'test')
-rw-r--r-- | test/.gitignore | 1 | ||||
-rw-r--r-- | test/Makefile.am | 1 | ||||
-rw-r--r-- | test/render-composite-solid-mask.c | 122 |
3 files changed, 124 insertions, 0 deletions
diff --git a/test/.gitignore b/test/.gitignore index 70885780..8e74a9a7 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -9,6 +9,7 @@ render-trapezoid render-trapezoid-image render-fill-copy render-composite-solid +render-composite-solid-mask render-copyarea render-copyarea-size render-copy-alphaless diff --git a/test/Makefile.am b/test/Makefile.am index 7ffb7dfa..de91cfa8 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -12,6 +12,7 @@ stress_TESTS = \ render-trapezoid-image \ render-fill-copy \ render-composite-solid \ + render-composite-solid-mask \ render-copyarea \ render-copyarea-size \ render-copy-alphaless \ diff --git a/test/render-composite-solid-mask.c b/test/render-composite-solid-mask.c new file mode 100644 index 00000000..b86512c8 --- /dev/null +++ b/test/render-composite-solid-mask.c @@ -0,0 +1,122 @@ +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> + +#include <X11/Xutil.h> /* for XDestroyImage */ +#include <pixman.h> /* for pixman blt functions */ + +#include "test.h" + +static const uint8_t ops[] = { + PictOpClear, + PictOpSrc, + PictOpDst, +}; + +static void fill_rect(struct test_display *dpy, Picture p, uint8_t op, + int x, int y, int w, int h, + uint8_t s_red, uint8_t s_green, uint8_t s_blue, uint8_t s_alpha, + uint8_t m_red, uint8_t m_green, uint8_t m_blue, uint8_t m_alpha) +{ + XRenderColor render_color; + Picture source, mask; + + render_color.red = s_red * s_alpha; + render_color.green = s_green * s_alpha; + render_color.blue = s_blue * s_alpha; + render_color.alpha = s_alpha << 8 | s_alpha; + source = XRenderCreateSolidFill(dpy->dpy, &render_color); + + render_color.red = m_red * m_alpha; + render_color.green = m_green * m_alpha; + render_color.blue = m_blue * m_alpha; + render_color.alpha = m_alpha << 8 | m_alpha; + mask = XRenderCreateSolidFill(dpy->dpy, &render_color); + + XRenderComposite(dpy->dpy, op, source, mask, p, 0, 0, 0, 0, x, y, w,h); + + XRenderFreePicture(dpy->dpy, mask); + XRenderFreePicture(dpy->dpy, source); +} + +static void clear(struct test_display *dpy, struct test_target *tt) +{ + XRenderColor render_color = {0}; + XRenderFillRectangle(dpy->dpy, PictOpClear, tt->picture, &render_color, + 0, 0, tt->width, tt->height); +} + +static void ref_tests(struct test *t, int reps, int sets, enum target target) +{ + struct test_target real, ref; + int r, s; + + printf("Testing area fills (%s): ", test_target_name(target)); + fflush(stdout); + + test_target_create_render(&t->real, target, &real); + clear(&t->real, &real); + + test_target_create_render(&t->ref, target, &ref); + clear(&t->ref, &ref); + + for (s = 0; s < sets; s++) { + for (r = 0; r < reps; r++) { + int x = rand() % (2*real.width) - real.width; + int y = rand() % (2*real.height) - real.height; + int w = rand() % real.width; + int h = rand() % real.height; + int op = ops[rand() % sizeof(ops)]; + int s_red = rand() % 0xff; + int s_green = rand() % 0xff; + int s_blue = rand() % 0xff; + int s_alpha = rand() % 0xff; + int m_red = rand() % 0xff; + int m_green = rand() % 0xff; + int m_blue = rand() % 0xff; + int m_alpha = rand() % 0xff; + + fill_rect(&t->real, real.picture, + op, x, y, w, h, + s_red, s_green, s_blue, s_alpha, + m_red, m_green, m_blue, m_alpha); + fill_rect(&t->ref, ref.picture, + op, x, y, w, h, + s_red, s_green, s_blue, s_alpha, + m_red, m_green, m_blue, m_alpha); + } + + test_compare(t, + real.draw, real.format, + ref.draw, ref.format, + 0, 0, real.width, real.height, + ""); + } + + printf("passed [%d iterations x %d]\n", reps, sets); + + test_target_destroy_render(&t->real, &real); + test_target_destroy_render(&t->ref, &ref); +} + +int main(int argc, char **argv) +{ + struct test test; + int i; + + test_init(&test, argc, argv); + + for (i = 0; i <= DEFAULT_ITERATIONS; i++) { + int reps = 1 << i; + int sets = 1 << (12 - i); + enum target t; + + if (sets < 2) + sets = 2; + + for (t = TARGET_FIRST; t <= TARGET_LAST; t++) + ref_tests(&test, reps, sets, t); + } + + return 0; +} |