From 1fbbb73343da9698a125302928320947cade5c89 Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Thu, 16 Feb 2023 14:11:18 +0100 Subject: [PATCH] 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: --- src/compositor/meta-window-actor-x11.c | 4 ++-- src/compositor/region-utils.c | 16 ++++++++++++++++ src/compositor/region-utils.h | 3 +++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/compositor/meta-window-actor-x11.c b/src/compositor/meta-window-actor-x11.c index 919984054..bdca02eb9 100644 --- a/src/compositor/meta-window-actor-x11.c +++ b/src/compositor/meta-window-actor-x11.c @@ -812,7 +812,7 @@ build_and_scan_frame_mask (MetaWindowActorX11 *actor_x11, stride); cr = cairo_create (image); - gdk_cairo_region (cr, shape_region); + meta_region_to_cairo_path (shape_region, cr); cairo_fill (cr); if (window->frame) @@ -843,7 +843,7 @@ build_and_scan_frame_mask (MetaWindowActorX11 *actor_x11, frame_paint_region = cairo_region_create_rectangle (&rect); 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); meta_frame_get_mask (window->frame, &frame_rect, cr); diff --git a/src/compositor/region-utils.c b/src/compositor/region-utils.c index ac4048a98..e00f123d3 100644 --- a/src/compositor/region-utils.c +++ b/src/compositor/region-utils.c @@ -456,3 +456,19 @@ meta_region_crop_and_scale (cairo_region_t *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); + } +} diff --git a/src/compositor/region-utils.h b/src/compositor/region-utils.h index 298c5540e..a3b89f994 100644 --- a/src/compositor/region-utils.h +++ b/src/compositor/region-utils.h @@ -116,4 +116,7 @@ cairo_region_t * meta_region_crop_and_scale (cairo_region_t *region, int dst_width, int dst_height); +void meta_region_to_cairo_path (cairo_region_t *region, + cairo_t *cr); + #endif /* __META_REGION_UTILS_H__ */