From 9e702e9cfe73f5aae665b5847cf470e66714e64a Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Wed, 3 May 2023 12:32:44 +0200 Subject: util/transform: move over wl_output_transform helpers These aren't really tied to wlr_output. --- util/meson.build | 2 +- util/transform.c | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 util/transform.c (limited to 'util') diff --git a/util/meson.build b/util/meson.build index 5af2254f..053e2c5e 100644 --- a/util/meson.build +++ b/util/meson.build @@ -11,6 +11,6 @@ wlr_files += files( 'shm.c', 'time.c', 'token.c', + 'transform.c', 'utf8.c', ) - diff --git a/util/transform.c b/util/transform.c new file mode 100644 index 00000000..4cc725fd --- /dev/null +++ b/util/transform.c @@ -0,0 +1,25 @@ +#include + +enum wl_output_transform wlr_output_transform_invert( + enum wl_output_transform tr) { + if ((tr & WL_OUTPUT_TRANSFORM_90) && !(tr & WL_OUTPUT_TRANSFORM_FLIPPED)) { + tr ^= WL_OUTPUT_TRANSFORM_180; + } + return tr; +} + +enum wl_output_transform wlr_output_transform_compose( + enum wl_output_transform tr_a, enum wl_output_transform tr_b) { + uint32_t flipped = (tr_a ^ tr_b) & WL_OUTPUT_TRANSFORM_FLIPPED; + uint32_t rotation_mask = WL_OUTPUT_TRANSFORM_90 | WL_OUTPUT_TRANSFORM_180; + uint32_t rotated; + if (tr_b & WL_OUTPUT_TRANSFORM_FLIPPED) { + // When a rotation of k degrees is followed by a flip, the + // equivalent transform is a flip followed by a rotation of + // -k degrees. + rotated = (tr_b - tr_a) & rotation_mask; + } else { + rotated = (tr_a + tr_b) & rotation_mask; + } + return flipped | rotated; +} -- cgit v1.2.3