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>
This commit is contained in:
committed by
Kristian Høgsberg
parent
15336e8b5c
commit
1bbf372e31
+20
-3
@@ -21,6 +21,7 @@
|
|||||||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <float.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
@@ -46,7 +47,8 @@ WL_EXPORT void
|
|||||||
weston_matrix_init(struct weston_matrix *matrix)
|
weston_matrix_init(struct weston_matrix *matrix)
|
||||||
{
|
{
|
||||||
static const struct weston_matrix identity = {
|
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);
|
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++)
|
for (j = 0; j < 4; j++)
|
||||||
tmp.d[i] += row[j] * column[j * 4];
|
tmp.d[i] += row[j] * column[j * 4];
|
||||||
}
|
}
|
||||||
|
tmp.type = m->type | n->type;
|
||||||
memcpy(m, &tmp, sizeof tmp);
|
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)
|
weston_matrix_translate(struct weston_matrix *matrix, float x, float y, float z)
|
||||||
{
|
{
|
||||||
struct weston_matrix translate = {
|
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);
|
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)
|
weston_matrix_scale(struct weston_matrix *matrix, float x, float y,float z)
|
||||||
{
|
{
|
||||||
struct weston_matrix scale = {
|
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);
|
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 */
|
/* v <- m * v */
|
||||||
WL_EXPORT void
|
WL_EXPORT void
|
||||||
weston_matrix_transform(struct weston_matrix *matrix, struct weston_vector *v)
|
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);
|
weston_matrix_init(inverse);
|
||||||
for (c = 0; c < 4; ++c)
|
for (c = 0; c < 4; ++c)
|
||||||
inverse_transform(LU, perm, &inverse->d[c * 4]);
|
inverse_transform(LU, perm, &inverse->d[c * 4]);
|
||||||
|
inverse->type = matrix->type;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,8 +24,16 @@
|
|||||||
#ifndef WESTON_MATRIX_H
|
#ifndef WESTON_MATRIX_H
|
||||||
#define 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 {
|
struct weston_matrix {
|
||||||
float d[16];
|
float d[16];
|
||||||
|
unsigned int type;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct weston_vector {
|
struct weston_vector {
|
||||||
@@ -42,6 +50,8 @@ void
|
|||||||
weston_matrix_translate(struct weston_matrix *matrix,
|
weston_matrix_translate(struct weston_matrix *matrix,
|
||||||
float x, float y, float z);
|
float x, float y, float z);
|
||||||
void
|
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);
|
weston_matrix_transform(struct weston_matrix *matrix, struct weston_vector *v);
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|||||||
@@ -539,6 +539,7 @@ weston_surface_update_transform_enable(struct weston_surface *surface)
|
|||||||
surface->transform.enabled = 1;
|
surface->transform.enabled = 1;
|
||||||
|
|
||||||
/* Otherwise identity matrix, but with x and y translation. */
|
/* Otherwise identity matrix, but with x and y translation. */
|
||||||
|
surface->transform.position.matrix.type = WESTON_MATRIX_TRANSFORM_TRANSLATE;
|
||||||
surface->transform.position.matrix.d[12] = surface->geometry.x;
|
surface->transform.position.matrix.d[12] = surface->geometry.x;
|
||||||
surface->transform.position.matrix.d[13] = surface->geometry.y;
|
surface->transform.position.matrix.d[13] = surface->geometry.y;
|
||||||
|
|
||||||
@@ -2754,12 +2755,14 @@ weston_output_compute_transform(struct weston_output *output)
|
|||||||
int flip;
|
int flip;
|
||||||
|
|
||||||
weston_matrix_init(&transform);
|
weston_matrix_init(&transform);
|
||||||
|
transform.type = WESTON_MATRIX_TRANSFORM_ROTATE;
|
||||||
|
|
||||||
switch(output->transform) {
|
switch(output->transform) {
|
||||||
case WL_OUTPUT_TRANSFORM_FLIPPED:
|
case WL_OUTPUT_TRANSFORM_FLIPPED:
|
||||||
case WL_OUTPUT_TRANSFORM_FLIPPED_90:
|
case WL_OUTPUT_TRANSFORM_FLIPPED_90:
|
||||||
case WL_OUTPUT_TRANSFORM_FLIPPED_180:
|
case WL_OUTPUT_TRANSFORM_FLIPPED_180:
|
||||||
case WL_OUTPUT_TRANSFORM_FLIPPED_270:
|
case WL_OUTPUT_TRANSFORM_FLIPPED_270:
|
||||||
|
transform.type |= WESTON_MATRIX_TRANSFORM_OTHER;
|
||||||
flip = -1;
|
flip = -1;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|||||||
+5
-12
@@ -1876,6 +1876,8 @@ shell_map_popup(struct shell_surface *shsurf)
|
|||||||
} else {
|
} else {
|
||||||
/* construct x, y translation matrix */
|
/* construct x, y translation matrix */
|
||||||
weston_matrix_init(&shsurf->popup.parent_transform.matrix);
|
weston_matrix_init(&shsurf->popup.parent_transform.matrix);
|
||||||
|
shsurf->popup.parent_transform.matrix.type =
|
||||||
|
WESTON_MATRIX_TRANSFORM_TRANSLATE;
|
||||||
shsurf->popup.parent_transform.matrix.d[12] =
|
shsurf->popup.parent_transform.matrix.d[12] =
|
||||||
parent->geometry.x;
|
parent->geometry.x;
|
||||||
shsurf->popup.parent_transform.matrix.d[13] =
|
shsurf->popup.parent_transform.matrix.d[13] =
|
||||||
@@ -2502,10 +2504,7 @@ rotate_grab_motion(struct wl_pointer_grab *grab,
|
|||||||
&shsurf->rotation.transform.matrix;
|
&shsurf->rotation.transform.matrix;
|
||||||
|
|
||||||
weston_matrix_init(&rotate->rotation);
|
weston_matrix_init(&rotate->rotation);
|
||||||
rotate->rotation.d[0] = dx / r;
|
weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r);
|
||||||
rotate->rotation.d[4] = -dy / r;
|
|
||||||
rotate->rotation.d[1] = -rotate->rotation.d[4];
|
|
||||||
rotate->rotation.d[5] = rotate->rotation.d[0];
|
|
||||||
|
|
||||||
weston_matrix_init(matrix);
|
weston_matrix_init(matrix);
|
||||||
weston_matrix_translate(matrix, -cx, -cy, 0.0f);
|
weston_matrix_translate(matrix, -cx, -cy, 0.0f);
|
||||||
@@ -2600,17 +2599,11 @@ rotate_binding(struct wl_seat *seat, uint32_t time, uint32_t button,
|
|||||||
struct weston_matrix inverse;
|
struct weston_matrix inverse;
|
||||||
|
|
||||||
weston_matrix_init(&inverse);
|
weston_matrix_init(&inverse);
|
||||||
inverse.d[0] = dx / r;
|
weston_matrix_rotate_xy(&inverse, dx / r, -dy / r);
|
||||||
inverse.d[4] = dy / r;
|
|
||||||
inverse.d[1] = -inverse.d[4];
|
|
||||||
inverse.d[5] = inverse.d[0];
|
|
||||||
weston_matrix_multiply(&surface->rotation.rotation, &inverse);
|
weston_matrix_multiply(&surface->rotation.rotation, &inverse);
|
||||||
|
|
||||||
weston_matrix_init(&rotate->rotation);
|
weston_matrix_init(&rotate->rotation);
|
||||||
rotate->rotation.d[0] = dx / r;
|
weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r);
|
||||||
rotate->rotation.d[4] = -dy / r;
|
|
||||||
rotate->rotation.d[1] = -rotate->rotation.d[4];
|
|
||||||
rotate->rotation.d[5] = rotate->rotation.d[0];
|
|
||||||
} else {
|
} else {
|
||||||
weston_matrix_init(&surface->rotation.rotation);
|
weston_matrix_init(&surface->rotation.rotation);
|
||||||
weston_matrix_init(&rotate->rotation);
|
weston_matrix_init(&rotate->rotation);
|
||||||
|
|||||||
Reference in New Issue
Block a user