Bug 1553818 - use GDI ClearType contrast for GDI font gamma. r=jrmuizel, a=RyanVM
authorLee Salzman <lsalzman@mozilla.com>
Wed, 24 Jul 2019 18:51:28 +0000
changeset 544810 a5573dc631138b3a3d4415bb3c6b500a9a65eab0
parent 544809 dd328d8b3a0ff4079a5aff7d4996725d96ffe17d
child 544811 4859fe78b41602342cb67bd6409f1ed79c8030db
push id2131
push userffxbld-merge
push dateMon, 26 Aug 2019 18:30:20 +0000
treeherdermozilla-release@b19ffb3ca153 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel, RyanVM
bugs1553818
milestone69.0
Bug 1553818 - use GDI ClearType contrast for GDI font gamma. r=jrmuizel, a=RyanVM Differential Revision: https://phabricator.services.mozilla.com/D39101
gfx/skia/skia/src/ports/SkTypeface_win_dw.cpp
gfx/thebes/gfxDWriteFonts.cpp
gfx/wr/webrender/src/platform/windows/font.rs
--- a/gfx/skia/skia/src/ports/SkTypeface_win_dw.cpp
+++ b/gfx/skia/skia/src/ports/SkTypeface_win_dw.cpp
@@ -432,21 +432,18 @@ void DWriteFontTypeface::onFilterRec(SkS
             rec->setPaintGamma(gamma);
 
             rec->setContrast(defaultRenderingParams->GetEnhancedContrast());
         }
     }
 #elif defined(MOZ_SKIA)
     rec->setContrast(fContrast);
 
-    // GDI gamma should be 2.3
-    // See the LUT gamma values comment for GDI fonts.
-    float gamma = ForceGDI() ? 2.3f : fGamma;
-    rec->setDeviceGamma(gamma);
-    rec->setPaintGamma(gamma);
+    rec->setDeviceGamma(fGamma);
+    rec->setPaintGamma(fGamma);
 #endif
 }
 
 ///////////////////////////////////////////////////////////////////////////////
 //PDF Support
 
 void DWriteFontTypeface::getGlyphToUnicodeMap(SkUnichar* glyphToUnicode) const {
     unsigned glyphCount = fDWriteFontFace->GetGlyphCount();
--- a/gfx/thebes/gfxDWriteFonts.cpp
+++ b/gfx/thebes/gfxDWriteFonts.cpp
@@ -67,16 +67,35 @@ static BYTE GetSystemTextQuality() {
     }
 
     return ANTIALIASED_QUALITY;
   }
 
   return DEFAULT_QUALITY;
 }
 
+#ifndef SPI_GETFONTSMOOTHINGCONTRAST
+#  define SPI_GETFONTSMOOTHINGCONTRAST 0x200c
+#endif
+
+// "Retrieves a contrast value that is used in ClearType smoothing. Valid
+// contrast values are from 1000 to 2200. The default value is 1400."
+static FLOAT GetSystemGDIGamma() {
+  static FLOAT sGDIGamma = 0.0f;
+  if (!sGDIGamma) {
+    UINT value = 0;
+    if (!SystemParametersInfo(SPI_GETFONTSMOOTHINGCONTRAST, 0, &value, 0) ||
+        value < 1000 || value > 2200) {
+      value = 1400;
+    }
+    sGDIGamma = value / 1000.0f;
+  }
+  return sGDIGamma;
+}
+
 ////////////////////////////////////////////////////////////////////////////////
 // gfxDWriteFont
 gfxDWriteFont::gfxDWriteFont(const RefPtr<UnscaledFontDWrite>& aUnscaledFont,
                              gfxFontEntry* aFontEntry,
                              const gfxFontStyle* aFontStyle,
                              RefPtr<IDWriteFontFace> aFontFace,
                              AntialiasOption anAAOption)
     : gfxFont(aUnscaledFont, aFontEntry, aFontStyle, anAAOption),
@@ -644,21 +663,23 @@ already_AddRefed<ScaledFont> gfxDWriteFo
             UsingClearType()
                 ? (forceGDI ? gfxWindowsPlatform::TEXT_RENDERING_GDI_CLASSIC
                             : gfxWindowsPlatform::TEXT_RENDERING_NORMAL)
                 : gfxWindowsPlatform::TEXT_RENDERING_NO_CLEARTYPE);
 
     DWRITE_RENDERING_MODE renderingMode =
       forceGDI ? DWRITE_RENDERING_MODE_GDI_CLASSIC : params->GetRenderingMode();
 
+    FLOAT gamma = forceGDI ? GetSystemGDIGamma() : params->GetGamma();
+
     const gfxFontStyle* fontStyle = GetStyle();
     mAzureScaledFont = Factory::CreateScaledFontForDWriteFont(
         mFontFace, fontStyle, GetUnscaledFont(), GetAdjustedSize(),
-        useEmbeddedBitmap, (int)renderingMode,
-        params, params->GetGamma(), params->GetEnhancedContrast());
+        useEmbeddedBitmap, (int)renderingMode, params, gamma,
+        params->GetEnhancedContrast());
     if (!mAzureScaledFont) {
       return nullptr;
     }
     InitializeScaledFont();
     mAzureScaledFontUsedClearType = UsingClearType();
   }
 
   if (aTarget->GetBackendType() == BackendType::CAIRO) {
--- a/gfx/wr/webrender/src/platform/windows/font.rs
+++ b/gfx/wr/webrender/src/platform/windows/font.rs
@@ -560,38 +560,24 @@ impl FontContext {
         if width == 0 || height == 0 {
             return Err(GlyphRasterError::LoadFailed);
         }
 
         let pixels = analysis.create_alpha_texture(texture_type, bounds).or(Err(GlyphRasterError::LoadFailed))?;
         let mut bgra_pixels = self.convert_to_bgra(&pixels, texture_type, font.render_mode, bitmaps,
                                                    font.flags.contains(FontInstanceFlags::SUBPIXEL_BGR));
 
-        // These are the default values we use in Gecko.
-        // We use a gamma value of 2.3 for gdi fonts
-        const GDI_GAMMA: u16 = 230;
-
         let FontInstancePlatformOptions { gamma, contrast, .. } = font.platform_options.unwrap_or_default();
-        let gdi_gamma = match font.render_mode {
-            FontRenderMode::Mono => GDI_GAMMA,
-            FontRenderMode::Alpha | FontRenderMode::Subpixel => {
-                if bitmaps || font.flags.contains(FontInstanceFlags::FORCE_GDI) {
-                    GDI_GAMMA
-                } else {
-                    gamma
-                }
-            }
-        };
         let gamma_lut = self.gamma_luts
-            .entry((gdi_gamma, contrast))
+            .entry((gamma, contrast))
             .or_insert_with(||
                 GammaLut::new(
                     contrast as f32 / 100.0,
-                    gdi_gamma as f32 / 100.0,
-                    gdi_gamma as f32 / 100.0,
+                    gamma as f32 / 100.0,
+                    gamma as f32 / 100.0,
                 ));
         gamma_lut.preblend(&mut bgra_pixels, font.color);
 
         let format = if bitmaps {
             GlyphFormat::Bitmap
         } else if texture_type == dwrote::DWRITE_TEXTURE_ALIASED_1x1 {
             font.get_alpha_glyph_format()
         } else {