-
Notifications
You must be signed in to change notification settings - Fork 69
added from_canvas and from_offscreen_canvas methods to Surface
#74
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
Conversation
| /// Creates a new instance of this struct, using the provided [`HtmlCanvasElement`](web_sys::HtmlCanvasElement). | ||
| #[cfg(target_arch = "wasm32")] | ||
| pub fn from_canvas(canvas: web_sys::HtmlCanvasElement) -> Result<Self, SoftBufferError> { | ||
| let imple = SurfaceDispatch::Web(web::WebImpl::from_canvas(canvas)?); | ||
|
|
||
| Ok(Self { | ||
| surface_impl: Box::new(imple), | ||
| }) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The general pattern in winit is to make this an extension trait on the existing type. Could we do that here?
| /// Creates a new instance of this struct, using the provided [`HtmlCanvasElement`](web_sys::OffscreenCanvas). | ||
| #[cfg(target_arch = "wasm32")] | ||
| pub fn from_offscreen_canvas( | ||
| offscreen_canvas: web_sys::OffscreenCanvas, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather avoid exposing a public dependency on web-sys if at all possible (in case we decide to move to stdweb or something). Is there a way of representing these types without web-sys?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know of a way to avoid that. Even Winit does it.
As far as I know stdweb is dead, but if you know of an alternative to the wasm-bindgen ecosystem I would be very interested!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forgot to mention, it is actually possible to represent these types without web-sys: using JsValue.
But this would still require wasm-bindgen as a public dependency, which doesn't really help if we want to change to an alternative later.
|
Closing this PR in favor of #76 |
Added methods to create
Surfacefrom aHtmlCanvasElementorOffscreenCanvasfollowing wgpu's example https://github.com/gfx-rs/wgpu/blob/v0.15.1/wgpu/src/lib.rs#L1570-L1640My use case required this to render in a web worker.
Edit: See this for a future alternative implementation rust-windowing/raw-window-handle#102