pub fn fit_within_max_dimension(width: u32, height: u32, max: u32) -> (u32, u32)Expand description
Shrink (width, height) until neither axis exceeds max, preserving the
aspect ratio. Sizes already within the limit are returned untouched.
wgpu treats a surface larger than max_texture_dimension_2d as a
validation error, and on wasm a validation error is a panic that takes the
whole instance with it — a black canvas and a dead engine, not a degraded
one. Every path that hands a size to Surface::configure must come through
here first.
Both axes scale by the same factor on purpose. Clamping only the offending one would change the aspect ratio of the drawing buffer while the CSS box kept its shape, and every circle on screen would render as an ellipse.
A zero on either axis is returned unchanged: it is separately invalid, and silently inventing a size would hide that from the caller who must reject it.