Basic damage tracking

This commit is contained in:
Miles Breslin 2021-01-16 14:22:26 -08:00
parent 9f90011ea2
commit 774a6e7f8c
2 changed files with 22 additions and 2 deletions

View File

@ -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
PKGS = wlroots wayland-server xcb xkbcommon libinput pixman-1
CFLAGS += $(foreach p,$(PKGS),$(shell pkg-config --cflags $(p)))
LDLIBS += $(foreach p,$(PKGS),$(shell pkg-config --libs $(p)))

22
dwl.c
View File

@ -26,6 +26,7 @@
#include <wlr/types/wlr_keyboard.h>
#include <wlr/types/wlr_matrix.h>
#include <wlr/types/wlr_output.h>
#include <wlr/types/wlr_output_damage.h>
#include <wlr/types/wlr_output_layout.h>
#include <wlr/types/wlr_output_management_v1.h>
#include <wlr/types/wlr_pointer.h>
@ -176,6 +177,7 @@ struct Monitor {
double mfact;
int nmaster;
Client *fullscreenclient;
struct wlr_output_damage *damage;
};
typedef struct {
@ -779,6 +781,10 @@ commitnotify(struct wl_listener *listener, void *data)
/* mark a pending resize as completed */
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);
}
void
@ -823,6 +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->tagset[0] = m->tagset[1] = 1;
for (r = monrules; r < END(monrules); r++) {
if (!r->name || strstr(wlr_output->name, r->name)) {
@ -1760,7 +1767,14 @@ rendermon(struct wl_listener *listener, void *data)
if (!wlr_output_attach_render(m->wlr_output, NULL))
return;
if (render) {
bool needs_frame;
pixman_region32_t damage;
pixman_region32_init(&damage);
if (!wlr_output_damage_attach_render(m->damage, &needs_frame, &damage)) {
BARF("Cannot make damage output current");
}
if (render && needs_frame) {
/* 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);
@ -1785,8 +1799,14 @@ 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);
}