-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed
Labels
C - needs discussionDirection must be ironed outDirection must be ironed outDS - webAffects the Web backend (WebAssembly/WASM)Affects the Web backend (WebAssembly/WASM)F - questionThere's no such thing as a stupid oneThere's no such thing as a stupid one
Description
Since web workers support canvas via OffscreenCanvas, would it be possible to make winit run in a web worker?
Main issues are these:
OffscreenCanvasimplementsEventTargetso events are not a problem. Although they will have to be forwarded from the main canvas via whatever worker implementation is used. Probably not awinitconcern.OffscreenCanvasis different type thanHtmlCanvasElementand can not be converted in rust. However, since javascript is an interpreted language, insertingOffscreenCanvasinstead ofHtmlCanvasElementfrom js side does not cause a problem. Although browser throws an error due to missing functions (style(),request_fullscreen(),set_attribute()), adding empty stubs fixes the issue and it works happily. This is a bit hacky, but other option would require replacingbackend::RawCanvasTypewith enum, which would require a lot of rewrites.- A lot of functions use
web_sys::window()and panic on web worker. Could they instead of panicking return default value? Main offenders arescale_factor()andis_fullscreen()which both are not essential. However, if they return default value would it make debugging harder for regular canvas?
Maybe there's no point in running winit in web worker, because the only usable feature without additional glue is the event loop. But I opened this for discussion, as this is relevant for projects that use winit and trying to support wasm.
Metadata
Metadata
Assignees
Labels
C - needs discussionDirection must be ironed outDirection must be ironed outDS - webAffects the Web backend (WebAssembly/WASM)Affects the Web backend (WebAssembly/WASM)F - questionThere's no such thing as a stupid oneThere's no such thing as a stupid one