Commit graph

121 commits

Author SHA1 Message Date
Derek Foreman
e286cf6e15 core: rename and internally share output_repaint_timer_arm
When we add timed transactions, we'll want to feed them through the repaint
timer, so share it to allow this in the future.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2025-12-16 10:58:01 -06:00
Derek Foreman
2dce06179f compositor: Don't return repaint times in the past
If we're late to present, just return the current time instead of a time in
the past.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2025-12-16 10:21:43 -06:00
Derek Foreman
75f2ec4747 compositor: Pull repaint time calculation out of finish_frame
Make this into a separate functions we can call from other places to get
the same results.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2025-12-16 10:21:43 -06:00
Derek Foreman
f50296d4e9 compositor: Add a deferred content update framework
Now that we have surface-state application streamlined, it's fairly easy to
add a framework for deferring content updates.

This will be used soon for fifo and commit timing. For now, the
weston_surface_state_ready() call that makes any of this do something
will always return true.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2025-12-04 14:03:10 -06:00
Derek Foreman
61134fa151 compositor: Track view and surface visibility per output
Keep track of whether a view has any unoccluded pixels on an output,
use this information to add a weston_surface_visibility_mask() function
that we'll use later.

Since the visibility information is calculated at repaint, and invalidated
by some (but not all) state updates, we'll keep track of when the previous
repaint's status is still valid by watching surface status bits.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2025-12-04 13:55:20 -06:00
Derek Foreman
6a280a8fad compositor: Push subsurface order application into apply_state
Seems like it makes sense to have it there, and this cleans up a bunch of
paths where we return status bits so a caller can do this.

We can also drop the explicit setting of view_list_needs_rebuild, as it's
going to happen automatically when applying subsurface order.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2025-12-04 12:38:17 -06:00
Derek Foreman
7bfedba650 compositor: move weston_surface_schedule_repaint into surface-state.c
Only user is there, so move it across.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2025-12-04 12:38:17 -06:00
Robert Mader
b688767680 backend-drm: Allow plane-less DRM background for opaque black solid buffers
The DRM documentation states:
> Unless explicitly specified (via CRTC property or otherwise), the active
> area of a CRTC will be black by default. This means portions of the active
> area which are not covered by a plane will be black, and alpha blending of
> any planes with the CRTC background will blend with black at the lowest zpos.

See https://dri.freedesktop.org/docs/drm/gpu/drm-kms.html#plane-abstraction

This means the view for the primary plane does not need to cover the
whole output and black areas of the scene-graph can be left out.
Doing so has various benefits - most importantly it:
1. allows us to use the plane-only path in more situations and with one
less plane, reducing memory bandwidth usage.
2. opens the path to offload arbitrary background colors in the future.

Iterate over the all visible paint nodes, remove solid-opaque-black
views so they are not considered for plane assignment and aggregate a
region that is later used to assign the primary plane.

Signed-off-by: Robert Mader <robert.mader@collabora.com>
2025-10-23 12:40:37 +02:00
Derek Foreman
58298e2346 compositor: store and use a clipped view in the paint node
Instead of clipping the visible region to the output, clip the entire
region to the output first and save that, then create the visible region
from that.

Now we have both the clipped and visible view regions that the backends
may want to do plane assignment stored in paint nodes, so we can save
some duplicate math.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2025-10-20 12:00:53 +01:00
Derek Foreman
3bd055145b compositor: turn paint_node->visible_next into visible
This is a step towards having correct visibility information in
assign_planes. Instead of visible_next and visible, we now have
visible_previous and visible, with visible being set up in the
visibility update function instead of being copied across in
the late update.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2025-10-20 12:00:53 +01:00
Derek Foreman
dc27dd7e95 compositor: Validate buffer scale
We're supposed to generate an INVALID_SIZE error if the buffer size isn't
an integer multiple of the scale.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2025-10-18 11:51:05 -05:00
Derek Foreman
8cdf3fb709 compositor: Make convert_size_by_transform_scale static inline
It's a tiny function, instead of exporting for test let's just inline it.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2025-10-18 11:51:05 -05:00
Daniel Stone
7f8c5f984e paint-node: Expose weston_paint_node_status
Expose the dirty status as public API so we can use it as a part of
weston_output.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2025-10-17 13:51:04 -05:00
Daniel Stone
abfe874a51 core: Don't rebuild view list on surface-local changes
If a surface changes size or opaque region, or a view changes position,
we don't need to rebuild the entire view list from scratch: we can just
rebuild what's changed and nothing else.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2025-10-17 13:49:21 -05:00
Derek Foreman
5ee711d374 compositor: Add some comments to paint node members
Just a bit of documentation.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2025-10-16 11:12:13 -05:00
Derek Foreman
62e76ee5fb compositor/drm-backend: Move censor check into paint nodes
This test is critical, so only do it once, and throw some asserts around
to make sure we don't mess it up.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2025-10-16 11:12:13 -05:00
Derek Foreman
25a281a0a8 drm-backend/gl-renderer: move fully transparent check into paint node
Video underlay "holes" are fully transparent but must be rendered
fully opaque. However, they appear to be fully transparent to
the current gl-renderer test which is missing a need_hole check.

Add a paint node attribute for this so it can be more easily
checked in assign_planes and renderers.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2025-10-16 11:04:31 -05:00
Derek Foreman
59e2a111fa compositor: Remove is_direct from paint node
It's the same as buffer->direct_display essentially 100% of the time,
except maybe if someone set weston_direct on a single-pixel-buffer, but
that's madness.

Just drop it entirely, and let the only existing reader of the variable
get it from the buffer directly.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2025-10-16 10:25:42 -05:00
Leandro Ribeiro
6fe0cfc2b8 color: introduce output color effects
Output color effects are applied to the whole output scenegraph. It
depends on color-management being disabled, as the color effects are
applied in sRGB content.

For now we added only a few accessibility options: color inversion,
deuteranopia, protanopia and tritanopia CVD correction.

Note that surfaces presented on outputs that contains a color effect
can't be used for direct scanout (i.e. bypass composition and offloading
to KMS overlay planes). The color effect is applied in our GL-renderer.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
2025-09-18 12:32:13 -03:00
Derek Foreman
eac3d78bc6 compositor: Remove view->visible
This is not what any sensible person would expect it to be. It was updated
by a walk of all the paint nodes on the output most recently repainted,
so if a view spanned outputs the visible region would only make sense
within the most recently painted output's region.

It's basically a scratchpad for a mid-repaint operation. Instead of making
it a view member, put it in the paint node, which are always per-output.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2025-09-05 15:23:08 -05:00
Derek Foreman
6e7b4d63c2 compositor/drm: Move failure reason stringification into compositor
While this is generally drm specific stuff, it's leaked into paint nodes
a little bit already.

Pushing it into the core gives us the ability to print failure reasons
in the scene graph debug text (in a future commit), which can be very
informative.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2025-09-05 13:34:17 -05:00
Derek Foreman
ed1edb7b5c compositor: replace surface_state->buffer with a buffer_ref
Use a buffer_ref here to allow us to remove the subsurface
cached_buffer_ref and keep it in the surface state struct instead.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2025-09-05 10:01:42 -05:00
Derek Foreman
0ea8141195 compositor: Move a bunch of surface state handling stuff to another file
compositor.c is too big, let's try to peel off a bit of surface state
handling code into another file.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2025-09-05 10:01:42 -05:00
Derek Foreman
72f73f6692 compositor: internally export weston_surface_to_subsurface
I'll want to use this in another file soon, but for now let's just
clean up the extra prototypes.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2025-09-05 10:01:42 -05:00
Derek Foreman
76dc730d3d compositor: Move region_init_infinite to a header
We've got it in two places, let's share the code.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2025-09-05 10:01:42 -05:00
Leandro Ribeiro
dd5e1f5047 libweston: rename get_supported_formats to get_supported_dmabuf_formats
Let's be more more specific and rename the renderer interface function
that returns the supported dma-buf formats. I.e. if we pass a dma-buf
with one of these formats for the renderer, it should be able to import
it.

Next we'll introduce a function to query the rendering formats from
the renderer, so this distinction is important.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
2025-09-02 13:34:00 +00:00
Daniel Stone
300d059044 libweston: Remove PAINT_NODE_CONTENT_DIRTY
This was only used by weston_surface_damage(), which we have just
gleefully deleted.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2025-05-28 16:46:05 +01:00
Erico Nunes
8f56d03d4b libweston: Vulkan renderer
A Vulkan renderer for weston, based on the GL renderer.
The goal is to impose the least requirements as possible on Vulkan
implementations, as to allow even Vulkan 1.0 (or early development)
drivers to run a Wayland compositor. Any additional features or
extensions are made optional if possible.
Currently supports drm, wayland, x11 and headless backends.
As of this implementation, this is still considered an experimental
renderer.

Signed-off-by: Erico Nunes <nunes.erico@gmail.com>
2025-05-23 20:36:05 +01:00
Erico Nunes
4ab8d6d2c4 libweston: move gl-borders up to weston_renderer
This just moves gl-borders up to libweston weston_renderer as-is,
with no change in functionality.
This is a preparation step so that other renderers can use the
same interface.

Signed-off-by: Erico Nunes <nunes.erico@gmail.com>
2025-05-18 18:00:08 +02:00
Marius Vlad
cda8de1089 backend-drm: Count and display KMS page flips
This patch counts the page flips (either in atomic or legacy page flips)
for DRM outputs and prints them using the drm-backend scope.

