mirror of
https://github.com/alacritty/alacritty.git
synced 2024-11-11 13:51:01 -05:00
Reuse Rasterizer in Display::new
Instead of creating a `Rasterizer` to guess the window dimensions, dropping it and then creating a new one for the glyph cache, reuse the same `Rasterizer`. This prevents the font from being loaded twice during startup.
This commit is contained in:
parent
ed5dbc1118
commit
a64553bbaf
2 changed files with 10 additions and 7 deletions
|
@ -232,7 +232,8 @@ impl Display {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Guess the target window dimensions.
|
// Guess the target window dimensions.
|
||||||
let metrics = GlyphCache::static_metrics(config.font.clone(), estimated_dpr)?;
|
let mut rasterizer = Rasterizer::new(estimated_dpr as f32, config.font.use_thin_strokes)?;
|
||||||
|
let metrics = GlyphCache::static_metrics(&mut rasterizer, config.font.clone())?;
|
||||||
let (cell_width, cell_height) = compute_cell_size(config, &metrics);
|
let (cell_width, cell_height) = compute_cell_size(config, &metrics);
|
||||||
|
|
||||||
// Guess the target window size if the user has specified the number of lines/columns.
|
// Guess the target window size if the user has specified the number of lines/columns.
|
||||||
|
@ -256,12 +257,13 @@ impl Display {
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
info!("Device pixel ratio: {}", window.dpr);
|
info!("Device pixel ratio: {}", window.dpr);
|
||||||
|
rasterizer.update_dpr(window.dpr as f32);
|
||||||
|
|
||||||
// Create renderer.
|
// Create renderer.
|
||||||
let mut renderer = QuadRenderer::new()?;
|
let mut renderer = QuadRenderer::new()?;
|
||||||
|
|
||||||
let (glyph_cache, cell_width, cell_height) =
|
let (glyph_cache, cell_width, cell_height) =
|
||||||
Self::new_glyph_cache(window.dpr, &mut renderer, config)?;
|
Self::new_glyph_cache(rasterizer, &mut renderer, config)?;
|
||||||
|
|
||||||
if let Some(dimensions) = dimensions {
|
if let Some(dimensions) = dimensions {
|
||||||
if (estimated_dpr - window.dpr).abs() < f64::EPSILON {
|
if (estimated_dpr - window.dpr).abs() < f64::EPSILON {
|
||||||
|
@ -361,12 +363,11 @@ impl Display {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new_glyph_cache(
|
fn new_glyph_cache(
|
||||||
dpr: f64,
|
rasterizer: Rasterizer,
|
||||||
renderer: &mut QuadRenderer,
|
renderer: &mut QuadRenderer,
|
||||||
config: &UiConfig,
|
config: &UiConfig,
|
||||||
) -> Result<(GlyphCache, f32, f32), Error> {
|
) -> Result<(GlyphCache, f32, f32), Error> {
|
||||||
let font = config.font.clone();
|
let font = config.font.clone();
|
||||||
let rasterizer = Rasterizer::new(dpr as f32, config.font.use_thin_strokes)?;
|
|
||||||
|
|
||||||
// Initialize glyph cache.
|
// Initialize glyph cache.
|
||||||
let glyph_cache = {
|
let glyph_cache = {
|
||||||
|
|
|
@ -404,10 +404,12 @@ impl GlyphCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Calculate font metrics without access to a glyph cache.
|
/// Calculate font metrics without access to a glyph cache.
|
||||||
pub fn static_metrics(font: Font, dpr: f64) -> Result<crossfont::Metrics, crossfont::Error> {
|
pub fn static_metrics(
|
||||||
let mut rasterizer = crossfont::Rasterizer::new(dpr as f32, font.use_thin_strokes)?;
|
rasterizer: &mut crossfont::Rasterizer,
|
||||||
|
font: Font,
|
||||||
|
) -> Result<crossfont::Metrics, crossfont::Error> {
|
||||||
let regular_desc = GlyphCache::make_desc(font.normal(), Slant::Normal, Weight::Normal);
|
let regular_desc = GlyphCache::make_desc(font.normal(), Slant::Normal, Weight::Normal);
|
||||||
let regular = Self::load_regular_font(&mut rasterizer, ®ular_desc, font.size())?;
|
let regular = Self::load_regular_font(rasterizer, ®ular_desc, font.size())?;
|
||||||
rasterizer.get_glyph(GlyphKey { font_key: regular, character: 'm', size: font.size() })?;
|
rasterizer.get_glyph(GlyphKey { font_key: regular, character: 'm', size: font.size() })?;
|
||||||
|
|
||||||
rasterizer.metrics(regular, font.size())
|
rasterizer.metrics(regular, font.size())
|
||||||
|
|
Loading…
Reference in a new issue