2022-08-13 16:14:23 +10:00
|
|
|
#ifndef _SWAY_OPENGL_H
|
|
|
|
#define _SWAY_OPENGL_H
|
|
|
|
|
|
|
|
#include <GLES2/gl2.h>
|
2022-11-12 13:21:51 +11:00
|
|
|
#include <GLES2/gl2ext.h>
|
2022-10-10 02:47:34 +11:00
|
|
|
#include <stdbool.h>
|
2023-04-24 14:11:55 +10:00
|
|
|
#include <wlr/render/egl.h>
|
2022-10-10 02:47:34 +11:00
|
|
|
|
2023-04-18 07:24:48 +10:00
|
|
|
#include "sway/desktop/fx_renderer/fx_framebuffer.h"
|
|
|
|
#include "sway/desktop/fx_renderer/fx_texture.h"
|
|
|
|
|
2023-04-28 08:50:36 +10:00
|
|
|
enum corner_location { TOP_LEFT, TOP_RIGHT, BOTTOM_RIGHT, BOTTOM_LEFT, ALL, NONE };
|
2022-08-13 16:14:23 +10:00
|
|
|
|
2023-04-04 10:16:54 +10:00
|
|
|
enum fx_tex_shader_source {
|
|
|
|
SHADER_SOURCE_TEXTURE_RGBA = 1,
|
|
|
|
SHADER_SOURCE_TEXTURE_RGBX = 2,
|
|
|
|
SHADER_SOURCE_TEXTURE_EXTERNAL = 3,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum fx_rounded_quad_shader_source {
|
|
|
|
SHADER_SOURCE_QUAD_ROUND = 1,
|
|
|
|
SHADER_SOURCE_QUAD_ROUND_TOP_LEFT = 2,
|
|
|
|
SHADER_SOURCE_QUAD_ROUND_TOP_RIGHT = 3,
|
2023-04-28 08:50:36 +10:00
|
|
|
SHADER_SOURCE_QUAD_ROUND_BOTTOM_RIGHT = 4,
|
|
|
|
SHADER_SOURCE_QUAD_ROUND_BOTTOM_LEFT = 5,
|
2023-03-18 16:03:02 +11:00
|
|
|
};
|
|
|
|
|
2022-11-24 15:37:35 +11:00
|
|
|
struct decoration_data {
|
|
|
|
float alpha;
|
|
|
|
float saturation;
|
|
|
|
int corner_radius;
|
2022-12-07 16:10:11 +11:00
|
|
|
float dim;
|
2023-04-18 07:24:48 +10:00
|
|
|
float *dim_color;
|
2022-11-24 15:37:35 +11:00
|
|
|
bool has_titlebar;
|
2023-09-21 11:35:49 +10:00
|
|
|
bool discard_transparent;
|
2023-04-18 07:24:48 +10:00
|
|
|
bool blur;
|
2023-05-20 05:14:06 +10:00
|
|
|
bool shadow;
|
2022-11-24 15:37:35 +11:00
|
|
|
};
|
|
|
|
|
2023-05-01 03:03:09 +10:00
|
|
|
struct blur_shader {
|
2022-08-13 16:14:23 +10:00
|
|
|
GLuint program;
|
|
|
|
GLint proj;
|
|
|
|
GLint tex;
|
|
|
|
GLint pos_attrib;
|
|
|
|
GLint tex_attrib;
|
2023-05-01 03:03:09 +10:00
|
|
|
GLint radius;
|
|
|
|
GLint halfpixel;
|
|
|
|
};
|
|
|
|
|
2024-01-04 04:38:44 +11:00
|
|
|
struct effects_shader {
|
|
|
|
GLuint program;
|
|
|
|
GLint proj;
|
|
|
|
GLint tex;
|
|
|
|
GLint pos_attrib;
|
|
|
|
GLint tex_attrib;
|
|
|
|
GLfloat noise;
|
|
|
|
GLfloat brightness;
|
|
|
|
GLfloat contrast;
|
|
|
|
GLfloat saturation;
|
|
|
|
};
|
|
|
|
|
2023-05-01 03:03:09 +10:00
|
|
|
struct box_shadow_shader {
|
|
|
|
GLuint program;
|
|
|
|
GLint proj;
|
|
|
|
GLint color;
|
|
|
|
GLint pos_attrib;
|
|
|
|
GLint position;
|
2022-10-26 17:48:49 +11:00
|
|
|
GLint size;
|
2023-05-01 03:03:09 +10:00
|
|
|
GLint blur_sigma;
|
|
|
|
GLint corner_radius;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct corner_shader {
|
|
|
|
GLuint program;
|
|
|
|
GLint proj;
|
|
|
|
GLint color;
|
|
|
|
GLint pos_attrib;
|
|
|
|
GLint is_top_left;
|
|
|
|
GLint is_top_right;
|
|
|
|
GLint is_bottom_left;
|
|
|
|
GLint is_bottom_right;
|
2022-08-30 08:25:11 +10:00
|
|
|
GLint position;
|
|
|
|
GLint radius;
|
2023-05-01 03:03:09 +10:00
|
|
|
GLint half_size;
|
|
|
|
GLint half_thickness;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct quad_shader {
|
|
|
|
GLuint program;
|
|
|
|
GLint proj;
|
|
|
|
GLint color;
|
|
|
|
GLint pos_attrib;
|
2022-11-11 17:19:02 +11:00
|
|
|
};
|
|
|
|
|
|
|
|
struct rounded_quad_shader {
|
|
|
|
GLuint program;
|
|
|
|
GLint proj;
|
|
|
|
GLint color;
|
|
|
|
GLint pos_attrib;
|
|
|
|
GLint size;
|
|
|
|
GLint position;
|
|
|
|
GLint radius;
|
2022-08-13 16:14:23 +10:00
|
|
|
};
|
|
|
|
|
2023-05-01 03:03:09 +10:00
|
|
|
struct stencil_mask_shader {
|
|
|
|
GLuint program;
|
|
|
|
GLint proj;
|
|
|
|
GLint color;
|
|
|
|
GLint pos_attrib;
|
|
|
|
GLint half_size;
|
|
|
|
GLint position;
|
|
|
|
GLint radius;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct tex_shader {
|
2023-04-18 07:24:48 +10:00
|
|
|
GLuint program;
|
|
|
|
GLint proj;
|
|
|
|
GLint tex;
|
2023-05-01 03:03:09 +10:00
|
|
|
GLint alpha;
|
2023-04-18 07:24:48 +10:00
|
|
|
GLint pos_attrib;
|
|
|
|
GLint tex_attrib;
|
2023-05-01 03:03:09 +10:00
|
|
|
GLint size;
|
|
|
|
GLint position;
|
2023-04-18 07:24:48 +10:00
|
|
|
GLint radius;
|
2023-05-01 03:03:09 +10:00
|
|
|
GLint saturation;
|
|
|
|
GLint dim;
|
|
|
|
GLint dim_color;
|
|
|
|
GLint has_titlebar;
|
2023-09-21 11:35:49 +10:00
|
|
|
GLint discard_transparent;
|
2023-04-18 07:24:48 +10:00
|
|
|
};
|
|
|
|
|
2022-08-13 16:14:23 +10:00
|
|
|
struct fx_renderer {
|
|
|
|
float projection[9];
|
|
|
|
|
2023-04-24 14:11:55 +10:00
|
|
|
int viewport_width, viewport_height;
|
2023-04-18 07:24:48 +10:00
|
|
|
|
2023-09-06 14:32:08 +10:00
|
|
|
struct wlr_output *wlr_output;
|
|
|
|
|
|
|
|
// The framebuffer used by wlroots
|
|
|
|
struct fx_framebuffer wlr_buffer;
|
|
|
|
// Contains the blurred background for tiled windows
|
|
|
|
struct fx_framebuffer blur_buffer;
|
|
|
|
// Contains the original pixels to draw over the areas where artifact are visible
|
|
|
|
struct fx_framebuffer blur_saved_pixels_buffer;
|
2023-04-18 07:24:48 +10:00
|
|
|
// Blur swaps between the two effects buffers everytime it scales the image
|
2023-09-06 14:32:08 +10:00
|
|
|
// Buffer used for effects
|
|
|
|
struct fx_framebuffer effects_buffer;
|
|
|
|
// Swap buffer used for effects
|
|
|
|
struct fx_framebuffer effects_buffer_swapped;
|
|
|
|
|
|
|
|
// The region where there's blur
|
|
|
|
pixman_region32_t blur_padding_region;
|
2023-04-18 07:24:48 +10:00
|
|
|
|
|
|
|
bool blur_buffer_dirty;
|
|
|
|
|
2022-11-12 13:21:51 +11:00
|
|
|
struct {
|
|
|
|
bool OES_egl_image_external;
|
|
|
|
} exts;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGLImageTargetTexture2DOES;
|
|
|
|
} procs;
|
|
|
|
|
2022-08-13 16:14:23 +10:00
|
|
|
struct {
|
2023-05-01 03:03:09 +10:00
|
|
|
struct box_shadow_shader box_shadow;
|
|
|
|
struct blur_shader blur1;
|
|
|
|
struct blur_shader blur2;
|
2024-01-04 04:38:44 +11:00
|
|
|
struct effects_shader blur_effects;
|
2023-05-01 03:03:09 +10:00
|
|
|
struct corner_shader corner;
|
|
|
|
struct quad_shader quad;
|
2022-11-12 12:05:05 +11:00
|
|
|
struct rounded_quad_shader rounded_quad;
|
2022-11-11 17:19:02 +11:00
|
|
|
struct rounded_quad_shader rounded_tl_quad;
|
|
|
|
struct rounded_quad_shader rounded_tr_quad;
|
2023-04-28 08:50:36 +10:00
|
|
|
struct rounded_quad_shader rounded_bl_quad;
|
|
|
|
struct rounded_quad_shader rounded_br_quad;
|
2023-05-01 03:03:09 +10:00
|
|
|
struct stencil_mask_shader stencil_mask;
|
|
|
|
struct tex_shader tex_rgba;
|
|
|
|
struct tex_shader tex_rgbx;
|
|
|
|
struct tex_shader tex_ext;
|
2022-08-13 16:14:23 +10:00
|
|
|
} shaders;
|
|
|
|
};
|
|
|
|
|
2024-02-15 19:48:31 +11:00
|
|
|
struct decoration_data get_undecorated_decoration_data();
|
|
|
|
|
2023-09-06 14:32:08 +10:00
|
|
|
struct fx_renderer *fx_renderer_create(struct wlr_egl *egl, struct wlr_output *output);
|
2022-08-13 16:14:23 +10:00
|
|
|
|
2023-04-18 07:24:48 +10:00
|
|
|
void fx_renderer_fini(struct fx_renderer *renderer);
|
|
|
|
|
2023-04-24 14:11:55 +10:00
|
|
|
void fx_renderer_begin(struct fx_renderer *renderer, int width, int height);
|
2022-08-13 16:14:23 +10:00
|
|
|
|
2023-09-06 14:32:08 +10:00
|
|
|
void fx_renderer_end(struct fx_renderer *renderer);
|
|
|
|
|
2022-08-13 16:14:23 +10:00
|
|
|
void fx_renderer_clear(const float color[static 4]);
|
|
|
|
|
|
|
|
void fx_renderer_scissor(struct wlr_box *box);
|
|
|
|
|
2023-09-21 11:35:49 +10:00
|
|
|
// Initialize the stenciling work
|
|
|
|
void fx_renderer_stencil_mask_init();
|
|
|
|
|
|
|
|
// Close the mask
|
|
|
|
void fx_renderer_stencil_mask_close(bool draw_inside_mask);
|
|
|
|
|
|
|
|
// Finish stenciling and clear the buffer
|
|
|
|
void fx_renderer_stencil_mask_fini();
|
|
|
|
|
2023-04-18 07:24:48 +10:00
|
|
|
bool fx_render_subtexture_with_matrix(struct fx_renderer *renderer, struct fx_texture *fx_texture,
|
2022-08-30 08:25:11 +10:00
|
|
|
const struct wlr_fbox *src_box, const struct wlr_box *dst_box, const float matrix[static 9],
|
2022-11-24 15:37:35 +11:00
|
|
|
struct decoration_data deco_data);
|
2022-08-13 16:14:23 +10:00
|
|
|
|
2023-04-18 07:24:48 +10:00
|
|
|
bool fx_render_texture_with_matrix(struct fx_renderer *renderer, struct fx_texture *fx_texture,
|
2022-11-24 15:37:35 +11:00
|
|
|
const struct wlr_box *dst_box, const float matrix[static 9], struct decoration_data deco_data);
|
2022-08-13 16:14:23 +10:00
|
|
|
|
2022-08-30 08:25:11 +10:00
|
|
|
void fx_render_rect(struct fx_renderer *renderer, const struct wlr_box *box,
|
|
|
|
const float color[static 4], const float projection[static 9]);
|
2022-08-22 06:30:00 +10:00
|
|
|
|
2022-11-11 17:19:02 +11:00
|
|
|
void fx_render_rounded_rect(struct fx_renderer *renderer, const struct wlr_box *box,
|
2023-04-28 08:50:36 +10:00
|
|
|
const float color[static 4], const float matrix[static 9], int radius,
|
|
|
|
enum corner_location corner_location);
|
2022-11-11 17:19:02 +11:00
|
|
|
|
2022-10-10 02:47:34 +11:00
|
|
|
void fx_render_border_corner(struct fx_renderer *renderer, const struct wlr_box *box,
|
2023-04-28 08:50:36 +10:00
|
|
|
const float color[static 4], const float matrix[static 9],
|
2022-10-10 02:47:34 +11:00
|
|
|
enum corner_location corner_location, int radius, int border_thickness);
|
|
|
|
|
2023-01-18 17:49:26 +11:00
|
|
|
void fx_render_box_shadow(struct fx_renderer *renderer, const struct wlr_box *box,
|
2023-12-22 17:08:09 +11:00
|
|
|
const struct wlr_box *inner_box, const float color[static 4],
|
|
|
|
const float matrix[static 9], int corner_radius, float blur_sigma);
|
2023-01-18 17:49:26 +11:00
|
|
|
|
2023-04-24 14:11:55 +10:00
|
|
|
void fx_render_blur(struct fx_renderer *renderer, const float matrix[static 9],
|
2024-01-04 04:38:44 +11:00
|
|
|
struct fx_framebuffer **buffer, struct blur_shader *shader,
|
|
|
|
const struct wlr_box *box, int blur_radius);
|
|
|
|
|
|
|
|
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);
|
2023-04-18 07:24:48 +10:00
|
|
|
|
2022-08-13 16:14:23 +10:00
|
|
|
#endif
|