diff options
author | Drew DeVault <sir@cmpwn.com> | 2017-08-07 08:01:32 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-07 08:01:32 -0400 |
commit | ab063c3936ff8dd0ee34388cbd260dccc59661df (patch) | |
tree | d7ad82aa3e5b3dbdfa494a7b7751b4dbd7c7ad9c /render | |
parent | f95c02eebe54785a4f64332f7e574dddff7e3669 (diff) | |
parent | d09ca20a4dccd7696423fc9f17acc88b7b3a7986 (diff) |
Merge pull request #44 from ascent12/drm
DRM plane support, refactoring, and other changes
Diffstat (limited to 'render')
-rw-r--r-- | render/matrix.c | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/render/matrix.c b/render/matrix.c index 4de20e5d..c7b11efe 100644 --- a/render/matrix.c +++ b/render/matrix.c @@ -1,5 +1,6 @@ #include <string.h> #include <math.h> +#include <wayland-server-protocol.h> #include <wlr/render/matrix.h> /* Obtains the index for the given row/column */ @@ -81,3 +82,62 @@ void wlr_matrix_mul(const float (*x)[16], const float (*y)[16], float (*product) }; 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, + }, +}; + +// Equivilent to glOrtho(0, width, 0, height, 1, -1) with the transform applied +void wlr_matrix_surface(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 + relection + 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; +} |