mirror of
https://github.com/slint-ui/slint.git
synced 2025-09-30 05:44:52 +00:00
Simplify font resolution in the GL backend
The font resolution function querying fontdb is fast now, so we can always call it when rendering text. That way we don't need all the indirection in the text_size(), etc. functions, we don't need an entry in the item graphics cache for the font and we can avoid a lot of property dependencies.
This commit is contained in:
parent
2f1db396e8
commit
ac0cc85d33
7 changed files with 62 additions and 140 deletions
|
@ -53,8 +53,6 @@ enum ItemGraphicsCacheEntry {
|
|||
_original_image: Rc<CachedImage>,
|
||||
colorized_image: Rc<CachedImage>,
|
||||
},
|
||||
// The font selection is expensive because it is also based on the concrete rendered text, so this is cached here to speed up re-paints
|
||||
Font(fonts::Font),
|
||||
}
|
||||
|
||||
impl ItemGraphicsCacheEntry {
|
||||
|
@ -62,18 +60,11 @@ impl ItemGraphicsCacheEntry {
|
|||
match self {
|
||||
ItemGraphicsCacheEntry::Image(image) => image,
|
||||
ItemGraphicsCacheEntry::ColorizedImage { colorized_image, .. } => colorized_image,
|
||||
_ => panic!("internal error. image requested for non-image gpu data"),
|
||||
}
|
||||
}
|
||||
fn is_colorized_image(&self) -> bool {
|
||||
matches!(self, ItemGraphicsCacheEntry::ColorizedImage { .. })
|
||||
}
|
||||
fn as_font(&self) -> &fonts::Font {
|
||||
match self {
|
||||
ItemGraphicsCacheEntry::Font(font) => font,
|
||||
_ => panic!("internal error. font requested for non-font gpu data"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type ItemGraphicsCache = RenderingCache<Option<ItemGraphicsCacheEntry>>;
|
||||
|
@ -453,21 +444,14 @@ impl ItemRenderer for GLItemRenderer {
|
|||
|
||||
let string = text.text();
|
||||
let string = string.as_str();
|
||||
let font = text
|
||||
.cached_rendering_data
|
||||
.get_or_update(&self.graphics_window.graphics_cache, || {
|
||||
Some(ItemGraphicsCacheEntry::Font(fonts::FONT_CACHE.with(|cache| {
|
||||
cache.borrow_mut().font(
|
||||
text.unresolved_font_request()
|
||||
.merge(&self.graphics_window.default_font_properties()),
|
||||
self.scale_factor,
|
||||
&text.text(),
|
||||
)
|
||||
})))
|
||||
})
|
||||
.unwrap()
|
||||
.as_font()
|
||||
.clone();
|
||||
let font = fonts::FONT_CACHE.with(|cache| {
|
||||
cache.borrow_mut().font(
|
||||
text.unresolved_font_request()
|
||||
.merge(&self.graphics_window.default_font_properties()),
|
||||
self.scale_factor,
|
||||
&text.text(),
|
||||
)
|
||||
});
|
||||
|
||||
let paint = match self
|
||||
.brush_to_paint(text.color(), &mut rect_to_path(item_rect(text, self.scale_factor)))
|
||||
|
@ -499,22 +483,15 @@ impl ItemRenderer for GLItemRenderer {
|
|||
return;
|
||||
}
|
||||
|
||||
let font = text_input
|
||||
.cached_rendering_data
|
||||
.get_or_update(&self.graphics_window.graphics_cache, || {
|
||||
Some(ItemGraphicsCacheEntry::Font(fonts::FONT_CACHE.with(|cache| {
|
||||
cache.borrow_mut().font(
|
||||
text_input
|
||||
.unresolved_font_request()
|
||||
.merge(&self.graphics_window.default_font_properties()),
|
||||
self.scale_factor,
|
||||
&text_input.text(),
|
||||
)
|
||||
})))
|
||||
})
|
||||
.unwrap()
|
||||
.as_font()
|
||||
.clone();
|
||||
let font = fonts::FONT_CACHE.with(|cache| {
|
||||
cache.borrow_mut().font(
|
||||
text_input
|
||||
.unresolved_font_request()
|
||||
.merge(&self.graphics_window.default_font_properties()),
|
||||
self.scale_factor,
|
||||
&text_input.text(),
|
||||
)
|
||||
});
|
||||
|
||||
let paint = match self.brush_to_paint(
|
||||
text_input.color(),
|
||||
|
@ -987,7 +964,6 @@ impl ItemRenderer for GLItemRenderer {
|
|||
let image_id = match cache_entry {
|
||||
Some(ItemGraphicsCacheEntry::Image(image)) => image.ensure_uploaded_to_gpu(self, None),
|
||||
Some(ItemGraphicsCacheEntry::ColorizedImage { .. }) => unreachable!(),
|
||||
Some(ItemGraphicsCacheEntry::Font(_)) => unreachable!(),
|
||||
None => return,
|
||||
};
|
||||
let mut canvas = self.canvas.borrow_mut();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue