diff --git a/include/libweston/matrix.h b/include/libweston/matrix.h index 08310003..ffa5b755 100644 --- a/include/libweston/matrix.h +++ b/include/libweston/matrix.h @@ -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 diff --git a/libweston/compositor.c b/libweston/compositor.c index 14ffc974..b967f01d 100644 --- a/libweston/compositor.c +++ b/libweston/compositor.c @@ -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); } diff --git a/shared/matrix.c b/shared/matrix.c index 72717f37..f41abe76 100644 --- a/shared/matrix.c +++ b/shared/matrix.c @@ -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); +}