wayland: optionally use the presentation time protocol to measure input lag

This adds a flag, -p,--presentation-timings, that enables input lag
measuring using the presentation time Wayland protocol.

When enabled, we store a timestamp when we *send* a key to the
slave. Then, when we commit a frame for rendering to the compositor,
we request presentation feedback. We also store a timestamp for when
the frame was committed.

The 'presented' callback then looks at the input and commit
timestamps, and compares it with the presented timestamp.

The delay is logged at INFO when the delay was less than one frame
interval, at WARN when it was one frame interval, and at ERR when it
was two or more frame intervals.

We also update statistic counters that we log when foot is shut down.
This commit is contained in:
Daniel Eklöf 2019-12-31 15:39:40 +01:00
parent ea1d072f52
commit 5a07419096
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
9 changed files with 187 additions and 11 deletions

View file

@ -199,6 +199,20 @@ static struct zxdg_output_v1_listener xdg_output_listener = {
.description = xdg_output_handle_description,
};
static void
clock_id(void *data, struct wp_presentation *wp_presentation, uint32_t clk_id)
{
struct wayland *wayl = data;
wayl->presentation_clock_id = clk_id;
LOG_DBG("presentation clock ID: %u", clk_id);
}
static const struct wp_presentation_listener presentation_listener = {
.clock_id = &clock_id,
};
static bool
verify_iface_version(const char *iface, uint32_t version, uint32_t wanted)
{
@ -326,6 +340,17 @@ handle_global(void *data, struct wl_registry *registry,
wayl->registry, name,
&zwp_primary_selection_device_manager_v1_interface, required);
}
else if (strcmp(interface, wp_presentation_interface.name) == 0) {
const uint32_t required = 1;
if (!verify_iface_version(interface, version, required))
return;
wayl->presentation = wl_registry_bind(
wayl->registry, name, &wp_presentation_interface, required);
wp_presentation_add_listener(
wayl->presentation, &presentation_listener, wayl);
}
}
static void
@ -658,6 +683,9 @@ wayl_destroy(struct wayland *wayl)
if (wayl->xdg_decoration_manager != NULL)
zxdg_decoration_manager_v1_destroy(wayl->xdg_decoration_manager);
if (wayl->presentation != NULL)
wp_presentation_destroy(wayl->presentation);
if (wayl->kbd.xkb_compose_state != NULL)
xkb_compose_state_unref(wayl->kbd.xkb_compose_state);
if (wayl->kbd.xkb_compose_table != NULL)