Bug 1532171 - don't use light-on-dark mask when font smoothing is disabled on macOS r=rhunt a=lizzard
authorLee Salzman <lsalzman@mozilla.com>
Mon, 04 Mar 2019 15:45:04 -0500
changeset 516275 cc04c5dab84a04c8ae648fbd95401b541553db2b
parent 516274 d65b3702be545d8323a54a46f8a236c83e0601dd
child 516276 0999f29d8f02f68c5ae0cc0ad1d6f7bb75a17e59
push id1953
push userffxbld-merge
push dateMon, 11 Mar 2019 12:10:20 +0000
treeherdermozilla-release@9c35dcbaa899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrhunt, lizzard
bugs1532171
milestone66.0
Bug 1532171 - don't use light-on-dark mask when font smoothing is disabled on macOS r=rhunt a=lizzard 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);