From 44fa2c4b49ced30a69e86a2ed78dd9bf62e0fbb3 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Thu, 11 Mar 2021 09:49:38 +0100 Subject: [PATCH] output: fix transform matrix for 90/270 rotations We need to adjust the second translation depending on the transform we applied. Fixes: 9601a2abf024 ("output: improve transform matrix calculation" Closes: https://github.com/swaywm/wlroots/issues/2774 --- backend/drm/drm.c | 10 ++++++++-- backend/wayland/output.c | 6 +++++- backend/x11/output.c | 6 +++++- types/wlr_output.c | 12 +++++++----- 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/backend/drm/drm.c b/backend/drm/drm.c index e06213fe..a74c9ca7 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -938,11 +938,17 @@ static bool drm_connector_set_cursor(struct wlr_output *output, float output_matrix[9]; wlr_matrix_identity(output_matrix); if (output->transform != WL_OUTPUT_TRANSFORM_NORMAL) { + struct wlr_box tr_size = { + .width = plane->surf.width, + .height = plane->surf.height, + }; + wlr_box_transform(&tr_size, &tr_size, output->transform, 0, 0); + wlr_matrix_translate(output_matrix, plane->surf.width / 2.0, plane->surf.height / 2.0); wlr_matrix_transform(output_matrix, output->transform); - wlr_matrix_translate(output_matrix, - plane->surf.width / 2.0, - - plane->surf.height / 2.0); + wlr_matrix_translate(output_matrix, - tr_size.width / 2.0, + - tr_size.height / 2.0); } float matrix[9]; diff --git a/backend/wayland/output.c b/backend/wayland/output.c index 1e13f455..b36af17b 100644 --- a/backend/wayland/output.c +++ b/backend/wayland/output.c @@ -434,9 +434,13 @@ static bool output_set_cursor(struct wlr_output *wlr_output, float output_matrix[9]; wlr_matrix_identity(output_matrix); if (wlr_output->transform != WL_OUTPUT_TRANSFORM_NORMAL) { + struct wlr_box tr_size = { .width = width, .height = height }; + wlr_box_transform(&tr_size, &tr_size, wlr_output->transform, 0, 0); + wlr_matrix_translate(output_matrix, width / 2.0, height / 2.0); wlr_matrix_transform(output_matrix, wlr_output->transform); - wlr_matrix_translate(output_matrix, - width / 2.0, - height / 2.0); + wlr_matrix_translate(output_matrix, + - tr_size.width / 2.0, - tr_size.height / 2.0); } float matrix[9]; diff --git a/backend/x11/output.c b/backend/x11/output.c index 406185e3..0d045ff4 100644 --- a/backend/x11/output.c +++ b/backend/x11/output.c @@ -418,9 +418,13 @@ static bool output_cursor_to_picture(struct wlr_x11_output *output, float output_matrix[9]; wlr_matrix_identity(output_matrix); if (output->wlr_output.transform != WL_OUTPUT_TRANSFORM_NORMAL) { + struct wlr_box tr_size = { .width = width, .height = height }; + wlr_box_transform(&tr_size, &tr_size, output->wlr_output.transform, 0, 0); + wlr_matrix_translate(output_matrix, width / 2.0, height / 2.0); wlr_matrix_transform(output_matrix, output->wlr_output.transform); - wlr_matrix_translate(output_matrix, - width / 2.0, - height / 2.0); + wlr_matrix_translate(output_matrix, + - tr_size.width / 2.0, - tr_size.height / 2.0); } float matrix[9]; diff --git a/types/wlr_output.c b/types/wlr_output.c index 237ed161..d07bc405 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -141,14 +141,16 @@ void wlr_output_update_enabled(struct wlr_output *output, bool enabled) { } static void output_update_matrix(struct wlr_output *output) { - float width = output->width / 2.f; - float height = output->height / 2.f; - wlr_matrix_identity(output->transform_matrix); if (output->transform != WL_OUTPUT_TRANSFORM_NORMAL) { - wlr_matrix_translate(output->transform_matrix, width, height); + int tr_width, tr_height; + wlr_output_transformed_resolution(output, &tr_width, &tr_height); + + wlr_matrix_translate(output->transform_matrix, + output->width / 2.0, output->height / 2.0); wlr_matrix_transform(output->transform_matrix, output->transform); - wlr_matrix_translate(output->transform_matrix, -width, -height); + wlr_matrix_translate(output->transform_matrix, + - tr_width / 2.0, - tr_height / 2.0); } }