summaryrefslogtreecommitdiff
path: root/sway/desktop/fx_renderer
diff options
context:
space:
mode:
authorReza Jelveh <[email protected]>2024-04-15 13:39:41 +0800
committerGitHub <[email protected]>2024-04-15 01:39:41 -0400
commitfb86ed6b0588dfdebfb66ce875bc63cfa0a897f6 (patch)
tree29857a1769107adc58696f08d379f608aa4e29a2 /sway/desktop/fx_renderer
parenta5e79676c4bd22fc5902182acf0667907202a465 (diff)
feat: 1.9 merge (#277)
Co-authored-by: William McKinnon <[email protected]> Co-authored-by: Erik Reider <[email protected]>
Diffstat (limited to 'sway/desktop/fx_renderer')
-rw-r--r--sway/desktop/fx_renderer/fx_framebuffer.c89
-rw-r--r--sway/desktop/fx_renderer/fx_renderer.c961
-rw-r--r--sway/desktop/fx_renderer/fx_stencilbuffer.c21
-rw-r--r--sway/desktop/fx_renderer/fx_texture.c37
-rw-r--r--sway/desktop/fx_renderer/matrix.c70
-rw-r--r--sway/desktop/fx_renderer/shaders/blur1.frag18
-rw-r--r--sway/desktop/fx_renderer/shaders/blur2.frag22
-rw-r--r--sway/desktop/fx_renderer/shaders/blur_effects.frag54
-rw-r--r--sway/desktop/fx_renderer/shaders/box_shadow.frag74
-rw-r--r--sway/desktop/fx_renderer/shaders/common.vert12
-rw-r--r--sway/desktop/fx_renderer/shaders/corner.frag36
-rw-r--r--sway/desktop/fx_renderer/shaders/embed.sh11
-rw-r--r--sway/desktop/fx_renderer/shaders/meson.build27
-rw-r--r--sway/desktop/fx_renderer/shaders/quad.frag7
-rw-r--r--sway/desktop/fx_renderer/shaders/quad_round.frag39
-rw-r--r--sway/desktop/fx_renderer/shaders/stencil_mask.frag17
-rw-r--r--sway/desktop/fx_renderer/shaders/tex.frag67
17 files changed, 0 insertions, 1562 deletions
diff --git a/sway/desktop/fx_renderer/fx_framebuffer.c b/sway/desktop/fx_renderer/fx_framebuffer.c
deleted file mode 100644
index dd8c27b1..00000000
--- a/sway/desktop/fx_renderer/fx_framebuffer.c
+++ /dev/null
@@ -1,89 +0,0 @@
-#include "log.h"
-#include "sway/desktop/fx_renderer/fx_framebuffer.h"
-#include "sway/desktop/fx_renderer/fx_stencilbuffer.h"
-#include "sway/desktop/fx_renderer/fx_texture.h"
-
-struct fx_framebuffer fx_framebuffer_create() {
- return (struct fx_framebuffer) {
- .fb = -1,
- .stencil_buffer = fx_stencilbuffer_create(),
- .texture = fx_texture_create(),
- };
-}
-
-void fx_framebuffer_bind(struct fx_framebuffer *buffer) {
- glBindFramebuffer(GL_FRAMEBUFFER, buffer->fb);
-}
-
-void fx_framebuffer_update(struct fx_framebuffer *buffer, int width, int height) {
- bool first_alloc = false;
-
- if (buffer->fb == (uint32_t) -1) {
- glGenFramebuffers(1, &buffer->fb);
- first_alloc = true;
- }
-
- if (buffer->texture.id == 0) {
- first_alloc = true;
- glGenTextures(1, &buffer->texture.id);
- glBindTexture(GL_TEXTURE_2D, buffer->texture.id);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- }
-
- if (first_alloc || buffer->texture.width != width || buffer->texture.height != height) {
- glBindTexture(GL_TEXTURE_2D, buffer->texture.id);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
-
- glBindFramebuffer(GL_FRAMEBUFFER, buffer->fb);
- glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
- buffer->texture.id, 0);
- buffer->texture.target = GL_TEXTURE_2D;
- buffer->texture.has_alpha = false;
- buffer->texture.width = width;
- buffer->texture.height = height;
-
- GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
- if (status != GL_FRAMEBUFFER_COMPLETE) {
- sway_log(SWAY_ERROR, "Framebuffer incomplete, couldn't create! (FB status: %i)", status);
- return;
- }
- sway_log(SWAY_DEBUG, "Framebuffer created, status %i", status);
- }
-
- glBindTexture(GL_TEXTURE_2D, 0);
-}
-
-void fx_framebuffer_add_stencil_buffer(struct fx_framebuffer *buffer, int width, int height) {
- bool first_alloc = false;
-
- if (buffer->stencil_buffer.rb == (uint32_t) -1) {
- glGenRenderbuffers(1, &buffer->stencil_buffer.rb);
- first_alloc = true;
- }
-
- if (first_alloc || buffer->stencil_buffer.width != width || buffer->stencil_buffer.height != height) {
- glBindRenderbuffer(GL_RENDERBUFFER, buffer->stencil_buffer.rb);
- glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, width, height);
- buffer->stencil_buffer.width = width;
- buffer->stencil_buffer.height = height;
- }
-
- glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, buffer->stencil_buffer.rb);
-}
-
-void fx_framebuffer_release(struct fx_framebuffer *buffer) {
- // Release the framebuffer
- if (buffer->fb != (uint32_t) -1 && buffer->fb) {
- glDeleteFramebuffers(1, &buffer->fb);
- }
- buffer->fb = -1;
-
- // Release the stencil buffer
- fx_stencilbuffer_release(&buffer->stencil_buffer);
-
- // Release the texture
- fx_texture_release(&buffer->texture);
-}
diff --git a/sway/desktop/fx_renderer/fx_renderer.c b/sway/desktop/fx_renderer/fx_renderer.c
deleted file mode 100644
index f06d93b5..00000000
--- a/sway/desktop/fx_renderer/fx_renderer.c
+++ /dev/null
@@ -1,961 +0,0 @@
-/*
- The original wlr_renderer was heavily referenced in making this project
- https://gitlab.freedesktop.org/wlroots/wlroots/-/tree/master/render/gles2
-*/
-
-#include <assert.h>
-#include <GLES2/gl2.h>
-#include <stdlib.h>
-#include <wlr/backend.h>
-#include <wlr/render/egl.h>
-#include <wlr/render/gles2.h>
-#include <wlr/types/wlr_matrix.h>
-#include <wlr/util/box.h>
-
-#include "log.h"
-#include "sway/desktop/fx_renderer/fx_framebuffer.h"
-#include "sway/desktop/fx_renderer/fx_renderer.h"
-#include "sway/desktop/fx_renderer/fx_stencilbuffer.h"
-#include "sway/desktop/fx_renderer/fx_texture.h"
-#include "sway/desktop/fx_renderer/matrix.h"
-#include "sway/server.h"
-
-// shaders
-#include "blur1_frag_src.h"
-#include "blur2_frag_src.h"
-#include "blur_effects_frag_src.h"
-#include "box_shadow_frag_src.h"
-#include "common_vert_src.h"
-#include "corner_frag_src.h"
-#include "quad_frag_src.h"
-#include "quad_round_frag_src.h"
-#include "stencil_mask_frag_src.h"
-#include "tex_frag_src.h"
-
-static const GLfloat verts[] = {
- 1, 0, // top right
- 0, 0, // top left
- 1, 1, // bottom right
- 0, 1, // bottom left
-};
-
-static GLuint compile_shader(GLuint type, const GLchar *src) {
- GLuint shader = glCreateShader(type);
- glShaderSource(shader, 1, &src, NULL);
- glCompileShader(shader);
-
- GLint ok;
- glGetShaderiv(shader, GL_COMPILE_STATUS, &ok);
- if (ok == GL_FALSE) {
- sway_log(SWAY_ERROR, "Failed to compile shader");
- glDeleteShader(shader);
- shader = 0;
- }
-
- return shader;
-}
-
-static GLuint link_program(const GLchar *frag_src) {
- const GLchar *vert_src = common_vert_src;
- GLuint vert = compile_shader(GL_VERTEX_SHADER, vert_src);
- if (!vert) {
- goto error;
- }
-
- GLuint frag = compile_shader(GL_FRAGMENT_SHADER, frag_src);
- if (!frag) {
- glDeleteShader(vert);
- goto error;
- }
-
- GLuint prog = glCreateProgram();
- glAttachShader(prog, vert);
- glAttachShader(prog, frag);
- glLinkProgram(prog);
-
- glDetachShader(prog, vert);
- glDetachShader(prog, frag);
- glDeleteShader(vert);
- glDeleteShader(frag);
-
- GLint ok;
- glGetProgramiv(prog, GL_LINK_STATUS, &ok);
- if (ok == GL_FALSE) {
- sway_log(SWAY_ERROR, "Failed to link shader");
- glDeleteProgram(prog);
- goto error;
- }
-
- return prog;
-
-error:
- return 0;
-}
-
-static bool link_blur_program(struct blur_shader *shader, const char *shader_program) {
- GLuint prog;
- shader->program = prog = link_program(shader_program);
- if (!shader->program) {
- return false;
- }
- shader->proj = glGetUniformLocation(prog, "proj");
- shader->tex = glGetUniformLocation(prog, "tex");
- shader->pos_attrib = glGetAttribLocation(prog, "pos");
- shader->tex_attrib = glGetAttribLocation(prog, "texcoord");
- shader->radius = glGetUniformLocation(prog, "radius");
- shader->halfpixel = glGetUniformLocation(prog, "halfpixel");
-
- return true;
-}
-
-static bool link_blur_effects_program(struct effects_shader *shader, const char *shader_program) {
- GLuint prog;
- shader->program = prog = link_program(shader_program);
- if (!shader->program) {
- return false;
- }
- shader->proj = glGetUniformLocation(prog, "proj");
- shader->tex = glGetUniformLocation(prog, "tex");
- shader->pos_attrib = glGetAttribLocation(prog, "pos");
- shader->tex_attrib = glGetAttribLocation(prog, "texcoord");
- shader->noise = glGetUniformLocation(prog, "noise");
- shader->brightness = glGetUniformLocation(prog, "brightness");
- shader->contrast = glGetUniformLocation(prog, "contrast");
- shader->saturation = glGetUniformLocation(prog, "saturation");
-
- return true;
-
-}
-
-static bool link_box_shadow_program(struct box_shadow_shader *shader) {
- GLuint prog;
- shader->program = prog = link_program(box_shadow_frag_src);
- if (!shader->program) {
- return false;
- }
- shader->proj = glGetUniformLocation(prog, "proj");
- shader->color = glGetUniformLocation(prog, "color");
- shader->pos_attrib = glGetAttribLocation(prog, "pos");
- shader->position = glGetUniformLocation(prog, "position");
- shader->size = glGetUniformLocation(prog, "size");
- shader->blur_sigma = glGetUniformLocation(prog, "blur_sigma");
- shader->corner_radius = glGetUniformLocation(prog, "corner_radius");
-
- return true;
-}
-
-static bool link_corner_program(struct corner_shader *shader) {
- GLuint prog;
- shader->program = prog = link_program(corner_frag_src);
- if (!shader->program) {
- return false;
- }
- shader->proj = glGetUniformLocation(prog, "proj");
- shader->color = glGetUniformLocation(prog, "color");
- shader->pos_attrib = glGetAttribLocation(prog, "pos");
- shader->position = glGetUniformLocation(prog, "position");
- shader->half_size = glGetUniformLocation(prog, "half_size");
- shader->half_thickness = glGetUniformLocation(prog, "half_thickness");
- shader->radius = glGetUniformLocation(prog, "radius");
- shader->is_top_left = glGetUniformLocation(prog, "is_top_left");
- shader->is_top_right = glGetUniformLocation(prog, "is_top_right");
- shader->is_bottom_left = glGetUniformLocation(prog, "is_bottom_left");
- shader->is_bottom_right = glGetUniformLocation(prog, "is_bottom_right");
-
- return true;
-}
-
-static bool link_quad_program(struct quad_shader *shader) {
- GLuint prog;
- shader->program = prog = link_program(quad_frag_src);
- if (!shader->program) {
- return false;
- }
-
- shader->proj = glGetUniformLocation(prog, "proj");
- shader->color = glGetUniformLocation(prog, "color");
- shader->pos_attrib = glGetAttribLocation(prog, "pos");
-
- return true;
-}
-
-static bool link_rounded_quad_program(struct rounded_quad_shader *shader,
- enum fx_rounded_quad_shader_source source) {
- GLchar quad_src[2048];
- snprintf(quad_src, sizeof(quad_src),
- "#define SOURCE %d\n%s", source, quad_round_frag_src);
-
- GLuint prog;
- shader->program = prog = link_program(quad_src);
- if (!shader->program) {
- return false;
- }
-
- shader->proj = glGetUniformLocation(prog, "proj");
- shader->color = glGetUniformLocation(prog, "color");
- shader->pos_attrib = glGetAttribLocation(prog, "pos");
- shader->size = glGetUniformLocation(prog, "size");
- shader->position = glGetUniformLocation(prog, "position");
- shader->radius = glGetUniformLocation(prog, "radius");
-
- return true;
-}
-
-static bool link_stencil_mask_program(struct stencil_mask_shader *shader) {
- GLuint prog;
- shader->program = prog = link_program(stencil_mask_frag_src);
- if (!shader->program) {
- return false;
- }
-
- shader->proj = glGetUniformLocation(prog, "proj");
- shader->color = glGetUniformLocation(prog, "color");
- shader->pos_attrib = glGetAttribLocation(prog, "pos");
- shader->position = glGetUniformLocation(prog, "position");
- shader->half_size = glGetUniformLocation(prog, "half_size");
- shader->radius = glGetUniformLocation(prog, "radius");
-
- return true;
-}
-
-static bool link_tex_program(struct tex_shader *shader,
- enum fx_tex_shader_source source) {
- GLchar frag_src[2048];
- snprintf(frag_src, sizeof(frag_src),
- "#define SOURCE %d\n%s", source, tex_frag_src);
-
- GLuint prog;
- shader->program = prog = link_program(frag_src);
- if (!shader->program) {
- return false;
- }
-
- shader->proj = glGetUniformLocation(prog, "proj");
- shader->tex = glGetUniformLocation(prog, "tex");
- shader->alpha = glGetUniformLocation(prog, "alpha");
- shader->dim = glGetUniformLocation(prog, "dim");
- shader->dim_color = glGetUniformLocation(prog, "dim_color");
- shader->pos_attrib = glGetAttribLocation(prog, "pos");
- shader->tex_attrib = glGetAttribLocation(prog, "texcoord");
- shader->size = glGetUniformLocation(prog, "size");
- shader->position = glGetUniformLocation(prog, "position");
- shader->radius = glGetUniformLocation(prog, "radius");
- shader->saturation = glGetUniformLocation(prog, "saturation");
- shader->has_titlebar = glGetUniformLocation(prog, "has_titlebar");
- shader->discard_transparent = glGetUniformLocation(prog, "discard_transparent");
-
- return true;
-}
-
-static bool check_gl_ext(const char *exts, const char *ext) {
- size_t extlen = strlen(ext);
- const char *end = exts + strlen(exts);
-
- while (exts < end) {
- if (exts[0] == ' ') {
- exts++;
- continue;
- }
- size_t n = strcspn(exts, " ");
- if (n == extlen && strncmp(ext, exts, n) == 0) {
- return true;
- }
- exts += n;
- }
- return false;
-}
-
-static void load_gl_proc(void *proc_ptr, const char *name) {
- void *proc = (void *)eglGetProcAddress(name);
- if (proc == NULL) {
- sway_log(SWAY_ERROR, "GLES2 RENDERER: eglGetProcAddress(%s) failed", name);
- abort();
- }
- *(void **)proc_ptr = proc;
-}
-
-struct fx_renderer *fx_renderer_create(struct wlr_egl *egl, struct wlr_output *wlr_output) {
- struct fx_renderer *renderer = calloc(1, sizeof(struct fx_renderer));
- if (renderer == NULL) {
- return NULL;
- }
-
- renderer->wlr_output = wlr_output;
-
- // TODO: wlr_egl_make_current or eglMakeCurrent?
- // TODO: assert instead of conditional statement?
- if (!eglMakeCurrent(wlr_egl_get_display(egl), EGL_NO_SURFACE, EGL_NO_SURFACE,
- wlr_egl_get_context(egl))) {
- sway_log(SWAY_ERROR, "GLES2 RENDERER: Could not make EGL current");
- return NULL;
- }
-
- renderer->wlr_buffer = fx_framebuffer_create();
- renderer->blur_buffer = fx_framebuffer_create();
- renderer->blur_saved_pixels_buffer = fx_framebuffer_create();
- renderer->effects_buffer = fx_framebuffer_create();
- renderer->effects_buffer_swapped = fx_framebuffer_create();
-
- renderer->blur_buffer_dirty = true;
-
- // get extensions
- const char *exts_str = (const char *)glGetString(GL_EXTENSIONS);
- if (exts_str == NULL) {
- sway_log(SWAY_ERROR, "GLES2 RENDERER: Failed to get GL_EXTENSIONS");
- return NULL;
- }
-
- sway_log(SWAY_INFO, "Creating swayfx GLES2 renderer");
- sway_log(SWAY_INFO, "Using %s", glGetString(GL_VERSION));
- sway_log(SWAY_INFO, "GL vendor: %s", glGetString(GL_VENDOR));
- sway_log(SWAY_INFO, "GL renderer: %s", glGetString(GL_RENDERER));
- sway_log(SWAY_INFO, "Supported GLES2 extensions: %s", exts_str);
-
- // TODO: the rest of the gl checks
- if (check_gl_ext(exts_str, "GL_OES_EGL_image_external")) {
- renderer->exts.OES_egl_image_external = true;
- load_gl_proc(&renderer->procs.glEGLImageTargetTexture2DOES,
- "glEGLImageTargetTexture2DOES");
- }
-
- // blur shaders
- if (!link_blur_program(&renderer->shaders.blur1, blur1_frag_src)) {
- goto error;
- }
- if (!link_blur_program(&renderer->shaders.blur2, blur2_frag_src)) {
- goto error;
- }
- // effects shader
- if (!link_blur_effects_program(&renderer->shaders.blur_effects, blur_effects_frag_src)) {
- goto error;
- }
- // box shadow shader
- if (!link_box_shadow_program(&renderer->shaders.box_shadow)) {
- goto error;
- }
- // corner border shader
- if (!link_corner_program(&renderer->shaders.corner)) {
- goto error;
- }
- // quad fragment shader
- if (!link_quad_program(&renderer->shaders.quad)) {
- goto error;
- }
- // rounded quad fragment shaders
- if (!link_rounded_quad_program(&renderer->shaders.rounded_quad,
- SHADER_SOURCE_QUAD_ROUND)) {
- goto error;
- }
- if (!link_rounded_quad_program(&renderer->shaders.rounded_tl_quad,
- SHADER_SOURCE_QUAD_ROUND_TOP_LEFT)) {
- goto error;
- }
- if (!link_rounded_quad_program(&renderer->shaders.rounded_tr_quad,
- SHADER_SOURCE_QUAD_ROUND_TOP_RIGHT)) {
- goto error;
- }
- if (!link_rounded_quad_program(&renderer->shaders.rounded_bl_quad,
- SHADER_SOURCE_QUAD_ROUND_BOTTOM_LEFT)) {
- goto error;
- }
- if (!link_rounded_quad_program(&renderer->shaders.rounded_br_quad,
- SHADER_SOURCE_QUAD_ROUND_BOTTOM_RIGHT)) {
- goto error;
- }
- // stencil mask shader
- if (!link_stencil_mask_program(&renderer->shaders.stencil_mask)) {
- goto error;
- }
- // fragment shaders
- if (!link_tex_program(&renderer->shaders.tex_rgba, SHADER_SOURCE_TEXTURE_RGBA)) {
- goto error;
- }
- if (!link_tex_program(&renderer->shaders.tex_rgbx, SHADER_SOURCE_TEXTURE_RGBX)) {
- goto error;
- }
- if (!link_tex_program(&renderer->shaders.tex_ext, SHADER_SOURCE_TEXTURE_EXTERNAL)) {
- goto error;
- }
-
- if (!eglMakeCurrent(wlr_egl_get_display(egl),
- EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT)) {
- sway_log(SWAY_ERROR, "GLES2 RENDERER: Could not unset current EGL");
- goto error;
- }
-
- sway_log(SWAY_INFO, "GLES2 RENDERER: Shaders Initialized Successfully");
- return renderer;
-
-error:
- glDeleteProgram(renderer->shaders.blur1.program);
- glDeleteProgram(renderer->shaders.blur2.program);
- glDeleteProgram(renderer->shaders.blur_effects.program);
- glDeleteProgram(renderer->shaders.box_shadow.program);
- glDeleteProgram(renderer->shaders.corner.program);
- glDeleteProgram(renderer->shaders.quad.program);
- glDeleteProgram(renderer->shaders.rounded_quad.program);
- glDeleteProgram(renderer->shaders.rounded_bl_quad.program);
- glDeleteProgram(renderer->shaders.rounded_br_quad.program);
- glDeleteProgram(renderer->shaders.rounded_tl_quad.program);
- glDeleteProgram(renderer->shaders.rounded_tr_quad.program);
- glDeleteProgram(renderer->shaders.stencil_mask.program);
- glDeleteProgram(renderer->shaders.tex_rgba.program);
- glDeleteProgram(renderer->shaders.tex_rgbx.program);
- glDeleteProgram(renderer->shaders.tex_ext.program);
-
- if (!eglMakeCurrent(wlr_egl_get_display(egl),
- EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT)) {
- sway_log(SWAY_ERROR, "GLES2 RENDERER: Could not unset current EGL");
- }
-
- // TODO: more freeing?
- free(renderer);
-
- sway_log(SWAY_ERROR, "GLES2 RENDERER: Error Initializing Shaders");
- return NULL;
-}
-
-void fx_renderer_fini(struct fx_renderer *renderer) {
- fx_framebuffer_release(&renderer->blur_buffer);
- fx_framebuffer_release(&renderer->blur_saved_pixels_buffer);
- fx_framebuffer_release(&renderer->effects_buffer);
- fx_framebuffer_release(&renderer->effects_buffer_swapped);
-}
-
-void fx_renderer_begin(struct fx_renderer *renderer, int width, int height) {
- glViewport(0, 0, width, height);
- renderer->viewport_width = width;
- renderer->viewport_height = height;
-
- // Store the wlr FBO
- renderer->wlr_buffer.fb =
- wlr_gles2_renderer_get_current_fbo(renderer->wlr_output->renderer);
- // Get the fx_texture
- struct wlr_texture *wlr_texture = wlr_texture_from_buffer(
- renderer->wlr_output->renderer, renderer->wlr_output->back_buffer);
- renderer->wlr_buffer.texture = fx_texture_from_wlr_texture(wlr_texture);
- wlr_texture_destroy(wlr_texture);
- // Add the stencil to the wlr fbo
- fx_framebuffer_add_stencil_buffer(&renderer->wlr_buffer, width, height);
-
- // Create the framebuffers
- fx_framebuffer_update(&renderer->blur_saved_pixels_buffer, width, height);
- fx_framebuffer_update(&renderer->effects_buffer, width, height);
- fx_framebuffer_update(&renderer->effects_buffer_swapped, width, height);
-
- // Add a stencil buffer to the main buffer & bind the main buffer
- fx_framebuffer_bind(&renderer->wlr_buffer);
-
- pixman_region32_init(&renderer->blur_padding_region);
-
- // refresh projection matrix
- matrix_projection(renderer->projection, width, height,
- WL_OUTPUT_TRANSFORM_FLIPPED_180);
-
- glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
-}
-
-void fx_renderer_end(struct fx_renderer *renderer) {
- pixman_region32_fini(&renderer->blur_padding_region);
-}
-
-void fx_renderer_clear(const float color[static 4]) {
- glClearColor(color[0], color[1], color[2], color[3]);
- glClearStencil(0);
- glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
-}
-
-void fx_renderer_scissor(struct wlr_box *box) {
- if (box) {
- glScissor(box->x, box->y, box->width, box->height);
- glEnable(GL_SCISSOR_TEST);
- } else {
- glDisable(GL_SCISSOR_TEST);
- }
-}
-
-void fx_renderer_stencil_mask_init() {
- glClearStencil(0);
- glClear(GL_STENCIL_BUFFER_BIT);
- glEnable(GL_STENCIL_TEST);
-
- glStencilFunc(GL_ALWAYS, 1, 0xFF);
- glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
- // Disable writing to color buffer
- glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
-}
-
-void fx_renderer_stencil_mask_close(bool draw_inside_mask) {
- // Reenable writing to color buffer
- glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
- if (draw_inside_mask) {
- glStencilFunc(GL_EQUAL, 1, 0xFF);
- glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
- return;
- }
- glStencilFunc(GL_NOTEQUAL, 1, 0xFF);
- glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
-}
-
-void fx_renderer_stencil_mask_fini() {
- glClearStencil(0);
- glClear(GL_STENCIL_BUFFER_BIT);
- glDisable(GL_STENCIL_TEST);
-}
-
-bool fx_render_subtexture_with_matrix(struct fx_renderer *renderer, struct fx_texture *fx_texture,
- const struct wlr_fbox *src_box, const struct wlr_box *dst_box, const float matrix[static 9],
- struct decoration_data deco_data) {
- // Fixes corner radii not being "round" when the radii is larger than
- // the height/width
- int min_size = MIN(dst_box->height, dst_box->width) * 0.5;
- if (deco_data.corner_radius > min_size) {
- deco_data.corner_radius = min_size;
- }
-
- struct tex_shader *shader = NULL;
-
- switch (fx_texture->target) {
- case GL_TEXTURE_2D:
- if (fx_texture->has_alpha) {
- shader = &renderer->shaders.tex_rgba;
- } else {
- shader = &renderer->shaders.tex_rgbx;
- }
- break;
- case GL_TEXTURE_EXTERNAL_OES:
- shader = &renderer->shaders.tex_ext;
-
- if (!renderer->exts.OES_egl_image_external) {
- sway_log(SWAY_ERROR, "Failed to render texture: "
- "GL_TEXTURE_EXTERNAL_OES not supported");
- return false;
- }
- break;
- default:
- sway_log(SWAY_ERROR, "Aborting render");
- abort();
- }
-
- float gl_matrix[9];
- wlr_matrix_multiply(gl_matrix, renderer->projection, matrix);
-
- // OpenGL ES 2 requires the glUniformMatrix3fv transpose parameter to be set
- // to GL_FALSE
- wlr_matrix_transpose(gl_matrix, gl_matrix);
-
- // if there's no opacity or rounded corners we don't need to blend
- if (!fx_texture->has_alpha && deco_data.alpha == 1.0 && !deco_data.corner_radius) {
- glDisable(GL_BLEND);
- } else {
- glEnable(GL_BLEND);
- }
-
- glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
-
- glActiveTexture(GL_TEXTURE0);
- glBindTexture(fx_texture->target, fx_texture->id);
-
- glTexParameteri(fx_texture->target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
-
- glUseProgram(shader->program);
-
- float* dim_color = deco_data.dim_color;
-
- glUniformMatrix3fv(shader->proj, 1, GL_FALSE, gl_matrix);
- glUniform1i(shader->tex, 0);
- glUniform2f(shader->size, dst_box->width, dst_box->height);
- glUniform2f(shader->position, dst_box->x, dst_box->y);
- glUniform1f(shader->alpha, deco_data.alpha);
- glUniform1f(shader->dim, deco_data.dim);
- glUniform4f(shader->dim_color, dim_color[0], dim_color[1], dim_color[2], dim_color[3]);
- glUniform1f(shader->has_titlebar, deco_data.has_titlebar);
- glUniform1f(shader->discard_transparent, deco_data.discard_transparent);
- glUniform1f(shader->saturation, deco_data.saturation);
- glUniform1f(shader->radius, deco_data.corner_radius);
-
- const GLfloat x1 = src_box->x / fx_texture->width;
- const GLfloat y1 = src_box->y / fx_texture->height;
- const GLfloat x2 = (src_box->x + src_box->width) / fx_texture->width;
- const GLfloat y2 = (src_box->y + src_box->height) / fx_texture->height;
- const GLfloat texcoord[] = {
- x2, y1, // top right
- x1, y1, // top left
- x2, y2, // bottom right
- x1, y2, // bottom left
- };
-
- glVertexAttribPointer(shader->pos_attrib, 2, GL_FLOAT, GL_FALSE, 0, verts);
- glVertexAttribPointer(shader->tex_attrib, 2, GL_FLOAT, GL_FALSE, 0, texcoord);
-
- glEnableVertexAttribArray(shader->pos_attrib);
- glEnableVertexAttribArray(shader->tex_attrib);
-
- glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
-
- glDisableVertexAttribArray(shader->pos_attrib);
- glDisableVertexAttribArray(shader->tex_attrib);
-
- glBindTexture(fx_texture->target, 0);
-
- return true;
-}
-
-bool fx_render_texture_with_matrix(struct fx_renderer *renderer, struct fx_texture *texture,
- const struct wlr_box *dst_box, const float matrix[static 9],
- struct decoration_data deco_data) {
- struct wlr_fbox src_box = {
- .x = 0,
- .y = 0,
- .width = texture->width,
- .height = texture->height,
- };
- return fx_render_subtexture_with_matrix(renderer, texture, &src_box,
- dst_box, matrix, deco_data);
-}
-
-void fx_render_rect(struct fx_renderer *renderer, const struct wlr_box *box,
- const float color[static 4], const float projection[static 9]) {
- if (box->width == 0 || box->height == 0) {
- return;
- }
- assert(box->width > 0 && box->height > 0);
- float matrix[9];
- wlr_matrix_project_box(matrix, box, WL_OUTPUT_TRANSFORM_NORMAL, 0, projection);
-
- float gl_matrix[9];
- wlr_matrix_multiply(gl_matrix, renderer->projection, matrix);
-
- // TODO: investigate why matrix is flipped prior to this cmd
- // wlr_matrix_multiply(gl_matrix, flip_180, gl_matrix);
-
- wlr_matrix_transpose(gl_matrix, gl_matrix);
-
- if (color[3] == 1.0) {
- glDisable(GL_BLEND);
- } else {
- glEnable(GL_BLEND);
- }
-
- struct quad_shader shader = renderer->shaders.quad;
- glUseProgram(shader.program);
-
- glUniformMatrix3fv(shader.proj, 1, GL_FALSE, gl_matrix);
- glUniform4f(shader.color, color[0], color[1], color[2], color[3]);
-
- glVertexAttribPointer(shader.pos_attrib, 2, GL_FLOAT, GL_FALSE,
- 0, verts);
-
- glEnableVertexAttribArray(shader.pos_attrib);
-
- glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
-
- glDisableVertexAttribArray(shader.pos_attrib);
-}
-
-void fx_render_rounded_rect(struct fx_renderer *renderer, const struct wlr_box *box,
- const float color[static 4], const float matrix[static 9], int radius,
- enum corner_location corner_location) {
- if (box->width == 0 || box->height == 0) {
- return;
- }
- assert(box->width > 0 && box->height > 0);
-
- // Fixes corner radii not being "round" when the radii is larger than
- // the height/width
- int min_size = MIN(box->height, box->width) * 0.5;
- if (radius > min_size) {
- radius = min_size;
- }
-
- struct rounded_quad_shader *shader = NULL;
-
- switch (corner_location) {
- case ALL:
- shader = &renderer->shaders.rounded_quad;
- break;
- case TOP_LEFT:
- shader = &renderer->shaders.rounded_tl_quad;
- break;
- case TOP_RIGHT:
- shader = &renderer->shaders.rounded_tr_quad;
- break;
- case BOTTOM_LEFT:
- shader = &renderer->shaders.rounded_bl_quad;
- break;
- case BOTTOM_RIGHT:
- shader = &renderer->shaders.rounded_br_quad;
- break;
- default:
- sway_log(SWAY_ERROR, "Invalid Corner Location. Aborting render");
- abort();
- }
-
- float gl_matrix[9];
- wlr_matrix_multiply(gl_matrix, renderer->projection, matrix);
-
- // TODO: investigate why matrix is flipped prior to this cmd
- // wlr_matrix_multiply(gl_matrix, flip_180, gl_matrix);
-
- wlr_matrix_transpose(gl_matrix, gl_matrix);
-
- glEnable(GL_BLEND);
-
- glUseProgram(shader->program);
-
- glUniformMatrix3fv(shader->proj, 1, GL_FALSE, gl_matrix);
- glUniform4f(shader->color, color[0], color[1], color[2], color[3]);
-
- // rounded corners
- glUniform2f(shader->size, box->width, box->height);
- glUniform2f(shader->position, box->x, box->y);
- glUniform1f(shader->radius, radius);
-
- glVertexAttribPointer(shader->pos_attrib, 2, GL_FLOAT, GL_FALSE,
- 0, verts);
-
- glEnableVertexAttribArray(shader->pos_attrib);
-
- glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
-
- glDisableVertexAttribArray(shader->pos_attrib);
-}
-
-void fx_render_border_corner(struct fx_renderer *renderer, const struct wlr_box *box,
- const float color[static 4], const float matrix[static 9],
- enum corner_location corner_location, int radius, int border_thickness) {
- if (border_thickness == 0 || box->width == 0 || box->height == 0) {
- return;
- }
- assert(box->width > 0 && box->height > 0);
-
- // Fixes corner radii not being "round" when the radii is larger than
- // the height/width
- int min_size = MIN(box->height, box->width) * 0.5;
- if (radius > min_size) {
- radius = min_size;
- }
-
- float gl_matrix[9];
- wlr_matrix_multiply(gl_matrix, renderer->projection, matrix);
-
- // TODO: investigate why matrix is flipped prior to this cmd
- // wlr_matrix_multiply(gl_matrix, flip_180, gl_matrix);
-
- wlr_matrix_transpose(gl_matrix, gl_matrix);
-
- if (color[3] == 1.0 && !radius) {
- glDisable(GL_BLEND);
- } else {
- glEnable(GL_BLEND);
- }
-
- struct corner_shader shader = renderer->shaders.corner;
-
- glUseProgram(shader.program);
-
- glUniformMatrix3fv(shader.proj, 1, GL_FALSE, gl_matrix);
- glUniform4f(shader.color, color[0], color[1], color[2], color[3]);
-
- glUniform1f(shader.is_top_left, corner_location == TOP_LEFT);
- glUniform1f(shader.is_top_right, corner_location == TOP_RIGHT);
- glUniform1f(shader.is_bottom_left, corner_location == BOTTOM_LEFT);
- glUniform1f(shader.is_bottom_right, corner_location == BOTTOM_RIGHT);
-
- glUniform2f(shader.position, box->x, box->y);
- glUniform1f(shader.radius, radius);
- glUniform2f(shader.half_size, box->width / 2.0, box->height / 2.0);
- glUniform1f(shader.half_thickness, border_thickness / 2.0);
-
- glVertexAttribPointer(shader.pos_attrib, 2, GL_FLOAT, GL_FALSE,
- 0, verts);
-
- glEnableVertexAttribArray(shader.pos_attrib);
-
- glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
-
- glDisableVertexAttribArray(shader.pos_attrib);
-}
-
-void fx_render_stencil_mask(struct fx_renderer *renderer, const struct wlr_box *box,
- const float matrix[static 9], int corner_radius) {
- if (box->width == 0 || box->height == 0) {
- return;
- }
- assert(box->width > 0 && box->height > 0);
-
- // Fixes corner radii not being "round" when the radii is larger than
- // the height/width
- int min_size = MIN(box->height, box->width) * 0.5;
- if (corner_radius > min_size) {
- corner_radius = min_size;
- }
-
- // TODO: just pass gl_matrix?
- float gl_matrix[9];
- wlr_matrix_multiply(gl_matrix, renderer->projection, matrix);
-
- // TODO: investigate why matrix is flipped prior to this cmd
- // wlr_matrix_multiply(gl_matrix, flip_180, gl_matrix);
-
- wlr_matrix_transpose(gl_matrix, gl_matrix);
-
- glEnable(GL_BLEND);
-
- struct stencil_mask_shader shader = renderer->shaders.stencil_mask;
-
- glUseProgram(shader.program);
-
- glUniformMatrix3fv(shader.proj, 1, GL_FALSE, gl_matrix);
-
- glUniform2f(shader.half_size, box->width * 0.5, box->height * 0.5);
- glUniform2f(shader.position, box->x, box->y);
- glUniform1f(shader.radius, corner_radius);
-
- glVertexAttribPointer(shader.pos_attrib, 2, GL_FLOAT, GL_FALSE,
- 0, verts);
-
- glEnableVertexAttribArray(shader.pos_attrib);
-
- glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
-
- glDisableVertexAttribArray(shader.pos_attrib);
-}
-
-// TODO: alpha input arg?
-void fx_render_box_shadow(struct fx_renderer *renderer, const struct wlr_box *box,
- const struct wlr_box *inner_box, const float color[static 4],
- const float matrix[static 9], int corner_radius, float blur_sigma) {
- if (box->width == 0 || box->height == 0) {
- return;
- }
- assert(box->width > 0 && box->height > 0);
-
- // Fixes corner radii not being "round" when the radii is larger than
- // the height/width
- int min_size = MIN(box->height, box->width) * 0.5;
- if (corner_radius > min_size) {
- corner_radius = min_size;
- }
-
- float gl_matrix[9];
- wlr_matrix_multiply(gl_matrix, renderer->projection, matrix);
-
- // TODO: investigate why matrix is flipped prior to this cmd
- // wlr_matrix_multiply(gl_matrix, flip_180, gl_matrix);
-
- wlr_matrix_transpose(gl_matrix, gl_matrix);
-
- fx_renderer_stencil_mask_init();
- // Draw the rounded rect as a mask
- fx_render_stencil_mask(renderer, inner_box, matrix, corner_radius);
- fx_renderer_stencil_mask_close(false);
-
- // blending will practically always be needed (unless we have a madman
- // who uses opaque shadows with zero sigma), so just enable it
- glEnable(GL_BLEND);
-
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-
- struct box_shadow_shader shader = renderer->shaders.box_shadow;
-
- glUseProgram(shader.program);
-
- glUniformMatrix3fv(shader.proj, 1, GL_FALSE, gl_matrix);
- glUniform4f(shader.color, color[0], color[1], color[2], color[3]);
- glUniform1f(shader.blur_sigma, blur_sigma);
- glUniform1f(shader.corner_radius, corner_radius);
-
- glUniform2f(shader.size, box->width, box->height);
- glUniform2f(shader.position, box->x, box->y);
-
- glVertexAttribPointer(shader.pos_attrib, 2, GL_FLOAT, GL_FALSE,
- 0, verts);
-
- glEnableVertexAttribArray(shader.pos_attrib);
-
- glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
-
- glDisableVertexAttribArray(shader.pos_attrib);
-
- glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
-
- fx_renderer_stencil_mask_fini();
-}
-
-void fx_render_blur(struct fx_renderer *renderer, const float matrix[static 9],
- struct fx_framebuffer **buffer, struct blur_shader *shader,
- const struct wlr_box *box, int blur_radius) {
- glDisable(GL_BLEND);
- glDisable(GL_STENCIL_TEST);
-
- glActiveTexture(GL_TEXTURE0);
-
- glBindTexture((*buffer)->texture.target, (*buffer)->texture.id);
-
- glTexParameteri((*buffer)->texture.target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
-
- glUseProgram(shader->program);
-
- // OpenGL ES 2 requires the glUniformMatrix3fv transpose parameter to be set
- // to GL_FALSE
- float gl_matrix[9];
- wlr_matrix_transpose(gl_matrix, matrix);
- glUniformMatrix3fv(shader->proj, 1, GL_FALSE, gl_matrix);
-
- glUniform1i(shader->tex, 0);
- glUniform1f(shader->radius, blur_radius);
-
- if (shader == &renderer->shaders.blur1) {
- glUniform2f(shader->halfpixel, 0.5f / (renderer->viewport_width / 2.0f), 0.5f / (renderer->viewport_height / 2.0f));
- } else {
- glUniform2f(shader->halfpixel, 0.5f / (renderer->viewport_width * 2.0f), 0.5f / (renderer->viewport_height * 2.0f));
- }
-
- glVertexAttribPointer(shader->pos_attrib, 2, GL_FLOAT, GL_FALSE, 0, verts);
- glVertexAttribPointer(shader->tex_attrib, 2, GL_FLOAT, GL_FALSE, 0, verts);
-
- glEnableVertexAttribArray(shader->pos_attrib);
- glEnableVertexAttribArray(shader->tex_attrib);
-
- glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
-
- glDisableVertexAttribArray(shader->pos_attrib);
- glDisableVertexAttribArray(shader->tex_attrib);
-
-}
-
-void fx_render_blur_effects(struct fx_renderer *renderer, const float matrix[static 9],
- struct fx_framebuffer **buffer, float blur_noise, float blur_brightness,
- float blur_contrast, float blur_saturation) {
- struct effects_shader shader = renderer->shaders.blur_effects;
-
- glActiveTexture(GL_TEXTURE0);
- glBindTexture((*buffer)->texture.target, (*buffer)->texture.id);
- glTexParameteri((*buffer)->texture.target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
-
- glUseProgram(shader.program);
-
- // OpenGL ES 2 requires the glUniformMatrix3fv transpose parameter to be set
- // to GL_FALSE
- float gl_matrix[9];
- wlr_matrix_transpose(gl_matrix, matrix);
- glUniformMatrix3fv(shader.proj, 1, GL_FALSE, gl_matrix);
-
- glUniform1i(shader.tex, 0);
- glUniform1f(shader.noise, blur_noise);
- glUniform1f(shader.brightness, blur_brightness);
- glUniform1f(shader.contrast, blur_contrast);
- glUniform1f(shader.saturation, blur_saturation);
-
- glVertexAttribPointer(shader.pos_attrib, 2, GL_FLOAT, GL_FALSE, 0, verts);
- glVertexAttribPointer(shader.tex_attrib, 2, GL_FLOAT, GL_FALSE, 0, verts);
-
- glEnableVertexAttribArray(shader.pos_attrib);
- glEnableVertexAttribArray(shader.tex_attrib);
-
- glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
-
- glDisableVertexAttribArray(shader.pos_attrib);
- glDisableVertexAttribArray(shader.tex_attrib);
-}
diff --git a/sway/desktop/fx_renderer/fx_stencilbuffer.c b/sway/desktop/fx_renderer/fx_stencilbuffer.c
deleted file mode 100644
index 5b99ff79..00000000
--- a/sway/desktop/fx_renderer/fx_stencilbuffer.c
+++ /dev/null
@@ -1,21 +0,0 @@
-#include <assert.h>
-#include <wlr/render/gles2.h>
-
-#include "sway/desktop/fx_renderer/fx_stencilbuffer.h"
-
-struct fx_stencilbuffer fx_stencilbuffer_create() {
- return (struct fx_stencilbuffer) {
- .rb = -1,
- .width = -1,
- .height = -1,
- };
-}
-
-void fx_stencilbuffer_release(struct fx_stencilbuffer *stencil_buffer) {
- if (stencil_buffer->rb != (uint32_t) -1 && stencil_buffer->rb) {
- glDeleteRenderbuffers(1, &stencil_buffer->rb);
- }
- stencil_buffer->rb = -1;
- stencil_buffer->width = -1;
- stencil_buffer->height = -1;
-}
diff --git a/sway/desktop/fx_renderer/fx_texture.c b/sway/desktop/fx_renderer/fx_texture.c
deleted file mode 100644
index cc5d14c8..00000000
--- a/sway/desktop/fx_renderer/fx_texture.c
+++ /dev/null
@@ -1,37 +0,0 @@
-#include <assert.h>
-#include <wlr/render/gles2.h>
-
-#include "sway/desktop/fx_renderer/fx_texture.h"
-
-struct fx_texture fx_texture_create() {
- return (struct fx_texture) {
- .id = 0,
- .target = 0,
- .width = -1,
- .height = -1,
- };
-}
-
-struct fx_texture fx_texture_from_wlr_texture(struct wlr_texture *texture) {
- assert(wlr_texture_is_gles2(texture));
-
- struct wlr_gles2_texture_attribs texture_attrs;
- wlr_gles2_texture_get_attribs(texture, &texture_attrs);
-
- return (struct fx_texture) {
- .target = texture_attrs.target,
- .id = texture_attrs.tex,
- .has_alpha = texture_attrs.has_alpha,
- .width = texture->width,
- .height = texture->height,
- };
-}
-
-void fx_texture_release(struct fx_texture *texture) {
- if (texture->id) {
- glDeleteTextures(1, &texture->id);
- }
- texture->id = 0;
- texture->width = -1;
- texture->height = -1;
-}
diff --git a/sway/desktop/fx_renderer/matrix.c b/sway/desktop/fx_renderer/matrix.c
deleted file mode 100644
index 9c9dabec..00000000
--- a/sway/desktop/fx_renderer/matrix.c
+++ /dev/null
@@ -1,70 +0,0 @@
-#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;
-}
diff --git a/sway/desktop/fx_renderer/shaders/blur1.frag b/sway/desktop/fx_renderer/shaders/blur1.frag
deleted file mode 100644
index e7cb1be8..00000000
--- a/sway/desktop/fx_renderer/shaders/blur1.frag
+++ /dev/null
@@ -1,18 +0,0 @@
-precision mediump float;
-varying mediump vec2 v_texcoord;
-uniform sampler2D tex;
-
-uniform float radius;
-uniform vec2 halfpixel;
-
-void main() {
- vec2 uv = v_texcoord * 2.0;
-
- vec4 sum = texture2D(tex, uv) * 4.0;
- sum += texture2D(tex, uv - halfpixel.xy * radius);
- sum += texture2D(tex, uv + halfpixel.xy * radius);
- sum += texture2D(tex, uv + vec2(halfpixel.x, -halfpixel.y) * radius);
- sum += texture2D(tex, uv - vec2(halfpixel.x, -halfpixel.y) * radius);
-
- gl_FragColor = sum / 8.0;
-}
diff --git a/sway/desktop/fx_renderer/shaders/blur2.frag b/sway/desktop/fx_renderer/shaders/blur2.frag
deleted file mode 100644
index 3755a294..00000000
--- a/sway/desktop/fx_renderer/shaders/blur2.frag
+++ /dev/null
@@ -1,22 +0,0 @@
-precision mediump float;
-varying mediump vec2 v_texcoord;
-uniform sampler2D tex;
-
-uniform float radius;
-uniform vec2 halfpixel;
-
-void main() {
- vec2 uv = v_texcoord / 2.0;
-
- vec4 sum = texture2D(tex, uv + vec2(-halfpixel.x * 2.0, 0.0) * radius);
-
- sum += texture2D(tex, uv + vec2(-halfpixel.x, halfpixel.y) * radius) * 2.0;
- sum += texture2D(tex, uv + vec2(0.0, halfpixel.y * 2.0) * radius);
- sum += texture2D(tex, uv + vec2(halfpixel.x, halfpixel.y) * radius) * 2.0;
- sum += texture2D(tex, uv + vec2(halfpixel.x * 2.0, 0.0) * radius);
- sum += texture2D(tex, uv + vec2(halfpixel.x, -halfpixel.y) * radius) * 2.0;
- sum += texture2D(tex, uv + vec2(0.0, -halfpixel.y * 2.0) * radius);
- sum += texture2D(tex, uv + vec2(-halfpixel.x, -halfpixel.y) * radius) * 2.0;
-
- gl_FragColor = sum / 12.0;
-}
diff --git a/sway/desktop/fx_renderer/shaders/blur_effects.frag b/sway/desktop/fx_renderer/shaders/blur_effects.frag
deleted file mode 100644
index 2fc16c15..00000000
--- a/sway/desktop/fx_renderer/shaders/blur_effects.frag
+++ /dev/null
@@ -1,54 +0,0 @@
-precision mediump float;
-varying vec2 v_texcoord;
-uniform sampler2D tex;
-
-uniform float noise;
-uniform float brightness;
-uniform float contrast;
-uniform float saturation;
-
-mat4 brightnessMatrix() {
- float b = brightness - 1.0;
- return mat4(1, 0, 0, 0,
- 0, 1, 0, 0,
- 0, 0, 1, 0,
- b, b, b, 1);
-}
-
-mat4 contrastMatrix() {
- float t = (1.0 - contrast) / 2.0;
- return mat4(contrast, 0, 0, 0,
- 0, contrast, 0, 0,
- 0, 0, contrast, 0,
- t, t, t, 1);
-}
-
-mat4 saturationMatrix() {
- vec3 luminance = vec3(0.3086, 0.6094, 0.0820);
- float oneMinusSat = 1.0 - saturation;
- vec3 red = vec3(luminance.x * oneMinusSat);
- red+= vec3(saturation, 0, 0);
- vec3 green = vec3(luminance.y * oneMinusSat);
- green += vec3(0, saturation, 0);
- vec3 blue = vec3(luminance.z * oneMinusSat);
- blue += vec3(0, 0, saturation);
- return mat4(red, 0,
- green, 0,
- blue, 0,
- 0, 0, 0, 1);
-}
-
-// Fast generative noise function
-float hash(vec2 p) {
- return fract(sin(dot(p, vec2(12.9898, 78.233))) * 43758.5453);
-}
-
-void main() {
- vec4 color = texture2D(tex, v_texcoord);
- color *= brightnessMatrix() * contrastMatrix() * saturationMatrix();
- float noiseHash = hash(v_texcoord);
- float noiseAmount = (mod(noiseHash, 1.0) - 0.5);
- color.rgb += noiseAmount * noise;
-
- gl_FragColor = color;
-}
diff --git a/sway/desktop/fx_renderer/shaders/box_shadow.frag b/sway/desktop/fx_renderer/shaders/box_shadow.frag
deleted file mode 100644
index c9b2b91f..00000000
--- a/sway/desktop/fx_renderer/shaders/box_shadow.frag
+++ /dev/null
@@ -1,74 +0,0 @@
-// Writeup: https://madebyevan.com/shaders/fast-rounded-rectangle-shadows/
-
-precision mediump float;
-varying vec4 v_color;
-varying vec2 v_texcoord;
-
-uniform vec2 position;
-uniform vec2 size;
-uniform float blur_sigma;
-uniform float corner_radius;
-
-float gaussian(float x, float sigma) {
- const float pi = 3.141592653589793;
- return exp(-(x * x) / (2.0 * sigma * sigma)) / (sqrt(2.0 * pi) * sigma);
-}
-
-// approximates the error function, needed for the gaussian integral
-vec2 erf(vec2 x) {
- vec2 s = sign(x), a = abs(x);
- x = 1.0 + (0.278393 + (0.230389 + 0.078108 * (a * a)) * a) * a;
- x *= x;
- return s - s / (x * x);
-}
-
-// return the blurred mask along the x dimension
-float roundedBoxShadowX(float x, float y, float sigma, float corner, vec2 halfSize) {
- float delta = min(halfSize.y - corner - abs(y), 0.0);
- float curved = halfSize.x - corner + sqrt(max(0.0, corner * corner - delta * delta));
- vec2 integral = 0.5 + 0.5 * erf((x + vec2(-curved, curved)) * (sqrt(0.5) / sigma));
- return integral.y - integral.x;
-}
-
-// return the mask for the shadow of a box from lower to upper
-float roundedBoxShadow(vec2 lower, vec2 upper, vec2 point, float sigma, float corner_radius) {
- // Center everything to make the math easier
- vec2 center = (lower + upper) * 0.5;
- vec2 halfSize = (upper - lower) * 0.5;
- point -= center;
-
- // The signal is only non-zero in a limited range, so don't waste samples
- float low = point.y - halfSize.y;
- float high = point.y + halfSize.y;
- float start = clamp(-3.0 * sigma, low, high);
- float end = clamp(3.0 * sigma, low, high);
-
- // Accumulate samples (we can get away with surprisingly few samples)
- float step = (end - start) / 4.0;
- float y = start + step * 0.5;
- float value = 0.0;
- for (int i = 0; i < 4; i++) {
- value += roundedBoxShadowX(point.x, point.y - y, sigma, corner_radius, halfSize) * gaussian(y, sigma) * step;
- y += step;
- }
-
- return value;
-}
-
-// per-pixel "random" number between 0 and 1
-float random() {
- return fract(sin(dot(vec2(12.9898, 78.233), gl_FragCoord.xy)) * 43758.5453);
-}
-
-void main() {
- float frag_alpha = v_color.a * roundedBoxShadow(
- position + blur_sigma,
- position + size - blur_sigma,
- gl_FragCoord.xy, blur_sigma * 0.5,
- corner_radius);
-
- // dither the alpha to break up color bands
- frag_alpha += (random() - 0.5) / 128.0;
-
- gl_FragColor = vec4(v_color.rgb, frag_alpha);
-}
diff --git a/sway/desktop/fx_renderer/shaders/common.vert b/sway/desktop/fx_renderer/shaders/common.vert
deleted file mode 100644
index 811e0f2d..00000000
--- a/sway/desktop/fx_renderer/shaders/common.vert
+++ /dev/null
@@ -1,12 +0,0 @@
-uniform mat3 proj;
-uniform vec4 color;
-attribute vec2 pos;
-attribute vec2 texcoord;
-varying vec4 v_color;
-varying vec2 v_texcoord;
-
-void main() {
- gl_Position = vec4(proj * vec3(pos, 1.0), 1.0);
- v_color = color;
- v_texcoord = texcoord;
-}
diff --git a/sway/desktop/fx_renderer/shaders/corner.frag b/sway/desktop/fx_renderer/shaders/corner.frag
deleted file mode 100644
index 7699299a..00000000
--- a/sway/desktop/fx_renderer/shaders/corner.frag
+++ /dev/null
@@ -1,36 +0,0 @@
-precision mediump float;
-varying vec4 v_color;
-varying vec2 v_texcoord;
-
-uniform bool is_top_left;
-uniform bool is_top_right;
-uniform bool is_bottom_left;
-uniform bool is_bottom_right;
-
-uniform vec2 position;
-uniform float radius;
-uniform vec2 half_size;
-uniform float half_thickness;
-
-float roundedBoxSDF(vec2 center, vec2 size, float radius) {
- return length(max(abs(center) - size + radius, 0.0)) - radius;
-}
-
-void main() {
- vec2 center = gl_FragCoord.xy - position - half_size;
- float distance = roundedBoxSDF(center, half_size - half_thickness, radius + half_thickness);
- float smoothedAlphaOuter = 1.0 - smoothstep(-1.0, 1.0, distance - half_thickness);
- // Create an inner circle that isn't as anti-aliased as the outer ring
- float smoothedAlphaInner = 1.0 - smoothstep(-1.0, 0.5, distance + half_thickness);
- gl_FragColor = mix(vec4(0), v_color, smoothedAlphaOuter - smoothedAlphaInner);
-
- if (is_top_left && (center.y > 0.0 || center.x > 0.0)) {
- discard;
- } else if (is_top_right && (center.y > 0.0 || center.x < 0.0)) {
- discard;
- } else if (is_bottom_left && (center.y < 0.0 || center.x > 0.0)) {
- discard;
- } else if (is_bottom_right && (center.y < 0.0 || center.x < 0.0)) {
- discard;
- }
-}
diff --git a/sway/desktop/fx_renderer/shaders/embed.sh b/sway/desktop/fx_renderer/shaders/embed.sh
deleted file mode 100644
index 47f07892..00000000
--- a/sway/desktop/fx_renderer/shaders/embed.sh
+++ /dev/null
@@ -1,11 +0,0 @@
-#!/bin/sh -eu
-
-var=${1:-data}
-hex="$(od -A n -t x1 -v)"
-
-echo "static const char $var[] = {"
-for byte in $hex; do
- echo " 0x$byte,"
-done
-echo " 0x00,"
-echo "};"
diff --git a/sway/desktop/fx_renderer/shaders/meson.build b/sway/desktop/fx_renderer/shaders/meson.build
deleted file mode 100644
index 19f76dc2..00000000
--- a/sway/desktop/fx_renderer/shaders/meson.build
+++ /dev/null
@@ -1,27 +0,0 @@
-embed = find_program('./embed.sh', native: true)
-
-shaders = [
- 'blur1.frag',
- 'blur2.frag',
- 'blur_effects.frag',
- 'box_shadow.frag',
- 'common.vert',
- 'corner.frag',
- 'quad.frag',
- 'quad_round.frag',
- 'stencil_mask.frag',
- 'tex.frag',
-]
-
-foreach name : shaders
- output = name.underscorify() + '_src.h'
- var = name.underscorify() + '_src'
- sway_sources += custom_target(
- output,
- command: [embed, var],
- input: name,
- output: output,
- feed: true,
- capture: true,
- )
-endforeach
diff --git a/sway/desktop/fx_renderer/shaders/quad.frag b/sway/desktop/fx_renderer/shaders/quad.frag
deleted file mode 100644
index 7c763272..00000000
--- a/sway/desktop/fx_renderer/shaders/quad.frag
+++ /dev/null
@@ -1,7 +0,0 @@
-precision mediump float;
-varying vec4 v_color;
-varying vec2 v_texcoord;
-
-void main() {
- gl_FragColor = v_color;
-}
diff --git a/sway/desktop/fx_renderer/shaders/quad_round.frag b/sway/desktop/fx_renderer/shaders/quad_round.frag
deleted file mode 100644
index 02e99028..00000000
--- a/sway/desktop/fx_renderer/shaders/quad_round.frag
+++ /dev/null
@@ -1,39 +0,0 @@
-#define SOURCE_QUAD_ROUND 1
-#define SOURCE_QUAD_ROUND_TOP_LEFT 2
-#define SOURCE_QUAD_ROUND_TOP_RIGHT 3
-#define SOURCE_QUAD_ROUND_BOTTOM_RIGHT 4
-#define SOURCE_QUAD_ROUND_BOTTOM_LEFT 5
-
-#if !defined(SOURCE)
-#error "Missing shader preamble"
-#endif
-
-precision mediump float;
-varying vec4 v_color;
-varying vec2 v_texcoord;
-
-uniform vec2 size;
-uniform vec2 position;
-uniform float radius;
-
-vec2 getCornerDist() {
-#if SOURCE == SOURCE_QUAD_ROUND
- vec2 half_size = size * 0.5;
- return abs(gl_FragCoord.xy - position - half_size) - half_size + radius;
-#elif SOURCE == SOURCE_QUAD_ROUND_TOP_LEFT
- return abs(gl_FragCoord.xy - position - size) - size + radius;
-#elif SOURCE == SOURCE_QUAD_ROUND_TOP_RIGHT
- return abs(gl_FragCoord.xy - position - vec2(0, size.y)) - size + radius;
-#elif SOURCE == SOURCE_QUAD_ROUND_BOTTOM_RIGHT
- return abs(gl_FragCoord.xy - position) - size + radius;
-#elif SOURCE == SOURCE_QUAD_ROUND_BOTTOM_LEFT
- return abs(gl_FragCoord.xy - position - vec2(size.x, 0)) - size + radius;
-#endif
-}
-
-void main() {
- vec2 q = getCornerDist();
- float dist = min(max(q.x,q.y), 0.0) + length(max(q, 0.0)) - radius;
- float smoothedAlpha = 1.0 - smoothstep(-1.0, 0.5, dist);
- gl_FragColor = mix(vec4(0), v_color, smoothedAlpha);
-}
diff --git a/sway/desktop/fx_renderer/shaders/stencil_mask.frag b/sway/desktop/fx_renderer/shaders/stencil_mask.frag
deleted file mode 100644
index ee033070..00000000
--- a/sway/desktop/fx_renderer/shaders/stencil_mask.frag
+++ /dev/null
@@ -1,17 +0,0 @@
-precision mediump float;
-varying vec2 v_texcoord;
-
-uniform vec2 half_size;
-uniform vec2 position;
-uniform float radius;
-
-void main() {
- vec2 q = abs(gl_FragCoord.xy - position - half_size) - half_size + radius;
- float dist = min(max(q.x,q.y), 0.0) + length(max(q, 0.0)) - radius;
- float smoothedAlpha = 1.0 - smoothstep(-1.0, 0.5, dist);
- gl_FragColor = mix(vec4(0.0), vec4(1.0), smoothedAlpha);
-
- if (gl_FragColor.a < 1.0) {
- discard;
- }
-}
diff --git a/sway/desktop/fx_renderer/shaders/tex.frag b/sway/desktop/fx_renderer/shaders/tex.frag
deleted file mode 100644
index 77501887..00000000
--- a/sway/desktop/fx_renderer/shaders/tex.frag
+++ /dev/null
@@ -1,67 +0,0 @@
-#define SOURCE_TEXTURE_RGBA 1
-#define SOURCE_TEXTURE_RGBX 2
-#define SOURCE_TEXTURE_EXTERNAL 3
-
-#if !defined(SOURCE)
-#error "Missing shader preamble"
-#endif
-
-#if SOURCE == SOURCE_TEXTURE_EXTERNAL
-#extension GL_OES_EGL_image_external : require
-#endif
-
-precision mediump float;
-
-varying vec2 v_texcoord;
-
-#if SOURCE == SOURCE_TEXTURE_EXTERNAL
-uniform samplerExternalOES tex;
-#elif SOURCE == SOURCE_TEXTURE_RGBA || SOURCE == SOURCE_TEXTURE_RGBX
-uniform sampler2D tex;
-#endif
-
-uniform float alpha;
-uniform float dim;
-uniform vec4 dim_color;
-uniform vec2 size;
-uniform vec2 position;
-uniform float radius;
-uniform float saturation;
-uniform bool has_titlebar;
-uniform bool discard_transparent;
-
-const vec3 saturation_weight = vec3(0.2125, 0.7154, 0.0721);
-
-vec4 sample_texture() {
-#if SOURCE == SOURCE_TEXTURE_RGBA || SOURCE == SOURCE_TEXTURE_EXTERNAL
- return texture2D(tex, v_texcoord);
-#elif SOURCE == SOURCE_TEXTURE_RGBX
- return vec4(texture2D(tex, v_texcoord).rgb, 1.0);
-#endif
-}
-
-void main() {
- vec4 color = sample_texture();
- // Saturation
- if (saturation != 1.0) {
- vec4 pixColor = texture2D(tex, v_texcoord);
- vec3 irgb = pixColor.rgb;
- vec3 target = vec3(dot(irgb, saturation_weight));
- color = vec4(mix(target, irgb, saturation), pixColor.a);
- }
- // Dimming
- gl_FragColor = mix(color, dim_color, dim) * alpha;
-
- if (!has_titlebar || gl_FragCoord.y - position.y > radius) {
- vec2 corner_distance = min(gl_FragCoord.xy - position, size + position - gl_FragCoord.xy);
- if (max(corner_distance.x, corner_distance.y) < radius) {
- float d = radius - distance(corner_distance, vec2(radius));
- float smooth = smoothstep(-1.0, 0.5, d);
- gl_FragColor = mix(vec4(0), gl_FragColor, smooth);
- }
- }
-
- if (discard_transparent && gl_FragColor.a == 0.0) {
- discard;
- }
-}