Wayland: on a fractional scale the viewport's destination is one larger than the configured size (a ceil of a ceil), and a window configured at its own size grows a pixel per configure #201

Open
opened 2026-11-18 05:44:51 +00:00 by jorijnvdgraaf · 0 comments

Summary

A configure's logical size becomes the swapchain's size as ceil(logical * scale), and the viewport's destination is then worked back from that as ceil(physical / scale). Wherever logical * scale is not a whole number, the second rounding lands one above the size the compositor configured. The surface is then one logical pixel wider and higher than asked and its buffer is shown slightly scaled. And when the compositor next configures the window at the size it now has, the same step is taken again: the window grows a pixel per configure, a swapchain each time, until it reaches a size where both roundings are exact. Line numbers refer to c006519.

Details

  • implementations/Crafter.Graphics-Window.cpp:1923-1926 (xdg_surface_handle_configure): newWidth = ceil(pendingLogicalWidth * scale), and the same for the height.
  • :784-788 (RebuildSwapchain): wp_viewport_set_destination(ceil(width / scale), ceil(height / scale)).
  • :406: the constructor does the second step on its arguments.

fractional-scale-v1 has it the other way about: the destination is the surface's size, and the buffer's size is that times the scale ("For toplevel surfaces, the size is rounded halfway away from zero").

The two roundings done in 32-bit float, as the code does them, for the logical sizes 1 to 3000: at 1.5 every odd size comes out one larger, at 1.25 and 1.75 every size that is not a multiple of 4, at 2.85 all but 127 of them. At 1 and 2 none does.

Concrete case

A Fairphone 6 with Plasma Mobile 6.8.2 (KWin 6.8.2), scale 2.85, running imsd-messages 0.0.0's tree (ca5cd72, the library at c006519) under WAYLAND_DEBUG=1. The maximized window is configured 392 x 796:

[03:12:45.397716] xdg_toplevel#16.configure(392, 796, array[4])
[03:12:45.421256]  -> wp_viewport#21.set_destination(393, 797)

392 x 2.85 = 1117.2, so the buffer is 1118 wide; 1118 / 2.85 = 392.28, so the destination is 393. The surface is 393 x 797 where 392 x 796 was configured, and a buffer 1118 pixels wide is laid over 1120.05.

Later in the same trace KWin configures the window at the size it now has, and each answer is one larger (the lines between are left out):

[03:13:24.613875] xdg_toplevel#16.configure(393, 797, array[8])
[03:13:24.618313]  -> wp_viewport#21.set_destination(394, 798)
[03:13:24.646890] xdg_toplevel#16.configure(394, 798, array[8])
[03:13:24.655157]  -> wp_viewport#21.set_destination(395, 799)
[03:13:24.672890] xdg_toplevel#16.configure(395, 799, array[8])
[03:13:24.673567]  -> wp_viewport#21.set_destination(396, 800)
[03:13:24.689235] xdg_toplevel#16.configure(396, 800, array[8])
[03:13:24.693924]  -> wp_viewport#21.set_destination(397, 800)
[03:13:24.722316] xdg_toplevel#16.configure(397, 800, array[8])
[03:13:24.727174]  -> wp_viewport#21.set_destination(398, 800)
[03:13:24.746577] xdg_toplevel#16.configure(398, 800, array[8])
[03:13:24.751471]  -> wp_viewport#21.set_destination(399, 800)
[03:13:24.767158] xdg_toplevel#16.configure(399, 800, array[8])
[03:13:24.771921]  -> wp_viewport#21.set_destination(400, 800)
[03:13:24.793058] xdg_toplevel#16.configure(400, 800, array[8])
[03:13:24.797760]  -> wp_viewport#21.set_destination(400, 800)

Eight rebuilds in 184 ms. It stops at 400 x 800 because both roundings are exact there (2.85 x 400 = 1140, 2.85 x 800 = 2280). 2.6 s later KWin configured 392 x 796 again. A second trace of the same night, of an earlier build of the app on the same library commit, has the same run of configures from 392 x 796 to 400 x 800.

Not looked into: what made KWin configure the window at its own size at those two moments, and whether the scaling of the buffer shows in the text.

Suggested fix

Keep the configured logical size as the window's state and send that as the destination, unchanged. Work out only the buffer's size from it, rounded as the protocol says. #165's suggested fix keeps the logical size already, for the scale's sake: this is the same state.

