Skip to content

Commit

Permalink
event: use dynarr for expose_rects
Browse files Browse the repository at this point in the history
Signed-off-by: Yuxuan Shui <[email protected]>
  • Loading branch information
yshui committed Jun 4, 2024
1 parent 48dd0cf commit 5e16eed
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 28 deletions.
7 changes: 2 additions & 5 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,12 +272,9 @@ typedef struct session {

// === Expose event related ===
/// Pointer to an array of <code>XRectangle</code>-s of exposed region.
/// XXX why do we need this array?
/// This is a reuse temporary buffer for handling root expose events.
/// This is a dynarr.
rect_t *expose_rects;
/// Number of <code>XRectangle</code>-s in <code>expose_rects</code>.
int size_expose;
/// Index of the next free slot in <code>expose_rects</code>.
int n_expose;

struct wm *wm;

Expand Down
33 changes: 13 additions & 20 deletions src/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "log.h"
#include "picom.h"
#include "region.h"
#include "utils/dynarr.h"
#include "utils/misc.h"
#include "wm/defs.h"
#include "wm/wm.h"
Expand Down Expand Up @@ -495,37 +496,29 @@ static inline void ev_circulate_notify(session_t *ps, xcb_circulate_notify_event
}
}

static inline void expose_root(session_t *ps, const rect_t *rects, int nrects) {
static inline void expose_root(session_t *ps, const rect_t *rects, size_t nrects) {
region_t region;
pixman_region32_init_rects(&region, rects, nrects);
pixman_region32_init_rects(&region, rects, (int)nrects);
add_damage(ps, &region);
pixman_region32_fini(&region);
}

static inline void ev_expose(session_t *ps, xcb_expose_event_t *ev) {
if (ev->window == ps->c.screen_info->root ||
(ps->overlay && ev->window == ps->overlay)) {
int more = ev->count + 1;
if (ps->n_expose == ps->size_expose) {
if (ps->expose_rects) {
ps->expose_rects =
crealloc(ps->expose_rects, ps->size_expose + more);
ps->size_expose += more;
} else {
ps->expose_rects = ccalloc(more, rect_t);
ps->size_expose = more;
}
}
dynarr_reserve(ps->expose_rects, ev->count + 1);

ps->expose_rects[ps->n_expose].x1 = ev->x;
ps->expose_rects[ps->n_expose].y1 = ev->y;
ps->expose_rects[ps->n_expose].x2 = ev->x + ev->width;
ps->expose_rects[ps->n_expose].y2 = ev->y + ev->height;
ps->n_expose++;
rect_t new_rect = {
.x1 = ev->x,
.y1 = ev->y,
.x2 = ev->x + ev->width,
.y2 = ev->y + ev->height,
};
dynarr_push(ps->expose_rects, new_rect);

if (ev->count == 0) {
expose_root(ps, ps->expose_rects, ps->n_expose);
ps->n_expose = 0;
expose_root(ps, ps->expose_rects, dynarr_len(ps->expose_rects));
dynarr_clear_pod(ps->expose_rects);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/picom.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
#include "renderer/command_builder.h"
#include "renderer/layout.h"
#include "renderer/renderer.h"
#include "utils/dynarr.h"
#include "utils/file_watch.h"
#include "utils/kernel.h"
#include "utils/list.h"
Expand Down Expand Up @@ -2020,8 +2021,6 @@ static session_t *session_init(int argc, char **argv, Display *dpy,
.quit = false,

.expose_rects = NULL,
.size_expose = 0,
.n_expose = 0,

.black_picture = XCB_NONE,
.cshadow_picture = XCB_NONE,
Expand Down Expand Up @@ -2521,6 +2520,7 @@ static session_t *session_init(int argc, char **argv, Display *dpy,
}

ps->command_builder = command_builder_new();
ps->expose_rects = dynarr_new(rect_t, 0);

ps->pending_updates = true;

Expand Down Expand Up @@ -2591,7 +2591,7 @@ static void session_destroy(session_t *ps) {
free_paint(ps, &ps->tgt_buffer);

pixman_region32_fini(&ps->screen_reg);
free(ps->expose_rects);
dynarr_free_pod(ps->expose_rects);

x_free_monitor_info(&ps->monitors);

Expand Down

0 comments on commit 5e16eed

Please sign in to comment.