From 4d53e4d156bedb6b9114bb4bb9d3a9bcc2f6a9f6 Mon Sep 17 00:00:00 2001 From: Bilal Elmoussaoui Date: Mon, 8 Jan 2024 20:22:10 +0100 Subject: [PATCH] region: Move Region.crop_and_scale to Mtk Part-of: --- mtk/mtk/mtk-region.c | 48 ++++++++++++++++++++++++++++++ mtk/mtk/mtk-region.h | 6 ++++ src/compositor/region-utils.c | 48 ------------------------------ src/compositor/region-utils.h | 6 ---- src/wayland/meta-wayland-surface.c | 8 ++--- 5 files changed, 58 insertions(+), 58 deletions(-) diff --git a/mtk/mtk/mtk-region.c b/mtk/mtk/mtk-region.c index 7dd4b7b03..d132ead3d 100644 --- a/mtk/mtk/mtk-region.c +++ b/mtk/mtk/mtk-region.c @@ -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; +} diff --git a/mtk/mtk/mtk-region.h b/mtk/mtk/mtk-region.h index 3a02f03e2..f4f6dcfec 100644 --- a/mtk/mtk/mtk-region.h +++ b/mtk/mtk/mtk-region.h @@ -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) diff --git a/src/compositor/region-utils.c b/src/compositor/region-utils.c index 7efe96870..981e843c8 100644 --- a/src/compositor/region-utils.c +++ b/src/compositor/region-utils.c @@ -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) diff --git a/src/compositor/region-utils.h b/src/compositor/region-utils.h index 35311480b..7613aa9ec 100644 --- a/src/compositor/region-utils.h +++ b/src/compositor/region-utils.h @@ -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); diff --git a/src/wayland/meta-wayland-surface.c b/src/wayland/meta-wayland-surface.c index 92d8de99d..4d490a884 100644 --- a/src/wayland/meta-wayland-surface.c +++ b/src/wayland/meta-wayland-surface.c @@ -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,