diff --git a/include/sway/desktop/fx_renderer.h b/include/sway/desktop/fx_renderer/fx_renderer.h similarity index 100% rename from include/sway/desktop/fx_renderer.h rename to include/sway/desktop/fx_renderer/fx_renderer.h diff --git a/include/sway/desktop/fx_renderer/matrix.h b/include/sway/desktop/fx_renderer/matrix.h new file mode 100644 index 000000000..6931e8d21 --- /dev/null +++ b/include/sway/desktop/fx_renderer/matrix.h @@ -0,0 +1,9 @@ +#ifndef _MATRIX_H +#define _MATRIX_H + +#include + +void matrix_projection(float mat[static 9], int width, int height, + enum wl_output_transform transform); + +#endif diff --git a/include/sway/output.h b/include/sway/output.h index 2d702741c..a6bec10a7 100644 --- a/include/sway/output.h +++ b/include/sway/output.h @@ -6,7 +6,7 @@ #include #include #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" diff --git a/sway/desktop/fx_renderer.c b/sway/desktop/fx_renderer/fx_renderer.c similarity index 94% rename from sway/desktop/fx_renderer.c rename to sway/desktop/fx_renderer/fx_renderer.c index a5ad0dabc..36c5bb610 100644 --- a/sway/desktop/fx_renderer.c +++ b/sway/desktop/fx_renderer/fx_renderer.c @@ -11,8 +11,10 @@ #include #include #include + #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" @@ -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); diff --git a/sway/desktop/fx_renderer/matrix.c b/sway/desktop/fx_renderer/matrix.c new file mode 100644 index 000000000..9c9dabec5 --- /dev/null +++ b/sway/desktop/fx_renderer/matrix.c @@ -0,0 +1,70 @@ +#include +#include +#include + +#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; +} diff --git a/sway/desktop/shaders/box_shadow.frag b/sway/desktop/fx_renderer/shaders/box_shadow.frag similarity index 100% rename from sway/desktop/shaders/box_shadow.frag rename to sway/desktop/fx_renderer/shaders/box_shadow.frag diff --git a/sway/desktop/shaders/common.vert b/sway/desktop/fx_renderer/shaders/common.vert similarity index 100% rename from sway/desktop/shaders/common.vert rename to sway/desktop/fx_renderer/shaders/common.vert diff --git a/sway/desktop/shaders/corner.frag b/sway/desktop/fx_renderer/shaders/corner.frag similarity index 100% rename from sway/desktop/shaders/corner.frag rename to sway/desktop/fx_renderer/shaders/corner.frag diff --git a/sway/desktop/shaders/embed.sh b/sway/desktop/fx_renderer/shaders/embed.sh similarity index 100% rename from sway/desktop/shaders/embed.sh rename to sway/desktop/fx_renderer/shaders/embed.sh diff --git a/sway/desktop/shaders/meson.build b/sway/desktop/fx_renderer/shaders/meson.build similarity index 100% rename from sway/desktop/shaders/meson.build rename to sway/desktop/fx_renderer/shaders/meson.build diff --git a/sway/desktop/shaders/quad.frag b/sway/desktop/fx_renderer/shaders/quad.frag similarity index 100% rename from sway/desktop/shaders/quad.frag rename to sway/desktop/fx_renderer/shaders/quad.frag diff --git a/sway/desktop/shaders/quad_round.frag b/sway/desktop/fx_renderer/shaders/quad_round.frag similarity index 100% rename from sway/desktop/shaders/quad_round.frag rename to sway/desktop/fx_renderer/shaders/quad_round.frag diff --git a/sway/desktop/shaders/tex.frag b/sway/desktop/fx_renderer/shaders/tex.frag similarity index 100% rename from sway/desktop/shaders/tex.frag rename to sway/desktop/fx_renderer/shaders/tex.frag diff --git a/sway/desktop/output.c b/sway/desktop/output.c index 5107c43ca..a7269b7b2 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -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) { diff --git a/sway/desktop/render.c b/sway/desktop/render.c index 244fe62e7..3a3517c1a 100644 --- a/sway/desktop/render.c +++ b/sway/desktop/render.c @@ -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" diff --git a/sway/meson.build b/sway/meson.build index b6f63c16b..7eef011b9 100644 --- a/sway/meson.build +++ b/sway/meson.build @@ -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', @@ -224,7 +225,7 @@ sway_sources = files( 'tree/output.c', ) -subdir('desktop/shaders') +subdir('desktop/fx_renderer/shaders') sway_deps = [ cairo, diff --git a/sway/server.c b/sway/server.c index b107d84af..c4d005b62 100644 --- a/sway/server.c +++ b/sway/server.c @@ -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" diff --git a/sway/tree/container.c b/sway/tree/container.c index d22dadd5b..f256bafcc 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -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"