mirror of
https://github.com/brl/mutter.git
synced 2024-11-25 09:30:45 -05:00
region: Move RegionIterator to Mtk
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3501>
This commit is contained in:
parent
cf8eb4944a
commit
9953704ceb
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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,
|
||||
|
@ -27,7 +27,7 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#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;
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user