Bug 1321901 - Use IDWriteFontFace::GetRecommendedRenderingMode for font rendering mode in Skia. r=lsalzman, a=jcristau
authorMason Chang <mchang@mozilla.com>
Thu, 15 Dec 2016 08:33:43 -0800
changeset 353072 e4865528325e8f9cc0a690ef9bcd3d6f79ca0866
parent 353071 c1af43b748f1e30cef0b721edd797bd45fcf9613
child 353073 06637572b51f6d266bdd60628e39b06d5f32fad8
push id6795
push userjlund@mozilla.com
push dateMon, 23 Jan 2017 14:19:46 +0000
treeherdermozilla-esr52@76101b503191 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslsalzman, jcristau
bugs1321901
milestone52.0a2
Bug 1321901 - Use IDWriteFontFace::GetRecommendedRenderingMode for font rendering mode in Skia. r=lsalzman, a=jcristau
gfx/skia/skia/src/ports/SkScalerContext_win_dw.cpp
gfx/skia/skia/src/ports/SkScalerContext_win_dw.h
layout/reftests/w3c-css/submitted/text-decor-3/reftest.list
--- a/gfx/skia/skia/src/ports/SkScalerContext_win_dw.cpp
+++ b/gfx/skia/skia/src/ports/SkScalerContext_win_dw.cpp
@@ -214,17 +214,23 @@ SkScalerContext_DW::SkScalerContext_DW(D
 #if SK_HAS_DWRITE_2_H
     fTypeface->fFactory->QueryInterface<IDWriteFactory2>(&fFactory2);
 
     SkTScopedComPtr<IDWriteFontFace2> fontFace2;
     fTypeface->fDWriteFontFace->QueryInterface<IDWriteFontFace2>(&fontFace2);
     fIsColorFont = fFactory2.get() && fontFace2.get() && fontFace2->IsColorFont();
 #endif
 
-    // In general, all glyphs should use CLEARTYPE_NATURAL_SYMMETRIC
+    IDWriteFactory* factory = sk_get_dwrite_factory();
+    if (factory != nullptr) {
+        HRVM(factory->CreateRenderingParams(&fDefaultRenderingParams),
+        "Could not create default rendering params");
+    }
+
+    // In general, all glyphs should DWriteFontFace::GetRecommendedRenderingMode
     // except when bi-level rendering is requested or there are embedded
     // bi-level bitmaps (and the embedded bitmap flag is set and no rotation).
     //
     // DirectWrite's IDWriteFontFace::GetRecommendedRenderingMode does not do
     // this. As a result, determine the actual size of the text and then see if
     // there are any embedded bi-level bitmaps of that size. If there are, then
     // force bitmaps by requesting bi-level rendering.
     //
@@ -310,23 +316,36 @@ SkScalerContext_DW::SkScalerContext_DW(D
     // drop out control in the y direction in order to be legible.
     } else if (is_hinted_without_gasp(typeface)) {
         fTextSizeRender = gdiTextSize;
         fRenderingMode = DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL;
         fTextureType = DWRITE_TEXTURE_CLEARTYPE_3x1;
         fTextSizeMeasure = realTextSize;
         fMeasuringMode = DWRITE_MEASURING_MODE_NATURAL;
 
-    // The normal case is to use natural symmetric rendering and linear metrics.
+    // The normal case is to use the recommended rendering mode
     } else {
         fTextSizeRender = realTextSize;
-        fRenderingMode = DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL_SYMMETRIC;
         fTextureType = DWRITE_TEXTURE_CLEARTYPE_3x1;
         fTextSizeMeasure = realTextSize;
         fMeasuringMode = DWRITE_MEASURING_MODE_NATURAL;
+
+        if (!SUCCEEDED(fTypeface->fDWriteFontFace->GetRecommendedRenderingMode(
+                fTextSizeRender,
+                1.0f,
+                fMeasuringMode,
+                fDefaultRenderingParams.get(),
+                &fRenderingMode))) {
+            fRenderingMode = DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL_SYMMETRIC;
+        }
+
+        // We don't support outline mode right now.
+        if (fRenderingMode == DWRITE_RENDERING_MODE_OUTLINE) {
+            fRenderingMode = DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL_SYMMETRIC;
+        }
     }
 
     if (this->isSubpixel()) {
         fTextSizeMeasure = realTextSize;
         fMeasuringMode = DWRITE_MEASURING_MODE_NATURAL;
     }
 }
 
