From 7b2185199d2c303b1d907e2f5e27fcab1f437aec Mon Sep 17 00:00:00 2001 From: William McKinnon Date: Fri, 6 Dec 2024 20:46:50 -0500 Subject: [PATCH 1/5] swayfx compat changes --- include/scenefx/render/fx_renderer/fx_renderer.h | 3 +-- meson.build | 1 - types/scene/wlr_scene.c | 5 +++++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/include/scenefx/render/fx_renderer/fx_renderer.h b/include/scenefx/render/fx_renderer/fx_renderer.h index 5b43c4d..cbd312d 100644 --- a/include/scenefx/render/fx_renderer/fx_renderer.h +++ b/include/scenefx/render/fx_renderer/fx_renderer.h @@ -12,8 +12,7 @@ struct fx_renderer; struct wlr_renderer *fx_renderer_create_with_drm_fd(int drm_fd); struct wlr_renderer *fx_renderer_create(struct wlr_backend *backend); -struct fx_renderer *fx_get_renderer( - struct wlr_renderer *wlr_renderer); +struct fx_renderer *fx_get_renderer(struct wlr_renderer *wlr_renderer); bool fx_renderer_check_ext(struct wlr_renderer *renderer, const char *ext); GLuint fx_renderer_get_buffer_fbo(struct wlr_renderer *renderer, struct wlr_buffer *buffer); diff --git a/meson.build b/meson.build index bf8b7e8..bc7a67b 100644 --- a/meson.build +++ b/meson.build @@ -174,7 +174,6 @@ pkgconfig.generate( name: versioned_name, version: meson.project_version(), filebase: meson.project_name(), - name: meson.project_name(), description: 'Wlroots effects library', subdirs: versioned_name, ) diff --git a/types/scene/wlr_scene.c b/types/scene/wlr_scene.c index bab2d00..aaee86e 100644 --- a/types/scene/wlr_scene.c +++ b/types/scene/wlr_scene.c @@ -2421,6 +2421,11 @@ bool wlr_scene_output_build_state(struct wlr_scene_output *scene_output, timer->pre_render_duration = timespec_to_nsec(&duration); } + // TODO: we need to revisit this, this is a stopgap to ensure we can resume swayfx rebase + if (!output->swapchain && !wlr_output_configure_primary_swapchain(output, state, &output->swapchain)) { + return false; + } + struct fx_gles_render_pass *render_pass = fx_renderer_begin_buffer_pass(output->renderer, buffer, output, &(struct wlr_buffer_pass_options) { From 4dcffb36ede3bae4ece568784df92dcc7ed57851 Mon Sep 17 00:00:00 2001 From: Erik Reider <35975961+ErikReider@users.noreply.github.com> Date: Fri, 27 Dec 2024 20:39:50 +0100 Subject: [PATCH 2/5] Provide the possibility to provide a different swapchain for creating custom buffers --- include/render/fx_renderer/fx_renderer.h | 4 +++- include/scenefx/render/pass.h | 9 ++++++++- render/fx_renderer/fx_framebuffer.c | 7 +++++-- render/fx_renderer/fx_pass.c | 14 +++++++++----- render/fx_renderer/fx_renderer.c | 5 ++++- types/scene/wlr_scene.c | 15 +++++++-------- 6 files changed, 36 insertions(+), 18 deletions(-) diff --git a/include/render/fx_renderer/fx_renderer.h b/include/render/fx_renderer/fx_renderer.h index b9b9e0b..d118e9a 100644 --- a/include/render/fx_renderer/fx_renderer.h +++ b/include/render/fx_renderer/fx_renderer.h @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -50,7 +51,8 @@ struct fx_framebuffer { /** Should only be used with custom fbs */ void fx_framebuffer_get_or_create_custom(struct fx_renderer *fx_renderer, - struct wlr_output *output, struct fx_framebuffer **fx_buffer); + struct wlr_output *output, struct wlr_swapchain *swapchain, + struct fx_framebuffer **fx_buffer); struct fx_framebuffer *fx_framebuffer_get_or_create(struct fx_renderer *renderer, struct wlr_buffer *wlr_buffer); diff --git a/include/scenefx/render/pass.h b/include/scenefx/render/pass.h index 816174d..2bb8424 100644 --- a/include/scenefx/render/pass.h +++ b/include/scenefx/render/pass.h @@ -4,6 +4,7 @@ #include #include #include +#include #include "render/egl.h" #include "scenefx/types/fx/corner_location.h" @@ -18,6 +19,12 @@ struct fx_gles_render_pass { struct fx_render_timer *timer; }; +struct fx_buffer_pass_options { + const struct wlr_buffer_pass_options *base; + + struct wlr_swapchain *swapchain; +}; + /** * Begin a new render pass with the supplied destination buffer. * @@ -26,7 +33,7 @@ struct fx_gles_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); + const struct fx_buffer_pass_options *options); struct fx_gradient { float degree; diff --git a/render/fx_renderer/fx_framebuffer.c b/render/fx_renderer/fx_framebuffer.c index dd4b299..0cab8d7 100644 --- a/render/fx_renderer/fx_framebuffer.c +++ b/render/fx_renderer/fx_framebuffer.c @@ -69,9 +69,12 @@ GLuint fx_framebuffer_get_fbo(struct fx_framebuffer *buffer) { } void fx_framebuffer_get_or_create_custom(struct fx_renderer *renderer, - struct wlr_output *output, struct fx_framebuffer **fx_framebuffer) { + struct wlr_output *output, struct wlr_swapchain *swapchain, + struct fx_framebuffer **fx_framebuffer) { struct wlr_allocator *allocator = output->allocator; - struct wlr_swapchain *swapchain = output->swapchain; + if (!swapchain) { + swapchain = output->swapchain; + } int width = output->width; int height = output->height; struct wlr_buffer *wlr_buffer = NULL; diff --git a/render/fx_renderer/fx_pass.c b/render/fx_renderer/fx_pass.c index 8788255..7a14f41 100644 --- a/render/fx_renderer/fx_pass.c +++ b/render/fx_renderer/fx_pass.c @@ -926,7 +926,7 @@ void fx_render_pass_add_optimized_blur(struct fx_gles_render_pass *pass, struct fx_framebuffer *buffer = get_main_buffer_blur(pass, &blur_options); // Update the optimized blur buffer if invalid - fx_framebuffer_get_or_create_custom(renderer, pass->output, + fx_framebuffer_get_or_create_custom(renderer, pass->output, NULL, &pass->fx_effect_framebuffers->optimized_blur_buffer); // Render the newly blurred content into the blur_buffer @@ -1051,7 +1051,8 @@ static struct fx_gles_render_pass *begin_buffer_pass(struct fx_framebuffer *buff 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 wlr_output *output, const struct fx_buffer_pass_options *fx_options) { + const struct wlr_buffer_pass_options *options = fx_options->base; struct fx_renderer *renderer = fx_get_renderer(wlr_renderer); renderer->basic_renderer = (output == NULL); @@ -1077,9 +1078,12 @@ struct fx_gles_render_pass *fx_renderer_begin_buffer_pass( // Update the buffers if needed if (!renderer->basic_renderer) { fbos = fx_effect_framebuffers_try_get(output); - fx_framebuffer_get_or_create_custom(renderer, output, &fbos->blur_saved_pixels_buffer); - fx_framebuffer_get_or_create_custom(renderer, output, &fbos->effects_buffer); - fx_framebuffer_get_or_create_custom(renderer, output, &fbos->effects_buffer_swapped); + fx_framebuffer_get_or_create_custom(renderer, output, fx_options->swapchain, + &fbos->blur_saved_pixels_buffer); + fx_framebuffer_get_or_create_custom(renderer, output, fx_options->swapchain, + &fbos->effects_buffer); + fx_framebuffer_get_or_create_custom(renderer, output, fx_options->swapchain, + &fbos->effects_buffer_swapped); pixman_region32_init(&fbos->blur_padding_region); } diff --git a/render/fx_renderer/fx_renderer.c b/render/fx_renderer/fx_renderer.c index 7029192..4572aed 100644 --- a/render/fx_renderer/fx_renderer.c +++ b/render/fx_renderer/fx_renderer.c @@ -121,7 +121,10 @@ static void fx_renderer_destroy(struct wlr_renderer *wlr_renderer) { static struct wlr_render_pass *begin_buffer_pass(struct wlr_renderer *wlr_renderer, struct wlr_buffer *wlr_buffer, const struct wlr_buffer_pass_options *options) { struct fx_gles_render_pass *pass = - fx_renderer_begin_buffer_pass(wlr_renderer, wlr_buffer, NULL, options); + fx_renderer_begin_buffer_pass(wlr_renderer, wlr_buffer, NULL, &(struct fx_buffer_pass_options) { + .base = options, + .swapchain = NULL, + }); if (!pass) { return NULL; } diff --git a/types/scene/wlr_scene.c b/types/scene/wlr_scene.c index aaee86e..b014ca1 100644 --- a/types/scene/wlr_scene.c +++ b/types/scene/wlr_scene.c @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -2421,16 +2422,14 @@ bool wlr_scene_output_build_state(struct wlr_scene_output *scene_output, timer->pre_render_duration = timespec_to_nsec(&duration); } - // TODO: we need to revisit this, this is a stopgap to ensure we can resume swayfx rebase - if (!output->swapchain && !wlr_output_configure_primary_swapchain(output, state, &output->swapchain)) { - return false; - } - struct fx_gles_render_pass *render_pass = fx_renderer_begin_buffer_pass(output->renderer, buffer, output, - &(struct wlr_buffer_pass_options) { - .timer = timer ? timer->render_timer : NULL, - .color_transform = options->color_transform, + &(struct fx_buffer_pass_options) { + .base = &(struct wlr_buffer_pass_options){ + .timer = timer ? timer->render_timer : NULL, + .color_transform = options->color_transform, + }, + .swapchain = swapchain, } ); if (render_pass == NULL) { From 6e79e1a362b7908071b31d4ec3a9620bda37aff2 Mon Sep 17 00:00:00 2001 From: William McKinnon Date: Sat, 28 Dec 2024 18:13:07 -0500 Subject: [PATCH 3/5] added assertion on optimized blur existing --- types/scene/wlr_scene.c | 1 + 1 file changed, 1 insertion(+) diff --git a/types/scene/wlr_scene.c b/types/scene/wlr_scene.c index b014ca1..445019a 100644 --- a/types/scene/wlr_scene.c +++ b/types/scene/wlr_scene.c @@ -843,6 +843,7 @@ struct wlr_scene_optimized_blur *wlr_scene_optimized_blur_create( void wlr_scene_optimized_blur_set_size(struct wlr_scene_optimized_blur *blur_node, int width, int height) { + assert(blur_node); if (blur_node->width == width && blur_node->height == height) { return; } From 520bd9fd811c570a9c3122171a65e1ec911c5dea Mon Sep 17 00:00:00 2001 From: Erik Reider <35975961+ErikReider@users.noreply.github.com> Date: Mon, 30 Dec 2024 23:46:54 +0100 Subject: [PATCH 4/5] Removed check_tex_src_box function in fx_pass like upstream --- render/fx_renderer/fx_pass.c | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/render/fx_renderer/fx_pass.c b/render/fx_renderer/fx_pass.c index 7a14f41..6e43a22 100644 --- a/render/fx_renderer/fx_pass.c +++ b/render/fx_renderer/fx_pass.c @@ -244,23 +244,9 @@ static void setup_blending(enum wlr_render_blend_mode mode) { } } -// make sure the texture source box does not try and sample outside of the -// texture -static void check_tex_src_box(const struct wlr_render_texture_options *options) { - if (!wlr_fbox_empty(&options->src_box)) { - const struct wlr_fbox *box = &options->src_box; - assert(box->x >= 0 && box->y >= 0 && - box->x + box->width <= options->texture->width && - box->y + box->height <= options->texture->height); - } -} - void fx_render_pass_add_texture(struct fx_gles_render_pass *pass, const struct fx_render_texture_options *fx_options) { const struct wlr_render_texture_options *options = &fx_options->base; - - check_tex_src_box(options); - struct fx_renderer *renderer = pass->buffer->renderer; struct fx_texture *texture = fx_get_texture(options->texture); @@ -634,8 +620,6 @@ static void render_blur_segments(struct fx_gles_render_pass *pass, fx_options->current_buffer->buffer); struct fx_texture *texture = fx_get_texture(options->texture); - check_tex_src_box(options); - /* * Render */ @@ -703,9 +687,6 @@ static void render_blur_effects(struct fx_gles_render_pass *pass, struct fx_render_blur_pass_options *fx_options) { struct fx_render_texture_options *tex_options = &fx_options->tex_options; struct wlr_render_texture_options *options = &tex_options->base; - - check_tex_src_box(options); - struct fx_renderer *renderer = pass->buffer->renderer; struct blur_data *blur_data = fx_options->blur_data; struct fx_texture *texture = fx_get_texture(options->texture); From 438b29f1c4531e7686ac290a87dde531f72d576d Mon Sep 17 00:00:00 2001 From: William McKinnon Date: Tue, 31 Dec 2024 17:05:50 -0500 Subject: [PATCH 5/5] added corner_location to scene rects --- include/scenefx/render/pass.h | 4 ++-- include/scenefx/types/wlr_scene.h | 5 +++-- render/fx_renderer/fx_framebuffer.c | 4 ++++ render/fx_renderer/fx_pass.c | 4 ++-- render/fx_renderer/fx_renderer.c | 1 + tinywl/tinywl.c | 3 ++- types/scene/wlr_scene.c | 12 ++++++++---- 7 files changed, 22 insertions(+), 11 deletions(-) diff --git a/include/scenefx/render/pass.h b/include/scenefx/render/pass.h index 2bb8424..9da8259 100644 --- a/include/scenefx/render/pass.h +++ b/include/scenefx/render/pass.h @@ -72,7 +72,7 @@ struct fx_render_rect_grad_options { struct fx_render_rounded_rect_options { struct wlr_render_rect_options base; int corner_radius; - enum corner_location corner_location; + enum corner_location corners; struct wlr_box window_box; int window_corner_radius; @@ -82,7 +82,7 @@ struct fx_render_rounded_rect_grad_options { struct wlr_render_rect_options base; struct fx_gradient gradient; int corner_radius; - enum corner_location corner_location; + enum corner_location corners; }; struct fx_render_box_shadow_options { diff --git a/include/scenefx/types/wlr_scene.h b/include/scenefx/types/wlr_scene.h index 2bbc770..19ab286 100644 --- a/include/scenefx/types/wlr_scene.h +++ b/include/scenefx/types/wlr_scene.h @@ -144,6 +144,7 @@ struct wlr_scene_rect { int width, height; float color[4]; int corner_radius; + enum corner_location corners; }; /** A scene-graph node displaying a shadow */ @@ -413,8 +414,8 @@ void wlr_scene_rect_set_size(struct wlr_scene_rect *rect, int width, int height) /** * Change the corner radius of an existing rectangle node. */ -void wlr_scene_rect_set_corner_radius(struct wlr_scene_rect *rect, int corner_radius); - +void wlr_scene_rect_set_corner_radius(struct wlr_scene_rect *rect, int corner_radius, + enum corner_location corners); /** * Change the color of an existing rectangle node. diff --git a/render/fx_renderer/fx_framebuffer.c b/render/fx_renderer/fx_framebuffer.c index 0cab8d7..b03f2ed 100644 --- a/render/fx_renderer/fx_framebuffer.c +++ b/render/fx_renderer/fx_framebuffer.c @@ -80,6 +80,9 @@ void fx_framebuffer_get_or_create_custom(struct fx_renderer *renderer, struct wlr_buffer *wlr_buffer = NULL; if (*fx_framebuffer == NULL) { + if (swapchain == NULL) { + printf("swapchain is null\n"); + } wlr_buffer = wlr_allocator_create_buffer(allocator, width, height, &swapchain->format); if (wlr_buffer == NULL) { @@ -173,3 +176,4 @@ void fx_framebuffer_destroy(struct fx_framebuffer *fx_buffer) { free(fx_buffer); } + diff --git a/render/fx_renderer/fx_pass.c b/render/fx_renderer/fx_pass.c index 6e43a22..5e29f16 100644 --- a/render/fx_renderer/fx_pass.c +++ b/render/fx_renderer/fx_pass.c @@ -411,7 +411,7 @@ void fx_render_pass_add_rounded_rect(struct fx_gles_render_pass *pass, struct fx_renderer *renderer = pass->buffer->renderer; struct quad_round_shader *shader = NULL; - switch (fx_options->corner_location) { + switch (fx_options->corners) { case CORNER_LOCATION_ALL: shader = &renderer->shaders.quad_round; break; @@ -485,7 +485,7 @@ void fx_render_pass_add_rounded_rect_grad(struct fx_gles_render_pass *pass, struct quad_grad_round_shader *shader = NULL; enum fx_rounded_quad_shader_source corner; - switch (fx_options->corner_location) { + switch (fx_options->corners) { case CORNER_LOCATION_ALL: corner = SHADER_SOURCE_QUAD_ROUND; shader = &renderer->shaders.quad_grad_round; diff --git a/render/fx_renderer/fx_renderer.c b/render/fx_renderer/fx_renderer.c index 4572aed..5f33e1e 100644 --- a/render/fx_renderer/fx_renderer.c +++ b/render/fx_renderer/fx_renderer.c @@ -568,6 +568,7 @@ struct wlr_renderer *fx_renderer_create_egl(struct wlr_egl *egl) { wlr_egl_unset_current(renderer->egl); get_fx_shm_formats(renderer, &renderer->shm_texture_formats); + printf("made renderer\n"); return &renderer->wlr_renderer; diff --git a/tinywl/tinywl.c b/tinywl/tinywl.c index d0067b4..aa11af1 100644 --- a/tinywl/tinywl.c +++ b/tinywl/tinywl.c @@ -954,7 +954,8 @@ static void server_new_xdg_toplevel(struct wl_listener *listener, void *data) { toplevel->border = wlr_scene_rect_create(toplevel->scene_tree, 0, 0, (float[4]){ 1.0f, 0.f, 0.f, 1.0f }); - wlr_scene_rect_set_corner_radius(toplevel->border, toplevel->corner_radius + BORDER_THICKNESS); + wlr_scene_rect_set_corner_radius(toplevel->border, + toplevel->corner_radius + BORDER_THICKNESS, CORNER_LOCATION_ALL); wlr_scene_node_set_position(&toplevel->border->node, -BORDER_THICKNESS, -BORDER_THICKNESS); float blur_sigma = 20.0f; diff --git a/types/scene/wlr_scene.c b/types/scene/wlr_scene.c index 445019a..b1272a2 100644 --- a/types/scene/wlr_scene.c +++ b/types/scene/wlr_scene.c @@ -20,6 +20,7 @@ #include "scenefx/render/fx_renderer/fx_renderer.h" #include "scenefx/render/pass.h" #include "scenefx/types/fx/blur_data.h" +#include "scenefx/types/fx/corner_location.h" #include "types/wlr_buffer.h" #include "types/wlr_output.h" #include "types/wlr_scene.h" @@ -664,6 +665,7 @@ struct wlr_scene_rect *wlr_scene_rect_create(struct wlr_scene_tree *parent, scene_rect->height = height; memcpy(scene_rect->color, color, sizeof(scene_rect->color)); scene_rect->corner_radius = 0; + scene_rect->corners = CORNER_LOCATION_NONE; scene_node_update(&scene_rect->node, NULL); @@ -745,12 +747,14 @@ static void scene_buffer_set_texture(struct wlr_scene_buffer *scene_buffer, } } -void wlr_scene_rect_set_corner_radius(struct wlr_scene_rect *rect, int corner_radius) { - if (rect->corner_radius == corner_radius) { +void wlr_scene_rect_set_corner_radius(struct wlr_scene_rect *rect, int corner_radius, + enum corner_location corners) { + if (rect->corner_radius == corner_radius && rect->corners == corners) { return; } rect->corner_radius = corner_radius; + rect->corners = corners; scene_node_update(&rect->node, NULL); } @@ -1586,7 +1590,7 @@ static void scene_entry_render(struct render_list_entry *entry, const struct ren }, }; - if (scene_rect->corner_radius) { + if (scene_rect->corner_radius && scene_rect->corners != CORNER_LOCATION_NONE) { struct wlr_box window_box; int window_corner_radius; scene_get_next_sibling_geometry(node, &window_box, &window_corner_radius); @@ -1600,7 +1604,7 @@ static void scene_entry_render(struct render_list_entry *entry, const struct ren struct fx_render_rounded_rect_options rounded_rect_options = { .base = rect_options.base, .corner_radius = scene_rect->corner_radius, - .corner_location = CORNER_LOCATION_ALL, + .corners = scene_rect->corners, .window_box = window_box, .window_corner_radius = window_corner_radius, };