Files
zed/crates/gpui_apple
Ben Brandt f816e1f926 gpui: Render macOS window screenshots offscreen (#66344)
`MetalRenderer::render_to_image` rendered a window's screenshot into the
layer's next drawable. Since macOS windows began presenting through a
`CAMetalDisplayLink`, the display link owns the layer's drawables, and
calling `nextDrawable` raises `CAMetalLayerInvalidOperation:
-nextDrawable should not be called when using CAMetalDisplayLink`, which
aborts the process. Every caller of `Window::render_to_image` on a live
macOS window crashed on its first screenshot, which broke automated UI
testing in apps built on GPUI.

This renders the screenshot into a texture of its own instead. It moves
the offscreen path that `render_scene_to_image` already used for
headless rendering into a shared `render_offscreen` helper, including
the blit that managed textures need on Intel Macs, and has
`render_to_image` call it at the layer's drawable size. Nothing is
presented, so taking a screenshot no longer touches what the display
link draws.

Tested by taking automation screenshots of a running GPUI app on macOS,
which aborted before this change and succeed with it.

Release Notes:

- [GPUI] Fixed a crash when capturing a macOS window with
`Window::render_to_image` while a display link drives its layer

---------

Co-authored-by: Anthony Eid <hello@anthonyeid.me>
2026-11-01 22:52:58 +00:00
..