Commit graph

1046 commits

Author SHA1 Message Date
Xaver Hugl
c3c3f56e98 implement a proper tone mapping algorithm
Instead of just clipping when HDR content is brighter than the maximum luminance the
screen can show, when HDR metadata indicates this could happen, KWin now
- converts the rgb colors to ICtCp, to split luminance and color
- applies a tone mapping curve that maps the intensity component from
 - [0, reference] to [0, newReference] linearly
 - [reference, max content luminance] to [newReference, max display luminance] nonlinearly
- converts the resulting ICtCp color back to rgb

The result is that HDR content looks much, much better on SDR displays, at least when decent
HDR metadata is provided.
As wrong metadata could cause this tone mapping to wrongly kick in in games for example, the
environment variable KWIN_DISABLE_TONEMAPPING is provided to disable tone mapping and fall back
to clipping again instead.
2024-08-22 23:04:00 +02:00
Xaver Hugl
e7780f1ab3 backends/drm: implement damage tracking for the color management shadow buffer
This significantly reduces the amount of pixels that have to be repainted in most frames
while an ICC profile is set.

BUG: 477223
2024-08-21 23:01:00 +02:00
Xaver Hugl
1dab5fb328 backends/drm: support tearing with atomic modesetting
Whenever tearing is desired, this does an atomic test to figure out if the current
configuration can do tearing - if not, the backend just transparently falls back to
synchronous commits.
As the kernel (as of Linux 6.9) rejects all commits that are both async and modify
more than the primary plane FB_ID property, this disables the cursor plane and
IN_FENCE_FD usage, to make it more likely for the atomic commit to succeed.
Once these restrictions are loosened, these checks can be removed as well.
2024-08-21 16:02:19 +00:00
Xaver Hugl
8a5f469f95 backends/drm: implement damage tracking for multi gpu transfers
Doesn't seem to help on my system, but maybe it helps with different drivers
2024-08-20 13:04:18 +00:00
Xaver Hugl
7ab825cba1 backends/drm: test direct scanout with the same code as presentation
This means that we prefer direct scanout over a specific presentation mode (tearing),
which usually just means we first engage direct scanout and program the relevant
properties, and then switch to tearing afterwards.
It also removes a hack for direct scanout with legacy, and is one step less for
implementing overlay plane support.
2024-08-16 14:26:58 +02:00
David Redondo
df184ebd11 fakeinput: Remove static touches list
We track now touches per device
2024-08-16 08:48:49 +00:00
David Redondo
436211ad45 fakeinput: Keep track of pressed buttons, keys and touches
To prevent having them eternally pressed when the device is
destroyed.
2024-08-16 08:48:49 +00:00
Xaver Hugl
fe5db7f97d backends/drm: disable degamma_lut and ctm on NVidia
The NVidia driver maps them to hardware planes, which means they do not
apply to the cursor because the cursor plane doesn't have these color
operations.

BUG: 491634
2024-08-15 15:26:41 +02:00
Xaver Hugl
45c09de02b backends/drm: make minBrightness in the color description more accurate in SDR
There's no way to go below the min. luminance of the transfer function
2024-08-15 01:23:00 +00:00
Xaver Hugl
0fdc3b2633 core/iccprofile: read and use the black point for black point compensation 2024-08-15 01:23:00 +00:00
Xaver Hugl
96ed79fd62 backends/drm: fix ICC profiles not being applied
The check for a shadow buffer used a variable before it was set to the new value,
and the shaders are broken for some reason, so I reverted them to use the previous
code with only the transfer function parameters added.
2024-08-12 21:07:19 +00:00
Xaver Hugl
418143a45b core/colorspace: move Colorimetry::toOther to ColorDescription
With some rendering intents we need to apply behavior based on brightness levels
or the SDR colorimetry
2024-08-12 11:46:32 +00:00
Xaver Hugl
833476a111 core/colorspace: add rendering intents
Rendering intents describe how to handle mapping between different colorspaces,
what to do with out of gamut values and what to do if the whitepoint doesn't match.
This way, clients can choose which behavior their content should get.
2024-08-12 11:46:32 +00:00
Xaver Hugl
6bd07ad6b3 backends/drm: remove the shadow buffer when possible, and reduce it to 10bpc when not
Using the custom values for min. and max. luminance in transfer functions, we can reduce the
ranges of values in the shadow buffer to be limited to [0, 1], and with that we can switch
from a floating point buffer back to a normalized format. As gamma 2.2 encoding is much more
efficient at storing color values, this also drops the buffer from 16bpc down to 10bpc.

Furthermore, this offloads the gamma 2.2 -> PQ conversion to KMS when possible, and then uses
the scanout buffer with gamma 2.2 encoding directly. This way the shadow buffer gets completely
skipped and performance and efficiency get improved a lot.

BUG: 491452
CCBUG: 477223
2024-08-09 15:18:43 +02:00
Xaver Hugl
bea4d1064c core: add transfer function minimum and maximum luminance values
This redefines the transfer functions to have a custom luminance at encoded
value zero, and a custom luminance at encoded value 1, neither of which are
tied to the reference luminance, even for relative transfer functions.

The goal of that is that we can use a gamma 2.2 transfer function for the shadow
buffer, with the reference luminance being much lower than the maximum luminance.
For example, on an HDR screen you might have the reference luminance of 600 nits,
while the maximum luminance is 1000 nits. By representing this in gamma 2.2, we
can use a much smaller amount of bits per color to store the values than if we
used a linear transfer function. An additional benefit is that this way the values
in the buffer can be scaled by arbitrary amounts, for example to limit the range of
values to [0, 1], which can be represented in a normalized buffer
2024-08-09 15:10:45 +02:00
Aleix Pol Gonzalez
d83f6e9a85 backends/wayland: Support touch input when there's multiple outputs
Makes the outputs we are emitting relative to the output position. This
way if there's an esoteric setup or just more than one output, it won't
just always be relative to the first output.

Signed-off-by: Victoria Fischer <victoria.fischer@mbition.io>
2024-08-04 17:15:21 +02:00
Xaver Hugl
ebffcd9dc4 backends/drm: don't block direct scanout if color profile source isn't set to ICC
If there's a valid ICC profile loaded is irrelevant with a different color profile source
2024-08-02 16:14:00 +02:00
Xaver Hugl
e351d9dca1 backends/libinput: don't apply pointer acceleration to touchpad gestures
It's unexpected that increasing pointer "speed" would also change the distance
required to activate gestures
2024-08-01 09:52:12 +00:00
Nicolas Fella
32c696b45e Expose input device group on DBus
This is useful to combine tablet pen and pad devices into one logical device
2024-07-23 13:33:41 +02:00
David Redondo
e0202c7531 Include span
This is needed on some compilers like g++ 11.
2024-07-23 07:34:57 +00:00
Vlad Zahorodnii
2ec45f33d1 backends/drm: Fix a crash in DrmGpu::releaseBuffers()
Currently, the code assumes that the primary and the cursor layers are
always present. However, it's not guaranteed if the render backend cannot
be recreated. Specifically:

- the Compositor destroys the EglGbmBackend. The egl gbm backend, in its
  turn, resets the primary and the cursor layers to null
- the Compositor tries to create the EglGbmBackend but that fails so it
  is destroyed. EglGbmBackend::~EglGbmBackend() calls DrmGpu::releaseBuffers(),
  but it hits an unexpected null primary layer.

Normally, the primary and the cursor layers would be created when the
Compositor successfully creates the WorkspaceScene. Since the RenderBackend
fails to initialize, the WorkspaceScene is not created and the DrmGpu
doesn't recreate the layers.
2024-07-23 06:22:20 +00:00
Xaver Hugl
eddced099d backends/drm: don't unset degamma in prepareAtomicModeset
We're now using and, if necessary, un-setting the property in prepareAtomicPresentation

