diff options
author | Joe Wilm <joe@jwilm.com> | 2017-12-19 18:59:45 -0800 |
---|---|---|
committer | Joe Wilm <jwilm@users.noreply.github.com> | 2017-12-22 13:18:08 -0800 |
commit | 41296a555e8df05bb2c83d3356abf0a8d1e5632f (patch) | |
tree | a3f767ec137e0b7367d01ac9d6a27a93b7a4bf0b /src/renderer | |
parent | c9abf571f2a2dcc8fabef1a582acc26a6359c19f (diff) | |
download | alacritty-41296a555e8df05bb2c83d3356abf0a8d1e5632f.tar.gz alacritty-41296a555e8df05bb2c83d3356abf0a8d1e5632f.zip |
Share LoadGlyph implementations
Previously there were two separate but intended-to-be-identical
implementations. Now the two implementations simply delegate to a
single, shared method. This should help correctness issues in the
future.
Diffstat (limited to 'src/renderer')
-rw-r--r-- | src/renderer/mod.rs | 80 |
1 files changed, 38 insertions, 42 deletions
diff --git a/src/renderer/mod.rs b/src/renderer/mod.rs index d510692c..bb2edf15 100644 --- a/src/renderer/mod.rs +++ b/src/renderer/mod.rs @@ -863,61 +863,57 @@ impl<'a> RenderApi<'a> { } } -impl<'a> LoadGlyph for LoaderApi<'a> { - /// Load a glyph into a texture atlas - /// - /// If the current atlas is full, a new one will be created. - fn load_glyph(&mut self, rasterized: &RasterizedGlyph) -> Glyph { - // At least one atlas is guaranteed to be in the `self.atlas` list; thus - // the unwrap should always be ok. - match self.atlas[*self.current_atlas].insert(rasterized, &mut self.active_tex) { - Ok(glyph) => glyph, - Err(_) => { - *self.current_atlas += 1; - if *self.current_atlas == self.atlas.len() { - let atlas = Atlas::new(ATLAS_SIZE); - *self.active_tex = 0; // Atlas::new binds a texture. Ugh this is sloppy. - self.atlas.push(atlas); - } - self.load_glyph(rasterized) +/// Load a glyph into a texture atlas +/// +/// If the current atlas is full, a new one will be created. +#[inline] +fn load_glyph( + active_tex: &mut GLuint, + atlas: &mut Vec<Atlas>, + current_atlas: &mut usize, + rasterized: &RasterizedGlyph +) -> Glyph { + // At least one atlas is guaranteed to be in the `self.atlas` list; thus + // the unwrap. + match atlas[*current_atlas].insert(rasterized, active_tex) { + Ok(glyph) => glyph, + Err(_) => { + *current_atlas += 1; + if *current_atlas == atlas.len() { + let new = Atlas::new(ATLAS_SIZE); + *active_tex = 0; // Atlas::new binds a texture. Ugh this is sloppy. + atlas.push(new); } + load_glyph(active_tex, atlas, current_atlas, rasterized) } } +} + +#[inline] +fn clear_atlas(atlas: &mut Vec<Atlas>, current_atlas: &mut usize) { + for atlas in atlas.iter_mut() { + atlas.clear(); + } + *current_atlas = 0; +} + +impl<'a> LoadGlyph for LoaderApi<'a> { + fn load_glyph(&mut self, rasterized: &RasterizedGlyph) -> Glyph { + load_glyph(self.active_tex, self.atlas, self.current_atlas, rasterized) + } fn clear(&mut self) { - for atlas in self.atlas.iter_mut() { - atlas.clear(); - } - *self.current_atlas = 0; + clear_atlas(self.atlas, self.current_atlas) } } impl<'a> LoadGlyph for RenderApi<'a> { - /// Load a glyph into a texture atlas - /// - /// If the current atlas is full, a new one will be created. fn load_glyph(&mut self, rasterized: &RasterizedGlyph) -> Glyph { - // At least one atlas is guaranteed to be in the `self.atlas` list; thus - // the unwrap. - match self.atlas[*self.current_atlas].insert(rasterized, &mut self.active_tex) { - Ok(glyph) => glyph, - Err(_) => { - *self.current_atlas += 1; - if *self.current_atlas == self.atlas.len() { - let atlas = Atlas::new(ATLAS_SIZE); - *self.active_tex = 0; // Atlas::new binds a texture. Ugh this is sloppy. - self.atlas.push(atlas); - } - self.load_glyph(rasterized) - } - } + load_glyph(self.active_tex, self.atlas, self.current_atlas, rasterized) } fn clear(&mut self) { - for atlas in self.atlas.iter_mut() { - atlas.clear(); - } - *self.current_atlas = 0; + clear_atlas(self.atlas, self.current_atlas) } } |