diff options
author | Simon Ser <contact@emersion.fr> | 2023-05-03 12:36:05 +0200 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2023-11-23 11:07:34 +0100 |
commit | 2eb225236eb72f27beec921e9f37ddf58e874fba (patch) | |
tree | e93ac7230acec8b28ce14ba199d9c063ee5d9727 | |
parent | 9e702e9cfe73f5aae665b5847cf470e66714e64a (diff) |
util/transform: add wlr_output_transform_coords()
We hand-roll this in multiple places.
-rw-r--r-- | include/wlr/util/transform.h | 5 | ||||
-rw-r--r-- | types/scene/surface.c | 7 | ||||
-rw-r--r-- | types/scene/wlr_scene.c | 32 | ||||
-rw-r--r-- | types/wlr_compositor.c | 14 | ||||
-rw-r--r-- | util/transform.c | 8 |
5 files changed, 30 insertions, 36 deletions
diff --git a/include/wlr/util/transform.h b/include/wlr/util/transform.h index d0ec5f53..6195e6d0 100644 --- a/include/wlr/util/transform.h +++ b/include/wlr/util/transform.h @@ -25,4 +25,9 @@ enum wl_output_transform wlr_output_transform_invert( enum wl_output_transform wlr_output_transform_compose( enum wl_output_transform tr_a, enum wl_output_transform tr_b); +/** + * Applies a transform to coordinates. + */ +void wlr_output_transform_coords(enum wl_output_transform tr, int *x, int *y); + #endif diff --git a/types/scene/surface.c b/types/scene/surface.c index 4741dd6c..1a2b31af 100644 --- a/types/scene/surface.c +++ b/types/scene/surface.c @@ -130,12 +130,7 @@ static void surface_reconfigure(struct wlr_scene_surface *scene_surface) { wlr_fbox_transform(&src_box, &src_box, state->transform, buffer_width, buffer_height); - - if (state->transform & WL_OUTPUT_TRANSFORM_90) { - int tmp = buffer_width; - buffer_width = buffer_height; - buffer_height = tmp; - } + wlr_output_transform_coords(state->transform, &buffer_width, &buffer_height); src_box.x += (double)(clip->x * buffer_width) / state->width; src_box.y += (double)(clip->y * buffer_height) / state->height; diff --git a/types/scene/wlr_scene.c b/types/scene/wlr_scene.c index d8c7b841..f83f7274 100644 --- a/types/scene/wlr_scene.c +++ b/types/scene/wlr_scene.c @@ -879,13 +879,9 @@ static void scene_node_get_size(struct wlr_scene_node *node, *width = scene_buffer->dst_width; *height = scene_buffer->dst_height; } else if (scene_buffer->buffer) { - if (scene_buffer->transform & WL_OUTPUT_TRANSFORM_90) { - *height = scene_buffer->buffer->width; - *width = scene_buffer->buffer->height; - } else { - *width = scene_buffer->buffer->width; - *height = scene_buffer->buffer->height; - } + *width = scene_buffer->buffer->width; + *height = scene_buffer->buffer->height; + wlr_output_transform_coords(scene_buffer->transform, width, height); } break; } @@ -1544,14 +1540,13 @@ static bool scene_entry_try_direct_scanout(struct render_list_entry *entry, struct wlr_scene_buffer *buffer = wlr_scene_buffer_from_node(node); - struct wlr_fbox default_box = {0}; - if (buffer->transform & WL_OUTPUT_TRANSFORM_90) { - default_box.width = buffer->buffer->height; - default_box.height = buffer->buffer->width; - } else { - default_box.width = buffer->buffer->width; - default_box.height = buffer->buffer->height; - } + int default_width = buffer->buffer->width; + int default_height = buffer->buffer->height; + wlr_output_transform_coords(buffer->transform, &default_width, &default_height); + struct wlr_fbox default_box = { + .width = default_width, + .height = default_height, + }; if (!wlr_fbox_empty(&buffer->src_box) && !wlr_fbox_equal(&buffer->src_box, &default_box)) { @@ -1679,11 +1674,8 @@ bool wlr_scene_output_build_state(struct wlr_scene_output *scene_output, render_data.scale = state->scale; } - if (render_data.transform & WL_OUTPUT_TRANSFORM_90) { - int tmp = render_data.trans_width; - render_data.trans_width = render_data.trans_height; - render_data.trans_height = tmp; - } + wlr_output_transform_coords(render_data.transform, + &render_data.trans_width, &render_data.trans_height); render_data.logical.width = render_data.trans_width / render_data.scale; render_data.logical.height = render_data.trans_height / render_data.scale; diff --git a/types/wlr_compositor.c b/types/wlr_compositor.c index 755d3760..ef05f8bb 100644 --- a/types/wlr_compositor.c +++ b/types/wlr_compositor.c @@ -146,16 +146,10 @@ static void surface_handle_set_input_region(struct wl_client *client, } static void surface_state_transformed_buffer_size(struct wlr_surface_state *state, - int *out_width, int *out_height) { - int width = state->buffer_width; - int height = state->buffer_height; - if ((state->transform & WL_OUTPUT_TRANSFORM_90) != 0) { - int tmp = width; - width = height; - height = tmp; - } - *out_width = width; - *out_height = height; + int *width, int *height) { + *width = state->buffer_width; + *height = state->buffer_height; + wlr_output_transform_coords(state->transform, width, height); } /** diff --git a/util/transform.c b/util/transform.c index 4cc725fd..de3f8ef4 100644 --- a/util/transform.c +++ b/util/transform.c @@ -23,3 +23,11 @@ enum wl_output_transform wlr_output_transform_compose( } return flipped | rotated; } + +void wlr_output_transform_coords(enum wl_output_transform tr, int *x, int *y) { + if (tr & WL_OUTPUT_TRANSFORM_90) { + int tmp = *x; + *x = *y; + *y = tmp; + } +} |