Commit graph

3021 commits

Author SHA1 Message Date
Pekka Paalanen
e9665ef36f libweston: print scene-graph into FILE
Being able to print the scene-graph straight into a FILE removes one
temporary memory allocation that used to be mandatory. That memory
allocation is now gone from the DRM-backend debug log. It has moved into
the scene-graph log scope. In the case of
weston_log_subscription_printf() it shouldn't matter, because it is only
used when new subscribers appear.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2026-03-10 16:40:40 +02:00
Pekka Paalanen
60567e7bd6 libweston: route log scope printf through FILE
The old implementation malloc'd a temporary buffer to hold the formatted
string, flushed it out to subscribers, and freed the buffer. On every
single call.

Forwarding the formatted output to the input stream instead avoids the
malloc. It is flushed explicitly so that interleaving messages through
multiple scopes continues to work. Color-lcms module uses that.

Also fix reference to the non-existing function
weston_debug_stream_write().

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2026-03-10 16:40:40 +02:00
Pekka Paalanen
664e882415 libweston: add weston_log_scope_stream()
Printing directly into an stdio stream and hooking up to the flush (the
write callback) avoids having to allocate+free a temporary buffer on
every printing call. The FILE uses a permanent buffer for storing the
text, and once it fills up or a newline is detected, it is flushed out.

It is fine to mix the new and the old APIs, since the old API flushes
the stream.

The buffer size of 3 kB is just a guess.

The man-page for fopencookie() recommends setting _FILE_OFFSET_BITS to
64. Even though this patch does not strictly need it (we don't implement
seek or take the address of fopencookie()), I think it's good to follow
anyway.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2026-03-10 16:40:40 +02:00
Pekka Paalanen
007faaf2d2 backend-drm: track drm_repaint_flush() with Perfetto
to follow its performance.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2026-03-10 16:40:40 +02:00
Marius Vlad
f8b39037ad libweston: Track weston_compositor_print_scene_graph
For logging performance profiling.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2026-03-10 16:40:40 +02:00
Marius Vlad
02aa53eb4b libweston/renderer-vulkan: Fix minor warning messages
When building without any of the x11 and wayland we still to have some
unused variables/functions.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
Reviewed-by: Erico Nunes <nunes.erico@gmail.com>
2026-03-06 16:50:49 +02:00
Erico Nunes
ba10e6d814 vulkan-renderer: guard surface output creation with backend defines
Fix compilation errors when compiling with x11 or wayland backends
disabled or not available.

Fixes: 8f56d03d ("libweston: Vulkan renderer")

Signed-off-by: Erico Nunes <nunes.erico@gmail.com>
2026-03-05 17:37:13 +01:00
Leandro Ribeiro
32d0bd3d0e compositor: add grayscale output color effect
This adds a new output color effect: grayscale. It takes RGB color as
input and computes a gray pixel color using the luminance formula for
linear sRGB:

Y = 0.2126 * R + 0.7152 * G + 0.0722 * B

Just like the other color effects we have, this only works for sRGB and
are not enabled when color-management is on.

Note: although the technique is designed to be applied in linear, it's
costly to convert to linear and then back to electrical. As doing the
conversion in electrical still gives a reasonable result, we do it this
way. When we add support for color effects with color-management on,
we'll apply the effect in linear.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
2026-03-04 13:11:56 -03:00
Leandro Ribeiro
ed29f588e4 gl-renderer: log inversion color effect to paint node scope
This was logging the CVD correction effects, but not the inversion one.
This commit adds this.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
2026-03-04 13:09:14 -03:00
Michael Tretter
d0d878972c backend-drm: prefer crtc with most supported planes
When selecting a crtc for an output, prefer the first available crtc that
supports the most hardware planes.

This increases the chance that the compositor can make use of hardware planes
for compositing instead of falling back to rendering just because it selected a
crtc that only supports one plane.

I found this on i.MX6, which has 4 crtcs and 6 planes. crtc 0 and crtc 2 have
two planes, and crtc 1 and crtc 3 have one plane. The current selection
algorithm selects the last matching crtc, which is crtc 3 and prevents the use
of planes.

Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
2026-03-04 13:27:07 +00:00
Derek Foreman
bbcd7d005b drm: Make underlay/overlay per output
Now that we have per output plane lists, we can make the overlay/underlay
subtype be part of the plane handle, and make the has_underlay property
part of the output.

