Skip to content
This repository has been archived by the owner on Nov 1, 2021. It is now read-only.

Commit

Permalink
output: improve transform matrix calculation
Browse files Browse the repository at this point in the history
Compute only the transform matrix in the output. The projection matrix
will be calculated inside the gles2 renderer when we start rendering.

The goal is to help the pixman rendering process.
  • Loading branch information
bl4ckb0ne committed Mar 8, 2021
1 parent c5dad8b commit 00f2766
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
1 change: 1 addition & 0 deletions include/render/gles2.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ struct wlr_gles2_tex_shader {
struct wlr_gles2_renderer {
struct wlr_renderer wlr_renderer;

float projection[9];
struct wlr_egl *egl;
int drm_fd;

Expand Down
13 changes: 10 additions & 3 deletions render/gles2/renderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ static void gles2_begin(struct wlr_renderer *wlr_renderer, uint32_t width,
renderer->viewport_width = width;
renderer->viewport_height = height;

// refresh projection matrix
wlr_matrix_projection(renderer->projection, width, height,
WL_OUTPUT_TRANSFORM_NORMAL);

// enable transparency
glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
Expand Down Expand Up @@ -271,7 +275,8 @@ static bool gles2_render_subtexture_with_matrix(
}

float gl_matrix[9];
wlr_matrix_multiply(gl_matrix, flip_180, matrix);
wlr_matrix_multiply(gl_matrix, renderer->projection, matrix);
wlr_matrix_multiply(gl_matrix, flip_180, gl_matrix);

// OpenGL ES 2 requires the glUniformMatrix3fv transpose parameter to be set
// to GL_FALSE
Expand Down Expand Up @@ -325,7 +330,8 @@ static void gles2_render_quad_with_matrix(struct wlr_renderer *wlr_renderer,
gles2_get_renderer_in_context(wlr_renderer);

float gl_matrix[9];
wlr_matrix_multiply(gl_matrix, flip_180, matrix);
wlr_matrix_multiply(gl_matrix, renderer->projection, matrix);
wlr_matrix_multiply(gl_matrix, flip_180, gl_matrix);

// OpenGL ES 2 requires the glUniformMatrix3fv transpose parameter to be set
// to GL_FALSE
Expand Down Expand Up @@ -355,7 +361,8 @@ static void gles2_render_ellipse_with_matrix(struct wlr_renderer *wlr_renderer,
gles2_get_renderer_in_context(wlr_renderer);

float gl_matrix[9];
wlr_matrix_multiply(gl_matrix, flip_180, matrix);
wlr_matrix_multiply(gl_matrix, renderer->projection, matrix);
wlr_matrix_multiply(gl_matrix, flip_180, gl_matrix);

// OpenGL ES 2 requires the glUniformMatrix3fv transpose parameter to be set
// to GL_FALSE
Expand Down
11 changes: 9 additions & 2 deletions types/wlr_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,15 @@ void wlr_output_update_enabled(struct wlr_output *output, bool enabled) {
}

static void output_update_matrix(struct wlr_output *output) {
wlr_matrix_projection(output->transform_matrix, output->width,
output->height, output->transform);
float width = output->width / 2.f;
float height = output->height / 2.f;

wlr_matrix_identity(output->transform_matrix);
if (output->transform != WL_OUTPUT_TRANSFORM_NORMAL) {
wlr_matrix_translate(output->transform_matrix, width, height);
wlr_matrix_transform(output->transform_matrix, output->transform);
wlr_matrix_translate(output->transform_matrix, -width, -height);
}
}

void wlr_output_enable(struct wlr_output *output, bool enable) {
Expand Down

0 comments on commit 00f2766

Please sign in to comment.