Iterate over text areas only once in prepare
This commit is contained in:
parent
d40b6ad2ed
commit
1469768013
1 changed files with 101 additions and 110 deletions
|
@ -68,7 +68,7 @@ impl TextRenderer {
|
|||
font_system: &mut FontSystem,
|
||||
atlas: &mut TextAtlas,
|
||||
screen_resolution: Resolution,
|
||||
text_areas: impl Iterator<Item = TextArea<'a>> + Clone,
|
||||
text_areas: impl Iterator<Item = TextArea<'a>>,
|
||||
cache: &mut SwashCache,
|
||||
mut metadata_to_depth: impl FnMut(usize) -> f32,
|
||||
) -> Result<(), PrepareError> {
|
||||
|
@ -86,22 +86,20 @@ impl TextRenderer {
|
|||
});
|
||||
}
|
||||
|
||||
for text_area in text_areas.clone() {
|
||||
let mut glyph_vertices: Vec<GlyphToRender> = Vec::new();
|
||||
let mut glyph_indices: Vec<u32> = Vec::new();
|
||||
let mut glyphs_added = 0;
|
||||
|
||||
for text_area in text_areas {
|
||||
for run in text_area.buffer.layout_runs() {
|
||||
for glyph in run.glyphs.iter() {
|
||||
if atlas.mask_atlas.glyph_cache.contains(&glyph.cache_key) {
|
||||
atlas.mask_atlas.promote(glyph.cache_key);
|
||||
continue;
|
||||
}
|
||||
|
||||
if atlas.color_atlas.glyph_cache.contains(&glyph.cache_key) {
|
||||
} else if atlas.color_atlas.glyph_cache.contains(&glyph.cache_key) {
|
||||
atlas.color_atlas.promote(glyph.cache_key);
|
||||
continue;
|
||||
}
|
||||
|
||||
let image = cache
|
||||
.get_image_uncached(font_system, glyph.cache_key)
|
||||
.unwrap();
|
||||
} else {
|
||||
let Some(image) = cache
|
||||
.get_image_uncached(font_system, glyph.cache_key) else { continue };
|
||||
|
||||
let content_type = match image.content {
|
||||
SwashContent::Color => ContentType::Color,
|
||||
|
@ -125,8 +123,13 @@ impl TextRenderer {
|
|||
match inner.try_allocate(width, height) {
|
||||
Some(a) => break a,
|
||||
None => {
|
||||
if !atlas.grow(device, queue, font_system, cache, content_type)
|
||||
{
|
||||
if !atlas.grow(
|
||||
device,
|
||||
queue,
|
||||
font_system,
|
||||
cache,
|
||||
content_type,
|
||||
) {
|
||||
return Err(PrepareError::AtlasFull);
|
||||
}
|
||||
|
||||
|
@ -186,24 +189,12 @@ impl TextRenderer {
|
|||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let mut glyph_vertices: Vec<GlyphToRender> = Vec::new();
|
||||
let mut glyph_indices: Vec<u32> = Vec::new();
|
||||
let mut glyphs_added = 0;
|
||||
|
||||
for text_area in text_areas {
|
||||
// Note: subpixel positioning is not currently handled, so we always truncate down to
|
||||
// the nearest pixel whenever necessary.
|
||||
for run in text_area.buffer.layout_runs() {
|
||||
let line_y = run.line_y;
|
||||
|
||||
for glyph in run.glyphs.iter() {
|
||||
let details = atlas.glyph(&glyph.cache_key).unwrap();
|
||||
|
||||
let mut x = glyph.x_int + details.left as i32 + text_area.left;
|
||||
let mut y = line_y as i32 + glyph.y_int - details.top as i32 + text_area.top;
|
||||
let mut y =
|
||||
run.line_y as i32 + glyph.y_int - details.top as i32 + text_area.top;
|
||||
|
||||
let (mut atlas_x, mut atlas_y, content_type) = match details.gpu_cache {
|
||||
GpuCacheStatus::InAtlas { x, y, content_type } => (x, y, content_type),
|
||||
|
@ -358,7 +349,7 @@ impl TextRenderer {
|
|||
font_system: &mut FontSystem,
|
||||
atlas: &mut TextAtlas,
|
||||
screen_resolution: Resolution,
|
||||
text_areas: impl Iterator<Item = TextArea<'a>> + Clone,
|
||||
text_areas: impl Iterator<Item = TextArea<'a>>,
|
||||
cache: &mut SwashCache,
|
||||
) -> Result<(), PrepareError> {
|
||||
self.prepare_with_depth(
|
||||
|
|
Loading…
Reference in a new issue