Prepare benchmarks + ~1.7x prepare perf improvement (#121)
* Add prepare benchmarks * Skip unnecessary peaks * Cite sample sources
This commit is contained in:
parent
87f959dfdb
commit
1055c2e534
8 changed files with 960 additions and 35 deletions
|
@ -107,16 +107,6 @@ impl InnerAtlas {
|
|||
self.kind.num_channels()
|
||||
}
|
||||
|
||||
pub(crate) fn promote(&mut self, glyph: GlyphonCacheKey) {
|
||||
self.glyph_cache.promote(&glyph);
|
||||
self.glyphs_in_use.insert(glyph);
|
||||
}
|
||||
|
||||
pub(crate) fn put(&mut self, glyph: GlyphonCacheKey, details: GlyphDetails) {
|
||||
self.glyph_cache.put(glyph, details);
|
||||
self.glyphs_in_use.insert(glyph);
|
||||
}
|
||||
|
||||
pub(crate) fn grow(
|
||||
&mut self,
|
||||
device: &wgpu::Device,
|
||||
|
@ -384,13 +374,6 @@ impl TextAtlas {
|
|||
did_grow
|
||||
}
|
||||
|
||||
pub(crate) fn glyph(&self, glyph: &GlyphonCacheKey) -> Option<&GlyphDetails> {
|
||||
self.mask_atlas
|
||||
.glyph_cache
|
||||
.peek(glyph)
|
||||
.or_else(|| self.color_atlas.glyph_cache.peek(glyph))
|
||||
}
|
||||
|
||||
pub(crate) fn inner_for_content_mut(&mut self, content_type: ContentType) -> &mut InnerAtlas {
|
||||
match content_type {
|
||||
ContentType::Color => &mut self.color_atlas,
|
||||
|
|
|
@ -428,10 +428,12 @@ fn prepare_glyph<R>(
|
|||
where
|
||||
R: FnMut(RasterizeCustomGlyphRequest) -> Option<RasterizedCustomGlyph>,
|
||||
{
|
||||
if atlas.mask_atlas.glyph_cache.contains(&cache_key) {
|
||||
atlas.mask_atlas.promote(cache_key);
|
||||
} else if atlas.color_atlas.glyph_cache.contains(&cache_key) {
|
||||
atlas.color_atlas.promote(cache_key);
|
||||
let details = if let Some(details) = atlas.mask_atlas.glyph_cache.get(&cache_key) {
|
||||
atlas.mask_atlas.glyphs_in_use.insert(cache_key);
|
||||
details
|
||||
} else if let Some(details) = atlas.color_atlas.glyph_cache.get(&cache_key) {
|
||||
atlas.color_atlas.glyphs_in_use.insert(cache_key);
|
||||
details
|
||||
} else {
|
||||
let Some(image) = (get_glyph_image)(cache, font_system, &mut rasterize_custom_glyph) else {
|
||||
return Ok(None);
|
||||
|
@ -503,20 +505,17 @@ where
|
|||
(GpuCacheStatus::SkipRasterization, None, inner)
|
||||
};
|
||||
|
||||
inner.put(
|
||||
cache_key,
|
||||
GlyphDetails {
|
||||
width: image.width,
|
||||
height: image.height,
|
||||
gpu_cache,
|
||||
atlas_id,
|
||||
top: image.top,
|
||||
left: image.left,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
let details = atlas.glyph(&cache_key).unwrap();
|
||||
inner.glyphs_in_use.insert(cache_key);
|
||||
// Insert the glyph into the cache and return the details reference
|
||||
inner.glyph_cache.get_or_insert(cache_key, || GlyphDetails {
|
||||
width: image.width,
|
||||
height: image.height,
|
||||
gpu_cache,
|
||||
atlas_id,
|
||||
top: image.top,
|
||||
left: image.left,
|
||||
})
|
||||
};
|
||||
|
||||
let mut x = x + details.left as i32;
|
||||
let mut y = (line_y * scale_factor).round() as i32 + y - details.top as i32;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue