Previously, we would reallocate when any CRTC_* property changes. This
leads to unnecessary reallocations when a plane moves or resizes. Cursor
movements would reallocate on every update, for example.
What we really care about is if a layer's intersection status with
another plane changes, so do that.
If we've found a good previous allocation, it's possible that there
is no point trying to continue exploring the graph. In particular,
if we won't get a higher score even if we manage to make use of all
available planes, we can stop right away.
For instance, let's say that we've previously found a way to make use
of 3 out of 5 planes. We're exploring a different path where we've
populated 1 plane, we've skipped 1 plane because we couldn't find a
suitable layer for it, and out of the 3 remaining planes only 2 are
compatible with the CRTC we're interested in. Even if we manage to
make use of these 2 extra planes we would end up with 3 effectively
used planes thus no benefit over the previous solution.
The default limit of 1ms might be too short if the compositor
calls liftoff_output_apply() early in the vblank cycle, or too
long if the refresh rate is high. The compositor is in a better
spot to decide how much time should be spent on atomic tests, so
add an option for that.
Closes: https://gitlab.freedesktop.org/emersion/libliftoff/-/issues/78
`gcc-14` added a new `-Wcalloc-transposed-args` warning recently. It
detected minor infelicity in `calloc()` API usage in `libliftoff`:
../layer.c: In function 'liftoff_layer_create':
../layer.c:20:48: error: 'calloc' sizes specified with 'sizeof' in the earlier argument and not in t
ument [-Werror=calloc-transposed-args]
20 | layer->candidate_planes = calloc(sizeof(layer->candidate_planes[0]),
| ^
../layer.c:20:48: note: earlier argument should specify number of elements, later size of each element
To optimize for offloading success, the list of output layers can be
ordered by allocation priority, improving the chances of a higher
allocation score before the deadline.
The allocation algorithm picks DRM planes first, then tests output
layers against them. To reduce the number of tests, the layers can be
ordered such that it matches the DRM plane order. DRM planes in
libliftoff are ordered by primary, followed by all other planes in
descending z-order. We order the layers similarly, with the composition
layer first, followed by layers of descending priority.
In addition to layer priority, it's z-pos and intersection with other
layers are considered. Since to offload a high priority layer, all
intersection layers with higher z-pos will also need to be offloaded.
This also changes when reallocation is necessary. On top of the existing
criteria, reallocation is done when a layer's ordering changes.
With layer priority now considered, the priority test now passes --
enable it.
Introduce a function to swap elements in a doubly linked list. This will
be helpful when keeping the list of output layers sorted by priority.
v2: re-define in terms of list_inserts and list_removes