Bug 1383817 - clamp gamma/contrast for ScaledFontDWrite when creating SkTypeface. r=mchang
authorLee Salzman <lsalzman@mozilla.com>
Mon, 24 Jul 2017 14:12:26 -0400
changeset 370569 02a519055f6fdbd69f4269333c54d1422acf84e2
parent 370568 64bdbc8ee42969b71da64e6c96ec58f7a5754eb9
child 370570 2f8b9d3feecbe55eb6faf5f419870aca27c8023d
push id92884
push userlsalzman@mozilla.com
push dateMon, 24 Jul 2017 18:14:55 +0000
treeherdermozilla-inbound@02a519055f6f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmchang
bugs1383817
milestone56.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 1383817 - clamp gamma/contrast for ScaledFontDWrite when creating SkTypeface. r=mchang MozReview-Commit-ID: LSSffVooDCI
gfx/2d/ScaledFontDWrite.cpp
gfx/thebes/gfxWindowsPlatform.cpp
--- a/gfx/2d/ScaledFontDWrite.cpp
+++ b/gfx/2d/ScaledFontDWrite.cpp
@@ -151,17 +151,29 @@ SkTypeface*
 ScaledFontDWrite::GetSkTypeface()
 {
   if (!mTypeface) {
     RefPtr<IDWriteFactory> factory = Factory::GetDWriteFactory();
     if (!factory) {
       return nullptr;
     }
 
-    mTypeface = SkCreateTypefaceFromDWriteFont(factory, mFontFace, mStyle, mForceGDIMode, mGamma, mContrast);
+    Float gamma = mGamma;
+    // Skia doesn't support a gamma value outside of 0-4, so default to 2.2
+    if (gamma < 0.0f || gamma > 4.0f) {
+      gamma = 2.2f;
+    }
+
+    Float contrast = mContrast;
+    // Skia doesn't support a contrast value outside of 0-1, so default to 1.0
+    if (contrast < 0.0f || contrast > 1.0f) {
+      contrast = 1.0f;
+    }
+
+    mTypeface = SkCreateTypefaceFromDWriteFont(factory, mFontFace, mStyle, mForceGDIMode, gamma, contrast);
   }
   return mTypeface;
 }
 #endif
 
 void
 ScaledFontDWrite::CopyGlyphsToBuilder(const GlyphBuffer &aBuffer, PathBuilder *aBuilder, const Matrix *aTransformHint)
 {
--- a/gfx/thebes/gfxWindowsPlatform.cpp
+++ b/gfx/thebes/gfxWindowsPlatform.cpp
@@ -1188,24 +1188,16 @@ gfxWindowsPlatform::SetupClearTypeParams
                 RegCloseKey(hKey);
             }
 
             if (contrast < 0.0 || contrast > 10.0) {
                 contrast = 1.0;
             }
         }
 
-        if (GetDefaultContentBackend() == BackendType::SKIA) {
-          // Skia doesn't support a contrast value outside of 0-1, so default to 1.0
-          if (contrast < 0.0 || contrast > 1.0) {
-            NS_WARNING("Custom dwrite contrast not supported in Skia. Defaulting to 1.0.");
-            contrast = 1.0;
-          }
-        }
-
         // For parameters that have not been explicitly set,
         // we copy values from default params (or our overridden value for contrast)
         if (gamma < 1.0 || gamma > 2.2) {
             gamma = defaultRenderingParams->GetGamma();
         }
 
         if (level < 0.0 || level > 1.0) {
             level = defaultRenderingParams->GetClearTypeLevel();