Donner SVG 0.8.0-pre
SVG editor and embeddable C⁠+⁠+⁠20 engine.
Loading...
Searching...
No Matches
WholeAppWorkerBridge.h File Reference

Main-thread bridges for the single-canvas architecture whole-app-worker build. More...

Detailed Description

Main-thread bridges for the single-canvas architecture whole-app-worker build.

In that build main() runs on a pthread (Emscripten PROXY_TO_PTHREAD) and the single #canvas is transferred to it as an OffscreenCanvas. EM_JS bodies run in the JS context of the calling thread, so every window, document, and navigator reference in the shipping editor's EM_JS probes evaluates in a DedicatedWorkerGlobalScope where those globals do not exist. This header owns the replacements.

Two mechanisms, chosen per seam by how often it is read:

  • Shared-memory mirror. Values the app thread reads every frame (CSS viewport size, device pixel ratio, the frame-request flag, the wheel zoom modifier shadow) are published by main-thread DOM listeners writing directly into linear memory, which is shared across all pthreads. Reads on the app thread are ordinary loads. A synchronous proxied call per read would cost a round trip on every frame, which is exactly the budget this phase is trying to measure.
  • Async proxied JS. Values the page must observe but the app thread only writes (the window.__donner* probe surface) go through MAIN_THREAD_ASYNC_EM_ASM, which posts to the main thread without blocking the app thread.

Nothing here is compiled unless DONNER_EDITOR_WHOLE_APP_WORKER is defined, so the shipping package is unaffected.