Pre-rotate Slint's Skia drawing on the wgpu swapchain on Android
The other half of the wgpu-hal patch: that one lets a caller promise a pre-rotated swapchain, and this is the caller keeping the promise. On configure, `WGPUSurface` reads the surface's `currentTransform`, sizes the swapchain in the panel's orientation (swapped for a quarter turn), tells wgpu-hal to use that transform, and before each frame concatenates the matching rotation onto the Skia canvas. Everything Slint draws goes through that one matrix, so an imported wgpu texture is rotated with the rest of the window. Input is not rotated, and must not be, because Android delivers it in window coordinates. Three details that would each have been a visible bug: - `resize_event` compared the new size against the swapchain's. The swapchain is transposed while a quarter turn is in effect, so the comparison now uses the window's size, kept beside it. - A half turn, landscape to reverse landscape, changes the transform without resizing the window, and wgpu-hal hides the SUBOPTIMAL that would report it. So the transform is re-read before every frame. That costs one query into the native window. - The item renderer snapped the origin to the pixel grid only when the canvas matrix was a pure translation. Under a rotation that is never true, so portrait would have lost pixel alignment everywhere. The check now accepts right-angle rotations and flips without scaling. The direction of each rotation follows the Vulkan spec's reading of preTransform (the image is drawn already rotated clockwise by the transform). It has not been confirmed on the device yet.
This commit is contained in:
Vendored
+19
-1
@@ -49,4 +49,22 @@ Unnecessary once wgpu exposes pre-rotation itself (#3345).
|
||||
|
||||
## i-slint-renderer-skia 1.17.1 — rotate the canvas to match
|
||||
|
||||
*(patch lands in a later commit)*
|
||||
`wgpu_29_surface.rs` keeps the promise the wgpu-hal patch lets it make.
|
||||
On Android it reads the surface's transform whenever it configures, sizes
|
||||
the swapchain in the panel's orientation (width and height swapped for a
|
||||
quarter turn), calls `set_pre_transform`, and concatenates the matching
|
||||
rotation onto the Skia canvas before Slint draws — so the whole UI,
|
||||
including an imported `wgpu::Texture`, is drawn pre-rotated. It checks the
|
||||
transform before every frame too, because a half turn (landscape to
|
||||
reverse landscape) changes it without resizing the window. Touch input is
|
||||
untouched: only drawing is rotated.
|
||||
|
||||
`itemrenderer.rs` widens the pixel-alignment check from "pure translation"
|
||||
to "any right-angle rotation or flip without scaling". Without that, a
|
||||
rotated canvas silently loses pixel snapping everywhere.
|
||||
|
||||
Off Android every path is upstream's: the rotation is always `None`.
|
||||
|
||||
Unnecessary once Slint's Skia wgpu surface pre-rotates on its own —
|
||||
worth offering upstream, since the linuxkms backend already renders
|
||||
through the same rotate-and-translate in `render_to_canvas`.
|
||||
|
||||
Reference in New Issue
Block a user