1
0
Fork 0

region: Move Region.crop_and_scale to Mtk

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3501>
This commit is contained in:
Bilal Elmoussaoui 2024-01-08 20:22:10 +01:00 committed by Marge Bot
parent 6e7d314e75
commit 4d53e4d156
5 changed files with 58 additions and 58 deletions

View file

@ -387,3 +387,51 @@ mtk_region_scale (MtkRegion *region,
return scaled_region;
}
MtkRegion *
mtk_region_crop_and_scale (MtkRegion *region,
graphene_rect_t *src_rect,
int dst_width,
int dst_height)
{
int n_rects, i;
MtkRectangle *rects;
MtkRegion *viewport_region;
if (G_APPROX_VALUE (src_rect->size.width, dst_width, FLT_EPSILON) &&
G_APPROX_VALUE (src_rect->size.height, dst_height, FLT_EPSILON) &&
G_APPROX_VALUE (roundf (src_rect->origin.x),
src_rect->origin.x, FLT_EPSILON) &&
G_APPROX_VALUE (roundf (src_rect->origin.y),
src_rect->origin.y, FLT_EPSILON))
{
viewport_region = mtk_region_copy (region);
if (!G_APPROX_VALUE (src_rect->origin.x, 0, FLT_EPSILON) ||
!G_APPROX_VALUE (src_rect->origin.y, 0, FLT_EPSILON))
{
mtk_region_translate (viewport_region,
(int) src_rect->origin.x,
(int) src_rect->origin.y);
}
return viewport_region;
}
n_rects = mtk_region_num_rectangles (region);
MTK_RECTANGLE_CREATE_ARRAY_SCOPED (n_rects, rects);
for (i = 0; i < n_rects; i++)
{
rects[i] = mtk_region_get_rectangle (region, i);
mtk_rectangle_crop_and_scale (&rects[i],
src_rect,
dst_width,
dst_height,
&rects[i]);
}
viewport_region = mtk_region_create_rectangles (rects, n_rects);
return viewport_region;
}

View file

@ -118,4 +118,10 @@ MTK_EXPORT
MtkRegion * mtk_region_scale (MtkRegion *region,
int scale);
MTK_EXPORT
MtkRegion * mtk_region_crop_and_scale (MtkRegion *region,
graphene_rect_t *src_rect,
int dst_width,
int dst_height);
G_DEFINE_AUTOPTR_CLEANUP_FUNC (MtkRegion, mtk_region_unref)

View file

@ -344,54 +344,6 @@ meta_region_transform (const MtkRegion *region,
return transformed_region;
}
MtkRegion *
meta_region_crop_and_scale (MtkRegion *region,
graphene_rect_t *src_rect,
int dst_width,
int dst_height)
{
int n_rects, i;
MtkRectangle *rects;
MtkRegion *viewport_region;
if (G_APPROX_VALUE (src_rect->size.width, dst_width, FLT_EPSILON) &&
G_APPROX_VALUE (src_rect->size.height, dst_height, FLT_EPSILON) &&
G_APPROX_VALUE (roundf (src_rect->origin.x),
src_rect->origin.x, FLT_EPSILON) &&
G_APPROX_VALUE (roundf (src_rect->origin.y),
src_rect->origin.y, FLT_EPSILON))
{
viewport_region = mtk_region_copy (region);
if (!G_APPROX_VALUE (src_rect->origin.x, 0, FLT_EPSILON) ||
!G_APPROX_VALUE (src_rect->origin.y, 0, FLT_EPSILON))
{
mtk_region_translate (viewport_region,
(int) src_rect->origin.x,
(int) src_rect->origin.y);
}
return viewport_region;
}
n_rects = mtk_region_num_rectangles (region);
MTK_RECTANGLE_CREATE_ARRAY_SCOPED (n_rects, rects);
for (i = 0; i < n_rects; i++)
{
rects[i] = mtk_region_get_rectangle (region, i);
mtk_rectangle_crop_and_scale (&rects[i],
src_rect,
dst_width,
dst_height,
&rects[i]);
}
viewport_region = mtk_region_create_rectangles (rects, n_rects);
return viewport_region;
}
MtkRegion *
meta_region_apply_matrix_transform_expand (const MtkRegion *region,
graphene_matrix_t *transform)

View file

@ -102,12 +102,6 @@ MtkRegion * meta_region_transform (const MtkRegion *region,
int width,
int height);
MtkRegion * meta_region_crop_and_scale (MtkRegion *region,
graphene_rect_t *src_rect,
int dst_width,
int dst_height);
MtkRegion *
meta_region_apply_matrix_transform_expand (const MtkRegion *region,
graphene_matrix_t *transform);

View file

@ -331,10 +331,10 @@ surface_process_damage (MetaWaylandSurface *surface,
.size.height = height / surface_scale
};
}
viewport_region = meta_region_crop_and_scale (surface_region,
&src_rect,
surface_rect.width,
surface_rect.height);
viewport_region = mtk_region_crop_and_scale (surface_region,
&src_rect,
surface_rect.width,
surface_rect.height);
scaled_region = mtk_region_scale (viewport_region, surface_scale);
transformed_region = meta_region_transform (scaled_region,
surface->buffer_transform,