Commit graph

2583 commits

Author SHA1 Message Date
Leandro Ribeiro
e6289aee68 color-lcms: rewrite misleading comment
Update a comment explaining what we may do in the future when
cmsSmoothToneCurve() fails.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
2025-05-15 14:42:45 +03:00
Daniel Stone
4393bec40a core: Short-circuit assign_outputs() during shutdown
If we're shutting down, moving surfaces to a different output will not
be profitable. Just clear out the output mask entirely and return early.

This specifically avoids the following issue seen with the Wayland
backend when shutting down:
  - outputs destroyed
  - colour manager destroyed
  - seats destroyed
  - pointer destroyed
  - sprite view destroyed
  - find new output for the sprite view
  - update colour profile for the sprite view
  - neither the view nor the compositor has any outputs left
  - try to use the stock sRGB transfer
  - oops, no colour manager

Signed-off-by: Daniel Stone <daniels@collabora.com>
2025-05-14 17:24:43 +00:00
Leandro Ribeiro
8ef3423bf7 color: remove unused WESTON_COLOR_MAPPING_TYPE_3D_LUT
Since "color: do not use color steps for non-optimized pipelines",
WESTON_COLOR_MAPPING_TYPE_3D_LUT became unused. So drop it from our
code.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
2025-05-13 17:36:52 +03:00
Leandro Ribeiro
df07af056d color: do not use color steps for non-optimized pipelines
For non-optimized pipelines, stop using the color steps (pre curve,
color mapping and post curve). Instead, make use of the
xform->to_shaper_plus_3dlut() vfunc.

In this patch we add a bool to signalize that the steps are valid (for
optimized pipelines) or not. If not (non-optimized ones), the vfunc must
be used.

This brings flexibility for the renderer/backend implementing the xform.
For now we only implement xform's in the GL-renderer, and this has no
behavior changes. It should be relevant when we implement the xform in
our DRM-backend, see commit "color: add to_shaper_plus_3dlut() vfunc to
struct weston_color_transform".

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
2025-05-13 17:36:52 +03:00
Leandro Ribeiro
0945ac3fa8 color: add to_shaper_plus_3dlut() vfunc to struct weston_color_transform
This function allow us to get a shaper (3x1D LUT) + 3D LUT that is
equivalent to a certain xform.

With that, we allow backend/renderer that are not capable of handling
the color steps of the xform to fallback to something else.

E.g. when we introduce the code to offload color xform to KMS using the
DRM-backend, we'll depend on the driver/hardware implementing the color
steps. With this patch, DRM-backend should be able to fallback to a
shaper (3x1D LUT) + 3DLUT, color operations that should be commonly
supported by drivers/hardwares.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
2025-05-13 17:36:52 +03:00
Leandro Ribeiro
9f1cf0db24 color-lcms: keep fallback LCMS xform even when pipeline is optimized
Up to now, when we were able to optimize a color pipeline, we'd delete
xform->cmap_3dlut. In such cases, we'd have a pre curve, color mapping
and post curve that Weston recognizes and implements in the shaders. So
there was no need to use xform->cmap_3dlut.

But at some point we'll try to offload such color transformations to our
DRM-backend, and we are not in control of what color operations the
hardware/driver are capable of. In such case, we may want to use the
fallback LCMS xform (xform->cmap_3dlut) and decompose it into a shaper
(3x1D LUT) + 3D LUT, as such operations should be commonly supported
by hardwares/drivers.

This shows that using the optimized pipeline or not should be a
renderer/backend decision. So do not delete xform->cmap_3dlut even when
we optimize the pipeline.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
2025-05-13 17:36:52 +03:00
Leandro Ribeiro
b3fae5ae6b gl-renderer: split gl_color_curve_lut_3x1d()
For now this is useless, but in the next commits this split will be
pretty useful.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
2025-05-13 17:36:52 +03:00
Leandro Ribeiro
4fe16c1bec gl-renderer: split gl_color_mapping_lut_3d()
For now this is useless, but in the next commits this split will be
pretty useful.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
2025-05-13 17:36:52 +03:00
Leandro Ribeiro
334ae04614 gl-renderer: cosmetic improvement to gl_color_mapping_lut_3d()
Change this function signature to look similar to
gl_color_curve_lut_3x1d(), as they do similar things.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
2025-05-13 17:36:52 +03:00
Leandro Ribeiro
209a5b8400 gl-renderer: rename gl_3d_lut() to gl_color_mapping_lut_3d()
We are filling a struct gl_renderer_color_mapping in this function,
so rename to better reflect that.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
2025-05-13 17:36:52 +03:00
Pekka Paalanen
5ca78cdf05 color-lcms: accept matrices with offset
Now that color mapping matrix in GL-renderer supports an offset, allow
merging and translating matrix stages with offsets.

color-icc-output test is already hitting these new paths with the
sRGB->sRGB CLUT fixture (number 6), hence new tests are not needed.
Previously, after optimization the pipeline still contained 3
consecutive matrix stages. Now, those three are combined into one.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2025-05-05 11:26:24 +03:00
Pekka Paalanen
b15dcfe790 gl-renderer: add offset to the color mapping matrix
The offset will be useful for black point handling.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2025-05-05 11:26:24 +03:00
Robert Mader
cd35c6c780 gl-renderer: Add YUV422 and YVU422 to yuv_formats
So we can test them on CI. For completeness and because they
are commonly used by SW decoders.

Signed-off-by: Robert Mader <robert.mader@collabora.com>
2025-04-30 11:13:06 +02:00
Pekka Paalanen
294d4cabd4 gl-renderer: unpack linpow/powlin parameters differently
This consolidates the parameter unpacking for the two types of
parametric curves. The goal is code that reads better.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2025-04-28 16:46:43 +03:00
Pekka Paalanen
107e9ed69c gl-renderer use struct to de-dup curves in fragment.glsl
Using more structured types allows removing one of color_pre_curve() and
color_post_curve() completely, reducing code duplication.

Ideally I would have wanted to use a single type for a curve, having
both lut and par in it, but I am not sure the unused half would still be
eliminated during compilation.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2025-04-28 16:46:34 +03:00
Pekka Paalanen
dcb4a1012d gl-renderer: de-dup getting curve uniform locations
Reduce pasta, reads better.

Shame that the string manipulation is so cumbersome. All strings are
hardcoded literals though, so the assert is good enough.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2025-04-28 16:42:46 +03:00
Pekka Paalanen
007a1e1def gl-renderer: assert lut_3x1d scale and offset
Add asserts the same as what the color mapping 3D LUT uses, for
consistency since both implement a LUT with the same principles.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2025-04-15 14:07:05 +03:00
Pekka Paalanen
95cb915d32 gl-renderer: move color mapping asserts to load config
The frequency of checking remaing the same, but we can use an already
needed switch statement and do not need one just for the asserts. This
makes gl_shader_config_set_color_transform() nice and short.

The MAPPING_MATRIX assert was useless, the variable is set right above.

Asserting the mapping type is valid happens already in
gl_shader_load_config_mapping().

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2025-04-15 12:07:45 +03:00
Pekka Paalanen
cf6735a761 gl-renderer: refactor into gl_shader_load_config_mapping()
The new function parameters acts as shorthands, making the moved code a
little more concise. It also gains an assert for an invalid mapping
type, which previously would have been awkward to code.
gl_shader_load_config() becomes easier to read.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2025-04-15 11:57:32 +03:00
Pekka Paalanen
9ce3ce4250 gl-renderer: share color mapping union for gl_shader_config
Reduce divergence between the structs to maybe allow more consolidation
in the future.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2025-04-15 11:38:23 +03:00
Pekka Paalanen
77015ae226 gl-renderer: name the anonymous union in gl_renderer_color_mapping
This is both more consistent with other embedded unions, and it allows
to pull the union out into its own named type in the following patch.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2025-04-15 11:38:23 +03:00
Pekka Paalanen
d1e4ae5e1d gl-renderer: refactor into gl_shader_load_config_curve()
De-duplicate code.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2025-04-15 11:38:19 +03:00
Pekka Paalanen
05f5e400e9 gl-renderer: union gl_shader_color_curve_uniforms
This type name allows for code de-duplication.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2025-04-15 11:35:41 +03:00
Pekka Paalanen
a47fabeaa4 gl-renderer: share curve union for gl_shader_config
This will help reducing the duplicate open-coding of pre- and
post-curves in the following commits. This is also a step towards
eliminating the duplication between struct gl_shader_config and
gl_renderer_color_transform.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2025-04-15 11:34:38 +03:00
Pekka Paalanen
70b5ec5bfe color: use weston_mat3f for mapping step
Replace a plain array with a type-safe documented structure.
This will get more wide use later.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2025-04-14 17:11:43 +03:00
Pekka Paalanen
98ec0d9b6c color: structurize parametric curve data
Rather than using a two-dimensional array, provide names to the fields.
The fields are primarily used by their names, but we also need the data
as a flat array of floats, so use unions to achieve that: two different
views into the same data.

This makes the code more self-explanatory. In color-operations.c it
removes a handful of temporaries. Comparison in color-properties.c is
simplified. ARRAY_COPY() turns into an assignment.

MAX_PARAMS_PARAM_CURVE is eliminated. Instead of having to maintain a
copy in fragment.glsl, the definition there is automated.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2025-04-14 11:00:21 +00:00
Pekka Paalanen
f7bf732004 gl-renderer: make gl-renderer-internal.h selfcontained
This helps me with VScode when clangd doesn't claim this header to be
full of unknown stuff.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2025-04-14 11:00:21 +00:00
xufeng wang
5eb316d77c libweston: fix crash when getting connector's property failed
When weston tries to update drm head info, if the connector is disconnected, it cannot get the connector's property.

If get connector's property failed, drm_connector_assign_connector_info returns -1 and head->connector->conn, head->connector->props_drm remain to be nullptr, but they are used in update_head_from_connector, so the crash occurs.

So just return ret when drm_connector_assign_connector_info returns -1, and head->connector, head->connector will not be used later.

Signed-off-by: xufeng wang <550002860@gehealthcare.com>
2025-04-11 15:58:22 +08:00
Leandro Ribeiro
8762c3bab5 color: implement perceptual quantizer transfer function
This implements WESTON_TF_ST2084_PQ.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
2025-04-10 12:43:00 +00:00
Leandro Ribeiro
0af48f0415 color: add function to create 3x1D LUT from color curve
Some external API's (e.g. DRM/KMS) are not capable of dealing with
enumerated color curves. In such cases, we may need to create LUT's that
correspond to such curves and give them to such API's

So add function weston_color_curve_to_3x1D_LUT() to craft 3x1D LUT from
a color curve.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
2025-04-10 12:43:00 +00:00
Leandro Ribeiro
2ac863397c color: add function to create color curve from tf
When we create a parametric color profile (we still do not fully
support, but plan to), a struct weston_color_tf_info is created.

So add a new function weston_color_curve_from_tf_info() to create a
color curve given a transfer function.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
2025-04-10 12:43:00 +00:00
Leandro Ribeiro
0ebd2b5e0e color-lcms: rename a few functions
Since "color-lcms: recognize LCMS curves that matches transfer
functions", a few function names became slightly outdated. Rename them.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
2025-04-10 12:43:00 +00:00
Leandro Ribeiro
ccf6db49b7 color-lcms: recognize LCMS curves that matches transfer functions
LittleCMS curves contain curves that are parametric. They may be
well-known curves, and we are not checking that. If that's the case,
we should create enumerated color curves, instead of parametric.

This can be helpful for renderers and/or backends that want to implement
the curve, as they may have access to an API that accept enumerated
curves.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
2025-04-10 12:43:00 +00:00
Leandro Ribeiro
209882c7d4 color: add curve type enumerated
Not all color curves comes from parameters. For instance, with the
CM&HDR protocol users can set color curves from tf_info.

So let's add a new curve type to accommodate that.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
2025-04-10 12:43:00 +00:00
Leandro Ribeiro
0fe575b4a9 color: move LINPOW/POWLIN to new enum weston_color_curve_parametric_type
This just makes the code more readable and should help us to avoid
mistakes in the future. No behavior changes.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
2025-04-10 12:43:00 +00:00
Leandro Ribeiro
46920d8a61 color-lcms: define max number of params for LittleCMS curves
Follow-up of "color: define max number of params for parametric curves
and tf's". Let's do the same for LittleCMS parametric curves.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
2025-04-10 12:43:00 +00:00
Leandro Ribeiro
037f2dbff1 color: define max number of params for parametric curves and tf's
Up to now we were using 10 as the max number of params for color curves
and transfer functions. But this came from LittleCMS, whose parametric
curves may contain up to 10 params.

But out color curves and tf's are not tied to LittleCMS, so let's define
constants to help avoid confusion.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
2025-04-10 12:43:00 +00:00
Derek Foreman
d9893c6af2 compositor: Fix a potential crash at shutdown
weston_global_destroy_save() can directly destroy a global if the
compositor state is WESTON_COMPOSITOR_OFFSCREEN.

