Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pixman (and gles) renderer fixes #1602

Merged
merged 3 commits into from
Dec 7, 2024
Merged

Conversation

ids1024
Copy link
Member

@ids1024 ids1024 commented Dec 6, 2024

This fixes an error I noticed in #1497 where it the renderer couldn't access an shm buffer that had been destroyed. I believe using a strong reference to the WlBuffer won't cause issues here.

For dmabuf buffers, retaining a strong Dmabuf would not be correct, since the caching is based on strong references to the Dmabuf. I've tested that the same error doesn't occur with dmabufs though. I guess as long as there is a strong reference in the WaylandSurfaceRenderElement, the user data of the WlBuffer has a strong reference to the Dmabuf.

So no corresponding change is needed for dmabufs, though perhaps its worth thinking if caching could be done differently. It could cache by Weak<WlBuffer> instead of WeakDmabuf by implementing ImportDmaWl. Though using WeakDmabuf allows this to be used with dmabufs that aren't from Wayland. (And it could be nice to disentangle renderers from wayland_backend, but that would also require an Shmbuf type or such, instead of just a WlBuffer reference...)

Doing tests with dmabufs, I also noticed that PixmanRenderer::import_dmabuf() succeeds for non dmabuf fds (then anvil crashed later when trying to use sync_plane). Seems good to test this in import_dmabuf() and error there, and I can't think of a better way at the moment than calling sync_plane there.

Comparing the gles renderer, I also noticed it was pushing to dmabuf_cache regardless of wayland_frontend, but only evicting from the cache with that feature. So I removed that #[cfg].

If a weak `WlBuffer` is used, it isn't possible to read the contents of
a destroyed shm buffer. But the Wayland protocol specifies that
destroying an attached buffer shouldn't change the contents of the
surface.

A `wayland_server::Weak` will not upgrade to a strong reference for a
destroyed object even if other strong references exist, like the strong
reference to the `WlBuffer` in `WaylandSurfaceRenderElement`.

This fixes an error when a buffer is destroyed by libdecor, which
crashed a version of Anvil patched to use pixman.
Previously, `PixmanRenderer::import_dmabuf` didn't error for an fd that
isn't a dmabuf. Which caused an error later when trying to use this
ioctl.

I'm not aware of a better way to test this, so we can just add a
`sync_plane` here.
Without `wayland_frontend`, this was pushing to the cache, but never
removing buffers. That presumably is not correct.
Copy link
Member

@Drakulix Drakulix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Drakulix Drakulix merged commit a5f30b9 into Smithay:master Dec 7, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants