From 640b4b1c99ed806e4775635ba92a95106e437481 Mon Sep 17 00:00:00 2001 From: Yuxuan Shui Date: Sat, 6 Jul 2019 13:26:25 +0100 Subject: [PATCH] Move resize_region to region.h Signed-off-by: Yuxuan Shui --- src/region.h | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/render.c | 33 +-------------------------------- 2 files changed, 52 insertions(+), 32 deletions(-) diff --git a/src/region.h b/src/region.h index a056c80..bda66e2 100644 --- a/src/region.h +++ b/src/region.h @@ -47,3 +47,54 @@ static inline rect_t *from_x_rects(int nrects, const xcb_rectangle_t *rects) { } return ret; } + +/** + * Resize a region. + */ +static inline void _resize_region(const region_t *region, region_t *output, int dx, + int dy) { + if (!region || !output) { + return; + } + if (!dx && !dy) { + if (region != output) { + pixman_region32_copy(output, (region_t *)region); + } + return; + } + // Loop through all rectangles + int nrects; + int nnewrects = 0; + const rect_t *rects = pixman_region32_rectangles((region_t *)region, &nrects); + auto newrects = ccalloc(nrects, rect_t); + for (int i = 0; i < nrects; i++) { + int x1 = rects[i].x1 - dx; + int y1 = rects[i].y1 - dy; + int x2 = rects[i].x2 + dx; + int y2 = rects[i].y2 + dy; + int wid = x2 - x1; + int hei = y2 - y1; + if (wid <= 0 || hei <= 0) { + continue; + } + newrects[nnewrects] = + (rect_t){.x1 = x1, .x2 = x2, .y1 = y1, .y2 = y2}; + ++nnewrects; + } + + pixman_region32_fini(output); + pixman_region32_init_rects(output, newrects, nnewrects); + + free(newrects); +} + +static inline region_t resize_region(const region_t *region, int dx, int dy) { + region_t ret; + pixman_region32_init(&ret); + _resize_region(region, &ret, dx, dy); + return ret; +} + +static inline void resize_region_in_place(region_t *region, int dx, int dy) { + return _resize_region(region, region, dx, dy); +} diff --git a/src/render.c b/src/render.c index b4fa733..d64ed27 100644 --- a/src/render.c +++ b/src/render.c @@ -740,37 +740,6 @@ win_blur_background(session_t *ps, struct managed_win *w, xcb_render_picture_t t } } -/** - * Resize a region. - */ -static inline void resize_region(region_t *region, short mod) { - if (!mod || !region) - return; - // Loop through all rectangles - int nrects; - int nnewrects = 0; - pixman_box32_t *rects = pixman_region32_rectangles(region, &nrects); - auto newrects = ccalloc(nrects, pixman_box32_t); - for (int i = 0; i < nrects; i++) { - int x1 = rects[i].x1 - mod; - int y1 = rects[i].y1 - mod; - int x2 = rects[i].x2 + mod; - int y2 = rects[i].y2 + mod; - int wid = x2 - x1; - int hei = y2 - y1; - if (wid <= 0 || hei <= 0) - continue; - newrects[nnewrects] = - (pixman_box32_t){.x1 = x1, .x2 = x2, .y1 = y1, .y2 = y2}; - ++nnewrects; - } - - pixman_region32_fini(region); - pixman_region32_init_rects(region, newrects, nnewrects); - - free(newrects); -} - /// paint all windows /// region = ?? /// region_real = the damage region @@ -807,7 +776,7 @@ void paint_all(session_t *ps, struct managed_win *t, bool ignore_damage) { #endif if (ps->o.resize_damage > 0) { - resize_region(®ion, (short)ps->o.resize_damage); + resize_region_in_place(®ion, ps->o.resize_damage, ps->o.resize_damage); } // Remove the damaged area out of screen