Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add functions required by SwayFX #35

Merged
merged 24 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
6d756b3
updated along with the 1.9 rebase for swayfx
WillPower3309 Mar 15, 2024
fc0b0f7
Made fx_renderer_begin_buffer_pass public
ErikReider Mar 15, 2024
8b49921
Added shadow offset
ErikReider Mar 22, 2024
b512545
Added support for per output effect buffers
ErikReider Mar 22, 2024
17db47c
Made blur_pass and its functions public
ErikReider Mar 22, 2024
758039a
Force BILINEAR filter when blurring
ErikReider Mar 22, 2024
7d381d1
Made fx_texture_attribs public
ErikReider Mar 22, 2024
40f42c2
Blur: Don't ignore transparent regions if texture is NULL
ErikReider Mar 23, 2024
cff3dc6
made fx_renderer public
WillPower3309 Mar 27, 2024
fed37a0
added rounded border corner shader
WillPower3309 Mar 28, 2024
15c6eeb
border shader fixes
WillPower3309 Mar 29, 2024
e9cf45a
added texture titlebar corner rounding logic
WillPower3309 Apr 3, 2024
8394801
added rounded rects
WillPower3309 Apr 4, 2024
6d1ca03
Fixed texture render not blending when using effects
ErikReider Apr 5, 2024
8a01af6
dim impl
WillPower3309 Apr 7, 2024
b0cc1db
reordered corner location enum to allow rotation function is swayfx t…
WillPower3309 Apr 8, 2024
5945a21
Simplified render pass blur parameters
ErikReider Apr 8, 2024
005cd6a
Fixed fx_renderer_read_to_buffer not compensating for transformed region
ErikReider Apr 8, 2024
d749c89
Fixed optimized blur region being treated as transformed
ErikReider Apr 8, 2024
2716ec0
Fixed shadows not being rendererd corrently when transformed
ErikReider Apr 8, 2024
384d247
fixed shadow scaling on swayfx
WillPower3309 Apr 10, 2024
a9e6a03
Make sure that the shadows surface_box geo isn't negative
ErikReider Apr 11, 2024
0043994
Removed fx_pass scale fields
ErikReider Apr 11, 2024
d0f8518
Fade shadow with the scene_buffers opacity
ErikReider Apr 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 1 addition & 92 deletions include/render/fx_renderer/fx_renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define _FX_OPENGL_H

#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include <scenefx/render/fx_renderer/fx_renderer.h>
#include <stdbool.h>
#include <time.h>
#include <wlr/render/egl.h>
Expand All @@ -11,9 +11,6 @@
#include <wlr/util/addon.h>
#include <wlr/util/box.h>

#include "render/fx_renderer/shaders.h"
#include "render/pass.h"

struct fx_pixel_format {
uint32_t drm_format;
// optional field, if empty then internalformat = format
Expand Down Expand Up @@ -84,102 +81,14 @@ struct fx_texture {
struct wlr_addon buffer_addon;
};

struct fx_texture_attribs {
GLenum target; /* either GL_TEXTURE_2D or GL_TEXTURE_EXTERNAL_OES */
GLuint tex;

bool has_alpha;
};

struct fx_texture *fx_get_texture(struct wlr_texture *wlr_texture);

struct wlr_texture *fx_texture_from_buffer(struct wlr_renderer *wlr_renderer,
struct wlr_buffer *buffer);

void fx_texture_destroy(struct fx_texture *texture);

bool wlr_texture_is_fx(struct wlr_texture *wlr_texture);

void fx_texture_get_attribs(struct wlr_texture *texture,
struct fx_texture_attribs *attribs);

///
/// fx_renderer
///

struct fx_renderer {
struct wlr_renderer wlr_renderer;

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

const char *exts_str;
struct {
bool EXT_read_format_bgra;
bool KHR_debug;
bool OES_egl_image_external;
bool OES_egl_image;
bool EXT_texture_type_2_10_10_10_REV;
bool OES_texture_half_float_linear;
bool EXT_texture_norm16;
bool EXT_disjoint_timer_query;
} exts;

struct {
PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGLImageTargetTexture2DOES;
PFNGLDEBUGMESSAGECALLBACKKHRPROC glDebugMessageCallbackKHR;
PFNGLDEBUGMESSAGECONTROLKHRPROC glDebugMessageControlKHR;
PFNGLPOPDEBUGGROUPKHRPROC glPopDebugGroupKHR;
PFNGLPUSHDEBUGGROUPKHRPROC glPushDebugGroupKHR;
PFNGLEGLIMAGETARGETRENDERBUFFERSTORAGEOESPROC glEGLImageTargetRenderbufferStorageOES;
PFNGLGETGRAPHICSRESETSTATUSKHRPROC glGetGraphicsResetStatusKHR;
PFNGLGENQUERIESEXTPROC glGenQueriesEXT;
PFNGLDELETEQUERIESEXTPROC glDeleteQueriesEXT;
PFNGLQUERYCOUNTEREXTPROC glQueryCounterEXT;
PFNGLGETQUERYOBJECTIVEXTPROC glGetQueryObjectivEXT;
PFNGLGETQUERYOBJECTUI64VEXTPROC glGetQueryObjectui64vEXT;
PFNGLGETINTEGER64VEXTPROC glGetInteger64vEXT;
} procs;

struct {
struct quad_shader quad;
struct tex_shader tex_rgba;
struct tex_shader tex_rgbx;
struct tex_shader tex_ext;
struct box_shadow_shader box_shadow;
struct stencil_mask_shader stencil_mask;
struct blur_shader blur1;
struct blur_shader blur2;
struct blur_effects_shader blur_effects;
} shaders;

struct wl_list buffers; // fx_framebuffer.link
struct wl_list textures; // fx_texture.link

struct fx_framebuffer *current_buffer;
uint32_t viewport_width, viewport_height;

// Contains the blurred background for tiled windows
struct fx_framebuffer *optimized_blur_buffer;
// Contains the original pixels to draw over the areas where artifact are visible
struct fx_framebuffer *blur_saved_pixels_buffer;
// Blur swaps between the two effects buffers everytime it scales the image
// 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;

bool blur_buffer_dirty;
};

bool wlr_renderer_is_fx(struct wlr_renderer *wlr_renderer);

struct fx_renderer *fx_get_renderer(
struct wlr_renderer *wlr_renderer);
struct fx_render_timer *fx_get_render_timer(
struct wlr_render_timer *timer);
struct fx_texture *fx_get_texture(
Expand Down
41 changes: 40 additions & 1 deletion include/render/fx_renderer/shaders.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ enum fx_tex_shader_source {
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,
SHADER_SOURCE_QUAD_ROUND_BOTTOM_RIGHT = 4,
SHADER_SOURCE_QUAD_ROUND_BOTTOM_LEFT = 5,
};

struct quad_shader {
GLuint program;
GLint proj;
Expand All @@ -29,6 +37,18 @@ struct quad_shader {

bool link_quad_program(struct quad_shader *shader);

struct quad_round_shader {
GLuint program;
GLint proj;
GLint color;
GLint pos_attrib;
GLint size;
GLint position;
GLint radius;
};

bool link_quad_round_program(struct quad_round_shader *shader, enum fx_rounded_quad_shader_source source);

struct tex_shader {
GLuint program;
GLint proj;
Expand All @@ -39,16 +59,35 @@ struct tex_shader {
GLint size;
GLint position;
GLint radius;
GLint has_titlebar;
GLint discard_transparent;
GLint dim;
GLint dim_color;
};

bool link_tex_program(struct tex_shader *shader, enum fx_tex_shader_source source);

struct stencil_mask_shader {
struct rounded_border_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;
GLint position;
GLint radius;
GLint half_size;
GLint half_thickness;
};

bool link_rounded_border_corner_program(struct rounded_border_corner_shader *shader);

struct stencil_mask_shader {
GLuint program;
GLint proj;
GLint pos_attrib;
GLint half_size;
GLint position;
GLint radius;
Expand Down
86 changes: 7 additions & 79 deletions include/render/pass.h
Original file line number Diff line number Diff line change
@@ -1,101 +1,29 @@
#ifndef FX_RENDER_PASS_H
#define FX_RENDER_PASS_H

#include <scenefx/render/pass.h>
#include <stdbool.h>
#include <wlr/render/pass.h>
#include <wlr/util/box.h>
#include <wlr/render/interface.h>
#include "scenefx/types/fx/shadow_data.h"

struct fx_gles_render_pass {
struct wlr_render_pass base;
struct fx_framebuffer *buffer;
float projection_matrix[9];
struct fx_render_timer *timer;
};

/**
* Begin a new render pass with the supplied destination buffer.
*
* Callers must call wlr_render_pass_submit() once they are done with the
* render pass.
*/
struct fx_gles_render_pass *fx_renderer_begin_buffer_pass(struct wlr_renderer *wlr_renderer,
struct wlr_buffer *wlr_buffer, struct wlr_output *output,
const struct wlr_buffer_pass_options *options);

struct fx_render_texture_options {
struct wlr_render_texture_options base;
float scale;
struct wlr_box *clip_box; // Used to clip csd. Ignored if NULL
int corner_radius;
bool discard_transparent;
};

struct fx_render_texture_options fx_render_texture_options_default(
const struct wlr_render_texture_options *base);

struct fx_render_rect_options {
struct wlr_render_rect_options base;
float scale;
};

struct fx_render_rect_options fx_render_rect_options_default(
const struct wlr_render_rect_options *base);

struct fx_render_blur_pass_options {
struct fx_render_texture_options tex_options;
pixman_region32_t *opaque_region;
struct wlr_output *output;
struct wlr_box monitor_box;
struct fx_framebuffer *current_buffer;
struct blur_data *blur_data;
bool use_optimized_blur;
bool ignore_transparent;
struct fx_render_stencil_box_options {
struct wlr_box box;
/* Clip region, leave NULL to disable clipping */
const pixman_region32_t *clip;
int corner_radius;
};

/**
* Render a fx texture.
*/
void fx_render_pass_add_texture(struct fx_gles_render_pass *render_pass,
const struct fx_render_texture_options *options);

/**
* Render a rectangle.
*/
void fx_render_pass_add_rect(struct fx_gles_render_pass *render_pass,
const struct fx_render_rect_options *options);

/**
* Render a stencil mask.
*/
void fx_render_pass_add_stencil_mask(struct fx_gles_render_pass *pass,
const struct fx_render_rect_options *fx_options, int corner_radius);

/**
* Render a box shadow.
*/
void fx_render_pass_add_box_shadow(struct fx_gles_render_pass *pass,
const struct fx_render_rect_options *fx_options,
int corner_radius, struct shadow_data *shadow_data);

/**
* Render blur.
*/
void fx_render_pass_add_blur(struct fx_gles_render_pass *pass,
struct fx_render_blur_pass_options *fx_options);

/**
* Render optimized blur.
*/
void fx_render_pass_add_optimized_blur(struct fx_gles_render_pass *pass,
struct fx_render_blur_pass_options *fx_options);

/**
* Render from one buffer to another
*/
void fx_renderer_read_to_buffer(struct fx_gles_render_pass *pass,
pixman_region32_t *region, struct fx_framebuffer *dst_buffer,
struct fx_framebuffer *src_buffer);
const struct fx_render_stencil_box_options *options);

#endif
9 changes: 0 additions & 9 deletions include/scenefx/fx_renderer/fx_renderer.h

This file was deleted.

29 changes: 29 additions & 0 deletions include/scenefx/render/fx_renderer/fx_effect_framebuffers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#ifndef _FX_EFFECT_FRAMEBUFFERS_H
#define _FX_EFFECT_FRAMEBUFFERS_H

#include <wlr/types/wlr_output.h>
#include <wlr/util/addon.h>

/**
* Used to add effect framebuffers per output instead of every output sharing
* them.
*/
struct fx_effect_framebuffers {
struct wlr_addon addon;

// Contains the blurred background for tiled windows
struct fx_framebuffer *optimized_blur_buffer;
// Contains the original pixels to draw over the areas where artifact are visible
struct fx_framebuffer *blur_saved_pixels_buffer;
// Blur swaps between the two effects buffers everytime it scales the image
// Buffer used for effects
struct fx_framebuffer *effects_buffer;
// Swap buffer used for effects
struct fx_framebuffer *effects_buffer_swapped;

bool blur_buffer_dirty;
};

struct fx_effect_framebuffers *fx_effect_framebuffers_try_get(struct wlr_output *output);

#endif
Loading