[PATCH weston] Simply the matrix calculation for zooming

Neil Roberts neil at linux.intel.com
Fri Apr 25 05:19:37 PDT 2014


In order to apply the zoom transformation to the output matrix, Weston was
doing the following:

• Create a temporary matrix to hold the translation
• Invert the translation matrix using weston_matrix_invert into
  another temporary matrix
• Scale that matrix by the scale factor
• Multiply the current matrix with the temporary matrix

Using weston_matrix_invert to invert a translation matrix is over the top.
Instead we can just negate the values we pass to weston_matrix_translate.
Matrix multiplication is associative so creating a temporary matrix to hold the
scale and translation transform should be equivalent to just applying them
directly to the output matrix.
---
 src/compositor.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)

diff --git a/src/compositor.c b/src/compositor.c
index fd2decb..f836cf7 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -3186,8 +3186,6 @@ WL_EXPORT void
 weston_output_update_matrix(struct weston_output *output)
 {
 	float magnification;
-	struct weston_matrix camera;
-	struct weston_matrix modelview;
 
 	weston_matrix_init(&output->matrix);
 	weston_matrix_translate(&output->matrix,
@@ -3202,14 +3200,11 @@ weston_output_update_matrix(struct weston_output *output)
 
 	if (output->zoom.active) {
 		magnification = 1 / (1 - output->zoom.spring_z.current);
-		weston_matrix_init(&camera);
-		weston_matrix_init(&modelview);
 		weston_output_update_zoom(output);
-		weston_matrix_translate(&camera, output->zoom.trans_x,
-					-output->zoom.trans_y, 0);
-		weston_matrix_invert(&modelview, &camera);
-		weston_matrix_scale(&modelview, magnification, magnification, 1.0);
-		weston_matrix_multiply(&output->matrix, &modelview);
+		weston_matrix_translate(&output->matrix, -output->zoom.trans_x,
+					output->zoom.trans_y, 0);
+		weston_matrix_scale(&output->matrix, magnification,
+				    magnification, 1.0);
 	}
 
 	output->dirty = 0;
-- 
1.9.0



More information about the wayland-devel mailing list