auto-sync: draw on idle to avoid flicker/tearing

st could easily tear/flicker with animation or other unattended
output. This commit eliminates most of the tear/flicker.

Before this commit, the display timing had two "modes":

- Interactively, st was waiting fixed `1000/xfps` ms after forwarding
  the kb/mouse event to the application and before drawing.

- Unattended, and specifically with animations, the draw frequency was
  throttled to `actionfps`. Animation at a higher rate would throttle
  and likely tear, and at lower rates it was tearing big frames
  (specifically, when one `read` didn't get a full "frame").

The interactive behavior was decent, but it was impossible to get good
unattended-draw behavior even with carefully chosen configuration.

This commit changes the behavior such that it draws on idle instead of
using fixed latency/frequency. This means that it tries to draw only
when it's very likely that the application has completed its output
(or after some duration without idle), so it mostly succeeds to avoid
tear, flicker, and partial drawing.

The config values minlatency/maxlatency replace xfps/actionfps and
define the range which the algorithm is allowed to wait from the
initial draw-trigger until the actual draw. The range enables the
flexibility to choose when to draw - when least likely to flicker.

It also unifies the interactive and unattended behavior and config
values, which makes the code simpler as well - without sacrificing
latency during interactive use, because typically interactively idle
arrives very quickly, so the wait is typically minlatency.

While it only slighly improves interactive behavior, for animations
and other unattended-drawing it improves greatly, as it effectively
adapts to any [animation] output rate without tearing, throttling,
redundant drawing, or unnecessary delays (sounds impossible, but it
works).
This commit is contained in:
bakkeby 2020-05-20 14:15:57 +02:00
parent 87fe11cfcc
commit 5c7d8ab1ad
10 changed files with 75 additions and 287 deletions

View file

@ -1,45 +0,0 @@
int
isvbellcell(int x, int y)
{
if (vbellmode == 1)
return 1;
if (vbellmode == 2)
return y == 0 || y == win.th / win.ch - 1 ||
x == 0 || x == win.tw / win.cw - 1;
return 0;
}
void
vbellbegin()
{
clock_gettime(CLOCK_MONOTONIC, &win.lastvbell);
if (win.vbellset) /* already visible, just extend win.lastvbell */
return;
win.vbellset = 1;
#if VISUALBELL_3_PATCH
if (vbellmode != 3) /* 3 is an overlay, no need to re-render cells */
tfulldirt();
#else
tfulldirt();
#endif // VISUALBELL_3_PATCH
draw();
XFlush(xw.dpy);
}
#if VISUALBELL_3_PATCH
void
xfillcircle(int x, int y, int r, uint color_ix)
{
XSetForeground(xw.dpy, dc.gc, dc.col[color_ix].pixel);
XFillArc(xw.dpy, xw.buf, dc.gc, x - r, y - r, r * 2, r * 2, 0, 360*64);
}
void
xdrawvbell() {
int r = round(vbellradius * (vbellradius > 0 ? win.w : -win.cw));
int x = borderpx + r + vbellx * (win.tw - 2 * r);
int y = borderpx + r + vbelly * (win.th - 2 * r);
xfillcircle(x, y, r, vbellcolor_outline);
xfillcircle(x, y, r / 1.2, vbellcolor); /* 1.2 - an artistic choice */
}
#endif // VISUALBELL_3_PATCH

View file

@ -1,7 +0,0 @@
static void vbellbegin();
static int isvbellcell(int x, int y);
#if VISUALBELL_3_PATCH
static void xdrawvbell();
static void xfillcircle(int x, int y, int r, uint color_ix);
#endif // VISUALBELL_3_PATCH

View file

@ -23,9 +23,6 @@
#if ST_EMBEDDER_PATCH
#include "st_embedder_x.c"
#endif
#if VISUALBELL_2_PATCH || VISUALBELL_3_PATCH
#include "visualbell.c"
#endif
#if XRESOURCES_PATCH
#include "xresources.c"
#endif

View file

@ -20,9 +20,6 @@
#if ST_EMBEDDER_PATCH
#include "st_embedder_x.h"
#endif
#if VISUALBELL_2_PATCH || VISUALBELL_3_PATCH
#include "visualbell.h"
#endif
#if XRESOURCES_PATCH
#include "xresources.h"
#endif