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,5 +1,5 @@
|
||||
use crate::{
|
||||
PatchRect,
|
||||
PatchRect, PxVec2,
|
||||
util::{HashMap, Vec2},
|
||||
};
|
||||
use image::RgbaImage;
|
||||
@@ -241,5 +241,7 @@ fn write_glyph(page: &mut RgbaImage, image: &Image, x: u32, y: u32) {
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct PlacedGlyph {
|
||||
pub entry: GlyphEntry,
|
||||
pub offset: Vec2,
|
||||
/// Whole pixels from the origin of the text to this glyph's top-left,
|
||||
/// on the grid once here rather than on every frame that draws it.
|
||||
pub offset: PxVec2,
|
||||
}
|
||||
Reference in new issue
Block a user