From 5d6cb00b1ac7664103b4f5ed7e3f6d2ead156144 Mon Sep 17 00:00:00 2001 From: Derek Foreman Date: Tue, 10 Jan 2023 10:32:48 -0600 Subject: [PATCH] matrix-transform-test: Test vector transforms Add an output transform function that doesn't use matrices so we can test our matrix generation by applying it to vectors and comparing with the non-matrix variant. Signed-off-by: Derek Foreman --- tests/matrix-transform-test.c | 55 +++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/tests/matrix-transform-test.c b/tests/matrix-transform-test.c index be5ea255..0837b6be 100644 --- a/tests/matrix-transform-test.c +++ b/tests/matrix-transform-test.c @@ -374,11 +374,60 @@ simple_weston_output_prepare(struct weston_output *output, weston_output_update_matrix(output); } +static struct weston_vector +simple_transform_vector(struct weston_output *output, struct weston_vector in) +{ + struct weston_vector out = in; + int scale = output->current_scale; + + switch (output->transform) { + case WL_OUTPUT_TRANSFORM_NORMAL: + out.f[0] = (-output->x + in.f[0]) * scale; + out.f[1] = (-output->y + in.f[1]) * scale; + break; + case WL_OUTPUT_TRANSFORM_FLIPPED: + out.f[0] = (output->x + output->width - in.f[0]) * scale; + out.f[1] = (-output->y + in.f[1]) * scale; + break; + case WL_OUTPUT_TRANSFORM_90: + out.f[0] = (-output->y + in.f[1]) * scale; + out.f[1] = (output->x + output->width - in.f[0]) * scale; + break; + case WL_OUTPUT_TRANSFORM_FLIPPED_90: + out.f[0] = (-output->y + in.f[1]) * scale; + out.f[1] = (-output->x + in.f[0]) * scale; + break; + case WL_OUTPUT_TRANSFORM_180: + out.f[0] = (output->x + output->width - in.f[0]) * scale; + out.f[1] = (output->y + output->height - in.f[1]) * scale; + break; + case WL_OUTPUT_TRANSFORM_FLIPPED_180: + out.f[0] = (-output->x + in.f[0]) * scale; + out.f[1] = (output->y + output->height - in.f[1]) * scale; + break; + case WL_OUTPUT_TRANSFORM_270: + out.f[0] = (output->y + output->height - in.f[1]) * scale; + out.f[1] = (-output->x + in.f[0]) * scale; + break; + case WL_OUTPUT_TRANSFORM_FLIPPED_270: + out.f[0] = (output->y + output->height - in.f[1]) * scale; + out.f[1] = (output->x + output->width - in.f[0]) * scale; + break; + } + out.f[2] = 0; + out.f[3] = 1; + + return out; +} + static void output_test_all_transforms(struct weston_output *output, int x, int y, int width, int height, int scale) { + int i; int transform; + struct weston_vector t = { { 7.0, 13.0, 0.0, 1.0 } }; + struct weston_vector v, sv; for (transform = WL_OUTPUT_TRANSFORM_NORMAL; transform <= WL_OUTPUT_TRANSFORM_FLIPPED_270; transform++) { @@ -389,6 +438,12 @@ output_test_all_transforms(struct weston_output *output, * standard transform. */ transform_expect(&output->matrix, true, transform); + + v = t; + weston_matrix_transform(&output->matrix, &v); + sv = simple_transform_vector(output, t); + for (i = 0; i < 4; i++) + assert (sv.f[i] == v.f[i]); } }