Bug 1593094. Add glyph flashing pref. r=kvark
authorJeff Muizelaar <jrmuizel@gmail.com>
Mon, 04 Nov 2019 14:03:57 +0000
changeset 500374 f88700daff3a2eaeadeab2b5bc2cf5b1cbc3fe57
parent 500373 a81df2957c097309ea213774fe83adfa629b0a6f
child 500375 747fc2e159baf123a82b85590b430f2b013b32ca
push id114164
push useraiakab@mozilla.com
push dateTue, 05 Nov 2019 10:06:15 +0000
treeherdermozilla-inbound@4d585c7edc76 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskvark
bugs1593094
milestone72.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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
gfx/thebes/gfxPlatform.cpp
gfx/wr/webrender/src/glyph_rasterizer/mod.rs
gfx/wr/webrender/src/resource_cache.rs
gfx/wr/webrender_api/src/api.rs
modules/libpref/init/all.js
--- a/gfx/thebes/gfxPlatform.cpp
+++ b/gfx/thebes/gfxPlatform.cpp
@@ -596,16 +596,17 @@ static void WebRenderDebugPrefChangeCall
   GFX_WEBRENDER_DEBUG(".disable-opaque-pass",
                       wr::DebugFlags_DISABLE_OPAQUE_PASS)
   GFX_WEBRENDER_DEBUG(".disable-alpha-pass", wr::DebugFlags_DISABLE_ALPHA_PASS)
   GFX_WEBRENDER_DEBUG(".disable-clip-masks", wr::DebugFlags_DISABLE_CLIP_MASKS)
   GFX_WEBRENDER_DEBUG(".disable-text-prims", wr::DebugFlags_DISABLE_TEXT_PRIMS)
   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);
 }
 
 #if defined(USE_SKIA)
 static uint32_t GetSkiaGlyphCacheSize() {
   // Only increase font cache size on non-android to save memory.
--- a/gfx/wr/webrender/src/glyph_rasterizer/mod.rs
+++ b/gfx/wr/webrender/src/glyph_rasterizer/mod.rs
@@ -19,36 +19,51 @@ use crate::render_task_graph::RenderTask
 use crate::render_task_cache::RenderTaskCache;
 use crate::profiler::TextureCacheProfileCounters;
 use malloc_size_of::{MallocSizeOf, MallocSizeOfOps};
 use rayon::ThreadPool;
 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.
     pub fn lock_current_context(&self) -> MutexGuard<FontContext> {
         let id = self.current_worker_id();
         self.lock_context(id)
     }
 
     pub(in super) fn current_worker_id(&self) -> Option<usize> {
         self.workers.current_thread_index()
     }
 }
 
+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,
         font: FontInstance,
         glyph_keys: &[GlyphKey],
         texture_cache: &mut TextureCache,
         gpu_cache: &mut GpuCache,
         _: &mut RenderTaskCache,
@@ -113,16 +128,32 @@ impl GlyphRasterizer {
 
                     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);
+                            }
+                        }
+
                         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
                 })
--- a/gfx/wr/webrender/src/resource_cache.rs
+++ b/gfx/wr/webrender/src/resource_cache.rs
@@ -16,17 +16,17 @@ use crate::capture::ExternalCaptureImage
 #[cfg(feature = "replay")]
 use crate::capture::PlainExternalImage;
 #[cfg(any(feature = "replay", feature = "png"))]
 use crate::capture::CaptureConfig;
 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};
 use crate::image::compute_valid_tiles_if_bounds_change;
 use crate::internal_types::{FastHashMap, FastHashSet, TextureSource, TextureUpdateList};
 use crate::profiler::{ResourceProfileCounters, TextureCacheProfileCounters};
 use crate::render_backend::{FrameId, FrameStamp};
 use crate::render_task_graph::{RenderTaskGraph, RenderTaskId};
@@ -1851,16 +1851,17 @@ impl ResourceCache {
     pub fn end_frame(&mut self, texture_cache_profile: &mut TextureCacheProfileCounters) {
         debug_assert_eq!(self.state, State::QueryResources);
         self.state = State::Idle;
         self.texture_cache.end_frame(texture_cache_profile);
         self.dirty_image_keys.clear();
     }
 
     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);
     }
 
     pub fn clear(&mut self, what: ClearCache) {
         if what.contains(ClearCache::IMAGES) {
             for (_key, mut cached) in self.cached_images.resources.drain() {
                 cached.drop_from_cache(&mut self.texture_cache);
             }
--- a/gfx/wr/webrender_api/src/api.rs
+++ b/gfx/wr/webrender_api/src/api.rs
@@ -1137,16 +1137,17 @@ bitflags! {
         /// Disable various bits of the WebRender pipeline, to help narrow
         /// down where slowness might be coming from.
         const DISABLE_OPAQUE_PASS = 1 << 19;
         const DISABLE_ALPHA_PASS = 1 << 20;
         const DISABLE_CLIP_MASKS = 1 << 21;
         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.
         const DISABLE_PICTURE_CACHING = 1 << 27;
     }
 }
 
 pub struct RenderApi {
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -668,16 +668,17 @@ pref("gfx.webrender.debug.echo-driver-me
 pref("gfx.webrender.debug.new-frame-indicator", false);
 pref("gfx.webrender.debug.new-scene-indicator", false);
 pref("gfx.webrender.debug.show-overdraw", false);
 pref("gfx.webrender.debug.slow-frame-indicator", false);
 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);
 
 pref("accessibility.browsewithcaret_shortcut.enabled", true);
 
 #ifndef XP_MACOSX
   // Tab focus model bit field:
   // 1 focuses text controls, 2 focuses other form elements, 4 adds links.