From 99b6084fcdccfeca5e5f0f808d5d123400e5693e Mon Sep 17 00:00:00 2001 From: Alexander Orzechowski Date: Mon, 27 Jan 2025 14:01:31 -0500 Subject: [PATCH] util/matrix: Inline wlr_matrix_{identity, scale, translate} --- include/util/matrix.h | 9 --------- util/matrix.c | 41 +++++++++++------------------------------ 2 files changed, 11 insertions(+), 39 deletions(-) diff --git a/include/util/matrix.h b/include/util/matrix.h index 7ad326823..9b219ff61 100644 --- a/include/util/matrix.h +++ b/include/util/matrix.h @@ -6,19 +6,10 @@ struct wlr_box; struct wlr_fbox; -/** Writes the identity matrix into mat */ -void wlr_matrix_identity(float mat[static 9]); - /** mat ← a × b */ void wlr_matrix_multiply(float mat[static 9], const float a[static 9], const float b[static 9]); -/** Writes a 2D translation matrix to mat of magnitude (x, y) */ -void wlr_matrix_translate(float mat[static 9], float x, float y); - -/** Writes a 2D scale matrix to mat of magnitude (x, y) */ -void wlr_matrix_scale(float mat[static 9], float x, float y); - /** Writes a transformation matrix which applies the specified * wl_output_transform to mat */ void wlr_matrix_transform(float mat[static 9], diff --git a/util/matrix.c b/util/matrix.c index d93eacdd8..20612182a 100644 --- a/util/matrix.c +++ b/util/matrix.c @@ -3,15 +3,6 @@ #include #include "util/matrix.h" -void wlr_matrix_identity(float mat[static 9]) { - static const float identity[9] = { - 1.0f, 0.0f, 0.0f, - 0.0f, 1.0f, 0.0f, - 0.0f, 0.0f, 1.0f, - }; - memcpy(mat, identity, sizeof(identity)); -} - void wlr_matrix_multiply(float mat[static 9], const float a[static 9], const float b[static 9]) { float product[9]; @@ -31,24 +22,6 @@ void wlr_matrix_multiply(float mat[static 9], const float a[static 9], memcpy(mat, product, sizeof(product)); } -void wlr_matrix_translate(float mat[static 9], float x, float y) { - float translate[9] = { - 1.0f, 0.0f, x, - 0.0f, 1.0f, y, - 0.0f, 0.0f, 1.0f, - }; - wlr_matrix_multiply(mat, mat, translate); -} - -void wlr_matrix_scale(float mat[static 9], float x, float y) { - float scale[9] = { - x, 0.0f, 0.0f, - 0.0f, y, 0.0f, - 0.0f, 0.0f, 1.0f, - }; - wlr_matrix_multiply(mat, mat, scale); -} - static const float transforms[][9] = { [WL_OUTPUT_TRANSFORM_NORMAL] = { 1.0f, 0.0f, 0.0f, @@ -112,9 +85,17 @@ void matrix_projection(float mat[static 9], int width, int height) { } void wlr_matrix_project_fbox(float mat[static 9], const struct wlr_fbox *box) { - wlr_matrix_identity(mat); - wlr_matrix_translate(mat, box->x, box->y); - wlr_matrix_scale(mat, box->width, box->height); + mat[0] = box->width; + mat[1] = 0.0f; + mat[2] = box->x; + + mat[3] = 0.0f; + mat[4] = box->height; + mat[5] = box->y; + + mat[6] = 0.0f; + mat[7] = 0.0f; + mat[8] = 1.0f; } void wlr_matrix_project_box(float mat[static 9], const struct wlr_box *box) {