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,
 | 
					        font_system: &mut FontSystem,
 | 
				
			||||||
        atlas: &mut TextAtlas,
 | 
					        atlas: &mut TextAtlas,
 | 
				
			||||||
        screen_resolution: Resolution,
 | 
					        screen_resolution: Resolution,
 | 
				
			||||||
        text_areas: impl Iterator<Item = TextArea<'a>> + Clone,
 | 
					        text_areas: impl Iterator<Item = TextArea<'a>>,
 | 
				
			||||||
        cache: &mut SwashCache,
 | 
					        cache: &mut SwashCache,
 | 
				
			||||||
        mut metadata_to_depth: impl FnMut(usize) -> f32,
 | 
					        mut metadata_to_depth: impl FnMut(usize) -> f32,
 | 
				
			||||||
    ) -> Result<(), PrepareError> {
 | 
					    ) -> 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 run in text_area.buffer.layout_runs() {
 | 
				
			||||||
                for glyph in run.glyphs.iter() {
 | 
					                for glyph in run.glyphs.iter() {
 | 
				
			||||||
                    if atlas.mask_atlas.glyph_cache.contains(&glyph.cache_key) {
 | 
					                    if atlas.mask_atlas.glyph_cache.contains(&glyph.cache_key) {
 | 
				
			||||||
                        atlas.mask_atlas.promote(glyph.cache_key);
 | 
					                        atlas.mask_atlas.promote(glyph.cache_key);
 | 
				
			||||||
                        continue;
 | 
					                    } else if atlas.color_atlas.glyph_cache.contains(&glyph.cache_key) {
 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                    if atlas.color_atlas.glyph_cache.contains(&glyph.cache_key) {
 | 
					 | 
				
			||||||
                        atlas.color_atlas.promote(glyph.cache_key);
 | 
					                        atlas.color_atlas.promote(glyph.cache_key);
 | 
				
			||||||
                        continue;
 | 
					                    } else {
 | 
				
			||||||
                    }
 | 
					                        let Some(image) = cache
 | 
				
			||||||
 | 
					                            .get_image_uncached(font_system, glyph.cache_key) else { continue };
 | 
				
			||||||
                    let image = cache
 | 
					 | 
				
			||||||
                        .get_image_uncached(font_system, glyph.cache_key)
 | 
					 | 
				
			||||||
                        .unwrap();
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        let content_type = match image.content {
 | 
					                        let content_type = match image.content {
 | 
				
			||||||
                            SwashContent::Color => ContentType::Color,
 | 
					                            SwashContent::Color => ContentType::Color,
 | 
				
			||||||
| 
						 | 
					@ -125,8 +123,13 @@ impl TextRenderer {
 | 
				
			||||||
                                match inner.try_allocate(width, height) {
 | 
					                                match inner.try_allocate(width, height) {
 | 
				
			||||||
                                    Some(a) => break a,
 | 
					                                    Some(a) => break a,
 | 
				
			||||||
                                    None => {
 | 
					                                    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);
 | 
					                                            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 details = atlas.glyph(&glyph.cache_key).unwrap();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    let mut x = glyph.x_int + details.left as i32 + text_area.left;
 | 
					                    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 {
 | 
					                    let (mut atlas_x, mut atlas_y, content_type) = match details.gpu_cache {
 | 
				
			||||||
                        GpuCacheStatus::InAtlas { x, y, content_type } => (x, y, content_type),
 | 
					                        GpuCacheStatus::InAtlas { x, y, content_type } => (x, y, content_type),
 | 
				
			||||||
| 
						 | 
					@ -358,7 +349,7 @@ impl TextRenderer {
 | 
				
			||||||
        font_system: &mut FontSystem,
 | 
					        font_system: &mut FontSystem,
 | 
				
			||||||
        atlas: &mut TextAtlas,
 | 
					        atlas: &mut TextAtlas,
 | 
				
			||||||
        screen_resolution: Resolution,
 | 
					        screen_resolution: Resolution,
 | 
				
			||||||
        text_areas: impl Iterator<Item = TextArea<'a>> + Clone,
 | 
					        text_areas: impl Iterator<Item = TextArea<'a>>,
 | 
				
			||||||
        cache: &mut SwashCache,
 | 
					        cache: &mut SwashCache,
 | 
				
			||||||
    ) -> Result<(), PrepareError> {
 | 
					    ) -> Result<(), PrepareError> {
 | 
				
			||||||
        self.prepare_with_depth(
 | 
					        self.prepare_with_depth(
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue