Merge remote-tracking branch 'miles/basic_damage_tracking' into basic_damage_tracking

This commit is contained in:
Stivvo 2021-03-14 23:20:19 +01:00
commit b267258251
2 changed files with 66 additions and 32 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)))

96
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>
@ -146,6 +147,7 @@ typedef struct {
struct wlr_box geo;
enum zwlr_layer_shell_v1_layer layer;
Monitor *mon;
} LayerSurface;
typedef struct {
@ -176,6 +178,7 @@ struct Monitor {
double mfact;
int nmaster;
Client *fullscreenclient;
struct wlr_output_damage *damage;
};
typedef struct {
@ -769,6 +772,9 @@ commitlayersurfacenotify(struct wl_listener *listener, void *data)
&layersurface->link);
layersurface->layer = wlr_layer_surface->current.layer;
}
// Damage the whole screen
wlr_output_damage_add_whole(m->damage);
}
void
@ -779,6 +785,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 +833,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)) {
@ -1013,6 +1024,11 @@ 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);
wl_list_remove(&c->map.link);
wl_list_remove(&c->unmap.link);
wl_list_remove(&c->destroy.link);
@ -1355,6 +1371,9 @@ 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);
if (c->mon->fullscreenclient && c->mon->fullscreenclient == oldfocus
&& !c->isfloating && c->mon->lt[c->mon->sellt]->arrange) {
maximizeclient(c->mon->fullscreenclient);
@ -1739,7 +1758,9 @@ void
rendermon(struct wl_listener *listener, void *data)
{
Client *c;
int render = 1;
int render;
bool needs_frame;
pixman_region32_t damage;
/* This function is called every time an output is ready to display a frame,
* generally at the output's refresh rate (e.g. 60Hz). */
@ -1748,45 +1769,51 @@ rendermon(struct wl_listener *listener, void *data)
struct timespec now;
clock_gettime(CLOCK_MONOTONIC, &now);
/* Do not render if any XDG clients have an outstanding resize. */
/* If there is any XDG client which is awaiting resize, request a new
* frame from that client, and do not render anything new until there
* are no pending resizes remaining. */
wl_list_for_each(c, &stack, slink) {
if (c->resize) {
wlr_surface_send_frame_done(client_surface(c), &now);
render = 0;
return;
}
}
/* wlr_output_attach_render makes the OpenGL context current. */
if (!wlr_output_attach_render(m->wlr_output, NULL))
/* Do not render if no new frame is needed */
pixman_region32_init(&damage);
render = wlr_output_damage_attach_render(m->damage, &needs_frame, &damage);
pixman_region32_fini(&damage);
if (!render || !needs_frame) {
/* Rollback is needed because attach_render is double-buffered */
wlr_output_rollback(m->wlr_output);
return;
if (render) {
/* 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);
renderlayer(&m->layers[ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND], &now);
renderlayer(&m->layers[ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM], &now);
renderclients(m, &now);
#ifdef XWAYLAND
renderindependents(m->wlr_output, &now);
#endif
renderlayer(&m->layers[ZWLR_LAYER_SHELL_V1_LAYER_TOP], &now);
renderlayer(&m->layers[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY], &now);
/* Hardware cursors are rendered by the GPU on a separate plane, and can be
* moved around without re-rendering what's beneath them - which is more
* efficient. However, not all hardware supports hardware cursors. For this
* reason, wlroots provides a software fallback, which we ask it to render
* here. wlr_cursor handles configuring hardware vs software cursors for you,
* and this function is a no-op when hardware cursors are in use. */
wlr_output_render_software_cursors(m->wlr_output, NULL);
/* Conclude rendering and swap the buffers, showing the final frame
* on-screen. */
wlr_renderer_end(drw);
}
/* 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);
renderlayer(&m->layers[ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND], &now);
renderlayer(&m->layers[ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM], &now);
renderclients(m, &now);
#ifdef XWAYLAND
renderindependents(m->wlr_output, &now);
#endif
renderlayer(&m->layers[ZWLR_LAYER_SHELL_V1_LAYER_TOP], &now);
renderlayer(&m->layers[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY], &now);
/* Hardware cursors are rendered by the GPU on a separate plane, and can be
* moved around without re-rendering what's beneath them - which is more
* efficient. However, not all hardware supports hardware cursors. For this
* reason, wlroots provides a software fallback, which we ask it to render
* here. wlr_cursor handles configuring hardware vs software cursors for you,
* and this function is a no-op when hardware cursors are in use. */
wlr_output_render_software_cursors(m->wlr_output, NULL);
/* 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);
wlr_output_commit(m->wlr_output);
}
@ -1944,6 +1971,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);
}
if (m) {
/* Make sure window actually overlaps with the monitor */
@ -1951,6 +1979,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);
}
focusclient(focustop(selmon), 1);
}
@ -2274,6 +2303,11 @@ 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);
wl_list_remove(&c->link);
if (client_is_unmanaged(c))
return;