mirror of
https://github.com/brl/mutter.git
synced 2024-11-25 01:20:42 -05:00
region-utils: Add API to crop and scale an integer region
https://gitlab.gnome.org/GNOME/mutter/merge_requests/323
This commit is contained in:
parent
d574cf59f1
commit
07e65a6ef2
@ -408,3 +408,51 @@ meta_region_transform (cairo_region_t *region,
|
||||
|
||||
return transformed_region;
|
||||
}
|
||||
|
||||
cairo_region_t *
|
||||
meta_region_crop_and_scale (cairo_region_t *region,
|
||||
ClutterRect *src_rect,
|
||||
int dst_width,
|
||||
int dst_height)
|
||||
{
|
||||
int n_rects, i;
|
||||
cairo_rectangle_int_t *rects;
|
||||
cairo_region_t *viewport_region;
|
||||
|
||||
if (src_rect->size.width == dst_width &&
|
||||
src_rect->size.height == dst_height &&
|
||||
roundf (src_rect->origin.x) == src_rect->origin.x &&
|
||||
roundf (src_rect->origin.y) == src_rect->origin.y)
|
||||
{
|
||||
viewport_region = cairo_region_copy (region);
|
||||
|
||||
if (src_rect->origin.x != 0 || src_rect->origin.y != 0)
|
||||
{
|
||||
cairo_region_translate (viewport_region,
|
||||
(int) src_rect->origin.x,
|
||||
(int) src_rect->origin.y);
|
||||
}
|
||||
|
||||
return viewport_region;
|
||||
}
|
||||
|
||||
n_rects = cairo_region_num_rectangles (region);
|
||||
|
||||
rects = g_new0 (cairo_rectangle_int_t, n_rects);
|
||||
for (i = 0; i < n_rects; i++)
|
||||
{
|
||||
cairo_region_get_rectangle (region, i, &rects[i]);
|
||||
|
||||
meta_rectangle_crop_and_scale (&rects[i],
|
||||
src_rect,
|
||||
dst_width,
|
||||
dst_height,
|
||||
&rects[i]);
|
||||
}
|
||||
|
||||
viewport_region = cairo_region_create_rectangles (rects, n_rects);
|
||||
|
||||
g_free (rects);
|
||||
|
||||
return viewport_region;
|
||||
}
|
||||
|
@ -111,4 +111,9 @@ cairo_region_t * meta_region_transform (cairo_region_t *region,
|
||||
int width,
|
||||
int height);
|
||||
|
||||
cairo_region_t * meta_region_crop_and_scale (cairo_region_t *region,
|
||||
ClutterRect *src_rect,
|
||||
int dst_width,
|
||||
int dst_height);
|
||||
|
||||
#endif /* __META_REGION_UTILS_H__ */
|
||||
|
Loading…
Reference in New Issue
Block a user