imsd-messages/interfaces/ImsdMessages-Gesture.cppm

286 lines
12 KiB
Text
Raw Normal View History

// SPDX-License-Identifier: GPL-3.0-only
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
/*
ImsdMessages:Gesture — what a finger or a mouse did, decided from raw
Gesture, Ui, project: Crafter.Graphics at 3f646ec, whose key repeat fires once at the delay The pinned library's key repeat counted the compositor's delay as missed periods: lastFireTime was the press itself and the catch-up loop fired once per period since it, so the first repeat after the delay was a burst of floor(delay / period) events — with rate 25 and delay 600 a held Backspace deleted sixteen characters at the delay mark and a held letter put fifteen copies in the field, from a hardware keyboard and from an on-screen keyboard that sends Backspace as key events; a rate above 1000 made the period zero and the loop endless. Crafter.Graphics 3f646ec lands the first repeat at the delay, keeps the period at a millisecond or more and caps the catch-up after a stalled frame; the app's own repeat timer and the frame path's TickKeyRepeats need nothing more. The pin moves from 6f471ca to the library's master of 2026-11-01, eight commits on: the swapchain sized for its present mode and frames in flight keyed by frame, the font atlas's SDF decoded in atlas pixels and glyphs that find no room given a cell at the next frame, Win32 linking and titles and a Win32 test's stand-in dropped, the library's AGENTS template, the key repeat. One contract changes with a4be6f1: once the atlas evicts, a glyph item is good for the frame it was shaped for, so item buffers must be one set per frame in flight (the library's usage contract since; its HelloUI shows it). The Canvas's layers keep Window::numFrames sets of their quad, circle and glyph buffers and fill the one at UIBuildArgs::frameIdx, where one set had served the three frames paced by frame callbacks — about 3 MB of host-visible memory in all; the descriptor heap grows to hold their slots. The atlas's contract changed with the eviction: a glyph that finds no free cell draws blank and gets one when the next frame begins — a frame this app, drawing on demand, has to ask for: the layers count the glyphs drawn blank (FontAtlas::Lookup, not Resident) and Build asks for another frame while glyphs wait, until the frames in flight plus one have passed without a cell gained — a cell comes from glyphs not drawn in those frames, so a screen change needs that many before the cells it displaced come free (FrameWait in Gesture, beside the fling's frame rule, added with this, its use — restarted by every redraw request and by each frame of a fling, which changes what is drawn as a request does — and tested there). The other contracts this app relies on hold at the new commit: the disable ends the composition and clears the shown record, CaptureNextFrame writes its PNG inside the frame that records the copy, a touch's up precedes the synthesised release, the deletion queue still wants the app's drain when a window ends (DrainDeletions), libevdev stays vendored; the licence texts are unchanged.
2026-11-01 00:59:06 +01:00
pointer phases, the scroll physics of a list, and the frames the on-demand
window still owes (a fling's, the font atlas's wait). Pure arithmetic over
the app's own point and box types, so the tests feed it by hand.
*/
export module ImsdMessages:Gesture;
import std;
export namespace ImsdMessages {
struct Point {
float x = 0;
float y = 0;
friend bool operator==(const Point&, const Point&) = default;
};
struct Box {
float x = 0;
float y = 0;
float w = 0;
float h = 0;
bool Contains(Point p) const noexcept { return p.x >= x && p.x < x + w && p.y >= y && p.y < y + h; }
float Right() const noexcept { return x + w; }
float Bottom() const noexcept { return y + h; }
friend bool operator==(const Box&, const Box&) = default;
};
enum class PointerPhase : std::uint8_t { Down, Move, Up, Cancel };
struct GestureEvent {
enum class Kind : std::uint8_t { None, Tap, LongPress, DragStart, Drag, Fling, Release };
Kind kind = Kind::None;
Point at; // the press for Tap, LongPress and DragStart; the current position for Drag
Point delta; // Drag: the movement since the previous event
Point velocity; // Fling: pixels per second
};
// One pointer at a time: a press that ends within the slop and before
// the long-press time is a tap; a press held past that time without
Gesture, Ui, project: Crafter.Graphics at 364d210, whose pointer and touch events carry their time The pinned library dropped the compositor's time of every pointer and touch event, so the app dated them by its own clock at dispatch. Events queued while the main loop was busy — a List importing a backlog, each Import an fdatasync — all carried the time the loop came back: a swipe's backlog read as a few milliseconds' travel and flung the list to its far end, and a press whose down and up both waited out a stall had them at one time, a tap where the user held — on a Failed bubble a Retry, an SMS the user did not ask for. Crafter.Graphics 364d210 keeps the time on the window (lastInputTime, set before the event fires), one commit on the master of 2026-11-02, which added the library's review configuration and no code. The gesture detector now gets each event's own time, unwrapped past the wrap at 2^32 into one running clock (an event stamped 0, which the compositor's time reads for one millisecond in 2^32, gets the host's clock), and the long-press timer's expiry is the host's elapsed since the press put on that clock, so a press and its release keep their distance however late the loop dispatches them — and a release or a move the detector sees past the long-press time with no timer fired is the long press itself, at the press, where the press can be one, since the hold is measured on the events' clock (tests/Gesture pins both). The pin moves from 3f646ec; the contracts this app relies on are unchanged by the two commits between.
2026-11-02 16:09:33 +01:00
// moving is a long press (the host runs the timer and calls Timeout —
// or the first move or the release past that time is, when it comes
// before the timer could: the host's loop dispatched the press and
// what followed it together, behind a stall, each with its own time);
// movement past the slop starts a drag whose release is a fling when it
Ui, main: the new-conversation screen and the long-press sheets The + opens a screen with a number field (its placeholder "Number", a parameter of the compose field now) and Start; the number becomes a conversation key through Number's ConversationKey, as an sms: link's does (E.164 through the country code, a short code as digits), anything else is refused in place. A long press on a conversation row offers to delete the conversation, on a message to copy its text to the clipboard or delete it; only those two have one: App tells the recogniser before each press whether what it lands on has a long press (GestureDetector's longPress), and without one a press held as long — on a button, a field, a sheet's row — stays a tap at its release, so a slow finger presses the button all the same. A sheet draws on the overlay layer over a scrim and pushes its regions last, so they win the hit test, and the wheel scrolls nothing under it; Escape, the back arrow and a tap outside dismiss it. Deleting a conversation also closes its notification and drops its draft; the + keeps the draft of the conversation it leaves, as Back does, and so does a view that closes because its last message was deleted. The deletes go through Sync (Erase, EraseConversation: the commit before, which keeps a deleted text deleted). The number field's box is drawn by its screen, as the send bar's is by the bar: the shared field drawing paints no background of its own. Opening a conversation, from a notification or a link, leaves the new-conversation screen and any sheet, and the + leaves any sheet. A key whose press changed the screen acts once: held, its repeats are not the new screen's — Enter, which started the conversation, would type line breaks into its field, and Escape would go on back, from a sheet through the conversation and its draft. A sheet that asks to delete a conversation goes when a text arrives for it: a yes would delete that text unread. A press on the conversation's row opens no such sheet either while the row it aimed at had not shown the text — the regions are a frame's: the press that is down when the text arrives, and one that comes down before the next frame is drawn, have no long press; a release before the long-press time is still the row's tap, while the row stays under the finger. --new and --bench-sheet put either on screen for the bench (--bench-sheet conversation or message, each on the screen a long press opens it over: another value is refused, and one that finds nothing to press says so in the log), and are window flags as --screenshot is. Tested: the screens and the sheets by the bench (--new, --bench-sheet) and the phone step's screenshots; the deletes' logic with the commit before, in tests/Store and tests/Sync; the press without a long press in tests/Gesture (the timer gives no long press and a move within the slop nothing; the release is the tap, however late; a slide off the control is a drag); a deleted conversation's draft dropped, in tests/Edit. The press on a row a text arrived for has no bench: none holds a finger on a row.
2026-11-01 18:11:40 +01:00
// was fast enough. Where the host says that what the press lands on has
// no long press, a press held as long is still a tap at its release.
class GestureDetector {
public:
float slopPx = 8;
std::int64_t longPressMs = 500;
float flingMinPxPerS = 60;
Ui, main: the new-conversation screen and the long-press sheets The + opens a screen with a number field (its placeholder "Number", a parameter of the compose field now) and Start; the number becomes a conversation key through Number's ConversationKey, as an sms: link's does (E.164 through the country code, a short code as digits), anything else is refused in place. A long press on a conversation row offers to delete the conversation, on a message to copy its text to the clipboard or delete it; only those two have one: App tells the recogniser before each press whether what it lands on has a long press (GestureDetector's longPress), and without one a press held as long — on a button, a field, a sheet's row — stays a tap at its release, so a slow finger presses the button all the same. A sheet draws on the overlay layer over a scrim and pushes its regions last, so they win the hit test, and the wheel scrolls nothing under it; Escape, the back arrow and a tap outside dismiss it. Deleting a conversation also closes its notification and drops its draft; the + keeps the draft of the conversation it leaves, as Back does, and so does a view that closes because its last message was deleted. The deletes go through Sync (Erase, EraseConversation: the commit before, which keeps a deleted text deleted). The number field's box is drawn by its screen, as the send bar's is by the bar: the shared field drawing paints no background of its own. Opening a conversation, from a notification or a link, leaves the new-conversation screen and any sheet, and the + leaves any sheet. A key whose press changed the screen acts once: held, its repeats are not the new screen's — Enter, which started the conversation, would type line breaks into its field, and Escape would go on back, from a sheet through the conversation and its draft. A sheet that asks to delete a conversation goes when a text arrives for it: a yes would delete that text unread. A press on the conversation's row opens no such sheet either while the row it aimed at had not shown the text — the regions are a frame's: the press that is down when the text arrives, and one that comes down before the next frame is drawn, have no long press; a release before the long-press time is still the row's tap, while the row stays under the finger. --new and --bench-sheet put either on screen for the bench (--bench-sheet conversation or message, each on the screen a long press opens it over: another value is refused, and one that finds nothing to press says so in the log), and are window flags as --screenshot is. Tested: the screens and the sheets by the bench (--new, --bench-sheet) and the phone step's screenshots; the deletes' logic with the commit before, in tests/Store and tests/Sync; the press without a long press in tests/Gesture (the timer gives no long press and a move within the slop nothing; the release is the tap, however late; a slide off the control is a drag); a deleted conversation's draft dropped, in tests/Edit. The press on a row a text arrived for has no bench: none holds a finger on a row.
2026-11-01 18:11:40 +01:00
bool longPress = true; // whether the press that follows can be a long press: the host's word, before each Down
GestureEvent Feed(PointerPhase phase, Point p, std::int64_t tMs) {
GestureEvent e;
switch (phase) {
case PointerPhase::Down:
pressed = true;
dragging = false;
longPressed = false;
down = p;
downAt = tMs;
last = p;
samples.clear();
samples.push_back({ p, tMs });
break;
case PointerPhase::Move: {
if (!pressed) break;
Gesture, Ui, project: Crafter.Graphics at 364d210, whose pointer and touch events carry their time The pinned library dropped the compositor's time of every pointer and touch event, so the app dated them by its own clock at dispatch. Events queued while the main loop was busy — a List importing a backlog, each Import an fdatasync — all carried the time the loop came back: a swipe's backlog read as a few milliseconds' travel and flung the list to its far end, and a press whose down and up both waited out a stall had them at one time, a tap where the user held — on a Failed bubble a Retry, an SMS the user did not ask for. Crafter.Graphics 364d210 keeps the time on the window (lastInputTime, set before the event fires), one commit on the master of 2026-11-02, which added the library's review configuration and no code. The gesture detector now gets each event's own time, unwrapped past the wrap at 2^32 into one running clock (an event stamped 0, which the compositor's time reads for one millisecond in 2^32, gets the host's clock), and the long-press timer's expiry is the host's elapsed since the press put on that clock, so a press and its release keep their distance however late the loop dispatches them — and a release or a move the detector sees past the long-press time with no timer fired is the long press itself, at the press, where the press can be one, since the hold is measured on the events' clock (tests/Gesture pins both). The pin moves from 3f646ec; the contracts this app relies on are unchanged by the two commits between.
2026-11-02 16:09:33 +01:00
if (longPress && !dragging && !longPressed && tMs - downAt >= longPressMs) {
// Held past the long-press time with no Timeout yet (the
// events of a stall dispatched before the timer): the
// long press, before any movement is read.
longPressed = true;
e.kind = GestureEvent::Kind::LongPress;
e.at = down;
break;
}
if (!dragging && !longPressed && (std::abs(p.x - down.x) > slopPx || std::abs(p.y - down.y) > slopPx)) {
dragging = true;
e.kind = GestureEvent::Kind::DragStart;
e.at = down;
last = down;
}
if (dragging) {
if (e.kind == GestureEvent::Kind::DragStart) {
e.delta = { p.x - down.x, p.y - down.y };
} else {
e.kind = GestureEvent::Kind::Drag;
e.delta = { p.x - last.x, p.y - last.y };
e.at = p;
}
}
last = p;
samples.push_back({ p, tMs });
while (samples.size() > 1 && tMs - samples.front().tMs > 100) samples.erase(samples.begin());
break;
}
case PointerPhase::Up: {
if (!pressed) break;
pressed = false;
if (dragging) {
// The velocity is the last 100 ms of movement before
// the release: a finger held still before letting go
// has none, whatever it did before (no event comes
// while it is still).
while (samples.size() > 1 && tMs - samples.front().tMs > 100) samples.erase(samples.begin());
const Point v = Velocity(p, tMs);
if (std::hypot(v.x, v.y) >= flingMinPxPerS) {
e.kind = GestureEvent::Kind::Fling;
e.velocity = v;
} else {
e.kind = GestureEvent::Kind::Release;
}
e.at = p;
Ui, main: the new-conversation screen and the long-press sheets The + opens a screen with a number field (its placeholder "Number", a parameter of the compose field now) and Start; the number becomes a conversation key through Number's ConversationKey, as an sms: link's does (E.164 through the country code, a short code as digits), anything else is refused in place. A long press on a conversation row offers to delete the conversation, on a message to copy its text to the clipboard or delete it; only those two have one: App tells the recogniser before each press whether what it lands on has a long press (GestureDetector's longPress), and without one a press held as long — on a button, a field, a sheet's row — stays a tap at its release, so a slow finger presses the button all the same. A sheet draws on the overlay layer over a scrim and pushes its regions last, so they win the hit test, and the wheel scrolls nothing under it; Escape, the back arrow and a tap outside dismiss it. Deleting a conversation also closes its notification and drops its draft; the + keeps the draft of the conversation it leaves, as Back does, and so does a view that closes because its last message was deleted. The deletes go through Sync (Erase, EraseConversation: the commit before, which keeps a deleted text deleted). The number field's box is drawn by its screen, as the send bar's is by the bar: the shared field drawing paints no background of its own. Opening a conversation, from a notification or a link, leaves the new-conversation screen and any sheet, and the + leaves any sheet. A key whose press changed the screen acts once: held, its repeats are not the new screen's — Enter, which started the conversation, would type line breaks into its field, and Escape would go on back, from a sheet through the conversation and its draft. A sheet that asks to delete a conversation goes when a text arrives for it: a yes would delete that text unread. A press on the conversation's row opens no such sheet either while the row it aimed at had not shown the text — the regions are a frame's: the press that is down when the text arrives, and one that comes down before the next frame is drawn, have no long press; a release before the long-press time is still the row's tap, while the row stays under the finger. --new and --bench-sheet put either on screen for the bench (--bench-sheet conversation or message, each on the screen a long press opens it over: another value is refused, and one that finds nothing to press says so in the log), and are window flags as --screenshot is. Tested: the screens and the sheets by the bench (--new, --bench-sheet) and the phone step's screenshots; the deletes' logic with the commit before, in tests/Store and tests/Sync; the press without a long press in tests/Gesture (the timer gives no long press and a move within the slop nothing; the release is the tap, however late; a slide off the control is a drag); a deleted conversation's draft dropped, in tests/Edit. The press on a row a text arrived for has no bench: none holds a finger on a row.
2026-11-01 18:11:40 +01:00
} else if (!longPressed && (!longPress || tMs - downAt < longPressMs)) {
e.kind = GestureEvent::Kind::Tap;
e.at = down;
Gesture, Ui, project: Crafter.Graphics at 364d210, whose pointer and touch events carry their time The pinned library dropped the compositor's time of every pointer and touch event, so the app dated them by its own clock at dispatch. Events queued while the main loop was busy — a List importing a backlog, each Import an fdatasync — all carried the time the loop came back: a swipe's backlog read as a few milliseconds' travel and flung the list to its far end, and a press whose down and up both waited out a stall had them at one time, a tap where the user held — on a Failed bubble a Retry, an SMS the user did not ask for. Crafter.Graphics 364d210 keeps the time on the window (lastInputTime, set before the event fires), one commit on the master of 2026-11-02, which added the library's review configuration and no code. The gesture detector now gets each event's own time, unwrapped past the wrap at 2^32 into one running clock (an event stamped 0, which the compositor's time reads for one millisecond in 2^32, gets the host's clock), and the long-press timer's expiry is the host's elapsed since the press put on that clock, so a press and its release keep their distance however late the loop dispatches them — and a release or a move the detector sees past the long-press time with no timer fired is the long press itself, at the press, where the press can be one, since the hold is measured on the events' clock (tests/Gesture pins both). The pin moves from 3f646ec; the contracts this app relies on are unchanged by the two commits between.
2026-11-02 16:09:33 +01:00
} else if (!longPressed) {
// Held past the long-press time with no Timeout yet: the
// long press, at the release.
longPressed = true;
e.kind = GestureEvent::Kind::LongPress;
e.at = down;
} else {
e.kind = GestureEvent::Kind::Release;
e.at = p;
}
dragging = false;
break;
}
case PointerPhase::Cancel:
pressed = false;
dragging = false;
longPressed = false;
break;
}
return e;
}
// The host's timer at Down + longPressMs.
GestureEvent Timeout(std::int64_t tMs) {
GestureEvent e;
Ui, main: the new-conversation screen and the long-press sheets The + opens a screen with a number field (its placeholder "Number", a parameter of the compose field now) and Start; the number becomes a conversation key through Number's ConversationKey, as an sms: link's does (E.164 through the country code, a short code as digits), anything else is refused in place. A long press on a conversation row offers to delete the conversation, on a message to copy its text to the clipboard or delete it; only those two have one: App tells the recogniser before each press whether what it lands on has a long press (GestureDetector's longPress), and without one a press held as long — on a button, a field, a sheet's row — stays a tap at its release, so a slow finger presses the button all the same. A sheet draws on the overlay layer over a scrim and pushes its regions last, so they win the hit test, and the wheel scrolls nothing under it; Escape, the back arrow and a tap outside dismiss it. Deleting a conversation also closes its notification and drops its draft; the + keeps the draft of the conversation it leaves, as Back does, and so does a view that closes because its last message was deleted. The deletes go through Sync (Erase, EraseConversation: the commit before, which keeps a deleted text deleted). The number field's box is drawn by its screen, as the send bar's is by the bar: the shared field drawing paints no background of its own. Opening a conversation, from a notification or a link, leaves the new-conversation screen and any sheet, and the + leaves any sheet. A key whose press changed the screen acts once: held, its repeats are not the new screen's — Enter, which started the conversation, would type line breaks into its field, and Escape would go on back, from a sheet through the conversation and its draft. A sheet that asks to delete a conversation goes when a text arrives for it: a yes would delete that text unread. A press on the conversation's row opens no such sheet either while the row it aimed at had not shown the text — the regions are a frame's: the press that is down when the text arrives, and one that comes down before the next frame is drawn, have no long press; a release before the long-press time is still the row's tap, while the row stays under the finger. --new and --bench-sheet put either on screen for the bench (--bench-sheet conversation or message, each on the screen a long press opens it over: another value is refused, and one that finds nothing to press says so in the log), and are window flags as --screenshot is. Tested: the screens and the sheets by the bench (--new, --bench-sheet) and the phone step's screenshots; the deletes' logic with the commit before, in tests/Store and tests/Sync; the press without a long press in tests/Gesture (the timer gives no long press and a move within the slop nothing; the release is the tap, however late; a slide off the control is a drag); a deleted conversation's draft dropped, in tests/Edit. The press on a row a text arrived for has no bench: none holds a finger on a row.
2026-11-01 18:11:40 +01:00
if (!longPress || !pressed || dragging || longPressed || tMs - downAt < longPressMs) return e;
longPressed = true;
e.kind = GestureEvent::Kind::LongPress;
e.at = down;
return e;
}
bool Pressed() const noexcept { return pressed; }
bool Dragging() const noexcept { return dragging; }
private:
struct Sample {
Point p;
std::int64_t tMs;
};
Point Velocity(Point p, std::int64_t tMs) const {
if (samples.empty()) return {};
const Sample& oldest = samples.front();
const std::int64_t dt = tMs - oldest.tMs;
if (dt <= 0) return {};
return { (p.x - oldest.p.x) * 1000.0f / static_cast<float>(dt), (p.y - oldest.p.y) * 1000.0f / static_cast<float>(dt) };
}
bool pressed = false;
bool dragging = false;
bool longPressed = false;
Point down;
Point last;
std::int64_t downAt = 0;
std::vector<Sample> samples;
};
// A scrollable extent: the offset is how far the content moved up.
struct ScrollState {
float offset = 0;
float velocity = 0; // px/s, positive scrolls further down
float content = 0;
float viewport = 0;
float Max() const noexcept { return std::max(0.0f, content - viewport); }
void Clamp() noexcept { offset = std::clamp(offset, 0.0f, Max()); }
void ScrollBy(float dy) noexcept {
offset += dy;
velocity = 0;
Clamp();
}
void Fling(float pxPerS) noexcept { velocity = pxPerS; }
// Advances the fling by dt seconds; true while still moving.
bool Tick(float dt) noexcept {
if (std::abs(velocity) < 20.0f) {
velocity = 0;
return false;
}
const float before = offset;
offset += velocity * dt;
Clamp();
if (offset == before || offset == 0.0f || offset == Max()) {
velocity = 0;
return false;
}
velocity *= std::exp(-4.0f * dt);
return true;
}
};
struct HitRegion {
Box box;
std::uint32_t id = 0;
};
// The topmost region (the last drawn) under a point.
std::optional<std::uint32_t> HitTest(std::span<const HitRegion> regions, Point p) {
for (auto it = regions.rbegin(); it != regions.rend(); ++it) {
if (it->box.Contains(p)) return it->id;
}
return std::nullopt;
}
// What a point names on a drawn frame, by what the region stood for
// rather than its index: a control's id, or — for the regions of a
// list (`rowBase` + the row's index into `keys`) and of a conversation
// (`messageBase` + the bubble's index into `messages`) — the
// conversation or the message. A press is bound to this: a frame
// drawn while the finger is down (a new text snaps the conversation,
// the list re-sorts) that moves another row or bubble under it names
// something else at the release, which then acts on nothing.
struct HitTarget {
std::uint32_t id = 0;
std::string key;
std::uint64_t message = 0;
friend bool operator==(const HitTarget&, const HitTarget&) = default;
};
std::optional<HitTarget> TargetAt(std::span<const HitRegion> regions, Point p, std::uint32_t rowBase, std::span<const std::string> keys, std::uint32_t messageBase, std::span<const std::uint64_t> messages) {
const std::optional<std::uint32_t> id = HitTest(regions, p);
if (!id) return std::nullopt;
if (*id >= messageBase) {
if (const std::size_t i = *id - messageBase; i < messages.size()) return HitTarget{ messageBase, "", messages[i] };
} else if (*id >= rowBase) {
if (const std::size_t i = *id - rowBase; i < keys.size()) return HitTarget{ rowBase, keys[i] };
}
return HitTarget{ *id };
}
Gesture, Ui, project: Crafter.Graphics at 3f646ec, whose key repeat fires once at the delay The pinned library's key repeat counted the compositor's delay as missed periods: lastFireTime was the press itself and the catch-up loop fired once per period since it, so the first repeat after the delay was a burst of floor(delay / period) events — with rate 25 and delay 600 a held Backspace deleted sixteen characters at the delay mark and a held letter put fifteen copies in the field, from a hardware keyboard and from an on-screen keyboard that sends Backspace as key events; a rate above 1000 made the period zero and the loop endless. Crafter.Graphics 3f646ec lands the first repeat at the delay, keeps the period at a millisecond or more and caps the catch-up after a stalled frame; the app's own repeat timer and the frame path's TickKeyRepeats need nothing more. The pin moves from 6f471ca to the library's master of 2026-11-01, eight commits on: the swapchain sized for its present mode and frames in flight keyed by frame, the font atlas's SDF decoded in atlas pixels and glyphs that find no room given a cell at the next frame, Win32 linking and titles and a Win32 test's stand-in dropped, the library's AGENTS template, the key repeat. One contract changes with a4be6f1: once the atlas evicts, a glyph item is good for the frame it was shaped for, so item buffers must be one set per frame in flight (the library's usage contract since; its HelloUI shows it). The Canvas's layers keep Window::numFrames sets of their quad, circle and glyph buffers and fill the one at UIBuildArgs::frameIdx, where one set had served the three frames paced by frame callbacks — about 3 MB of host-visible memory in all; the descriptor heap grows to hold their slots. The atlas's contract changed with the eviction: a glyph that finds no free cell draws blank and gets one when the next frame begins — a frame this app, drawing on demand, has to ask for: the layers count the glyphs drawn blank (FontAtlas::Lookup, not Resident) and Build asks for another frame while glyphs wait, until the frames in flight plus one have passed without a cell gained — a cell comes from glyphs not drawn in those frames, so a screen change needs that many before the cells it displaced come free (FrameWait in Gesture, beside the fling's frame rule, added with this, its use — restarted by every redraw request and by each frame of a fling, which changes what is drawn as a request does — and tested there). The other contracts this app relies on hold at the new commit: the disable ends the composition and clears the shown record, CaptureNextFrame writes its PNG inside the frame that records the copy, a touch's up precedes the synthesised release, the deletion queue still wants the app's drain when a window ends (DrainDeletions), libevdev stays vendored; the licence texts are unchanged.
2026-11-01 00:59:06 +01:00
// The frames a screen owes the font atlas. A glyph that found no cell
// drew blank and gets one when a later frame begins — from the glyphs
// not drawn in the last `patience` frames (the frames in flight plus
// one) — and a frame comes only when asked for: Again(waiting) after
// each frame asks for another while glyphs wait, until `patience`
// frames in a row gained no cell, when the screen needs more cells than
// the atlas holds. A change in the count — a gain, a screen change —
// starts the count over; Reset does on any other change of what is
// drawn (the app's every redraw request but the wait's own, and each
// frame of a fling).
struct FrameWait {
std::uint32_t patience = 4;
std::uint32_t last = 0; // the previous frame's waiting glyphs
std::uint32_t gainless = 0; // frames in a row that gained no cell
bool Again(std::uint32_t waiting) {
if (waiting == 0) {
Reset();
return false;
}
if (last == 0 || waiting != last) gainless = 0;
else ++gainless;
last = waiting;
return gainless < patience;
}
void Reset() {
last = 0;
gainless = 0;
}
};
}