Adjust internal canvas size on Surface::configure()
#3690
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Checklist
cargo clippy
.RUSTFLAGS=--cfg=web_sys_unstable_apis cargo clippy --target wasm32-unknown-unknown
if applicable.Connections
Fixes #3620.
Related to rust-windowing/winit#2733.
Description
According to the spec, a canvas has two sizes, a rendered size, let's call it canvas size, and an output bitmap size. In WebGPU and WebGL a third size is added, the surface size.
The surface is rendered onto -> the output bitmap size is rendered onto -> the canvas. Each time the image will be resized to fit the size of what it's rendered to.
The canvas size is the only one actually affecting the visual size of the canvas (as long as it is set) on the screen and therefore the layout of the web page.
Currently
wgpu
only sets the surface size, when usingSurface::configure()
, this PR changes that to set the output bitmap size as well.The main motivation was that when using
HTMLCanvasElement.transferControlToOffscreen()
this can become difficult to handle otherwise. As setting the output bitmap size on theHTMLCanvasElement
will fail. It is difficult to design an API around that in e.g. Winit (see rust-windowing/winit#2733), so this PR alleviates this issue and shifts the responsibility of resizing the output bitmap size to the renderer.After this PR, users of
wgpu
don't have to set the output bitmap size anymore, but they will need to continue to set the canvas size.Testing
It's not, testing has to be done manually. Maybe an example can be adjusted to help test this manually?