Put a glyph's offset on the grid where it is placed
A placed glyph's offset is whole pixels by construction -- a floored pen position plus the entry's integer bearing -- and `Painter::glyphs` was converting it, and the entry's width and height, from `f32` on every frame that drew the glyph. It is a `PxVec2` now, converted once when the text is placed, and the size is two integer shifts. Measured with `perf stat -e instructions:u`, since the difference is smaller than this machine's clock: the `many` phase went from 2,013,099,594 instructions to 1,938,264,572 over 500 frames, 3.7% less. `scroll` and `repaint` are unchanged to within noise, which is right -- they do not redraw glyphs. Checked: fmt, clippy, 105 tests, the reorder fuzzer at 300 seeds, and `tabs`, `text` and `random` byte-identical. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f11f5f4825
commit
11c55bcef9
4 files changed
+24
-9
No files matched your search
@@ -1,7 +1,8 @@
|
||||
#[cfg(feature = "layout-diagnostics")]
|
||||
use crate::layout_diagnostics::{self as diag, Counter, TimerKind};
|
||||
use crate::{
|
||||
Align, GlyphAtlas, GlyphEntry, GlyphKey, PlacedGlyph, RegionAlign, UiColor, util::Vec2,
|
||||
Align, GlyphAtlas, GlyphEntry, GlyphKey, PlacedGlyph, Px, PxVec2, RegionAlign, UiColor,
|
||||
util::Vec2,
|
||||
};
|
||||
use parley::{
|
||||
Alignment, AlignmentOptions, FontContext, FontFamily, FontFamilyName, GenericFamily, Layout,
|
||||
@@ -303,9 +304,9 @@ impl TextData {
|
||||
};
|
||||
placed.push(PlacedGlyph {
|
||||
entry,
|
||||
offset: Vec2::new(
|
||||
glyph.x.floor() + entry.left as f32,
|
||||
glyph.y.floor() - entry.top as f32,
|
||||
offset: PxVec2::new(
|
||||
Px::from_int(glyph.x.floor() as i32 + entry.left),
|
||||
Px::from_int(glyph.y.floor() as i32 - entry.top),
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user