From 68f83ebade1c29fa3b3fddd732305ddba10facce Mon Sep 17 00:00:00 2001 From: Lee Salzman Date: Mon, 24 Jul 2017 14:12:26 -0400 Subject: [PATCH] Bug 1383817 - clamp gamma/contrast for ScaledFontDWrite when creating SkTypeface. r=mchang MozReview-Commit-ID: LSSffVooDCI --- gfx/2d/ScaledFontDWrite.cpp | 14 +++++++++++++- gfx/thebes/gfxWindowsPlatform.cpp | 8 -------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/gfx/2d/ScaledFontDWrite.cpp b/gfx/2d/ScaledFontDWrite.cpp index 7d2e6901efde..a1d91b17f871 100644 --- a/gfx/2d/ScaledFontDWrite.cpp +++ b/gfx/2d/ScaledFontDWrite.cpp @@ -156,7 +156,19 @@ ScaledFontDWrite::GetSkTypeface() 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; } diff --git a/gfx/thebes/gfxWindowsPlatform.cpp b/gfx/thebes/gfxWindowsPlatform.cpp index 57c5a18ea075..b0d00b103dd8 100755 --- a/gfx/thebes/gfxWindowsPlatform.cpp +++ b/gfx/thebes/gfxWindowsPlatform.cpp @@ -1193,14 +1193,6 @@ gfxWindowsPlatform::SetupClearTypeParams() } } - 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) {