gallery/vendor/i-slint-core/graphics/bitmapfont.rs
Greg Pomerantz 2f4768f354 Fix 120Hz scroll jank end-to-end: render-ahead present + full-cache eviction off the UI thread
Three root causes, all fixed and verified on the Pixel 9 Pro:

1. Present phase (backend + renderer): VSYNC_LOCKED_RENDER defers the
   render to the vsync wake; RENDER_AHEAD presents the previous frame at
   the start of render() (phase = wake + ~1.1 ms) and holds the new
   frame one slot. Crash fix: a held wgpu frame must be PRESENTED, never
   merely dropped, before the next acquire (AlreadyAcquired panic at
   launch otherwise); discard_pending_frame presents too.

2. Full-res prefetch churn (src/lib.rs): the 8-slot full cache cycled
   through a ~20-cell viewport forever (137 decodes/20 s) and each
   eviction free()'d a 50 MB Vec on the UI thread (20-52 ms CPU spikes,
   ~7/s = the residual SLOWEV NonMain jank). Fix: 60 s tombstone
   cooldown on evicted paths (idle prefetch skips, urgent tap bypasses)
   + off-thread reaper for the freed blobs (insert: 21 ms -> 4 us).

3. (earlier) Skia final flush + Mailbox present mode (vendor, M3).

Instrumentation (all behind --features perf): OTHR/INVK/INVK_TAG/FLCK
lines for cross-thread closure timing and push-site tagging.

Warm measured swipe, 8580-file grid: cadence median 8.33 ms (exact
120 Hz), p99 15.5 ms, 5/552 gaps >16.7 ms (0.9%, max 28.3 ms, zero
>33 ms); PRES phase median ~994 us, zero late frames. Docs updated
(docs/BUGS/scroll-jank-120hz.md, full scorecard + line reference).

Also: vendored i-slint-core + wgpu-hal (vkshim interposition patch),
vkshim profiling tooling, backend made a non-optional dep, debuggable
flag for simpleperf (REMOVE before shipping).
2026-10-30 02:49:23 -04:00

77 lines
2.9 KiB
Rust

// Copyright © SixtyFPS GmbH <info@slint.dev>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
use crate::slice::Slice;
#[repr(C)]
#[derive(Debug)]
/// A pre-rendered glyph with the alpha map and associated metrics
pub struct BitmapGlyph {
/// The starting x-coordinate for the glyph, relative to the base line
/// This is a fixed point number that is shifted by 6 bits
pub x: i16,
/// The starting y-coordinate for the glyph, relative to the base line
/// This is a fixed point number that is shifted by 6 bits
pub y: i16,
/// The width of the glyph in pixels
pub width: i16,
/// The height of the glyph in pixels
pub height: i16,
/// The horizontal distance to the next glyph
/// This is a fixed point number that is shifted by 6 bits
pub x_advance: i16,
/// The 8-bit alpha map that's to be blended with the current text color
/// or 8-bit signed distance field depending on `BitmapFont::sdf`
pub data: Slice<'static, u8>,
}
#[repr(C)]
#[derive(Debug)]
/// A set of pre-rendered bitmap glyphs at a fixed pixel size
pub struct BitmapGlyphs {
/// The font size in pixels at which the glyphs were pre-rendered. The boundaries of glyphs may exceed this
/// size, if the font designer has chosen so. This is only used for matching.
pub pixel_size: i16,
/// The data of the pre-rendered glyphs
pub glyph_data: Slice<'static, BitmapGlyph>,
}
#[repr(C)]
#[derive(Debug)]
/// An entry in the character map of a [`BitmapFont`].
pub struct CharacterMapEntry {
/// The unicode code point for a given glyph
pub code_point: char,
/// The corresponding index in the `glyph_data` of [`BitmapGlyphs`]
pub glyph_index: u16,
}
#[repr(C)]
#[derive(Debug)]
/// A subset of an originally scalable font that's rendered ahead of time.
pub struct BitmapFont {
/// The family name of the font
pub family_name: Slice<'static, u8>,
/// A vector of code points and their corresponding glyph index, sorted by code point.
pub character_map: Slice<'static, CharacterMapEntry>,
/// The font supplied size of the em square.
pub units_per_em: f32,
/// The font ascent in design metrics (typically positive)
pub ascent: f32,
/// The font descent in design metrics (typically negative)
pub descent: f32,
/// The font's x-height.
pub x_height: f32,
/// The font's cap-height.
pub cap_height: f32,
/// A vector of pre-rendered glyph sets. Each glyph set must have the same number of glyphs,
/// which must be at least as big as the largest glyph index in the character map.
pub glyphs: Slice<'static, BitmapGlyphs>,
/// The weight of the font in CSS units (400 is normal).
pub weight: u16,
/// Whether the type-face is rendered italic.
pub italic: bool,
/// Whether the format of the font is a signed distance field
pub sdf: bool,
}