Bug 1325743: Cache Moz2D ClearType usage information in a way similar to Thebes. r=mchang
authorBas Schouten <bschouten@mozilla.com>
Wed, 04 Jan 2017 20:26:17 +0100
changeset 374667 279ce8dbf8f645c853060cc98e3d4ee17bd5d60d
parent 374666 48c65e52aea5a9acc4d5239b0287255a80971727
child 374668 9a55df40a9a8e9956ad0ffc3aea74c3f98792556
push id6996
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 20:48:21 +0000
treeherdermozilla-beta@d89512dab048 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmchang
bugs1325743
milestone53.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 1325743: Cache Moz2D ClearType usage information in a way similar to Thebes. r=mchang This patch makes sure content processes update their cleartype settings, as well as making sure Moz2D's idea of the ClearType settings are in sync with those of Thebes. If the two differ this can cause graphical glitches. MozReview-Commit-ID: 94arUnBWoUy
gfx/2d/2D.h
gfx/2d/Factory.cpp
gfx/2d/HelpersWinFonts.h
gfx/layers/client/ClientLayerManager.cpp
gfx/thebes/gfxDWriteFonts.cpp
widget/windows/nsWindowGfx.cpp
--- a/gfx/2d/2D.h
+++ b/gfx/2d/2D.h
@@ -1554,16 +1554,18 @@ public:
 
   static already_AddRefed<ScaledFont>
     CreateScaledFontForDWriteFont(IDWriteFontFace* aFontFace,
                                   const gfxFontStyle* aStyle,
                                   Float aSize,
                                   bool aUseEmbeddedBitmap,
                                   bool aForceGDIMode);
 
+  static void UpdateSystemTextQuality();
+
 private:
   static ID2D1Device *mD2D1Device;
   static ID3D11Device *mD3D11Device;
   static IDWriteFactory *mDWriteFactory;
 #endif
 
   static DrawEventRecorder *mRecorder;
 };
--- a/gfx/2d/Factory.cpp
+++ b/gfx/2d/Factory.cpp
@@ -36,16 +36,17 @@
 #endif
 
 #ifdef WIN32
 #include "DrawTargetD2D1.h"
 #include "ScaledFontDWrite.h"
 #include "NativeFontResourceDWrite.h"
 #include <d3d10_1.h>
 #include "HelpersD2D.h"
+#include "HelpersWinFonts.h"
 #endif
 
 #include "DrawTargetDual.h"
 #include "DrawTargetTiled.h"
 #include "DrawTargetRecording.h"
 
 #include "SourceSurfaceRawData.h"
 
@@ -704,16 +705,25 @@ Factory::SupportsD2D1()
 }
 
 already_AddRefed<GlyphRenderingOptions>
 Factory::CreateDWriteGlyphRenderingOptions(IDWriteRenderingParams *aParams)
 {
   return MakeAndAddRef<GlyphRenderingOptionsDWrite>(aParams);
 }
 
+BYTE sSystemTextQuality = CLEARTYPE_QUALITY;
+void
+Factory::UpdateSystemTextQuality()
+{
+#ifdef WIN32
+  gfx::UpdateSystemTextQuality();
+#endif
+}
+
 uint64_t
 Factory::GetD2DVRAMUsageDrawTarget()
 {
   return DrawTargetD2D1::mVRAMUsageDT;
 }
 
 uint64_t
 Factory::GetD2DVRAMUsageSourceSurface()
