Repository navigation
linux-capture: XComposite tracks window state from X events instead of a round trip per frame (#1356) - #1377
Merged
Merged
Conversation
zackees
added a commit
that referenced
this pull request
Oct 18, 2026
zackees
force-pushed
the
fix/1356-xcomposite-exists-from-events
branch
from
October 18, 2026 02:04
9c6cf2d to
4bff34e
Compare
zackees
marked this pull request as ready for review
October 18, 2026 02:05
zackees
enabled auto-merge
October 18, 2026 02:05
zackees
disabled auto-merge
October 18, 2026 02:15
…f a round trip per frame (#1356) xcompcap_video_tick called xcomp_window_exists (xcb_get_window_attributes request + reply) once or twice per frame under obs_enter_graphics and the source lock. The watcher now feeds Map/Unmap/DestroyNotify into a cached presence state; the tick reads the cache, reads events with the non-blocking xcb_poll_for_event (and frees them), and asks the server only after window_changed/new settings and at most once a second as a safety net, before obs_enter_graphics. #1366's search backoff is unchanged. Refs #1356
… to end under Xvfb (#1356) Compiles the linux-capture unity file into a cmocka test, publishes a minimal EWMH setup in place of a window manager, and drives a plain xcb window through map, three unmap/map rounds and destroy while libobs ticks the real xcomposite source. Unmap must unhook within 400 ms (well under the 1 s safety net, so it comes from the UnmapNotify read by xcb_poll_for_event), map must re-hook within 2 s, destroy must unhook. Xvfb's llvmpipe cannot import the window pixmap as an EGLImage, so the capture's texture is not checked; the hooked state is. Refs #1356
zackees
force-pushed
the
fix/1356-xcomposite-exists-from-events
branch
from
October 18, 2026 02:58
4bff34e to
38a292a
Compare
zackees
enabled auto-merge
October 18, 2026 02:58
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #1356 (parent #1273; builds on #1366).
Cause
xcompcap_video_tickcalledxcomp_window_exists()(a blockingxcb_get_window_attributesrequest + reply) once or twice per frame, underobs_enter_graphics()and the source lock. A busy or remote X server stalled the render path every frame.Design
plugins/linux-capture/xcomposite-presence.h(same approach as linux-capture: XComposite backs off the window search while the window is unmapped (#1357) #1366'sxcomposite-search.h): cachedknown/viewablestate, fed by events, with a safety-net recheck at most once per second (XCOMP_PRESENCE_RECHECK).StructureNotifyMask | ExposureMask | VisibilityChangeMaskon the target window, so no mask change is needed.watcher_processnow maps MapNotify → viewable, UnmapNotify (newly handled; does not setwindow_changed) → not viewable, DestroyNotify → not viewable; Configure/Expose/Visibility still setwindow_changedas before.xcb_poll_for_event(the per-frame round trips used to be what pulled events into the queue forxcb_poll_for_queued_event), frees them (they were leaked), and does the real round trip only when the cache is unknown (new settings,window_changed) or ≥1 s old. That check runs under the source lock but beforeobs_enter_graphics().window_lostread the cached state. After a search, the result'sviewablerefreshes the cache. linux-capture: XComposite backs off the window search while the window is unmapped (#1357) #1366's backoff (xcomp_search_*) is unchanged.Test
New self-contained cmocka test
test/cmocka/test_xcomposite_presence.c(tests.d/test_xcomposite_presence.cmake, links only cmocka): simulated 60 fps ticks with a fake server and event feed, counting existence round trips.RED (
74d91fc82, helpers stubbed to today's per-frame check):rust/tools/linux-validate/run.sh --repeat 1 --tests test_xcomposite_presenceGREEN (
c4789fcb4):100% tests passed, 0 tests failed out of 296; repeat runtest_xcomposite_presence ... Passed,test_xcomposite_search_backoff ... Passed.End to end under Xvfb (requested by the lead)
test/cmocka/test_xcomposite_window_events.c(38a292ac5,tests.d/test_xcomposite_window_events.cmake): compiles the linux-capture unity file into the test, callsxcomposite_load(), runsobs_startup+obs_reset_video(libobs-opengl by path) under the harness's xvfb-run display (Composite present). The test publishes a minimal EWMH setup (_NET_SUPPORTING_WM_CHECK,_NET_CLIENT_LIST) in place of a window manager, creates a plain xcb window and anxcomposite_inputsource on it, and lets libobs tick it:get_hooked)unhookedwithin 400 ms, three rounds (the safety net is 1 s, so this comes from the UnmapNotify read byxcb_poll_for_event)hookedagain within 2 sunhookedLimitation: Xvfb's Mesa llvmpipe has no DRI3, so
gs_texture_create_from_pixmaplogsCannot create EGLImage: One or more argument values are invalidand the source has no texture (0x0). Width/height are therefore not asserted; the rounds run on the no-texture path. Passed underrun.sh --repeat 1 --tests test_xcomposite(full run 298/298, repeat 3/3).Tiers: Tier 2 (new C tests). Tier 1/3/4 do not apply (C plugin fix, no Rust port, no protocol). Not run against a real desktop X server with GPU pixmap import; the compile check is PR CI's Fast Gate for
linux-capture.Ledger: docs/features.md, Fixed upstream bugs → Video capture.