From 23f73e333122106dcbef04c36f063d92787a58b3 Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Wed, 12 Jan 2022 14:49:15 +1100 Subject: [PATCH] MR 3421 change: remove scale param, always scale to dst width or height --- examples/mirror.c | 36 +++++-------------- include/wlr/types/wlr_mirror.h | 20 ++--------- types/wlr_mirror.c | 63 +++++++++++----------------------- 3 files changed, 31 insertions(+), 88 deletions(-) diff --git a/examples/mirror.c b/examples/mirror.c index cbac82110..0eb9d55f0 100644 --- a/examples/mirror.c +++ b/examples/mirror.c @@ -27,9 +27,7 @@ static const char usage[] = "usage: mirror \n" " e.g. mirror eDP-1 HDMI-A-1\n" "keys:\n" -" a: WLR_MIRROR_SCALE_ASPECT\n" -" f: WLR_MIRROR_SCALE_FULL\n" -" c: WLR_MIRROR_SCALE_CENTER\n" +" m: toggle mirroring\n" " esc: exit\n"; struct sample_state { @@ -88,7 +86,7 @@ struct sample_keyboard { struct wl_listener destroy; }; -void start_mirror(struct sample_state *state, enum wlr_mirror_scale scale); +void start_mirror(struct sample_state *state); void end_mirror(struct sample_state *state); void handle_mirror_ready(struct wl_listener *listener, void *data); void handle_mirror_destroy(struct wl_listener *listener, void *data); @@ -104,7 +102,7 @@ void handle_keyboard_destroy(struct wl_listener *listener, void *data); void render_rects(struct wlr_renderer *renderer, struct sample_output *output, float colour[]); // start a mirror session -void start_mirror(struct sample_state *state, enum wlr_mirror_scale scale) { +void start_mirror(struct sample_state *state) { struct sample_output *output_src = state->output_src; struct sample_output *output_dst = state->output_dst; if (!output_src || !output_dst) { @@ -124,7 +122,6 @@ void start_mirror(struct sample_state *state, enum wlr_mirror_scale scale) { mirror->dy = 1; // params immutable over the session - mirror->params.scale = scale; mirror->params.overlay_cursor = true; mirror->params.output_dst = state->output_dst->wlr_output; @@ -300,8 +297,6 @@ void handle_keyboard_key(struct wl_listener *listener, void *data) { uint32_t keycode = event->keycode + 8; const xkb_keysym_t *syms; int nsyms = xkb_state_key_get_syms(keyboard->device->keyboard->xkb_state, keycode, &syms); - bool start_end_mirror = false; - enum wlr_mirror_scale scale; for (int i = 0; i < nsyms; i++) { xkb_keysym_t sym = syms[i]; @@ -310,31 +305,18 @@ void handle_keyboard_key(struct wl_listener *listener, void *data) { case XKB_KEY_Escape: wl_display_terminate(state->display); break; - case XKB_KEY_f: - scale = WLR_MIRROR_SCALE_FULL; - start_end_mirror = true; - break; - case XKB_KEY_a: - scale = WLR_MIRROR_SCALE_ASPECT; - start_end_mirror = true; - break; - case XKB_KEY_c: - scale = WLR_MIRROR_SCALE_CENTER; - start_end_mirror = true; + case XKB_KEY_m: + if (state->mirror) { + end_mirror(state); + } else { + start_mirror(state); + } break; default: break; } } } - - if (start_end_mirror) { - if (state->mirror) { - end_mirror(state); - } else { - start_mirror(state, scale); - } - } } void handle_output_destroy(struct wl_listener *listener, void *data) { diff --git a/include/wlr/types/wlr_mirror.h b/include/wlr/types/wlr_mirror.h index 28387b104..cc80cd9c6 100644 --- a/include/wlr/types/wlr_mirror.h +++ b/include/wlr/types/wlr_mirror.h @@ -18,6 +18,8 @@ * Allows mirroring: rendering some contents of one output (the src) on another * output (the dst). dst is fixed for the duration of the session, src may vary. * + * Content will be scaled to fit the width or height of dst. + * * On output_srcs precommit, wlr_mirror::ready is emitted. The compositor may * call wlr_mirror_request_ to request to render a frame on dst. * @@ -31,29 +33,11 @@ * wlr_mirror_destroy */ -enum wlr_mirror_scale { - /** - * src will be stretched to cover dst, distorting if necessary. - */ - WLR_MIRROR_SCALE_FULL, - /** - * src will be stretched to the width or the height of dst, preserving the - * aspect ratio. - */ - WLR_MIRROR_SCALE_ASPECT, - /** - * src will be rendered 1:1 at the center of dst. Content may be lost. - */ - WLR_MIRROR_SCALE_CENTER, -}; - /** * Immutable over session. */ struct wlr_mirror_params { - enum wlr_mirror_scale scale; - /** * Render the src cursor on dst. */ diff --git a/types/wlr_mirror.c b/types/wlr_mirror.c index 599b1be16..e79c2c79f 100644 --- a/types/wlr_mirror.c +++ b/types/wlr_mirror.c @@ -127,11 +127,10 @@ static void calculate_absolute_box(struct wlr_box *absolute, } /** - * Position a box according to the scale method. It will be rotated from src - * to dst. + * Position a box scaled to fit the width or height of dst. It will be rotated + * from src to dst. */ static void calculate_dst_box(struct wlr_fbox *box_dst, - enum wlr_mirror_scale scale_method, enum wl_output_transform transform_src, enum wl_output_transform transform_dst, int32_t width_src, int32_t height_src, @@ -146,46 +145,24 @@ static void calculate_dst_box(struct wlr_fbox *box_dst, rotate_v_h(&width_src_rotated, &height_src_rotated, transform_src, width_src, height_src); rotate_v_h(&width_dst_rotated, &height_dst_rotated, transform_dst, width_dst, height_dst); - switch (scale_method) { - case WLR_MIRROR_SCALE_CENTER: - box_dst->width = width_src; - box_dst->height = height_src; - box_dst->x = (((float) width_dst_rotated) - width_src_rotated) / 2; - box_dst->y = (((float) height_dst_rotated) - height_src_rotated) / 2; - break; - case WLR_MIRROR_SCALE_ASPECT: - if (width_dst_rotated * height_src_rotated > height_dst_rotated * width_src_rotated) { - // expand to dst height - width_scaled = ((float) width_src_rotated) * height_dst_rotated / height_src_rotated; - height_scaled = height_dst_rotated; - } else { - // expand to dst width - width_scaled = width_dst_rotated; - height_scaled = ((float) height_src_rotated) * width_dst_rotated / width_src_rotated; - } - if (src_rotated) { - box_dst->width = height_scaled; - box_dst->height = width_scaled; - } else { - box_dst->width = width_scaled; - box_dst->height = height_scaled; - } - box_dst->x = (((float) width_dst_rotated) - width_scaled) / 2; - box_dst->y = (((float) height_dst_rotated) - height_scaled) / 2; - break; - case WLR_MIRROR_SCALE_FULL: - default: - if (src_rotated) { - box_dst->width = height_dst_rotated; - box_dst->height = width_dst_rotated; - } else { - box_dst->width = width_dst_rotated; - box_dst->height = height_dst_rotated; - } - box_dst->x = 0; - box_dst->y = 0; - break; + if (width_dst_rotated * height_src_rotated > height_dst_rotated * width_src_rotated) { + // expand to dst height + width_scaled = ((float) width_src_rotated) * height_dst_rotated / height_src_rotated; + height_scaled = height_dst_rotated; + } else { + // expand to dst width + width_scaled = width_dst_rotated; + height_scaled = ((float) height_src_rotated) * width_dst_rotated / width_src_rotated; } + if (src_rotated) { + box_dst->width = height_scaled; + box_dst->height = width_scaled; + } else { + box_dst->width = width_scaled; + box_dst->height = height_scaled; + } + box_dst->x = (((float) width_dst_rotated) - width_scaled) / 2; + box_dst->y = (((float) height_dst_rotated) - height_scaled) / 2; } /** @@ -340,7 +317,7 @@ static void output_dst_handle_frame(struct wl_listener *listener, void *data) { // scale and position a box for the dst struct wlr_fbox fbox_dst = {0}; - calculate_dst_box(&fbox_dst, state->params.scale, + calculate_dst_box(&fbox_dst, output_src->transform, output_dst->transform, box_src.width, box_src.height, output_dst->width, output_dst->height);