fix(wayland): the surface takes a new size with the first frame drawn at it, and a configure's rebuild waits for Render
At a resize RebuildSwapchain sent wp_viewport.set_destination for the new size at once, and the configure listener, which had called it, acknowledged the configure and committed the surface. The destination is the surface's size, and it is state the next wl_surface.commit applies whatever buffer is attached then. That commit was the listener's, or the one a consumer makes to ask for a frame callback, and it put the old frame at the new size, where it stayed until the consumer's next frame brought a buffer of that size (#199). The acknowledgement named that commit as the answer to the configure. And the rebuild ran inside libwayland's dispatch: the consumer's loop stood still in it, each new size before a frame cost a swapchain, and a Vulkan error there was thrown from inside the dispatch, where the `try` a consumer has around Update() does not cover it (#200). Window: the configure listener keeps a new size (deferredLogicalWidth and Height, surface-local) and, where a frame is owed, the serial (unackedConfigure), and makes no Vulkan call. Render() takes what waits at its two boundaries (RebuildIfDeferred) and makes the swapchain again where that calls for one: first thing, for what came since the last frame, and after its present, as before, for what its listeners and the present asked for, and now for a size configured while they ran. Right before its present a frame sends what the surface is to take with its buffer (SendFrameSurfaceState): the destination, when the surface's size is not the one last sent (sentLogicalWidth and Height), and the acknowledgement of the configure it answers, the last one when several came. The present's commit then applies them together with the buffer. The constructor sends no destination: the window's first frame does. The surface's size is state of the window for that, beside the buffers' (logicalWidth and Height; logicalConfigured says which of the two sizes the window was given). TakeDeferredSize makes a configured size the surface's, unchanged, and works the pixels out of it with the scale of that moment. MatchSizesToScale does the same before every swapchain is made, and for a window the application sized (the constructor's size, Resize) works the surface's size out of the pixels, which is what RebuildSwapchain and the constructor did when they sent the destination. The destination is that state as it is and not ceil(width / scale) at the present, because the scale is the compositor's to change in any dispatch: between a configure and the frame that takes it, and in the middle of a frame, when a listener reads the clipboard or makes a window. And a size and a scale that change together can come to the pixels the swapchain has: then no swapchain is made, and the frame still brings the surface its size with the acknowledgement. With that the destination of a configured size is the size itself, where it was worked back from the pixels and could come out larger (392x796 at 2.85 came back as 393x797), and a configure at the size the surface has leaves a window the compositor sized alone while the scale stays what it was, where it could make the window grow again (#201). A window the application sized, configured at the size its surface has, takes the pixels for that size once where its own do not come to it (320x240 at 1.75, shown at 183x138, becomes 321x242), and is then left alone in the same way. That much of #201 comes with this change, since the state it asks for is the one this needs. The buffers' size is still rounded up, where the protocol rounds half away from zero: the rest of #201. A swapchain RebuildSwapchain made for another reason after the scale changed (a present mode, a present that found the swapchain out of date) applied the new scale by working the destination out again from the pixels. It still does for a window the application sized. A window the compositor sized keeps the surface's size and takes the pixels for it. The acquire's OUT_OF_DATE path repeated four of RebuildSwapchain's lines and sent no destination: it calls RebuildSwapchain now, and so settles the two sizes as the other rebuilds do. Of a Resize and a configured size the one asked for last is taken, as when the listener resized on the spot: a configure with a size clears a Resize that waits for its frame's present, also when its size is the one the window has, and Resize clears a configured size that waits. A configure that asks for nothing new while nothing is owed is acknowledged in the listener, as before. One that comes while a size waits, or while the surface does not show the window as it is (a swapchain still to be made, one that has presented no frame yet, a size not sent yet), waits for that frame. One for the size the window has, when nothing else is owed, is acknowledged at once and takes the wait away with it, as an acknowledgement of a serial older than the last is a protocol error. A frame being recorded when a size comes does not acknowledge it while that size waits; when a Resize later in the frame takes the size's place, that frame does. The listener still commits, which applies whatever else is pending on the surface, such as a request for a frame callback that StartUpdate made after a frame. For consumers: onResize for a compositor's resize fires from inside Render(), before the onUpdate of the frame that brings the size, with the queue idle and no frame being recorded, as Resize fires it; until that frame the window keeps its old size on screen. A window that draws on demand took onResize as its cue to ask for a frame, and gets onFrameOwed for it: the Wayland backend's alone, fired from the configure after onToplevelState, and only for a window that is still there after that event's listeners, whenever the configure leaves a frame owed. A size the surface does not have yet that comes to the pixels the window has (the scale changed with it) fires onFrameOwed and no onResize. Resize and SetPresentMode outside a frame rebuild at once as they did, and there too the surface takes the new size with the next frame. A rebuild that throws stays pending, since RebuildSwapchain clears swapchainRebuildPending only once the swapchain is made, and the next Render() tries it again. The README, the consumer notes and the guide's gotchas say so, and the bug-prover lens section lists the pending surface state and the scale among the re-entry contexts. Examples: InputSystem and the native mains of VulkanTriangle, RTVolume and Sponza drew one frame and then only ran the event loop, so nothing would have answered a compositor's resize of their windows. They call StartUpdate after that frame, as the examples that draw every frame do. Not changed: a scale that changes by itself still reaches the buffers and the surface only with the next swapchain or the next configured size (#165); the first configure's size (#166); and Win32's WM_SIZE, which still rebuilds from the window procedure. A window under StartUpdate on the compositor's clock still draws from its frame callback, so for it the rebuild, like every frame's Vulkan call, stays inside libwayland's dispatch; one on its own clock is updated by StartSync's loop after the dispatch, as before. #200 is answered for a consumer that calls Update() itself. A present that fails after SendFrameSurfaceState leaves what that sent pending for the surface's next commit, whoever makes it. Tests: ConfigureResize feeds the configure callbacks of a window whose surfaces are proxies on a wl_display over a socketpair, as ToplevelState does, with a made-up swapchain handle and no device, steps the two ends of a frame, and reads the requests off the wire: a configure for a new size sends one bare commit; the frame sends the destination and the acknowledgement before its present, once; several configures before a frame cost one of each, of the last serial; a configure for nothing new, or back to the window's size, is acknowledged in the listener, and the serial that waited never is; a frame being recorded when a size comes does not acknowledge it while the size waits, and does once a Resize has taken its place; the window's first frame and the first at any new size of the surface bring the destination, and a configure before it waits, and so does one for the size a rebuild that threw is still pending for, and one that comes after a present that found the swapchain out of date, whose surface state is not sent a second time; without a viewport the acknowledgement still waits. The destination is the configured size when the scale changes before the frame, when it changes between the frame's start and its present, and when the size and the scale together come to the swapchain's pixels, in either order of the two events, which makes no swapchain; with the numbers of #201's trace, 392x796 at 2.85, it is that size, and three more configures at it change nothing. A swapchain made after the scale changed keeps a configured window's surface size and an application-sized window's pixels. Of a Resize and a configured size the later one is taken, also when it is the size the window has. onFrameOwed fires after onToplevelState and not for a window its listener destroyed; every acknowledgement names a later serial than the one before. ResizeViewport runs a window against the compositor with WAYLAND_DEBUG set and stderr in a file, and replays the log, which has the driver's attach and commit too: at every commit the destination in effect belongs to the buffer in effect, to within a surface-local pixel, and every acknowledgement of a configure that asked for a size, once the surface has a buffer, is committed with a buffer of that size in effect and with that size itself as the destination, through a Resize with a commit before the next frame, a size the compositor configures (the window asks to be maximized), and one it configures while the frame loop of StartUpdate runs (the window asks to be restored), which that loop takes and answers by itself. Where the compositor configures no other size at that request, the step is a SKIP, and the test holds the log to it: no configure for another size came. `ResizeViewport --keyboard` is the manual probe for a phone: it asks for text input and takes it back three times (SetTextInput), which is what brings a phone's on-screen keyboard up and down, and holds the resizes that makes to the same checks.
This commit is contained in:
parent
c006519fa0
commit
89111e0d65
14 changed files with 2059 additions and 71 deletions
|
|
@ -383,7 +383,8 @@ Window::Window(std::uint32_t width, std::uint32_t height) : width(width), height
|
|||
// the buffer at width/scale x height/scale, so without a viewporter there
|
||||
// is no fractional scale either: scale stays 1, the surface is as large as
|
||||
// its buffer, and the compositor scales it up on a HiDPI output. A scale
|
||||
// that changes after this is applied only by the next resize (#165).
|
||||
// that changes after this is applied only by the next swapchain, or by
|
||||
// the next size the compositor configures (#165).
|
||||
if (Device::fractionalScaleManager != nullptr && Device::wpViewporter != nullptr) {
|
||||
wp_scale = wp_fractional_scale_manager_v1_get_fractional_scale(Device::fractionalScaleManager, surface);
|
||||
wp_fractional_scale_v1_add_listener(wp_scale, &wp_fractional_scale_v1_listener, this);
|
||||
|
|
@ -401,10 +402,15 @@ Window::Window(std::uint32_t width, std::uint32_t height) : width(width), height
|
|||
zxdg_toplevel_decoration_v1_set_mode(decoration, ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE);
|
||||
}
|
||||
|
||||
// The viewport's destination is not set here: it is the size the surface
|
||||
// takes with a buffer, so the window's first frame brings it
|
||||
// (SendFrameSurfaceState). What it is to be is settled now, from the
|
||||
// constructor's size in pixels and the scale the compositor has named so
|
||||
// far, as it used to be sent from here.
|
||||
if (Device::wpViewporter != nullptr) {
|
||||
wpViewport = wp_viewporter_get_viewport(Device::wpViewporter, surface);
|
||||
wp_viewport_set_destination(wpViewport, std::ceil(width/scale), std::ceil(height/scale));
|
||||
}
|
||||
MatchSizesToScale();
|
||||
|
||||
wl_surface_commit(surface);
|
||||
#endif
|
||||
|
|
@ -743,9 +749,19 @@ void Window::PointerScroll(double detents) {
|
|||
}
|
||||
|
||||
void Window::Resize(std::uint32_t newWidth, std::uint32_t newHeight) {
|
||||
// Skip degenerate resizes. Win32 minimised windows give (0, 0); Wayland
|
||||
// sometimes echoes the current size in a configure.
|
||||
// Skip degenerate resizes: Win32 minimised windows give (0, 0). A
|
||||
// Wayland configure does not come through here: its size waits for the
|
||||
// next Render() (xdg_surface_handle_configure).
|
||||
if (newWidth == 0 || newHeight == 0) return;
|
||||
#ifdef CRAFTER_GRAPHICS_WINDOW_WAYLAND
|
||||
// The last size asked for wins, whoever asked. A size the compositor
|
||||
// configured that still waits for its frame gives way to this later
|
||||
// one, the size the window has included, as it did when the configure's
|
||||
// listener resized on the spot and this call came after it. The
|
||||
// configure's serial goes on waiting for a frame.
|
||||
deferredLogicalWidth = 0;
|
||||
deferredLogicalHeight = 0;
|
||||
#endif
|
||||
// A listener of the frame being recorded asked: the rest of that frame
|
||||
// still draws into an image of the current swapchain at the current
|
||||
// size, so the size changes once the frame has been presented. The last
|
||||
|
|
@ -768,28 +784,110 @@ void Window::Resize(std::uint32_t newWidth, std::uint32_t newHeight) {
|
|||
|
||||
width = newWidth;
|
||||
height = newHeight;
|
||||
#ifdef CRAFTER_GRAPHICS_WINDOW_WAYLAND
|
||||
// The application's size, in pixels: the surface's follows from it.
|
||||
logicalConfigured = false;
|
||||
#endif
|
||||
RebuildSwapchain();
|
||||
}
|
||||
|
||||
void Window::RebuildSwapchain() {
|
||||
// Configure handlers and WM_SIZE run between frames, and a frame that
|
||||
// asked waited for its present, but frames may still be in flight: none
|
||||
// may still use the old swapchain.
|
||||
// Pending from here until the swapchain is made, whoever called: a
|
||||
// rebuild that throws below is then tried again by the next Render().
|
||||
swapchainRebuildPending = true;
|
||||
// WM_SIZE and a Resize or SetPresentMode from outside a frame run
|
||||
// between frames, and what a frame or a configure asked for waited for a
|
||||
// frame boundary (RebuildIfDeferred), but frames may still be in flight:
|
||||
// none may still use the old swapchain.
|
||||
Device::CheckVkResult(vkQueueWaitIdle(Device::queue));
|
||||
// The queue is idle, so every deferred resource is now safe to free
|
||||
// regardless of its retire frame (issue #101).
|
||||
Device::DrainDeletions();
|
||||
|
||||
#ifdef CRAFTER_GRAPHICS_WINDOW_WAYLAND
|
||||
if (wpViewport) {
|
||||
wp_viewport_set_destination(wpViewport,
|
||||
static_cast<int>(std::ceil(width / scale)),
|
||||
static_cast<int>(std::ceil(height / scale)));
|
||||
// The buffers' size and the surface's, from the scale of this moment.
|
||||
// The surface itself is told nothing here. Its size is the viewport's
|
||||
// destination, which the next commit applies whatever buffer is attached
|
||||
// then: sent now, the old frame would be shown scaled to the new size
|
||||
// until the first new one (#199). SendFrameSurfaceState sends it with
|
||||
// that frame.
|
||||
MatchSizesToScale();
|
||||
#endif
|
||||
RecreateSwapchainAndImages();
|
||||
// Made, so nothing waits. Cleared only here: a rebuild that threw above
|
||||
// still waits, and the next Render() tries it again instead of drawing
|
||||
// into a swapchain whose views CreateSwapchain has already destroyed.
|
||||
// And before the listeners, which may render, or ask for another.
|
||||
swapchainRebuildPending = false;
|
||||
onResize.Invoke();
|
||||
}
|
||||
|
||||
#ifdef CRAFTER_GRAPHICS_WINDOW_WAYLAND
|
||||
namespace {
|
||||
// The pixels a surface-local length takes at `scale`, as a size the
|
||||
// compositor configured becomes the swapchain's. Rounded up, in float,
|
||||
// where fractional-scale-v1 rounds half away from zero: that much of
|
||||
// #201 is as it was.
|
||||
std::uint32_t ScaledPixels(std::int32_t logical, float scale) {
|
||||
return static_cast<std::uint32_t>(std::ceil(logical * scale));
|
||||
}
|
||||
|
||||
// The other way: the surface-local length `pixels` come to at `scale`,
|
||||
// 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));
|
||||
}
|
||||
}
|
||||
|
||||
void Window::MatchSizesToScale() {
|
||||
if (logicalConfigured) {
|
||||
width = ScaledPixels(logicalWidth, scale);
|
||||
height = ScaledPixels(logicalHeight, scale);
|
||||
} else {
|
||||
logicalWidth = SurfaceLength(width, scale);
|
||||
logicalHeight = SurfaceLength(height, scale);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
bool Window::TakeDeferredSize() {
|
||||
const std::uint32_t widthBefore = width;
|
||||
const std::uint32_t heightBefore = height;
|
||||
if (deferredWidth != 0) {
|
||||
width = deferredWidth;
|
||||
height = deferredHeight;
|
||||
deferredWidth = 0;
|
||||
deferredHeight = 0;
|
||||
#ifdef CRAFTER_GRAPHICS_WINDOW_WAYLAND
|
||||
// The application's size, in pixels: the surface's follows from it
|
||||
// at the rebuild. Asking for the size the window has changes
|
||||
// nothing, as in Resize.
|
||||
if (width != widthBefore || height != heightBefore) logicalConfigured = false;
|
||||
#endif
|
||||
}
|
||||
#ifdef CRAFTER_GRAPHICS_WINDOW_WAYLAND
|
||||
// The compositor's size, when that is what waits (Resize and the
|
||||
// configure's listener each clear the other's): the surface's size from
|
||||
// here on, unchanged, and the pixels for it at the scale of this moment.
|
||||
// Those may be the pixels the swapchain has, where the scale changed
|
||||
// with the size. Then nothing is rebuilt, and the frame still brings the
|
||||
// surface its new size.
|
||||
if (deferredLogicalWidth != 0) {
|
||||
logicalWidth = deferredLogicalWidth;
|
||||
logicalHeight = deferredLogicalHeight;
|
||||
logicalConfigured = true;
|
||||
deferredLogicalWidth = 0;
|
||||
deferredLogicalHeight = 0;
|
||||
MatchSizesToScale();
|
||||
}
|
||||
#endif
|
||||
return width != widthBefore || height != heightBefore;
|
||||
}
|
||||
|
||||
RecreateSwapchainAndImages();
|
||||
onResize.Invoke();
|
||||
void Window::RebuildIfDeferred() {
|
||||
// The sizes are taken before the rebuild, so an onResize listener that
|
||||
// renders finds none waiting.
|
||||
if (TakeDeferredSize() || swapchainRebuildPending) RebuildSwapchain();
|
||||
}
|
||||
|
||||
void Window::RecreateSwapchainAndImages() {
|
||||
|
|
@ -1297,6 +1395,15 @@ namespace {
|
|||
}
|
||||
|
||||
void Window::Render() {
|
||||
// A rebuild that waited for a frame boundary and came since the last
|
||||
// one: on Wayland the size the compositor configured, which its listener
|
||||
// only keeps (#199, #200), and a rebuild that threw. Here, not in that
|
||||
// listener, a consumer that calls Update() itself has its `try` around
|
||||
// it cover the Vulkan calls, and configures that came since the last
|
||||
// frame cost one rebuild between them. onResize fires from it, with the
|
||||
// queue idle and no frame being recorded, as it does from Resize.
|
||||
RebuildIfDeferred();
|
||||
|
||||
// This frame's slot among the numFrames in flight. Its command buffer,
|
||||
// descriptor-heap copy and acquire semaphore were last used numFrames
|
||||
// frames ago: wait for that submission's fence before touching any of
|
||||
|
|
@ -1317,10 +1424,7 @@ void Window::Render() {
|
|||
VkResult acquire = vkAcquireNextImageKHR(Device::device, swapChain, UINT64_MAX,
|
||||
imageAcquired, (VkFence)nullptr, ¤tImage);
|
||||
if (acquire == VK_ERROR_OUT_OF_DATE_KHR) {
|
||||
Device::CheckVkResult(vkQueueWaitIdle(Device::queue));
|
||||
Device::DrainDeletions();
|
||||
RecreateSwapchainAndImages();
|
||||
onResize.Invoke();
|
||||
RebuildSwapchain();
|
||||
acquire = vkAcquireNextImageKHR(Device::device, swapChain, UINT64_MAX,
|
||||
imageAcquired, (VkFence)nullptr, ¤tImage);
|
||||
}
|
||||
|
|
@ -1489,6 +1593,16 @@ void Window::Render() {
|
|||
|
||||
presentInfo.pWaitSemaphores = &renderFinishedSemaphores[currentImage];
|
||||
|
||||
#ifdef CRAFTER_GRAPHICS_WINDOW_WAYLAND
|
||||
// The present attaches this frame's buffer and commits the surface. What
|
||||
// the surface is to take with that buffer goes right before it, so that
|
||||
// one commit applies all of it: the surface's size, where this frame is
|
||||
// the first drawn for it, and the acknowledgement of the configure the
|
||||
// frame answers (#199). Nothing between here and the present commits the
|
||||
// surface.
|
||||
SendFrameSurfaceState();
|
||||
#endif
|
||||
|
||||
VkResult result = vkQueuePresentKHR(Device::queue, &presentInfo);
|
||||
// The frame is handed over: a swapchain rebuild may go ahead now.
|
||||
recording = false;
|
||||
|
|
@ -1498,6 +1612,19 @@ void Window::Render() {
|
|||
} else {
|
||||
Device::CheckVkResult(result);
|
||||
}
|
||||
#ifdef CRAFTER_GRAPHICS_WINDOW_WAYLAND
|
||||
// The surface shows this swapchain from here, unless the present found
|
||||
// it out of date and queued nothing. What SendFrameSurfaceState sent is
|
||||
// with the compositor all the same then, pending until the surface's
|
||||
// next commit. That is the first frame of the swapchain made below,
|
||||
// unless a commit that is no frame's comes before it (the configure
|
||||
// listener's, a consumer's request for a frame callback), which would
|
||||
// show the last buffer at the new size after all: nothing sent can be
|
||||
// taken back, and the present is where the driver commits.
|
||||
if (result != VK_ERROR_OUT_OF_DATE_KHR) {
|
||||
presentedGeneration = swapchainGeneration;
|
||||
}
|
||||
#endif
|
||||
// No vkQueueWaitIdle in the steady-state path: per-frame fences now gate
|
||||
// command-buffer reuse, so the CPU is free to acquire/record frame N+1
|
||||
// while the GPU is still executing frame N.
|
||||
|
|
@ -1515,23 +1642,12 @@ void Window::Render() {
|
|||
}
|
||||
|
||||
// The rebuild the frame held back: the present's, or a Resize or
|
||||
// SetPresentMode from one of its listeners. RebuildSwapchain drains the
|
||||
// queue (the only other wait-idles are Resize's and SetPresentMode's own
|
||||
// and the acquire's OUT_OF_DATE path) and fires onResize before the next
|
||||
// SetPresentMode from one of its listeners, or on Wayland a size
|
||||
// configured while they ran (a listener that dispatches events).
|
||||
// RebuildSwapchain drains the queue and fires onResize before the next
|
||||
// frame; the wait also leaves every per-frame fence signaled, so the next
|
||||
// Render()'s fence wait passes through.
|
||||
bool rebuild = swapchainRebuildPending;
|
||||
if (deferredWidth != 0) {
|
||||
rebuild = rebuild || deferredWidth != width || deferredHeight != height;
|
||||
width = deferredWidth;
|
||||
height = deferredHeight;
|
||||
deferredWidth = 0;
|
||||
deferredHeight = 0;
|
||||
}
|
||||
if (rebuild) {
|
||||
swapchainRebuildPending = false;
|
||||
RebuildSwapchain();
|
||||
}
|
||||
RebuildIfDeferred();
|
||||
}
|
||||
|
||||
#ifdef CRAFTER_TIMING
|
||||
|
|
@ -1908,30 +2024,97 @@ void Window::xdg_toplevel_handle_close(void* data, xdg_toplevel*) {
|
|||
|
||||
void Window::xdg_surface_handle_configure(void* data, xdg_surface* xdg_surface, std::uint32_t serial) {
|
||||
Window* window = reinterpret_cast<Window*>(data);
|
||||
// The compositor configures our surface, acknowledge the configure event
|
||||
xdg_surface_ack_configure(xdg_surface, serial);
|
||||
|
||||
// The size this batch asks for. The listener only keeps it: the next
|
||||
// Render() makes the swapchain again (RebuildIfDeferred) and answers the
|
||||
// configure with its frame. Rebuilt here, a Vulkan error would be thrown
|
||||
// through libwayland's dispatch (#200), the consumer's loop would stand
|
||||
// still in it for the rebuild, and each of several configures before a
|
||||
// frame would cost one. (0, 0) means the compositor has no preference,
|
||||
// and a size that waited goes on waiting. Before the swapchain exists a
|
||||
// configure's size is not taken (the first configure's, #166).
|
||||
const bool hasSwapchain = window->configured && window->swapChain != VK_NULL_HANDLE;
|
||||
if (hasSwapchain && window->pendingLogicalWidth > 0 && window->pendingLogicalHeight > 0) {
|
||||
// The last size asked for wins, whoever asked: a Resize from a
|
||||
// listener of the frame being recorded, which waits for that frame's
|
||||
// present, gives way to this later one, as it did when this listener
|
||||
// called Resize itself.
|
||||
window->deferredWidth = 0;
|
||||
window->deferredHeight = 0;
|
||||
// The size the window has means that nothing waits any more,
|
||||
// whatever did. It has it when the surface's size is this one and
|
||||
// the buffers are the pixels for it at the scale of now: a scale
|
||||
// that changed since they were made has the frame make them again,
|
||||
// and a size that only comes to the same pixels as the one before
|
||||
// (the scale changed with it) is still another size for the surface.
|
||||
const bool current = window->pendingLogicalWidth == window->logicalWidth
|
||||
&& window->pendingLogicalHeight == window->logicalHeight
|
||||
&& ScaledPixels(window->pendingLogicalWidth, window->scale) == window->width
|
||||
&& ScaledPixels(window->pendingLogicalHeight, window->scale) == window->height;
|
||||
window->deferredLogicalWidth = current ? 0 : window->pendingLogicalWidth;
|
||||
window->deferredLogicalHeight = current ? 0 : window->pendingLogicalHeight;
|
||||
// And the size is the compositor's from here, also where the
|
||||
// application's pixels had come to it.
|
||||
if (current) window->logicalConfigured = true;
|
||||
}
|
||||
|
||||
// An acknowledgement says that the next commit answers the configure.
|
||||
// While a frame is owed, that commit is the frame's and not the one
|
||||
// below or a consumer's request for a frame callback, which show the old
|
||||
// frame: the serial waits for it, the last one when several come
|
||||
// (SendFrameSurfaceState). A frame is owed while a size waits, and while
|
||||
// the surface does not show the window as it is: a swapchain still to
|
||||
// be made (a rebuild that threw, after which width and height are ahead
|
||||
// of it), one no frame has been presented from yet, a size the surface
|
||||
// has not been sent. Otherwise what the surface shows answers the
|
||||
// configure already, and this acknowledgement takes with it any serial
|
||||
// that waited: one older than the last acknowledged is a protocol error.
|
||||
const bool sizeUnsent = window->wpViewport != nullptr
|
||||
&& (window->logicalWidth != window->sentLogicalWidth || window->logicalHeight != window->sentLogicalHeight);
|
||||
const bool frameOwed = window->deferredLogicalWidth != 0
|
||||
|| (hasSwapchain && (window->swapchainRebuildPending || window->presentedGeneration != window->swapchainGeneration || sizeUnsent));
|
||||
if (frameOwed) {
|
||||
window->unackedConfigure = serial;
|
||||
} else {
|
||||
window->unackedConfigure.reset();
|
||||
xdg_surface_ack_configure(xdg_surface, serial);
|
||||
}
|
||||
|
||||
// Not the answer to a configure that waits, and it brings the surface no
|
||||
// new size, since the viewport's destination comes with the frame too
|
||||
// (#199). It applies what else is pending: a frame callback StartUpdate
|
||||
// asked for, which is what starts its loop.
|
||||
if (window->configured) {
|
||||
// Subsequent configure: if the toplevel asked for a new size
|
||||
// (non-zero, different from current), drive the resize end-to-end.
|
||||
// (0, 0) means "compositor has no preference, keep current size".
|
||||
// The swapchain may not exist yet on the very first frame between
|
||||
// the constructor's wait loop and CreateSwapchain — the Resize
|
||||
// guard against equal sizes already covers that path.
|
||||
if (window->pendingLogicalWidth > 0 && window->pendingLogicalHeight > 0 &&
|
||||
window->swapChain != VK_NULL_HANDLE) {
|
||||
std::uint32_t newWidth = static_cast<std::uint32_t>(
|
||||
std::ceil(window->pendingLogicalWidth * window->scale));
|
||||
std::uint32_t newHeight = static_cast<std::uint32_t>(
|
||||
std::ceil(window->pendingLogicalHeight * window->scale));
|
||||
window->Resize(newWidth, newHeight);
|
||||
}
|
||||
wl_surface_commit(window->surface);
|
||||
}
|
||||
|
||||
window->configured = true;
|
||||
// Last: the handler does nothing with the window after its listeners.
|
||||
// The events last, since a listener may destroy the window: the second
|
||||
// fires only for one that is still there, and nothing of the window is
|
||||
// used after it.
|
||||
window->ApplyToplevelState();
|
||||
if (frameOwed && std::ranges::contains(Device::windows, window)) {
|
||||
window->onFrameOwed.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
void Window::SendFrameSurfaceState() {
|
||||
// The surface's size, when this frame is the first to be drawn for it
|
||||
// (the window's first frame among them). It is the size that was settled
|
||||
// when the buffers' was, and not worked out from the scale of this
|
||||
// moment: a listener of this frame may have dispatched a new one since.
|
||||
// A swapchain made again for the size the surface has sends nothing.
|
||||
if (wpViewport != nullptr && (logicalWidth != sentLogicalWidth || logicalHeight != sentLogicalHeight)) {
|
||||
wp_viewport_set_destination(wpViewport, logicalWidth, logicalHeight);
|
||||
sentLogicalWidth = logicalWidth;
|
||||
sentLogicalHeight = logicalHeight;
|
||||
}
|
||||
// A frame recorded before a size came does not honour it: that
|
||||
// configure, and any after it, waits for the frame at that size.
|
||||
if (unackedConfigure && deferredLogicalWidth == 0) {
|
||||
xdg_surface_ack_configure(xdgSurface, *unackedConfigure);
|
||||
unackedConfigure.reset();
|
||||
}
|
||||
}
|
||||
|
||||
void Window::xdg_surface_handle_preferred_scale(void* data, wp_fractional_scale_v1*, std::uint32_t scale) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue