Skip to content

Commit 89ad0e8

Browse files
committed
blur plugin: add some missing features and stuff to truly make a independent working plugin
1 parent fdd4398 commit 89ad0e8

File tree

5 files changed

+22
-9
lines changed

5 files changed

+22
-9
lines changed

examples/example-blur-plugin.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ static char* invert_gles3_src =
3939
" fragColor = texture(tex, inverted_coord);\n"
4040
"}\n";
4141

42-
static bool invert_init(int client_version, void** user_data)
42+
static bool invert_init(int client_version, char *id, void** user_data)
4343
{
4444
struct invert_data* v = malloc(sizeof(struct invert_data));
4545
if (!v)
@@ -67,6 +67,8 @@ static void invert_execute(pixman_region32_t* damage, struct wlr_box* box,
6767
struct fx_render_blur_pass_options* fx_options,
6868
void* data)
6969
{
70+
fx_options->tex_options.base.clip = damage;
71+
7072
struct fx_render_texture_options* tex_options = &fx_options->tex_options;
7173
struct wlr_render_texture_options* options = &tex_options->base;
7274
struct fx_texture* texture = fx_get_texture(options->texture);

include/scenefx/render/pass.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ struct fx_render_blur_pass_options {
112112

113113
struct fx_blur_impl {
114114
char *name;
115-
bool (*init)(int client_version, void ** data);
115+
bool (*init)(int client_version, char *id, void ** data);
116+
bool (*supports_optimized_blur)(void *);
116117
int (*get_expansion)(struct fx_gles_render_pass *, struct fx_render_blur_pass_options *, void *);
117118
bool (*prepare)(pixman_region32_t *damage, struct fx_gles_render_pass *, struct fx_render_blur_pass_options *, void *);
118119
void (*execute)(pixman_region32_t *damage, struct wlr_box *box, struct fx_gles_render_pass *, struct fx_render_blur_pass_options *, void *);

render/fx_renderer/fx_blur.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ bool fx_blur_plugin_link(struct wlr_renderer *renderer, struct fx_blur_plugin_in
9898
eglQueryContext(fx_renderer->egl->display, fx_renderer->egl->context,
9999
EGL_CONTEXT_CLIENT_VERSION, &client_version);
100100

101-
bool res = info->blur_impl->init(client_version, &info->user_data);
101+
bool res = info->blur_impl->init(client_version, info->id, &info->user_data);
102102
if (!res) {
103103
return false;
104104
}

render/fx_renderer/fx_pass.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -929,12 +929,12 @@ static struct fx_framebuffer *get_main_buffer_blur(struct fx_gles_render_pass *p
929929
struct fx_blur_plugin_info *found = fx_renderer_get_plugin(&renderer->wlr_renderer, fx_options->blur_id);
930930
if (found == NULL) {
931931
wlr_log(WLR_ERROR, "invalid custom blur given");
932-
return NULL;
932+
return fx_options->current_buffer;
933933
}
934934

935935
if (!(found->state & BLUR_READY)) {
936936
wlr_log(WLR_ERROR, "custom blur %s hasn't been readied for renderer", found->id);
937-
return NULL;
937+
return fx_options->current_buffer;
938938
}
939939

940940
blur_user_data = found->user_data;
@@ -965,8 +965,8 @@ static struct fx_framebuffer *get_main_buffer_blur(struct fx_gles_render_pass *p
965965
// Artifacts with NEAREST filter
966966
fx_options->tex_options.base.filter_mode = WLR_SCALE_FILTER_BILINEAR;
967967

968-
if (blur->prepare != NULL && !blur->prepare(&damage, pass, fx_options, &blur_user_data)) {
969-
return NULL;
968+
if (blur->prepare != NULL && !blur->prepare(&damage, pass, fx_options, blur_user_data)) {
969+
return fx_options->current_buffer;
970970
}
971971

972972
// Render additional blur effects like saturation, noise, contrast, etc...
@@ -1027,7 +1027,15 @@ void fx_render_pass_add_blur(struct fx_gles_render_pass *pass,
10271027

10281028
const bool has_strength = fx_options->blur_strength < 1.0;
10291029
struct fx_framebuffer *buffer = pass->fx_effect_framebuffers->optimized_blur_buffer;
1030-
if (!buffer || !fx_options->use_optimized_blur || has_strength) {
1030+
bool use_optimized_blur = buffer && fx_options->use_optimized_blur && !has_strength;
1031+
if (use_optimized_blur && fx_options->blur_data->id != NULL) {
1032+
struct fx_blur_plugin_info *info = fx_renderer_get_plugin(&renderer->wlr_renderer, fx_options->blur_data->id);
1033+
if (info->blur_impl->supports_optimized_blur && !info->blur_impl->supports_optimized_blur(info->user_data)) {
1034+
use_optimized_blur = false;
1035+
}
1036+
}
1037+
1038+
if (!use_optimized_blur) {
10311039
if (!buffer) {
10321040
wlr_log(WLR_ERROR, "Warning: Failed to use optimized blur");
10331041
}
@@ -1036,7 +1044,9 @@ void fx_render_pass_add_blur(struct fx_gles_render_pass *pass,
10361044

10371045
// Render the blur into its own buffer
10381046
struct fx_render_blur_pass_options blur_options = *fx_options;
1047+
blur_options.blur_id = blur_options.blur_data->id;
10391048
blur_options.tex_options.base.clip = &translucent_region;
1049+
10401050
if (fx_options->use_optimized_blur && has_strength
10411051
// If the optimized blur hasn't been rendered yet
10421052
&& pass->fx_effect_framebuffers->optimized_no_blur_buffer) {
@@ -1046,7 +1056,6 @@ void fx_render_pass_add_blur(struct fx_gles_render_pass *pass,
10461056
} else {
10471057
blur_options.current_buffer = pass->buffer;
10481058
}
1049-
blur_options.blur_id = blur_options.blur_data->id;
10501059
buffer = get_main_buffer_blur(pass, &blur_options);
10511060
if (!buffer) {
10521061
goto damage_finish;

types/scene/wlr_scene.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2847,6 +2847,7 @@ bool wlr_scene_output_build_state(struct wlr_scene_output *scene_output,
28472847

28482848
if (debug_damage == WLR_SCENE_DEBUG_DAMAGE_RERENDER) {
28492849
scene_output_damage_whole(scene_output);
2850+
mark_all_optimized_blur_nodes_dirty(&scene_output->scene->tree.node);
28502851
}
28512852

28522853
struct timespec now;

0 commit comments

Comments
 (0)