-
Notifications
You must be signed in to change notification settings - Fork 910
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Web worker support #1518
Comments
I guess my question would be why would you want to point winit at an offscreen canvas? Is it possible for that canvas to receive events? |
It does implement I just opened this issue to maybe explore possibilities and get ideas from other people on best practices with web assembly. There is a big issue with wasm that it supports threads (under web workers), with one big exception that you can't atomic wait (mutex, lock, sleep, etc) in main thread. This renders many native libraries and projects unable to run on wasm without major rewrites. So running entire application in a web worker is one way to overcome this problem. We explored this option for https://github.com/amethyst/amethyst and had a PoC running with |
I think for now it doesn't quite make sense for This should be kind of similar to how OpenGL rendering on its own thread works on native. The user passes the OpenGL context to another thread and do the rendering over there, but the IMO The current event handling and threading model on web makes it quite complicated to run the |
I didn't discover this issue before, but I have made some work towards supporting a multi-threaded Wasm environment. I agree with @alvinhochun that I do not believe that
The last bugs connected to |
This has been successfully resolved by #2834.
|
Since web workers support canvas via
OffscreenCanvas
, would it be possible to make winit run in a web worker?Main issues are these:
OffscreenCanvas
implementsEventTarget
so events are not a problem. Although they will have to be forwarded from the main canvas via whatever worker implementation is used. Probably not awinit
concern.OffscreenCanvas
is different type thanHtmlCanvasElement
and can not be converted in rust. However, since javascript is an interpreted language, insertingOffscreenCanvas
instead ofHtmlCanvasElement
from 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::RawCanvasType
with enum, which would require a lot of rewrites.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 usewinit
and trying to support wasm.The text was updated successfully, but these errors were encountered: