Commit graph

365 commits

Author SHA1 Message Date
Pekka Paalanen debfeb3049 backend-drm: reset CRTC_GAMMA_LUT
We are assuming that CRTC_GAMMA_LUT is pass-through, so better ensure it
really is pass-through rather than whatever the previous KMS client left
there.

Unfortunately, we have old drm_output_set_gamma() API that cms-static
and cms-colord plugins are using. To avoid trampling over them, do not
touch gamma after they did. Those plugins are deprecated, so there is no
reason to make set_gamma work through atomic.

drm_output_set_gamma() is called from weston_compositor_add_output()
through the output_created_signal. This is after drm_output_enable() and
before any KMS modeset or atomic commit on the CRTC. Therefore it is not
possible that there would be any KMS action in flight when
drm_output_set_gamma() is called, and so setting deprecated_gamma_is_set
should be non-racy - like setting CRTC_GAMMA_LUT itself.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2023-01-10 11:28:27 +00:00
Pekka Paalanen dbce396c7c backend-drm: move *_add_prop() debug earlier
Move the debug printing before the bail-out if the property does not
exist. This means that trying to set a missing property will be logged,
and it can be identified by the property id being 0.

We are starting to program more KMS properties, and if KMS state
building fails, this gives better chances to figure out what happened.
For example, if we accidentally assume that some property always exists
when it doesn't.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2023-01-10 11:28:27 +00:00
Daniel Stone c683ebdea3 backend-drm: Use renderer enum type for config selection
When we're selecting our renderer, use the enum rather than a boolean to
force Pixman on.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2023-01-10 10:59:04 +02:00
Derek Foreman 68cad4db42 drm: Use cached matrix in drm_paint_node_transform_supported
We've passed the paint node deeply enough that we can now use the cached
matrix in it to save some calculations.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2023-01-09 21:58:19 +00:00
Derek Foreman 05eee6eaef drm: Pass paint node to drm_view_transform_supported
Rename it as well.

By passing the paint node we'll have access to the cached buffer to output
matrix later.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2023-01-09 21:58:19 +00:00
Derek Foreman 7c7489fe79 drm: Pass paint node to drm_plane_state_coords_for_view
Rename the function as well, as it no longer takes a view.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2023-01-09 21:58:19 +00:00
Derek Foreman a65ba82232 drm: Pass paint node to drm_output_try_view_on_plane
Rename the function as it no longer tests views, but paint nodes.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2023-01-09 21:58:19 +00:00
Derek Foreman 263e78d0fc drm: Pass paint node to cursor view prep function
Rename this as well, since it no longer takes a view.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2023-01-09 21:58:19 +00:00
Derek Foreman 567ed2706a drm: pass paint node to drm_fb_get_from_view
This is a preamble to saving a bit of matrix maths.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2023-01-09 21:58:19 +00:00
Pekka Paalanen 915d8e8cdf build: simplify dep_egl a bit
Make sure dep_egl is always a valid dependency object, even if not
found. Ensure it is not found when not wanted, to avoid linking when
found but not wanted.

Using a not-found dependency in Meson is defined to be a safe no-op, so
use that to simplify the backend dependencies.

libweston/meson.build already errors out if renderer-gl is enabled and
EGL is not found, so the same checks can be removed from the backends.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2022-12-14 11:57:24 +00:00
Philipp Zabel 746a03068e libweston, backends: store backend pointer in struct weston_head
Compositor code can use opaque pointer comparison to determine whether
a head belongs to a given backend. Store a backend pointer in struct
weston_head to enable the compositor to select the correct backend
specific output configuration code.

This also allows to use the backend pointer instead of the opaque
backend_id pointer to check whether a head belongs to a backend, so
replace the checks in all to_xyz_head() functions and drop backend_id.

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
2022-12-12 15:21:16 +01:00
Philipp Zabel a9c1b41f3f backend-drm: drop use_pixman from drm_backend
Now that the renderer type is stored in struct weston_renderer,
use that instead of use_pixman to determine the renderer type.

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
2022-12-08 09:44:20 +00:00
Pekka Paalanen 3700c78131 libweston: implement new screenshooting protocol base
This implements the basics of the new screenshooting protocol. The
actual pixel operations will be implemented separately in the renderers
and DRM-backend.

See the previous commit "protocol: new screenshooter protocol" for why.

If DRM-backend needs more from weston_capture_task when it implements
writeback screenshooting, it will be easy to add user_data or expose
weston_capture_task::link for the backend to use. Those were not added
yet because it is uncertain what is actually needed.

The DRM-backend no-damage optimization requires special handling here as
well. See also 7f1a113c89 .

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2022-11-29 11:00:52 +02:00
Derek Foreman 021fdf4244 backend-drm: Analyze transformation chain to check if it's supported
Instead of bailing based on our loosely tracked matrix "type" (that won't
recognize when an operation is reversed by its inverse) use the new
weston_matrix_to_transform to determine if the matrix reasonably matches.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2022-11-25 08:29:05 -06:00
Pekka Paalanen f3bed68100 backend-drm: do not print head info twice
Before this patch, when a new head is found its information is printed
first as "updated" and then as "found" in the log.

The reason is that drm_head_create() calls drm_head_update_info() which
printed the head as "changed". Then drm_head_create() itself prints it
as "found".

This fixes it to print only once as "found".

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2022-11-08 16:57:51 +02:00
Emmanuel Gil Peyrot 1c5ce4c2cc DRM: Add support for HDMI content type
Some monitors expose a selector for the kind of content that will get
displayed, allowing them to optimise their settings for this particular
content type.

I got access to such a monitor, sadly even setting it to game mode
didn’t lower its atrocious latency, but drm_info[1] reports it to be set
correctly so hopefully it’ll work better with other monitors.

[1] https://github.com/ascent12/drm_info

Signed-off-by: Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
2022-11-03 15:40:00 +00:00
Derek Foreman 5079f0b2f9 helpers: Add a u64 from 2 u32 helper
We do this enough that having a single implementation for it is probably
a win.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2022-10-27 08:13:30 +00:00
Pekka Paalanen 7886cbe4b9 gl-renderer: pass initial output area explicitly
This changes the GL-renderer interface to pass the initial framebuffer
size and compositing area explicitly. All backends are changed to
provide the correct parameters.

GL-renderer mostly does not yet use these values, but later patches
will. The pbuffer path uses it already, because they replaced the
existing fields.

All this is to make GL-renderer aware of the different sizes, so it can
implement the future revision of the screenshooting API.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2022-09-23 12:42:05 +00:00
Pekka Paalanen f4559b0760 pixman-renderer: pass initial size explicitly
In a journey to decouple renderer from weston_output, pass the initial
framebuffer size to Pixman-renderer explicitly.

Now Pixman-renderer will never look into weston_output::current_mode.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2022-09-23 12:42:05 +00:00
Derek Foreman 64c618e47e libweston: Remove x,y from weston_plane_init
This is always passed as 0 right now.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2022-09-23 11:53:16 +00:00
Marius Vlad eaf2de3441 compositor: Use weston_load_module
Except the module dir path, they're one and the same. This change
warrants a libweston version bump, if it hasn't been done already.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2022-09-23 11:47:40 +00:00
Derek Foreman 21deaee6a9 libweston: use weston_region_global_to_output more often
Use this anywhere we used weston_matrix_transform_region with an output
matrix.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2022-09-23 11:41:59 +00:00
Derek Foreman c12ec7a2e5 compositor: Remove weston_transformed_region
Replace all uses of weston_transform_region with
weston_matrix_transform_region, then remove the function completely.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2022-09-23 11:41:59 +00:00
Derek Foreman df96fd435c backend-drm: Use weston_matrix_transform_region for plane setup
Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2022-09-23 11:41:59 +00:00
vanfanel 3240ccc69d Don't change the max_bpc connector prop if mode=current.
As things are, even when mode=current is specified on the .ini file,
a full modeset is needed (and done), which causes a very noticeable
screen blinking. That is because setting the max_bpc on a connector
needs full modesetting.
The idea here is that if mode=current on the .ini, no modesetting
should be done, so the current max_bpc is programmed into the
connector.
But if a custom max-bpc=... is specified, that will be used instead,
even if mode=current on the .ini