This fixes bugs on platforms where not all CRTCs have the same
minimum zpos, and underlays can be broken for all outputs because
one output doesn't have any.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2026-03-04 13:17:49 +00:00
Derek Foreman
6527c586d3 drm: Use plane_handle in drm_plane_state
Instead of an output pointer, use a plane_handle from the output. This will
be more useful later when the plane_handle contains output specific
information.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2026-03-04 13:17:49 +00:00
Derek Foreman
c9a298b3df drm: replace scanout_plane and cursor_plane with handles
This is a step towards making the handle the thing we keep in plane state
later.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2026-03-04 13:17:49 +00:00
Derek Foreman
3b03aaa759 drm: Use the output plane handle list instead of the device plane list
Use the output specific plane handle list instead of the entire device
plane list.

For now this is a low benefit optimization.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2026-03-04 13:17:49 +00:00
Derek Foreman
3e2e54f032 drm: Introduce plane handles
Planes can sometimes be used on a subset of the CRTCs available, so add a
new structure that allows an output to have handles to the planes that are
available on the CRTC it can drive.

For now we just track the lists without using them.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2026-03-04 13:17:49 +00:00
Derek Foreman
c1fa2ebe5a drm: Don't set cursors_are_broken from output_init_planes
There might be existing outputs with perfectly functional cursors,
there's no reason to break all of that because the new output doesn't
have a cursor plane.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2026-03-04 13:17:49 +00:00
Derek Foreman
77156786f0 compositor: Remove weston_compositor_stack_plane
It's been a long time since the core has cared about plane z-order. Remove
this.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2026-03-04 13:17:49 +00:00
Derek Foreman
313ea43f35 compositor: Remove x,y co-ordinates from weston_plane
Turns out nothing actually uses these anymore.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2026-03-04 13:17:49 +00:00
Pekka Paalanen
4232db2864 shell-utils: delete weston_shell_utils_surface_get_label()
Unused. Replaced earlier by weston_desktop_surface_make_label().

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2026-03-04 09:40:32 +02:00
Pekka Paalanen
eefcd97e2a libweston: delete weston_surface::get_label as unused
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2026-03-04 09:40:32 +02:00
Marius Vlad
78d15a6f95 libweston: do not call weston_surface::get_label()
Use the new label field instead. The code becomes much simpler.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2026-03-04 09:40:29 +02:00
Pekka Paalanen
81c9bca764 perfetto: do not call weston_surface::get_label()
Use the new label field instead. It's always non-NULL.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2026-03-04 07:28:49 +00:00
Marius Vlad
128a88d1a8 shell-utils: Add labels for curtain created surfaces
struct weston_curtain_params is changed to match the new
weston_surface_set_label() API. For now, I did not bother hooking up the
static label flavor.

Part of migration away from get_label().

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2026-03-04 07:28:49 +00:00
Marius Vlad
4011de1e22 desktop-shell: set the new surface label field
To update the surface label based on client-controllable fields like
app_id and title we need to use a listener and update the label
accordingly using weston_surface_set_label() added previously.

The added weston_desktop_surface_make_label() will eventually supersede
weston_shell_utils_surface_get_label() by having a more fluent API.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2026-03-04 07:28:49 +00:00
Pekka Paalanen
83424f4025 libweston: use new label for pointer cursors
Part of migration away from get_label().

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2026-03-04 07:28:49 +00:00
Pekka Paalanen
f26ccbc3b2 libweston: use new label for drag icons
Part of migration away from get_label().

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2026-03-04 07:28:49 +00:00
Marius Vlad
286f58c3d2 libweston: Use the new label infra for subsurfaces
Subsurfaces labels do not have dynamic fields that change so we can just
use it as is.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2026-03-04 07:28:49 +00:00
Marius Vlad
2e61633b32 libweston: Use a string for storing surface label
This is an alternative to using set_label_func to avoid using get_label()
callback. get_label() is inconvenient to set up and to call. It incurs
the cost of creating the string every time it is needed. During
debug logging, the string is needed much more often than it changes.

The new label field simply stores the string, making it easy and cheap
to use. As the trade-off, components that set the label string must
re-create the string when it changes, whether it is needed or not.

For the migration to the new label field, get_label_member callback is
used. It will be deleted once the migration is done.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2026-03-04 07:28:49 +00:00
Pekka Paalanen
03a081f2c8 libweston: ensure weston_surface::get_label is non-NULL
On the quest to delete the get_label() vfunc completely, a temporary
default get_label implementation needs to be plugged in. This would
affect all the code that checks whether the get_label vfunc is NULL.

Let's make get_label vfunc non-NULL always intentionally first. We can
delete all the code that checked for NULL, and the bespoke label
replacements in that case. Now all those different "no label" cases are
unified.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2026-03-04 07:28:49 +00:00
Pekka Paalanen
f02c628ee0 libweston: drop a copy in debug_scene_graph_cb()
Doing

	weston_log_subscription_printf(sub, "%s", str);

