From 6f9ff3394422040209c8d130bdcf921308c5f8ba Mon Sep 17 00:00:00 2001 From: Loukas Agorgianitis Date: Sat, 5 Apr 2025 20:32:25 +0300 Subject: [PATCH] scene: use fractional positions Signed-off-by: Loukas Agorgianitis --- include/wlr/types/wlr_scene.h | 12 +++---- test/bench_scene.c | 2 +- types/ext_image_capture_source_v1/scene.c | 12 +++---- types/scene/surface.c | 2 +- types/scene/wlr_scene.c | 44 +++++++++++------------ 5 files changed, 36 insertions(+), 36 deletions(-) diff --git a/include/wlr/types/wlr_scene.h b/include/wlr/types/wlr_scene.h index f6f97cfea..629744496 100644 --- a/include/wlr/types/wlr_scene.h +++ b/include/wlr/types/wlr_scene.h @@ -50,7 +50,7 @@ typedef bool (*wlr_scene_buffer_point_accepts_input_func_t)( struct wlr_scene_buffer *buffer, double *sx, double *sy); typedef void (*wlr_scene_buffer_iterator_func_t)( - struct wlr_scene_buffer *buffer, int sx, int sy, void *user_data); + struct wlr_scene_buffer *buffer, double sx, double sy, void *user_data); enum wlr_scene_node_type { WLR_SCENE_NODE_TREE, @@ -66,7 +66,7 @@ struct wlr_scene_node { struct wl_list link; // wlr_scene_tree.children bool enabled; - int x, y; // relative to parent + double x, y; // relative to parent struct { struct wl_signal destroy; @@ -228,7 +228,7 @@ struct wlr_scene_output { struct wlr_damage_ring damage_ring; - int x, y; + double x, y; struct { struct wl_signal destroy; @@ -301,7 +301,7 @@ void wlr_scene_node_set_enabled(struct wlr_scene_node *node, bool enabled); /** * Set the position of the node relative to its parent. */ -void wlr_scene_node_set_position(struct wlr_scene_node *node, int x, int y); +void wlr_scene_node_set_position(struct wlr_scene_node *node, double x, double y); /** * Move the node right above the specified sibling. * Asserts that node and sibling are distinct and share the same parent. @@ -332,7 +332,7 @@ void wlr_scene_node_reparent(struct wlr_scene_node *node, * * True is returned if the node and all of its ancestors are enabled. */ -bool wlr_scene_node_coords(struct wlr_scene_node *node, int *lx, int *ly); +bool wlr_scene_node_coords(struct wlr_scene_node *node, double *lx, double *ly); /** * Call `iterator` on each buffer in the scene-graph, with the buffer's * position in layout coordinates. The function is called from root to leaves @@ -591,7 +591,7 @@ void wlr_scene_output_destroy(struct wlr_scene_output *scene_output); * Set the output's position in the scene-graph. */ void wlr_scene_output_set_position(struct wlr_scene_output *scene_output, - int lx, int ly); + double lx, double ly); struct wlr_scene_output_state_options { struct wlr_scene_timer *timer; diff --git a/test/bench_scene.c b/test/bench_scene.c index 6d6b270f0..89cfff265 100644 --- a/test/bench_scene.c +++ b/test/bench_scene.c @@ -104,7 +104,7 @@ static void bench_scene_node_at(struct wlr_scene *scene, struct tree_spec *spec) } static void noop_iterator(struct wlr_scene_buffer *buffer, - int sx, int sy, void *user_data) { + double sx, double sy, void *user_data) { (void)buffer; (void)sx; (void)sy; diff --git a/types/ext_image_capture_source_v1/scene.c b/types/ext_image_capture_source_v1/scene.c index 99d34e012..d5db8f276 100644 --- a/types/ext_image_capture_source_v1/scene.c +++ b/types/ext_image_capture_source_v1/scene.c @@ -34,7 +34,7 @@ struct scene_node_source_frame_event { static size_t last_output_num = 0; -static void _get_scene_node_extents(struct wlr_scene_node *node, struct wlr_box *box, int lx, int ly) { +static void _get_scene_node_extents(struct wlr_scene_node *node, struct wlr_fbox *box, double lx, double ly) { switch (node->type) { case WLR_SCENE_NODE_TREE:; struct wlr_scene_tree *scene_tree = wlr_scene_tree_from_node(node); @@ -45,7 +45,7 @@ static void _get_scene_node_extents(struct wlr_scene_node *node, struct wlr_box break; case WLR_SCENE_NODE_RECT: case WLR_SCENE_NODE_BUFFER:; - struct wlr_box node_box = { .x = lx, .y = ly }; + struct wlr_fbox node_box = { .x = lx, .y = ly }; scene_node_get_size(node, &node_box.width, &node_box.height); if (node_box.x < box->x) { @@ -64,9 +64,9 @@ static void _get_scene_node_extents(struct wlr_scene_node *node, struct wlr_box } } -static void get_scene_node_extents(struct wlr_scene_node *node, struct wlr_box *box) { - *box = (struct wlr_box){ .x = INT_MAX, .y = INT_MAX }; - int lx = 0, ly = 0; +static void get_scene_node_extents(struct wlr_scene_node *node, struct wlr_fbox *box) { + *box = (struct wlr_fbox){ .x = INT_MAX, .y = INT_MAX }; + double lx = 0, ly = 0; wlr_scene_node_coords(node, &lx, &ly); _get_scene_node_extents(node, box, lx, ly); } @@ -74,7 +74,7 @@ static void get_scene_node_extents(struct wlr_scene_node *node, struct wlr_box * static void source_render(struct scene_node_source *source) { struct wlr_scene_output *scene_output = source->scene_output; - struct wlr_box extents; + struct wlr_fbox extents; get_scene_node_extents(source->node, &extents); if (extents.width == 0 || extents.height == 0) { diff --git a/types/scene/surface.c b/types/scene/surface.c index e6ea1333a..414620687 100644 --- a/types/scene/surface.c +++ b/types/scene/surface.c @@ -359,7 +359,7 @@ static void handle_scene_surface_surface_commit( // schedule the frame however if the node is enabled and there is an // output intersecting, otherwise the frame done events would never reach // the surface anyway. - int lx, ly; + double lx, ly; bool enabled = wlr_scene_node_coords(&scene_buffer->node, &lx, &ly); if (!wl_list_empty(&surface->surface->current.frame_callback_list) && diff --git a/types/scene/wlr_scene.c b/types/scene/wlr_scene.c index 7231422e8..7b5ff28e1 100644 --- a/types/scene/wlr_scene.c +++ b/types/scene/wlr_scene.c @@ -202,10 +202,10 @@ struct wlr_scene_tree *wlr_scene_tree_create(struct wlr_scene_tree *parent) { } typedef bool (*scene_node_box_iterator_func_t)(struct wlr_scene_node *node, - int sx, int sy, void *data); + double sx, double sy, void *data); static bool _scene_nodes_in_box(struct wlr_scene_node *node, struct wlr_box *box, - scene_node_box_iterator_func_t iterator, void *user_data, int lx, int ly) { + scene_node_box_iterator_func_t iterator, void *user_data, double lx, double ly) { if (!node->enabled) { return false; } @@ -237,13 +237,13 @@ static bool _scene_nodes_in_box(struct wlr_scene_node *node, struct wlr_box *box static bool scene_nodes_in_box(struct wlr_scene_node *node, struct wlr_box *box, scene_node_box_iterator_func_t iterator, void *user_data) { - int x, y; + double x, y; wlr_scene_node_coords(node, &x, &y); return _scene_nodes_in_box(node, box, iterator, user_data, x, y); } -static void scene_node_opaque_region(struct wlr_scene_node *node, int x, int y, +static void scene_node_opaque_region(struct wlr_scene_node *node, double x, double y, pixman_region32_t *opaque) { int width, height; scene_node_get_size(node, &width, &height); @@ -545,7 +545,7 @@ static void restack_xwayland_surface(struct wlr_scene_node *node, #endif static bool scene_node_update_iterator(struct wlr_scene_node *node, - int lx, int ly, void *_data) { + double lx, double ly, void *_data) { struct scene_update_data *data = _data; struct wlr_box box = { .x = lx, .y = ly }; @@ -593,7 +593,7 @@ static void scene_node_visibility(struct wlr_scene_node *node, } static void scene_node_bounds(struct wlr_scene_node *node, - int x, int y, pixman_region32_t *visible) { + double x, double y, pixman_region32_t *visible) { if (!node->enabled) { return; } @@ -688,7 +688,7 @@ static void scene_node_update(struct wlr_scene_node *node, pixman_region32_t *damage) { struct wlr_scene *scene = scene_node_get_root(node); - int x, y; + double x, y; if (!wlr_scene_node_coords(node, &x, &y)) { // We assume explicit damage on a disabled tree means the node was just // disabled. @@ -919,7 +919,7 @@ void wlr_scene_buffer_set_buffer_with_options(struct wlr_scene_buffer *scene_buf return; } - int lx, ly; + double lx, ly; if (!wlr_scene_node_coords(&scene_buffer->node, &lx, &ly)) { return; } @@ -1030,7 +1030,7 @@ void wlr_scene_buffer_set_opaque_region(struct wlr_scene_buffer *scene_buffer, pixman_region32_copy(&scene_buffer->opaque_region, region); - int x, y; + double x, y; if (!wlr_scene_node_coords(&scene_buffer->node, &x, &y)) { return; } @@ -1201,7 +1201,7 @@ void wlr_scene_node_set_enabled(struct wlr_scene_node *node, bool enabled) { return; } - int x, y; + double x, y; pixman_region32_t visible; pixman_region32_init(&visible); if (wlr_scene_node_coords(node, &x, &y)) { @@ -1213,7 +1213,7 @@ void wlr_scene_node_set_enabled(struct wlr_scene_node *node, bool enabled) { scene_node_update(node, &visible); } -void wlr_scene_node_set_position(struct wlr_scene_node *node, int x, int y) { +void wlr_scene_node_set_position(struct wlr_scene_node *node, double x, double y) { if (node->x == x && node->y == y) { return; } @@ -1283,7 +1283,7 @@ void wlr_scene_node_reparent(struct wlr_scene_node *node, assert(&ancestor->node != node); } - int x, y; + double x, y; pixman_region32_t visible; pixman_region32_init(&visible); if (wlr_scene_node_coords(node, &x, &y)) { @@ -1297,10 +1297,10 @@ void wlr_scene_node_reparent(struct wlr_scene_node *node, } bool wlr_scene_node_coords(struct wlr_scene_node *node, - int *lx_ptr, int *ly_ptr) { + double *lx_ptr, double *ly_ptr) { assert(node); - int lx = 0, ly = 0; + double lx = 0, ly = 0; bool enabled = true; while (true) { lx += node->x; @@ -1319,7 +1319,7 @@ bool wlr_scene_node_coords(struct wlr_scene_node *node, } static void scene_node_for_each_scene_buffer(struct wlr_scene_node *node, - int lx, int ly, wlr_scene_buffer_iterator_func_t user_iterator, + double lx, double ly, wlr_scene_buffer_iterator_func_t user_iterator, void *user_data) { if (!node->enabled) { return; @@ -1352,7 +1352,7 @@ struct node_at_data { }; static bool scene_node_at_iterator(struct wlr_scene_node *node, - int lx, int ly, void *data) { + double lx, double ly, void *data) { struct node_at_data *at_data = data; double rx = at_data->lx - lx; @@ -1403,7 +1403,7 @@ struct wlr_scene_node *wlr_scene_node_at(struct wlr_scene_node *node, struct render_list_entry { struct wlr_scene_node *node; bool highlight_transparent_region; - int x, y; + double x, y; }; static float get_luminance_multiplier(const struct wlr_color_luminances *src_lum, @@ -1425,8 +1425,8 @@ static void scene_entry_render(struct render_list_entry *entry, const struct ren return; } - int x = entry->x - data->logical.x; - int y = entry->y - data->logical.y; + double x = entry->x - data->logical.x; + double y = entry->y - data->logical.y; struct wlr_box dst_box = { .x = x, @@ -1845,7 +1845,7 @@ struct wlr_scene_output *wlr_scene_get_scene_output(struct wlr_scene *scene, } void wlr_scene_output_set_position(struct wlr_scene_output *scene_output, - int lx, int ly) { + double lx, double ly) { if (scene_output->x == lx && scene_output->y == ly) { return; } @@ -1890,7 +1890,7 @@ static bool scene_buffer_is_black_opaque(struct wlr_scene_buffer *scene_buffer) } static bool construct_render_list_iterator(struct wlr_scene_node *node, - int lx, int ly, void *_data) { + double lx, double ly, void *_data) { struct render_list_constructor_data *data = _data; if (scene_node_invisible(node)) { @@ -2656,7 +2656,7 @@ void wlr_scene_output_send_frame_done(struct wlr_scene_output *scene_output, } static void scene_output_for_each_scene_buffer(const struct wlr_box *output_box, - struct wlr_scene_node *node, int lx, int ly, + struct wlr_scene_node *node, double lx, double ly, wlr_scene_buffer_iterator_func_t user_iterator, void *user_data) { if (!node->enabled) { return;