-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -235,6 +235,28 @@ impl Surface { | |
| }) | ||
| } | ||
|
|
||
| /// 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), | ||
| }) | ||
| } | ||
|
|
||
| /// 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, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd rather avoid exposing a public dependency on
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| ) -> Result<Self, SoftBufferError> { | ||
| let imple = SurfaceDispatch::Web(web::WebImpl::from_offscreen_canvas(offscreen_canvas)?); | ||
|
|
||
| Ok(Self { | ||
| surface_impl: Box::new(imple), | ||
| }) | ||
| } | ||
|
|
||
| /// Shows the given buffer with the given width and height on the window corresponding to this | ||
| /// graphics context. Panics if buffer.len() ≠ width*height. If the size of the buffer does | ||
| /// not match the size of the window, the buffer is drawn in the upper-left corner of the window. | ||
|
|
||
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
winitis to make this an extension trait on the existing type. Could we do that here?