Bug 1593094. Add glyph flashing pref. r=kvark

This makes it easier to debug glyph rasterization issues

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Jeff Muizelaar 2019-11-04 14:03:57 +00:00
Родитель 9a95077157
Коммит ce81d707e0
5 изменённых файлов: 37 добавлений и 2 удалений

Просмотреть файл

@ -601,6 +601,7 @@ static void WebRenderDebugPrefChangeCallback(const char* aPrefName, void*) {
GFX_WEBRENDER_DEBUG(".disable-gradient-prims",
wr::DebugFlags_DISABLE_GRADIENT_PRIMS)
GFX_WEBRENDER_DEBUG(".obscure-images", wr::DebugFlags_OBSCURE_IMAGES)
GFX_WEBRENDER_DEBUG(".glyph-flashing", wr::DebugFlags_GLYPH_FLASHING)
#undef GFX_WEBRENDER_DEBUG
gfx::gfxVars::SetWebRenderDebugFlags(flags.bits);

Просмотреть файл

@ -24,11 +24,15 @@ use rayon::prelude::*;
use euclid::approxeq::ApproxEq;
use euclid::size2;
use std::cmp;
use std::cell::Cell;
use std::hash::{Hash, Hasher};
use std::mem;
use std::ops::Deref;
use std::sync::{Arc, Condvar, Mutex, MutexGuard};
use std::sync::mpsc::{channel, Receiver, Sender};
use std::sync::atomic::{AtomicBool, Ordering};
pub static GLYPH_FLASHING: AtomicBool = AtomicBool::new(false);
impl FontContexts {
/// Get access to the font context associated to the current thread.
@ -42,8 +46,19 @@ impl FontContexts {
}
}
impl GlyphRasterizer {
thread_local! {
pub static SEED: Cell<u32> = Cell::new(0);
}
// super simple random to avoid dependency on rand
fn random() -> u32 {
SEED.with(|seed| {
seed.set(seed.get().wrapping_mul(22695477).wrapping_add(1));
seed.get()
})
}
impl GlyphRasterizer {
pub fn request_glyphs(
&mut self,
glyph_cache: &mut GlyphCache,
@ -118,6 +133,22 @@ impl GlyphRasterizer {
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);
}
}
assert_eq!((glyph.left.fract(), glyph.top.fract()), (0.0, 0.0));
// Check if the glyph has a bitmap that needs to be downscaled.

Просмотреть файл

@ -21,7 +21,7 @@ use crate::device::TextureFilter;
use euclid::{point2, size2};
use crate::glyph_cache::GlyphCache;
use crate::glyph_cache::GlyphCacheEntry;
use crate::glyph_rasterizer::{BaseFontInstance, FontInstance, GlyphFormat, GlyphKey, GlyphRasterizer};
use crate::glyph_rasterizer::{GLYPH_FLASHING, BaseFontInstance, FontInstance, GlyphFormat, GlyphKey, GlyphRasterizer};
use crate::gpu_cache::{GpuCache, GpuCacheAddress, GpuCacheHandle};
use crate::gpu_types::UvRectKind;
use crate::image::{compute_tile_size, compute_tile_rect, compute_tile_range, for_each_tile_in_range};
@ -1856,6 +1856,7 @@ impl ResourceCache {
}
pub fn set_debug_flags(&mut self, flags: DebugFlags) {
GLYPH_FLASHING.store(flags.contains(DebugFlags::GLYPH_FLASHING), std::sync::atomic::Ordering::Relaxed);
self.texture_cache.set_debug_flags(flags);
}

Просмотреть файл

@ -1142,6 +1142,7 @@ bitflags! {
const DISABLE_TEXT_PRIMS = 1 << 22;
const DISABLE_GRADIENT_PRIMS = 1 << 23;
const OBSCURE_IMAGES = 1 << 24;
const GLYPH_FLASHING = 1 << 25;
/// The profiler only displays information that is out of the ordinary.
const SMART_PROFILER = 1 << 26;
/// Dynamically control whether picture caching is enabled.

Просмотреть файл

@ -673,6 +673,7 @@ pref("gfx.webrender.debug.picture-caching", false);
pref("gfx.webrender.debug.primitives", false);
pref("gfx.webrender.debug.small-screen", false);
pref("gfx.webrender.debug.obscure-images", false);
pref("gfx.webrender.debug.glyph-flashing", false);
pref("accessibility.warn_on_browsewithcaret", true);