boxes: Move Rectangle.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-06 19:36:22 +01:00 committed by Marge Bot
parent abe47769b7
commit 59457dff81
6 changed files with 36 additions and 35 deletions

View File

@ -349,3 +349,22 @@ mtk_rectangle_from_graphene_rect (const graphene_rect_t *rect,
} }
} }
} }
void
mtk_rectangle_crop_and_scale (const MtkRectangle *rect,
const graphene_rect_t *src_rect,
int dst_width,
int dst_height,
MtkRectangle *dest)
{
graphene_rect_t tmp = GRAPHENE_RECT_INIT (rect->x, rect->y,
rect->width, rect->height);
graphene_rect_scale (&tmp,
src_rect->size.width / dst_width,
src_rect->size.height / dst_height,
&tmp);
graphene_rect_offset (&tmp, src_rect->origin.x, src_rect->origin.y);
mtk_rectangle_from_graphene_rect (&tmp, MTK_ROUNDING_STRATEGY_GROW, dest);
}

View File

@ -124,3 +124,9 @@ void mtk_rectangle_from_graphene_rect (const graphene_rect_t *rect,
MtkRoundingStrategy rounding_strategy, MtkRoundingStrategy rounding_strategy,
MtkRectangle *dest); MtkRectangle *dest);
MTK_EXPORT
void mtk_rectangle_crop_and_scale (const MtkRectangle *rect,
const graphene_rect_t *src_rect,
int dst_width,
int dst_height,
MtkRectangle *dest);

View File

@ -1113,7 +1113,7 @@ meta_shaped_texture_update_area (MetaShapedTexture *stex,
inverted_dst_width = ceilf (viewport.size.width); inverted_dst_width = ceilf (viewport.size.width);
inverted_dst_height = ceilf (viewport.size.height); inverted_dst_height = ceilf (viewport.size.height);
meta_rectangle_crop_and_scale (clip, mtk_rectangle_crop_and_scale (clip,
&inverted_viewport, &inverted_viewport,
inverted_dst_width, inverted_dst_width,
inverted_dst_height, inverted_dst_height,

View File

@ -416,7 +416,7 @@ meta_region_crop_and_scale (MtkRegion *region,
{ {
rects[i] = mtk_region_get_rectangle (region, i); rects[i] = mtk_region_get_rectangle (region, i);
meta_rectangle_crop_and_scale (&rects[i], mtk_rectangle_crop_and_scale (&rects[i],
src_rect, src_rect,
dst_width, dst_width,
dst_height, dst_height,

View File

@ -253,9 +253,3 @@ void meta_rectangle_transform (const MtkRectangle *rect,
int width, int width,
int height, int height,
MtkRectangle *dest); MtkRectangle *dest);
void meta_rectangle_crop_and_scale (const MtkRectangle *rect,
graphene_rect_t *src_rect,
int dst_width,
int dst_height,
MtkRectangle *dest);

View File

@ -1946,21 +1946,3 @@ meta_rectangle_transform (const MtkRectangle *rect,
} }
} }
void
meta_rectangle_crop_and_scale (const MtkRectangle *rect,
graphene_rect_t *src_rect,
int dst_width,
int dst_height,
MtkRectangle *dest)
{
graphene_rect_t tmp = GRAPHENE_RECT_INIT (rect->x, rect->y,
rect->width, rect->height);
graphene_rect_scale (&tmp,
src_rect->size.width / dst_width,
src_rect->size.height / dst_height,
&tmp);
graphene_rect_offset (&tmp, src_rect->origin.x, src_rect->origin.y);
mtk_rectangle_from_graphene_rect (&tmp, MTK_ROUNDING_STRATEGY_GROW, dest);
}