Found reading the phone trace taken for #199, 2026-11-18.

## Summary A configure's logical size becomes the swapchain's size as `ceil(logical * scale)`, and the viewport's destination is then worked back from that as `ceil(physical / scale)`. Wherever `logical * scale` is not a whole number, the second rounding lands one above the size the compositor configured. The surface is then one logical pixel wider and higher than asked and its buffer is shown slightly scaled. And when the compositor next configures the window at the size it now has, the same step is taken again: the window grows a pixel per configure, a swapchain each time, until it reaches a size where both roundings are exact. Line numbers refer to `c006519`. ## Details - `implementations/Crafter.Graphics-Window.cpp:1923-1926` (`xdg_surface_handle_configure`): `newWidth = ceil(pendingLogicalWidth * scale)`, and the same for the height. - `:784-788` (`RebuildSwapchain`): `wp_viewport_set_destination(ceil(width / scale), ceil(height / scale))`. - `:406`: the constructor does the second step on its arguments. fractional-scale-v1 has it the other way about: the destination is the surface's size, and the buffer's size is that times the scale ("For toplevel surfaces, the size is rounded halfway away from zero"). The two roundings done in 32-bit float, as the code does them, for the logical sizes 1 to 3000: at 1.5 every odd size comes out one larger, at 1.25 and 1.75 every size that is not a multiple of 4, at 2.85 all but 127 of them. At 1 and 2 none does. ## Concrete case A Fairphone 6 with Plasma Mobile 6.8.2 (KWin 6.8.2), scale 2.85, running imsd-messages 0.0.0's tree (ca5cd72, the library at c006519) under `WAYLAND_DEBUG=1`. The maximized window is configured 392 x 796: ``` [03:12:45.397716] xdg_toplevel#16.configure(392, 796, array[4]) [03:12:45.421256] -> wp_viewport#21.set_destination(393, 797) ``` 392 x 2.85 = 1117.2, so the buffer is 1118 wide; 1118 / 2.85 = 392.28, so the destination is 393. The surface is 393 x 797 where 392 x 796 was configured, and a buffer 1118 pixels wide is laid over 1120.05. Later in the same trace KWin configures the window at the size it now has, and each answer is one larger (the lines between are left out): ``` [03:13:24.613875] xdg_toplevel#16.configure(393, 797, array[8]) [03:13:24.618313] -> wp_viewport#21.set_destination(394, 798) [03:13:24.646890] xdg_toplevel#16.configure(394, 798, array[8]) [03:13:24.655157] -> wp_viewport#21.set_destination(395, 799) [03:13:24.672890] xdg_toplevel#16.configure(395, 799, array[8]) [03:13:24.673567] -> wp_viewport#21.set_destination(396, 800) [03:13:24.689235] xdg_toplevel#16.configure(396, 800, array[8]) [03:13:24.693924] -> wp_viewport#21.set_destination(397, 800) [03:13:24.722316] xdg_toplevel#16.configure(397, 800, array[8]) [03:13:24.727174] -> wp_viewport#21.set_destination(398, 800) [03:13:24.746577] xdg_toplevel#16.configure(398, 800, array[8]) [03:13:24.751471] -> wp_viewport#21.set_destination(399, 800) [03:13:24.767158] xdg_toplevel#16.configure(399, 800, array[8]) [03:13:24.771921] -> wp_viewport#21.set_destination(400, 800) [03:13:24.793058] xdg_toplevel#16.configure(400, 800, array[8]) [03:13:24.797760] -> wp_viewport#21.set_destination(400, 800) ``` Eight rebuilds in 184 ms. It stops at 400 x 800 because both roundings are exact there (2.85 x 400 = 1140, 2.85 x 800 = 2280). 2.6 s later KWin configured 392 x 796 again. A second trace of the same night, of an earlier build of the app on the same library commit, has the same run of configures from 392 x 796 to 400 x 800. Not looked into: what made KWin configure the window at its own size at those two moments, and whether the scaling of the buffer shows in the text. ## Suggested fix Keep the configured logical size as the window's state and send that as the destination, unchanged. Work out only the buffer's size from it, rounded as the protocol says. #165's suggested fix keeps the logical size already, for the scale's sake: this is the same state. Found reading the phone trace taken for #199, 2026-11-18.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Catcrafts/Crafter.Graphics#201
No description provided.