Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync changes from mozilla-central #3825

Merged
merged 2 commits into from Jan 8, 2020
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Next

Bug 1595767 - Don't use rayon for glyph rasterization unless there is…

  • Loading branch information
bpeersmoz authored and moz-gfx committed Jan 8, 2020
commit 6fb9178eb5b70309485da0b4843cd9ca101b6104
@@ -112,55 +112,66 @@ impl GlyphRasterizer {
let font_contexts = Arc::clone(&self.font_contexts);
let glyph_tx = self.glyph_tx.clone();

// 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| {
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 {
// Sanity check.
let bpp = 4; // We always render glyphs in 32 bits RGBA format.
assert_eq!(
glyph.bytes.len(),
bpp * (glyph.width * glyph.height) as usize
);

// a quick-and-dirty monochrome over
fn over(dst: u8, src: u8) -> u8 {
let a = src as u32;
let a = 256 - a;
let dst = ((dst as u32 * a) >> 8) as u8;
src + dst
}
fn process_glyph(key: &GlyphKey, font_contexts: &FontContexts, font: &FontInstance) -> GlyphRasterJob {
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 {
// Sanity check.
let bpp = 4; // We always render glyphs in 32 bits RGBA format.
assert_eq!(
glyph.bytes.len(),
bpp * (glyph.width * glyph.height) as usize
);

// a quick-and-dirty monochrome over
fn over(dst: u8, src: u8) -> u8 {
let a = src as u32;
let a = 256 - a;
let dst = ((dst as u32 * a) >> 8) as u8;
src + dst
}

if GLYPH_FLASHING.load(Ordering::Relaxed) {
let color = (random() & 0xff) as u8;
for i in &mut glyph.bytes {
*i = over(*i, color);
}
}
if GLYPH_FLASHING.load(Ordering::Relaxed) {
let color = (random() & 0xff) as u8;
for i in &mut glyph.bytes {
*i = over(*i, color);
}
}

assert_eq!((glyph.left.fract(), glyph.top.fract()), (0.0, 0.0));
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);
}
// Check if the glyph has a bitmap that needs to be downscaled.
glyph.downscale_bitmap_if_required(&font);
}

job
})
.collect();
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();
});
} 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(
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.