From cf8eb4944aa9a3b75af61e9b1c94e0b6676f624e Mon Sep 17 00:00:00 2001 From: Bilal Elmoussaoui Date: Mon, 8 Jan 2024 20:34:26 +0100 Subject: [PATCH] region: Make make_region_border private It is only used by the shadow factory and doesn't make sense to have as part of mtk Part-of: --- src/compositor/meta-shadow-factory.c | 142 ++++++++++++++++++++++++++- src/compositor/region-utils.c | 137 -------------------------- src/compositor/region-utils.h | 5 - 3 files changed, 140 insertions(+), 144 deletions(-) diff --git a/src/compositor/meta-shadow-factory.c b/src/compositor/meta-shadow-factory.c index 25cb8f13d..192e3116f 100644 --- a/src/compositor/meta-shadow-factory.c +++ b/src/compositor/meta-shadow-factory.c @@ -699,6 +699,144 @@ flip_buffer (guchar *buffer, #undef BLOCK_SIZE } +static void +add_expanded_rect (MetaRegionBuilder *builder, + int x, + int y, + int width, + int height, + int x_amount, + int y_amount, + gboolean flip) +{ + if (flip) + meta_region_builder_add_rectangle (builder, + y - y_amount, x - x_amount, + height + 2 * y_amount, width + 2 * x_amount); + else + meta_region_builder_add_rectangle (builder, + x - x_amount, y - y_amount, + width + 2 * x_amount, height + 2 * y_amount); +} + +static MtkRegion * +expand_region (MtkRegion *region, + int x_amount, + int y_amount, + gboolean flip) +{ + MetaRegionBuilder builder; + int n; + int i; + + meta_region_builder_init (&builder); + + n = mtk_region_num_rectangles (region); + for (i = 0; i < n; i++) + { + MtkRectangle rect; + + rect = mtk_region_get_rectangle (region, i); + add_expanded_rect (&builder, + rect.x, rect.y, rect.width, rect.height, + x_amount, y_amount, flip); + } + + return meta_region_builder_finish (&builder); +} + +/* This computes a (clipped version) of the inverse of the region + * and expands it by the given amount */ +static MtkRegion * +expand_region_inverse (MtkRegion *region, + int x_amount, + int y_amount, + gboolean flip) +{ + MetaRegionBuilder builder; + MetaRegionIterator iter; + MtkRectangle extents; + int last_x; + + meta_region_builder_init (&builder); + + extents = mtk_region_get_extents (region); + add_expanded_rect (&builder, + extents.x, extents.y - 1, extents.width, 1, + x_amount, y_amount, flip); + add_expanded_rect (&builder, + extents.x - 1, extents.y, 1, extents.height, + x_amount, y_amount, flip); + add_expanded_rect (&builder, + extents.x + extents.width, extents.y, 1, extents.height, + x_amount, y_amount, flip); + add_expanded_rect (&builder, + extents.x, extents.y + extents.height, extents.width, 1, + x_amount, y_amount, flip); + + last_x = extents.x; + for (meta_region_iterator_init (&iter, region); + !meta_region_iterator_at_end (&iter); + meta_region_iterator_next (&iter)) + { + if (iter.rectangle.x > last_x) + add_expanded_rect (&builder, + last_x, iter.rectangle.y, + iter.rectangle.x - last_x, iter.rectangle.height, + x_amount, y_amount, flip); + + if (iter.line_end) + { + if (extents.x + extents.width > iter.rectangle.x + iter.rectangle.width) + add_expanded_rect (&builder, + iter.rectangle.x + iter.rectangle.width, iter.rectangle.y, + (extents.x + extents.width) - (iter.rectangle.x + iter.rectangle.width), iter.rectangle.height, + x_amount, y_amount, flip); + last_x = extents.x; + } + else + { + last_x = iter.rectangle.x + iter.rectangle.width; + } + } + + return meta_region_builder_finish (&builder); +} + +/** + * make_border_region: + * @region: a #MtkRegion + * @x_amount: distance from the border to extend horizontally + * @y_amount: distance from the border to extend vertically + * @flip: if true, the result is computed with x and y interchanged + * + * Computes the "border region" of a given region, which is roughly + * speaking the set of points near the boundary of the region. If we + * define the operation of growing a region as computing the set of + * points within a given manhattan distance of the region, then the + * border is 'grow(region) intersect grow(inverse(region))'. + * + * If we create an image by filling the region with a solid color, + * the border is the region affected by blurring the region. + * + * Return value: a new region which is the border of the given region + */ +static MtkRegion * +make_border_region (MtkRegion *region, + int x_amount, + int y_amount, + gboolean flip) +{ + g_autoptr (MtkRegion) border_region = NULL; + g_autoptr (MtkRegion) inverse_region = NULL; + + border_region = expand_region (region, x_amount, y_amount, flip); + inverse_region = expand_region_inverse (region, x_amount, y_amount, flip); + mtk_region_intersect (border_region, inverse_region); + + return g_steal_pointer (&border_region); +} + static void make_shadow (MetaShadow *shadow, MtkRegion *region) @@ -750,8 +888,8 @@ make_shadow (MetaShadow *shadow, * large shadow sizes) we can improve efficiency by restricting the blur * to the region that actually needs to be blurred. */ - row_convolve_region = meta_make_border_region (region, spread, spread, FALSE); - column_convolve_region = meta_make_border_region (region, 0, spread, TRUE); + row_convolve_region = make_border_region (region, spread, spread, FALSE); + column_convolve_region = make_border_region (region, 0, spread, TRUE); /* Offsets between coordinates of the regions and coordinates in the buffer */ x_offset = spread; diff --git a/src/compositor/region-utils.c b/src/compositor/region-utils.c index c5bf39c97..ff05f9c26 100644 --- a/src/compositor/region-utils.c +++ b/src/compositor/region-utils.c @@ -176,143 +176,6 @@ meta_region_iterator_next (MetaRegionIterator *iter) } } -static void -add_expanded_rect (MetaRegionBuilder *builder, - int x, - int y, - int width, - int height, - int x_amount, - int y_amount, - gboolean flip) -{ - if (flip) - meta_region_builder_add_rectangle (builder, - y - y_amount, x - x_amount, - height + 2 * y_amount, width + 2 * x_amount); - else - meta_region_builder_add_rectangle (builder, - x - x_amount, y - y_amount, - width + 2 * x_amount, height + 2 * y_amount); -} - -static MtkRegion * -expand_region (MtkRegion *region, - int x_amount, - int y_amount, - gboolean flip) -{ - MetaRegionBuilder builder; - int n; - int i; - - meta_region_builder_init (&builder); - - n = mtk_region_num_rectangles (region); - for (i = 0; i < n; i++) - { - MtkRectangle rect; - - rect = mtk_region_get_rectangle (region, i); - add_expanded_rect (&builder, - rect.x, rect.y, rect.width, rect.height, - x_amount, y_amount, flip); - } - - return meta_region_builder_finish (&builder); -} - -/* This computes a (clipped version) of the inverse of the region - * and expands it by the given amount */ -static MtkRegion * -expand_region_inverse (MtkRegion *region, - int x_amount, - int y_amount, - gboolean flip) -{ - MetaRegionBuilder builder; - MetaRegionIterator iter; - MtkRectangle extents; - - int last_x; - - meta_region_builder_init (&builder); - - extents = mtk_region_get_extents (region); - add_expanded_rect (&builder, - extents.x, extents.y - 1, extents.width, 1, - x_amount, y_amount, flip); - add_expanded_rect (&builder, - extents.x - 1, extents.y, 1, extents.height, - x_amount, y_amount, flip); - add_expanded_rect (&builder, - extents.x + extents.width, extents.y, 1, extents.height, - x_amount, y_amount, flip); - add_expanded_rect (&builder, - extents.x, extents.y + extents.height, extents.width, 1, - x_amount, y_amount, flip); - - last_x = extents.x; - for (meta_region_iterator_init (&iter, region); - !meta_region_iterator_at_end (&iter); - meta_region_iterator_next (&iter)) - { - if (iter.rectangle.x > last_x) - add_expanded_rect (&builder, - last_x, iter.rectangle.y, - iter.rectangle.x - last_x, iter.rectangle.height, - x_amount, y_amount, flip); - - if (iter.line_end) - { - if (extents.x + extents.width > iter.rectangle.x + iter.rectangle.width) - add_expanded_rect (&builder, - iter.rectangle.x + iter.rectangle.width, iter.rectangle.y, - (extents.x + extents.width) - (iter.rectangle.x + iter.rectangle.width), iter.rectangle.height, - x_amount, y_amount, flip); - last_x = extents.x; - } - else - last_x = iter.rectangle.x + iter.rectangle.width; - } - - return meta_region_builder_finish (&builder); -} - -/** - * meta_make_border_region: - * @region: a #MtkRegion - * @x_amount: distance from the border to extend horizontally - * @y_amount: distance from the border to extend vertically - * @flip: if true, the result is computed with x and y interchanged - * - * Computes the "border region" of a given region, which is roughly - * speaking the set of points near the boundary of the region. If we - * define the operation of growing a region as computing the set of - * points within a given manhattan distance of the region, then the - * border is 'grow(region) intersect grow(inverse(region))'. - * - * If we create an image by filling the region with a solid color, - * the border is the region affected by blurring the region. - * - * Return value: a new region which is the border of the given region - */ -MtkRegion * -meta_make_border_region (MtkRegion *region, - int x_amount, - int y_amount, - gboolean flip) -{ - g_autoptr (MtkRegion) border_region = NULL; - g_autoptr (MtkRegion) inverse_region = NULL; - - border_region = expand_region (region, x_amount, y_amount, flip); - inverse_region = expand_region_inverse (region, x_amount, y_amount, flip); - mtk_region_intersect (border_region, inverse_region); - - return g_steal_pointer (&border_region); -} - MtkRegion * meta_region_transform (const MtkRegion *region, MetaMonitorTransform transform, diff --git a/src/compositor/region-utils.h b/src/compositor/region-utils.h index c62192ffa..5651408e3 100644 --- a/src/compositor/region-utils.h +++ b/src/compositor/region-utils.h @@ -92,11 +92,6 @@ void meta_region_iterator_init (MetaRegionIterator *iter, gboolean meta_region_iterator_at_end (MetaRegionIterator *iter); void meta_region_iterator_next (MetaRegionIterator *iter); -MtkRegion * meta_make_border_region (MtkRegion *region, - int x_amount, - int y_amount, - gboolean flip); - MtkRegion * meta_region_transform (const MtkRegion *region, MetaMonitorTransform transform, int width,