Fixes: https://gitlab.freedesktop.org/wayland/weston/-/issues/660

Signed-off-by: vanfanel <redwindwanderer@gmail.com>
2022-09-23 11:05:34 +00:00
Michael Olbrich 4cde507be6 backend-drm: fix plane sorting
The planes in the plane_list must be sorted from largest zpos_max to smallest.

Currently the plane order is only correct when the planes are already ordered
and added starting with the smallest zpos_max. This works accidentally in most
cases because the primary plane is usually first and there is often only one
overlay plane or the zpos is sufficiantly configurable.

To fix this, insert a new plane before the first plane with a smaller zpos_max.
And if none is found, insert it at the end of the list.

Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
2022-08-31 08:28:55 +02:00
Michael Olbrich 6275a0fb32 backend-drm: delay mode switches until the last commit is completed
Changing the mode will destoy the GBM surface for the output. As a result all
corresponding BOs are deleted regardless of the drm_fb refcount.

While a commit is pending, the last_state may contain a reference to such a BO.
So delay the mode switch until the commit is finished and the reference is
release.

Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
2022-08-08 14:37:50 +00:00
Michael Olbrich 3b3fdc52c3 backend-drm: improve atomic commit failure handling
When an atomic commit fails then the output will be stuck in
REPAINT_AWAITING_COMPLETION state. It is waiting for a vblank event that was
never scheduled.
If the error is EBUSY then it can be expected to be a transient error. So
propagate the error and schedule a new repaint in the core compositor.

This is necessary because there are some circumstances when the commit can fail
unexpectedly:
- With 'state_invalid == true' one commit will disable all planes. If another
  commit for a different output is triggered immediately afterwards, then this
  commit can temporarily fail with EBUSY because it tries to use the same
  planes.
- At least with i915, if one commit enables an output then a second commit for a
  different output immediately afterwards can temporarily fail with EBUSY. This
  is probably caused by some hardware interdependency.

Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
2022-08-03 17:35:26 +02:00
Marius Vlad 78ccc99d0a libweston: Remove runtime render switching
It is only enabled by a debug key binding, currently not tested at all,
and is seems it doesn't really work, so let's remove it. This also
removes it from the man page.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2022-07-26 13:40:43 +00:00
Marius Vlad 50f98b1006 backend-drm/state-propose: Amend an older comment
Since b38b735e20, 'backend-drm: Remove Pixman conditional
for keep_buffer' the Pixman renderer keeps its own reference to buffers
when attached to surfaces, rather than flipping keep_buffer variable for
the surface. Problem is that when switching from the Pixman render to
the GL would not work and could result in a crash upon first repaint.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2022-07-15 12:54:05 +03:00
Michael Olbrich f5a4fb5abc backend-drm: make sure all buffers are released when an output is removed
When an output is destroyed then the output state is freed immediately. In this
case, the plane state is only partially destroyed because it is the currently
active state. This includes the buffer reference.

Without the output, the plane will not be updated any more until it is used by a
different output (if possible) or the output returns and the plane is used
again.
As a result, the buffer reference is kept for a long time. This will cause some
applications to stall because weston now keeps two buffers (the one here and
another one for a different output where the application is now displayed).

To avoid this, do a synchronous commit that disables the output. The output
needs to be disabled anyways and this way the current state contains no
buffers that would remain.

`device->state_invalid = true` in drm_output_detach_crtc() is no longer
needed, because drm_output_detach_crtc() is called only when initialization
failed and the crtc was not yet used or in drm_output_deinit() when the
crtc was already disabled with the new synchronous commit.

Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
2022-07-04 18:42:48 +00:00
Daniel Stone 01c57eca43 backend-drm: Don't leak drm_device on shutdown
This was introduced in a partial MR, where the later commits in the new
multi-GPU MR fully fix it, but the initially cherry-picked ones don't.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2022-06-29 14:33:21 +01:00
Michael Olbrich 2929b6c483 backend-drm: check that outputs are in fact ours
This is another followup to ffc011d6a3
("backend-drm: check that outputs and heads are in fact ours") which missed
some places.

Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
2022-06-23 14:00:04 +00:00
Ivan Nikolaenko 0d3e438d08 build: fix possible race/error for some backends
There is missing dependency on linux-dmabuf-unstable-v1-server-protocol.h
header file in backend-headless, backend-drm and backend-x11. That files
do not depend on that header, in fact. But by this moment they've had
that implicit dependency due to linux-dmabuf.h header.

With specific set of meson configure options the protocol header is not
generated at the right time, what causes build error in 100% cases using
small amount of building threads (from -j1 to -j8).

Signed-off-by: Ivan Nikolaenko <ivan.nikolaenko@unikie.com>
2022-06-20 16:14:01 +03:00
Michael Olbrich 78933093a1 backend-drm: check that outputs are in fact ours
This is a followup to ffc011d6a3
("backend-drm: check that outputs and heads are in fact ours") which missed
some places.

Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
2022-06-16 09:53:01 +00:00
Michael Olbrich 3e44a6eb3d backend-drm: don't try to disable planes on session deactivation
This uses the legacy DRM API it incomplete and no longer works anyways.
At this point, weston is no longer DRM master, so these calls fail with
"Permission denied".

So just remove the corresponding code.

Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
2022-06-16 09:53:01 +00:00
Pekka Paalanen d24adbbe25 backend-drm: set connector max bpc
"max bpc" property is meant for working around faulty sink hardware.
Normally it should be set to the maximum possible value so that the
kernel driver has full freedom to choose the link bpc without being
artificially forced to lower color precision.

The default value is 16 because that is a nice round number and more
than any link technology I've heard is using today which would be 12.

Also offer an API set the value, so that weston.ini could be used in the
next patch for sink workaround purposes.

Closes: https://gitlab.freedesktop.org/wayland/weston/-/issues/612

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2022-06-15 12:58:38 +00:00
Philipp Zabel ffc011d6a3 backend-drm: check that outputs and heads are in fact ours
As a first step towards heterogeneous outputs, ignore other backends'
heads and outputs. This is done by checking the destroy callbacks for
heads and outputs.

See: https://gitlab.freedesktop.org/wayland/weston/-/issues/268

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
2022-06-10 09:27:43 +00:00
Philipp Zabel aab722bb17 backend-drm: prepare virtual output API for heterogeneous outputs
Stop plugins from overwriting the struct weston_output::destroy vfunc,
as that will be used by backends to recognize their outputs.
Instead, pass a plugin-specific destroy callback when creating the
virtual output.

See: https://gitlab.freedesktop.org/wayland/weston/-/issues/268

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
2022-06-10 09:27:43 +00:00
Luigi Santivetti 8b654c47eb Revert "backend-drm: add HDR_OUTPUT_METADATA definitions"
This reverts commit 6914064066.

