From e17445bb43726c8bf35f1e1a384dd98d51f3834d Mon Sep 17 00:00:00 2001 From: Miles Breslin Date: Mon, 18 Jan 2021 16:01:20 -0800 Subject: [PATCH] Simpler damage implementation --- Makefile | 2 +- dwl.c | 43 +++++++++++++++---------------------------- 2 files changed, 16 insertions(+), 29 deletions(-) diff --git a/Makefile b/Makefile index 81bf017..a0d1cc3 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ CFLAGS += -I. -DWLR_USE_UNSTABLE -std=c99 WAYLAND_PROTOCOLS=$(shell pkg-config --variable=pkgdatadir wayland-protocols) WAYLAND_SCANNER=$(shell pkg-config --variable=wayland_scanner wayland-scanner) -PKGS = wlroots wayland-server xcb xkbcommon libinput pixman-1 +PKGS = wlroots wayland-server xcb xkbcommon libinput CFLAGS += $(foreach p,$(PKGS),$(shell pkg-config --cflags $(p))) LDLIBS += $(foreach p,$(PKGS),$(shell pkg-config --libs $(p))) diff --git a/dwl.c b/dwl.c index 722da7d..e3e8516 100644 --- a/dwl.c +++ b/dwl.c @@ -26,7 +26,6 @@ #include #include #include -#include #include #include #include @@ -147,7 +146,6 @@ typedef struct { struct wlr_box geo; enum zwlr_layer_shell_v1_layer layer; - Monitor *mon; } LayerSurface; typedef struct { @@ -178,7 +176,7 @@ struct Monitor { double mfact; int nmaster; Client *fullscreenclient; - struct wlr_output_damage *damage; + int isdamaged; }; typedef struct { @@ -773,8 +771,7 @@ commitlayersurfacenotify(struct wl_listener *listener, void *data) layersurface->layer = wlr_layer_surface->current.layer; } - // Damage the whole screen - wlr_output_damage_add_whole(m->damage); + m->isdamaged = true; } void @@ -786,9 +783,8 @@ commitnotify(struct wl_listener *listener, void *data) if (c->resize && c->resize <= c->surface.xdg->configure_serial) c->resize = 0; - // Damage the whole screen if (c->mon) - wlr_output_damage_add_whole(c->mon->damage); + c->mon->isdamaged = true; } void @@ -833,7 +829,7 @@ createmon(struct wl_listener *listener, void *data) /* Initialize monitor state using configured rules */ for (size_t i = 0; i < LENGTH(m->layers); i++) wl_list_init(&m->layers[i]); - m->damage = wlr_output_damage_create(wlr_output); + m->isdamaged = 1; m->tagset[0] = m->tagset[1] = 1; for (r = monrules; r < END(monrules); r++) { if (!r->name || strstr(wlr_output->name, r->name)) { @@ -1025,9 +1021,8 @@ destroynotify(struct wl_listener *listener, void *data) /* Called when the surface is destroyed and should never be shown again. */ Client *c = wl_container_of(listener, c, destroy); - // Damage the whole screen if (c->mon) - wlr_output_damage_add_whole(c->mon->damage); + c->mon->isdamaged = true; wl_list_remove(&c->map.link); wl_list_remove(&c->unmap.link); @@ -1371,8 +1366,7 @@ mapnotify(struct wl_listener *listener, void *data) /* Set initial monitor, tags, floating status, and focus */ applyrules(c); - // Damage the whole screen - wlr_output_damage_add_whole(c->mon->damage); + c->mon->isdamaged = true; if (c->mon->fullscreenclient && c->mon->fullscreenclient == oldfocus && !c->isfloating && c->mon->lt[c->mon->sellt]->arrange) { @@ -1775,13 +1769,14 @@ rendermon(struct wl_listener *listener, void *data) } } - bool needs_frame; - pixman_region32_t damage; - pixman_region32_init(&damage); - if (!wlr_output_damage_attach_render(m->damage, &needs_frame, &damage)) + /* wlr_output_attach_render makes the OpenGL context current. */ + if (!wlr_output_attach_render(m->wlr_output, NULL)) return; - if (render && needs_frame) { + // We must render the monitor twice, once for each buffer, each time damage occurs + if (render && (m->isdamaged > -1)) { + m->isdamaged--; + /* Begin the renderer (calls glViewport and some other GL sanity checks) */ wlr_renderer_begin(drw, m->wlr_output->width, m->wlr_output->height); wlr_renderer_clear(drw, rootcolor); @@ -1806,14 +1801,8 @@ rendermon(struct wl_listener *listener, void *data) /* Conclude rendering and swap the buffers, showing the final frame * on-screen. */ wlr_renderer_end(drw); - - wlr_output_set_damage(m->wlr_output, &m->damage->current); - } else { - wlr_output_rollback(m->wlr_output); } - pixman_region32_fini(&damage); - wlr_output_commit(m->wlr_output); } @@ -1971,7 +1960,7 @@ setmon(Client *c, Monitor *m, unsigned int newtags) if (oldmon) { wlr_surface_send_leave(client_surface(c), oldmon->wlr_output); arrange(oldmon); - wlr_output_damage_add_whole(oldmon->damage); + oldmon->isdamaged = true; } if (m) { /* Make sure window actually overlaps with the monitor */ @@ -1979,7 +1968,7 @@ setmon(Client *c, Monitor *m, unsigned int newtags) wlr_surface_send_enter(client_surface(c), m->wlr_output); c->tags = newtags ? newtags : m->tagset[m->seltags]; /* assign tags of target monitor */ arrange(m); - wlr_output_damage_add_whole(m->damage); + m->isdamaged = true; } focusclient(focustop(selmon), 1); } @@ -2299,9 +2288,7 @@ unmapnotify(struct wl_listener *listener, void *data) /* Called when the surface is unmapped, and should no longer be shown. */ Client *c = wl_container_of(listener, c, unmap); - // Damage the whole screen - if (c->mon) - wlr_output_damage_add_whole(c->mon->damage); + c->mon->isdamaged = true; wl_list_remove(&c->link); if (client_is_unmanaged(c))