--- a/gfx/2d/HelpersWinFonts.h
+++ b/gfx/2d/HelpersWinFonts.h
@@ -1,42 +1,55 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 namespace mozilla {
 namespace gfx {
 
-// Cleartype can be dynamically enabled/disabled, so we have to check it
-// everytime we want to render some text.
+
+extern BYTE sSystemTextQuality;
+
 static BYTE
 GetSystemTextQuality()
 {
+  return sSystemTextQuality;
+}
+
+// Cleartype can be dynamically enabled/disabled, so we have to allow for dynamically
+// updating it.
+static void
+UpdateSystemTextQuality()
+{
   BOOL font_smoothing;
   UINT smoothing_type;
 
   if (!SystemParametersInfo(SPI_GETFONTSMOOTHING, 0, &font_smoothing, 0)) {
-    return DEFAULT_QUALITY;
+    sSystemTextQuality = DEFAULT_QUALITY;
+    return;
   }
 
   if (font_smoothing) {
       if (!SystemParametersInfo(SPI_GETFONTSMOOTHINGTYPE,
                                 0, &smoothing_type, 0)) {
-        return DEFAULT_QUALITY;
+        sSystemTextQuality = DEFAULT_QUALITY;
+        return;
       }
 
       if (smoothing_type == FE_FONTSMOOTHINGCLEARTYPE) {
-        return CLEARTYPE_QUALITY;
+        sSystemTextQuality = CLEARTYPE_QUALITY;
+        return;
       }
 
-      return ANTIALIASED_QUALITY;
+      sSystemTextQuality = ANTIALIASED_QUALITY;
+      return;
   }
 
-  return DEFAULT_QUALITY;
+  sSystemTextQuality = DEFAULT_QUALITY;
 }
 
 static AntialiasMode
 GetSystemDefaultAAMode()
 {
   AntialiasMode defaultMode = AntialiasMode::SUBPIXEL;
   if (gfxPrefs::DisableAllTextAA()) {
     return AntialiasMode::NONE;
--- a/gfx/layers/client/ClientLayerManager.cpp
+++ b/gfx/layers/client/ClientLayerManager.cpp
@@ -30,16 +30,17 @@
 #include "mozilla/dom/WindowBinding.h"  // for Overfill Callback
 #include "FrameLayerBuilder.h"          // for FrameLayerbuilder
 #ifdef MOZ_WIDGET_ANDROID
 #include "AndroidBridge.h"
 #include "LayerMetricsWrapper.h"
 #endif
 #ifdef XP_WIN
 #include "mozilla/gfx/DeviceManagerDx.h"
+#include "gfxDWriteFonts.h"
 #endif
 
 namespace mozilla {
 namespace layers {
 
 using namespace mozilla::gfx;
 
 void
@@ -284,16 +285,24 @@ ClientLayerManager::BeginTransaction()
 
 bool
 ClientLayerManager::EndTransactionInternal(DrawPaintedLayerCallback aCallback,
                                            void* aCallbackData,
                                            EndTransactionFlags)
 {
   PaintTelemetry::AutoRecord record(PaintTelemetry::Metric::Rasterization);
 
+#ifdef WIN32
+  if (aCallbackData) {
+    // Content processes don't get OnPaint called. So update here whenever we
+    // may do Thebes drawing.
+    gfxDWriteFont::UpdateClearTypeUsage();
+  }
+#endif
+
   PROFILER_LABEL("ClientLayerManager", "EndTransactionInternal",
     js::ProfileEntry::Category::GRAPHICS);
 
 #ifdef MOZ_LAYERS_HAVE_LOG
   MOZ_LAYERS_LOG(("  ----- (beginning paint)"));
   Log();
 #endif
   profiler_tracing("Paint", "Rasterize", TRACING_INTERVAL_START);
--- a/gfx/thebes/gfxDWriteFonts.cpp
+++ b/gfx/thebes/gfxDWriteFonts.cpp
@@ -118,16 +118,17 @@ gfxDWriteFont::~gfxDWriteFont()
         cairo_scaled_font_destroy(mScaledFont);
     }
     delete mMetrics;
 }
 
 void
 gfxDWriteFont::UpdateClearTypeUsage()
 {
+  Factory::UpdateSystemTextQuality();
   mUseClearType = UsingClearType();
 }
 
 UniquePtr<gfxFont>
 gfxDWriteFont::CopyWithAntialiasOption(AntialiasOption anAAOption)
 {
     auto entry = static_cast<gfxDWriteFontEntry*>(mFontEntry.get());
     return MakeUnique<gfxDWriteFont>(entry, &mStyle, mNeedsBold, anAAOption);
--- a/widget/windows/nsWindowGfx.cpp
+++ b/widget/windows/nsWindowGfx.cpp
@@ -183,18 +183,16 @@ 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 &&