fix(wayland): take a new preferred scale at a frame boundary, and convert input with the scale the window draws at
xdg_surface_handle_preferred_scale set Window::scale and did nothing
else (#165). The buffers' size and the surface's follow the scale only
where the window works one out from the other, which it did when it
made a swapchain and when a frame took a configured size. So a scale
that changed by itself, with no configure (the issue's case is a
window moved to an output of another scale), reached them only at the
next of those, and until then the window drew at the old scale. The
pointer's and the touches' positions are turned into pixels with
Window::scale, and the text input's caret back into surface-local
units with it, so those were converted with the new scale while the
frames were still drawn at the old one.
The issue suggests making the swapchain again in the listener. That
predates 89111e0, which moved the configure's rebuild out of its
listener into Render() for #199 and #200; the scale takes the same
way.
Window: the listener keeps the scale in a new member, preferredScale,
as wp_fractional_scale_v1 sends it, in 120ths, and Window::scale is
the scale the window draws at. MatchSizesToScale, where the window
works out the size it was not given from the one it was, sets it from
preferredScale where it takes a new scale, and nothing else in the
library sets it. TakeDeferredSize takes a preferredScale that is not
the scale the window draws at, at a frame boundary of Render(), as it
takes a configured size, and with one where one waits. A window the
compositor sized keeps its surface's size and takes the pixels for it
at the new scale, so Render() makes the swapchain again there and
onResize fires where those pixels differ. One the application sized
keeps its pixels and makes no swapchain, and its surface takes the
size they come to at the new scale, which the next frame sends with
its buffer (SendFrameSurfaceState). Before the start of the next frame
the scale is taken only with a swapchain made where it gives the
window new pixels: a window the compositor sized whose surface comes
to other pixels at it, as after a present or with the swapchain a
SetPresentMode makes outside a frame. Anywhere else it would change
only the conversions and the size the surface is to take, which goes
out with the next frame, and until that frame's commit the compositor
maps the surface, and the pointer and the touches on it, by the
destination it has: a click in between would be converted for a frame
not drawn yet, landing where the new scale puts it on the one drawn at
the old scale, and the onResize of a swapchain made for another reason
at the pixels the window has would not tell the application of the
scale. So a scale that leaves the pixels as they are waits for the
start of the next frame (for a window the application sized, whose
pixels are its own, and one the compositor sized that it leaves at its
pixels), also where a present mode, a rebuild that waited or a Resize
makes a swapchain before then, and so does a configured size that
comes to the pixels the window has with it (an output's scale changed
under a window that fills it). TakeDeferredSize and RebuildIfDeferred
are told which of the two boundaries they run at (FrameBoundary), and
MatchSizesToScale whether it takes the scale whatever it does to the
pixels (takeScale), as at a frame's start and in the constructor. The
listener sends no request and makes no Vulkan call, so the window goes
on drawing at the old scale, and converting with it, until then; a
scale that a listener of a frame dispatched is taken at the boundary
after its present where it gives the window new pixels, and at the
start of the next frame otherwise. From the window's first swapchain
on, the listener fires onFrameOwed where the scale is not the one the
window draws at, so that a window that draws on demand learns that a
frame is owed, as it does from a configure; for a window the
application sized no onResize comes. Before the first swapchain the
listener only keeps the scale, which the constructor takes before it
makes the swapchain, as it did. A scale of 0, with which no size can
be worked out, is not taken. Where MatchSizesToScale changes the
scale, it takes what the window holds in pixels of the scale before to
the new one: currentMousePos, lastMousePos and mouseDelta, and the
touch slots of the window's fingers. The compositor gives those in
surface-local units and sends nothing for a pointer or a finger that
rests, so a pointer resting over the window would otherwise stand at
the old scale's pixels in the frames drawn at the new one until it
moved, and the next delta would be the change of grid. The pointer's
position as the compositor gave it is kept beside, in surface-local
units, in a new member, surfaceMousePos, which no scale moves. And it
sends the caret SetTextInput was given again, converted with the new
scale, as the window does when the keyboard focus comes back: for a
window the application sized, the surface changes size around pixels
that stay, and the rectangle the input method holds would otherwise
stay in the old units.
The configure listener's test for a configure at the size the window
has compares the buffers with the pixels for that size at
preferredScale, the scale the frame takes with the size, as it
compared them at Window::scale while the listener set that. While a
new scale waits it finds no configure at the size the window has: one
for the size the surface has waits for the frame that takes the scale
and takes its size with it, so that the window is not made one the
compositor sized while it draws at the scale before, at pixels that
are not that size's at the scale it draws at.
Input: Map took its delta for MouseDeltaBind from currentMousePos and
a last position of its own, which the window's conversion does not
reach, so a pointer that rests would read the change of grid as a
delta at the Map's next Tick, which a camera bound to MouseDeltaBind
turns by. On Wayland it takes it from surfaceMousePos, as the
surface-local motion since its last Tick in the window's pixels of
now: none for a pointer that rests, whatever scales the window took in
between, where a last position taken along to each new scale would
come back with a float residue through two of them. A position the
application writes into currentMousePos itself does not reach it
there.
Device: the pointer's and the touches' handlers keep the position the
compositor gave in surfaceMousePos (the first finger's for the pointer
it stands in for), and touch_down, touch_motion and an enter's move
work it into the pixels they store with the scale in force at the
store. They store after listeners, of onTouchDown, onTouchMove and
onMouseEnter, that may take a new scale (a SetPresentMode outside a
frame for a window the compositor sized, the Render() of a frame
callback one of them dispatched), and a position worked out before
those listeners would be in the pixels of the scale before. The
conversions read Window::scale, which is now the scale of the frames
drawn since the boundary that took it.
Docs: the README, the consumer notes and the guide's gotchas say what
scale and preferredScale are and when a scale is taken; the first two
said that scale could be newer than the sizes (#165). The README, the
consumer notes and the comment on SetTextInput say what goes to the
new scale with it, and that the caret is sent again; the consumer
notes name surfaceMousePos, the Map's delta from it, and that a
position the application writes into currentMousePos does not reach
the Map. The bug-prover lens section names preferredScale as what
changes in any dispatch, and the scale among what waits for a frame
boundary, and that before the next frame's start it is taken only
where it gives the window new pixels; the consumer notes, that a size
configured during a frame waits with a new scale where the two come to
the pixels the window has.
Tests: ConfigureResize names the scale in 120ths, as the compositor
does, and drives the scale's listener on a window whose surfaces are
proxies. The listener sends nothing, leaves the scale and both sizes
as they are, and fires onFrameOwed. Until a frame boundary takes the
scale, a pointer motion to the surface's middle is at the middle of
the buffers drawn at the scale before, and so is a finger that goes
down there on the window the application sized; a caret given in the
pixels of the window the compositor sized goes to a text input proxy
converted with that scale. The next boundary takes it: a window the
compositor sized keeps 400x300 and goes from 800x600 to 600x450 pixels
at 1.5, which makes the swapchain, and its surface is sent nothing;
one the application sized keeps its 640x480 pixels and makes no
swapchain, and its surface goes from 320x240 to 640x480 at 1, sent
with the frame. After it the motion, the finger's move and the caret
are converted with the new scale. And before any new motion or call,
the boundary has taken what the window held to the new scale: the
pointer of the window the compositor sized is at the middle of the new
buffers, the one the first finger stands in for on the other window is
where its surface-local place comes to, a second finger that went down
before the boundary lifts after it where its surface-local place comes
to, and each boundary sends the caret again, converted, with no
SetTextInput. An Input::Map attached to the window and ticked across a
boundary that takes 1.5 reads no delta for a pointer that rests, and a
motion of 10 units after it as 15 pixels; ticked across two boundaries
between two Ticks on a window the compositor sized, 1.75 taken by a
swapchain made outside a frame at the pixels it gives the window and 1
again by a frame's start, with the pointer resting at surface 100.25,
it reads no delta and fires no event. On a window the compositor
sized, a listener of onTouchDown, of onTouchMove and of onMouseEnter
that takes a scale that waits has the click the finger stands in for,
the finger's move and the move after the enter in the pixels of that
scale. A scale that comes back before a frame owes nothing; one that
comes while a frame is being recorded leaves that frame at the scale
it began with, and the window the compositor sized takes it at the
boundary after the present, with its new pixels, where the one the
application sized takes it at the next frame's start: the boundary
after the present takes nothing, a motion after it is still at the
pixels of the frame on screen, and the caret is sent again only at the
next frame's start (the fixture steps the boundary after the present,
End, apart from the next frame's start, Begin); a configure that comes
with it to the pixels the window has waits for that start as well,
which takes the two together, the frame bringing the surface its size
and the acknowledgement, and so does a scale that leaves a small
window the compositor sized at its pixels; a configure without a size
while a scale waits is acknowledged in the listener, and one for the
size the surface has waits for the frame that takes the scale, also
where its pixels at that scale are the window's (101x101 pixels at 2,
a surface of 51x51, a scale of 237/120); before the first swapchain
the listener only keeps the scale, which MatchSizesToScale takes, and
a scale of 0 is not taken. In the cases there were, the check that
nothing is owed counts a scale that waits as well, the frame whose
scale changes while it is recorded is followed to the boundary that
takes it, a swapchain made between frames is checked to leave no scale
waiting for a window the compositor sized, and for one the application
sized to take none, a motion until the next frame's start landing at
the pixels of the frame on screen, also where the swapchain is made
after a present that found it out of date, with a configure that comes
with the scale to the window's pixels waiting too, and the case of a
scale and then a configure counts onFrameOwed for both. ResizeViewport
drives the scale against the compositor, where it has the fractional
scale and the viewporter: on its window as the application sized it,
and maximized where the compositor configures a size for that, it
calls the listener with a scale the window does not draw at and then
with the compositor's own. Each time it checks that the listener
rebuilds nothing and fires onFrameOwed, that the next Render() takes
the scale, with no swapchain and no onResize for the application's
size and with a new swapchain and one onResize from inside Render()
for the maximized one, and that a pointer motion to the surface's
middle is at the buffers' middle, to within the rounding of one size
from the other, before that Render() and after it, and that the
pointer, resting across that Render(), is where its surface-local
place comes to at the new scale. The log's checks hold each of those
commits to its buffer at the scales the marks name.
This commit is contained in:
parent
e1ca2fdb54
commit
61f2698d13
11 changed files with 1110 additions and 151 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -23,7 +23,7 @@
|
|||
// effect, to within one surface-local pixel at the window's scale (one
|
||||
// of the two is rounded from the other). Covers the window's first
|
||||
// frame, a Resize from the application with a commit before the next
|
||||
// frame, and a size the compositor configures
|
||||
// frame, a size the compositor configures, and the scales below
|
||||
// - Resize outside a frame still makes the swapchain at once and fires
|
||||
// onResize from the call
|
||||
// - every acknowledgement of a configure that asked for a size is
|
||||
|
|
@ -40,6 +40,21 @@
|
|||
// frame of the next one takes the size and answers it, without a call
|
||||
// to Render() from here. A compositor that held the callbacks back for
|
||||
// the acknowledgement would stall every window that updates that way
|
||||
// - a scale the compositor asks for by itself (#165), given by calling
|
||||
// the fractional scale's listener as its event would, first with a
|
||||
// scale the window does not draw at and then with the compositor's own
|
||||
// again: the listener rebuilds nothing, leaves the scale the window
|
||||
// draws at, and fires onFrameOwed, and the next Render() takes the
|
||||
// scale. Before that Render() and after it a pointer motion to the
|
||||
// surface's middle is at the middle of the buffers the window draws
|
||||
// at, to within the rounding of one size from the other, and the
|
||||
// pointer that rests across it is where its surface-local place comes
|
||||
// to at the new scale. The window the application sized keeps its
|
||||
// pixels, makes no swapchain and fires
|
||||
// no onResize, and its surface takes the size they come to with that
|
||||
// frame; maximized, the window the compositor sized keeps its surface's
|
||||
// size and gets the swapchain made at the new pixels, firing onResize
|
||||
// once from inside Render()
|
||||
// - the compositor raises no protocol error over any of it, and the
|
||||
// validation layer no error (only with CRAFTER_GRAPHICS_VALIDATION set)
|
||||
//
|
||||
|
|
@ -55,8 +70,10 @@
|
|||
// does for a driver whose buffers' sizes are not in the log, for a
|
||||
// compositor without wp_viewporter, where a surface is as large as its
|
||||
// buffer, and for the frame loop's step where the window gets no frame
|
||||
// callbacks to begin with (a locked session, a screen that is off). The
|
||||
// log is kept when a check fails.
|
||||
// callbacks to begin with (a locked session, a screen that is off). So it
|
||||
// does for the scale's steps where the compositor has no fractional scale,
|
||||
// whose listener the test then does not call. The log is kept when a check
|
||||
// fails.
|
||||
//
|
||||
// `ResizeViewport --keyboard` is the manual probe for a phone, and the case
|
||||
// #199 was found in: it asks for text input (Window::SetTextInput) and takes
|
||||
|
|
@ -320,6 +337,28 @@ std::uint32_t Pixels(std::int32_t logical, float scale) {
|
|||
return static_cast<std::uint32_t>(std::ceil(logical * scale));
|
||||
}
|
||||
|
||||
// As the window works out the surface-local length its pixels come to,
|
||||
// for a window the application sized.
|
||||
std::int32_t SurfaceLength(std::uint32_t pixels, float scale) {
|
||||
return static_cast<std::int32_t>(std::ceil(pixels / scale));
|
||||
}
|
||||
|
||||
// Whether a pointer motion to the middle of the window's surface, as the
|
||||
// compositor reports it in surface-local units, is at the middle of its
|
||||
// buffers. One size is rounded from the other, which puts up to half the
|
||||
// scale (or half a pixel) between the two middles. focusedWindow is the
|
||||
// window for the call alone: what the compositor's own pointer events set it
|
||||
// to is put back.
|
||||
bool MotionAtMiddle(Window& window) {
|
||||
Window* const focused = Device::focusedWindow;
|
||||
Device::focusedWindow = &window;
|
||||
Device::PointerListenerHandleMotion(nullptr, nullptr, 0, wl_fixed_from_double(window.logicalWidth / 2.0),
|
||||
wl_fixed_from_double(window.logicalHeight / 2.0));
|
||||
Device::focusedWindow = focused;
|
||||
const float slack = std::max(0.5f, window.scale / 2.0f) + 0.01f;
|
||||
return std::abs(window.currentMousePos.x - window.width / 2.0f) <= slack && std::abs(window.currentMousePos.y - window.height / 2.0f) <= slack;
|
||||
}
|
||||
|
||||
// Dispatches until `done`, for at most `limit`. False when the display fails.
|
||||
template <class Done>
|
||||
bool Pump(Done&& done, std::chrono::milliseconds limit) {
|
||||
|
|
@ -377,6 +416,77 @@ Scenario Drive(bool keyboard) {
|
|||
Mark("frames", window.scale);
|
||||
};
|
||||
|
||||
// #165: a scale the compositor asks for by itself, with no configure, as
|
||||
// when the window goes to an output of another scale. The test cannot
|
||||
// move the window, so it calls the fractional scale's listener as that
|
||||
// event would, with a scale the window does not draw at, and then with
|
||||
// the compositor's own again. Each time the listener rebuilds nothing
|
||||
// and fires onFrameOwed, and the next Render() takes the scale: a window
|
||||
// the compositor sized keeps its surface's size and gets the swapchain
|
||||
// made at new pixels, with onResize from inside Render(); one the
|
||||
// application sized keeps its pixels, and its surface takes the size
|
||||
// they come to with that frame. The log's checks below hold every
|
||||
// commit of it to its buffer at the scales the marks name.
|
||||
const auto rescale = [&](std::string_view step) {
|
||||
if (window.wp_scale == nullptr) {
|
||||
std::println("SKIP the compositor offers no fractional scale (or no viewporter), so a scale was not driven for {}", step);
|
||||
return;
|
||||
}
|
||||
const std::uint32_t own = window.preferredScale;
|
||||
for (const std::uint32_t to : { own == 120 ? 210u : 120u, own }) {
|
||||
const float scaleBefore = window.scale;
|
||||
const std::uint32_t widthBefore = window.width;
|
||||
const std::uint32_t heightBefore = window.height;
|
||||
const std::int32_t logicalWidthBefore = window.logicalWidth;
|
||||
const std::int32_t logicalHeightBefore = window.logicalHeight;
|
||||
const std::uint64_t generation = window.swapchainGeneration;
|
||||
const int resizesBefore = resizesInRender + resizesElsewhere;
|
||||
const int inRenderBefore = resizesInRender;
|
||||
const int owedBefore = owed;
|
||||
const float scale = to / 120.0f;
|
||||
Mark(std::format("scale-{}", step), window.scale);
|
||||
Window::xdg_surface_handle_preferred_scale(&window, window.wp_scale, to);
|
||||
Check(owed == owedBefore + 1, std::format("{}: a scale of {} from the compositor fires onFrameOwed", step, scale));
|
||||
Check(window.scale == scaleBefore && window.width == widthBefore && window.height == heightBefore
|
||||
&& window.logicalWidth == logicalWidthBefore && window.logicalHeight == logicalHeightBefore
|
||||
&& window.swapchainGeneration == generation && resizesInRender + resizesElsewhere == resizesBefore,
|
||||
std::format("and its listener leaves the window at {}x{} drawn at {}, and the swapchain alone", window.width, window.height, window.scale));
|
||||
Check(MotionAtMiddle(window), std::format("until a frame takes the scale, a motion to the surface's middle is at the middle of the buffers drawn at {} ({},{})",
|
||||
window.scale, window.currentMousePos.x, window.currentMousePos.y));
|
||||
render(1);
|
||||
Check(window.scale == scale, std::format("the next Render() takes the scale ({})", window.scale));
|
||||
// The pointer rests where the motion before the Render() put it,
|
||||
// at the middle of the surface as it was: what the window holds
|
||||
// of it went to the new scale with no new motion.
|
||||
const float restX = logicalWidthBefore / 2.0f * scale;
|
||||
const float restY = logicalHeightBefore / 2.0f * scale;
|
||||
Check(std::abs(window.currentMousePos.x - restX) <= 0.01f && std::abs(window.currentMousePos.y - restY) <= 0.01f,
|
||||
std::format("the pointer, which has not moved, is at ({},{}), where that surface-local place comes to at {} ({},{})",
|
||||
window.currentMousePos.x, window.currentMousePos.y, scale, restX, restY));
|
||||
Check(MotionAtMiddle(window), std::format("and from there that motion is at the middle of the {}x{} buffers ({},{})",
|
||||
window.width, window.height, window.currentMousePos.x, window.currentMousePos.y));
|
||||
if (window.logicalConfigured) {
|
||||
Check(window.logicalWidth == logicalWidthBefore && window.logicalHeight == logicalHeightBefore
|
||||
&& window.width == Pixels(logicalWidthBefore, scale) && window.height == Pixels(logicalHeightBefore, scale),
|
||||
std::format("a window the compositor sized keeps its surface's {}x{} and takes the pixels for it ({}x{})",
|
||||
window.logicalWidth, window.logicalHeight, window.width, window.height));
|
||||
Check(window.swapchainGeneration != generation && resizesInRender == inRenderBefore + 1
|
||||
&& resizesInRender + resizesElsewhere == resizesBefore + 1,
|
||||
"makes the swapchain at them, and fires onResize once, from inside Render()");
|
||||
} else {
|
||||
Check(window.width == widthBefore && window.height == heightBefore && window.swapchainGeneration == generation
|
||||
&& resizesInRender + resizesElsewhere == resizesBefore,
|
||||
std::format("a window the application sized keeps its {}x{} pixels: no swapchain is made, and onResize does not fire", window.width, window.height));
|
||||
Check(window.logicalWidth == SurfaceLength(widthBefore, scale) && window.logicalHeight == SurfaceLength(heightBefore, scale)
|
||||
&& window.sentLogicalWidth == window.logicalWidth && window.sentLogicalHeight == window.logicalHeight,
|
||||
std::format("and its surface takes the {}x{} they come to, sent with that frame", window.logicalWidth, window.logicalHeight));
|
||||
}
|
||||
Check(window.presentedGeneration == window.swapchainGeneration && window.scale == window.preferredScale / 120.0f,
|
||||
"after that frame nothing is owed");
|
||||
render(Window::numFrames * 2);
|
||||
}
|
||||
};
|
||||
|
||||
// The first frames, and whatever the compositor has to say of the new
|
||||
// window (the decoration's configure, the scale).
|
||||
render(Window::numFrames * 2);
|
||||
|
|
@ -427,6 +537,7 @@ Scenario Drive(bool keyboard) {
|
|||
wl_surface_commit(window.surface);
|
||||
render(Window::numFrames * 2);
|
||||
}
|
||||
rescale("a window the application sized");
|
||||
|
||||
// A size from the compositor. Asking to be maximized gets one where the
|
||||
// compositor has floating windows.
|
||||
|
|
@ -477,6 +588,7 @@ Scenario Drive(bool keyboard) {
|
|||
Check(!window.unackedConfigure && window.deferredLogicalWidth == 0 && window.presentedGeneration == window.swapchainGeneration,
|
||||
"after that frame nothing is owed");
|
||||
render(Window::numFrames * 2);
|
||||
rescale("a window the compositor sized");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue