From b6a3f240c7621d1ebb5774fcdf7784d976500ee1 Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 15 Mar 2018 09:11:03 +0100 Subject: matrix: move to types/ --- backend/drm/drm.c | 2 +- backend/drm/renderer.c | 2 +- examples/multi-pointer.c | 2 +- examples/output-layout.c | 2 +- examples/pointer.c | 2 +- examples/rotation.c | 2 +- examples/tablet.c | 2 +- examples/touch.c | 2 +- include/wlr/render/matrix.h | 22 ----- include/wlr/types/wlr_matrix.h | 22 +++++ render/gles2/renderer.c | 2 +- render/gles2/texture.c | 2 +- render/matrix.c | 210 ----------------------------------------- render/meson.build | 1 - rootston/output.c | 2 +- types/meson.build | 3 +- types/wlr_matrix.c | 210 +++++++++++++++++++++++++++++++++++++++++ types/wlr_output.c | 2 +- types/wlr_surface.c | 2 +- 19 files changed, 247 insertions(+), 247 deletions(-) delete mode 100644 include/wlr/render/matrix.h create mode 100644 include/wlr/types/wlr_matrix.h delete mode 100644 render/matrix.c create mode 100644 types/wlr_matrix.c diff --git a/backend/drm/drm.c b/backend/drm/drm.c index 0d1d527d..af701c6a 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/backend/drm/renderer.c b/backend/drm/renderer.c index 7ee13843..13311df3 100644 --- a/backend/drm/renderer.c +++ b/backend/drm/renderer.c @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include #include "backend/drm/drm.h" #include "glapi.h" diff --git a/examples/multi-pointer.c b/examples/multi-pointer.c index d3d425f2..6e56bfdc 100644 --- a/examples/multi-pointer.c +++ b/examples/multi-pointer.c @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/examples/output-layout.c b/examples/output-layout.c index 45257be9..8ba77861 100644 --- a/examples/output-layout.c +++ b/examples/output-layout.c @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/examples/pointer.c b/examples/pointer.c index 0dbd02d2..e80b346a 100644 --- a/examples/pointer.c +++ b/examples/pointer.c @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/examples/rotation.c b/examples/rotation.c index 1158ccc4..e38d53f4 100644 --- a/examples/rotation.c +++ b/examples/rotation.c @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/examples/tablet.c b/examples/tablet.c index 5bfa1271..aa02c6f4 100644 --- a/examples/tablet.c +++ b/examples/tablet.c @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/examples/touch.c b/examples/touch.c index 278252cc..7b4559b9 100644 --- a/examples/touch.c +++ b/examples/touch.c @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/include/wlr/render/matrix.h b/include/wlr/render/matrix.h deleted file mode 100644 index a333bf0f..00000000 --- a/include/wlr/render/matrix.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef WLR_RENDER_MATRIX_H -#define WLR_RENDER_MATRIX_H - -#include -#include - -void wlr_matrix_identity(float (*output)[16]); -void wlr_matrix_translate(float (*output)[16], float x, float y, float z); -void wlr_matrix_scale(float (*output)[16], float x, float y, float z); -void wlr_matrix_rotate(float (*output)[16], float radians); -void wlr_matrix_mul(const float (*x)[16], const float (*y)[16], float (*product)[16]); - -enum wl_output_transform; -void wlr_matrix_transform(float mat[static 16], - enum wl_output_transform transform); -void wlr_matrix_texture(float mat[static 16], int32_t width, int32_t height, - enum wl_output_transform transform); -void wlr_matrix_project_box(float (*mat)[16], struct wlr_box *box, - enum wl_output_transform transform, float rotation, float - (*projection)[16]); - -#endif diff --git a/include/wlr/types/wlr_matrix.h b/include/wlr/types/wlr_matrix.h new file mode 100644 index 00000000..498b643c --- /dev/null +++ b/include/wlr/types/wlr_matrix.h @@ -0,0 +1,22 @@ +#ifndef WLR_TYPES_WLR_MATRIX_H +#define WLR_TYPES_WLR_MATRIX_H + +#include +#include + +void wlr_matrix_identity(float (*output)[16]); +void wlr_matrix_translate(float (*output)[16], float x, float y, float z); +void wlr_matrix_scale(float (*output)[16], float x, float y, float z); +void wlr_matrix_rotate(float (*output)[16], float radians); +void wlr_matrix_mul(const float (*x)[16], const float (*y)[16], float (*product)[16]); + +enum wl_output_transform; +void wlr_matrix_transform(float mat[static 16], + enum wl_output_transform transform); +void wlr_matrix_texture(float mat[static 16], int32_t width, int32_t height, + enum wl_output_transform transform); +void wlr_matrix_project_box(float (*mat)[16], struct wlr_box *box, + enum wl_output_transform transform, float rotation, float + (*projection)[16]); + +#endif diff --git a/render/gles2/renderer.c b/render/gles2/renderer.c index ad739cf8..5b1395fb 100644 --- a/render/gles2/renderer.c +++ b/render/gles2/renderer.c @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include #include "render/gles2.h" #include "glapi.h" diff --git a/render/gles2/texture.c b/render/gles2/texture.c index 241b94a8..7a180446 100644 --- a/render/gles2/texture.c +++ b/render/gles2/texture.c @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include #include "render/gles2.h" #include "util/signal.h" diff --git a/render/matrix.c b/render/matrix.c deleted file mode 100644 index d5d7f49d..00000000 --- a/render/matrix.c +++ /dev/null @@ -1,210 +0,0 @@ -#include -#include -#include -#include -#include -#include - -/* Obtains the index for the given row/column */ -static inline int mind(int row, int col) { - return (row - 1) * 4 + col - 1; -} - -void wlr_matrix_identity(float (*output)[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 - }; - memcpy(*output, 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_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_rotate(float (*output)[16], float radians) { - wlr_matrix_identity(output); - 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; -} - -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)], - - (*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(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)); -} - -static const float transforms[][4] = { - [WL_OUTPUT_TRANSFORM_NORMAL] = { - 1.0f, 0.0f, - 0.0f, 1.0f, - }, - [WL_OUTPUT_TRANSFORM_90] = { - 0.0f, -1.0f, - 1.0f, 0.0f, - }, - [WL_OUTPUT_TRANSFORM_180] = { - -1.0f, 0.0f, - 0.0f, -1.0f, - }, - [WL_OUTPUT_TRANSFORM_270] = { - 0.0f, 1.0f, - -1.0f, 0.0f, - }, - [WL_OUTPUT_TRANSFORM_FLIPPED] = { - -1.0f, 0.0f, - 0.0f, 1.0f, - }, - [WL_OUTPUT_TRANSFORM_FLIPPED_90] = { - 0.0f, -1.0f, - -1.0f, 0.0f, - }, - [WL_OUTPUT_TRANSFORM_FLIPPED_180] = { - 1.0f, 0.0f, - 0.0f, -1.0f, - }, - [WL_OUTPUT_TRANSFORM_FLIPPED_270] = { - 0.0f, 1.0f, - 1.0f, 0.0f, - }, -}; - -void wlr_matrix_transform(float mat[static 16], - enum wl_output_transform transform) { - memset(mat, 0, sizeof(*mat) * 16); - - const float *t = transforms[transform]; - - // Rotation + reflection - mat[0] = t[0]; - mat[1] = t[1]; - mat[4] = t[2]; - mat[5] = t[3]; - - // Identity - mat[10] = 1.0f; - mat[15] = 1.0f; -} - -// Equivilent to glOrtho(0, width, 0, height, 1, -1) with the transform applied -void wlr_matrix_texture(float mat[static 16], int32_t width, int32_t height, - enum wl_output_transform transform) { - memset(mat, 0, sizeof(*mat) * 16); - - const float *t = transforms[transform]; - float x = 2.0f / width; - float y = 2.0f / height; - - // Rotation + reflection - mat[0] = x * t[0]; - mat[1] = x * t[1]; - mat[4] = y * -t[2]; - mat[5] = y * -t[3]; - - // Translation - mat[3] = -copysign(1.0f, mat[0] + mat[1]); - mat[7] = -copysign(1.0f, mat[4] + mat[5]); - - // Identity - mat[10] = 1.0f; - mat[15] = 1.0f; -} - -void wlr_matrix_project_box(float (*mat)[16], struct wlr_box *box, - enum wl_output_transform transform, float rotation, - float (*projection)[16]) { - int x = box->x; - int y = box->y; - int width = box->width; - int height = box->height; - - wlr_matrix_translate(mat, x, y, 0); - - if (rotation != 0) { - float translate_center[16]; - wlr_matrix_translate(&translate_center, width/2, height/2, 0); - - float rotate[16]; - wlr_matrix_rotate(&rotate, rotation); - - float translate_origin[16]; - 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); - } - - float scale[16]; - wlr_matrix_scale(&scale, width, height, 1); - - wlr_matrix_mul(mat, &scale, mat); - - if (transform != WL_OUTPUT_TRANSFORM_NORMAL) { - float surface_translate_center[16]; - 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_mul(mat, &surface_translate_center, mat); - wlr_matrix_mul(mat, &surface_transform, mat); - wlr_matrix_mul(mat, &surface_translate_origin, mat); - } - - wlr_matrix_mul(projection, mat, mat); -} diff --git a/render/meson.build b/render/meson.build index 8aa70cea..4fe9ea67 100644 --- a/render/meson.build +++ b/render/meson.build @@ -15,7 +15,6 @@ lib_wlr_render = static_library( 'gles2/shaders.c', 'gles2/texture.c', 'gles2/util.c', - 'matrix.c', 'wlr_renderer.c', 'wlr_texture.c', ), diff --git a/rootston/output.c b/rootston/output.c index 4d0a9c05..bdf025ad 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/types/meson.build b/types/meson.build index 703b06ca..91b4326d 100644 --- a/types/meson.build +++ b/types/meson.build @@ -6,10 +6,12 @@ lib_wlr_types = static_library( 'wlr_cursor.c', 'wlr_data_device.c', 'wlr_gamma_control.c', + 'wlr_idle_inhibit_v1.c', 'wlr_idle.c', 'wlr_input_device.c', 'wlr_keyboard.c', 'wlr_list.c', + 'wlr_matrix.c', 'wlr_output_damage.c', 'wlr_output_layout.c', 'wlr_output.c', @@ -27,7 +29,6 @@ lib_wlr_types = static_library( 'wlr_xcursor_manager.c', 'wlr_xdg_shell_v6.c', 'wlr_xdg_shell.c', - 'wlr_idle_inhibit_v1.c', ), include_directories: wlr_inc, dependencies: [pixman, xkbcommon, wayland_server, wlr_protos], diff --git a/types/wlr_matrix.c b/types/wlr_matrix.c new file mode 100644 index 00000000..f3546e0e --- /dev/null +++ b/types/wlr_matrix.c @@ -0,0 +1,210 @@ +#include +#include +#include +#include +#include +#include + +/* Obtains the index for the given row/column */ +static inline int mind(int row, int col) { + return (row - 1) * 4 + col - 1; +} + +void wlr_matrix_identity(float (*output)[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 + }; + memcpy(*output, 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_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_rotate(float (*output)[16], float radians) { + wlr_matrix_identity(output); + 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; +} + +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)], + + (*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(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)); +} + +static const float transforms[][4] = { + [WL_OUTPUT_TRANSFORM_NORMAL] = { + 1.0f, 0.0f, + 0.0f, 1.0f, + }, + [WL_OUTPUT_TRANSFORM_90] = { + 0.0f, -1.0f, + 1.0f, 0.0f, + }, + [WL_OUTPUT_TRANSFORM_180] = { + -1.0f, 0.0f, + 0.0f, -1.0f, + }, + [WL_OUTPUT_TRANSFORM_270] = { + 0.0f, 1.0f, + -1.0f, 0.0f, + }, + [WL_OUTPUT_TRANSFORM_FLIPPED] = { + -1.0f, 0.0f, + 0.0f, 1.0f, + }, + [WL_OUTPUT_TRANSFORM_FLIPPED_90] = { + 0.0f, -1.0f, + -1.0f, 0.0f, + }, + [WL_OUTPUT_TRANSFORM_FLIPPED_180] = { + 1.0f, 0.0f, + 0.0f, -1.0f, + }, + [WL_OUTPUT_TRANSFORM_FLIPPED_270] = { + 0.0f, 1.0f, + 1.0f, 0.0f, + }, +}; + +void wlr_matrix_transform(float mat[static 16], + enum wl_output_transform transform) { + memset(mat, 0, sizeof(*mat) * 16); + + const float *t = transforms[transform]; + + // Rotation + reflection + mat[0] = t[0]; + mat[1] = t[1]; + mat[4] = t[2]; + mat[5] = t[3]; + + // Identity + mat[10] = 1.0f; + mat[15] = 1.0f; +} + +// Equivilent to glOrtho(0, width, 0, height, 1, -1) with the transform applied +void wlr_matrix_texture(float mat[static 16], int32_t width, int32_t height, + enum wl_output_transform transform) { + memset(mat, 0, sizeof(*mat) * 16); + + const float *t = transforms[transform]; + float x = 2.0f / width; + float y = 2.0f / height; + + // Rotation + reflection + mat[0] = x * t[0]; + mat[1] = x * t[1]; + mat[4] = y * -t[2]; + mat[5] = y * -t[3]; + + // Translation + mat[3] = -copysign(1.0f, mat[0] + mat[1]); + mat[7] = -copysign(1.0f, mat[4] + mat[5]); + + // Identity + mat[10] = 1.0f; + mat[15] = 1.0f; +} + +void wlr_matrix_project_box(float (*mat)[16], struct wlr_box *box, + enum wl_output_transform transform, float rotation, + float (*projection)[16]) { + int x = box->x; + int y = box->y; + int width = box->width; + int height = box->height; + + wlr_matrix_translate(mat, x, y, 0); + + if (rotation != 0) { + float translate_center[16]; + wlr_matrix_translate(&translate_center, width/2, height/2, 0); + + float rotate[16]; + wlr_matrix_rotate(&rotate, rotation); + + float translate_origin[16]; + 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); + } + + float scale[16]; + wlr_matrix_scale(&scale, width, height, 1); + + wlr_matrix_mul(mat, &scale, mat); + + if (transform != WL_OUTPUT_TRANSFORM_NORMAL) { + float surface_translate_center[16]; + 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_mul(mat, &surface_translate_center, mat); + wlr_matrix_mul(mat, &surface_transform, mat); + wlr_matrix_mul(mat, &surface_translate_origin, mat); + } + + wlr_matrix_mul(projection, mat, mat); +} diff --git a/types/wlr_output.c b/types/wlr_output.c index 7f19d1fe..21343a68 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/types/wlr_surface.c b/types/wlr_surface.c index 23966cd1..5d52fd2a 100644 --- a/types/wlr_surface.c +++ b/types/wlr_surface.c @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include #include #include -- cgit v1.2.3