diff options
author | William McKinnon <[email protected]> | 2024-04-15 01:32:22 -0400 |
---|---|---|
committer | GitHub <[email protected]> | 2024-04-15 01:32:22 -0400 |
commit | e1f4bc5996b1c77c7fa8536b7c03d9eb4140227d (patch) | |
tree | 3fa8045ca37131acc96c88cec4a2f920de6113fb /types/scene | |
parent | 7e723f983b074e62e676caffe21cd5527b524587 (diff) |
feat: add functions required by SwayFX (#35)
Diffstat (limited to 'types/scene')
-rw-r--r-- | types/scene/wlr_scene.c | 46 |
1 files changed, 33 insertions, 13 deletions
diff --git a/types/scene/wlr_scene.c b/types/scene/wlr_scene.c index 0545e70..2f887e1 100644 --- a/types/scene/wlr_scene.c +++ b/types/scene/wlr_scene.c @@ -1,5 +1,6 @@ #define _POSIX_C_SOURCE 200809L #include <assert.h> +#include <pixman.h> #include <stdlib.h> #include <scenefx/types/fx/shadow_data.h> #include <scenefx/types/wlr_scene.h> @@ -16,7 +17,7 @@ #include <wlr/util/region.h> #include <wlr/render/swapchain.h> -#include "render/pass.h" +#include "scenefx/render/pass.h" #include "scenefx/types/fx/shadow_data.h" #include "types/wlr_buffer.h" #include "types/wlr_output.h" @@ -478,7 +479,16 @@ static bool scene_node_update_iterator(struct wlr_scene_node *node, struct wlr_scene_buffer *buffer = wlr_scene_buffer_from_node(node); struct shadow_data *shadow_data = &buffer->shadow_data; if (scene_buffer_has_shadow(shadow_data)) { - wlr_region_expand(&node->visible, &node->visible, shadow_data->blur_sigma); + // Expand towards the damage while also compensating for the x and y + // offsets + pixman_region32_t shadow; + pixman_region32_init(&shadow); + pixman_region32_copy(&shadow, &node->visible); + wlr_region_expand(&shadow, &shadow, shadow_data->blur_sigma); + pixman_region32_translate(&shadow, shadow_data->offset_x, shadow_data->offset_y); + pixman_region32_subtract(&shadow, &shadow, &node->visible); + pixman_region32_union(&node->visible, &node->visible, &shadow); + pixman_region32_fini(&shadow); } } @@ -881,6 +891,8 @@ void wlr_scene_buffer_set_shadow_data(struct wlr_scene_buffer *scene_buffer, struct shadow_data *buff_data = &scene_buffer->shadow_data; if (buff_data->enabled == shadow_data.enabled && buff_data->blur_sigma == shadow_data.blur_sigma && + buff_data->offset_x == shadow_data.offset_x && + buff_data->offset_y == shadow_data.offset_y && buff_data->color.r && shadow_data.color.r && buff_data->color.g && shadow_data.color.g && buff_data->color.b && shadow_data.color.b && @@ -1235,6 +1247,9 @@ static void scene_entry_render(struct render_list_entry *entry, const struct ren pixman_region32_copy(&geometry_region, &render_region); clip_xdg(node, &geometry_region, &xdg_box, dst_box.x, dst_box.y, data->scale); + // Shadow box + struct wlr_box shadow_box = xdg_box; + pixman_region32_t opaque; pixman_region32_init(&opaque); scene_node_opaque_region(node, dst_box.x, dst_box.y, &opaque); @@ -1264,7 +1279,6 @@ static void scene_entry_render(struct render_list_entry *entry, const struct ren }, .clip = &render_region, }, - .scale = data->scale, }; fx_render_pass_add_rect(data->render_pass, &rect_options); break; @@ -1284,16 +1298,23 @@ static void scene_entry_render(struct render_list_entry *entry, const struct ren // Shadow if (scene_buffer_has_shadow(&scene_buffer->shadow_data)) { - struct fx_render_rect_options shadow_options = { - .base = { - .box = xdg_box, - .clip = &render_region, // Render with the original extended clip region - }, - .scale = data->scale, + struct shadow_data shadow_data = scene_buffer->shadow_data; + shadow_box.x -= shadow_data.blur_sigma - shadow_data.offset_x; + shadow_box.y -= shadow_data.blur_sigma - shadow_data.offset_y; + shadow_box.width += shadow_data.blur_sigma * 2; + shadow_box.height += shadow_data.blur_sigma * 2; + transform_output_box(&shadow_box, data); + + shadow_data.color.a *= scene_buffer->opacity; + + struct fx_render_box_shadow_options shadow_options = { + .shadow_box = shadow_box, + .clip_box = xdg_box, + .clip = &render_region, + .shadow_data = &shadow_data, + .corner_radius = scene_buffer->corner_radius * data->scale, }; - fx_render_pass_add_box_shadow(data->render_pass, &shadow_options, - scene_buffer->corner_radius * data->scale, - &scene_buffer->shadow_data); + fx_render_pass_add_box_shadow(data->render_pass, &shadow_options); } struct fx_render_texture_options tex_options = { @@ -1308,7 +1329,6 @@ static void scene_entry_render(struct render_list_entry *entry, const struct ren .blend_mode = pixman_region32_not_empty(&opaque) ? WLR_RENDER_BLEND_MODE_PREMULTIPLIED : WLR_RENDER_BLEND_MODE_NONE, }, - .scale = data->scale, .clip_box = &xdg_box, .corner_radius = scene_buffer->corner_radius * data->scale, }; |