Repository navigation
offscreen: Render GPUI views into images on iOS and Android - #33
Merged
Merged
Conversation
…en` feature Ungate `WgpuHeadlessRenderer` from `test-support` / `bench-support`, add `WgpuHeadlessRenderer::with_instance` so iOS can pass a Metal instance (the default instance only enables Vulkan and GL), and inherent `render_to_image` / `sprite_atlas` / `max_texture_size` that do not need GPUI's test-only `PlatformHeadlessRenderer` trait. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
offscreen windows that render GPUI views into images
madcodelife
added a commit
that referenced
this pull request
Oct 13, 2026
…ws (#37) ## Summary Follow-up to #33. - **Release GPU memory after captures.** The headless renderer is kept for the rest of the process, so after a capture it held the render target and the path intermediate / MSAA textures sized to the last frame (for a 1170×16000 image that is roughly 75 MB + 75 MB + 300 MB at 4× path MSAA), plus every glyph and image tile uploaded to the sprite atlas the offscreen windows share. GPUI only removes image tiles through `App::drop_image` on open windows, which never reaches that atlas once the window is gone, so image tiles accumulated for the life of the process. - The vendored `gpui-pre-wgpu` gains two `offscreen`-gated methods on `WgpuHeadlessRenderer`: `release_render_target` (render target + path intermediates) and `clear_sprite_atlas` (atlas tiles + the cached bind groups that keep their textures alive). The readback buffer was already a per-call local, so there is no staging buffer to release. - `offscreen` counts live offscreen platform windows and calls both when GPUI drops the last one (after its view tree), so no open window can hold a tile that gets cleared. The device and pipelines stay for the next capture. - **Close dropped windows.** Dropping an `OffscreenWindow` without `close` (for example when the task holding it is cancelled) used to leave the window and its view tree alive forever. It now keeps an `AsyncApp` and, on drop, spawns the close on the foreground executor, since `Drop` may run while the `App` is borrowed. `close` disarms it, so the window is never closed twice. - README and the `[patch.crates-io]` comment describe the new vendor methods and the release behaviour. While an offscreen window stays open, image tiles still accumulate the same way they do for on-screen windows; the instance buffer, which grows to the largest frame's instance data, is kept with the pipelines. ## Testing - `cargo check --features offscreen` for `aarch64-apple-ios`, `aarch64-apple-ios-sim` and `aarch64-linux-android` - `cargo check --all-targets`, `cargo test --lib`, `cargo fmt --all -- --check` - `cargo clippy --features offscreen` for iOS and Android: no new warnings - New vendor test `headless_renderer_releases_frame_textures` (Linux, like the other headless tests); also run locally on macOS against a Metal instance, where it passes --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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.
Summary
Adds an
offscreenfeature for rendering GPUI views into images on iOS and Android — for share cards, long screenshots and similar exports.gpui_mobile::offscreen::OffscreenWindowopens an ordinary GPUI window whose platform side has no UIKit/NDK surface. Layout, text shaping and painting run exactly as on screen;render(size)forces one frame and reads its pixels back through wgpu's headless renderer (image::RgbaImage), andlayout(size)paints without reading back so views can measure their content first.max_size()reports the GPU texture limit in logical pixels.IosPlatform::open_window/AndroidPlatform::open_windowhand out the offscreen window whenOffscreenWindow::openasked for one (a thread-local pending slot, like Android's pending-window lookup).Why a vendored
gpui-pre-wgpuUpstream
gpui-pre-wgpu0.3.8 only buildsWgpuHeadlessRendererwithtest-support/bench-support(the latter turns on GPUI's per-frame profiler), and its device comes from a Vulkan + GL instance, which has no adapter on iOS.vendor/gpui-pre-wgpuis the unmodified 0.3.8 source (first commit) plus a small patch (second commit, ~100 lines):offscreenfeature;WgpuHeadlessRenderer::with_instance(wgpu::Instance)so iOS can pass a Metal instance;render_to_image/sprite_atlas/max_texture_size, which don't need GPUI's test-onlyPlatformHeadlessRenderertrait.Applications enabling
offscreenmust patchgpui-pre-wgputo this copy (see the README section). The longer-term fix is to offer the same in upstreamgpui_wgpu.Testing
cargo checkforaarch64-apple-ios,aarch64-apple-ios-simandaarch64-linux-androidwithoffscreen; hostcargo check --all-targets; clippy clean for the new module;cargo fmt --all -- --check.