libweston: Factor out transform matrix setup code

We want to use this in other places too, instead of open coding it
multiple times.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
This commit is contained in:
Derek Foreman 2022-12-20 16:49:23 -06:00 committed by Daniel Stone
parent 5d6cb00b1a
commit 31b3527418
3 changed files with 58 additions and 40 deletions

View File

@ -77,6 +77,12 @@ bool
weston_matrix_to_transform(const struct weston_matrix *mat,
enum wl_output_transform *transform);
void
weston_matrix_init_transform(struct weston_matrix *matrix,
enum wl_output_transform transform,
int x, int y, int width, int height,
int scale);
#ifdef __cplusplus
}
#endif

View File

@ -6269,46 +6269,10 @@ weston_region_global_to_output(pixman_region32_t *dst,
WESTON_EXPORT_FOR_TESTS void
weston_output_update_matrix(struct weston_output *output)
{
weston_matrix_init(&output->matrix);
weston_matrix_translate(&output->matrix, -output->x, -output->y, 0);
switch (output->transform) {
case WL_OUTPUT_TRANSFORM_FLIPPED:
case WL_OUTPUT_TRANSFORM_FLIPPED_90:
case WL_OUTPUT_TRANSFORM_FLIPPED_180:
case WL_OUTPUT_TRANSFORM_FLIPPED_270:
weston_matrix_translate(&output->matrix, -output->width, 0, 0);
weston_matrix_scale(&output->matrix, -1, 1, 1);
break;
}
switch (output->transform) {
default:
case WL_OUTPUT_TRANSFORM_NORMAL:
case WL_OUTPUT_TRANSFORM_FLIPPED:
break;
case WL_OUTPUT_TRANSFORM_90:
case WL_OUTPUT_TRANSFORM_FLIPPED_90:
weston_matrix_translate(&output->matrix, -output->width, 0, 0);
weston_matrix_rotate_xy(&output->matrix, 0, -1);
break;
case WL_OUTPUT_TRANSFORM_180:
case WL_OUTPUT_TRANSFORM_FLIPPED_180:
weston_matrix_translate(&output->matrix,
-output->width, -output->height, 0);
weston_matrix_rotate_xy(&output->matrix, -1, 0);
break;
case WL_OUTPUT_TRANSFORM_270:
case WL_OUTPUT_TRANSFORM_FLIPPED_270:
weston_matrix_translate(&output->matrix, 0, -output->height, 0);
weston_matrix_rotate_xy(&output->matrix, 0, 1);
break;
}
if (output->current_scale != 1)
weston_matrix_scale(&output->matrix,
output->current_scale,
output->current_scale, 1);
weston_matrix_init_transform(&output->matrix, output->transform,
output->x, output->y,
output->width, output->height,
output->current_scale);
weston_matrix_invert(&output->inverse_matrix, &output->matrix);
}

View File

@ -516,3 +516,51 @@ weston_matrix_to_transform(const struct weston_matrix *mat,
return true;
}
WL_EXPORT void
weston_matrix_init_transform(struct weston_matrix *matrix,
enum wl_output_transform transform,
int x, int y, int width, int height,
int scale)
{
weston_matrix_init(matrix);
weston_matrix_translate(matrix, -x, -y, 0);
switch (transform) {
case WL_OUTPUT_TRANSFORM_FLIPPED:
case WL_OUTPUT_TRANSFORM_FLIPPED_90:
case WL_OUTPUT_TRANSFORM_FLIPPED_180:
case WL_OUTPUT_TRANSFORM_FLIPPED_270:
weston_matrix_scale(matrix, -1, 1, 1);
weston_matrix_translate(matrix, width, 0, 0);
break;
default:
break;
}
switch (transform) {
default:
case WL_OUTPUT_TRANSFORM_NORMAL:
case WL_OUTPUT_TRANSFORM_FLIPPED:
break;
case WL_OUTPUT_TRANSFORM_90:
case WL_OUTPUT_TRANSFORM_FLIPPED_90:
weston_matrix_rotate_xy(matrix, 0, -1);
weston_matrix_translate(matrix, 0, width, 0);
break;
case WL_OUTPUT_TRANSFORM_180:
case WL_OUTPUT_TRANSFORM_FLIPPED_180:
weston_matrix_rotate_xy(matrix, -1, 0);
weston_matrix_translate(matrix,
width, height, 0);
break;
case WL_OUTPUT_TRANSFORM_270:
case WL_OUTPUT_TRANSFORM_FLIPPED_270:
weston_matrix_rotate_xy(matrix, 0, 1);
weston_matrix_translate(matrix, height, 0, 0);
break;
}
weston_matrix_scale(matrix, scale, scale, 1);
}