This is a follow-up change of b623fd2a ("drm-backend: stop parsing IN_FORMATS
blobs, use libdrm instead"). Weston now has a hard-requirement on libdrm
2.4.108, clean up remaining and unnecessary conditional code. Change 69140640
("backend-drm: add HDR_OUTPUT_METADATA definitions") is no longer needed
and stop including libdrm-updates.h from kms-color.c.

Signed-off-by: Luigi Santivetti <luigi.santivetti@imgtec.com>
2022-06-07 09:35:14 +01:00
Luigi Santivetti a62bf5ff48 drm-backend: stop parsing IN_FORMATS blobs, use libdrm instead
Before this change the drm-backend in Weston did the work of parsing DRM
blobs in order to query IN_FORMATS data, if available. This is also the
case for other DRM/KMS clients that use IN_FORMATS (i.e. X).

libdrm 2.4.108 with e641e2a6 ("xf86drm: add iterator API for DRM/KMS
IN_FORMATS blobs") introduced a dedicated API for querying IN_FORMATS data.

Bump the minimum required version to 2.4.108, stop parsing IN_FORMATS in
Weston and start using DRM iterators. In addition, remove fallback code for
libdrm <2.4.107.

Signed-off-by: Luigi Santivetti <luigi.santivetti@imgtec.com>
2022-06-07 09:35:14 +01:00
Michael Tretter dfceb60274 backend-drm: explicitly pass device to initialization
The drm_device is initialized as a side effect of the (badly named)
drm_device_is_kms function. Explicitly pass the drm_device to be able to
initialize kms devices that are not the main drm device of the drm backend.

Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
2022-06-03 09:18:12 +02:00
Michael Tretter deebfd99e3 backend-drm: get the drm device from the output
If we have multiple drm devices, we cannot use the drm device from the backend,
because we would only get the primary device and not the device of the output.

Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
2022-06-03 09:17:49 +02:00
Michael Tretter 6e36787dfd backend-drm: handle hotplug events per drm device
If Weston receives a hotplug event, it has to check if the hotplug device
actually belongs to the drm device before updating the heads of the device. The
hotplug event should only remove heads that belong to the device and must not
change heads of other devices.

Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
2022-06-03 09:17:32 +02:00
Michael Tretter d990c6a939 backend-drm: ignore heads from other devices
The compositor lists the heads from all devices, but we must only disable the
connectors that belong to the current device. Therefore, other heads must be
ignored.

Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
2022-06-03 09:17:16 +02:00
Michael Tretter 345e705e33 backend-drm: move drm objects from backend to drm device
The outputs, heads, crtcs, and connectors are specific to a drm device and not
the backend in general.

Link them to the device that they belong to to be able to retrieve the
respective device.

Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
2022-06-03 09:17:15 +02:00
Michael Tretter c4685d9463 backend-drm: attach device to pending state
The commits happen per device instead of per backend. The pending state is
therefore per device as well. Allow to retrieve the device from the pending
state.

Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
2022-06-03 09:14:11 +02:00
Michael Tretter 615a37dc88 backend-drm: make dma-buf feedback device specific
The scanout format for the dma-buf feedback are specific to the kms device that
is used for scanout. Therefore, we have to pass the device of the output when
retrieving the scanout formats.

Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
2022-06-03 09:13:55 +02:00
Michael Tretter 101c0f6b8b backend-drm: get the fb using the device instead of the backend
The fbs are specific to the device on which they will be displayed. Therefore,
we have to tell which device shall be used when we are creating the fb.

Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
2022-06-03 09:13:40 +02:00
Michael Tretter d89fcf10cb backend-drm: pass device through atomic commit handler
The atomic commit is device specific. If we have multiple kms devices, we need
to know which device was used for the atomic commit.

Pass the device instead of the backend through the atomic commit.

Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
2022-06-03 09:13:23 +02:00
Michael Tretter 0d967bd7f4 backend-drm: extract device from backend
Extract the kms device from the backend to allow a better separation of the
backend and the kms device. This will allow to handle multiple kms devices with
a single drm backend.

Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
2022-06-03 09:12:57 +02:00
Michael Tretter 2860933ded backend-drm: cleanup debugging
Get the backend at the beginning of the function instead of retrieving it from
another object in the debug statement. This simplifies refactoring, as the debug
statement is not affected by changes how the backend is retrieved.

Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
2022-06-03 09:04:29 +02:00
Michael Tretter 00b74293e8 backend-drm: use pixel format to print gbm format
The gbm_format is the same as the drm format used by the pixel format.

Print the format name using the pixel format in the error message to make the
error message easier to understand for humans.

Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
2022-06-03 09:04:29 +02:00
Michael Olbrich 83d1eafd81 backend-drm: virtual: use the DRM fd from the fb
The fb already contains a DRM fd for later use. So just use that one instead of
fetching it from the backend.

This is necessary if the fbs are allocated on different devices, since otherwise
the wrong device might be used to get the fd of the passed fb.

Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
2022-06-03 09:04:29 +02:00
Derek Foreman c0cafde80f drm: Remove destroy listener from list when fired
Looks like we missed this one during the conversion to
weston_signal_emit_mutable.

Found by running weston under valgrind and running/killing
weston-simple-dmabuf-egl

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2022-06-03 09:58:09 +03:00
Marius Vlad b0257e0ffc backend-drm: Add GBM_BO_HANDLE as a failure reason
And use it to get a feedback event for when adding scanout tranche.

With this change, I get back a feedback event for dmabuf-feedback
on VC4:

���� tranche: target device /dev/dri/card0, scanout
�   ���� format ABGR2101010, modifier LINEAR (0x0)
�   ���� format XBGR2101010, modifier LINEAR (0x0)
�   ���� format ARGB8888, modifier LINEAR (0x0)
�   ���� format ABGR8888, modifier LINEAR (0x0)
�   ���� format XRGB8888, modifier LINEAR (0x0)
�   ���� format XBGR8888, modifier LINEAR (0x0)
�   ���� format RGB565, modifier LINEAR (0x0)
�   ���� format YUV420, modifier LINEAR (0x0)
�   ���� format YUV422, modifier LINEAR (0x0)
�   ���� format YVU420, modifier LINEAR (0x0)
�   ���� format YVU422, modifier LINEAR (0x0)
�   ���� format NV12, modifier LINEAR (0x0)
�   ���� format NV12, modifier BROADCOM_SAND128 (0x700000000000004)
�   ���� format NV16, modifier LINEAR (0x0)
�   ���� end of tranche

Besides that, it can place a fullscreen state of simple-egl on the
primary plane, which without this change wasn't possible.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2022-06-01 07:38:17 +00:00
Marius Vlad 7412a01437 backend-drm: Retrieve reason if dmabuf import failed
As we could have situations where dmabuf import failed when attempting
to figure it the framebuffer is scanout-capable, make sure we also have
a way to store that information. Otherwise, we could end up
NULL-dereferencing, as we don't provide a valid storage for it.

Further more, with this, we also print out the reason why it failed, to
aid in further debugging.

Observed on platforms where GBM_BO_HANDLE failed + in combination w/
direct-display proto extension.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2022-05-30 16:22:35 +03:00
Pekka Paalanen 8ebebb20ef drm-backend: add color_outcome / HDR metadata serial
Output color profile may be changed in flight. Output basic color
characteristics and EOTF mode cannot yet be changed in flight, but it is
reasonable to assume they could in the future. Therefore the color
outcome data may change in flight as well, which is the basis for HDR
metadata, which needs to be updated as well.

Track the changes to color outcome data with a serial number.
DRM-backend checks the serial number to see if it needs to re-create the
HDR metadata blob. This allows the changes to propagate all the way to
KMS.

The code added here is more of a reminder of what should happen than a
tested path.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2022-05-27 10:30:35 +00:00
Pekka Paalanen c217453c85 backend-drm: forward HDR metadata
Forward the HDR Static Metadata Type 1 to the video sink. This makes the
sink aware of our video content parameters and may be able to produce a
better picture. This type of metadata is used only with the ST 2084 HDR
mode a.k.a PQ.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2022-05-27 10:30:35 +00:00
Pekka Paalanen c4fedd503f backend-drm: move code to kms-color.c
This creates a new file for KMS related color code, to avoid making
drm.c even longer.

The moved code was just added in 5151f9fe9e
so the new file copyrights are written based on that.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2022-05-27 10:30:35 +00:00
Daniel Stone c54eace91d pixel-formats: Rename addfb_legacy_depth
'depth' isn't actually used to determine the bit depth of meaningful
components generally, but specifically to determine whether we can use
the legacy drmModeAddFB (pre-AddFB2) with those formats.

Rename the member to make it more clear what it's used for.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2022-05-20 11:24:41 +00:00
Robert Mader 29d480813a backend-drm: Add failure reasons for failing gbm_bo_import
And add it to the list of failures triggering a resend of
dmabuf feedback scanout tranches.

Closes https://gitlab.freedesktop.org/wayland/weston/-/issues/614

Signed-off-by: Robert Mader <robert.mader@collabora.com>
2022-05-12 11:53:04 +00:00
Pekka Paalanen e6a9e3c4ee backend-drm: default to XRGB2101010 for HDR
Trying to do HDR with XRGB8888 is a bit like using RGB565 on SDR: you
get visible color quantization and banding in gradients (without dithering
which Weston does not implement yet, and might not work too well for HDR
anyway).

Therefore, on any HDR mode, default output framebuffer format to 10 bpc
instead of 8 bpc.

Ideally we'd also optionally try 16F or 16 bpc formats, but automatic
fallbacks for those are more complicated to arrange. You can still
configure 16F or 16 bpc manually.

This patch also moves the default format setting from
drm_output_set_gbm_format() to drm_output_enable(), because setting the
default now requires eotf_mode. Frontends may call set_gbm_format()
first and set eotf_mode next. This does create an awkward situation for
outputs that a frontend disables and re-enables. This patch here makes
sure that the old output configuration remains, but changing eotf_mode
may not change the default format. One needs to call
set_gbm_format(NULL) to re-evaluate the default format. Resetting the
format on drm_output_deinit() would lose the current setting.

DRM_FORMAT_INVALID was introduced in libdrm 2.4.95 which we already
hard-depend on.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2022-05-02 12:19:24 +00:00
Pekka Paalanen 5151f9fe9e backend-drm: program HDR_OUTPUT_METADATA
Program the connector property HDR_OUTPUT_METADATA based on the EOTF
mode of the output.

For now, this changes only the EOTF. The colorimetry and luminance are
left undefined, to be filled in by later patches. This should still be
enough to put a video sink into HDR mode, albeit the response is
probably unknown.

drm_output keeps track of the currently existing blob id. If the blob
contents need to be re-created, this blob would be destroyed and the
field set to zero. In this patch, there is no provision for runtime
changing of HDR metadata, so there is no code doing that.

Destroying the blob at arbitrary times is not a problem, because the
kernel keeps a reference to the data as long as the blob id remains with
KMS.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2022-05-02 12:19:24 +00:00
Pekka Paalanen 1d17e4991f backend-drm: check for HDR_OUTPUT_METADATA
Check whether HDR_OUTPUT_METADATA property exists on a KMS connector. If
yes, pretend that EDID claims support for all EOTF modes and update the
head supported EOTFs mask accordingly. If not, then only SDR is
possible.

Parsing EDID to take monitor capabilities into account is left for
later.

HDR mode cannot be set without HDR_OUTPUT_METADATA.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2022-05-02 12:19:24 +00:00
Pekka Paalanen 6914064066 backend-drm: add HDR_OUTPUT_METADATA definitions
These are fallback definitions in case libdrm is not new enough.
They are copied from libdrm 2.4.107.

struct hdr_output_metadata defines the contents of the blob to be used
with the connector property "HDR_OUTPUT_METADATA".

This is needed for programming a HDR mode in KMS.

This headers need to be excluded from Doxygen, because Doxygen chokes on
the kerneldoc markup.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2022-05-02 12:19:24 +00:00
Daniel Stone 82b646728c backend-drm: Handle solid-colour buffers in state propose
When we're checking to see if a view is suitable to go on a plane, check
for (and reject) solid-colour buffers.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2022-04-25 14:27:08 +00:00
Daniel Stone b38b735e20 backend-drm: Remove Pixman conditional for keep_buffer
The Pixman renderer keeps its own reference to buffers when attached to
surfaces, through its surface state: just use that instead.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2022-04-25 14:27:08 +00:00
Daniel Stone fdc7b9c352 weston_buffer: Add mode to weston_buffer_reference
Add a mode argument to weston_buffer_reference which indicates whether a
buffer's storage may/will be accessed, or whether the underlying storage
will no longer be accessed, e.g. because it has been copied. This will
be used to retain a pointer to the weston_buffer whilst being able to
send a release event to the client.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2022-04-25 14:27:08 +00:00
Daniel Stone e9c792ed64 backend-drm: More failure reasons
Signed-off-by: Daniel Stone <daniels@collabora.com>
2022-04-25 14:27:08 +00:00
Daniel Stone 231a67ff8c drm-backend: Refactor unpleasant keep_buffer if tree
Break a giant if statement out into a more legible grouping.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2022-04-25 14:27:08 +00:00
Daniel Stone 2dcfe723be backend-drm: Make use of weston_buffer format and type
Just pull it from the structure rather than pulling it in externally.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2022-04-25 14:27:08 +00:00
Daniel Stone fef8bb275c weston_buffer: Make use of weston_buffer->type
Rather than calling accessors (wl_shm_buffer_get etc) to figure out
which type our buffer is, just look in the structure.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2022-04-25 14:27:08 +00:00
Sören Meier edef874696 libbacklight: Fix backlight never gets initialized
In 913d7c15f7 stricter error checking was
introduced to the strtol call, which broke reading backlight values.
Since every sysfs backlight file ends with a newline.

As noted in a comment in the previous MR to prevent damaged pointers
after calling asprintf, replace every asprintf call with str_printf.

Previous-MR: https://gitlab.freedesktop.org/wayland/weston/-/merge_requests/543

Signed-off-by: Sören Meier <soerenmeier@livgood.ch>
2022-04-11 08:38:00 +03:00
Michael Tretter 6ee6e76a0c compositor: remove repaint_data from compositor
The repaint_data is entirely backend specific. Moreover, it is only used by the
drm backend, while other backends ignore the repaint data.

There will always be only one repaint active, thus, there is no need to pass the
repaint data from the outside.

The repaint_data breaks with the multi-backend series, which calls repaint begin
for all backends to get the repaint_data. The repaint_data of the last backend
will then be passed to all other backend. At the moment, this works, because the
drm backend is the only backend that implements the begin_repaint call.

Another option would be to track the repaint data per backend in the compositor,
but actually, it the backend needs to track state across the calls, it's its own
responsibility.

Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
2022-04-06 12:47:05 +02:00
Michael Tretter c448b938f7 backend-drm: always get pending_state from backend
The pending_state is already stored in the backend and can be directly retrieved
from there.

This avoids involving the compositor in passing state between the repaint
phases for a single backend.

Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
2022-04-06 12:47:05 +02:00
Derek Foreman 2c91c70250 launchers: Remove --tty option
This doesn't work with any of the launchers we've kept. Remove the option
and all the bits that handle it.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2022-03-03 17:00:15 -06:00
Derek Foreman a96dfc7098 launchers: remove launchers
Moving forward we're going to be supporting libseat and logind as our
only launchers. We're doing this to reduce our maintenance burden,
and security impact.

Libseat supports all our existing use cases, and seatd can replace
weston-launch so we no longer have to carry a setuid-root program.

This patch removes weston-launch, and launcher-direct, leaving only
libseat and logind.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2022-03-03 16:54:14 -06:00
Marius Vlad 0b5c75f540 backend-drm/state-propose: Missing some newlines
It would look much better if the debug is printed separately.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2022-02-07 17:58:35 +02:00
Derek Foreman 66374d48f1 compositor: Remove desktop zoom
Zoom is a neat trick, but in its current form it's very hard to test
and maintain.

It also causes output damage to scale outside of the output's boundaries,
which leads to an extra clipping step that's only necessary when zoom
is enabled.

Remove it to simplify desktop-shell and compositor.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2022-02-03 15:51:20 +00:00
Daniel Stone 30de938624 backend-drm: Add more view-to-plane failure states
Specifically log if there were no suitable planes for us to use, or if
we tried to place it on a plane but were told no by the kernel.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2022-02-01 23:12:11 +00:00
Daniel Stone a2c5709e71 backend-drm: Pass paint node through to plane_state find
This lets us clean up a bit of code.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2022-02-01 23:12:11 +00:00
Daniel Stone 0ace8b66af backend-drm: Unify overlay/primary view->plane code
There's no real reason for these to be separate now that the eligibility
checks have been moved up so we don't call them unless it makes sense.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2022-02-01 23:12:11 +00:00
Daniel Stone 81e74ff334 backend-drm: Don't take buffer-release reference for cursor views
We just copy the SHM buffer straight into a separately-allocated GBM BO,
so no need to take a reference on the buffer itself or keep it from
being released.

All drm_output_try_view_on_plane really does at this point is to call
the prepare_*_view function for the requisite plane type, and take a ref
on the weston_buffer from the client. Given that we don't need to keep
the client buffer alive, we can short-circuit
drm_output_try_view_on_plane, and instead just call
drm_output_prepare_cursor_view directly when we have a cursor plane.

This also makes it easier to just remove drm_output_try_view_on_plane in
following patches when we merge the overlay/scanout plane path into one.
Doing so gives us two clearly-separated paths: one for copying a SHM
client buffer into a cursor, and another for directly scanning out
client content.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2022-02-01 23:12:11 +00:00
Daniel Stone 873e32137e backend-drm: Remove unnecessary check for fb
Signed-off-by: Daniel Stone <daniels@collabora.com>
2022-02-01 23:12:11 +00:00
Daniel Stone e1114228f5 backend-drm: Remove unused enum
At some point this got hobbled, such that NO_PLANES and
NO_PLANES_ACCEPTED became the same thing, so we can just check if the
returned plane_state is NULL or not.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2022-02-01 23:12:11 +00:00
Daniel Stone 2dd3af3c22 backend-drm: Move IN_FENCE_FD check to common code
No need for this to be specialised within both overlay and scanout plane
paths.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2022-02-01 23:12:11 +00:00
Daniel Stone 1b34c5cd80 backend-drm: Remove unnecessary check in prepare_scanout_view
We already guarantee this from the caller.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2022-02-01 23:12:11 +00:00
Daniel Stone 6b828c7b57 backend-drm: Don't try non-fullscreen views on the primary plane
You'd think this would go without saying, but no, we just sort of buried
that.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2022-02-01 23:12:11 +00:00
Daniel Stone dc0de9ee2b backend-drm: Move overlay vs. primary plane check earlier
For views which cover the entire output, we always attempt to place them
on the primary plane, to avoid a situation where we place a fullscreen
view into an overlay plane and then have to disable the primary plane,
which doesn't always work.

Move this check earlier, so we don't consider overlay planes to be
candidates for fullscreen views. This check should be changed in future
to only filter for opaque views, but that's for another time.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2022-02-01 23:12:11 +00:00
Daniel Stone 5e41b44b10 backend-drm: Change cursor checks to asserts
We shouldn't get down into trying to place a view on a cursor plane if
these checks are not met, so change them to asserts rather than early
returns.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2022-02-01 23:12:11 +00:00
Daniel Stone b3d7df5c3e backend-drm: Move plane-type-specific checks to switch statement
This makes it a bit more clear and easy to follow, rather than diving
through if nesting.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2022-02-01 23:12:11 +00:00
Daniel Stone 0ecd6c3d33 backend-drm: Move renderer-only vs. scanout_plane test earlier
No point trying to put something on the scanout plane in mixed mode.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2022-02-01 23:12:11 +00:00
Daniel Stone ae60745b61 backend-drm: Move cursors_are_broken test earlier
No point trying to place a cursor buffer on a plane when we can't do
cursor planes.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2022-02-01 23:12:11 +00:00
Daniel Stone e5ad3c8865 backend-drm: Remove separate zpos_plane list
When we introduced support for variable zpos, we did so by filtering the
list of acceptable planes and then creating a separate zpos-ordered
list. Now that the planes are already zpos-sorted in the backend list,
and we have more early filtering, we can replace this with a single
plane-list walk.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2022-02-01 23:12:11 +00:00
Daniel Stone 23257c073f backend-drm: Minor comment rewording
Signed-off-by: Daniel Stone <daniels@collabora.com>
2022-02-01 23:12:11 +00:00
Daniel Stone 26c2f9a65f backend-drm: Don't try cursor buffers for client planes
For better or worse, cursor planes can only be used by uploaded SHM
buffers right now, so ignore them when we're calculating the acceptable
plane mask for client dmabufs.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2022-02-01 23:12:11 +00:00
Daniel Stone 9c6a069435 backend-drm: Early-out for non-SHM buffers in renderer-only mode
If we're in renderer-only mode, we can only use the renderer and the
cursor plane. Don't even try to import client buffers as it makes no
sense.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2022-02-01 23:12:11 +00:00
Daniel Stone 6aec64b2f7 backend-drm: Early-out for too-large SHM/cursor buffers
We know what our limit is for cursor planes, so don't try to assign a
view which is too large.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2022-02-01 23:12:11 +00:00
Daniel Stone ca4c2865e9 backend-drm: Early-out for cursor plane format testing
If we have a SHM buffer, it can only go into a cursor plane - and only
then if it's of the right format.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2022-02-01 23:12:11 +00:00
Daniel Stone 66244856e2 backend-drm: Don't try to import SHM buffers as drm_fb
It won't work.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2022-02-01 23:12:11 +00:00
Daniel Stone d5ec9a1a1d backend-drm: Don't try to steal other-output special planes
Each output is hardcoded to the use of a single 'special' (primary or
cursor) plane; make sure we don't try to steal them from other outputs
which might not be happy to discover that we've taken it off them.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2022-02-01 23:12:11 +00:00
Daniel Stone 075c4ac286 backend-drm: Don't try to use planes without GBM
GBM is how we import all our client content into DRM FBs, so don't try
anything other than renderer-only without it.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2022-02-01 23:12:11 +00:00
Daniel Stone af42fc1e33 backend-drm: Assign plane_idx by plane list order
Signed-off-by: Daniel Stone <daniels@collabora.com>
2022-02-01 23:12:11 +00:00
Daniel Stone 6609840479 backend-drm: Pre-sort plane list by zpos
Rather than constructing a zpos-sorted list every time, just have
plane_list be pre-sorted.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2022-02-01 23:12:11 +00:00
Daniel Stone 7ca7c14553 backend-drm: Rewrite zpos-sorting list insertion
It's possible to write this with a few less twisty special cases. Tested
manually with a randomly-distributed input tree as well as manually
trying to hit special cases around first/last entries.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2022-02-01 23:12:11 +00:00
Derek Foreman db7e85d5f8 drm: Fix hang on zoom
Transforming the scanout damage by the zoom will result in rectangles
outside of the display, and some with negative co-ordinates. This makes
at least some drivers unhappy (tested on vmware), and the page flip fails,
and weston hangs indefinitely.

Clip the damage to the output so we don't fall down.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2022-01-25 16:33:10 +00:00
Marius Vlad bb55d86300 backend-drm/drm-gbm: gbm_device_destroy on an invalid gbm device
When EGL initialization fails (failure to create a GLES3 or GLES2
context) we will end up calling gbm_device_destroy() twice, once
in init_egl() and once in the drm_backend_create() error path.

Given that we should also take care of properly destroying the gbm
device when we don't have any inputs for instance, mark the gbm device
as NULL to avoid calling gbm_device_destroy() once more when destroying
the DRM-backend.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2022-01-12 13:52:26 +00:00
Daniel Stone 57d609a47e backend-drm: Cache fb<->plane format compatibility list
Walking the format/modifier list to try to find out if our FB is
compatible with the plane is surprisingly expensive. Since the plane's
capabilities are static over the lifetime of the KMS device, cache the
set of planes for which the FB is theoretically
format/modifier-compatible when it's created, and use that to do an
early cull of the set of acceptable planes.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2021-12-08 13:38:18 +00:00
Daniel Stone 7d27df4c4c backend-drm: Cache drm_fb for each weston_buffer
When we first create a drm_fb from a weston_buffer, cache it and keep it
alive as long as the buffer lives. This allows us to reuse the gbm_bo
and kernel-side DRM framebuffer, rather than constantly creating and
destroying them at every repaint. The overhead of doing so (e.g. MMU
updates) can be significant on some platforms.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2021-12-08 13:38:18 +00:00
Daniel Stone 2ecc38b042 backend-drm: Move fb -> buffer reference to plane state
Currently each drm_fb takes a reference on a client buffer it wraps.
This prevents us from being able to reuse a drm_fb in multiple places
(e.g. two views of the same client buffer) simultaneously, or even back
to back.

Move the buffer reference to the plane state, as preparation for
allowing drm_fb to be cached inside the weston_buffer.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2021-12-08 13:38:18 +00:00
Daniel Stone 267f6cc6a1 backend-drm: Move drm_fb reference to state-propose
Currently we take a reference on the underlying client buffer every time
we materialise a drm_fb from a view, and release it when the drm_fb is
destroyed. This means that we need to create and destroy a drm_fb every
time we want to use it, which is pathologically unperformant on some
platforms.

To start working towards being able to cache drm_fb, only take the
reference when we apply it to a plane state.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2021-12-08 13:38:18 +00:00
Daniel Stone 9e379db082 backend-drm: Early-out in plane assignment for unimportable buffers
No sense walking the plane list every frame if we can't use it because
it's neither a SHM buffer nor a client buffer we can directly import as
a framebuffer.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2021-12-08 13:38:18 +00:00
Daniel Stone f508603420 backend-drm: Free scanout format table after use
We were deinitialising the array, but not also freeing the allocation.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2021-12-08 13:38:18 +00:00
Leandro Ribeiro 5429302e78 backend-drm: add KMS plane's formats to per-surface dma-buf feedback
In commit "libweston: add initial dma-buf feedback implementation" we've
added initial support to dma-buf feedback, but it was not using the
feedback from DRM-backend to add useful per-surface feedback.

In this patch we add this. The scanout tranche of the per-surface
feedback is based on the union of formats/modifiers of the primary and
overlay planes available. These are intersected with the
formats/modifiers supported by the renderer device.

Also, it's important to mention that the scene can change a lot and we
can't predict much. So this patch also adds hysteresis to the dma-buf
feedback. We wait a few seconds to be sure that we reached stability
before adding or removing the scanout tranche from dma-buf feedback and
resending them. This help us to avoid spamming clients and leading to
unnecessary buffer reallocations on their end.

Here's an example of what we want to avoid:

1. We detect that a view was not placed in a plane only because its
   format is not supported by the plane, so we add the scanout tranche
   to the feedback and send the events.

2. A few milliseconds after, the view gets occluded. So now the view
   can't be placed in a plane anymore. We need to remove the scanout
   tranche and resend the feedback with formats/modifiers optimal for
   the renderer device. The client will then reallocate its buffers.

3. A few milliseconds after, the view that was causing the occlusion
   gets minimized. So we got back to the first situation, in which the
   format of the view is not compatible with the plane. Then we need to
   add a scanout tranche and resend the feedback...

This patch is based on previous work of Scott Anderson (@ascent).

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
Signed-off-by: Scott Anderson <scott.anderson@collabora.com>
Reviewed-by: Daniel Stone <daniels@collabora.com>
2021-11-25 11:16:52 -03:00
Leandro Ribeiro 0a7034c0cb backend-drm: keep track of the reason why promoting view to a plane failed
Add enum try_view_on_plane_failure_reasons to help us to keep track of
the reason why promoting view to a plane failed. We also add a variable
to struct weston_paint_node so that we can update this information in
each output repaint.

This will be used in the next commits, in which we add proper surface
dma-buf feedback support.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
Reviewed-by: Daniel Stone <daniels@collabora.com>
2021-11-25 11:16:21 -03:00
nerdopolis d2a320d53e Fix TTY switching after failed failed repaint with legacy mode set.
Reported in !179 adding weston_output_repaint_failed resets the output

Co-authored-by: Daniel Stone
Co-authored-by: Julius Krah
Signed-off-by: n3rdopolis <bluescreen_avenger@verizon.net>
2021-09-29 12:17:58 +00:00
Daniel Stone aed8aafdbf drm/vaapi: Fix pointer-size confusion
The API expects uintptr_t (good!), but we're passing an unsigned long
here. Make the conversion explicit.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2021-08-03 11:13:23 +00:00
Emmanuel Gil Peyrot eff793ab46 Fix indentation all through the project
Fixes a “regression” from 04918f3b0b, but
also other missed pieces.
2021-07-31 15:28:20 +00:00
Derek Foreman 74bdb35c85 drm: Ignore timestamp for monitor shut-off
Some graphics drivers (currently at least VMware and AMD) will give a 0
timestamp for the atomic mode flip completion event when turning off
the display. This causes us to trip an assertion in
weston_output_frame_finish() because the clock jumps backwards, which
isn't a condition the presentation feedback code should be dealing with.

This is a good assertion and we'd like to keep it. And there's some
expectation that this is buggy behaviour in the graphics drivers that will
be fixed at some point.

Pragmatically speaking though, there's nothing productive we can do with a
correct timestamp for the display shutdown.  So let's just flag the
event sent for DPMS off as invalid so presentation feedback doesn't have
to worry about it, and the assert doesn't fire.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2021-07-31 13:39:27 +00:00
Marius Vlad 7a44ee7f37 backend-drm: Clean-up minor leak when destroying the DRM-backend
Fixes a minor leak due to launcher-libseatd:

Direct leak of 32 byte(s) in 1 object(s) allocated from:
    #0 0x7f15664e5037 in calloc (/usr/lib/x86_64-linux-gnu/libasan.so.6+0xaa037)
    #1 0x7f156305c59f in zalloc ../include/libweston/zalloc.h:38
    #2 0x7f156305c99b in seat_open_device ../libweston/launcher-libseat.c:114
    #3 0x7f1563056341 in weston_launcher_open ../libweston/launcher-util.c:79
    #4 0x7f156302f1e2 in drm_device_is_kms ../libweston/backend-drm/drm.c:2616
    #5 0x7f156302f751 in find_primary_gpu ../libweston/backend-drm/drm.c:2715
    #6 0x7f15630309a5 in drm_backend_create ../libweston/backend-drm/drm.c:2970
    #7 0x7f15630317ab in weston_backend_init ../libweston/backend-drm/drm.c:3162
    #8 0x7f1566025b61 in weston_compositor_load_backend ../libweston/compositor.c:8201
    #9 0x7f156640cb9e in load_drm_backend ../compositor/main.c:2596
    #10 0x7f156641193c in load_backend ../compositor/main.c:3079
    #11 0x7f1566413cc3 in wet_main ../compositor/main.c:3356
    #12 0x562ba484b179 in main ../compositor/executable.c:33
    #13 0x7f156624fcc9 in __libc_start_main ../csu/libc-start.c:308

But also use the launcher interface to actually close the DRM fd, in
mirror to what weston_launcher_open() does.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2021-06-28 11:44:52 +00:00
Alexandros Frantzis 10937feef8 backend-drm: Clear drm_output cursor_view when view is destroyed
The DRM backend uses changes in the cursor view memory address and
surface damage to detect when it needs to re-upload to a cursor plane
framebuffer.

However, when a cursor view is destroyed and then recreated, e.g., when
the pointer cursor surface is updated, the newly created view may have
the same memory address as the just destroyed one. If no new cursor
buffer is provided (because it was attached, committed and used
previously) when this address reuse occurs, then there also isn't any
updated surface damage and the backend doesn't update the cursor plane
framebuffer at all.

To fix this issue utilize the destroy signal to track when the cursor
view is destroyed, and clear the cached cursor_view value in drm_output.
After clearing the cached value, the next cursor view is always
considered new and thus uploaded to the plane properly.

Signed-off-by: Alexandros Frantzis <alexandros.frantzis@collabora.com>
2021-06-14 13:31:41 +00:00
Pekka Paalanen 90a5ffa097 libweston: introduce CMS component architecture
See: https://gitlab.freedesktop.org/wayland/weston/-/issues/467#note_814985

This starts building the framework required for implementing color
management.

The main new interface is struct weston_color_manager. This commit also
adds a no-op color manager implementation, which is used if no other
color manager is loaded. This no-op color manager simply provides
identity color transforms for everything, so that Weston keeps running
exactly like before.

weston_color_manager interface is incomplete and will be extended later.

Colorspace objects are not introduced in this commit. However, when
client content colorspace and output colorspace definitions are
combined, they will produce color transformations from client content to
output blending space and from output blending space to output space.

This commit introduces a placeholder struct for color transforms,
weston_color_transform. Objects of this type are expected to be heavy to
create and store, which is why they are designed to be shared as much as
possible, ideally making their instances unique. As color transform
description is intended to be generic in libweston core, renderers and
backends are expected to derive their own state for each transform
object as necessary. Creating and storing the derived state maybe be
expensive as well, more the reason to re-use these objects as much as
possible. E.g. GL-renderer might upload a 3D LUT into a texture and keep
the texture around. DRM-backend might create a KMS blob for a LUT and
keep that around.

As a color transform depends on both the surface and the output, a
transform object may need to be created for each unique pair of them.
Therefore color transforms are referenced from weston_paint_node. As
paint nodes exist for not just surface+output but surface+view+output
triplets, the code ensures that all paint nodes (having different view)
for the same surface+output have the same color transform state.

As a special case, if weston_color_transform is NULL, it means identity
transform. This short-circuits some checks and memory allocations, but
it does mean we use a separate member on weston_paint_node to know if
the color transform has been initialized or not.

Color transformations are pre-created at the weston_output
paint_node_z_order_list creation step. Currently the z order lists
contain all views globally, which means we populate color transforms we
may never need, e.g. a view is never shown on a particular output.
This problem should get fixed naturally when z order lists are
constructed "pruned" in the future: to contain only those paint nodes
that actually contribute to the output's image.

As nothing actually supports color transforms yet, both renderers and
the DRM-backend assert that they only get identity transforms. This
check has the side-effect that all surface-output pairs actually get a
weston_surface_color_transform_ref even though it points to NULL
weston_color_transform.

This design is inspired by Sebastian Wick's Weston color management
work.

Co-authored-by: Sebastian Wick <sebastian@sebastianwick.net>
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2021-06-14 12:53:41 +00:00
Igor Matheus Andrade Torrente bfcb1adc14 backend-drm: Drop support to non universal plane drivers
Remove all the backend code to support drivers without universal planes.

From[1]:

"The code needed to support kernels where DRM does not support uiniversal
planes makes the DRM-backend a little more complicated, because it needs
to create fake planes for primary and cursor. The lifetimes of the fake
planes does not match the lifetime of "proper" planes, which is surprising."

And since the universal planes left the experimetal flag in 2014[2] it is
safe to remove the support now.

[1] https://gitlab.freedesktop.org/wayland/weston/-/issues/427
[2] https://cgit.freedesktop.org/drm/drm-tip/commit/?id=c7dbc6c9ae5c3baa3be755a228a349374d043b5b

Signed-off-by: Igor Matheus Andrade Torrente <igormtorrente@gmail.com>
2021-06-01 17:25:20 +00:00
Pekka Paalanen aa2e0b2075 drm-backend: iterate paint nodes
Iterate paint nodes instead of the global view list. Right now this does
not change behavior.

This is a step towards using per-output view lists that can then be
optimized for the output in libweston core.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2021-05-18 14:06:21 +03:00
Daniel Stone 3d9b73c9e5 drm/state-propose: Remove unnecessary check
If sprites_are_broken, then we will only ever arrive in renderer_only
mode, so this case will be caught by the checks above.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2021-05-15 15:24:12 +00:00
Pekka Paalanen f48277b577 drm-backend: require DRM_CAP_TIMESTAMP_MONOTONIC
Weston internals and Wayland clients assume that output presentation
clock cannot go backwards. Therefore require unconditionally that KMS
uses the monotonic clock.

The kernel unconditionally supports DRM_CAP_TIMESTAMP_MONOTONIC. See:

commit 25e1a79874eb3821d93310c908cc0a81b47af060
Author: Arnd Bergmann <arnd@arndb.de>
Date:   Wed Oct 11 17:20:13 2017 +0200

    drm: vblank: remove drm_timestamp_monotonic parameter

That one removed the final possibility of DRM_CAP_TIMESTAMP_MONOTONIC
being false, by removing the module option. But even before that, all
drivers have been supporting monotonic, since

commit c61eef726a78ae77b6ce223d01ea2130f465fe5c
Author: Imre Deak <imre.deak@intel.com>
Date:   Tue Oct 23 18:53:26 2012 +0000

    drm: add support for monotonic vblank timestamps

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2021-05-11 09:07:46 +00:00
Bastian Krause d8b861766c backend-drm/state-propose: print format instead of *pixel_format_info address
fb->format is *pixel_format_info, whereas fb->format->format is the
actual DRM/wl_shm format code we want to see here. Fix the drm_debug()
call accordingly.

Signed-off-by: Bastian Krause <bst@pengutronix.de>
2021-05-06 14:12:32 +02:00
Leandro Ribeiro 3193ab5807 backend-drm: simplify compile time array copy
In drm_fb_get_from_dmabuf() we have some compile time array copies, and
multiple static_assert() calls are needed (for safety). This makes the
code unpleasant to read.

Add ARRAY_COPY macro, to simplify the code.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
2021-04-27 19:00:38 -03:00
Leandro Ribeiro a5560d6dbe backend-drm: document that we allow to import wl_drm buffers to KMS with no modifiers
In commit "backend-drm: do not import dmabuf buffers with no modifiers
to KMS" we've stopped to import dmabuf with no modifiers to KMS.

In this patch we document why we can still import wl_drm buffers with no
modifiers to KMS.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
2021-04-27 19:56:38 +00:00
Leandro Ribeiro 5aea1bc522 backend-drm: do not import dmabuf buffers with no modifiers to KMS
We can't tell the layout of a buffer that has been allocated with no
modifiers. Although usually drivers use linear layouts to allocate in
these cases, it is not a rule. It can use a tiling layout, for instance,
under the hood.

So it is not safe to import a buffer with no modifiers to KMS, as it
can't tell the buffer layout and this may result in garbage being
displayed. In this patch we start to require explicit modifiers to
import buffers to KMS.

In most cases things just work as expected, but just because both sides
(display and render driver) usually end up using the linear layout when
modifiers are not exposed. It also works on systems where the display
and render devices are tied (desktops with Intel or AMD, for instance),
as there's only one driver and it knows the layout of the buffer (no
need to guess).

But in SoC's where the display and render device are split, things can
go wrong. It is better to lose performance and not break things. To
solve the problem, drivers should be updated to expose modifiers (even
if only DRM_FORMAT_MOD_LINEAR), as the concept of implicit modifiers is
the root of the problem.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
2021-04-27 19:56:38 +00:00
Leandro Ribeiro 98101e88cc backend-drm: ignore formats without modifiers from IN_FORMATS
In commit "backend-drm: add DRM_FORMAT_MOD_INVALID to modifier sets when
no modifiers are supported" we've changed the code that iterates through
the IN_FORMATS blob property. Now it adds DRM_FORMAT_MOD_INVALID for
formats exposed without modifiers.

But the thing is that there shouldn't be formats in the IN_FORMATS blob
exposed without modifiers, as the blob has been added after the
introduction of the explicit modifiers API in the kernel. For now,
there's nothing in the kernel to ensure this correct behavior. So
instead of adding DRM_FORMAT_MOD_INVALID in this case, ignore these
formats, as userspace can't do much in this case.

In the future this may be fixed by the kernel. Or maybe the following MR
in libdrm, which adds an iterator API for the IN_FORMATS blob:

https://gitlab.freedesktop.org/mesa/drm/-/merge_requests/146

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
2021-04-27 19:56:38 +00:00
Leandro Ribeiro 567cc92797 backend-drm: add DRM_FORMAT_MOD_INVALID to modifier sets when no modifiers are supported
From now on, when we can't know the modifiers supported for a certain
format, we add DRM_FORMAT_MOD_INVALID to its modifier set.

There is some parts where nothing is being added an others where
DRM_FORMAT_MOD_LINEAR is being added, so fix them.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
2021-04-27 19:56:38 +00:00
Leandro Ribeiro f767302729 backend-drm: fix slightly wrong comment about allocating with no modifiers
In create_gbm_surface() we may allocate with no modifiers in the
following situations:

1. old GBM version, so HAVE_GBM_MODIFIERS is false;
2. the KMS driver does not support modifiers;
3. if allocating with modifiers failed, what can happen when the KMS
   display device supports modifiers but the GBM driver does not, e.g.
   the old i915 Mesa driver.

The comment was only stating the third situation, so add the other two.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
2021-04-27 19:56:38 +00:00
Leandro Ribeiro 3459bad63d backend-drm: move code that creates gbm surface to a separate function
The function drm_output_init_egl() is too big, so move the code to
create the gbm surface to a separate function: create_gbm_surface().

Also made some minor style changes to the code that has been moved, in
order to improve readability.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
2021-04-27 19:56:38 +00:00
Scott Anderson 7466309c12 backend-drm: start to use weston_drm_format in drm_plane
In commit "libweston: add struct weston_drm_format" struct
weston_drm_format and its helper functions were added to libweston.
Also, unit tests for this API have been added in commit "tests: add unit
tests for struct weston_drm_format".

Start to use this API in the DRM-backend, as it enhances the code by
avoiding repetition and ensuring correctness.

Signed-off-by: Scott Anderson <scott.anderson@collabora.com>
Co-authored-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
2021-04-27 19:56:38 +00:00
Leandro Ribeiro 4b5df8b39f backend-drm: move check that skips cursor planes for views that don't use wl_shm buffer
In drm_output_prepare_plane_view() we iterate the list of planes and add
them as candidates to promote the view to one of them.

Cursor planes do not support buffers other than wl_shm (at least for
now). So when we have a dmabuf or an EGL buffer in the view, the
function drm_output_plane_cursor_has_valid_format() returns false and
the cursor plane is not added to the candidate list.

In this patch we move the responsibility of doing this from
drm_output_plane_cursor_has_valid_format() to
drm_output_prepare_plane_view() itself, as the incompatibility between
other types of buffers and cursor planes is different from the
incompatibility between formats. This makes the code easier to read
and also documents the current incompatibility between cursor planes
and buffers that are not created through wl_shm.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
2021-04-27 19:56:38 +00:00
Leandro Ribeiro 2984f36c72 backend-drm: set plane format to gbm_format at the appropriate time
In the absence of universal planes support,
drm_output_find_special_plane() sets the plane format to zero as a
placeholder. Then in drm_output_init_planes() it sets the format to
output->gbm_format.

As output->gbm_format is already set by the time we call
drm_output_find_special_plane(), simply set the plane format to it
directly in this function. This makes the code clearer, as there is no
reason to use the placeholder.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
2021-04-27 19:56:38 +00:00
Marius Vlad 7a465d855e backend-drm/state-propose: Check the surface buffer dimensions for cursor case
In some situations, like positioning a sub-surface that exceeds the
output's dimensions we would adjust the plane state dimensions to some
lower values to that of the buffer. That would ultimately trip the cursor
update function because the buffer itself actually exceeds the maximum
size/dimension of the cursor.

The plane state destination co-ordinates is the area of the view which
is visible on the output, which in some situations, would actually be
smaller than the original buffer dimensions (making it so that it will
pass the cropping/scaling check), but depending on of
how large is the surface buffer, it would tripping the assert wrt to
cursor width/height dimensions.

This hasn't been seen so far due to the fact that until recently we had
a cursor surface that always reached the cursor plane and that was
already being set-up by default (with desktop-shell, which is no longer
the case), and also because kiosk-shell, which doesn't set-up a cursor
surface, was not available.

This adds a check to skip placing the view in the cursor plane if the
buffer dimensions exceed the cursor permitted width/height.
(Suggested-by Daniel Stone).

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2021-04-10 23:03:23 +00:00
Marius Vlad d171c7b3ba libweston/backend-drm: Re-order gbm destruction at DRM-backend tear down
Tearing down the drm-backend when there are no input devices, would call
for the gbm device destruction before compositor shutdown. The latter
would call into the renderer detroy function and assume that the
EGLDisplay, which was created using the before-mentioned gbm device, is
still available. This patch re-orders the gbm destruction after the
compositor shutdown when no one would make use of it.

Fixes: #314

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
Suggested-by: Daniel Stone <daniel.stone@collabora.com>
2021-04-01 11:28:44 +03:00
Pekka Paalanen 4b301fe7f2 Add weston-drm-fourcc.h
This header is for sharing fallback definitions for drm_fourcc.h. A new
test in tests/yuv-buffer-test.c is going to be needing XYUV8888 format,
and more new formats will be expected with HDR supports.

Share these fallback definitions in one place instead of copying them
all over.

All users of drm_fourcc.h are converted to include weston-drm-fourcc.h
instead for consistency: have the same definitions available everywhere.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2021-02-25 14:35:03 +02:00
Pekka Paalanen b9ca801324 drop MOD_INVALID, MOD_LINEAR definitions
MOD_INVALID came with libdrm 2.4.83 and MOD_LINEAR came with libdrm
2.4.82. libweston unconditionally depends on libdrm >= 2.4.95, so the
fallback is not necessary.

Since linux-dmabuf.h itself has no use for these and also forgets to
include drm_fourcc.h, .c files including drm_fourcc.h after this header
would trigger compiler warnings.

linux-dmabuf.c does need these, so add the proper include.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2021-02-25 14:35:03 +02:00
Pekka Paalanen 7f1a113c89 drm-backend: do not skip renderer if capturing screen
The renderer must be called for any pending screen capture to complete.
Previously this was guaranteed by weston_screenshooter_shoot() forcing
full output damage, so damage was never empty. If the future,
screenshooting stops inflicting damage, and the damage on the primary
plane even after disabling hardware planes may be empty.

This patch ensures that screenshots do not get stuck until damage
occurs.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2021-02-25 12:47:07 +02:00
Maxime Roussin-Bélanger 35e34505ce backend-drm: fix typos
Signed-off-by: Maxime Roussin-Bélanger <maxime.roussinbelanger@gmail.com>
2021-02-24 10:01:07 -05:00
Marius Vlad a86b590fea backend-drm: Fix ignoring config 'require-input' option
Without this patch, the DRM-backend would rewrite the 'require-input',
core section option given by the user.

This removes 'continue_without_input' DRM-backend option and takes into
consideration the cmd line option only if that was passed (Pekka Paalanen).

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2020-12-07 12:49:38 +02:00
Heiko Thiery ea0b03dff0 libweston/backend/drm: might need EGL
gbm-drm.c includes gl-renderer.h. When EGL is enabled, that in turns
includes egl.h. As such, dependencies for drm should include EGL if
it is available.

This condition is modelled after a similar one in libweston/meson.build

Reported-by: Gary Bisson <gary.bisson@boundarydevices.com>
Reported-by: Heiko Thiery <heiko.thiery@gmail.com>
Signed-off-by: Yann E. MORIN <yann.morin.1998@free.fr>
Cc: Refik Tuzakli <tuzakli.refik@gmail.com>
Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Signed-off-by: Heiko Thiery <heiko.thiery@gmail.com>
2020-10-26 15:44:34 +01:00
Igor Matheus Andrade Torrente 6354455979 backend-drm: Reuse drmModeRes in drm_backend_create
Rework some functions in `drm.c` to reuse the `drmModeRes` and
reduce the usage of `drmModeGetResources` and `drmModeGetResources`.

Signed-off-by: Igor Matheus Andrade Torrente <igormtorrente@gmail.com>
2020-10-19 09:12:02 +00:00
Pekka Paalanen 9b94a7d833 Bump libdrm dependency to 2.4.95
96bef0517e "drm-backend: add support for
writeback connectors" started using DRM_MODE_CONNECTOR_WRITEBACK and
DRM_CLIENT_CAP_WRITEBACK_CONNECTORS. These were introduced in libdrm
2.4.95.

According to
https://gitlab.freedesktop.org/wayland/weston/-/merge_requests/311
Ubunut Xenial is the only mentioned distribution that does not provide a
libdrm new enough. I think that is fine to drop now, 2016 was a good
while ago.

Libdrm 2.4.95 also introduced DRM_CLIENT_CAP_ASPECT_RATIO,
DRM_MODE_PICTURE_ASPECT_64_27, DRM_MODE_PICTURE_ASPECT_256_135.

The fallback definitions for the above are dropped.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2020-10-16 16:20:54 +00:00
Leandro Ribeiro 96bef0517e drm-backend: add support for writeback connectors
Recognize writeback connectors and add 'struct drm_writeback'
objects in order to store them.

These objects are created and stored in a list by the time
that DRM-backend is initialized. This list is updated if a
writeback connector dynamically appears or is disconnected.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
2020-09-16 14:03:18 +00:00
Leandro Ribeiro 7243022b38 drm-backend: add function drm_backend_add_connector() to create drm_head for connectors that appear
Instead of directly creating heads for the connectors in functions
drm_backend_create_heads() and drm_backend_update_connectors(),
add drm_backend_add_connector() that will handle this.

This split makes the code look better and will also make our lives
easier when we introduce writeback connectors.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
2020-09-16 14:03:18 +00:00