--- a/gfx/skia/skia/src/ports/SkScalerContext_win_dw.h
+++ b/gfx/skia/skia/src/ports/SkScalerContext_win_dw.h
@@ -70,15 +70,16 @@ private:
     SkScalar fTextSizeRender;
     /** The text size to measure with. */
     SkScalar fTextSizeMeasure;
     SkAutoTUnref<DWriteFontTypeface> fTypeface;
     int fGlyphCount;
     DWRITE_RENDERING_MODE fRenderingMode;
     DWRITE_TEXTURE_TYPE fTextureType;
     DWRITE_MEASURING_MODE fMeasuringMode;
+    SkTScopedComPtr<IDWriteRenderingParams> fDefaultRenderingParams;
 #if SK_HAS_DWRITE_2_H
     SkTScopedComPtr<IDWriteFactory2> fFactory2;
     bool fIsColorFont;
 #endif
 };
 
 #endif
--- a/layout/reftests/w3c-css/submitted/text-decor-3/reftest.list
+++ b/layout/reftests/w3c-css/submitted/text-decor-3/reftest.list
@@ -1,14 +1,14 @@
 == ruby-text-decoration-01.html ruby-text-decoration-01-ref.html
 == text-decoration-propagation-01.html text-decoration-propagation-01-ref.html
 
 # text-emphasis-style
 == text-emphasis-style-property-001.html text-emphasis-style-property-001-ref.html
-fuzzy-if(gtkWidget,3,4) fuzzy-if(skiaContent,87,80)  == text-emphasis-style-property-002.html text-emphasis-style-property-002-ref.html
+fuzzy-if(gtkWidget,3,4) fuzzy-if(skiaContent,103,80)  == text-emphasis-style-property-002.html text-emphasis-style-property-002-ref.html
 skip-if(/^Windows\x20NT\x205\.1/.test(http.oscpu)) == text-emphasis-style-property-003.html text-emphasis-style-property-003-ref.html
 skip-if(/^Windows\x20NT\x205\.1/.test(http.oscpu)) == text-emphasis-style-property-004.html text-emphasis-style-property-004-ref.html
 == text-emphasis-style-property-005.html text-emphasis-style-property-005-ref.html
 == text-emphasis-style-property-005a.html text-emphasis-style-property-005-ref.html
 # START tests from support/generate-text-emphasis-style-property-010-tests.sh
 == text-emphasis-style-property-010Zs.html text-emphasis-style-property-010-ref.html
 == text-emphasis-style-property-010Zl.html text-emphasis-style-property-010-ref.html
 == text-emphasis-style-property-010Zp.html text-emphasis-style-property-010-ref.html
@@ -48,17 +48,17 @@ fuzzy-if(gtkWidget,3,4) skip-if(/^Window
 
 # text-emphasis-color
 fuzzy-if(gtkWidget,3,4) == text-emphasis-color-property-001.html text-emphasis-color-property-001-ref.html
 fuzzy-if(gtkWidget,3,4) == text-emphasis-color-property-001a.html text-emphasis-color-property-001-ref.html
 fuzzy-if(gtkWidget,3,4) == text-emphasis-color-property-002.html text-emphasis-color-property-002-ref.html
 
 # text-emphasis
 == text-emphasis-property-001.html text-emphasis-style-property-001-ref.html
-fuzzy-if(gtkWidget,3,4) fuzzy-if(skiaContent,87,80) == text-emphasis-property-002.html text-emphasis-style-property-002-ref.html
+fuzzy-if(gtkWidget,3,4) fuzzy-if(skiaContent,103,80) == text-emphasis-property-002.html text-emphasis-style-property-002-ref.html
 fuzzy-if(gtkWidget,3,4) == text-emphasis-property-003.html text-emphasis-style-property-012-ref.html
 fuzzy-if(gtkWidget,3,4) == text-emphasis-property-003a.html text-emphasis-style-property-012-ref.html
 fuzzy-if(gtkWidget,3,4) == text-emphasis-property-003b.html text-emphasis-style-property-012-ref.html
 fuzzy-if(gtkWidget,3,4) == text-emphasis-property-004.html text-emphasis-color-property-002-ref.html
 fuzzy-if(gtkWidget,3,4) == text-emphasis-property-004a.html text-emphasis-color-property-002-ref.html
 
 # text-emphasis-position
 # START tests from support/generate-text-emphasis-position-property-tests.py