Skip to content

Conversation

@jholveck
Copy link
Contributor

@jholveck jholveck commented Nov 22, 2025

Changes proposed in this PR

This is close to complete, but there's a few things that need to be
chased down: notably, the test_thread_safety test is failing, for some
reason. It also currently doesn't work correctly if the root window
size increases.

That said, this is quite promising: on my computer, the new backend
can take 4k screenshots at 30-34 fps, while the XGetImage backend
could only run at 11-14 fps.

It is very important to keep up to date tests and documentation.

  • Tests added/updated
  • Documentation updated

Is your code right?

  • ./check.sh passed

This only adds the support for the XCB MIT-SHM extension to mss's
internal xcb libraries. The actual usage of shared memory for
screenshots will be done in a future commit.
This is close to complete, but there's a few things that need to be
chased down: notably, the test_thread_safety test is failing, for some
reason.  It also currently doesn't work correctly if the root window
size increases.

That said, this is quite promising: on my computer, the new backend
can take 4k screenshots at 30-34 fps, while the XGetImage backend
could only run at 11-14 fps.
Previously, I had been trying to close the memfd in _shutdown_shm, and
ignoring EBADF.  It turns out that XCB will close the memfd when you
send it to the X server.

I think this was one potential cause of the issues I saw in
test_thread_safety: the two threads would be reallocated each others'
fds, leading to thread A closing an fd that thread B was using,
thinking that it was thread A's memfd.

Fix so that the memfd is only explicitly closed in an error situation.
Under X11, when the last client disconnects, the server resets.  If
a new client tries to connect before the reset is complete, it may fail.
Since we often run the tests under Xvfb, they're frequently the only
clients.  Since our tests run in rapid succession, this combination
can lead to intermittent failures.

To avoid this, we open a connection at the start of the test session
and keep it open until the end.
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.

Improve speed on GNU/Linux with XShm

1 participant