Commit graph

42 commits

Author SHA1 Message Date
Simon Ser
ef29d341cb
Move plane allocation algorithm to alloc.c
And move plane-related functions to plane.c.
2019-10-19 13:43:09 +03:00
Simon Ser
ba80e32054
Introduce liftoff_log_errno
Like perror, but uses the liftoff logging infrastructure.
2019-10-19 13:35:14 +03:00
Simon Ser
dc9c39ed5c
Introduce display_test_commit
This function wraps drmModeAtomicCommit and handles error conditions and
logging.
2019-10-19 13:15:34 +03:00
Simon Ser
5a66e567ec
Track layer property changes
This commit adds basic per-property change tracking.

When only FB_ID has changed, we try to re-use the previous allocation. If that
fails, go on with regular plane allocation.

Closes: https://github.com/emersion/libliftoff/issues/6
2019-10-15 12:07:43 +03:00
Simon Ser
fe2e7d0133
Extract plane allocation constraints in functions
Instead of baking plane allocation constraints in output_choose_layers, extract
constraints checked at each step in check_layer_plane_compatible and final
constraints in check_alloc_valid.
2019-10-15 11:42:40 +03:00
Simon Ser
72f5e9bd2f
Add TODO about remaining plane counting optimization 2019-10-13 01:25:08 +03:00
Simon Ser
aacbcf40b4
Split plane functions into a separate file 2019-10-11 17:09:35 +03:00
Simon Ser
e9433997d9
Add liftoff_output_set_composition_layer
This lets the library user define a layer where composition will happen. At the
moment there can be at most one composition layer per output, on the primary
plane. It should be possible to remove these restrictions in the future if
desirable.

The composition layer will be put on a plane if and only if composition is
needed.

The compositor needs to know where composited layers will be blended to resolve
zpos conflicts.

Closes: https://github.com/emersion/libliftoff/issues/9
2019-10-11 14:31:17 +03:00
Simon Ser
1ee86c6290
Add logging functions
This allows turning on and off debug logs, as well as defining a logging
callback.
2019-10-11 12:03:14 +03:00
Simon Ser
35da32683f
Unset CRTC_ID on planes before plane allocation
If a plane was previously enabled on another CRTC, we need to set its CRTC_ID to
zero. Otherwise atomic commits fail with:

    [drm:drm_atomic_check_only [drm]] [PLANE:31:primary A] CRTC set but no FB
2019-09-25 12:23:42 +03:00
Simon Ser
74040a817b
Rename plane_alloc and plane_data
Rename plane_alloc to alloc_result and plane_data to alloc_step. This is more
accurate and less confusing.
2019-09-16 00:13:04 +03:00
Simon Ser
0596d6f66e
Rename on_top to over
Rename has_composited_layer_on_top to has_composited_layer_over. This is more
consistent with has_allocated_layer_over.

While at it, add a comment to explain why has_allocated_layer_over is named like
so.
2019-09-16 00:00:03 +03:00
Simon Ser
7382dfd346
Add intersection check for layers over the current one
Make sure we don't use planes with lower zpos for layers over the previous ones,
unless there is no collision.

This adds the last intersection check.

Closes: https://github.com/emersion/libliftoff/issues/3
2019-09-15 23:54:29 +03:00
Simon Ser
e898ce0631
Fix format string in liftoff_display_apply 2019-09-15 23:28:08 +03:00
Simon Ser
cf861bae35
Remove last_plane_zpos from plane allocation state
Comparing with the last plane zpos isn't enough, we now perform intersection
checks too. The last plane zpos isn't used anymore, remove it.
2019-09-15 22:32:42 +03:00
Simon Ser
8617ddfd05
Add intersection check for planes under the current one
References: https://github.com/emersion/libliftoff/issues/3
2019-09-15 22:31:10 +03:00
Simon Ser
c5d22e1310
Add intersection checks for composited layer on top check
has_composited_layer_on_top is now less strict and performs plane intersection
checks before returning true.

This allows for more layers to be assigned to planes, the relevant tests have
been enabled.

References: https://github.com/emersion/libliftoff/issues/3
2019-09-15 17:08:32 +03:00
Simon Ser
aa2478cda8
Extract plane_data init logic to function
This allows to unclutter output_choose_layers a little.
2019-09-15 15:11:29 +03:00
Simon Ser
364be1c5a6
Document how plane allocation works
Describe the core of the idea in a big comment right before the algorithm
implementation.
2019-09-15 14:31:00 +03:00
Simon Ser
dcf6bc750b
Move composited layer on top constraint up
Move it before applying properties. There's no point in applying properties if
this constraint fails.
2019-09-14 21:24:20 +03:00
Simon Ser
07e04a50b6
Make composited layers prevent plane allocation underneath
If a layer cannot be mapped to a plane, make it so all layers under it also fail
plane allocation so that they can be properly composited on the primary plane.

A test was incorrect and has been fixed. Another test had two possible solutions
and has been updated with the one libliftoff yields.
2019-09-14 21:03:30 +03:00
Simon Ser
a1e3798f6f
Use PRIu32 for printing plane IDs 2019-09-13 19:43:01 +03:00
Simon Ser
bb887aa7d0
Fix segfault when dup fails in liftoff_display_create 2019-09-12 20:15:50 +03:00
Simon Ser
caac9bc87f
Rename library to liftoff
Let's make these planes useful!
2019-09-12 11:40:21 +03:00
Simon Ser
c4a8afb39b
Add basic support for zpos
This commit adds special handling for the layer zpos property. Setting it won't
forward it to KMS, instead it will be handled internally.

The plane zpos (either retrieved from KMS if the property is supported, or
guessed from the plane type and ID) is checked during plane allocation to have
the same ordering as the layer zpos. This adds more constraints to the
allocation.

Note that the new constraints are too strict. In case two layers don't overlap,
there's no need for one plane to be on top of the other. See [1].

Also, the new constraints don't account for underlay planes [2].

[1]: https://github.com/emersion/libhwc/issues/3
[2]: https://github.com/emersion/libhwc/issues/7

Closes: https://github.com/emersion/libhwc/issues/4
2019-09-12 11:27:00 +03:00
Simon Ser
fc901d0e26
Fix early bailout when we already have a better allocation
In case we can't do better than the current best allocation even if we manage
to allocate all remaining planes, we bail out early. However the bailout
condition was incorrect and didn't account for the current score.
2019-09-12 10:17:03 +03:00
Simon Ser
1509e50fd5
Extract allocation arguments to a struct
Just trying to keep the number of arguments under a reasonable limit. More
arguments will be added in the future.
2019-09-11 19:23:35 +03:00
Simon Ser
4d641041bb
Don't assign layer to plane if missing props
Sometimes the properties applied on a layer are missing on a plane. Instead of
making the whole allocation fail, just mark the plane as incompatible with the
layer.
2019-09-10 22:58:29 +03:00
Simon Ser
e2df5e73d0
List planes by allocation order
Given a primary plane with zpos=0 and overlay planes with zpos 1 2, we want
first to allocate the primary plane, then the furthest overlay plane, then the
remaining one: 0 2 1.

References: https://github.com/emersion/libhwc/issues/3
2019-09-09 20:55:43 +03:00
Simon Ser
dac885222b
Add support for reading immutable plane zpos
If zpos is present, instead of guessing the zpos from the plane type, just use
it. If two planes have the same zpos, we consider their relative position as
undefined.

We don't handle the case where some planes have zpos set but some others don't.

References: https://github.com/emersion/libhwc/issues/4
2019-09-09 19:46:44 +03:00
Simon Ser
42db49c6fe
Guess zpos from plane type
Many drivers don't expose the zpos plane property. We can guess it from the
plane type though: primary, overlay, cursor. Except some drivers expose
underlays too: underlays, primary, overlay, cursor. Underlay planes don't have a
special type, they are just marked as overlays. To detect them, check whether
their plane ID is less than the primary plane ID.

References: https://github.com/emersion/libhwc/issues/3
2019-09-08 18:33:09 +03:00
Simon Ser
d90d7bdc36
Check plane is compatible with CRTC
This allows us to rule out some potential solutions.

Closes: https://github.com/emersion/libhwc/issues/2
2019-09-08 17:41:25 +03:00
Simon Ser
66bedbc854
Reset best allocation to NULL
Without this, if no allocation has been found, garbage will be read from
alloc.best.
2019-09-08 17:39:55 +03:00
Simon Ser
b3eb0e323c
Basic brute-force plane allocation
This is the very first complete allocator. There are many things that can be
improved, but at least it works.

Closes: https://github.com/emersion/libhwc/issues/8
2019-09-08 16:32:38 +03:00
Simon Ser
165d013b80
Change planes to be a linked list instead of an array
We'll need this anyway when we allow users to choose which planes to give us.
Let's not start building algorithms on top of arrays.
2019-09-08 15:26:50 +03:00
Simon Ser
7bea0c7bf7
Better hwc_display_apply error handling 2019-08-23 19:27:13 +03:00
Simon Ser
1ca4a03224
Disable all planes before building the mapping 2019-08-23 19:20:05 +03:00
Simon Ser
559bd2bf3a
Don't pick a busy plane in layer_choose_plane 2019-08-23 18:59:20 +03:00
Simon Ser
9a6237026a
Reset all mappings in hwc_display_apply 2019-08-23 18:56:44 +03:00
Simon Ser
6d5221370e
Disable unused planes 2019-08-23 18:48:13 +03:00
Simon Ser
00f85c4eca
Add missing static qualifiers 2019-08-23 18:20:42 +03:00
Simon Ser
9fe471dd6b
Initial experiments 2019-08-21 23:07:37 +03:00