Skip to content

Commit

Permalink
Move resize_region to region.h
Browse files Browse the repository at this point in the history
Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
  • Loading branch information
yshui committed Jul 6, 2019
1 parent 387e247 commit 640b4b1
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 32 deletions.
51 changes: 51 additions & 0 deletions src/region.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
33 changes: 1 addition & 32 deletions src/render.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(&region, (short)ps->o.resize_damage);
resize_region_in_place(&region, ps->o.resize_damage, ps->o.resize_damage);
}

// Remove the damaged area out of screen
Expand Down

0 comments on commit 640b4b1

Please sign in to comment.