Bug 1595767 - Don't use rayon for glyph rasterization unless there is a lot of glyphs to rasterize r=nical

Differential Revision: https://phabricator.services.mozilla.com/D57005

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Bert Peers 2020-01-07 17:30:14 +00:00
parent d68a88e8fe
commit 44e618b772

View File

@ -112,55 +112,66 @@ impl GlyphRasterizer {
let font_contexts = Arc::clone(&self.font_contexts); let font_contexts = Arc::clone(&self.font_contexts);
let glyph_tx = self.glyph_tx.clone(); let glyph_tx = self.glyph_tx.clone();
// spawn an async task to get off of the render backend thread as early as fn process_glyph(key: &GlyphKey, font_contexts: &FontContexts, font: &FontInstance) -> GlyphRasterJob {
// possible and in that task use rayon's fork join dispatch to rasterize the profile_scope!("glyph-raster");
// glyphs in the thread pool. let mut context = font_contexts.lock_current_context();
self.workers.spawn(move || { let mut job = GlyphRasterJob {
let jobs = glyphs key: key.clone(),
.par_iter() result: context.rasterize_glyph(&font, key),
.map(|key: &GlyphKey| { };
profile_scope!("glyph-raster");
let mut context = font_contexts.lock_current_context();
let mut job = GlyphRasterJob {
key: key.clone(),
result: context.rasterize_glyph(&font, key),
};
if let Ok(ref mut glyph) = job.result { if let Ok(ref mut glyph) = job.result {
// Sanity check. // Sanity check.
let bpp = 4; // We always render glyphs in 32 bits RGBA format. let bpp = 4; // We always render glyphs in 32 bits RGBA format.
assert_eq!( assert_eq!(
glyph.bytes.len(), glyph.bytes.len(),
bpp * (glyph.width * glyph.height) as usize bpp * (glyph.width * glyph.height) as usize
); );
// a quick-and-dirty monochrome over // a quick-and-dirty monochrome over
fn over(dst: u8, src: u8) -> u8 { fn over(dst: u8, src: u8) -> u8 {
let a = src as u32; let a = src as u32;
let a = 256 - a; let a = 256 - a;
let dst = ((dst as u32 * a) >> 8) as u8; let dst = ((dst as u32 * a) >> 8) as u8;
src + dst src + dst
} }
if GLYPH_FLASHING.load(Ordering::Relaxed) { if GLYPH_FLASHING.load(Ordering::Relaxed) {
let color = (random() & 0xff) as u8; let color = (random() & 0xff) as u8;
for i in &mut glyph.bytes { for i in &mut glyph.bytes {
*i = over(*i, color); *i = over(*i, color);
}
}
assert_eq!((glyph.left.fract(), glyph.top.fract()), (0.0, 0.0));
// Check if the glyph has a bitmap that needs to be downscaled.
glyph.downscale_bitmap_if_required(&font);
} }
}
job assert_eq!((glyph.left.fract(), glyph.top.fract()), (0.0, 0.0));
})
.collect();
// Check if the glyph has a bitmap that needs to be downscaled.
glyph.downscale_bitmap_if_required(&font);
}
job
}
// if the number of glyphs is small, do it inline to avoid the threading overhead;
// send the result into glyph_tx so downstream code can't tell the difference.
if glyphs.len() < 8 {
let jobs = glyphs.iter()
.map(|key: &GlyphKey| process_glyph(key, &font_contexts, &font))
.collect();
glyph_tx.send(GlyphRasterJobs { font, jobs }).unwrap(); glyph_tx.send(GlyphRasterJobs { font, jobs }).unwrap();
}); } else {
// spawn an async task to get off of the render backend thread as early as
// possible and in that task use rayon's fork join dispatch to rasterize the
// glyphs in the thread pool.
self.workers.spawn(move || {
let jobs = glyphs
.par_iter()
.map(|key: &GlyphKey| process_glyph(key, &font_contexts, &font))
.collect();
glyph_tx.send(GlyphRasterJobs { font, jobs }).unwrap();
});
}
} }
pub fn resolve_glyphs( pub fn resolve_glyphs(