fix(wayland): round a configured size's pixels half away from zero, and work both sizes out exactly from the scale's 120ths
A size the compositor configured became the buffers' size as ceil(size * scale), in float. The protocol, as bundled in lib/fractional-scale-v1.h, has the buffer's size as the surface's times the scale, and says that "For toplevel surfaces, the size is rounded halfway away from zero": wherever the product's fraction is below a half, rounding up gave a pixel more than that.89111e0left this as the rest of #201, and the comment on #165 asks for it. And the sum was done in float, with the scale as a float, which a scale that is no whole number of eighths is not exactly: a product that is a whole number of pixels could come out just above it, and rounding up then went a pixel past it, as 50 at 1.2 came to 61. The other way, the surface's size for a window the application sized, ceil(pixels / scale), had the same trouble: 171 pixels at 2.85 came to 61, where they are 60. Window: ScaledPixels rounds half away from zero, and both it and SurfaceLength work in 64-bit integers from the 120ths the compositor sends: MatchSizesToScale from those of the scale the window draws at, which a new member, drawnScale_, keeps beside scale, as they are not preferredScale while a new scale waits, and the tests of whether a scale gives the window new pixels from preferredScale. SurfaceLength still rounds up, so that the surface of a window the application sized is no smaller than its pixels at the scale. ScaledPixels never gives less than one pixel: below a scale of a half a length of one rounds to none, where rounding up gave one, and a swapchain cannot be made 0 wide or high. Nor more than the largest 32-bit value, which a configured length can pass at a scale above 2 (2^30 at 4 comes to 2^32), where the cast to 32 bits would wrap it, to none in that case; and SurfaceLength stops at the largest int32, which a length worked out from 32-bit pixels can pass. The configure listener's test for a configure at the size the window has uses the same sum, so a configured size the window took is found to be the one it has, and so do the tests, in TakeDeferredSize after a present and in MatchSizesToScale, of whether a size or a scale comes to new pixels; and the listener tells that no new scale waits from the 120ths, preferredScale against drawnScale_, where61f2698compared the two scales as floats. So 392x796 at 2.85, the size in #201's phone trace, takes 1117x2269 pixels where it took 1118x2269. A window of 320x240 pixels at 1.75, shown at 183x138, takes 320x242 for a configure of that size, where it took 321x242. Docs: the consumer notes say how a configured size's pixels are rounded, and that the surface of a window the application sized is rounded up; the guide's gotchas, that both are worked out in integers from the 120ths; both, that the pixels are never fewer than one nor more than the largest 32-bit value, and that the surface's length never passes the largest int32. The gotcha and the interface's comment on logicalWidth give, as a reason not to work the surface's size back from the pixels, that a configured size worked back from them lands above itself wherever its product with the scale is not whole. That held while both roundings went up; now it lands above where that product has a fraction of a half or more, short of the 32-bit limits the two sums stop at, and both say so. Tests: ConfigureResize takes the new numbers in its cases of #201's trace and of the window at 1.75, and adds the protocol's own example (100x50 at 1.5 is 150x75), halves that go up (853x101 at 1.5 is 1280x152), fractions below a half that go down (101x853 at 1.25 is 126x1066, which rounding up made 127x1067), and whole numbers the sum in float came out above (50x25 at 1.2 is 60x30, which came to 61x31), each acknowledged in the listener when it is configured again; a configure of 1x300 at 0.4, whose width rounds to no pixel, taken as 1x120; a configure of 2^30x300 at 4, whose width is the largest 32-bit value, and pixels of that value at a half, whose surface is the largest int32 wide; and a window of 342x171 pixels at 2.85, whose surface is 120x60, which came to 121x61. And it works configured sizes into pixels and back with a window's own MatchSizesToScale: 853x101 at 1.5 comes back as 854x102, and 392x796 at 2.85 as 392x797. ResizeViewport works the pixels and the surface's size out as the window now does, and its comments say which way each is rounded.
This commit is contained in:
parent
61f2698d13
commit
e1b36b9257
6 changed files with 211 additions and 53 deletions
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue