feat(attach): host-surface attach path on all platforms (PerryTS/perry#5519)#71
Merged
Merged
Conversation
…y#5519) Add a per-platform "attach to a host-provided surface" entry point so a BloomView (Perry UI) can hand the engine a native view/window/surface it already owns, instead of the engine creating its own window. Previously only Windows could embed (via the engine#70 bloom_attach_hwnd work); every other target created a view but no renderer attached to it. Engine - native/shared/src/attach.rs: factor the wgpu bring-up — instance → surface → adapter → device → swapchain → Renderer → EngineState — duplicated in every platform's bloom_init_window into one attach_engine() helper, parameterised by backend bitmask, dimensions (logical + physical for HiDPI), and a FormatPreference (Srgb / NonSrgb / First) covering each platform's swapchain-format policy. Returns a Result instead of panicking so a host attaching to a not-yet-realized view can recover. - One unified ABI symbol bloom_attach_native(handle, w, h) -> f64 rather than distinct per-platform names: the function manifest is shared and validate-ffi requires every platform to export every entry, so a single symbol (each platform interpreting `handle` as its own view/window/surface pointer) is cleaner than N stubs. TS exposes the named wrappers attachToNSView / attachToUIView / attachToSurface + attachToNativeView, all forwarding to it. - macOS: bloom_init_window refactored to use attach_engine (proves the factoring) + real bloom_attach_native on a host NSView. - iOS / tvOS / visionOS: real attach on a host UIView (tvOS/visionOS use a non-sRGB swapchain to match their windowed path). - Android: real attach on a host ANativeWindow. - Windows: real attach on a host HWND. - Linux: documented stub returning 0 — GTK4 GtkWidget→GdkSurface bridging is the larger follow-up the issue calls out. - watchOS: regenerated no-op stub (no wgpu). web: wasm_bindgen no-op (web builds its surface from the canvas id). - package.json manifest entry; validate-ffi passes 0/0 across all 8 platforms. Verification - shared compiles (native + wasm32); macОS builds and renders a scene end-to-end headless (getScreenWidth/Height read back 320x240 from the attached EngineState, 30 frames, clean exit); iOS cross-compiles; web wasm32 checks. Android/Linux/Windows cross-builds blocked locally by missing C cross-toolchains (NDK / linux-gcc / MSVC), not by this code.
The ffi-parity check was already red on main (29 failures): #69 added the mesh-scratch / tonemap / bloom-intensity / auto-exposure FFI functions and #70 added bloom_attach_hwnd / bloom_resize to the shared manifest, but neither was exported (or allowlisted) on the platforms that don't pick them up automatically. The manifest contract requires every platform to export every entry, so the attach PR can't go green without closing them. - bloom_resize: real on macOS/iOS/tvOS/visionOS/Android/Linux — it just forwards to the shared Renderer::resize (same body as the Windows impl from #70), so host-driven BloomView resizing now works on every target, not only Windows. - bloom_attach_hwnd: no-op stub on the non-Windows native platforms (it's HWND-specific; those hosts use bloom_attach_native). Mirrors #70's own cfg(not(windows)) no-op. - watchos: regenerated ffi_stubs.rs covers the new entries. - web: documented the genuinely-unimplemented entries in tools/validate-ffi.js WEB_GAP_ALLOWLIST (pointer-taking mesh scratch = same WASM linear-memory TODO as bloom_scene_set_lod; post-FX controls not yet wired in the web crate; attach_hwnd N/A on canvas). validate-ffi now passes 0 failures / 0 warnings across all 8 platforms. macOS rebuilds + renders a scene end-to-end; iOS cross-compiles.
947de52 to
89d970b
Compare
renderer/mod.rs grew to 11985 lines in #69 (clouds / foliage wind / additive fog / immediate-mode shadows) but the ratcheting file-lines baseline was left at 11775, leaving check-file-lines red on main. Record the new grandfathered size so the gate is green; the baseline still only ratchets down from here. No code change.
Contributor
Author
|
Rebased onto current Two follow-on commits beyond the attach feature, both fixing pre-existing red on
Verified after rebase: macOS rebuilds + renders a scene end-to-end headless (screen reads back 320x240 from the attached EngineState, 30 frames, clean exit); iOS cross-compiles. |
proggeramlug
pushed a commit
to PerryTS/perry
that referenced
this pull request
Jun 22, 2026
Perry-UI side of #5519 (the engine side landed in Bloom-Engine/engine#71 as the platform-neutral bloom_attach_native). Makes a BloomView actually usable as a render surface on every backend, not just Windows. - Rename bloomViewGetHwnd -> bloomViewGetNativeHandle, keeping the old name as a deprecated alias (both dispatch rows route to the same perry_ui_bloomview_get_hwnd runtime symbol). Platform-neutral now that the handle is an NSView*/UIView*/GtkWidget*/ANativeWindow*, not only an HWND. Updated ui_table.rs, api-manifest entries.rs, types/perry/ui/index.d.ts, and regenerated docs/api/perry.d.ts + docs/src/api/reference.md. - Sizing: the non-Windows backends ignored the requested size, so the renderer's surface came up 0x0. BloomView(w,h) now pins the size on macOS/iOS/visionOS/ tvOS (Auto Layout) and Android (LayoutParams); GTK/Windows already did. - tvOS: promoted the 0-handle stub to a real UIView (new widgets/bloomview.rs). - Android: switched View -> SurfaceView; bloomViewGetNativeHandle now returns the real ANativeWindow* (ANativeWindow_fromSurface on the SurfaceHolder surface), 0 until the surface is ready. - Input/focus: the host view is now focusable so a focused BloomView receives key/pointer events for the attached engine (macOS acceptsFirstResponder via a PerryBloomView subclass; iOS/tvOS/visionOS userInteractionEnabled; GTK set_focusable; Android setFocusable). - examples/bloomview_embed_demo.ts: a live Bloom scene inside a Perry UI window (BloomView + bloomViewGetNativeHandle + attachToNSView, driven by onFrame). Verified on macOS: the integrated binary (Perry UI + Bloom engine) links and runs the attach/frame loop without crashing; iOS cross-compiles; tvOS/visionOS host-build; dispatch+manifest tests pass; no api-docs drift. Android/GTK/Windows are best-effort (no local cross-toolchain), mirroring established per-backend patterns.
proggeramlug
added a commit
to PerryTS/perry
that referenced
this pull request
Jun 22, 2026
) * feat(ui): BloomView live-render plumbing on every backend (#5519) Perry-UI side of #5519 (the engine side landed in Bloom-Engine/engine#71 as the platform-neutral bloom_attach_native). Makes a BloomView actually usable as a render surface on every backend, not just Windows. - Rename bloomViewGetHwnd -> bloomViewGetNativeHandle, keeping the old name as a deprecated alias (both dispatch rows route to the same perry_ui_bloomview_get_hwnd runtime symbol). Platform-neutral now that the handle is an NSView*/UIView*/GtkWidget*/ANativeWindow*, not only an HWND. Updated ui_table.rs, api-manifest entries.rs, types/perry/ui/index.d.ts, and regenerated docs/api/perry.d.ts + docs/src/api/reference.md. - Sizing: the non-Windows backends ignored the requested size, so the renderer's surface came up 0x0. BloomView(w,h) now pins the size on macOS/iOS/visionOS/ tvOS (Auto Layout) and Android (LayoutParams); GTK/Windows already did. - tvOS: promoted the 0-handle stub to a real UIView (new widgets/bloomview.rs). - Android: switched View -> SurfaceView; bloomViewGetNativeHandle now returns the real ANativeWindow* (ANativeWindow_fromSurface on the SurfaceHolder surface), 0 until the surface is ready. - Input/focus: the host view is now focusable so a focused BloomView receives key/pointer events for the attached engine (macOS acceptsFirstResponder via a PerryBloomView subclass; iOS/tvOS/visionOS userInteractionEnabled; GTK set_focusable; Android setFocusable). - examples/bloomview_embed_demo.ts: a live Bloom scene inside a Perry UI window (BloomView + bloomViewGetNativeHandle + attachToNSView, driven by onFrame). Verified on macOS: the integrated binary (Perry UI + Bloom engine) links and runs the attach/frame loop without crashing; iOS cross-compiles; tvOS/visionOS host-build; dispatch+manifest tests pass; no api-docs drift. Android/GTK/Windows are best-effort (no local cross-toolchain), mirroring established per-backend patterns. * fix(ui): address CodeRabbit review on #5538 - android BloomView: cache the ANativeWindow* per handle instead of calling ANativeWindow_fromSurface (which returns a +1-refcount window) on every get_native_handle poll — that leaked a window reference per call. The first ready surface builds the window; later calls reuse the cached pointer. - tvos BloomView create(): add the MainThreadMarker main-thread guard the iOS path has (UIKit view creation must be on the main thread; return 0 otherwise). - types/perry/ui/index.d.ts: the deprecated bloomViewGetHwnd JSDoc had a raw `NSView*/UIView*/…` whose `*/` prematurely closed the block comment — backtick the type names so the sequence no longer terminates the comment. --------- Co-authored-by: Ralph Küpper <ralph2@skelpo.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.
Follow-up to PerryTS/perry#5519 (BloomView live rendering) and the Windows-side
bloom_attach_hwndwork (#70). Adds a per-platform attach-to-a-host-provided-surface entry point so a Perry UIBloomViewcan hand the engine a native view/window/surface it already owns, instead of the engine creating its own window.What
A single unified ABI symbol —
bloom_attach_native(handle, width, height) -> f64— exported by every platform, each interpretinghandleas its own native pointer. (Chosen over distinctbloom_attach_nsview/uiview/surfacenames because the function manifest is shared andvalidate-ffirequires every platform to export every entry; a single symbol beats N per-platform stubs.) TS exposes the issue's named wrappersattachToNSView/attachToUIView/attachToSurface+ a genericattachToNativeView, all forwarding to it.Engine
native/shared/src/attach.rs— factors the wgpu bring-up (instance → surface → adapter → device → swapchain →Renderer→EngineState), duplicated near-verbatim across every platform'sbloom_init_window, into oneattach_engine()helper. Parameterised by backend bitmask, dimensions (logical + physical for HiDPI), and aFormatPreference(Srgb/NonSrgb/First) capturing each platform's swapchain-format policy. Returns aResultinstead of panicking so a host attaching to a not-yet-realized view can recover.bloom_init_windowrefactored to callattach_engine(proving the factoring) + realbloom_attach_nativeon a hostNSView.UIView(tvOS/visionOS use a non-sRGB swapchain to match their windowed path).ANativeWindow.HWND.0: GTK4GtkWidget→GdkSurfacebridging is the larger follow-up the issue calls out.wasm_bindgenno-op (web builds its surface from the canvas id).package.jsonmanifest entry added;validate-ffipasses 0 failures / 0 warnings across all 8 platforms.Verification
sharedcompiles (native + wasm32); macOS builds and renders a scene end-to-end headless —getScreenWidth/Heightread back320x240from the attachedEngineState, 30 frames, clean exit 0 (a failed attach.expect-panics, so this confirms the refactoredbloom_init_windowpath).Perry side (not in this PR)
The Perry
BloomViewrename (bloomViewGetHwnd→bloomViewGetNativeHandle), per-platform sizing, AndroidSurfaceView, and input/focus routing tracked in PerryTS/perry#5519 are a separate change against the Perry repo.