From 1e40a7ec7ae25ed8cdc570df9e8f2b2d863ce83d Mon Sep 17 00:00:00 2001 From: Neil Roberts Date: Fri, 25 Apr 2014 13:19:37 +0100 Subject: [PATCH] Simply the matrix calculation for zooming MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 a35c578..ee8dc24 100644 --- a/src/compositor.c +++ b/src/compositor.c @@ -3188,8 +3188,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, @@ -3204,14 +3202,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; -- 2.7.4