compositor: Add utility function to convert region to cairo_t path

We were relying on gdk_cairo_region() to convert a cairo_region_t
into a path ready to fill/stroke in a cairo_t. This is a small
and detached helper that we can do ourselves, so put it together
with all other region helper functions.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2864>
This commit is contained in:
Carlos Garnacho 2023-02-16 14:11:18 +01:00 committed by Marge Bot
parent ab9ea61d3d
commit 1fbbb73343
3 changed files with 21 additions and 2 deletions

View File

@ -812,7 +812,7 @@ build_and_scan_frame_mask (MetaWindowActorX11 *actor_x11,
stride); stride);
cr = cairo_create (image); cr = cairo_create (image);
gdk_cairo_region (cr, shape_region); meta_region_to_cairo_path (shape_region, cr);
cairo_fill (cr); cairo_fill (cr);
if (window->frame) if (window->frame)
@ -843,7 +843,7 @@ build_and_scan_frame_mask (MetaWindowActorX11 *actor_x11,
frame_paint_region = cairo_region_create_rectangle (&rect); frame_paint_region = cairo_region_create_rectangle (&rect);
cairo_region_subtract_rectangle (frame_paint_region, &client_area); cairo_region_subtract_rectangle (frame_paint_region, &client_area);
gdk_cairo_region (cr, frame_paint_region); meta_region_to_cairo_path (frame_paint_region, cr);
cairo_clip (cr); cairo_clip (cr);
meta_frame_get_mask (window->frame, &frame_rect, cr); meta_frame_get_mask (window->frame, &frame_rect, cr);

View File

@ -456,3 +456,19 @@ meta_region_crop_and_scale (cairo_region_t *region,
return viewport_region; return viewport_region;
} }
void
meta_region_to_cairo_path (cairo_region_t *region,
cairo_t *cr)
{
cairo_rectangle_int_t rect;
int n_rects, i;
n_rects = cairo_region_num_rectangles (region);
for (i = 0; i < n_rects; i++)
{
cairo_region_get_rectangle (region, i, &rect);
cairo_rectangle (cr, rect.x, rect.y, rect.width, rect.height);
}
}

View File

@ -116,4 +116,7 @@ cairo_region_t * meta_region_crop_and_scale (cairo_region_t *region,
int dst_width, int dst_width,
int dst_height); int dst_height);
void meta_region_to_cairo_path (cairo_region_t *region,
cairo_t *cr);
#endif /* __META_REGION_UTILS_H__ */ #endif /* __META_REGION_UTILS_H__ */