would malloc a new buffer, copy str into it, flush it our to the
subscriber, and free the buffer before returning.

Using weston_log_subscription_write() instead there is no malloc and
copy. Only open_memstream() has a malloc'd temporary buffer.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2026-03-03 15:59:39 +02:00
Marius Vlad
2d70cbf037 gl-renderer: Add a new gl-renderer scope to print repaint regions
Add a new gl-renderer scope (gl-renderer-paint-nodes) to print out
repaint (damage) regions, opaque and blended regions as well as other
optimizations we might be taking (clear region, color effects), and
skipping repaints.

It includes as well the elapsed time being used by GPU timeline
(GL_EXT_disjoint_timer_query) as well.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2026-03-03 13:24:22 +02:00
Marius Vlad
58a18e1a9f gl-renderer: Clarify gl-renderer-ext debug scope
Further clarify that is printing the GL/EGL-extension by renaming
the internal scope name to extensions_scope and the advertised name
is gl-renderer-ext.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2026-03-03 13:24:22 +02:00
Pekka Paalanen
bf513a362a libweston: add weston_color_gamut_from_protocol()
Reduce 4 copies of a piece of code into one. Usable for both client and
server side.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2026-03-03 07:41:27 +00:00
Robert Mader
5c49563ef4 gl-shaders: Remove asserts relying on shader compiler behavior
yuv_coefficients and yuv_offsets should get optimized away by shader
compilers as the related code paths can never be reached. This seems to
work well on Mesa but not necessarily with other drivers.

While on it, assert that the uniforms *are* present, unless the
yuv-to-rgb conversion is handled by the driver.

Signed-off-by: Robert Mader <robert.mader@collabora.com>
2026-03-02 14:04:48 +01:00
Wang Yu
2c73ce8bac backend-drm: fix read() parameters in libbacklight
The read() function expects a pointer to buffer, not address of
pointer. Three instances were incorrectly passing &buffer instead
of buffer to read().

Signed-off-by: Wang Yu <wangyu@uniontech.com>
2026-03-02 09:54:06 +08:00
Pekka Paalanen
d4d4dc6771 backend-drm: fix leak in drm_device_create()
Found by ASan, now that this function is used for the primary DRM device
as well.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2026-02-27 10:19:21 -06:00
Pekka Paalanen
dfb4be7904 backend-drm: destroy secondary KMS devices too
These were simply leaked before. Now they get destroyed together with
the primary DRM device, too.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2026-02-27 10:19:21 -06:00
Pekka Paalanen
f1380a3dc5 backend-drm: put the main device in the list too
Turns out the main device was not special after all, and we can drop
duplicate code.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2026-02-27 10:19:21 -06:00
Pekka Paalanen
f24ab9d7fe backend-drm: use drm_device_create()
Replace all the open-coding in drm_backend_create() with a call to
drm_device_create(). This is much more maintainable.

drm_source is not needed, it is tracked in struct
drm_device::drm_event_source.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2026-02-27 10:19:21 -06:00
Pekka Paalanen
e06b246c83 backend-drm: add event source to drm_device
Otherwise we cannot clean it up.

The special backend->drm device has the special backend->drm_source for
the same purpose.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2026-02-27 10:19:21 -06:00
Pekka Paalanen
20c951b3ee backend-drm: add drm_device_destroy()
Will need to destroy more than the special b->drm. All the additional
devices are currently leaked.

Move the code into a new function to re-use it.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2026-02-27 10:19:21 -06:00
Pekka Paalanen
853aa1c564 backend-drm: destroy_sprites() after outputs
I want to consolidate 'struct drm_device' destruction into a single
function in the next patch, and that function needs to be usable for
both the primary device drm_backend::drm, and the secondary KMS devices
drm_backend::kms_list.

Sprites, a.k.a drm_planes, are objects fundamentally owned by their
drm_device. To encapsulate drm_device destruction into a single function
(that assumes that all outputs on that device are already destroyed),
one cannot call destroy_sprites() from drm_shutdown() anymore - it
logically belongs in drm_device_destroy().

The problem is that that will reverse the order of destroying drm_planes
vs. output (GBM) surfaces. drm_plane_state holds a reference to drm_fb
which points to a GBM BO that was received from a GBM surface. When the
GBM surface is destroyed, all its GBM BOs are destroyed as well, which
will cause all drm_fb pointing to them to be destroyed as well
regardless of drm_fb reference count. Therefore, if any object was
thought to hold a reference to a drm_fb, it now holds a dangling
pointer.

