diff options
-rw-r--r-- | include/wlr/render/matrix.h | 3 | ||||
-rw-r--r-- | include/wlr/types/wlr_output.h | 7 | ||||
-rw-r--r-- | render/matrix.c | 46 | ||||
-rw-r--r-- | rootston/output.c | 25 | ||||
-rw-r--r-- | types/wlr_output.c | 43 |
5 files changed, 68 insertions, 56 deletions
diff --git a/include/wlr/render/matrix.h b/include/wlr/render/matrix.h index 0b35aad3..dbd06c8d 100644 --- a/include/wlr/render/matrix.h +++ b/include/wlr/render/matrix.h @@ -2,6 +2,7 @@ #define WLR_RENDER_MATRIX_H #include <stdint.h> +#include <wlr/types/wlr_box.h> void wlr_matrix_identity(float (*output)[16]); void wlr_matrix_translate(float (*output)[16], float x, float y, float z); @@ -14,5 +15,7 @@ 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_box_model(float (*mat)[16], struct wlr_box *box, + enum wl_output_transform transform, float rotation); #endif diff --git a/include/wlr/types/wlr_output.h b/include/wlr/types/wlr_output.h index 4c59d98b..71463cb5 100644 --- a/include/wlr/types/wlr_output.h +++ b/include/wlr/types/wlr_output.h @@ -136,11 +136,4 @@ enum wl_output_transform wlr_output_transform_invert( enum wl_output_transform wlr_output_transform_compose( enum wl_output_transform tr_a, enum wl_output_transform tr_b); -/** - * Get a matrix suitable for rendering a box on the output. - */ -void wlr_output_get_box_matrix(struct wlr_output *output, int ox, int oy, - int width, int height, enum wl_output_transform transform, - float rotation, float (*mat)[16]); - #endif diff --git a/render/matrix.c b/render/matrix.c index 54dba4cc..a64a8f9b 100644 --- a/render/matrix.c +++ b/render/matrix.c @@ -1,6 +1,8 @@ #include <string.h> #include <math.h> #include <wayland-server-protocol.h> +#include <wlr/types/wlr_box.h> +#include <wlr/types/wlr_output.h> #include <wlr/render/matrix.h> /* Obtains the index for the given row/column */ @@ -158,3 +160,47 @@ void wlr_matrix_texture(float mat[static 16], int32_t width, int32_t height, mat[10] = 1.0f; mat[15] = 1.0f; } + +void wlr_matrix_box_model(float (*mat)[16], struct wlr_box *box, + enum wl_output_transform transform, float rotation) { + int x = box->x; + int y = box->y; + int width = box->width; + int height = box->height; + + float translate_center[16]; + wlr_matrix_translate(&translate_center, + (int)x + width / 2, (int)y + 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); + + float scale[16]; + wlr_matrix_scale(&scale, width, height, 1); + + wlr_matrix_mul(&translate_center, &rotate, mat); + wlr_matrix_mul(mat, &translate_origin, mat); + 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, + wlr_output_transform_invert(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); + } +} diff --git a/rootston/output.c b/rootston/output.c index 502e72d2..3680beac 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -52,9 +52,16 @@ static void render_surface(struct wlr_surface *surface, .width = render_width, .height = render_height, }; if (wlr_output_layout_intersects(desktop->layout, wlr_output, &render_box)) { + struct wlr_box model_box = { + .x = ox, + .y = oy, + .width = render_width, + .height = render_height, + }; float matrix[16]; - wlr_output_get_box_matrix(wlr_output, ox, oy, render_width, - render_height, surface->current->transform, rotation, &matrix); + wlr_matrix_box_model(&matrix, &model_box, surface->current->transform, + rotation); + wlr_matrix_mul(&wlr_output->transform_matrix, &matrix, &matrix); wlr_render_with_matrix(desktop->server->renderer, surface->texture, &matrix); @@ -157,11 +164,17 @@ static void render_decorations(struct roots_view *view, ox *= output->scale; oy *= output->scale; - float matrix[16]; - wlr_output_get_box_matrix(output, ox, oy, deco_box.width, - deco_box.height, WL_OUTPUT_TRANSFORM_NORMAL, view->rotation, - &matrix); + struct wlr_box model_box = { + .x = ox, + .y = oy, + .width = deco_box.width, + .height = deco_box.height, + }; + float matrix[16]; + wlr_matrix_box_model(&matrix, &model_box, WL_OUTPUT_TRANSFORM_NORMAL, + view->rotation); + wlr_matrix_mul(&output->transform_matrix, &matrix, &matrix); float color[4] = { 0.2, 0.2, 0.2, 1 }; wlr_render_colored_quad(desktop->server->renderer, &color, &matrix); } diff --git a/types/wlr_output.c b/types/wlr_output.c index 178306a8..b47fb3a0 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -751,46 +751,3 @@ enum wl_output_transform wlr_output_transform_compose( } return flipped | rotated; } - -void wlr_output_get_box_matrix(struct wlr_output *output, int ox, int oy, - int width, int height, enum wl_output_transform transform, - float rotation, float (*mat)[16]) { - float translate_center[16]; - wlr_matrix_translate(&translate_center, - (int)ox + width / 2, (int)oy + 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); - - float scale[16]; - wlr_matrix_scale(&scale, width, height, 1); - - float transform_matrix[16]; - wlr_matrix_mul(&translate_center, &rotate, &transform_matrix); - wlr_matrix_mul(&transform_matrix, &translate_origin, &transform_matrix); - wlr_matrix_mul(&transform_matrix, &scale, &transform_matrix); - - 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, - wlr_output_transform_invert(transform)); - - float surface_translate_origin[16]; - wlr_matrix_translate(&surface_translate_origin, -0.5, -0.5, 0); - - wlr_matrix_mul(&transform_matrix, &surface_translate_center, - &transform_matrix); - wlr_matrix_mul(&transform_matrix, &surface_transform, &transform_matrix); - wlr_matrix_mul(&transform_matrix, &surface_translate_origin, - &transform_matrix); - } - - wlr_matrix_mul(&output->transform_matrix, &transform_matrix, mat); -} |