BUG: 490517
2024-07-19 21:39:33 +02:00
Xaver Hugl
2340470a9a backends/drm: add support for drm plane size hints
On a lot of hardware, using bigger plane sizes than necessary means wasting power.
This is specifically problematic with the cursor plane, where we so far only had a
single fixed size hint through drm caps, even though the hardware often could use
a smaller cursor size.
This adds support for the per-plane SIZE_HINTS property, which allows us to pick a
smaller cursor size when the cursor image fits into it, and should save some power
that way.
2024-07-19 13:40:44 +02:00
Xaver Hugl
099a1cc31f backends/drm: limit max_bpc to 8 by default with docks
There's generally a lot of problems with higher than 8bpc in docking stations,
especially when multiple monitors are involved. Until these problems are hopefully
eventually fixed on the driver side, limit the bpc to 8 with docks by default
2024-07-18 15:28:32 +00:00
Xaver Hugl
75075fdb89 backends/drm: combine matrix operations in the right order
Matrix multiplication is right to left, so the operations have to be added
in the reverse order from the list
2024-07-18 12:02:35 +00:00
Xaver Hugl
cd1b70ef05 backends/x11/standalone: fix night light 2024-07-18 13:38:58 +02:00
Bruno Filipe
998be47ac1 backends/libinput: Ignore redundant events for pointer buttons and keyboard keys when pressed/released on multiple devices
BUG: 486034
2024-07-18 06:56:18 +00:00
Xaver Hugl
cb830957aa core: remove unused colorlut class 2024-07-17 16:08:18 +00:00
Xaver Hugl
0260c2e9cd backends/drm,x11/standalone: apply night light in linear space
It's more correct and, as long as you have a programmable LUT, also not less efficient
2024-07-17 16:08:18 +00:00
Xaver Hugl
a86a914f70 backends/drm: allow offloading more complex color pipelines to legacy modesetting
This is done by combining multiple transfer functions and multipliers into one LUT.
2024-07-17 16:08:18 +00:00
Xaver Hugl
e2c8f25d31 backends/drm: combine color operations more aggressively than ColorPipeline does
With programmable LUTs, consecutive transfer functions, inverse transfer functions and
multipliers can all be combined into one LUT. This allows offloading operations in more
situations and makes the operations more efficient too, as potentially fewer LUTs have
to be programmed
2024-07-17 16:08:18 +00:00
Vlad Zahorodnii
7a472fcab2 backends/x11: Fix crash that happens when toggling compositing
When the GLX or the EGL backend is destroyed, it is going to reset the
RenderLoop state, including the number of frames in flight. It does so
because of the historical reasons. At the time, there was no output frame
object to track the lifecycle of a frame.

After introducing the OutputFrame and hooking it into the RenderLoop,
the pending frame count will be reset automatically in RenderLoop when
the GLX or the EGL backend is destroyed. But we forgot to remove
the invalidate() function calls. So, when the GLX backend goes down, it
resets the pending frame count to zero and then it destroys the pending
OutputFrame object, which would result in decreasing the pending frame
count by 1 and triggering an assert in the RenderLoopPrivate::notifyFrameDropped()
function.

Since there is the OutputFrame helper now, the invalidate() function
can be dropped. Technically, the invalidate function did more than just
reset pendingFrameCount to 0, for example also stop the compositeTime.
But that should be fairly harmless new behavior.
2024-07-17 12:19:21 +00:00
Neal Gompa
915d103128 cmake: Allow not building kwin_x11
Some distributions do not wish to build the KWin X11 backend as
they do not use it, even though they wish to maintain X11 support
for Xwayland when using KWin as a Wayland compositor.

Allow this choice by splitting the build flag and setting it up to
forcibly disable building the backend when building X11 code is
switched off.
2024-07-16 06:47:43 +00:00
Vlad Zahorodnii
a23ebe12ac Drop leftover infrastructure for modifier only shortcuts 2024-07-15 12:55:28 +00:00
Patrik Fábián
b84a6af8d3 backends/drm: Pass the correct arguments to encodingToNits in the ICC shader 2024-07-14 16:22:14 +00:00
Xaver Hugl
3c87b7476e backends/drm: always expose brightness control
This allows the user to change the brightness level of content even if there's no
actual underlying "backlight" device. This is the case with many internal OLED
screens for example.

BUG: 413451
2024-07-14 00:03:28 +00:00
Xaver Hugl
faba2b6286 wayland: add support for controlling brightness devices exposed by powerdevil
This way, KWin can set the brightness on internal panels or external monitors with
DDC/CI support, without being exposed to the mess that is actually directly setting
the brightness.