Similar to the frame callback timer counter this installs a counter that
periodically computes page flips per a pre-defined interval.

This also includes a perfetto counter to display these in perfetto.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2025-03-06 16:09:42 +02:00
Loïc Molinari
7f87268474 libweston: Fix doc string
Signed-off-by: Loïc Molinari <loic.molinari@collabora.com>
2025-01-21 14:34:31 +01:00
Loïc Molinari
96c49d91a5 libweston: Enforce renderbuffer size
Although backends can create renderbuffers of any size, they always
request the output's current mode size (including decorations).
Letting backends ask for a different size than the output has a few
read-back related design issues like for instance weston_renderer's
read_pixels() API users, currently assuming the output size and
without knowledge of renderbuffers, can retrieve cropped images if a
backend asks for a smaller size. Same issue for the output capture
subsystem.

This commit proposes to fix these issues by simply, albeit perhaps
radically, removing the width and height parameters from
create_renderbuffer(), enforcing the current mode's size of the
associated output.

The VNC and PipeWire backends now also access the output size via the
current mode, not through the width and height variables. This has the
benefit of unifying the backends, as well as the renderers, in their
use of output sizes.

Signed-off-by: Loïc Molinari <loic.molinari@collabora.com>
2025-01-21 14:34:31 +01:00
Loïc Molinari
4eddce5557 libweston: Unify renderbuffer creation API
The Pixman renderer creates renderbuffers with the create_image() and
create_image_from_ptr() functions. The recent addition of the GL
renderer's create_fbo() function, which is pretty similar to the
Pixman ones, brings the opportunity to unify Pixman and GL renderers.

This commit proposes a common renderer function create_renderbuffer()
to create a renderbuffer of the specified format with an optional user
provided destination buffer.

Signed-off-by: Loïc Molinari <loic.molinari@collabora.com>
2025-01-21 14:34:31 +01:00
Loïc Molinari
a49b2e5a0d libweston: Deal with renderbuffer discards using an event handler
It's currently assumed by backends that renderers discard
renderbuffers on resize. This commit introduces a new
weston_renderbuffer_discarded_func callback that must be passed at
renderbuffer creation in order to be notified of discarded events from
the renderer. This discarded event could potentially be reused later
by renderers on other occasions without having to change backends once
they get proper support for that.

On output resize, once a discarded event handler fails (returns false)
on a renderbuffer, all the remaining renderbuffers in the output list
go stale and weston_renderer_resize_output() ultimately returns false
for backends to be notified of the failure.

Signed-off-by: Loïc Molinari <loic.molinari@collabora.com>
2025-01-21 14:21:40 +01:00
Loïc Molinari
b9e199b47d libweston: Use explicit renderbuffer destruction
Renderbuffers currently have a libweston-internal base data structure
with a ref-counting system to handle their lifetime. The problem is
that renderers keep a ref to all renderbuffers in a list per output
(to deal with damages) and that it prevents backends from releasing
renderbuffer resources when not needed anymore. Renderbuffers are then
only released (last ref removed) when the output is destroyed or
resized. dma-buf renderbuffers even expose a dedicated function
remove_renderbuffer_dmabuf() to explictly request the release of their
resources.

This commit proposes to get rid of the ref-counting system by exposing
a single entry point to explicitly destroy all types of renderbuffers
from the renderer.

Instead of removing a renderbuffer from its output list and dropping
its ref when the output is resized, this commit also introduces the
concept of stale renderbuffers which consists in releasing the
resources of a renderbuffer when it's discarded by the renderer while
keeping it in the output list, with a stale state, until it's
explicitly destroyed.

Signed-off-by: Loïc Molinari <loic.molinari@collabora.com>
2025-01-21 14:21:40 +01:00
Loïc Molinari
1619a4a1e5 libweston: Let renderers manage renderbuffers' damage
Move the responsibility for damaging the entire area of new
renderbuffers from backends to renderers.

There's one little drawback: VNC damage logging can't log the
accumulated renderbuffer damage anymore, but I guess this should
somehow be done as an option in the renderers.

Signed-off-by: Loïc Molinari <loic.molinari@collabora.com>
2025-01-21 14:21:40 +01:00
Derek Foreman
50d92f9d6f libweston: Fix crash with mirror-of
Since c4eb15d453 we keep a copy of
native mode parameters, however we forgot to initialize the
native mode parameters in some situations, which breaks the
output mirroring code when it sees uninitialized data.

