From c3b5e710f49d099706d62423f973d0fb3a2606e4 Mon Sep 17 00:00:00 2001 From: Alexander Orzechowski Date: Wed, 21 Aug 2024 11:11:49 -0400 Subject: [PATCH] wlr_output: Make wlr_output_transformed_resolution take a state --- backend/drm/drm.c | 2 +- include/wlr/types/wlr_output.h | 2 +- types/output/cursor.c | 5 +++-- types/output/output.c | 23 ++++++++++++++--------- types/scene/wlr_scene.c | 4 ++-- 5 files changed, 21 insertions(+), 15 deletions(-) diff --git a/backend/drm/drm.c b/backend/drm/drm.c index 6ae9dcbf3..d49517c98 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -1179,7 +1179,7 @@ static bool drm_connector_move_cursor(struct wlr_output *output, struct wlr_box box = { .x = x, .y = y }; int width, height; - wlr_output_transformed_resolution(output, &width, &height); + wlr_output_transformed_resolution(output, NULL, &width, &height); enum wl_output_transform transform = wlr_output_transform_invert(output->transform); diff --git a/include/wlr/types/wlr_output.h b/include/wlr/types/wlr_output.h index 9c08a2c34..1de0673f9 100644 --- a/include/wlr/types/wlr_output.h +++ b/include/wlr/types/wlr_output.h @@ -339,7 +339,7 @@ void wlr_output_destroy(struct wlr_output *output); * Computes the transformed output resolution. */ void wlr_output_transformed_resolution(struct wlr_output *output, - int *width, int *height); + const struct wlr_output_state *state, int *width, int *height); /** * Computes the transformed and scaled output resolution. */ diff --git a/types/output/cursor.c b/types/output/cursor.c index af1663574..d399f7288 100644 --- a/types/output/cursor.c +++ b/types/output/cursor.c @@ -89,8 +89,9 @@ static void output_cursor_get_box(struct wlr_output_cursor *cursor, void wlr_output_add_software_cursors_to_render_pass(struct wlr_output *output, struct wlr_render_pass *render_pass, const pixman_region32_t *damage) { + // TODO: pass output state from caller int width, height; - wlr_output_transformed_resolution(output, &width, &height); + wlr_output_transformed_resolution(output, NULL, &width, &height); struct wlr_output_cursor *cursor; wl_list_for_each(cursor, &output->cursors, link) { @@ -158,7 +159,7 @@ static void output_cursor_reset(struct wlr_output_cursor *cursor) { static void output_cursor_update_visible(struct wlr_output_cursor *cursor) { struct wlr_box output_box; output_box.x = output_box.y = 0; - wlr_output_transformed_resolution(cursor->output, &output_box.width, + wlr_output_transformed_resolution(cursor->output, NULL, &output_box.width, &output_box.height); struct wlr_box cursor_box; diff --git a/types/output/output.c b/types/output/output.c index a352a5e59..1a0df6c2b 100644 --- a/types/output/output.c +++ b/types/output/output.c @@ -441,19 +441,24 @@ void wlr_output_destroy(struct wlr_output *output) { } void wlr_output_transformed_resolution(struct wlr_output *output, - int *width, int *height) { - if (output->transform % 2 == 0) { - *width = output->width; - *height = output->height; - } else { - *width = output->height; - *height = output->width; + const struct wlr_output_state *state, int *width, int *height) { + output_pending_resolution(output, state, width, height); + + enum wl_output_transform transform = output->transform; + if (state && state->committed & WLR_OUTPUT_STATE_TRANSFORM) { + transform = state->transform; + } + + if (transform % 2 != 0) { + int tmp = *width; + *width = *height; + *height = tmp; } } void wlr_output_effective_resolution(struct wlr_output *output, int *width, int *height) { - wlr_output_transformed_resolution(output, width, height); + wlr_output_transformed_resolution(output, NULL, width, height); *width /= output->scale; *height /= output->scale; } @@ -476,7 +481,7 @@ struct wlr_output_mode *wlr_output_preferred_mode(struct wlr_output *output) { void output_pending_resolution(struct wlr_output *output, const struct wlr_output_state *state, int *width, int *height) { - if (state->committed & WLR_OUTPUT_STATE_MODE) { + if (state && state->committed & WLR_OUTPUT_STATE_MODE) { switch (state->mode_type) { case WLR_OUTPUT_STATE_MODE_FIXED: *width = state->mode->width; diff --git a/types/scene/wlr_scene.c b/types/scene/wlr_scene.c index 62ff576bf..bb5faa9f2 100644 --- a/types/scene/wlr_scene.c +++ b/types/scene/wlr_scene.c @@ -339,7 +339,7 @@ static void logical_to_buffer_coords(pixman_region32_t *damage, const struct ren static void output_to_buffer_coords(pixman_region32_t *damage, struct wlr_output *output) { int width, height; - wlr_output_transformed_resolution(output, &width, &height); + wlr_output_transformed_resolution(output, NULL, &width, &height); wlr_region_transform(damage, damage, wlr_output_transform_invert(output->transform), width, height); @@ -1579,7 +1579,7 @@ static void scene_output_handle_damage(struct wl_listener *listener, void *data) struct wlr_output_event_damage *event = data; int width, height; - wlr_output_transformed_resolution(output, &width, &height); + wlr_output_transformed_resolution(output, NULL, &width, &height); pixman_region32_t damage; pixman_region32_init(&damage);