Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion sbr-rasterize/src/rasterizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,24 @@ impl TextureInner {
pub struct Texture(TextureInner);

impl Texture {
pub(crate) fn memory_footprint(&self) -> usize {
pub fn memory_footprint(&self) -> usize {
match &self.0 {
TextureInner::Software(sw) => sw.memory_footprint(),
}
}

pub fn width(&self) -> u32 {
match &self.0 {
TextureInner::Software(sw) => sw.width(),
}
}

pub fn height(&self) -> u32 {
match &self.0 {
TextureInner::Software(sw) => sw.height(),
}
}

pub(crate) fn is_mono(&self) -> bool {
match &self.0 {
TextureInner::Software(sw) => matches!(sw.format(), PixelFormat::Mono),
Expand Down
5 changes: 5 additions & 0 deletions sbr-util/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,11 @@ impl<K: Hash + PartialEq + Eq + 'static> Cache<K> {
Ok(value) => value,
}
}

#[must_use]
pub fn get<V: CacheValue>(&self, key: K) -> Option<&V> {
self.get_or_try_insert_with(key, || Err(())).ok()
}
}

#[cfg(test)]
Expand Down
27 changes: 16 additions & 11 deletions src/text/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use util::{
};

use super::FreeTypeError;
use crate::text::{FontSizeCacheKey, GlyphCache, OpenTypeTag};
use crate::text::{FontSizeKey, GlyphCache, GlyphKey, OpenTypeTag};

pub mod freetype;
pub use freetype::GlyphDisplayError;
Expand Down Expand Up @@ -191,7 +191,7 @@ impl Font {
forward_methods!(
variants = Font::[FreeType, Tofu];

fn size_cache_key[&]() -> FontSizeCacheKey;
fn size_cache_key[&]() -> FontSizeKey;
pub fn metrics[&]() -> &FontMetrics;
pub fn point_size[&]() -> I26Dot6;
pub fn harfbuzz_scale_factor_for[&](glyph: u32) -> I26Dot6;
Expand Down Expand Up @@ -224,15 +224,20 @@ impl Font {
rasterizer: &mut dyn Rasterizer,
) -> Result<&'c GlyphSubscene, GlyphDisplayError> {
let (render_offset, subpixel_bucket) =
FontSizeCacheKey::get_subpixel_bucket(offset_value, offset_axis_is_y);
let key = self
.size_cache_key()
.for_glyph(self.face(), glyph, subpixel_bucket);

cache.get_or_try_insert_with(key, || match self {
Self::FreeType(font) => font.glyph_subscene_uncached(glyph, render_offset, rasterizer),
Self::Tofu(font) => Ok(font.glyph_subscene_uncached(glyph, render_offset, rasterizer)),
})
GlyphKey::get_subpixel_bucket(offset_value, offset_axis_is_y);
let key = self.size_cache_key().for_glyph(self.face(), glyph);

cache.get_or_try_insert_with(
key.clone().for_subpixel_bucket(subpixel_bucket),
|| match self {
Self::FreeType(font) => {
font.glyph_subscene_uncached(glyph, render_offset, rasterizer, cache, key)
}
Self::Tofu(font) => {
Ok(font.glyph_subscene_uncached(glyph, render_offset, rasterizer))
}
},
)
}
}

Expand Down
Loading
Loading