Bug 1322897 - Use only the G channel for grayscale AA Dwrite fonts and Skia. r=lsalzman, a=lizzard
authorMason Chang <mchang@mozilla.com>
Wed, 01 Feb 2017 15:47:33 -0800
changeset 480410 f3b0ab9fdef6be72279fbe5d32668628bcb62d9e
parent 480409 045cc752a2898bda4ca740cc0f7ecacbe994c78d
child 480411 09af90635cd0262d9ec1bf072952d89c6efc6a26
child 482884 8b510eefa687ab18725e2c7abce570488d1e1825
push id44524
push usermartin.thomson@gmail.com
push dateWed, 08 Feb 2017 05:10:11 +0000
reviewerslsalzman, lizzard
bugs1322897
milestone52.0
Bug 1322897 - Use only the G channel for grayscale AA Dwrite fonts and Skia. r=lsalzman, a=lizzard
gfx/skia/skia/src/ports/SkScalerContext_win_dw.cpp
--- a/gfx/skia/skia/src/ports/SkScalerContext_win_dw.cpp
+++ b/gfx/skia/skia/src/ports/SkScalerContext_win_dw.cpp
@@ -677,20 +677,23 @@ static void bilevel_to_bw(const uint8_t*
 template<bool APPLY_PREBLEND>
 static void rgb_to_a8(const uint8_t* SK_RESTRICT src, const SkGlyph& glyph, const uint8_t* table8) {
     const size_t dstRB = glyph.rowBytes();
     const U16CPU width = glyph.fWidth;
     uint8_t* SK_RESTRICT dst = static_cast<uint8_t*>(glyph.fImage);
 
     for (U16CPU y = 0; y < glyph.fHeight; y++) {
         for (U16CPU i = 0; i < width; i++) {
-            U8CPU r = *(src++);
-            U8CPU g = *(src++);
-            U8CPU b = *(src++);
-            dst[i] = sk_apply_lut_if<APPLY_PREBLEND>((r + g + b) / 3, table8);
+            U8CPU g = src[1];
+            src += 3;
+
+            // Ignore the R, B channels. It looks the closest to what
+            // D2D with grayscale AA has. But there's no way
+            // to just get a grayscale AA alpha texture from a glyph run.
+            dst[i] = sk_apply_lut_if<APPLY_PREBLEND>(g, table8);
         }
         dst = (uint8_t*)((char*)dst + dstRB);
     }
 }
 
 template<bool APPLY_PREBLEND, bool RGB>
 static void rgb_to_lcd16(const uint8_t* SK_RESTRICT src, const SkGlyph& glyph,
                          const uint8_t* tableR, const uint8_t* tableG, const uint8_t* tableB) {