Bug 1494715 - Add a pref to disable antialiasing for Ahem only, r=jfkthame
authorMats Palmgren <mats@mozilla.com>
Wed, 19 Sep 2018 11:17:13 +0100
changeset 490229 d4e0fd62e8e0e31392256787b2597d3988642806
parent 490228 d7c8b670ac687fc3e7b98820a5a4fecc046f51b0
child 490230 d4de0eb65962f0aa404ac7e632d46a8f7f296557
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
reviewersjfkthame
bugs1494715
milestone64.0a1
Bug 1494715 - Add a pref to disable antialiasing for Ahem only, r=jfkthame Add a pref called gfx.font_ahem_antialias_none which disables antialiasing for any font with the family name "Ahem". This is useful for wpt reftests where antialaising of Ahem causes spurious failures. Differential Revision: https://phabricator.services.mozilla.com/D7200
gfx/thebes/gfxFont.cpp
gfx/thebes/gfxMacFont.cpp
modules/libpref/init/StaticPrefList.h
modules/libpref/init/all.js
testing/profiles/web-platform/user.js
--- a/gfx/thebes/gfxFont.cpp
+++ b/gfx/thebes/gfxFont.cpp
@@ -5,16 +5,17 @@
 
 #include "gfxFont.h"
 
 #include "mozilla/BinarySearch.h"
 #include "mozilla/DebugOnly.h"
 #include "mozilla/FontPropertyTypes.h"
 #include "mozilla/gfx/2D.h"
 #include "mozilla/MathAlgorithms.h"
+#include "mozilla/StaticPrefs.h"
 #include "mozilla/SVGContextPaint.h"
 
 #include "mozilla/Logging.h"
 
 #include "nsITimer.h"
 
 #include "gfxGlyphExtents.h"
 #include "gfxPlatform.h"
@@ -822,16 +823,23 @@ gfxFont::gfxFont(const RefPtr<UnscaledFo
     mIsValid(true),
     mApplySyntheticBold(false),
     mKerningEnabled(false),
     mMathInitialized(false)
 {
 #ifdef DEBUG_TEXT_RUN_STORAGE_METRICS
     ++gFontCount;
 #endif
+
+    // Turn off AA for Ahem for testing purposes when requested.
+    if (MOZ_UNLIKELY(StaticPrefs::gfx_font_ahem_antialias_none() &&
+                     mFontEntry->FamilyName().EqualsLiteral("Ahem"))) {
+        mAntialiasOption = kAntialiasNone;
+    }
+
     mKerningSet = HasFeatureSet(HB_TAG('k','e','r','n'), mKerningEnabled);
 }
 
 gfxFont::~gfxFont()
 {
     mFontEntry->NotifyFontDestroyed(this);
 
     if (mGlyphChangeObservers) {
--- a/gfx/thebes/gfxMacFont.cpp
+++ b/gfx/thebes/gfxMacFont.cpp
@@ -2,16 +2,17 @@
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "gfxMacFont.h"
 
 #include "mozilla/MemoryReporting.h"
 #include "mozilla/Sprintf.h"
+#include "mozilla/StaticPrefs.h"
 
 #include "gfxCoreTextShaper.h"
 #include <algorithm>
 #include "gfxPlatformMac.h"
 #include "gfxContext.h"
 #include "gfxFontUtils.h"
 #include "gfxMacPlatformFontList.h"
 #include "gfxFontConstants.h"
@@ -144,18 +145,21 @@ gfxMacFont::gfxMacFont(const RefPtr<Unsc
 
     cairo_matrix_t sizeMatrix, ctm;
     cairo_matrix_init_identity(&ctm);
     cairo_matrix_init_scale(&sizeMatrix, mAdjustedSize, mAdjustedSize);
 
     cairo_font_options_t *fontOptions = cairo_font_options_create();
 
     // turn off font anti-aliasing based on user pref setting
-    if (mAdjustedSize <=
-        (gfxFloat)gfxPlatformMac::GetPlatform()->GetAntiAliasingThreshold()) {
+    if ((mAdjustedSize <=
+         (gfxFloat)gfxPlatformMac::GetPlatform()->GetAntiAliasingThreshold()) ||
+        // Turn off AA for Ahem for testing purposes when requested.
+        MOZ_UNLIKELY(StaticPrefs::gfx_font_ahem_antialias_none() &&
+                     mFontEntry->FamilyName().EqualsLiteral("Ahem"))) {
         cairo_font_options_set_antialias(fontOptions, CAIRO_ANTIALIAS_NONE);
         mAntialiasOption = kAntialiasNone;
     } else if (mStyle.useGrayscaleAntialiasing) {
         cairo_font_options_set_antialias(fontOptions, CAIRO_ANTIALIAS_GRAY);
         mAntialiasOption = kAntialiasGrayscale;
     }
 
     mScaledFont = cairo_scaled_font_create(mFontFace, &sizeMatrix, &ctm,
--- a/modules/libpref/init/StaticPrefList.h
+++ b/modules/libpref/init/StaticPrefList.h
@@ -461,16 +461,22 @@ VARCACHE_PREF(
 )
 
 VARCACHE_PREF(
   "gfx.offscreencanvas.enabled",
    gfx_offscreencanvas_enabled,
   RelaxedAtomicBool, false
 )
 
+VARCACHE_PREF(
+  "gfx.font_ahem_antialias_none",
+   gfx_font_ahem_antialias_none,
+  RelaxedAtomicBool, false
+)
+
 //---------------------------------------------------------------------------
 // HTML5 parser prefs
 //---------------------------------------------------------------------------
 
 // Toggle which thread the HTML5 parser uses for stream parsing.
 VARCACHE_PREF(
   "html5.offmainthread",
    html5_offmainthread,
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -850,16 +850,19 @@ pref("gfx.font_rendering.wordcache.charl
 pref("gfx.font_rendering.wordcache.maxentries", 10000);
 
 pref("gfx.font_rendering.graphite.enabled", true);
 
 #ifdef XP_WIN
 pref("gfx.font_rendering.directwrite.use_gdi_table_loading", true);
 #endif
 
+// Disable antialiasing of Ahem, for use in tests
+pref("gfx.font_ahem_antialias_none", false);
+
 #ifdef XP_WIN
 // comma separated list of backends to use in order of preference
 // e.g., pref("gfx.canvas.azure.backends", "direct2d,skia,cairo");
 pref("gfx.canvas.azure.backends", "direct2d1.1,skia,cairo");
 pref("gfx.content.azure.backends", "direct2d1.1,skia,cairo");
 #else
 #ifdef XP_MACOSX
 pref("gfx.content.azure.backends", "skia");
--- a/testing/profiles/web-platform/user.js
+++ b/testing/profiles/web-platform/user.js
@@ -17,8 +17,10 @@ user_pref("network.preload", true);
 // Enable direct connection
 user_pref("network.proxy.type", 0);
 // Web-platform-tests load a lot of URLs very quickly. This puts avoidable and
 // unnecessary I/O pressure on the Places DB (measured to be in the
 // gigabytes).
 user_pref("places.history.enabled", false);
 // Suppress automatic safe mode after crashes
 user_pref("toolkit.startup.max_resumed_crashes", -1);
+// Disable antialiasing for the Ahem font.
+user_pref("gfx.font_ahem_antialias_none", true);