summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPekka Paalanen <ppaalanen@gmail.com>2012-01-12 14:30:47 +0200
committerPekka Paalanen <ppaalanen@gmail.com>2012-01-27 10:44:22 +0200
commit668ca37b19926e57b414497f3881f3939e804c0d (patch)
tree59f6ea24d1cfdc36410271b10eaa653d8566c5d8
parentdaaf01b3e104047326d072e8bd8c849537129530 (diff)
compositor: move matrix code to separate files
Move matrix code to separate files to allow writing unit tests for it. Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
-rw-r--r--src/Makefile.am2
-rw-r--r--src/compositor.h20
-rw-r--r--src/matrix.c102
-rw-r--r--src/matrix.h46
-rw-r--r--src/util.c74
5 files changed, 151 insertions, 93 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index cea7cd3..efb2acd 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -20,6 +20,8 @@ weston_SOURCES = \
screenshooter-protocol.c \
screenshooter-server-protocol.h \
util.c \
+ matrix.c \
+ matrix.h \
$(xserver_launcher_sources)
if ENABLE_SETUID_INSTALL
diff --git a/src/compositor.h b/src/compositor.h
index 3ac6558..bec45c4 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -32,25 +32,7 @@
#include <EGL/egl.h>
#include <EGL/eglext.h>
-struct weston_matrix {
- GLfloat d[16];
-};
-
-struct weston_vector {
- GLfloat f[4];
-};
-
-void
-weston_matrix_init(struct weston_matrix *matrix);
-void
-weston_matrix_multiply(struct weston_matrix *m, const struct weston_matrix *n);
-void
-weston_matrix_scale(struct weston_matrix *matrix, GLfloat x, GLfloat y, GLfloat z);
-void
-weston_matrix_translate(struct weston_matrix *matrix,
- GLfloat x, GLfloat y, GLfloat z);
-void
-weston_matrix_transform(struct weston_matrix *matrix, struct weston_vector *v);
+#include "matrix.h"
struct weston_transform {
struct weston_matrix matrix;
diff --git a/src/matrix.c b/src/matrix.c
new file mode 100644
index 0000000..c71471f
--- /dev/null
+++ b/src/matrix.c
@@ -0,0 +1,102 @@
+/*
+ * Copyright © 2011 Intel Corporation
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and
+ * its documentation for any purpose is hereby granted without fee, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of the copyright holders not be used in
+ * advertising or publicity pertaining to distribution of the software
+ * without specific, written prior permission. The copyright holders make
+ * no representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <string.h>
+#include <stdlib.h>
+#include <GLES2/gl2.h>
+#include <wayland-server.h>
+
+#include "matrix.h"
+
+/*
+ * Matrices are stored in column-major order, that is the array indices are:
+ * 0 4 8 12
+ * 1 5 9 13
+ * 2 6 10 14
+ * 3 7 11 15
+ */
+
+WL_EXPORT void
+weston_matrix_init(struct weston_matrix *matrix)
+{
+ static const struct weston_matrix identity = {
+ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 }
+ };
+
+ memcpy(matrix, &identity, sizeof identity);
+}
+
+/* m <- n * m, that is, m is multiplied on the LEFT. */
+WL_EXPORT void
+weston_matrix_multiply(struct weston_matrix *m, const struct weston_matrix *n)
+{
+ struct weston_matrix tmp;
+ const GLfloat *row, *column;
+ div_t d;
+ int i, j;
+
+ for (i = 0; i < 16; i++) {
+ tmp.d[i] = 0;
+ d = div(i, 4);
+ row = m->d + d.quot * 4;
+ column = n->d + d.rem;
+ for (j = 0; j < 4; j++)
+ tmp.d[i] += row[j] * column[j * 4];
+ }
+ memcpy(m, &tmp, sizeof tmp);
+}
+
+WL_EXPORT void
+weston_matrix_translate(struct weston_matrix *matrix, GLfloat x, GLfloat y, GLfloat z)
+{
+ struct weston_matrix translate = {
+ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, x, y, z, 1 }
+ };
+
+ weston_matrix_multiply(matrix, &translate);
+}
+
+WL_EXPORT void
+weston_matrix_scale(struct weston_matrix *matrix, GLfloat x, GLfloat y, GLfloat z)
+{
+ struct weston_matrix scale = {
+ { x, 0, 0, 0, 0, y, 0, 0, 0, 0, z, 0, 0, 0, 0, 1 }
+ };
+
+ weston_matrix_multiply(matrix, &scale);
+}
+
+/* v <- m * v */
+WL_EXPORT void
+weston_matrix_transform(struct weston_matrix *matrix, struct weston_vector *v)
+{
+ int i, j;
+ struct weston_vector t;
+
+ for (i = 0; i < 4; i++) {
+ t.f[i] = 0;
+ for (j = 0; j < 4; j++)
+ t.f[i] += v->f[j] * matrix->d[i + j * 4];
+ }
+
+ *v = t;
+}
diff --git a/src/matrix.h b/src/matrix.h
new file mode 100644
index 0000000..f149d87
--- /dev/null
+++ b/src/matrix.h
@@ -0,0 +1,46 @@
+/*
+ * Copyright © 2008-2011 Kristian Høgsberg
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and
+ * its documentation for any purpose is hereby granted without fee, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of the copyright holders not be used in
+ * advertising or publicity pertaining to distribution of the software
+ * without specific, written prior permission. The copyright holders make
+ * no representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef WESTON_MATRIX_H
+#define WESTON_MATRIX_H
+
+struct weston_matrix {
+ GLfloat d[16];
+};
+
+struct weston_vector {
+ GLfloat f[4];
+};
+
+void
+weston_matrix_init(struct weston_matrix *matrix);
+void
+weston_matrix_multiply(struct weston_matrix *m, const struct weston_matrix *n);
+void
+weston_matrix_scale(struct weston_matrix *matrix, GLfloat x, GLfloat y, GLfloat z);
+void
+weston_matrix_translate(struct weston_matrix *matrix,
+ GLfloat x, GLfloat y, GLfloat z);
+void
+weston_matrix_transform(struct weston_matrix *matrix, struct weston_vector *v);
+
+#endif /* WESTON_MATRIX_H */
diff --git a/src/util.c b/src/util.c
index 8a1742a..c803716 100644
--- a/src/util.c
+++ b/src/util.c
@@ -27,80 +27,6 @@
#include "compositor.h"
-/*
- * Matrices are stored in column-major order, that is the array indices are:
- * 0 4 8 12
- * 1 5 9 13
- * 2 6 10 14
- * 3 7 11 15
- */
-
-WL_EXPORT void
-weston_matrix_init(struct weston_matrix *matrix)
-{
- static const struct weston_matrix identity = {
- { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 }
- };
-
- memcpy(matrix, &identity, sizeof identity);
-}
-
-/* m <- n * m, that is, m is multiplied on the LEFT. */
-WL_EXPORT void
-weston_matrix_multiply(struct weston_matrix *m, const struct weston_matrix *n)
-{
- struct weston_matrix tmp;
- const GLfloat *row, *column;
- div_t d;
- int i, j;
-
- for (i = 0; i < 16; i++) {
- tmp.d[i] = 0;
- d = div(i, 4);
- row = m->d + d.quot * 4;
- column = n->d + d.rem;
- for (j = 0; j < 4; j++)
- tmp.d[i] += row[j] * column[j * 4];
- }
- memcpy(m, &tmp, sizeof tmp);
-}
-
-WL_EXPORT void
-weston_matrix_translate(struct weston_matrix *matrix, GLfloat x, GLfloat y, GLfloat z)
-{
- struct weston_matrix translate = {
- { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, x, y, z, 1 }
- };
-
- weston_matrix_multiply(matrix, &translate);
-}
-
-WL_EXPORT void
-weston_matrix_scale(struct weston_matrix *matrix, GLfloat x, GLfloat y, GLfloat z)
-{
- struct weston_matrix scale = {
- { x, 0, 0, 0, 0, y, 0, 0, 0, 0, z, 0, 0, 0, 0, 1 }
- };
-
- weston_matrix_multiply(matrix, &scale);
-}
-
-/* v <- m * v */
-WL_EXPORT void
-weston_matrix_transform(struct weston_matrix *matrix, struct weston_vector *v)
-{
- int i, j;
- struct weston_vector t;
-
- for (i = 0; i < 4; i++) {
- t.f[i] = 0;
- for (j = 0; j < 4; j++)
- t.f[i] += v->f[j] * matrix->d[i + j * 4];
- }
-
- *v = t;
-}
-
WL_EXPORT void
weston_spring_init(struct weston_spring *spring,
double k, double current, double target)