Commit 07e65a6e authored by Robert Mader's avatar Robert Mader Committed by Jonas Ådahl

region-utils: Add API to crop and scale an integer region

GNOME/mutter!323
parent d574cf59
......@@ -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__ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment