Simply the matrix calculation for zooming
authorNeil Roberts <neil@linux.intel.com>
Fri, 25 Apr 2014 12:19:37 +0000 (13:19 +0100)
committerKristian Høgsberg <krh@bitplanet.net>
Fri, 25 Apr 2014 22:18:37 +0000 (15:18 -0700)
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

index a35c578..ee8dc24 100644 (file)
@@ -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;