Skip to content
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

Adjust internal canvas size on Surface::configure() #3690

Merged
merged 2 commits into from
Apr 19, 2023

Conversation

daxpedda
Copy link
Contributor

@daxpedda daxpedda commented Apr 14, 2023

Checklist

  • Run cargo clippy.
  • Run RUSTFLAGS=--cfg=web_sys_unstable_apis cargo clippy --target wasm32-unknown-unknown if applicable.
  • Add change to CHANGELOG.md. See simple instructions inside file.

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 using Surface::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 the HTMLCanvasElement 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?

@daxpedda daxpedda force-pushed the canvas-size branch 3 times, most recently from 2e38464 to 9860b56 Compare April 14, 2023 18:49
@daxpedda daxpedda requested a review from cwfitzgerald April 19, 2023 20:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Surface::configure() should resize canvas
2 participants