Make sure we don't try to set_user_data after this has happened.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2025-04-10 12:02:26 +00:00
Leandro Ribeiro
d3ef4f9576 color: improve code that validates color gamut
First of all, we make it work for NaN CIE xy values.

We also improve the error message a bit. It was only printing that the
color gamut was invalid, but it didn't explain why. This adds the
explanation (out of valid range).

And finally, we make the code a bit shorter.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
2025-04-03 17:49:53 +03:00
Leandro Ribeiro
25a10fa2cd color: add WL_EXPORT to param builder functions
The internal API to create parametric color profiles should be available
not only to libweston, but also to frontend. WL_EXPORT was missing from
the functions, so add that.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
2025-04-03 17:49:40 +03:00
Pekka Paalanen
98becedfcd libweston: publish eotf and colorimetry mode to string
Frontend wants to print these sometimes.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2025-04-03 17:49:20 +03:00
Pekka Paalanen
d26ab4360d color-lcms: transform_search_param well-formedness
Assert that the search param structure is well-formed, so that there
won't be cache misses due inconsistent fields.

Anything called from inside cmlcms_color_transform_get() can skip
asserting these.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2025-04-03 17:49:03 +03:00
Pekka Paalanen
ce80a059f1 color-lcms: use alloc/register in profile_from_params
This is a nice clean-up.

The parameter-based color profile is actually fully formed. The problem
of using it is dealt in the next patch.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2025-04-03 17:48:08 +03:00
Pekka Paalanen
5ef1432195 color-lcms: cmlcms_color_profile_alloc/register()
Split the create function into two parts, allocation and finalization.
All ICC-specific code is moved into callers, so that the parameter-based
profile creation can start using alloc/register too.

cmlcms_color_profile 120 bytes, so it's unlikely we could ever deal with
that allocation failing - don't even try.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2025-04-03 17:47:32 +03:00
Pekka Paalanen
385334b77a color-noop: improve profile error messages
While no-op does not support these, other color managers might. Change
the wording so that the user does not think that Weston does not support
these at all.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2025-04-03 17:46:45 +03:00
Michael Olbrich
83053f0ce4 backend-drm: make sure outputs are enabled during plane assignment
drm_output_propose_state() is called during from drm_assign_planes(). At this
point, the output is enabled, but it may be disabled in the current state, that
is copied.

So explicitly enable the output by setting dpms to WESTON_DPMS_ON.
The same thing is already done in drm_output_repaint() but that's to late for
drm_output_propose_state(). Move that to the fallback path when planes are
disabled. It's no longer needed in general and changing the state between the
atomic test and commit is not a good idea anyways.

Without this, the atomic commit may fail, even though the corresponding test was
successful.

Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
2025-04-02 18:02:45 +00:00
Marius Vlad
9aa910c4d4 backend-drm: Fix count page flips on invalid outputs
Slight oversight of counting page flips from within the atomic commit
handler when we don't really have an output. Do that after *after*
checking for a valid output.

Fixes: cda8de1089, ("backend-drm: Count and display KMS page flips")

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2025-04-02 13:09:45 +00:00
Loïc Molinari
5a56856866 gl-renderer: Init output borders with transparent pixels
When the 1st frame of the X11 backend is rendered by the GL renderer,
an invalid call to glBindTexture() with a target of 0 is emitted. This
is because the border status of the window renderbuffers are flagged
dirty while the border status of the output state is not. This commit
ensures that the output state and the renderbuffers border status are
dirty by default. It also enforces the creation of output border
textures even though no valid data have (yet) been passed, in which
case the textures are filled with transparent pixels.

Signed-off-by: Loïc Molinari <loic.molinari@collabora.com>
2025-04-01 13:55:06 +00:00
Pekka Paalanen
b872c71820 color-lcms: use weston_mat4f for matrix stages
This makes multiply_matrix_stages() handle offset vectors correctly, but
they will not apprear here yet, because
is_matrix_stage_with_zero_offset() forbids merging such matrices.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2025-04-01 15:59:54 +03:00
Pekka Paalanen
3fefb5ba44 libweston, clients, tests: implement weston_matrix in terms of weston_mat4f
This converts weston_matrix and weston_vector to use linalg-types
internally. All direct accesses to members had to be converted
everywhere, mostly in the simplest form possible which leaves some
trivially reducable code around.

The intention is that we can now gradually migrate away from
weston_matrix in the future.

Look like one trailing space got accidentally annihilated in
compositor.c.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2025-04-01 15:59:54 +03:00