diff options
author | Vasily Khoruzhick <anarsoul@gmail.com> | 2013-01-28 22:40:28 +0300 |
---|---|---|
committer | Kristian Høgsberg <krh@bitplanet.net> | 2013-01-28 16:10:03 -0500 |
commit | 1bbf372e31a4f60015f38c17d1ad6bb64fb76b10 (patch) | |
tree | 704699483850ec5cd0fe63d2ebb68c4d404a76e0 /shared | |
parent | 15336e8b5c3a76a0c9e1b717a18514781f28dd3e (diff) | |
download | weston-1bbf372e31a4f60015f38c17d1ad6bb64fb76b10.tar.gz weston-1bbf372e31a4f60015f38c17d1ad6bb64fb76b10.tar.bz2 weston-1bbf372e31a4f60015f38c17d1ad6bb64fb76b10.zip |
matrix: track transform type
Introduce several matrix transform types and track type for matrix.
Could be usefull for activating some fastpath that depends on some
transform type.
Signed-off-by: Vasily Khoruzhick <anarsoul@gmail.com>
Diffstat (limited to 'shared')
-rw-r--r-- | shared/matrix.c | 23 | ||||
-rw-r--r-- | shared/matrix.h | 10 |
2 files changed, 30 insertions, 3 deletions
diff --git a/shared/matrix.c b/shared/matrix.c index 11b5b959..3ff4089a 100644 --- a/shared/matrix.c +++ b/shared/matrix.c @@ -21,6 +21,7 @@ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include <float.h> #include <string.h> #include <stdlib.h> #include <math.h> @@ -46,7 +47,8 @@ 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 } + .d = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 }, + .type = 0, }; memcpy(matrix, &identity, sizeof identity); @@ -69,6 +71,7 @@ weston_matrix_multiply(struct weston_matrix *m, const struct weston_matrix *n) for (j = 0; j < 4; j++) tmp.d[i] += row[j] * column[j * 4]; } + tmp.type = m->type | n->type; memcpy(m, &tmp, sizeof tmp); } @@ -76,7 +79,8 @@ WL_EXPORT void weston_matrix_translate(struct weston_matrix *matrix, float x, float y, float z) { struct weston_matrix translate = { - { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, x, y, z, 1 } + .d = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, x, y, z, 1 }, + .type = WESTON_MATRIX_TRANSFORM_TRANSLATE, }; weston_matrix_multiply(matrix, &translate); @@ -86,12 +90,24 @@ WL_EXPORT void weston_matrix_scale(struct weston_matrix *matrix, float x, float y,float z) { struct weston_matrix scale = { - { x, 0, 0, 0, 0, y, 0, 0, 0, 0, z, 0, 0, 0, 0, 1 } + .d = { x, 0, 0, 0, 0, y, 0, 0, 0, 0, z, 0, 0, 0, 0, 1 }, + .type = WESTON_MATRIX_TRANSFORM_SCALE, }; weston_matrix_multiply(matrix, &scale); } +WL_EXPORT void +weston_matrix_rotate_xy(struct weston_matrix *matrix, float cos, float sin) +{ + struct weston_matrix translate = { + .d = { cos, sin, 0, 0, -sin, cos, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 }, + .type = WESTON_MATRIX_TRANSFORM_ROTATE, + }; + + weston_matrix_multiply(matrix, &translate); +} + /* v <- m * v */ WL_EXPORT void weston_matrix_transform(struct weston_matrix *matrix, struct weston_vector *v) @@ -249,6 +265,7 @@ weston_matrix_invert(struct weston_matrix *inverse, weston_matrix_init(inverse); for (c = 0; c < 4; ++c) inverse_transform(LU, perm, &inverse->d[c * 4]); + inverse->type = matrix->type; return 0; } diff --git a/shared/matrix.h b/shared/matrix.h index bacb7bf3..47354f6a 100644 --- a/shared/matrix.h +++ b/shared/matrix.h @@ -24,8 +24,16 @@ #ifndef WESTON_MATRIX_H #define WESTON_MATRIX_H +enum weston_matrix_transform_type { + WESTON_MATRIX_TRANSFORM_TRANSLATE = (1 << 0), + WESTON_MATRIX_TRANSFORM_SCALE = (1 << 1), + WESTON_MATRIX_TRANSFORM_ROTATE = (1 << 2), + WESTON_MATRIX_TRANSFORM_OTHER = (1 << 3), +}; + struct weston_matrix { float d[16]; + unsigned int type; }; struct weston_vector { @@ -42,6 +50,8 @@ void weston_matrix_translate(struct weston_matrix *matrix, float x, float y, float z); void +weston_matrix_rotate_xy(struct weston_matrix *matrix, float cos, float sin); +void weston_matrix_transform(struct weston_matrix *matrix, struct weston_vector *v); int |