diff --git a/mtk/mtk/mtk-region.c b/mtk/mtk/mtk-region.c index 78651efea..98579a4f7 100644 --- a/mtk/mtk/mtk-region.c +++ b/mtk/mtk/mtk-region.c @@ -468,3 +468,50 @@ mtk_region_apply_matrix_transform_expand (const MtkRegion *region, return transformed_region; } + +void +mtk_region_iterator_init (MtkRegionIterator *iter, + MtkRegion *region) +{ + iter->region = region; + iter->i = 0; + iter->n_rectangles = mtk_region_num_rectangles (region); + iter->line_start = TRUE; + + if (iter->n_rectangles > 1) + { + iter->rectangle = mtk_region_get_rectangle (region, 0); + iter->next_rectangle = mtk_region_get_rectangle (region, 1); + + iter->line_end = iter->next_rectangle.y != iter->rectangle.y; + } + else if (iter->n_rectangles > 0) + { + iter->rectangle = mtk_region_get_rectangle (region, 0); + iter->line_end = TRUE; + } +} + +gboolean +mtk_region_iterator_at_end (MtkRegionIterator *iter) +{ + return iter->i >= iter->n_rectangles; +} + +void +mtk_region_iterator_next (MtkRegionIterator *iter) +{ + iter->i++; + iter->rectangle = iter->next_rectangle; + iter->line_start = iter->line_end; + + if (iter->i + 1 < iter->n_rectangles) + { + iter->next_rectangle = mtk_region_get_rectangle (iter->region, iter->i + 1); + iter->line_end = iter->next_rectangle.y != iter->rectangle.y; + } + else + { + iter->line_end = TRUE; + } +} diff --git a/mtk/mtk/mtk-region.h b/mtk/mtk/mtk-region.h index 831a583bd..7a4e0154e 100644 --- a/mtk/mtk/mtk-region.h +++ b/mtk/mtk/mtk-region.h @@ -129,3 +129,50 @@ MtkRegion * mtk_region_apply_matrix_transform_expand (const MtkRegion *region, graphene_matrix_t *transform); G_DEFINE_AUTOPTR_CLEANUP_FUNC (MtkRegion, mtk_region_unref) + +/** + * MtkRegionIterator: + * @region: region being iterated + * @rectangle: current rectangle + * @line_start: whether the current rectangle starts a horizontal band + * @line_end: whether the current rectangle ends a horizontal band + * + * MtkRegion is a yx banded region; sometimes its useful to iterate through + * such a region treating the start and end of each horizontal band in a distinct + * fashion. + * + * Usage: + * + * ```c + * MtkRegionIterator iter; + * for (mtk_region_iterator_init (&iter, region); + * !mtk_region_iterator_at_end (&iter); + * mtk_region_iterator_next (&iter)) + * { + * [ Use iter.rectangle, iter.line_start, iter.line_end ] + * } + *``` + */ +typedef struct MtkaRegionIterator MtkRegionIterator; + +struct MtkaRegionIterator { + MtkRegion *region; + MtkRectangle rectangle; + gboolean line_start; + gboolean line_end; + int i; + + /*< private >*/ + int n_rectangles; + MtkRectangle next_rectangle; +}; + +MTK_EXPORT +void mtk_region_iterator_init (MtkRegionIterator *iter, + MtkRegion *region); + +MTK_EXPORT +gboolean mtk_region_iterator_at_end (MtkRegionIterator *iter); + +MTK_EXPORT +void mtk_region_iterator_next (MtkRegionIterator *iter); diff --git a/src/compositor/meta-shadow-factory.c b/src/compositor/meta-shadow-factory.c index 192e3116f..1483c3991 100644 --- a/src/compositor/meta-shadow-factory.c +++ b/src/compositor/meta-shadow-factory.c @@ -754,7 +754,7 @@ expand_region_inverse (MtkRegion *region, gboolean flip) { MetaRegionBuilder builder; - MetaRegionIterator iter; + MtkRegionIterator iter; MtkRectangle extents; int last_x; @@ -775,9 +775,9 @@ expand_region_inverse (MtkRegion *region, 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)) + for (mtk_region_iterator_init (&iter, region); + !mtk_region_iterator_at_end (&iter); + mtk_region_iterator_next (&iter)) { if (iter.rectangle.x > last_x) add_expanded_rect (&builder, diff --git a/src/compositor/meta-window-shape.c b/src/compositor/meta-window-shape.c index 709de869c..ceedbc52f 100644 --- a/src/compositor/meta-window-shape.c +++ b/src/compositor/meta-window-shape.c @@ -27,7 +27,7 @@ #include -#include "compositor/region-utils.h" +#include "mtk/mtk-region.h" struct _MetaWindowShape { @@ -43,7 +43,7 @@ MetaWindowShape * meta_window_shape_new (MtkRegion *region) { MetaWindowShape *shape; - MetaRegionIterator iter; + MtkRegionIterator iter; MtkRectangle extents; int max_yspan_y1 = 0; int max_yspan_y2 = 0; @@ -66,9 +66,9 @@ meta_window_shape_new (MtkRegion *region) return shape; } - for (meta_region_iterator_init (&iter, region); - !meta_region_iterator_at_end (&iter); - meta_region_iterator_next (&iter)) + for (mtk_region_iterator_init (&iter, region); + !mtk_region_iterator_at_end (&iter); + mtk_region_iterator_next (&iter)) { int max_line_xspan_x1 = -1; int max_line_xspan_x2 = -1; @@ -117,9 +117,9 @@ meta_window_shape_new (MtkRegion *region) shape->rectangles = g_new (MtkRectangle, shape->n_rectangles); hash = 0; - for (meta_region_iterator_init (&iter, region); - !meta_region_iterator_at_end (&iter); - meta_region_iterator_next (&iter)) + for (mtk_region_iterator_init (&iter, region); + !mtk_region_iterator_at_end (&iter); + mtk_region_iterator_next (&iter)) { int x1, x2, y1, y2; diff --git a/src/compositor/region-utils.c b/src/compositor/region-utils.c index ff05f9c26..d837bae4b 100644 --- a/src/compositor/region-utils.c +++ b/src/compositor/region-utils.c @@ -126,56 +126,6 @@ meta_region_builder_finish (MetaRegionBuilder *builder) return result; } - -/* MetaRegionIterator */ - -void -meta_region_iterator_init (MetaRegionIterator *iter, - MtkRegion *region) -{ - iter->region = region; - iter->i = 0; - iter->n_rectangles = mtk_region_num_rectangles (region); - iter->line_start = TRUE; - - if (iter->n_rectangles > 1) - { - iter->rectangle = mtk_region_get_rectangle (region, 0); - iter->next_rectangle = mtk_region_get_rectangle (region, 1); - - iter->line_end = iter->next_rectangle.y != iter->rectangle.y; - } - else if (iter->n_rectangles > 0) - { - iter->rectangle = mtk_region_get_rectangle (region, 0); - iter->line_end = TRUE; - } -} - -gboolean -meta_region_iterator_at_end (MetaRegionIterator *iter) -{ - return iter->i >= iter->n_rectangles; -} - -void -meta_region_iterator_next (MetaRegionIterator *iter) -{ - iter->i++; - iter->rectangle = iter->next_rectangle; - iter->line_start = iter->line_end; - - if (iter->i + 1 < iter->n_rectangles) - { - iter->next_rectangle = mtk_region_get_rectangle (iter->region, iter->i + 1); - iter->line_end = iter->next_rectangle.y != iter->rectangle.y; - } - else - { - iter->line_end = TRUE; - } -} - MtkRegion * meta_region_transform (const MtkRegion *region, MetaMonitorTransform transform, diff --git a/src/compositor/region-utils.h b/src/compositor/region-utils.h index 5651408e3..21df0795c 100644 --- a/src/compositor/region-utils.h +++ b/src/compositor/region-utils.h @@ -26,41 +26,6 @@ #include "clutter/clutter.h" #include "core/boxes-private.h" -/** - * MetaRegionIterator: - * @region: region being iterated - * @rectangle: current rectangle - * @line_start: whether the current rectangle starts a horizontal band - * @line_end: whether the current rectangle ends a horizontal band - * - * MtkRegion is a yx banded region; sometimes its useful to iterate through - * such a region treating the start and end of each horizontal band in a distinct - * fashion. - * - * Usage: - * - * MetaRegionIterator iter; - * for (meta_region_iterator_init (&iter, region); - * !meta_region_iterator_at_end (&iter); - * meta_region_iterator_next (&iter)) - * { - * [ Use iter.rectangle, iter.line_start, iter.line_end ] - * } - */ -typedef struct _MetaRegionIterator MetaRegionIterator; - -struct _MetaRegionIterator { - MtkRegion *region; - MtkRectangle rectangle; - gboolean line_start; - gboolean line_end; - int i; - - /*< private >*/ - int n_rectangles; - MtkRectangle next_rectangle; -}; - typedef struct _MetaRegionBuilder MetaRegionBuilder; #define META_REGION_BUILDER_MAX_LEVELS 16 @@ -87,11 +52,6 @@ void meta_region_builder_add_rectangle (MetaRegionBuilder *builder, int height); MtkRegion * meta_region_builder_finish (MetaRegionBuilder *builder); -void meta_region_iterator_init (MetaRegionIterator *iter, - MtkRegion *region); -gboolean meta_region_iterator_at_end (MetaRegionIterator *iter); -void meta_region_iterator_next (MetaRegionIterator *iter); - MtkRegion * meta_region_transform (const MtkRegion *region, MetaMonitorTransform transform, int width,