mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2025-11-01 22:58:38 -04:00
matrix: unify API, don't use array pointers
This commit is contained in:
parent
b6a3f240c7
commit
d26b67cb06
18 changed files with 172 additions and 167 deletions
|
|
@ -10,79 +10,80 @@ static inline int mind(int row, int col) {
|
|||
return (row - 1) * 4 + col - 1;
|
||||
}
|
||||
|
||||
void wlr_matrix_identity(float (*output)[16]) {
|
||||
void wlr_matrix_identity(float mat[static 16]) {
|
||||
static const float identity[16] = {
|
||||
1.0f, 0.0f, 0.0f, 0.0f,
|
||||
0.0f, 1.0f, 0.0f, 0.0f,
|
||||
0.0f, 0.0f, 1.0f, 0.0f,
|
||||
0.0f, 0.0f, 0.0f, 1.0f
|
||||
0.0f, 0.0f, 0.0f, 1.0f,
|
||||
};
|
||||
memcpy(*output, identity, sizeof(identity));
|
||||
memcpy(mat, identity, sizeof(identity));
|
||||
}
|
||||
|
||||
void wlr_matrix_translate(float (*output)[16], float x, float y, float z) {
|
||||
wlr_matrix_identity(output);
|
||||
(*output)[mind(1, 4)] = x;
|
||||
(*output)[mind(2, 4)] = y;
|
||||
(*output)[mind(3, 4)] = z;
|
||||
void wlr_matrix_translate(float mat[static 16], float x, float y, float z) {
|
||||
wlr_matrix_identity(mat);
|
||||
mat[mind(1, 4)] = x;
|
||||
mat[mind(2, 4)] = y;
|
||||
mat[mind(3, 4)] = z;
|
||||
}
|
||||
|
||||
void wlr_matrix_scale(float (*output)[16], float x, float y, float z) {
|
||||
wlr_matrix_identity(output);
|
||||
(*output)[mind(1, 1)] = x;
|
||||
(*output)[mind(2, 2)] = y;
|
||||
(*output)[mind(3, 3)] = z;
|
||||
void wlr_matrix_scale(float mat[static 16], float x, float y, float z) {
|
||||
wlr_matrix_identity(mat);
|
||||
mat[mind(1, 1)] = x;
|
||||
mat[mind(2, 2)] = y;
|
||||
mat[mind(3, 3)] = z;
|
||||
}
|
||||
|
||||
void wlr_matrix_rotate(float (*output)[16], float radians) {
|
||||
wlr_matrix_identity(output);
|
||||
void wlr_matrix_rotate(float mat[static 16], float radians) {
|
||||
wlr_matrix_identity(mat);
|
||||
float _cos = cosf(radians);
|
||||
float _sin = sinf(radians);
|
||||
(*output)[mind(1, 1)] = _cos;
|
||||
(*output)[mind(1, 2)] = _sin;
|
||||
(*output)[mind(2, 1)] = -_sin;
|
||||
(*output)[mind(2, 2)] = _cos;
|
||||
mat[mind(1, 1)] = _cos;
|
||||
mat[mind(1, 2)] = _sin;
|
||||
mat[mind(2, 1)] = -_sin;
|
||||
mat[mind(2, 2)] = _cos;
|
||||
}
|
||||
|
||||
void wlr_matrix_mul(const float (*x)[16], const float (*y)[16], float (*product)[16]) {
|
||||
float _product[16] = {
|
||||
(*x)[mind(1, 1)] * (*y)[mind(1, 1)] + (*x)[mind(1, 2)] * (*y)[mind(2, 1)] +
|
||||
(*x)[mind(1, 3)] * (*y)[mind(3, 1)] + (*x)[mind(1, 4)] * (*y)[mind(4, 1)],
|
||||
(*x)[mind(1, 1)] * (*y)[mind(1, 2)] + (*x)[mind(1, 2)] * (*y)[mind(2, 2)] +
|
||||
(*x)[mind(1, 3)] * (*y)[mind(3, 2)] + (*x)[mind(1, 4)] * (*y)[mind(4, 2)],
|
||||
(*x)[mind(1, 1)] * (*y)[mind(1, 3)] + (*x)[mind(1, 2)] * (*y)[mind(2, 3)] +
|
||||
(*x)[mind(1, 3)] * (*y)[mind(3, 3)] + (*x)[mind(1, 4)] * (*y)[mind(4, 3)],
|
||||
(*x)[mind(1, 1)] * (*y)[mind(1, 4)] + (*x)[mind(1, 2)] * (*y)[mind(2, 4)] +
|
||||
(*x)[mind(1, 4)] * (*y)[mind(3, 4)] + (*x)[mind(1, 4)] * (*y)[mind(4, 4)],
|
||||
void wlr_matrix_mul(float mat[static 16], const float x[static 16],
|
||||
const float y[static 16]) {
|
||||
float product[16] = {
|
||||
x[mind(1, 1)] * y[mind(1, 1)] + x[mind(1, 2)] * y[mind(2, 1)] +
|
||||
x[mind(1, 3)] * y[mind(3, 1)] + x[mind(1, 4)] * y[mind(4, 1)],
|
||||
x[mind(1, 1)] * y[mind(1, 2)] + x[mind(1, 2)] * y[mind(2, 2)] +
|
||||
x[mind(1, 3)] * y[mind(3, 2)] + x[mind(1, 4)] * y[mind(4, 2)],
|
||||
x[mind(1, 1)] * y[mind(1, 3)] + x[mind(1, 2)] * y[mind(2, 3)] +
|
||||
x[mind(1, 3)] * y[mind(3, 3)] + x[mind(1, 4)] * y[mind(4, 3)],
|
||||
x[mind(1, 1)] * y[mind(1, 4)] + x[mind(1, 2)] * y[mind(2, 4)] +
|
||||
x[mind(1, 4)] * y[mind(3, 4)] + x[mind(1, 4)] * y[mind(4, 4)],
|
||||
|
||||
(*x)[mind(2, 1)] * (*y)[mind(1, 1)] + (*x)[mind(2, 2)] * (*y)[mind(2, 1)] +
|
||||
(*x)[mind(2, 3)] * (*y)[mind(3, 1)] + (*x)[mind(2, 4)] * (*y)[mind(4, 1)],
|
||||
(*x)[mind(2, 1)] * (*y)[mind(1, 2)] + (*x)[mind(2, 2)] * (*y)[mind(2, 2)] +
|
||||
(*x)[mind(2, 3)] * (*y)[mind(3, 2)] + (*x)[mind(2, 4)] * (*y)[mind(4, 2)],
|
||||
(*x)[mind(2, 1)] * (*y)[mind(1, 3)] + (*x)[mind(2, 2)] * (*y)[mind(2, 3)] +
|
||||
(*x)[mind(2, 3)] * (*y)[mind(3, 3)] + (*x)[mind(2, 4)] * (*y)[mind(4, 3)],
|
||||
(*x)[mind(2, 1)] * (*y)[mind(1, 4)] + (*x)[mind(2, 2)] * (*y)[mind(2, 4)] +
|
||||
(*x)[mind(2, 4)] * (*y)[mind(3, 4)] + (*x)[mind(2, 4)] * (*y)[mind(4, 4)],
|
||||
x[mind(2, 1)] * y[mind(1, 1)] + x[mind(2, 2)] * y[mind(2, 1)] +
|
||||
x[mind(2, 3)] * y[mind(3, 1)] + x[mind(2, 4)] * y[mind(4, 1)],
|
||||
x[mind(2, 1)] * y[mind(1, 2)] + x[mind(2, 2)] * y[mind(2, 2)] +
|
||||
x[mind(2, 3)] * y[mind(3, 2)] + x[mind(2, 4)] * y[mind(4, 2)],
|
||||
x[mind(2, 1)] * y[mind(1, 3)] + x[mind(2, 2)] * y[mind(2, 3)] +
|
||||
x[mind(2, 3)] * y[mind(3, 3)] + x[mind(2, 4)] * y[mind(4, 3)],
|
||||
x[mind(2, 1)] * y[mind(1, 4)] + x[mind(2, 2)] * y[mind(2, 4)] +
|
||||
x[mind(2, 4)] * y[mind(3, 4)] + x[mind(2, 4)] * y[mind(4, 4)],
|
||||
|
||||
(*x)[mind(3, 1)] * (*y)[mind(1, 1)] + (*x)[mind(3, 2)] * (*y)[mind(2, 1)] +
|
||||
(*x)[mind(3, 3)] * (*y)[mind(3, 1)] + (*x)[mind(3, 4)] * (*y)[mind(4, 1)],
|
||||
(*x)[mind(3, 1)] * (*y)[mind(1, 2)] + (*x)[mind(3, 2)] * (*y)[mind(2, 2)] +
|
||||
(*x)[mind(3, 3)] * (*y)[mind(3, 2)] + (*x)[mind(3, 4)] * (*y)[mind(4, 2)],
|
||||
(*x)[mind(3, 1)] * (*y)[mind(1, 3)] + (*x)[mind(3, 2)] * (*y)[mind(2, 3)] +
|
||||
(*x)[mind(3, 3)] * (*y)[mind(3, 3)] + (*x)[mind(3, 4)] * (*y)[mind(4, 3)],
|
||||
(*x)[mind(3, 1)] * (*y)[mind(1, 4)] + (*x)[mind(3, 2)] * (*y)[mind(2, 4)] +
|
||||
(*x)[mind(3, 4)] * (*y)[mind(3, 4)] + (*x)[mind(3, 4)] * (*y)[mind(4, 4)],
|
||||
x[mind(3, 1)] * y[mind(1, 1)] + x[mind(3, 2)] * y[mind(2, 1)] +
|
||||
x[mind(3, 3)] * y[mind(3, 1)] + x[mind(3, 4)] * y[mind(4, 1)],
|
||||
x[mind(3, 1)] * y[mind(1, 2)] + x[mind(3, 2)] * y[mind(2, 2)] +
|
||||
x[mind(3, 3)] * y[mind(3, 2)] + x[mind(3, 4)] * y[mind(4, 2)],
|
||||
x[mind(3, 1)] * y[mind(1, 3)] + x[mind(3, 2)] * y[mind(2, 3)] +
|
||||
x[mind(3, 3)] * y[mind(3, 3)] + x[mind(3, 4)] * y[mind(4, 3)],
|
||||
x[mind(3, 1)] * y[mind(1, 4)] + x[mind(3, 2)] * y[mind(2, 4)] +
|
||||
x[mind(3, 4)] * y[mind(3, 4)] + x[mind(3, 4)] * y[mind(4, 4)],
|
||||
|
||||
(*x)[mind(4, 1)] * (*y)[mind(1, 1)] + (*x)[mind(4, 2)] * (*y)[mind(2, 1)] +
|
||||
(*x)[mind(4, 3)] * (*y)[mind(3, 1)] + (*x)[mind(4, 4)] * (*y)[mind(4, 1)],
|
||||
(*x)[mind(4, 1)] * (*y)[mind(1, 2)] + (*x)[mind(4, 2)] * (*y)[mind(2, 2)] +
|
||||
(*x)[mind(4, 3)] * (*y)[mind(3, 2)] + (*x)[mind(4, 4)] * (*y)[mind(4, 2)],
|
||||
(*x)[mind(4, 1)] * (*y)[mind(1, 3)] + (*x)[mind(4, 2)] * (*y)[mind(2, 3)] +
|
||||
(*x)[mind(4, 3)] * (*y)[mind(3, 3)] + (*x)[mind(4, 4)] * (*y)[mind(4, 3)],
|
||||
(*x)[mind(4, 1)] * (*y)[mind(1, 4)] + (*x)[mind(4, 2)] * (*y)[mind(2, 4)] +
|
||||
(*x)[mind(4, 4)] * (*y)[mind(3, 4)] + (*x)[mind(4, 4)] * (*y)[mind(4, 4)],
|
||||
x[mind(4, 1)] * y[mind(1, 1)] + x[mind(4, 2)] * y[mind(2, 1)] +
|
||||
x[mind(4, 3)] * y[mind(3, 1)] + x[mind(4, 4)] * y[mind(4, 1)],
|
||||
x[mind(4, 1)] * y[mind(1, 2)] + x[mind(4, 2)] * y[mind(2, 2)] +
|
||||
x[mind(4, 3)] * y[mind(3, 2)] + x[mind(4, 4)] * y[mind(4, 2)],
|
||||
x[mind(4, 1)] * y[mind(1, 3)] + x[mind(4, 2)] * y[mind(2, 3)] +
|
||||
x[mind(4, 3)] * y[mind(3, 3)] + x[mind(4, 4)] * y[mind(4, 3)],
|
||||
x[mind(4, 1)] * y[mind(1, 4)] + x[mind(4, 2)] * y[mind(2, 4)] +
|
||||
x[mind(4, 4)] * y[mind(3, 4)] + x[mind(4, 4)] * y[mind(4, 4)],
|
||||
};
|
||||
memcpy(*product, _product, sizeof(_product));
|
||||
memcpy(mat, product, sizeof(product));
|
||||
}
|
||||
|
||||
static const float transforms[][4] = {
|
||||
|
|
@ -161,9 +162,9 @@ void wlr_matrix_texture(float mat[static 16], int32_t width, int32_t height,
|
|||
mat[15] = 1.0f;
|
||||
}
|
||||
|
||||
void wlr_matrix_project_box(float (*mat)[16], struct wlr_box *box,
|
||||
void wlr_matrix_project_box(float mat[static 16], const struct wlr_box *box,
|
||||
enum wl_output_transform transform, float rotation,
|
||||
float (*projection)[16]) {
|
||||
const float projection[static 16]) {
|
||||
int x = box->x;
|
||||
int y = box->y;
|
||||
int width = box->width;
|
||||
|
|
@ -173,38 +174,38 @@ void wlr_matrix_project_box(float (*mat)[16], struct wlr_box *box,
|
|||
|
||||
if (rotation != 0) {
|
||||
float translate_center[16];
|
||||
wlr_matrix_translate(&translate_center, width/2, height/2, 0);
|
||||
wlr_matrix_translate(translate_center, width/2, height/2, 0);
|
||||
|
||||
float rotate[16];
|
||||
wlr_matrix_rotate(&rotate, rotation);
|
||||
wlr_matrix_rotate(rotate, rotation);
|
||||
|
||||
float translate_origin[16];
|
||||
wlr_matrix_translate(&translate_origin, -width/2, -height/2, 0);
|
||||
wlr_matrix_translate(translate_origin, -width/2, -height/2, 0);
|
||||
|
||||
wlr_matrix_mul(mat, &translate_center, mat);
|
||||
wlr_matrix_mul(mat, &rotate, mat);
|
||||
wlr_matrix_mul(mat, &translate_origin, mat);
|
||||
wlr_matrix_mul(mat, mat, translate_center);
|
||||
wlr_matrix_mul(mat, mat, rotate);
|
||||
wlr_matrix_mul(mat, mat, translate_origin);
|
||||
}
|
||||
|
||||
float scale[16];
|
||||
wlr_matrix_scale(&scale, width, height, 1);
|
||||
wlr_matrix_scale(scale, width, height, 1);
|
||||
|
||||
wlr_matrix_mul(mat, &scale, mat);
|
||||
wlr_matrix_mul(mat, mat, scale);
|
||||
|
||||
if (transform != WL_OUTPUT_TRANSFORM_NORMAL) {
|
||||
float surface_translate_center[16];
|
||||
wlr_matrix_translate(&surface_translate_center, 0.5, 0.5, 0);
|
||||
wlr_matrix_translate(surface_translate_center, 0.5, 0.5, 0);
|
||||
|
||||
float surface_transform[16];
|
||||
wlr_matrix_transform(surface_transform, transform);
|
||||
|
||||
float surface_translate_origin[16];
|
||||
wlr_matrix_translate(&surface_translate_origin, -0.5, -0.5, 0);
|
||||
wlr_matrix_translate(surface_translate_origin, -0.5, -0.5, 0);
|
||||
|
||||
wlr_matrix_mul(mat, &surface_translate_center, mat);
|
||||
wlr_matrix_mul(mat, &surface_transform, mat);
|
||||
wlr_matrix_mul(mat, &surface_translate_origin, mat);
|
||||
wlr_matrix_mul(mat, mat, surface_translate_center);
|
||||
wlr_matrix_mul(mat, mat, surface_transform);
|
||||
wlr_matrix_mul(mat, mat, surface_translate_origin);
|
||||
}
|
||||
|
||||
wlr_matrix_mul(projection, mat, mat);
|
||||
wlr_matrix_mul(mat, projection, mat);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -368,7 +368,7 @@ static void output_fullscreen_surface_render(struct wlr_output *output,
|
|||
assert(renderer);
|
||||
|
||||
if (!wlr_surface_has_buffer(surface)) {
|
||||
wlr_renderer_clear(renderer, &(float[]){0, 0, 0, 0});
|
||||
wlr_renderer_clear(renderer, (float[]){0, 0, 0, 0});
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -378,15 +378,15 @@ static void output_fullscreen_surface_render(struct wlr_output *output,
|
|||
float matrix[16];
|
||||
enum wl_output_transform transform =
|
||||
wlr_output_transform_invert(surface->current->transform);
|
||||
wlr_matrix_project_box(&matrix, &box, transform, 0,
|
||||
&output->transform_matrix);
|
||||
wlr_matrix_project_box(matrix, &box, transform, 0,
|
||||
output->transform_matrix);
|
||||
|
||||
int nrects;
|
||||
pixman_box32_t *rects = pixman_region32_rectangles(damage, &nrects);
|
||||
for (int i = 0; i < nrects; ++i) {
|
||||
output_scissor(output, &rects[i]);
|
||||
wlr_renderer_clear(renderer, &(float[]){0, 0, 0, 0});
|
||||
wlr_render_with_matrix(surface->renderer, surface->texture, &matrix, 1.0f);
|
||||
wlr_renderer_clear(renderer, (float[]){0, 0, 0, 0});
|
||||
wlr_render_with_matrix(surface->renderer, surface->texture, matrix, 1.0f);
|
||||
}
|
||||
wlr_renderer_scissor(renderer, NULL);
|
||||
|
||||
|
|
@ -436,14 +436,14 @@ static void output_cursor_render(struct wlr_output_cursor *cursor,
|
|||
}
|
||||
|
||||
float matrix[16];
|
||||
wlr_matrix_project_box(&matrix, &box, WL_OUTPUT_TRANSFORM_NORMAL, 0,
|
||||
&cursor->output->transform_matrix);
|
||||
wlr_matrix_project_box(matrix, &box, WL_OUTPUT_TRANSFORM_NORMAL, 0,
|
||||
cursor->output->transform_matrix);
|
||||
|
||||
int nrects;
|
||||
pixman_box32_t *rects = pixman_region32_rectangles(&surface_damage, &nrects);
|
||||
for (int i = 0; i < nrects; ++i) {
|
||||
output_scissor(cursor->output, &rects[i]);
|
||||
wlr_render_with_matrix(renderer, texture, &matrix, 1.0f);
|
||||
wlr_render_with_matrix(renderer, texture, matrix, 1.0f);
|
||||
}
|
||||
wlr_renderer_scissor(renderer, NULL);
|
||||
|
||||
|
|
|
|||
|
|
@ -625,19 +625,19 @@ struct wlr_surface *wlr_surface_create(struct wl_resource *res,
|
|||
}
|
||||
|
||||
void wlr_surface_get_matrix(struct wlr_surface *surface,
|
||||
float (*matrix)[16],
|
||||
const float (*projection)[16],
|
||||
const float (*transform)[16]) {
|
||||
float mat[static 16],
|
||||
const float projection[static 16],
|
||||
const float transform[static 16]) {
|
||||
int width = surface->texture->width;
|
||||
int height = surface->texture->height;
|
||||
float scale[16];
|
||||
wlr_matrix_identity(matrix);
|
||||
wlr_matrix_identity(mat);
|
||||
if (transform) {
|
||||
wlr_matrix_mul(matrix, transform, matrix);
|
||||
wlr_matrix_mul(mat, mat, transform);
|
||||
}
|
||||
wlr_matrix_scale(&scale, width, height, 1);
|
||||
wlr_matrix_mul(matrix, &scale, matrix);
|
||||
wlr_matrix_mul(projection, matrix, matrix);
|
||||
wlr_matrix_scale(scale, width, height, 1);
|
||||
wlr_matrix_mul(mat, mat, scale);
|
||||
wlr_matrix_mul(mat, projection, mat);
|
||||
}
|
||||
|
||||
bool wlr_surface_has_buffer(struct wlr_surface *surface) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue