Bug 1325199: Only read system parameters for ClearType when we receive a paint event. r=jrmuizel draft
authorBas Schouten <bschouten@mozilla.com>
Wed, 21 Dec 2016 22:12:31 +0100
changeset 452620 282f60f8250ecc1d98fc6d4c9d971064bd7476ce
parent 451551 c59499ae612da18687d3053136e4a33ba8dc0a95
child 540245 018815244c4933b7c5aed0fd3a0f94ad0116ebc9
push id39423
push userbschouten@mozilla.com
push dateWed, 21 Dec 2016 21:15:14 +0000
reviewersjrmuizel
bugs1325199
milestone53.0a1
Bug 1325199: Only read system parameters for ClearType when we receive a paint event. r=jrmuizel MozReview-Commit-ID: EjQyCcdWXEc
gfx/thebes/gfxDWriteFonts.cpp
gfx/thebes/gfxDWriteFonts.h
widget/windows/nsWindowGfx.cpp
--- a/gfx/thebes/gfxDWriteFonts.cpp
+++ b/gfx/thebes/gfxDWriteFonts.cpp
@@ -42,16 +42,18 @@ GetCairoAntialiasOption(gfxFont::Antiali
 
 #ifndef SPI_GETFONTSMOOTHINGTYPE
 #define SPI_GETFONTSMOOTHINGTYPE 0x200a
 #endif
 #ifndef FE_FONTSMOOTHINGCLEARTYPE
 #define FE_FONTSMOOTHINGCLEARTYPE 2
 #endif
 
+bool gfxDWriteFont::mUseClearType = true;
+
 static bool
 UsingClearType()
 {
     BOOL fontSmoothing;
     if (!SystemParametersInfo(SPI_GETFONTSMOOTHING, 0, &fontSmoothing, 0) ||
         !fontSmoothing)
     {
         return false;
@@ -112,16 +114,22 @@ gfxDWriteFont::~gfxDWriteFont()
         cairo_font_face_destroy(mCairoFontFace);
     }
     if (mScaledFont) {
         cairo_scaled_font_destroy(mScaledFont);
     }
     delete mMetrics;
 }
 
+void
+gfxDWriteFont::UpdateClearTypeUsage()
+{
+  mUseClearType = UsingClearType();
+}
+
 gfxFont*
 gfxDWriteFont::CopyWithAntialiasOption(AntialiasOption anAAOption)
 {
     return new gfxDWriteFont(static_cast<gfxDWriteFontEntry*>(mFontEntry.get()),
                              &mStyle, mNeedsBold, anAAOption);
 }
 
 const gfxFont::Metrics&
@@ -168,17 +176,17 @@ gfxDWriteFont::ComputeMetrics(AntialiasO
                    fontMetrics.designUnitsPerEm;
         mAdjustedSize = mStyle.GetAdjustedSize(aspect);
     } else {
         mAdjustedSize = mStyle.size;
     }
 
     // Note that GetMeasuringMode depends on mAdjustedSize
     if ((anAAOption == gfxFont::kAntialiasDefault &&
-         UsingClearType() &&
+         mUseClearType &&
          GetMeasuringMode() == DWRITE_MEASURING_MODE_NATURAL) ||
         anAAOption == gfxFont::kAntialiasSubpixel)
     {
         mUseSubpixelPositions = true;
         // note that this may be reset to FALSE if we determine that a bitmap
         // strike is going to be used
     }
 
@@ -595,17 +603,17 @@ gfxDWriteFont::GetGlyphWidth(DrawTarget&
     width = NS_lround(MeasureGlyphWidth(aGID) * 65536.0);
     mGlyphWidths->Put(aGID, width);
     return width;
 }
 
 already_AddRefed<GlyphRenderingOptions>
 gfxDWriteFont::GetGlyphRenderingOptions(const TextRunDrawParams* aRunParams)
 {
-  if (UsingClearType()) {
+  if (mUseClearType) {
     return Factory::CreateDWriteGlyphRenderingOptions(
       gfxWindowsPlatform::GetPlatform()->GetRenderingParams(GetForceGDIClassic() ?
         gfxWindowsPlatform::TEXT_RENDERING_GDI_CLASSIC : gfxWindowsPlatform::TEXT_RENDERING_NORMAL));
   } else {
     return Factory::CreateDWriteGlyphRenderingOptions(gfxWindowsPlatform::GetPlatform()->
       GetRenderingParams(gfxWindowsPlatform::TEXT_RENDERING_NO_CLEARTYPE));
   }
 }
--- a/gfx/thebes/gfxDWriteFonts.h
+++ b/gfx/thebes/gfxDWriteFonts.h
@@ -24,16 +24,18 @@ class gfxDWriteFont : public gfxFont
 {
 public:
     gfxDWriteFont(gfxFontEntry *aFontEntry,
                   const gfxFontStyle *aFontStyle,
                   bool aNeedsBold = false,
                   AntialiasOption = kAntialiasDefault);
     ~gfxDWriteFont();
 
+    static void UpdateClearTypeUsage();
+
     virtual gfxFont*
     CopyWithAntialiasOption(AntialiasOption anAAOption) override;
 
     virtual uint32_t GetSpaceGlyph() override;
 
     virtual bool SetupCairoFont(DrawTarget* aDrawTarget) override;
 
     virtual bool AllowSubpixelAA() override
@@ -97,11 +99,12 @@ protected:
 
     uint32_t mSpaceGlyph;
 
     bool mNeedsOblique;
     bool mNeedsBold;
     bool mUseSubpixelPositions;
     bool mAllowManualShowGlyphs;
     bool mAzureScaledFontIsCairo;
+    static bool mUseClearType;
 };
 
 #endif
--- a/widget/windows/nsWindowGfx.cpp
+++ b/widget/windows/nsWindowGfx.cpp
@@ -24,16 +24,17 @@ using mozilla::plugins::PluginInstancePa
 #include "nsWindowGfx.h"
 #include "nsAppRunner.h"
 #include <windows.h>
 #include "gfxEnv.h"
 #include "gfxImageSurface.h"
 #include "gfxUtils.h"
 #include "gfxWindowsSurface.h"
 #include "gfxWindowsPlatform.h"
+#include "gfxDWriteFonts.h"
 #include "mozilla/gfx/2D.h"
 #include "mozilla/gfx/DataSurfaceHelpers.h"
 #include "mozilla/gfx/Tools.h"
 #include "mozilla/RefPtr.h"
 #include "mozilla/UniquePtrExtensions.h"
 #include "nsGfxCIID.h"
 #include "gfxContext.h"
 #include "prmem.h"
@@ -182,16 +183,18 @@ bool nsWindow::OnPaint(HDC aDC, uint32_t
     for (nsWindow* window : windows) {
       window->OnRenderingDeviceReset(resetSeqNo);
     }
 
     gfxCriticalNote << "(nsWindow) Finished device reset.";
     return false;
   }
 
+  gfxDWriteFont::UpdateClearTypeUsage();
+
   // After we CallUpdateWindow to the child, occasionally a WM_PAINT message
   // is posted to the parent event loop with an empty update rect. Do a
   // dummy paint so that Windows stops dispatching WM_PAINT in an inifinite
   // loop. See bug 543788.
   if (IsPlugin()) {
     RECT updateRect;
     if (!GetUpdateRect(mWnd, &updateRect, FALSE) ||
         (updateRect.left == updateRect.right &&