Skip to content

Commit

Permalink
structure: moved fx_renderer and related fuctions to a folder
Browse files Browse the repository at this point in the history
  • Loading branch information
WillPower3309 committed Apr 7, 2023
1 parent c24fccd commit 420364d
Show file tree
Hide file tree
Showing 18 changed files with 88 additions and 73 deletions.
File renamed without changes.
9 changes: 9 additions & 0 deletions include/sway/desktop/fx_renderer/matrix.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef _MATRIX_H
#define _MATRIX_H

#include <wlr/types/wlr_output.h>

void matrix_projection(float mat[static 9], int width, int height,
enum wl_output_transform transform);

#endif
2 changes: 1 addition & 1 deletion include/sway/output.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <wlr/types/wlr_damage_ring.h>
#include <wlr/types/wlr_output.h>
#include "config.h"
#include "sway/desktop/fx_renderer.h"
#include "sway/desktop/fx_renderer/fx_renderer.h"
#include "sway/tree/node.h"
#include "sway/tree/view.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
#include <wlr/render/gles2.h>
#include <wlr/types/wlr_matrix.h>
#include <wlr/util/box.h>

#include "log.h"
#include "sway/desktop/fx_renderer.h"
#include "sway/desktop/fx_renderer/fx_renderer.h"
#include "sway/desktop/fx_renderer/matrix.h"
#include "sway/output.h"
#include "sway/server.h"

Expand All @@ -31,71 +33,6 @@ static const GLfloat verts[] = {
0, 1, // bottom left
};

static const float transforms[][9] = {
[WL_OUTPUT_TRANSFORM_NORMAL] = {
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, 0.0f,
-1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f,
},
[WL_OUTPUT_TRANSFORM_180] = {
-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, 0.0f,
1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f,
},
[WL_OUTPUT_TRANSFORM_FLIPPED] = {
-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, 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,
0.0f, -1.0f, 0.0f,
0.0f, 0.0f, 1.0f,
},
[WL_OUTPUT_TRANSFORM_FLIPPED_270] = {
0.0f, -1.0f, 0.0f,
-1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f,
},
};

static void matrix_projection(float mat[static 9], int width, int height,
enum wl_output_transform transform) {
memset(mat, 0, sizeof(*mat) * 9);

const float *t = transforms[transform];
float x = 2.0f / width;
float y = 2.0f / height;

// Rotation + reflection
mat[0] = x * t[0];
mat[1] = x * t[1];
mat[3] = y * -t[3];
mat[4] = y * -t[4];

// Translation
mat[2] = -copysign(1.0f, mat[0] + mat[1]);
mat[5] = -copysign(1.0f, mat[3] + mat[4]);

// Identity
mat[8] = 1.0f;
}

static GLuint compile_shader(GLuint type, const GLchar *src) {
GLuint shader = glCreateShader(type);
glShaderSource(shader, 1, &src, NULL);
Expand Down
70 changes: 70 additions & 0 deletions sway/desktop/fx_renderer/matrix.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#include <math.h>
#include <string.h>
#include <wlr/types/wlr_output.h>

#include "sway/desktop/fx_renderer/matrix.h"

static const float transforms[][9] = {
[WL_OUTPUT_TRANSFORM_NORMAL] = {
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, 0.0f,
-1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f,
},
[WL_OUTPUT_TRANSFORM_180] = {
-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, 0.0f,
1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f,
},
[WL_OUTPUT_TRANSFORM_FLIPPED] = {
-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, 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,
0.0f, -1.0f, 0.0f,
0.0f, 0.0f, 1.0f,
},
[WL_OUTPUT_TRANSFORM_FLIPPED_270] = {
0.0f, -1.0f, 0.0f,
-1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f,
},
};

void matrix_projection(float mat[static 9], int width, int height,
enum wl_output_transform transform) {
memset(mat, 0, sizeof(*mat) * 9);

const float *t = transforms[transform];
float x = 2.0f / width;
float y = 2.0f / height;

// Rotation + reflection
mat[0] = x * t[0];
mat[1] = x * t[1];
mat[3] = y * -t[3];
mat[4] = y * -t[4];

// Translation
mat[2] = -copysign(1.0f, mat[0] + mat[1]);
mat[5] = -copysign(1.0f, mat[3] + mat[4]);

// Identity
mat[8] = 1.0f;
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion sway/desktop/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#include "sway/tree/root.h"
#include "sway/tree/view.h"
#include "sway/tree/workspace.h"
#include "sway/desktop/fx_renderer.h"

struct sway_output *output_by_name_or_id(const char *name_or_id) {
for (int i = 0; i < root->outputs->length; ++i) {
Expand Down
2 changes: 1 addition & 1 deletion sway/desktop/render.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "log.h"
#include "config.h"
#include "sway/config.h"
#include "sway/desktop/fx_renderer.h"
#include "sway/desktop/fx_renderer/fx_renderer.h"
#include "sway/input/input-manager.h"
#include "sway/input/seat.h"
#include "sway/layers.h"
Expand Down
5 changes: 3 additions & 2 deletions sway/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ sway_sources = files(
'xdg_decoration.c',

'desktop/desktop.c',
'desktop/fx_renderer.c',
'desktop/fx_renderer/fx_renderer.c',
'desktop/fx_renderer/matrix.c',
'desktop/idle_inhibit_v1.c',
'desktop/layer_shell.c',
'desktop/output.c',
Expand Down Expand Up @@ -224,7 +225,7 @@ sway_sources = files(
'tree/output.c',
)

subdir('desktop/shaders')
subdir('desktop/fx_renderer/shaders')

sway_deps = [
cairo,
Expand Down
2 changes: 1 addition & 1 deletion sway/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
#include "list.h"
#include "log.h"
#include "sway/config.h"
#include "sway/desktop/fx_renderer.h"
#include "sway/desktop/fx_renderer/fx_renderer.h"
#include "sway/desktop/idle_inhibit_v1.h"
#include "sway/input/input-manager.h"
#include "sway/output.h"
Expand Down
1 change: 0 additions & 1 deletion sway/tree/container.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include "pango.h"
#include "sway/config.h"
#include "sway/desktop.h"
#include "sway/desktop/fx_renderer.h"
#include "sway/desktop/transaction.h"
#include "sway/input/input-manager.h"
#include "sway/input/seat.h"
Expand Down

0 comments on commit 420364d

Please sign in to comment.