Donner SVG 0.8.0
0.8.0 ยท ebf353960.8.0 main
SVG editor and embeddable C⁠+⁠+⁠20 engine.
Loading...
Searching...
No Matches
WholeAppWorkerBridge.h File Reference

Main-thread bridges for the browser editor, which is built as a whole-app worker. More...

Detailed Description

Main-thread bridges for the browser editor, which is built as a whole-app worker.

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 a window, document, or navigator reference in an EM_JS body would evaluate in a DedicatedWorkerGlobalScope where those globals do not exist. This header owns every browser-page seam the editor uses instead.

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, which the browser editor build always defines.