This also adds a capability flag for brightness control to the output management
protocol. Powerdevil will expose a brightness slider for each output and change the
brightness setting of the output accordingly. KWin in turn changes the brightness
levels of the actual brightness device, or of a multiplier in compositing accordingly.
2024-07-14 00:03:28 +00:00
Xaver Hugl
f20ccabe80 backends/drm: do blending in gamma 2.2 space with color management too
This matches what we do without color management, and is more what users and app
developers expect. Going with linear blending before was mostly from it being more
"correct" / how physical blending of light works, but that doesn't really matter
when existing software expects it to behave differently.

BUG: 476868
CCBUG: 479755
2024-07-05 14:52:47 +02:00
Xaver Hugl
5b86dba6bf backends/drm: support arbitrary input transfer functions in the icc shader 2024-07-05 14:52:47 +02:00
Xaver Hugl
8c97c4dd31 backends/drm: move virtual outputs out of DrmGpu
They're not related to each other in any way
2024-07-04 16:25:14 +00:00
Xaver Hugl
0704319235 backends/drm: use the post-blending color pipeline for direct scanout
This makes direct scanout of SDR content on an HDR screen and vice versa possible,
as well as direct scanout while night color is active or the brightness isn't 100%.
2024-07-04 17:39:33 +02:00
Xaver Hugl
2799c270b4 backends/drm: implement support for post blending color pipelines
This exposes the degamma->ctm->gamma pipeline as a drm color op, which can
be set to a generic color pipeline. The same code can later be adapted to
program the upcoming per-plane color pipeline properties.
2024-07-04 17:39:10 +02:00
Xaver Hugl
5aaab715b0 core: add color pipeline class
This allows encapsulating color operations in a generic way, which can then be used in KMS or shaders.
The class automatically optimizes out unnecessary color operations like identity matrices, and
combines consecutive operations like
- matrix + matrix
- multiplier + multiplier
- matrix + multiplier
- EOTF + inverse EOTF
- relative EOTF + multiplier
to improve efficiency and make KMS offloading easier
2024-07-04 17:39:10 +02:00
Xaver Hugl
de85867675 core: add a TransferFunction class and move transfer function functions in there
This way it's more obvious where to find them, and the class can be extended with more
functionality later, like transfer functions with parameters
2024-07-04 17:19:31 +02:00
Xaver Hugl
b103decda2 backends/drm: test and apply all mode changes at once
This avoids doing multiple atomic tests with outdated state for when multiple
outputs change simultaneously, and avoids crashing because outputs get used
before they're fully constructed
(https://crash-reports.kde.org/organizations/kde/issues/40960)
2024-07-02 14:59:06 +02:00
Aleix Pol Gonzalez
718a0c26c0 backends/windowed: Port X11 Windowed backend away from XLib
It's a dependency that we have been porting away from.

Signed-off-by: Victoria Fischer <victoria.fischer@mbition.io>
2024-06-29 09:29:47 +00:00
Xaver Hugl
f1a867ea12 color management: map reference luminance of source and target content to each other
This ensures that different content on the screen matches with the user configured
reference / SDR luminance, and both simplifies SDR<->HDR mapping by removing the need
for special casing that situation and significantly improves the mapping in some cases.
As we don't get any reference luminance values for HDR content (yet), this commit
assumes that HDR content is prepared for the reference luminance of the preferred
color description.
2024-06-28 13:16:02 +00:00
Xaver Hugl
15589c9997 color management: change brightness information names to be shorter and more correct
Brightness is a loose word for how bright we perceive things to be, but the
values we're using are about objective measurements, about luminance instead.
2024-06-28 13:16:02 +00:00
Xaver Hugl
eb7b04e320 core/colorspace: make max brightness values optional
Zero is already optional, but it's easy to make mistakes that way
2024-06-26 15:41:38 +02:00
Xaver Hugl
bdc24ff8c7 core/colorspace: add mastering display colorimetry
The mastering display colorimetry describes what part of the colorspace
is actually used, which is important when we're sending desired metadata
about a screen using the rec.2020 container colorspace, or when the client
uses an "infinite" / extended colorspace like scRGB
2024-06-26 15:41:38 +02:00