compositor: drop inverse matrix from weston_transform

Remove the inverse matrix member from struct weston_transform. It is
easier (and probably faster, too) to create and store only forward
transformation matrices in a list, multiply them once, and then invert
the final matrix, rather than creating both forward and inverse
matrices, and multiplying both.

Add a stub for the 4x4 matrix inversion function.

Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
diff --git a/src/compositor.c b/src/compositor.c
index 0a7dea3..69ad60e 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -505,7 +505,7 @@
 	t.f[2] = 0.0;
 	t.f[3] = 1.0;
 
-	weston_matrix_transform(&surface->transform.cached.matrix, &t);
+	weston_matrix_transform(&surface->transform.matrix, &t);
 
 	/* XXX: assumes last row of matrix is [0 0 * 1] */
 
@@ -544,8 +544,8 @@
 static void
 weston_surface_update_transform(struct weston_surface *surface)
 {
-	struct weston_matrix *matrix = &surface->transform.cached.matrix;
-	struct weston_matrix *inverse = &surface->transform.cached.inverse;
+	struct weston_matrix *matrix = &surface->transform.matrix;
+	struct weston_matrix *inverse = &surface->transform.inverse;
 	struct weston_transform *tform;
 
 	if (!surface->transform.dirty)
@@ -564,9 +564,7 @@
 	wl_list_for_each(tform, &surface->transform.list, link)
 		weston_matrix_multiply(matrix, &tform->matrix);
 
-	weston_matrix_init(inverse);
-	wl_list_for_each_reverse(tform, &surface->transform.list, link)
-		weston_matrix_multiply(inverse, &tform->inverse);
+	weston_matrix_invert(inverse, matrix);
 }
 
 WL_EXPORT void
diff --git a/src/compositor.h b/src/compositor.h
index bec45c4..5312665 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -36,7 +36,6 @@
 
 struct weston_transform {
 	struct weston_matrix matrix;
-	struct weston_matrix inverse;
 	struct wl_list link;
 };
 
@@ -229,7 +228,9 @@
 		struct wl_list list;
 		int dirty;
 
-		struct weston_transform cached;
+		/* derived state, set up by weston_surface_update_transform */
+		struct weston_matrix matrix;
+		struct weston_matrix inverse;
 		int enabled;
 	} transform;
 
diff --git a/src/matrix.c b/src/matrix.c
index c71471f..941e958 100644
--- a/src/matrix.c
+++ b/src/matrix.c
@@ -100,3 +100,10 @@
 
 	*v = t;
 }
+
+WL_EXPORT int
+weston_matrix_invert(struct weston_matrix *inverse,
+		     const struct weston_matrix *matrix)
+{
+	return -1; /* fail */
+}
diff --git a/src/matrix.h b/src/matrix.h
index f149d87..2c3285a 100644
--- a/src/matrix.h
+++ b/src/matrix.h
@@ -43,4 +43,8 @@
 void
 weston_matrix_transform(struct weston_matrix *matrix, struct weston_vector *v);
 
+int
+weston_matrix_invert(struct weston_matrix *inverse,
+		     const struct weston_matrix *matrix);
+
 #endif /* WESTON_MATRIX_H */
diff --git a/src/util.c b/src/util.c
index c803716..6b8477a 100644
--- a/src/util.c
+++ b/src/util.c
@@ -145,9 +145,6 @@
 	es->alpha = zoom->spring.current * 255;
 	if (es->alpha > 255)
 		es->alpha = 255;
-	scale = 1.0 / zoom->spring.current;
-	weston_matrix_init(&zoom->transform.inverse);
-	weston_matrix_scale(&zoom->transform.inverse, scale, scale, scale);
 
 	zoom->surface->transform.dirty = 1;