Why is drm_output_deinit() not clearing the drm_plane state it used,
releasing all the drm_fb references? And do that before destroying the
GBM surface?

Because drm_output_deinit_planes() explicitly skips clearing the
drm_plane state during compositor shutdown, because during shutdown the
drm_planes have already been destroyed.

If we change both, we get a much simpler tear-down logic:

- drm_output_deinit_planes() will always clear drm_plane states, no
  special handling for shutdown (which is an elaborate way of saying
  "before outputs are destroyed").

- drm_output_deinit() calls drm_output_deinit_planes() before it
  destroys the GBM surface, which ensures no dangling drm_fb pointers
  are left.

- destroy_sprites() call is moved *after* destruction of outputs where
  it logically belongs.

This also means that the per-renderer fini functions do not need to
clean up manually when the compositor is not shutting down. They can
just assert the scanout_plane has already been cleaned up.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2026-02-27 10:19:21 -06:00
Pekka Paalanen
6b7d2d39c1 backend-drm: pass drm_kms_device to drm_device_create()
This makes it possible to use drm_device_create() from
drm_backend_create() in the future.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2026-02-27 10:19:21 -06:00
Pekka Paalanen
6aaa309116 backend-drm: return drm_kms_device, don't mod drm_device
find_primary_gpu() and open_specific_drm_device() are modified to return
drm_kms_device instead of modifying fields inside the given drm_device.
Likewise, there is no need to pass the whole drm_backend in (which is
not fully initialized, maybe), but just the needed things.

This should make the code a little easier to follow.

Accidentally, this seems to fix a reference leak of udev_device in
drm_device_create(), because the udev_device is now tracked inside
drm_kms_device and properly unref'd. drm_backend_create() had the unref
that drm_device_create() missed.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2026-02-27 10:19:21 -06:00
Pekka Paalanen
62931d2024 backend-drm: store udev_device in drm_kms_device
find_primary_gpu() and open_specific_drm_device() are currently
returning the udev_device while modifying the passed in drm_device. To
stop the modification, these functions should return drm_kms_device
directly, but the udev_device is also needed.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2026-02-27 10:19:21 -06:00
Pekka Paalanen
201a62baab backend-drm: malloc drm_kms_device
drm_device_is_kms() used to populate a few fields of the passed in
struct drm_device, releasing old values. This was inconvenient, because
one must allocate struct drm_device first, then call drm_device_kms() in
a loop, and finally end up with only some fields of drm_device
populated, then continue to populate it more.

The new function drm_kms_device_create() will malloc a new struct
drm_kms_device every time. RAII. No need to populate and re-populate the
same fields in drm_device until the right KMS device is found.

One can no longer check the fd >= 0 for device validity, now one checks
if kms_device is not NULL.

The fd_owner field is added because it would be inconvenient to pass in
the launcher to the destroy function. It's cleaner to save it, make sure
the right one used for releasing an fd (as if we had multiple launcher
instances, haa haa). Can't release it properly without the launcher.

This is just a minor step to facilitate more refactoring.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2026-02-27 10:19:21 -06:00
Pekka Paalanen
70f9bd41da backend-drm: define struct drm_kms_device
This gives the anonymous struct at struct drm_device::drm a name.

drm_device::drm is renamed to kms_device, which I think is a better
name, lacking an even better one.

The type of kms_device field is changed into a pointer, so that struct
drm_kms_device could be created and destroyed separately from struct
drm_device. Actually implementing this is left for the next patch, and
here the pointer is temporarily initialized with

	device->kms_device = &device->kms_device_allocd;

Changing the name and type causes tons of trivial changes all over the
DRM-backend. This patch does only that, and the next patch will be more
interesting.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2026-02-27 10:19:21 -06:00
Pekka Paalanen
955b7f1522 backend-drm: clear on destroy in drm_rb_discarded_cb()
There are failure paths here that may return without resetting the
variables, leaving dangling pointers behind.

Make sure there cannot be dangling pointers.

Found by manual code review.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2026-02-27 10:19:21 -06:00
Pekka Paalanen
d043c45350 backend-drm: adjust free() in drm_gbm_dmabuf_destroy()
drm_gbm_dmabuf was the type allocated, so that is the type that should
be freed, too.

This was only a semantical bug. It did work before because 'base' was
the first member of struct drm_gbm_dmabuf and therefore the two pointers
were identical.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2026-02-27 10:19:21 -06:00
Pekka Paalanen
42b367304b backend-drm: fix drm_repaint_cancel() for kms_list
Surely the intention was not to cancel the primary device multiple
times.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2026-02-27 10:19:21 -06:00