Fixes c4eb15d453
Fixes #949

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2024-08-30 08:16:45 -05:00
Michael Tretter
14e133e48e gl-renderer: add DMABUF allocator
The GL renderer is able to use a gbm_device to allocate gbm_bos, which can be
used as DMABUFs.

Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
2024-07-19 11:43:42 +02:00
Michael Tretter
5a779b7804 gl-renderer: add dmabuf renderbuffer support
Support importing dmabuf buffers as renderbuffers and binding them to
FBOs. These can then be rendered to directly, or they can be blitted
into from the shadow render buffer.

How to best create those dmabuf buffers in the backend is an open
question and may vary depending on what external API the backend is
interfacing with.

Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
2024-07-19 11:43:42 +02:00
Daniel Stone
f5074f261a view: Move psf_flags from weston_view to weston_paint_node
Fundamentally, the flags are a property of each paint node, rather than
each view as such. Move them over there so it gets a little less painful
to work with.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2024-07-12 17:50:21 +03:00
Chao Guo
e1594110f0 compositor: Add a new member to the weston_paint_node
Add a boolean member named need_hole in weston_paint_node, which is used
to indicate whether the renderer should draw through hole on primary
plane when rendering.

For paint node whose view are placed on the underlay plane, this
member should be set to true, otherwise it is false.

Signed-off-by: Chao Guo <chao.guo@nxp.com>
2024-07-10 13:17:21 +00:00
Derek Foreman
bb0944c8be compositor: fix damage optimization
We can skip posting damage beneath planes that are fully translucent,
but that doesn't mean we can skip posting damage beneath planes that
are not fully opaque.

Add a check for content that is entirely blended, and use that instead.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2024-07-03 11:09:23 +00:00
Derek Foreman
83b37c0ac4 renderers: pull dmabuf initial setup out of attach
With attach only being called at render time, the dmabuf can be deleted
along with its private data before we attach for the first time.

Let's move the first-time logic into its own callback to call at
buffer setup time instead.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2024-06-18 08:45:43 -05:00
Derek Foreman
984d36aaca compositor: Move censor/direct checks into paint node update
By moving this here we can use the information to disable damage tracking
for placeholder surfaces, as well as render them entirely opaquely.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2024-06-11 09:23:27 +00:00
Derek Foreman
290301882f renderers: Pass a paint node to the attach callbacks
Since we only call this from the paint node update code now, we can pass
the paint node directly.

A bit of internal refactoring is required to support copy_content.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2024-06-11 09:23:27 +00:00
Derek Foreman
da6622f1d6 compositor: Add PAINT_NODE_BUFFER_DIRTY
In the future we'll use this, but for now just add the tracking.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2024-06-11 09:23:27 +00:00
Derek Foreman
71079ffd1a renderers: Make flush_damage take a weston_paint_node
Currently we're passing in a surface, a buffer, and an output. All of
these things are available in the paint node.

Further, if we pass in the paint node directly, we don't have to walk
a list of paint nodes to figure out if the texture is used in the
upcoming repaint.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2024-06-11 09:23:27 +00:00
Derek Foreman
e169b77430 compositor: Don't lift planes out of scene graph entirely
When we lift planes entirely out of the scene graph, paint node visibility
calculations become "per plane". This means that when we lift something
onto a paint node, anything beneath it will be redrawn in response to
client side damage even if the lower surfaces are occluded.

Instead, keep the scene graph together and make the paint node visible
regions be their visibility within the global scene graph.

This has the side effect of plane motion causing redraws, to update
regions they've been obscuring. My assumption is that moving planes
is less frequent than damage being posted beneath an overlay, and
that we'll be more efficient for normal use cases this way.

An optimization is in place to prevent redraws when moving transparent
planes, as they haven't been occluding updates.

In addition to theoretically removing some wasteful rendering time, this
also simplifies damage accumulation.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2024-05-24 11:13:34 -05:00
Philipp Zabel
1d59530e4b libweston: Set the presentation clock in the compositor
Let backends declare the presentation clocks they can use with a
new bitfield weston_backend::supported_presentation_clocks and set
presentation clock after loading the backend in the compositor.

Make weston_compositor_set_presentation_clock() internal and replace
weston_compositor_set_presentation_clock_software() with an exported
weston_compositor_backends_loaded(), which is called by the compositor
after the backend is loaded.

In the future, this can be extended to determine the subset of clocks
supported by all backends.

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
2023-08-02 11:51:56 +03:00
Philipp Zabel
155fa3a56a libweston: Add output parameter to weston_renderer::flush_damage()
When flush_damage() is called, the output to be repainted next is
already known. Pass it along into the renderer, which can make use
of this information:

The GL renderer can get a better idea which SHM surface textures
actually have to be updated, in case a surface can be put on a plane
on one output, but not another.

A future Vulkan renderer could record texture uploads into an output
specific command buffer.

Signed-off-by: Philipp Zabel <philipp.zabel@gmail.com>
2023-07-14 16:30:52 +00:00