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 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'backend') 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" -- cgit v1.2.3 From d26b67cb06509fb39d9ed473a5d27b1f241ff635 Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 15 Mar 2018 11:10:56 +0100 Subject: matrix: unify API, don't use array pointers --- backend/drm/drm.c | 4 +- backend/drm/renderer.c | 2 +- examples/output-layout.c | 8 +-- examples/rotation.c | 8 +-- examples/tablet.c | 19 +++--- examples/touch.c | 10 +-- include/wlr/render.h | 12 ++-- include/wlr/render/interface.h | 13 ++-- include/wlr/types/wlr_matrix.h | 21 +++--- include/wlr/types/wlr_surface.h | 7 +- render/gles2/renderer.c | 21 +++--- render/gles2/texture.c | 14 ++-- render/wlr_renderer.c | 9 +-- render/wlr_texture.c | 4 +- rootston/output.c | 14 ++-- types/wlr_matrix.c | 147 ++++++++++++++++++++-------------------- types/wlr_output.c | 16 ++--- types/wlr_surface.c | 16 ++--- 18 files changed, 175 insertions(+), 170 deletions(-) (limited to 'backend') diff --git a/backend/drm/drm.c b/backend/drm/drm.c index af701c6a..1e78d301 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -648,9 +648,9 @@ static bool wlr_drm_connector_set_cursor(struct wlr_output *output, glClear(GL_COLOR_BUFFER_BIT); float matrix[16]; - wlr_texture_get_matrix(plane->wlr_tex, &matrix, &plane->matrix, 0, 0); + wlr_texture_get_matrix(plane->wlr_tex, matrix, plane->matrix, 0, 0); wlr_render_with_matrix(plane->surf.renderer->wlr_rend, plane->wlr_tex, - &matrix, 1.0f); + matrix, 1.0f); glFinish(); glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, bo_stride); diff --git a/backend/drm/renderer.c b/backend/drm/renderer.c index 13311df3..ab56e6c2 100644 --- a/backend/drm/renderer.c +++ b/backend/drm/renderer.c @@ -239,7 +239,7 @@ struct gbm_bo *wlr_drm_surface_mgpu_copy(struct wlr_drm_surface *dest, glViewport(0, 0, dest->width, dest->height); glClearColor(0.0, 0.0, 0.0, 1.0); glClear(GL_COLOR_BUFFER_BIT); - wlr_render_with_matrix(dest->renderer->wlr_rend, tex, &matrix, 1.0f); + wlr_render_with_matrix(dest->renderer->wlr_rend, tex, matrix, 1.0f); return wlr_drm_surface_swap_buffers(dest, NULL); } diff --git a/examples/output-layout.c b/examples/output-layout.c index 8ba77861..f4df73a0 100644 --- a/examples/output-layout.c +++ b/examples/output-layout.c @@ -102,7 +102,7 @@ static void handle_output_frame(struct output_state *output, wlr_output_make_current(wlr_output, NULL); wlr_renderer_begin(sample->renderer, wlr_output); - wlr_renderer_clear(sample->renderer, &(float[]){0.25f, 0.25f, 0.25f, 1}); + wlr_renderer_clear(sample->renderer, (float[]){0.25f, 0.25f, 0.25f, 1}); animate_cat(sample, output->output); @@ -119,10 +119,10 @@ static void handle_output_frame(struct output_state *output, wlr_output_layout_output_coords(sample->layout, output->output, &local_x, &local_y); - wlr_texture_get_matrix(sample->cat_texture, &matrix, - &wlr_output->transform_matrix, local_x, local_y); + wlr_texture_get_matrix(sample->cat_texture, matrix, + wlr_output->transform_matrix, local_x, local_y); wlr_render_with_matrix(sample->renderer, - sample->cat_texture, &matrix, 1.0f); + sample->cat_texture, matrix, 1.0f); } wlr_renderer_end(sample->renderer); diff --git a/examples/rotation.c b/examples/rotation.c index e38d53f4..0b0c6adf 100644 --- a/examples/rotation.c +++ b/examples/rotation.c @@ -44,15 +44,15 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts wlr_output_make_current(wlr_output, NULL); wlr_renderer_begin(sample->renderer, wlr_output); - wlr_renderer_clear(sample->renderer, &(float[]){0.25f, 0.25f, 0.25f, 1}); + wlr_renderer_clear(sample->renderer, (float[]){0.25f, 0.25f, 0.25f, 1}); float matrix[16]; for (int y = -128 + (int)odata->y_offs; y < height; y += 128) { for (int x = -128 + (int)odata->x_offs; x < width; x += 128) { - wlr_texture_get_matrix(sample->cat_texture, &matrix, - &wlr_output->transform_matrix, x, y); + wlr_texture_get_matrix(sample->cat_texture, matrix, + wlr_output->transform_matrix, x, y); wlr_render_with_matrix(sample->renderer, - sample->cat_texture, &matrix, 1.0f); + sample->cat_texture, matrix, 1.0f); } } diff --git a/examples/tablet.c b/examples/tablet.c index aa02c6f4..82f86553 100644 --- a/examples/tablet.c +++ b/examples/tablet.c @@ -47,7 +47,7 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts wlr_output_make_current(wlr_output, NULL); wlr_renderer_begin(sample->renderer, wlr_output); - wlr_renderer_clear(sample->renderer, &(float[]){0.25f, 0.25f, 0.25f, 1}); + wlr_renderer_clear(sample->renderer, (float[]){0.25f, 0.25f, 0.25f, 1}); float matrix[16]; float distance = 0.8f * (1 - sample->distance); @@ -65,9 +65,8 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts .x = left, .y = top, .width = pad_width, .height = pad_height, }; - wlr_matrix_project_box(&matrix, &box, 0, 0, - &wlr_output->transform_matrix); - wlr_render_colored_quad(sample->renderer, &sample->pad_color, &matrix); + wlr_matrix_project_box(matrix, &box, 0, 0, wlr_output->transform_matrix); + wlr_render_colored_quad(sample->renderer, sample->pad_color, matrix); if (sample->proximity) { struct wlr_box box = { @@ -76,16 +75,16 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts .width = 16 * (sample->pressure + 1), .height = 16 * (sample->pressure + 1), }; - wlr_matrix_project_box(&matrix, &box, 0, sample->ring, - &wlr_output->transform_matrix); - wlr_render_colored_quad(sample->renderer, &tool_color, &matrix); + wlr_matrix_project_box(matrix, &box, 0, sample->ring, + wlr_output->transform_matrix); + wlr_render_colored_quad(sample->renderer, tool_color, matrix); box.x += sample->x_tilt; box.y += sample->y_tilt; box.width /= 2; box.height /= 2; - wlr_matrix_project_box(&matrix, &box, 0, 0, - &wlr_output->transform_matrix); - wlr_render_colored_quad(sample->renderer, &tool_color, &matrix); + wlr_matrix_project_box(matrix, &box, 0, 0, + wlr_output->transform_matrix); + wlr_render_colored_quad(sample->renderer, tool_color, matrix); } wlr_renderer_end(sample->renderer); diff --git a/examples/touch.c b/examples/touch.c index 7b4559b9..6f4821ad 100644 --- a/examples/touch.c +++ b/examples/touch.c @@ -43,17 +43,17 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts wlr_output_make_current(wlr_output, NULL); wlr_renderer_begin(sample->renderer, wlr_output); - wlr_renderer_clear(sample->renderer, &(float[]){0.25f, 0.25f, 0.25f, 1}); + wlr_renderer_clear(sample->renderer, (float[]){0.25f, 0.25f, 0.25f, 1}); float matrix[16]; struct touch_point *p; wl_list_for_each(p, &sample->touch_points, link) { - wlr_texture_get_matrix(sample->cat_texture, &matrix, - &wlr_output->transform_matrix, + wlr_texture_get_matrix(sample->cat_texture, matrix, + wlr_output->transform_matrix, (int)(p->x * width) - sample->cat_texture->width / 2, (int)(p->y * height) - sample->cat_texture->height / 2); - wlr_render_with_matrix(sample->renderer, - sample->cat_texture, &matrix, 1.0f); + wlr_render_with_matrix(sample->renderer, sample->cat_texture, + matrix, 1.0f); } wlr_renderer_end(sample->renderer); diff --git a/include/wlr/render.h b/include/wlr/render.h index 747603da..50c2dd13 100644 --- a/include/wlr/render.h +++ b/include/wlr/render.h @@ -13,7 +13,7 @@ struct wlr_renderer; void wlr_renderer_begin(struct wlr_renderer *r, struct wlr_output *output); void wlr_renderer_end(struct wlr_renderer *r); -void wlr_renderer_clear(struct wlr_renderer *r, const float (*color)[4]); +void wlr_renderer_clear(struct wlr_renderer *r, const float color[static 4]); /** * Defines a scissor box. Only pixels that lie within the scissor box can be * modified by drawing functions. Providing a NULL `box` disables the scissor @@ -38,18 +38,18 @@ struct wlr_texture *wlr_render_texture_create(struct wlr_renderer *r); * This will render the texture at <123, 321> with an alpha channel of 0.5. */ bool wlr_render_with_matrix(struct wlr_renderer *r, - struct wlr_texture *texture, const float (*matrix)[16], float alpha); + struct wlr_texture *texture, const float matrix[static 16], float alpha); /** * Renders a solid quad in the specified color. */ void wlr_render_colored_quad(struct wlr_renderer *r, - const float (*color)[4], const float (*matrix)[16]); + const float color[static 4], const float matrix[static 16]); /** * Renders a solid ellipse in the specified color. */ void wlr_render_colored_ellipse(struct wlr_renderer *r, - const float (*color)[4], const float (*matrix)[16]); + const float color[static 4], const float matrix[static 16]); /** * Returns a list of pixel formats supported by this renderer. */ @@ -139,8 +139,8 @@ bool wlr_texture_update_shm(struct wlr_texture *surf, uint32_t format, * width) and [0, height], and the x and y coordinates provided are used as * such. */ -void wlr_texture_get_matrix(struct wlr_texture *texture, - float (*matrix)[16], const float (*projection)[16], int x, int y); +void wlr_texture_get_matrix(struct wlr_texture *texture, float mat[static 16], + const float projection[static 16], int x, int y); /** * Destroys this wlr_texture. */ diff --git a/include/wlr/render/interface.h b/include/wlr/render/interface.h index eda5af1c..4d81bdf9 100644 --- a/include/wlr/render/interface.h +++ b/include/wlr/render/interface.h @@ -18,15 +18,16 @@ struct wlr_renderer { struct wlr_renderer_impl { void (*begin)(struct wlr_renderer *renderer, struct wlr_output *output); void (*end)(struct wlr_renderer *renderer); - void (*clear)(struct wlr_renderer *renderer, const float (*color)[4]); + void (*clear)(struct wlr_renderer *renderer, const float color[static 4]); void (*scissor)(struct wlr_renderer *renderer, struct wlr_box *box); struct wlr_texture *(*texture_create)(struct wlr_renderer *renderer); bool (*render_with_matrix)(struct wlr_renderer *renderer, - struct wlr_texture *texture, const float (*matrix)[16], float alpha); + struct wlr_texture *texture, const float matrix[static 16], + float alpha); void (*render_quad)(struct wlr_renderer *renderer, - const float (*color)[4], const float (*matrix)[16]); + const float color[static 4], const float matrix[static 16]); void (*render_ellipse)(struct wlr_renderer *renderer, - const float (*color)[4], const float (*matrix)[16]); + const float color[static 4], const float matrix[static 16]); const enum wl_shm_format *(*formats)( struct wlr_renderer *renderer, size_t *len); bool (*buffer_is_drm)(struct wlr_renderer *renderer, @@ -58,8 +59,8 @@ struct wlr_texture_impl { struct wl_resource *drm_buf); bool (*upload_eglimage)(struct wlr_texture *texture, EGLImageKHR image, uint32_t width, uint32_t height); - void (*get_matrix)(struct wlr_texture *state, - float (*matrix)[16], const float (*projection)[16], int x, int y); + void (*get_matrix)(struct wlr_texture *state, float mat[static 16], + const float projection[static 16], int x, int y); void (*get_buffer_size)(struct wlr_texture *texture, struct wl_resource *resource, int *width, int *height); void (*bind)(struct wlr_texture *texture); diff --git a/include/wlr/types/wlr_matrix.h b/include/wlr/types/wlr_matrix.h index 498b643c..cf5ad20d 100644 --- a/include/wlr/types/wlr_matrix.h +++ b/include/wlr/types/wlr_matrix.h @@ -4,19 +4,20 @@ #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]); +void wlr_matrix_identity(float mat[static 16]); +void wlr_matrix_translate(float mat[static 16], float x, float y, float z); +void wlr_matrix_scale(float mat[static 16], float x, float y, float z); +void wlr_matrix_rotate(float mat[static 16], float radians); +void wlr_matrix_mul(float mat[static 16], const float x[static 16], + const float y[static 16]); enum wl_output_transform; void wlr_matrix_transform(float mat[static 16], - enum wl_output_transform transform); + 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]); + enum wl_output_transform transform); +void wlr_matrix_project_box(float mat[static 16], const struct wlr_box *box, + enum wl_output_transform transform, float rotation, + const float projection[static 16]); #endif diff --git a/include/wlr/types/wlr_surface.h b/include/wlr/types/wlr_surface.h index 203345bd..1d4c1f01 100644 --- a/include/wlr/types/wlr_surface.h +++ b/include/wlr/types/wlr_surface.h @@ -99,6 +99,7 @@ struct wlr_surface { struct wlr_renderer; struct wlr_surface *wlr_surface_create(struct wl_resource *res, struct wlr_renderer *renderer); + /** * Gets a matrix you can pass into wlr_render_with_matrix to display this * surface. `matrix` is the output matrix, `projection` is the wlr_output @@ -108,9 +109,9 @@ struct wlr_surface *wlr_surface_create(struct wl_resource *res, * from 0 to 1 in both dimensions. */ 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]); /** diff --git a/render/gles2/renderer.c b/render/gles2/renderer.c index 5b1395fb..9134a2fd 100644 --- a/render/gles2/renderer.c +++ b/render/gles2/renderer.c @@ -122,8 +122,8 @@ static void wlr_gles2_end(struct wlr_renderer *wlr_renderer) { } static void wlr_gles2_clear(struct wlr_renderer *wlr_renderer, - const float (*color)[4]) { - glClearColor((*color)[0], (*color)[1], (*color)[2], (*color)[3]); + const float color[static 4]) { + glClearColor(color[0], color[1], color[2], color[3]); glClear(GL_COLOR_BUFFER_BIT); } @@ -171,14 +171,15 @@ static void draw_quad() { } static bool wlr_gles2_render_texture(struct wlr_renderer *wlr_renderer, - struct wlr_texture *texture, const float (*matrix)[16], float alpha) { + struct wlr_texture *texture, const float matrix[static 16], + float alpha) { if (!texture || !texture->valid) { wlr_log(L_ERROR, "attempt to render invalid texture"); return false; } wlr_texture_bind(texture); - GL_CALL(glUniformMatrix4fv(0, 1, GL_FALSE, *matrix)); + GL_CALL(glUniformMatrix4fv(0, 1, GL_FALSE, matrix)); GL_CALL(glUniform1f(2, alpha)); draw_quad(); return true; @@ -186,18 +187,18 @@ static bool wlr_gles2_render_texture(struct wlr_renderer *wlr_renderer, static void wlr_gles2_render_quad(struct wlr_renderer *wlr_renderer, - const float (*color)[4], const float (*matrix)[16]) { + const float color[static 4], const float matrix[static 16]) { GL_CALL(glUseProgram(shaders.quad)); - GL_CALL(glUniformMatrix4fv(0, 1, GL_FALSE, *matrix)); - GL_CALL(glUniform4f(1, (*color)[0], (*color)[1], (*color)[2], (*color)[3])); + GL_CALL(glUniformMatrix4fv(0, 1, GL_FALSE, matrix)); + GL_CALL(glUniform4f(1, color[0], color[1], color[2], color[3])); draw_quad(); } static void wlr_gles2_render_ellipse(struct wlr_renderer *wlr_renderer, - const float (*color)[4], const float (*matrix)[16]) { + const float color[static 4], const float matrix[static 16]) { GL_CALL(glUseProgram(shaders.ellipse)); - GL_CALL(glUniformMatrix4fv(0, 1, GL_TRUE, *matrix)); - GL_CALL(glUniform4f(1, (*color)[0], (*color)[1], (*color)[2], (*color)[3])); + GL_CALL(glUniformMatrix4fv(0, 1, GL_TRUE, matrix)); + GL_CALL(glUniform4f(1, color[0], color[1], color[2], color[3])); draw_quad(); } diff --git a/render/gles2/texture.c b/render/gles2/texture.c index 7a180446..0dfebc48 100644 --- a/render/gles2/texture.c +++ b/render/gles2/texture.c @@ -227,16 +227,16 @@ static bool gles2_texture_upload_eglimage(struct wlr_texture *wlr_tex, } static void gles2_texture_get_matrix(struct wlr_texture *_texture, - float (*matrix)[16], const float (*projection)[16], int x, int y) { + float mat[static 16], const float projection[static 16], int x, int y) { struct wlr_gles2_texture *texture = (struct wlr_gles2_texture *)_texture; float world[16]; - wlr_matrix_identity(matrix); - wlr_matrix_translate(&world, x, y, 0); - wlr_matrix_mul(matrix, &world, matrix); - wlr_matrix_scale(&world, + wlr_matrix_identity(mat); + wlr_matrix_translate(world, x, y, 0); + wlr_matrix_mul(mat, mat, world); + wlr_matrix_scale(world, texture->wlr_texture.width, texture->wlr_texture.height, 1); - wlr_matrix_mul(matrix, &world, matrix); - wlr_matrix_mul(projection, matrix, matrix); + wlr_matrix_mul(mat, mat, world); + wlr_matrix_mul(mat, projection, mat); } static void gles2_texture_get_buffer_size(struct wlr_texture *texture, struct diff --git a/render/wlr_renderer.c b/render/wlr_renderer.c index ce8fbe36..372e4caf 100644 --- a/render/wlr_renderer.c +++ b/render/wlr_renderer.c @@ -23,7 +23,7 @@ void wlr_renderer_end(struct wlr_renderer *r) { r->impl->end(r); } -void wlr_renderer_clear(struct wlr_renderer *r, const float (*color)[4]) { +void wlr_renderer_clear(struct wlr_renderer *r, const float color[static 4]) { r->impl->clear(r, color); } @@ -36,17 +36,18 @@ struct wlr_texture *wlr_render_texture_create(struct wlr_renderer *r) { } bool wlr_render_with_matrix(struct wlr_renderer *r, - struct wlr_texture *texture, const float (*matrix)[16], float alpha) { + struct wlr_texture *texture, const float matrix[static 16], + float alpha) { return r->impl->render_with_matrix(r, texture, matrix, alpha); } void wlr_render_colored_quad(struct wlr_renderer *r, - const float (*color)[4], const float (*matrix)[16]) { + const float color[static 4], const float matrix[static 16]) { r->impl->render_quad(r, color, matrix); } void wlr_render_colored_ellipse(struct wlr_renderer *r, - const float (*color)[4], const float (*matrix)[16]) { + const float color[static 4], const float matrix[static 16]) { r->impl->render_ellipse(r, color, matrix); } diff --git a/render/wlr_texture.c b/render/wlr_texture.c index a82a16b2..0bfac32c 100644 --- a/render/wlr_texture.c +++ b/render/wlr_texture.c @@ -54,8 +54,8 @@ bool wlr_texture_upload_eglimage(struct wlr_texture *texture, } void wlr_texture_get_matrix(struct wlr_texture *texture, - float (*matrix)[16], const float (*projection)[16], int x, int y) { - texture->impl->get_matrix(texture, matrix, projection, x, y); + float mat[static 16], const float projection[static 16], int x, int y) { + texture->impl->get_matrix(texture, mat, projection, x, y); } void wlr_texture_get_buffer_size(struct wlr_texture *texture, struct wl_resource diff --git a/rootston/output.c b/rootston/output.c index bdf025ad..47236720 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -290,14 +290,14 @@ static void render_surface(struct wlr_surface *surface, double lx, double ly, float matrix[16]; enum wl_output_transform transform = wlr_output_transform_invert(surface->current->transform); - wlr_matrix_project_box(&matrix, &box, transform, rotation, - &output->wlr_output->transform_matrix); + wlr_matrix_project_box(matrix, &box, transform, rotation, + output->wlr_output->transform_matrix); int nrects; pixman_box32_t *rects = pixman_region32_rectangles(&damage, &nrects); for (int i = 0; i < nrects; ++i) { scissor_output(output, &rects[i]); - wlr_render_with_matrix(renderer, surface->texture, &matrix, data->alpha); + wlr_render_with_matrix(renderer, surface->texture, matrix, data->alpha); } damage_finish: @@ -354,8 +354,8 @@ static void render_decorations(struct roots_view *view, } float matrix[16]; - wlr_matrix_project_box(&matrix, &box, WL_OUTPUT_TRANSFORM_NORMAL, - view->rotation, &output->wlr_output->transform_matrix); + wlr_matrix_project_box(matrix, &box, WL_OUTPUT_TRANSFORM_NORMAL, + view->rotation, output->wlr_output->transform_matrix); float color[] = { 0.2, 0.2, 0.2, view->alpha }; int nrects; @@ -363,7 +363,7 @@ static void render_decorations(struct roots_view *view, pixman_region32_rectangles(&damage, &nrects); for (int i = 0; i < nrects; ++i) { scissor_output(output, &rects[i]); - wlr_render_colored_quad(renderer, &color, &matrix); + wlr_render_colored_quad(renderer, color, matrix); } damage_finish: @@ -489,7 +489,7 @@ static void render_output(struct roots_output *output) { pixman_box32_t *rects = pixman_region32_rectangles(&damage, &nrects); for (int i = 0; i < nrects; ++i) { scissor_output(output, &rects[i]); - wlr_renderer_clear(renderer, &clear_color); + wlr_renderer_clear(renderer, clear_color); } // If a view is fullscreen on this output, render it diff --git a/types/wlr_matrix.c b/types/wlr_matrix.c index f3546e0e..a6be9908 100644 --- a/types/wlr_matrix.c +++ b/types/wlr_matrix.c @@ -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)], - - (*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)], +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(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)); + 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); } diff --git a/types/wlr_output.c b/types/wlr_output.c index 21343a68..a9fb01c5 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -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); diff --git a/types/wlr_surface.c b/types/wlr_surface.c index 5d52fd2a..04dcb141 100644 --- a/types/wlr_surface.c +++ b/types/wlr_surface.c @@ -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) { -- cgit v1.2.3 From 824a95ad19062e867178593f0937d14049422989 Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 15 Mar 2018 15:33:58 +0100 Subject: matrix: use 2D matrices --- backend/drm/drm.c | 4 +- backend/drm/renderer.c | 20 ++-- examples/output-layout.c | 6 +- examples/rotation.c | 4 +- examples/tablet.c | 2 +- examples/touch.c | 4 +- include/backend/drm/drm.h | 2 +- include/wlr/render.h | 20 ++-- include/wlr/render/interface.h | 12 +-- include/wlr/types/wlr_matrix.h | 24 ++--- include/wlr/types/wlr_output.h | 2 +- include/wlr/types/wlr_surface.h | 10 +- render/gles2/renderer.c | 24 +++-- render/gles2/shaders.c | 67 ++++++------ render/gles2/texture.c | 13 +-- render/wlr_renderer.c | 10 +- render/wlr_texture.c | 2 +- rootston/output.c | 6 +- types/wlr_matrix.c | 227 ++++++++++++++++------------------------ types/wlr_output.c | 8 +- types/wlr_surface.c | 16 ++- 21 files changed, 214 insertions(+), 269 deletions(-) (limited to 'backend') diff --git a/backend/drm/drm.c b/backend/drm/drm.c index 1e78d301..e956f280 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -647,9 +647,9 @@ static bool wlr_drm_connector_set_cursor(struct wlr_output *output, glClearColor(0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT); - float matrix[16]; + float matrix[9]; wlr_texture_get_matrix(plane->wlr_tex, matrix, plane->matrix, 0, 0); - wlr_render_with_matrix(plane->surf.renderer->wlr_rend, plane->wlr_tex, + wlr_render_texture_with_matrix(plane->surf.renderer->wlr_rend, plane->wlr_tex, matrix, 1.0f); glFinish(); diff --git a/backend/drm/renderer.c b/backend/drm/renderer.c index ab56e6c2..f700dd59 100644 --- a/backend/drm/renderer.c +++ b/backend/drm/renderer.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -226,20 +227,21 @@ struct gbm_bo *wlr_drm_surface_mgpu_copy(struct wlr_drm_surface *dest, wlr_drm_surface_make_current(dest, NULL); struct wlr_texture *tex = get_tex_for_bo(dest->renderer, src); + assert(tex); - static const float matrix[16] = { + static const float color[] = {0.0, 0.0, 0.0, 1.0}; + + static const float mat[9] = { [0] = 2.0f, - [3] = -1.0f, - [5] = 2.0f, - [7] = -1.0f, - [10] = 1.0f, - [15] = 1.0f, + [2] = -1.0f, + [4] = 2.0f, + [5] = -1.0f, + [8] = 1.0f, }; glViewport(0, 0, dest->width, dest->height); - glClearColor(0.0, 0.0, 0.0, 1.0); - glClear(GL_COLOR_BUFFER_BIT); - wlr_render_with_matrix(dest->renderer->wlr_rend, tex, matrix, 1.0f); + wlr_renderer_clear(dest->renderer->wlr_rend, color); + wlr_render_texture_with_matrix(dest->renderer->wlr_rend, tex, mat, 1.0f); return wlr_drm_surface_swap_buffers(dest, NULL); } diff --git a/examples/output-layout.c b/examples/output-layout.c index f4df73a0..9c914137 100644 --- a/examples/output-layout.c +++ b/examples/output-layout.c @@ -111,7 +111,7 @@ static void handle_output_frame(struct output_state *output, .width = 128, .height = 128, }; if (wlr_output_layout_intersects(sample->layout, output->output, &box)) { - float matrix[16]; + float matrix[9]; // transform global coordinates to local coordinates double local_x = sample->x_offs; @@ -121,8 +121,8 @@ static void handle_output_frame(struct output_state *output, wlr_texture_get_matrix(sample->cat_texture, matrix, wlr_output->transform_matrix, local_x, local_y); - wlr_render_with_matrix(sample->renderer, - sample->cat_texture, matrix, 1.0f); + wlr_render_texture_with_matrix(sample->renderer, sample->cat_texture, + matrix, 1.0f); } wlr_renderer_end(sample->renderer); diff --git a/examples/rotation.c b/examples/rotation.c index 0b0c6adf..4431f60a 100644 --- a/examples/rotation.c +++ b/examples/rotation.c @@ -46,12 +46,12 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts wlr_renderer_begin(sample->renderer, wlr_output); wlr_renderer_clear(sample->renderer, (float[]){0.25f, 0.25f, 0.25f, 1}); - float matrix[16]; + float matrix[9]; for (int y = -128 + (int)odata->y_offs; y < height; y += 128) { for (int x = -128 + (int)odata->x_offs; x < width; x += 128) { wlr_texture_get_matrix(sample->cat_texture, matrix, wlr_output->transform_matrix, x, y); - wlr_render_with_matrix(sample->renderer, + wlr_render_texture_with_matrix(sample->renderer, sample->cat_texture, matrix, 1.0f); } } diff --git a/examples/tablet.c b/examples/tablet.c index 82f86553..521447b9 100644 --- a/examples/tablet.c +++ b/examples/tablet.c @@ -49,7 +49,7 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts wlr_renderer_begin(sample->renderer, wlr_output); wlr_renderer_clear(sample->renderer, (float[]){0.25f, 0.25f, 0.25f, 1}); - float matrix[16]; + float matrix[9]; float distance = 0.8f * (1 - sample->distance); float tool_color[4] = { distance, distance, distance, 1 }; for (size_t i = 0; sample->button && i < 4; ++i) { diff --git a/examples/touch.c b/examples/touch.c index 6f4821ad..47bbebc2 100644 --- a/examples/touch.c +++ b/examples/touch.c @@ -45,14 +45,14 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts wlr_renderer_begin(sample->renderer, wlr_output); wlr_renderer_clear(sample->renderer, (float[]){0.25f, 0.25f, 0.25f, 1}); - float matrix[16]; + float matrix[9]; struct touch_point *p; wl_list_for_each(p, &sample->touch_points, link) { wlr_texture_get_matrix(sample->cat_texture, matrix, wlr_output->transform_matrix, (int)(p->x * width) - sample->cat_texture->width / 2, (int)(p->y * height) - sample->cat_texture->height / 2); - wlr_render_with_matrix(sample->renderer, sample->cat_texture, + wlr_render_texture_with_matrix(sample->renderer, sample->cat_texture, matrix, 1.0f); } diff --git a/include/backend/drm/drm.h b/include/backend/drm/drm.h index ee3fd38e..26189340 100644 --- a/include/backend/drm/drm.h +++ b/include/backend/drm/drm.h @@ -26,7 +26,7 @@ struct wlr_drm_plane { struct wlr_drm_surface mgpu_surf; // Only used by cursor - float matrix[16]; + float matrix[9]; struct wlr_texture *wlr_tex; struct gbm_bo *cursor_bo; bool cursor_enabled; diff --git a/include/wlr/render.h b/include/wlr/render.h index 50c2dd13..d1498b07 100644 --- a/include/wlr/render.h +++ b/include/wlr/render.h @@ -30,26 +30,26 @@ struct wlr_texture *wlr_render_texture_create(struct wlr_renderer *r); * * struct wlr_renderer *renderer; * struct wlr_texture *texture; - * float projection[16]; - * float matrix[16]; - * wlr_texture_get_matrix(texture, &matrix, &projection, 123, 321); - * wlr_render_with_matrix(renderer, texture, &matrix, 0.5f); + * float projection[9]; + * float matrix[9]; + * wlr_texture_get_matrix(texture, matrix, projection, 123, 321); + * wlr_render_texture_with_matrix(renderer, texture, matrix, 0.5f); * * This will render the texture at <123, 321> with an alpha channel of 0.5. */ -bool wlr_render_with_matrix(struct wlr_renderer *r, - struct wlr_texture *texture, const float matrix[static 16], float alpha); +bool wlr_render_texture_with_matrix(struct wlr_renderer *r, + struct wlr_texture *texture, const float matrix[static 9], float alpha); /** * Renders a solid quad in the specified color. */ void wlr_render_colored_quad(struct wlr_renderer *r, - const float color[static 4], const float matrix[static 16]); + const float color[static 4], const float matrix[static 9]); /** * Renders a solid ellipse in the specified color. */ void wlr_render_colored_ellipse(struct wlr_renderer *r, - const float color[static 4], const float matrix[static 16]); + const float color[static 4], const float matrix[static 9]); /** * Returns a list of pixel formats supported by this renderer. */ @@ -139,8 +139,8 @@ bool wlr_texture_update_shm(struct wlr_texture *surf, uint32_t format, * width) and [0, height], and the x and y coordinates provided are used as * such. */ -void wlr_texture_get_matrix(struct wlr_texture *texture, float mat[static 16], - const float projection[static 16], int x, int y); +void wlr_texture_get_matrix(struct wlr_texture *texture, float mat[static 9], + const float projection[static 9], int x, int y); /** * Destroys this wlr_texture. */ diff --git a/include/wlr/render/interface.h b/include/wlr/render/interface.h index 4d81bdf9..03b8309f 100644 --- a/include/wlr/render/interface.h +++ b/include/wlr/render/interface.h @@ -21,13 +21,13 @@ struct wlr_renderer_impl { void (*clear)(struct wlr_renderer *renderer, const float color[static 4]); void (*scissor)(struct wlr_renderer *renderer, struct wlr_box *box); struct wlr_texture *(*texture_create)(struct wlr_renderer *renderer); - bool (*render_with_matrix)(struct wlr_renderer *renderer, - struct wlr_texture *texture, const float matrix[static 16], + bool (*render_texture_with_matrix)(struct wlr_renderer *renderer, + struct wlr_texture *texture, const float matrix[static 9], float alpha); void (*render_quad)(struct wlr_renderer *renderer, - const float color[static 4], const float matrix[static 16]); + const float color[static 4], const float matrix[static 9]); void (*render_ellipse)(struct wlr_renderer *renderer, - const float color[static 4], const float matrix[static 16]); + const float color[static 4], const float matrix[static 9]); const enum wl_shm_format *(*formats)( struct wlr_renderer *renderer, size_t *len); bool (*buffer_is_drm)(struct wlr_renderer *renderer, @@ -59,8 +59,8 @@ struct wlr_texture_impl { struct wl_resource *drm_buf); bool (*upload_eglimage)(struct wlr_texture *texture, EGLImageKHR image, uint32_t width, uint32_t height); - void (*get_matrix)(struct wlr_texture *state, float mat[static 16], - const float projection[static 16], int x, int y); + void (*get_matrix)(struct wlr_texture *state, float mat[static 9], + const float projection[static 9], int x, int y); void (*get_buffer_size)(struct wlr_texture *texture, struct wl_resource *resource, int *width, int *height); void (*bind)(struct wlr_texture *texture); diff --git a/include/wlr/types/wlr_matrix.h b/include/wlr/types/wlr_matrix.h index cf5ad20d..5255980a 100644 --- a/include/wlr/types/wlr_matrix.h +++ b/include/wlr/types/wlr_matrix.h @@ -2,22 +2,22 @@ #define WLR_TYPES_WLR_MATRIX_H #include +#include #include -void wlr_matrix_identity(float mat[static 16]); -void wlr_matrix_translate(float mat[static 16], float x, float y, float z); -void wlr_matrix_scale(float mat[static 16], float x, float y, float z); -void wlr_matrix_rotate(float mat[static 16], float radians); -void wlr_matrix_mul(float mat[static 16], const float x[static 16], - const float y[static 16]); - -enum wl_output_transform; -void wlr_matrix_transform(float mat[static 16], +void wlr_matrix_identity(float mat[static 9]); +void wlr_matrix_translate(float mat[static 9], float x, float y); +void wlr_matrix_scale(float mat[static 9], float x, float y); +void wlr_matrix_rotate(float mat[static 9], float rad); +void wlr_matrix_multiply(float mat[static 9], const float a[static 9], + const float b[static 9]); +void wlr_matrix_transform(float mat[static 9], enum wl_output_transform transform); -void wlr_matrix_texture(float mat[static 16], int32_t width, int32_t height, + +void wlr_matrix_texture(float mat[static 9], int32_t width, int32_t height, enum wl_output_transform transform); -void wlr_matrix_project_box(float mat[static 16], const struct wlr_box *box, +void wlr_matrix_project_box(float mat[static 9], const struct wlr_box *box, enum wl_output_transform transform, float rotation, - const float projection[static 16]); + const float projection[static 9]); #endif diff --git a/include/wlr/types/wlr_output.h b/include/wlr/types/wlr_output.h index a8138a80..b838a737 100644 --- a/include/wlr/types/wlr_output.h +++ b/include/wlr/types/wlr_output.h @@ -76,7 +76,7 @@ struct wlr_output { // damage for cursors and fullscreen surface, in output-local coordinates pixman_region32_t damage; bool frame_pending; - float transform_matrix[16]; + float transform_matrix[9]; struct { struct wl_signal frame; diff --git a/include/wlr/types/wlr_surface.h b/include/wlr/types/wlr_surface.h index 1d4c1f01..2bfd1bc9 100644 --- a/include/wlr/types/wlr_surface.h +++ b/include/wlr/types/wlr_surface.h @@ -70,8 +70,8 @@ struct wlr_surface { struct wlr_surface_state *current, *pending; const char *role; // the lifetime-bound role or null - float buffer_to_surface_matrix[16]; - float surface_to_buffer_matrix[16]; + float buffer_to_surface_matrix[9]; + float surface_to_buffer_matrix[9]; struct { struct wl_signal commit; @@ -109,9 +109,9 @@ struct wlr_surface *wlr_surface_create(struct wl_resource *res, * from 0 to 1 in both dimensions. */ void wlr_surface_get_matrix(struct wlr_surface *surface, - float mat[static 16], - const float projection[static 16], - const float transform[static 16]); + float mat[static 9], + const float projection[static 9], + const float transform[static 9]); /** diff --git a/render/gles2/renderer.c b/render/gles2/renderer.c index 9134a2fd..e0a98d29 100644 --- a/render/gles2/renderer.c +++ b/render/gles2/renderer.c @@ -85,11 +85,13 @@ static void init_default_shaders() { if (!compile_program(quad_vertex_src, quad_fragment_src, &shaders.quad)) { goto error; } - if (!compile_program(quad_vertex_src, ellipse_fragment_src, &shaders.ellipse)) { + if (!compile_program(quad_vertex_src, ellipse_fragment_src, + &shaders.ellipse)) { goto error; } if (glEGLImageTargetTexture2DOES) { - if (!compile_program(quad_vertex_src, fragment_src_external, &shaders.external)) { + if (!compile_program(quad_vertex_src, fragment_src_external, + &shaders.external)) { goto error; } } @@ -170,16 +172,16 @@ static void draw_quad() { GL_CALL(glDisableVertexAttribArray(1)); } -static bool wlr_gles2_render_texture(struct wlr_renderer *wlr_renderer, - struct wlr_texture *texture, const float matrix[static 16], - float alpha) { +static bool wlr_gles2_render_texture_with_matrix( + struct wlr_renderer *wlr_renderer, struct wlr_texture *texture, + const float matrix[static 9], float alpha) { if (!texture || !texture->valid) { wlr_log(L_ERROR, "attempt to render invalid texture"); return false; } wlr_texture_bind(texture); - GL_CALL(glUniformMatrix4fv(0, 1, GL_FALSE, matrix)); + GL_CALL(glUniformMatrix3fv(0, 1, GL_FALSE, matrix)); GL_CALL(glUniform1f(2, alpha)); draw_quad(); return true; @@ -187,17 +189,17 @@ static bool wlr_gles2_render_texture(struct wlr_renderer *wlr_renderer, static void wlr_gles2_render_quad(struct wlr_renderer *wlr_renderer, - const float color[static 4], const float matrix[static 16]) { + const float color[static 4], const float matrix[static 9]) { GL_CALL(glUseProgram(shaders.quad)); - GL_CALL(glUniformMatrix4fv(0, 1, GL_FALSE, matrix)); + GL_CALL(glUniformMatrix3fv(0, 1, GL_FALSE, matrix)); GL_CALL(glUniform4f(1, color[0], color[1], color[2], color[3])); draw_quad(); } static void wlr_gles2_render_ellipse(struct wlr_renderer *wlr_renderer, - const float color[static 4], const float matrix[static 16]) { + const float color[static 4], const float matrix[static 9]) { GL_CALL(glUseProgram(shaders.ellipse)); - GL_CALL(glUniformMatrix4fv(0, 1, GL_TRUE, matrix)); + GL_CALL(glUniformMatrix3fv(0, 1, GL_TRUE, matrix)); GL_CALL(glUniform4f(1, color[0], color[1], color[2], color[3])); draw_quad(); } @@ -258,7 +260,7 @@ static struct wlr_renderer_impl wlr_renderer_impl = { .clear = wlr_gles2_clear, .scissor = wlr_gles2_scissor, .texture_create = wlr_gles2_texture_create, - .render_with_matrix = wlr_gles2_render_texture, + .render_texture_with_matrix = wlr_gles2_render_texture_with_matrix, .render_quad = wlr_gles2_render_quad, .render_ellipse = wlr_gles2_render_ellipse, .formats = wlr_gles2_formats, diff --git a/render/gles2/shaders.c b/render/gles2/shaders.c index 46a10248..9d3a67c2 100644 --- a/render/gles2/shaders.c +++ b/render/gles2/shaders.c @@ -3,29 +3,29 @@ // Colored quads const GLchar quad_vertex_src[] = -"uniform mat4 proj;" +"uniform mat3 proj;" "uniform vec4 color;" "attribute vec2 pos;" "attribute vec2 texcoord;" "varying vec4 v_color;" "varying vec2 v_texcoord;" -"mat4 transpose(in mat4 inMatrix) {" -" vec4 i0 = inMatrix[0];" -" vec4 i1 = inMatrix[1];" -" vec4 i2 = inMatrix[2];" -" vec4 i3 = inMatrix[3];" -" mat4 outMatrix = mat4(" -" vec4(i0.x, i1.x, i2.x, i3.x)," -" vec4(i0.y, i1.y, i2.y, i3.y)," -" vec4(i0.z, i1.z, i2.z, i3.z)," -" vec4(i0.w, i1.w, i2.w, i3.w)" -" );" -" return outMatrix;" +"" +"mat3 transpose(in mat3 inMatrix) {" +" vec3 i0 = inMatrix[0];" +" vec3 i1 = inMatrix[1];" +" vec3 i2 = inMatrix[2];" +" mat3 outMatrix = mat3(" +" vec3(i0.x, i1.x, i2.x)," +" vec3(i0.y, i1.y, i2.y)," +" vec3(i0.z, i1.z, i2.z)" +" );" +" return outMatrix;" "}" +"" "void main() {" -" gl_Position = transpose(proj) * vec4(pos, 0.0, 1.0);" -" v_color = color;" -" v_texcoord = texcoord;" +" gl_Position = vec4(transpose(proj) * vec3(pos, 1.0), 1.0);" +" v_color = color;" +" v_texcoord = texcoord;" "}"; const GLchar quad_fragment_src[] = @@ -49,26 +49,25 @@ const GLchar ellipse_fragment_src[] = // Textured quads const GLchar vertex_src[] = -"uniform mat4 proj;" +"uniform mat3 proj;" "attribute vec2 pos;" "attribute vec2 texcoord;" "varying vec2 v_texcoord;" -"mat4 transpose(in mat4 inMatrix) {" -" vec4 i0 = inMatrix[0];" -" vec4 i1 = inMatrix[1];" -" vec4 i2 = inMatrix[2];" -" vec4 i3 = inMatrix[3];" -" mat4 outMatrix = mat4(" -" vec4(i0.x, i1.x, i2.x, i3.x)," -" vec4(i0.y, i1.y, i2.y, i3.y)," -" vec4(i0.z, i1.z, i2.z, i3.z)," -" vec4(i0.w, i1.w, i2.w, i3.w)" -" );" "" -" return outMatrix;" +"mat3 transpose(in mat3 inMatrix) {" +" vec3 i0 = inMatrix[0];" +" vec3 i1 = inMatrix[1];" +" vec3 i2 = inMatrix[2];" +" mat3 outMatrix = mat3(" +" vec3(i0.x, i1.x, i2.x)," +" vec3(i0.y, i1.y, i2.y)," +" vec3(i0.z, i1.z, i2.z)" +" );" +" return outMatrix;" "}" +"" "void main() {" -" gl_Position = transpose(proj) * vec4(pos, 0.0, 1.0);" +" gl_Position = vec4(transpose(proj) * vec3(pos, 1.0), 1.0);" " v_texcoord = texcoord;" "}"; @@ -87,8 +86,8 @@ const GLchar fragment_src_rgbx[] = "uniform sampler2D tex;" "uniform float alpha;" "void main() {" -" gl_FragColor.rgb = alpha * texture2D(tex, v_texcoord).rgb;" -" gl_FragColor.a = alpha;" +" gl_FragColor.rgb = alpha * texture2D(tex, v_texcoord).rgb;" +" gl_FragColor.a = alpha;" "}"; const GLchar fragment_src_external[] = @@ -97,6 +96,6 @@ const GLchar fragment_src_external[] = "varying vec2 v_texcoord;" "uniform samplerExternalOES texture0;" "void main() {" -" vec4 col = texture2D(texture0, v_texcoord);" -" gl_FragColor = vec4(col.rgb, col.a);" +" vec4 col = texture2D(texture0, v_texcoord);" +" gl_FragColor = vec4(col.rgb, col.a);" "}"; diff --git a/render/gles2/texture.c b/render/gles2/texture.c index 0dfebc48..9ee2a3e3 100644 --- a/render/gles2/texture.c +++ b/render/gles2/texture.c @@ -227,16 +227,13 @@ static bool gles2_texture_upload_eglimage(struct wlr_texture *wlr_tex, } static void gles2_texture_get_matrix(struct wlr_texture *_texture, - float mat[static 16], const float projection[static 16], int x, int y) { + float mat[static 9], const float projection[static 9], int x, int y) { struct wlr_gles2_texture *texture = (struct wlr_gles2_texture *)_texture; - float world[16]; wlr_matrix_identity(mat); - wlr_matrix_translate(world, x, y, 0); - wlr_matrix_mul(mat, mat, world); - wlr_matrix_scale(world, - texture->wlr_texture.width, texture->wlr_texture.height, 1); - wlr_matrix_mul(mat, mat, world); - wlr_matrix_mul(mat, projection, mat); + wlr_matrix_translate(mat, x, y); + wlr_matrix_scale(mat, texture->wlr_texture.width, + texture->wlr_texture.height); + wlr_matrix_multiply(mat, projection, mat); } static void gles2_texture_get_buffer_size(struct wlr_texture *texture, struct diff --git a/render/wlr_renderer.c b/render/wlr_renderer.c index 372e4caf..e847fcc2 100644 --- a/render/wlr_renderer.c +++ b/render/wlr_renderer.c @@ -35,19 +35,19 @@ struct wlr_texture *wlr_render_texture_create(struct wlr_renderer *r) { return r->impl->texture_create(r); } -bool wlr_render_with_matrix(struct wlr_renderer *r, - struct wlr_texture *texture, const float matrix[static 16], +bool wlr_render_texture_with_matrix(struct wlr_renderer *r, + struct wlr_texture *texture, const float matrix[static 9], float alpha) { - return r->impl->render_with_matrix(r, texture, matrix, alpha); + return r->impl->render_texture_with_matrix(r, texture, matrix, alpha); } void wlr_render_colored_quad(struct wlr_renderer *r, - const float color[static 4], const float matrix[static 16]) { + const float color[static 4], const float matrix[static 9]) { r->impl->render_quad(r, color, matrix); } void wlr_render_colored_ellipse(struct wlr_renderer *r, - const float color[static 4], const float matrix[static 16]) { + const float color[static 4], const float matrix[static 9]) { r->impl->render_ellipse(r, color, matrix); } diff --git a/render/wlr_texture.c b/render/wlr_texture.c index 0bfac32c..1ec9beb9 100644 --- a/render/wlr_texture.c +++ b/render/wlr_texture.c @@ -54,7 +54,7 @@ bool wlr_texture_upload_eglimage(struct wlr_texture *texture, } void wlr_texture_get_matrix(struct wlr_texture *texture, - float mat[static 16], const float projection[static 16], int x, int y) { + float mat[static 9], const float projection[static 9], int x, int y) { texture->impl->get_matrix(texture, mat, projection, x, y); } diff --git a/rootston/output.c b/rootston/output.c index 47236720..29fb1202 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -287,7 +287,7 @@ static void render_surface(struct wlr_surface *surface, double lx, double ly, goto damage_finish; } - float matrix[16]; + float matrix[9]; enum wl_output_transform transform = wlr_output_transform_invert(surface->current->transform); wlr_matrix_project_box(matrix, &box, transform, rotation, @@ -297,7 +297,7 @@ static void render_surface(struct wlr_surface *surface, double lx, double ly, pixman_box32_t *rects = pixman_region32_rectangles(&damage, &nrects); for (int i = 0; i < nrects; ++i) { scissor_output(output, &rects[i]); - wlr_render_with_matrix(renderer, surface->texture, matrix, data->alpha); + wlr_render_texture_with_matrix(renderer, surface->texture, matrix, data->alpha); } damage_finish: @@ -353,7 +353,7 @@ static void render_decorations(struct roots_view *view, goto damage_finish; } - float matrix[16]; + float matrix[9]; wlr_matrix_project_box(matrix, &box, WL_OUTPUT_TRANSFORM_NORMAL, view->rotation, output->wlr_output->transform_matrix); float color[] = { 0.2, 0.2, 0.2, view->alpha }; diff --git a/types/wlr_matrix.c b/types/wlr_matrix.c index a6be9908..85a294d9 100644 --- a/types/wlr_matrix.c +++ b/types/wlr_matrix.c @@ -5,143 +5,113 @@ #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 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, +void wlr_matrix_identity(float mat[static 9]) { + static const float identity[9] = { + 1.0f, 0.0f, 0.0f, + 0.0f, 1.0f, 0.0f, + 0.0f, 0.0f, 1.0f, }; memcpy(mat, identity, sizeof(identity)); } -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_multiply(float mat[static 9], const float a[static 9], + const float b[static 9]) { + float product[9]; + + product[0] = a[0]*b[0] + a[1]*b[3] + a[2]*b[6]; + product[1] = a[0]*b[1] + a[1]*b[4] + a[2]*b[7]; + product[2] = a[0]*b[2] + a[1]*b[5] + a[2]*b[8]; + + product[3] = a[3]*b[0] + a[4]*b[3] + a[5]*b[6]; + product[4] = a[3]*b[1] + a[4]*b[4] + a[5]*b[7]; + product[5] = a[3]*b[2] + a[4]*b[5] + a[5]*b[8]; + + product[6] = a[6]*b[0] + a[7]*b[3] + a[8]*b[6]; + product[7] = a[6]*b[1] + a[7]*b[4] + a[8]*b[7]; + product[8] = a[6]*b[2] + a[7]*b[5] + a[8]*b[8]; + + memcpy(mat, product, sizeof(product)); } -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_translate(float mat[static 9], float x, float y) { + float translate[9] = { + 1.0f, 0.0f, x, + 0.0f, 1.0f, y, + 0.0f, 0.0f, 1.0f, + }; + wlr_matrix_multiply(mat, mat, translate); } -void wlr_matrix_rotate(float mat[static 16], float radians) { - wlr_matrix_identity(mat); - float _cos = cosf(radians); - float _sin = sinf(radians); - mat[mind(1, 1)] = _cos; - mat[mind(1, 2)] = _sin; - mat[mind(2, 1)] = -_sin; - mat[mind(2, 2)] = _cos; +void wlr_matrix_scale(float mat[static 9], float x, float y) { + float scale[9] = { + x, 0.0f, 0.0f, + 0.0f, y, 0.0f, + 0.0f, 0.0f, 1.0f, + }; + wlr_matrix_multiply(mat, mat, scale); } -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(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)], +void wlr_matrix_rotate(float mat[static 9], float rad) { + float rotate[9] = { + cos(rad), -sin(rad), 0.0f, + sin(rad), cos(rad), 0.0f, + 0.0f, 0.0f, 1.0f, }; - memcpy(mat, product, sizeof(product)); + wlr_matrix_multiply(mat, mat, rotate); } -static const float transforms[][4] = { +static const float transforms[][9] = { [WL_OUTPUT_TRANSFORM_NORMAL] = { - 1.0f, 0.0f, - 0.0f, 1.0f, + 1.0f, 0.0f, 0.0f, + 0.0f, 1.0f, 0.0f, + 0.0f, 0.0f, 1.0f, }, [WL_OUTPUT_TRANSFORM_90] = { - 0.0f, -1.0f, - 1.0f, 0.0f, + 0.0f, -1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 1.0f, }, [WL_OUTPUT_TRANSFORM_180] = { - -1.0f, 0.0f, - 0.0f, -1.0f, + -1.0f, 0.0f, 0.0f, + 0.0f, -1.0f, 0.0f, + 0.0f, 0.0f, 1.0f, }, [WL_OUTPUT_TRANSFORM_270] = { - 0.0f, 1.0f, - -1.0f, 0.0f, + 0.0f, 1.0f, 0.0f, + -1.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 1.0f, }, [WL_OUTPUT_TRANSFORM_FLIPPED] = { - -1.0f, 0.0f, - 0.0f, 1.0f, + -1.0f, 0.0f, 0.0f, + 0.0f, 1.0f, 0.0f, + 0.0f, 0.0f, 1.0f, }, [WL_OUTPUT_TRANSFORM_FLIPPED_90] = { - 0.0f, -1.0f, - -1.0f, 0.0f, + 0.0f, -1.0f, 0.0f, + -1.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 1.0f, }, [WL_OUTPUT_TRANSFORM_FLIPPED_180] = { - 1.0f, 0.0f, - 0.0f, -1.0f, + 1.0f, 0.0f, 0.0f, + 0.0f, -1.0f, 0.0f, + 0.0f, 0.0f, 1.0f, }, [WL_OUTPUT_TRANSFORM_FLIPPED_270] = { - 0.0f, 1.0f, - 1.0f, 0.0f, + 0.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 1.0f, }, }; -void wlr_matrix_transform(float mat[static 16], +void wlr_matrix_transform(float mat[static 9], 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; + wlr_matrix_multiply(mat, mat, transforms[transform]); } // 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, +void wlr_matrix_texture(float mat[static 9], int32_t width, int32_t height, enum wl_output_transform transform) { - memset(mat, 0, sizeof(*mat) * 16); + memset(mat, 0, sizeof(*mat) * 9); const float *t = transforms[transform]; float x = 2.0f / width; @@ -150,62 +120,41 @@ void wlr_matrix_texture(float mat[static 16], int32_t width, int32_t height, // Rotation + reflection mat[0] = x * t[0]; mat[1] = x * t[1]; - mat[4] = y * -t[2]; - mat[5] = y * -t[3]; + mat[3] = y * -t[3]; + mat[4] = y * -t[4]; // Translation - mat[3] = -copysign(1.0f, mat[0] + mat[1]); - mat[7] = -copysign(1.0f, mat[4] + mat[5]); + mat[2] = -copysign(1.0f, mat[0] + mat[1]); + mat[5] = -copysign(1.0f, mat[3] + mat[4]); // Identity - mat[10] = 1.0f; - mat[15] = 1.0f; + mat[8] = 1.0f; } -void wlr_matrix_project_box(float mat[static 16], const struct wlr_box *box, +void wlr_matrix_project_box(float mat[static 9], const struct wlr_box *box, enum wl_output_transform transform, float rotation, - const float projection[static 16]) { + const float projection[static 9]) { int x = box->x; int y = box->y; int width = box->width; int height = box->height; - wlr_matrix_translate(mat, x, y, 0); + wlr_matrix_identity(mat); + wlr_matrix_translate(mat, x, y); 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, mat, translate_center); - wlr_matrix_mul(mat, mat, rotate); - wlr_matrix_mul(mat, mat, translate_origin); + wlr_matrix_translate(mat, width/2, height/2); + wlr_matrix_rotate(mat, rotation); + wlr_matrix_translate(mat, -width/2, -height/2); } - float scale[16]; - wlr_matrix_scale(scale, width, height, 1); - - wlr_matrix_mul(mat, mat, scale); + wlr_matrix_scale(mat, width, height); 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, mat, surface_translate_center); - wlr_matrix_mul(mat, mat, surface_transform); - wlr_matrix_mul(mat, mat, surface_translate_origin); + wlr_matrix_translate(mat, 0.5, 0.5); + wlr_matrix_transform(mat, transform); + wlr_matrix_translate(mat, -0.5, -0.5); } - wlr_matrix_mul(mat, projection, mat); + wlr_matrix_multiply(mat, projection, mat); } diff --git a/types/wlr_output.c b/types/wlr_output.c index a9fb01c5..9a0edd44 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -375,7 +375,7 @@ static void output_fullscreen_surface_render(struct wlr_output *output, struct wlr_box box; output_fullscreen_surface_get_box(output, surface, &box); - float matrix[16]; + float matrix[9]; enum wl_output_transform transform = wlr_output_transform_invert(surface->current->transform); wlr_matrix_project_box(matrix, &box, transform, 0, @@ -386,7 +386,7 @@ static void output_fullscreen_surface_render(struct wlr_output *output, 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_render_texture_with_matrix(surface->renderer, surface->texture, matrix, 1.0f); } wlr_renderer_scissor(renderer, NULL); @@ -435,7 +435,7 @@ static void output_cursor_render(struct wlr_output_cursor *cursor, goto surface_damage_finish; } - float matrix[16]; + float matrix[9]; wlr_matrix_project_box(matrix, &box, WL_OUTPUT_TRANSFORM_NORMAL, 0, cursor->output->transform_matrix); @@ -443,7 +443,7 @@ static void output_cursor_render(struct wlr_output_cursor *cursor, 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_texture_with_matrix(renderer, texture, matrix, 1.0f); } wlr_renderer_scissor(renderer, NULL); diff --git a/types/wlr_surface.c b/types/wlr_surface.c index 04dcb141..ecab4842 100644 --- a/types/wlr_surface.c +++ b/types/wlr_surface.c @@ -624,20 +624,16 @@ struct wlr_surface *wlr_surface_create(struct wl_resource *res, return surface; } -void wlr_surface_get_matrix(struct wlr_surface *surface, - float mat[static 16], - const float projection[static 16], - const float transform[static 16]) { +void wlr_surface_get_matrix(struct wlr_surface *surface, float mat[static 9], + const float projection[static 9], const float transform[static 9]) { int width = surface->texture->width; int height = surface->texture->height; - float scale[16]; wlr_matrix_identity(mat); - if (transform) { - wlr_matrix_mul(mat, mat, transform); + if (transform != NULL) { + wlr_matrix_multiply(mat, mat, transform); } - wlr_matrix_scale(scale, width, height, 1); - wlr_matrix_mul(mat, mat, scale); - wlr_matrix_mul(mat, projection, mat); + wlr_matrix_scale(mat, width, height); + wlr_matrix_multiply(mat, projection, mat); } bool wlr_surface_has_buffer(struct wlr_surface *surface) { -- cgit v1.2.3 From 876f07e9f13946609047e8e32ca7918548315e1c Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 15 Mar 2018 19:31:02 +0100 Subject: renderer: replace wlr_texture_get_matrix by wlr_render_texture --- backend/drm/drm.c | 6 ++---- examples/output-layout.c | 8 ++------ examples/rotation.c | 7 ++----- examples/touch.c | 11 ++++------- include/wlr/render.h | 41 ++++++++++++----------------------------- include/wlr/render/interface.h | 2 -- render/gles2/texture.c | 14 -------------- render/wlr_renderer.c | 12 ++++++++++++ render/wlr_texture.c | 5 ----- 9 files changed, 34 insertions(+), 72 deletions(-) (limited to 'backend') diff --git a/backend/drm/drm.c b/backend/drm/drm.c index e956f280..0447d865 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -647,10 +647,8 @@ static bool wlr_drm_connector_set_cursor(struct wlr_output *output, glClearColor(0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT); - float matrix[9]; - wlr_texture_get_matrix(plane->wlr_tex, matrix, plane->matrix, 0, 0); - wlr_render_texture_with_matrix(plane->surf.renderer->wlr_rend, plane->wlr_tex, - matrix, 1.0f); + wlr_render_texture(plane->surf.renderer->wlr_rend, plane->wlr_tex, + plane->matrix, 0, 0, 1.0f); glFinish(); glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, bo_stride); diff --git a/examples/output-layout.c b/examples/output-layout.c index 9c914137..8f506208 100644 --- a/examples/output-layout.c +++ b/examples/output-layout.c @@ -111,18 +111,14 @@ static void handle_output_frame(struct output_state *output, .width = 128, .height = 128, }; if (wlr_output_layout_intersects(sample->layout, output->output, &box)) { - float matrix[9]; - // transform global coordinates to local coordinates double local_x = sample->x_offs; double local_y = sample->y_offs; wlr_output_layout_output_coords(sample->layout, output->output, &local_x, &local_y); - wlr_texture_get_matrix(sample->cat_texture, matrix, - wlr_output->transform_matrix, local_x, local_y); - wlr_render_texture_with_matrix(sample->renderer, sample->cat_texture, - matrix, 1.0f); + wlr_render_texture(sample->renderer, sample->cat_texture, + wlr_output->transform_matrix, local_x, local_y, 1.0f); } wlr_renderer_end(sample->renderer); diff --git a/examples/rotation.c b/examples/rotation.c index 4431f60a..aaf006cf 100644 --- a/examples/rotation.c +++ b/examples/rotation.c @@ -46,13 +46,10 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts wlr_renderer_begin(sample->renderer, wlr_output); wlr_renderer_clear(sample->renderer, (float[]){0.25f, 0.25f, 0.25f, 1}); - float matrix[9]; for (int y = -128 + (int)odata->y_offs; y < height; y += 128) { for (int x = -128 + (int)odata->x_offs; x < width; x += 128) { - wlr_texture_get_matrix(sample->cat_texture, matrix, - wlr_output->transform_matrix, x, y); - wlr_render_texture_with_matrix(sample->renderer, - sample->cat_texture, matrix, 1.0f); + wlr_render_texture(sample->renderer, sample->cat_texture, + wlr_output->transform_matrix, x, y, 1.0f); } } diff --git a/examples/touch.c b/examples/touch.c index 47bbebc2..0af8bc4a 100644 --- a/examples/touch.c +++ b/examples/touch.c @@ -45,15 +45,12 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts wlr_renderer_begin(sample->renderer, wlr_output); wlr_renderer_clear(sample->renderer, (float[]){0.25f, 0.25f, 0.25f, 1}); - float matrix[9]; struct touch_point *p; wl_list_for_each(p, &sample->touch_points, link) { - wlr_texture_get_matrix(sample->cat_texture, matrix, - wlr_output->transform_matrix, - (int)(p->x * width) - sample->cat_texture->width / 2, - (int)(p->y * height) - sample->cat_texture->height / 2); - wlr_render_texture_with_matrix(sample->renderer, sample->cat_texture, - matrix, 1.0f); + int x = (int)(p->x * width) - sample->cat_texture->width / 2; + int y = (int)(p->y * height) - sample->cat_texture->height / 2; + wlr_render_texture(sample->renderer, sample->cat_texture, + wlr_output->transform_matrix, x, y, 1.0f); } wlr_renderer_end(sample->renderer); diff --git a/include/wlr/render.h b/include/wlr/render.h index c3bf5c97..01d05fb1 100644 --- a/include/wlr/render.h +++ b/include/wlr/render.h @@ -25,21 +25,15 @@ void wlr_renderer_scissor(struct wlr_renderer *r, struct wlr_box *box); */ struct wlr_texture *wlr_render_texture_create(struct wlr_renderer *r); /** - * Renders the requested texture using the provided matrix. A typical texture - * rendering goes like so: - * - * struct wlr_renderer *renderer; - * struct wlr_texture *texture; - * float projection[9]; - * float matrix[9]; - * wlr_texture_get_matrix(texture, matrix, projection, 123, 321); - * wlr_render_texture_with_matrix(renderer, texture, matrix, 0.5f); - * - * This will render the texture at <123, 321> with an alpha channel of 0.5. + * Renders the requested texture. + */ +bool wlr_render_texture(struct wlr_renderer *r, struct wlr_texture *texture, + const float projection[static 9], int x, int y, float alpha); +/** + * Renders the requested texture using the provided matrix. */ bool wlr_render_texture_with_matrix(struct wlr_renderer *r, struct wlr_texture *texture, const float matrix[static 9], float alpha); - /** * Renders a solid quad in the specified color. */ @@ -95,22 +89,22 @@ struct wlr_texture { * returns. */ bool wlr_texture_upload_pixels(struct wlr_texture *tex, - enum wl_shm_format format, int stride, int width, int height, - const unsigned char *pixels); + enum wl_shm_format format, int stride, int width, int height, + const unsigned char *pixels); /** * Copies pixels to this texture. The buffer is not accessed after this function * returns. Under some circumstances, this function may re-upload the entire * buffer - therefore, the entire buffer must be valid. */ bool wlr_texture_update_pixels(struct wlr_texture *surf, - enum wl_shm_format format, int stride, int x, int y, - int width, int height, const unsigned char *pixels); + enum wl_shm_format format, int stride, int x, int y, + int width, int height, const unsigned char *pixels); /** * Copies pixels from a wl_shm_buffer into this texture. The buffer is not * accessed after this function returns. */ bool wlr_texture_upload_shm(struct wlr_texture *tex, uint32_t format, - struct wl_shm_buffer *shm); + struct wl_shm_buffer *shm); /** * Attaches the contents from the given wl_drm wl_buffer resource onto the @@ -132,18 +126,7 @@ bool wlr_texture_upload_dmabuf(struct wlr_texture *tex, * must be valid. */ bool wlr_texture_update_shm(struct wlr_texture *surf, uint32_t format, - int x, int y, int width, int height, struct wl_shm_buffer *shm); -/** - * Prepares a matrix with the appropriate scale for the given texture and - * multiplies it with the projection, producing a matrix that the shader can - * muptlipy vertex coordinates with to get final screen coordinates. - * - * The projection matrix is assumed to be an orthographic projection of [0, - * width) and [0, height], and the x and y coordinates provided are used as - * such. - */ -void wlr_texture_get_matrix(struct wlr_texture *texture, float mat[static 9], - const float projection[static 9], int x, int y); + int x, int y, int width, int height, struct wl_shm_buffer *shm); /** * Destroys this wlr_texture. */ diff --git a/include/wlr/render/interface.h b/include/wlr/render/interface.h index c8b4c8eb..1b8b7946 100644 --- a/include/wlr/render/interface.h +++ b/include/wlr/render/interface.h @@ -62,8 +62,6 @@ struct wlr_texture_impl { uint32_t width, uint32_t height); bool (*upload_dmabuf)(struct wlr_texture *texture, struct wl_resource *dmabuf_resource); - void (*get_matrix)(struct wlr_texture *state, float mat[static 9], - const float projection[static 9], int x, int y); void (*get_buffer_size)(struct wlr_texture *texture, struct wl_resource *resource, int *width, int *height); void (*bind)(struct wlr_texture *texture); diff --git a/render/gles2/texture.c b/render/gles2/texture.c index 875affe2..ea05cde2 100644 --- a/render/gles2/texture.c +++ b/render/gles2/texture.c @@ -227,7 +227,6 @@ static bool gles2_texture_upload_eglimage(struct wlr_texture *wlr_tex, return true; } - static bool gles2_texture_upload_dmabuf(struct wlr_texture *_tex, struct wl_resource *dmabuf_resource) { struct wlr_gles2_texture *tex = (struct wlr_gles2_texture *)_tex; @@ -263,17 +262,6 @@ static bool gles2_texture_upload_dmabuf(struct wlr_texture *_tex, return true; } -static void gles2_texture_get_matrix(struct wlr_texture *_texture, - float mat[static 9], const float projection[static 9], int x, int y) { - struct wlr_gles2_texture *texture = (struct wlr_gles2_texture *)_texture; - wlr_matrix_identity(mat); - wlr_matrix_translate(mat, x, y); - wlr_matrix_scale(mat, texture->wlr_texture.width, - texture->wlr_texture.height); - wlr_matrix_multiply(mat, projection, mat); -} - - static bool gles2_texture_get_dmabuf_size(struct wlr_texture *texture, struct wl_resource *resource, int *width, int *height) { if (!wlr_dmabuf_resource_is_buffer(resource)) { @@ -287,7 +275,6 @@ static bool gles2_texture_get_dmabuf_size(struct wlr_texture *texture, struct return true; } - static void gles2_texture_get_buffer_size(struct wlr_texture *texture, struct wl_resource *resource, int *width, int *height) { struct wl_shm_buffer *buffer = wl_shm_buffer_get(resource); @@ -344,7 +331,6 @@ static struct wlr_texture_impl wlr_texture_impl = { .upload_drm = gles2_texture_upload_drm, .upload_dmabuf = gles2_texture_upload_dmabuf, .upload_eglimage = gles2_texture_upload_eglimage, - .get_matrix = gles2_texture_get_matrix, .get_buffer_size = gles2_texture_get_buffer_size, .bind = gles2_texture_bind, .destroy = gles2_texture_destroy, diff --git a/render/wlr_renderer.c b/render/wlr_renderer.c index e847fcc2..c4f91d5e 100644 --- a/render/wlr_renderer.c +++ b/render/wlr_renderer.c @@ -1,6 +1,7 @@ #include #include #include +#include void wlr_renderer_init(struct wlr_renderer *renderer, struct wlr_renderer_impl *impl) { @@ -35,6 +36,17 @@ struct wlr_texture *wlr_render_texture_create(struct wlr_renderer *r) { return r->impl->texture_create(r); } +bool wlr_render_texture(struct wlr_renderer *r, struct wlr_texture *texture, + const float projection[static 9], int x, int y, float alpha) { + float mat[9]; + wlr_matrix_identity(mat); + wlr_matrix_translate(mat, x, y); + wlr_matrix_scale(mat, texture->width, texture->height); + wlr_matrix_multiply(mat, projection, mat); + + return wlr_render_texture_with_matrix(r, texture, mat, alpha); +} + bool wlr_render_texture_with_matrix(struct wlr_renderer *r, struct wlr_texture *texture, const float matrix[static 9], float alpha) { diff --git a/render/wlr_texture.c b/render/wlr_texture.c index 3685185a..48f76c8e 100644 --- a/render/wlr_texture.c +++ b/render/wlr_texture.c @@ -58,11 +58,6 @@ bool wlr_texture_upload_dmabuf(struct wlr_texture *texture, return texture->impl->upload_dmabuf(texture, dmabuf_resource); } -void wlr_texture_get_matrix(struct wlr_texture *texture, - float mat[static 9], const float projection[static 9], int x, int y) { - texture->impl->get_matrix(texture, mat, projection, x, y); -} - void wlr_texture_get_buffer_size(struct wlr_texture *texture, struct wl_resource *resource, int *width, int *height) { texture->impl->get_buffer_size(texture, resource, width, height); -- cgit v1.2.3 From 7894fca22498f79f73b8f3c5853dd22a1727cd1c Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 15 Mar 2018 21:26:45 +0100 Subject: matrix: rename wlr_matrix_texture to wlr_matrix_projection --- backend/drm/drm.c | 4 ++-- include/wlr/types/wlr_matrix.h | 4 +--- types/wlr_matrix.c | 2 +- types/wlr_output.c | 4 ++-- 4 files changed, 6 insertions(+), 8 deletions(-) (limited to 'backend') diff --git a/backend/drm/drm.c b/backend/drm/drm.c index 0447d865..fd436659 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -587,8 +587,8 @@ static bool wlr_drm_connector_set_cursor(struct wlr_output *output, enum wl_output_transform transform = wlr_output_transform_compose( wlr_output_transform_invert(output->transform), WL_OUTPUT_TRANSFORM_FLIPPED_180); - wlr_matrix_texture(plane->matrix, plane->surf.width, plane->surf.height, - transform); + wlr_matrix_projection(plane->matrix, plane->surf.width, + plane->surf.height, transform); plane->wlr_tex = wlr_render_texture_create(plane->surf.renderer->wlr_rend); diff --git a/include/wlr/types/wlr_matrix.h b/include/wlr/types/wlr_matrix.h index 5255980a..fd060d11 100644 --- a/include/wlr/types/wlr_matrix.h +++ b/include/wlr/types/wlr_matrix.h @@ -1,7 +1,6 @@ #ifndef WLR_TYPES_WLR_MATRIX_H #define WLR_TYPES_WLR_MATRIX_H -#include #include #include @@ -13,8 +12,7 @@ void wlr_matrix_multiply(float mat[static 9], const float a[static 9], const float b[static 9]); void wlr_matrix_transform(float mat[static 9], enum wl_output_transform transform); - -void wlr_matrix_texture(float mat[static 9], int32_t width, int32_t height, +void wlr_matrix_projection(float mat[static 9], int width, int height, enum wl_output_transform transform); void wlr_matrix_project_box(float mat[static 9], const struct wlr_box *box, enum wl_output_transform transform, float rotation, diff --git a/types/wlr_matrix.c b/types/wlr_matrix.c index 85a294d9..c5fa1340 100644 --- a/types/wlr_matrix.c +++ b/types/wlr_matrix.c @@ -109,7 +109,7 @@ void wlr_matrix_transform(float mat[static 9], } // Equivilent to glOrtho(0, width, 0, height, 1, -1) with the transform applied -void wlr_matrix_texture(float mat[static 9], int32_t width, int32_t height, +void wlr_matrix_projection(float mat[static 9], int width, int height, enum wl_output_transform transform) { memset(mat, 0, sizeof(*mat) * 9); diff --git a/types/wlr_output.c b/types/wlr_output.c index 9a0edd44..9575f071 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -139,8 +139,8 @@ void wlr_output_update_enabled(struct wlr_output *output, bool enabled) { } static void wlr_output_update_matrix(struct wlr_output *output) { - wlr_matrix_texture(output->transform_matrix, output->width, output->height, - output->transform); + wlr_matrix_projection(output->transform_matrix, output->width, + output->height, output->transform); } void wlr_output_enable(struct wlr_output *output, bool enable) { -- cgit v1.2.3