Bug 1532171 - don't use light-on-dark mask when font smoothing is disabled on macOS r=rhunt
authorLee Salzman <lsalzman@mozilla.com>
Mon, 04 Mar 2019 15:45:04 -0500
changeset 520193 c12a447c2785d9efc277b484e6c67c1b9d892a8d
parent 520192 70fcbe1d49a582011185bb75f4d755e62927345c
child 520194 e5d9f2ee7ac7c67f8498b1f13f1d301a76f1fedc
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrhunt
bugs1532171
milestone67.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 1532171 - don't use light-on-dark mask when font smoothing is disabled on macOS r=rhunt Differential Revision: https://phabricator.services.mozilla.com/D22006
gfx/skia/skia/src/ports/SkFontHost_mac.cpp
--- a/gfx/skia/skia/src/ports/SkFontHost_mac.cpp
+++ b/gfx/skia/skia/src/ports/SkFontHost_mac.cpp
@@ -2332,29 +2332,16 @@ size_t SkTypeface_Mac::onGetTableData(Sk
 }
 
 SkScalerContext* SkTypeface_Mac::onCreateScalerContext(const SkScalerContextEffects& effects,
                                                        const SkDescriptor* desc) const {
     return new SkScalerContext_Mac(sk_ref_sp(const_cast<SkTypeface_Mac*>(this)), effects, desc);
 }
 
 void SkTypeface_Mac::onFilterRec(SkScalerContextRec* rec) const {
-    if (rec->fMaskFormat == SkMask::kLCD16_Format ||
-        rec->fFlags & SkScalerContext::kGenA8FromLCD_Flag) {
-        SkColor color = rec->getLuminanceColor();
-        int r = SkColorGetR(color);
-        int g = SkColorGetG(color);
-        int b = SkColorGetB(color);
-        // Choose whether to draw using a light-on-dark mask based on observed
-        // color/luminance thresholds that CoreText uses.
-        if (r >= 85 && g >= 85 && b >= 85 && r + g + b >= 2 * 255) {
-            rec->fFlags |= SkScalerContext::kLightOnDark_Flag;
-        }
-    }
-
     if (rec->fFlags & SkScalerContext::kLCD_BGROrder_Flag ||
         rec->fFlags & SkScalerContext::kLCD_Vertical_Flag)
     {
         rec->fMaskFormat = SkMask::kA8_Format;
         // Render the glyphs as close as possible to what was requested.
         // The above turns off subpixel rendering, but the user requested it.
         // Normal hinting will cause the A8 masks to be generated from CoreGraphics subpixel masks.
         // See comments below for more details.
@@ -2426,16 +2413,31 @@ void SkTypeface_Mac::onFilterRec(SkScale
 #ifndef SK_GAMMA_APPLY_TO_A8
         // SRGBTODO: Is this correct? Do we want contrast boost?
         rec->ignorePreBlend();
 #endif
     } else {
         //CoreGraphics dialates smoothed text as needed.
         rec->setContrast(0);
     }
+
+    // Smoothing will be used if the format is either LCD or if there is hinting.
+    // In those cases, we need to choose the proper dilation mask based on the color.
+    if (rec->fMaskFormat == SkMask::kLCD16_Format ||
+        (rec->fMaskFormat == SkMask::kA8_Format && rec->getHinting() != SkPaint::kNo_Hinting)) {
+        SkColor color = rec->getLuminanceColor();
+        int r = SkColorGetR(color);
+        int g = SkColorGetG(color);
+        int b = SkColorGetB(color);
+        // Choose whether to draw using a light-on-dark mask based on observed
+        // color/luminance thresholds that CoreText uses.
+        if (r >= 85 && g >= 85 && b >= 85 && r + g + b >= 2 * 255) {
+            rec->fFlags |= SkScalerContext::kLightOnDark_Flag;
+        }
+    }
 }
 
 /** Takes ownership of the CFStringRef. */
 static const char* get_str(CFStringRef ref, SkString* str) {
     if (nullptr == ref) {
         return nullptr;
     }
     CFStringToSkString(ref, str);