From 6f66dd9944619c1b6fd536252a476b54a223df5e Mon Sep 17 00:00:00 2001 From: Bilal Elmoussaoui Date: Wed, 19 Jul 2023 17:27:55 +0200 Subject: [PATCH] mtk: Move Rectangle.union from Meta Similar to Rectangle.equal. The clutter helper was not used. Part-of: --- clutter/clutter/clutter-private.h | 4 --- clutter/clutter/clutter-util.c | 31 ------------------- mtk/mtk/mtk-rectangle.c | 43 +++++++++++++++++++++++++++ mtk/mtk/mtk-rectangle.h | 6 ++++ src/core/boxes.c | 41 ------------------------- src/core/constraints.c | 18 +++++------ src/meta/boxes.h | 6 ---- src/wayland/meta-wayland-subsurface.c | 2 +- 8 files changed, 59 insertions(+), 92 deletions(-) diff --git a/clutter/clutter/clutter-private.h b/clutter/clutter/clutter-private.h index c4fb459d5..3512e4c74 100644 --- a/clutter/clutter/clutter-private.h +++ b/clutter/clutter/clutter-private.h @@ -214,10 +214,6 @@ void _clutter_util_rectangle_offset (const MtkRectangle *src, int y, MtkRectangle *dest); -void _clutter_util_rectangle_union (const MtkRectangle *src1, - const MtkRectangle *src2, - MtkRectangle *dest); - gboolean _clutter_util_rectangle_intersection (const MtkRectangle *src1, const MtkRectangle *src2, MtkRectangle *dest); diff --git a/clutter/clutter/clutter-util.c b/clutter/clutter/clutter-util.c index fdcb14b1b..e183ac80d 100644 --- a/clutter/clutter/clutter-util.c +++ b/clutter/clutter/clutter-util.c @@ -163,37 +163,6 @@ _clutter_util_rectangle_offset (const MtkRectangle *src, dest->y += y; } -/*< private > - * _clutter_util_rectangle_union: - * @src1: first rectangle to union - * @src2: second rectangle to union - * @dest: (out): return location for the unioned rectangle - * - * Calculates the union of two rectangles. - * - * The union of rectangles @src1 and @src2 is the smallest rectangle which - * includes both @src1 and @src2 within it. - * - * It is allowed for @dest to be the same as either @src1 or @src2. - * - * This function should really be in Cairo. - */ -void -_clutter_util_rectangle_union (const MtkRectangle *src1, - const MtkRectangle *src2, - MtkRectangle *dest) -{ - int dest_x, dest_y; - - dest_x = MIN (src1->x, src2->x); - dest_y = MIN (src1->y, src2->y); - - dest->width = MAX (src1->x + src1->width, src2->x + src2->width) - dest_x; - dest->height = MAX (src1->y + src1->height, src2->y + src2->height) - dest_y; - dest->x = dest_x; - dest->y = dest_y; -} - gboolean _clutter_util_rectangle_intersection (const MtkRectangle *src1, const MtkRectangle *src2, diff --git a/mtk/mtk/mtk-rectangle.c b/mtk/mtk/mtk-rectangle.c index 9ed225027..ba2cf4a99 100644 --- a/mtk/mtk/mtk-rectangle.c +++ b/mtk/mtk/mtk-rectangle.c @@ -55,3 +55,46 @@ mtk_rectangle_equal (const MtkRectangle *src1, (src1->width == src2->width) && (src1->height == src2->height)); } + +/** + * mtk_rectangle_union: + * @rect1: a #MtkRectangle + * @rect2: another #MtkRectangle + * @dest: (out caller-allocates): an empty #MtkRectangle, to be filled + * with the coordinates of the bounding box. + * + * Computes the union of the two rectangles + */ +void +mtk_rectangle_union (const MtkRectangle *rect1, + const MtkRectangle *rect2, + MtkRectangle *dest) +{ + int dest_x, dest_y; + int dest_w, dest_h; + + dest_x = rect1->x; + dest_y = rect1->y; + dest_w = rect1->width; + dest_h = rect1->height; + + if (rect2->x < dest_x) + { + dest_w += dest_x - rect2->x; + dest_x = rect2->x; + } + if (rect2->y < dest_y) + { + dest_h += dest_y - rect2->y; + dest_y = rect2->y; + } + if (rect2->x + rect2->width > dest_x + dest_w) + dest_w = rect2->x + rect2->width - dest_x; + if (rect2->y + rect2->height > dest_y + dest_h) + dest_h = rect2->y + rect2->height - dest_y; + + dest->x = dest_x; + dest->y = dest_y; + dest->width = dest_w; + dest->height = dest_h; +} diff --git a/mtk/mtk/mtk-rectangle.h b/mtk/mtk/mtk-rectangle.h index 1588cc5f3..b29e03eab 100644 --- a/mtk/mtk/mtk-rectangle.h +++ b/mtk/mtk/mtk-rectangle.h @@ -68,3 +68,9 @@ MTK_EXPORT gboolean mtk_rectangle_equal (const MtkRectangle *src1, const MtkRectangle *src2); +/* Find the bounding box of the union of two rectangles */ +MTK_EXPORT +void mtk_rectangle_union (const MtkRectangle *rect1, + const MtkRectangle *rect2, + MtkRectangle *dest); + diff --git a/src/core/boxes.c b/src/core/boxes.c index c2227433c..4a5fc263d 100644 --- a/src/core/boxes.c +++ b/src/core/boxes.c @@ -200,47 +200,6 @@ meta_rectangle_intersect (const MetaRectangle *src1, return return_val; } -/** - * meta_rectangle_union: - * @rect1: a #MetaRectangle - * @rect2: another #MetaRectangle - * @dest: (out caller-allocates): an empty #MetaRectangle, to be filled - * with the coordinates of the bounding box. - */ -void -meta_rectangle_union (const MetaRectangle *rect1, - const MetaRectangle *rect2, - MetaRectangle *dest) -{ - int dest_x, dest_y; - int dest_w, dest_h; - - dest_x = rect1->x; - dest_y = rect1->y; - dest_w = rect1->width; - dest_h = rect1->height; - - if (rect2->x < dest_x) - { - dest_w += dest_x - rect2->x; - dest_x = rect2->x; - } - if (rect2->y < dest_y) - { - dest_h += dest_y - rect2->y; - dest_y = rect2->y; - } - if (rect2->x + rect2->width > dest_x + dest_w) - dest_w = rect2->x + rect2->width - dest_x; - if (rect2->y + rect2->height > dest_y + dest_h) - dest_h = rect2->y + rect2->height - dest_y; - - dest->x = dest_x; - dest->y = dest_y; - dest->width = dest_w; - dest->height = dest_h; -} - gboolean meta_rectangle_overlap (const MetaRectangle *rect1, const MetaRectangle *rect2) diff --git a/src/core/constraints.c b/src/core/constraints.c index 393c664a3..d902525bf 100644 --- a/src/core/constraints.c +++ b/src/core/constraints.c @@ -458,15 +458,15 @@ setup_constraint_info (MetaBackend *backend, if (window->fullscreen && meta_window_has_fullscreen_monitors (window)) { info->entire_monitor = window->fullscreen_monitors.top->rect; - meta_rectangle_union (&info->entire_monitor, - &window->fullscreen_monitors.bottom->rect, - &info->entire_monitor); - meta_rectangle_union (&info->entire_monitor, - &window->fullscreen_monitors.left->rect, - &info->entire_monitor); - meta_rectangle_union (&info->entire_monitor, - &window->fullscreen_monitors.right->rect, - &info->entire_monitor); + mtk_rectangle_union (&info->entire_monitor, + &window->fullscreen_monitors.bottom->rect, + &info->entire_monitor); + mtk_rectangle_union (&info->entire_monitor, + &window->fullscreen_monitors.left->rect, + &info->entire_monitor); + mtk_rectangle_union (&info->entire_monitor, + &window->fullscreen_monitors.right->rect, + &info->entire_monitor); if (window->fullscreen_monitors.top == logical_monitor && window->fullscreen_monitors.bottom == logical_monitor && window->fullscreen_monitors.left == logical_monitor && diff --git a/src/meta/boxes.h b/src/meta/boxes.h index 29e6c0ab7..5f562288a 100644 --- a/src/meta/boxes.h +++ b/src/meta/boxes.h @@ -122,12 +122,6 @@ gboolean meta_rectangle_intersect (const MetaRectangle *src1, const MetaRectangle *src2, MetaRectangle *dest); -/* Find the bounding box of the union of two rectangles */ -META_EXPORT -void meta_rectangle_union (const MetaRectangle *rect1, - const MetaRectangle *rect2, - MetaRectangle *dest); - /* overlap is similar to intersect but doesn't provide location of * intersection information. */ diff --git a/src/wayland/meta-wayland-subsurface.c b/src/wayland/meta-wayland-subsurface.c index 9adffcfa8..c34156678 100644 --- a/src/wayland/meta-wayland-subsurface.c +++ b/src/wayland/meta-wayland-subsurface.c @@ -127,7 +127,7 @@ meta_wayland_subsurface_union_geometry (MetaWaylandSubsurface *subsurface, }; if (surface->buffer) - meta_rectangle_union (out_geometry, &geometry, out_geometry); + mtk_rectangle_union (out_geometry, &geometry, out_geometry); META_WAYLAND_SURFACE_FOREACH_SUBSURFACE (&surface->output_state, subsurface_surface)