compositor: implement inverse matrix transformation

Implement 4x4 matrix inversion based on LU-decomposition with partial
pivoting.

Instead of simply computing the inverse matrix explicitly, introduce the
type struct weston_inverse_matrix for storing the LU-decomposition and
the permutation from pivoting. Using doubles, this struct has greater
precision than struct weston_matrix.

If you need only few (less than 5, presumably) multiplications with the
inverse matrix, is it cheaper to use weston_inverse_matrix, and not
compute the inverse matrix explicitly into a weston_matrix.

Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
diff --git a/src/matrix.h b/src/matrix.h
index 2c3285a..21c1e78 100644
--- a/src/matrix.h
+++ b/src/matrix.h
@@ -1,5 +1,6 @@
 /*
  * Copyright © 2008-2011 Kristian Høgsberg
+ * Copyright © 2012 Collabora, Ltd.
  *
  * Permission to use, copy, modify, distribute, and sell this software and
  * its documentation for any purpose is hereby granted without fee, provided
@@ -27,6 +28,11 @@
 	GLfloat d[16];
 };
 
+struct weston_inverse_matrix {
+	double LU[16];	/* column-major */
+	unsigned p[4];	/* permutation */
+};
+
 struct weston_vector {
 	GLfloat f[4];
 };
@@ -44,7 +50,10 @@
 weston_matrix_transform(struct weston_matrix *matrix, struct weston_vector *v);
 
 int
-weston_matrix_invert(struct weston_matrix *inverse,
+weston_matrix_invert(struct weston_inverse_matrix *inverse,
 		     const struct weston_matrix *matrix);
+void
+weston_matrix_inverse_transform(struct weston_inverse_matrix *inverse,
+				struct weston_vector *v);
 
 #endif /* WESTON_MATRIX_H */