region: Move Region.crop_and_scale to Mtk
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3501>
This commit is contained in:
parent
6e7d314e75
commit
4d53e4d156
@ -387,3 +387,51 @@ mtk_region_scale (MtkRegion *region,
|
|||||||
|
|
||||||
return scaled_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;
|
||||||
|
}
|
||||||
|
@ -118,4 +118,10 @@ MTK_EXPORT
|
|||||||
MtkRegion * mtk_region_scale (MtkRegion *region,
|
MtkRegion * mtk_region_scale (MtkRegion *region,
|
||||||
int scale);
|
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)
|
G_DEFINE_AUTOPTR_CLEANUP_FUNC (MtkRegion, mtk_region_unref)
|
||||||
|
@ -344,54 +344,6 @@ meta_region_transform (const MtkRegion *region,
|
|||||||
return transformed_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 *
|
MtkRegion *
|
||||||
meta_region_apply_matrix_transform_expand (const MtkRegion *region,
|
meta_region_apply_matrix_transform_expand (const MtkRegion *region,
|
||||||
graphene_matrix_t *transform)
|
graphene_matrix_t *transform)
|
||||||
|
@ -102,12 +102,6 @@ MtkRegion * meta_region_transform (const MtkRegion *region,
|
|||||||
int width,
|
int width,
|
||||||
int height);
|
int height);
|
||||||
|
|
||||||
MtkRegion * meta_region_crop_and_scale (MtkRegion *region,
|
|
||||||
graphene_rect_t *src_rect,
|
|
||||||
int dst_width,
|
|
||||||
int dst_height);
|
|
||||||
|
|
||||||
|
|
||||||
MtkRegion *
|
MtkRegion *
|
||||||
meta_region_apply_matrix_transform_expand (const MtkRegion *region,
|
meta_region_apply_matrix_transform_expand (const MtkRegion *region,
|
||||||
graphene_matrix_t *transform);
|
graphene_matrix_t *transform);
|
||||||
|
@ -331,10 +331,10 @@ surface_process_damage (MetaWaylandSurface *surface,
|
|||||||
.size.height = height / surface_scale
|
.size.height = height / surface_scale
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
viewport_region = meta_region_crop_and_scale (surface_region,
|
viewport_region = mtk_region_crop_and_scale (surface_region,
|
||||||
&src_rect,
|
&src_rect,
|
||||||
surface_rect.width,
|
surface_rect.width,
|
||||||
surface_rect.height);
|
surface_rect.height);
|
||||||
scaled_region = mtk_region_scale (viewport_region, surface_scale);
|
scaled_region = mtk_region_scale (viewport_region, surface_scale);
|
||||||
transformed_region = meta_region_transform (scaled_region,
|
transformed_region = meta_region_transform (scaled_region,
|
||||||
surface->buffer_transform,
|
surface->buffer_transform,
|
||||||
|
Loading…
Reference in New Issue
Block a user