Bug 1495661 - reuse the default UnscaledFontDWrite for variation fonts. r=jfkthame
authorLee Salzman <lsalzman@mozilla.com>
Thu, 11 Oct 2018 11:19:25 -0400
changeset 496447 d492774b453f8e7ecdd79b71b5092e408ae005b2
parent 496446 d0c617e2d35101856d1f26431520a65187f29c78
child 496448 11f33f3c73b4d58511d16cc0fbfcf8fa9363084f
push id9984
push userffxbld-merge
push dateMon, 15 Oct 2018 21:07:35 +0000
treeherdermozilla-beta@183d27ea8570 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjfkthame
bugs1495661
milestone64.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 1495661 - reuse the default UnscaledFontDWrite for variation fonts. r=jfkthame
gfx/thebes/gfxDWriteFontList.cpp
gfx/thebes/gfxDWriteFonts.cpp
gfx/thebes/gfxDWriteFonts.h
--- a/gfx/thebes/gfxDWriteFontList.cpp
+++ b/gfx/thebes/gfxDWriteFontList.cpp
@@ -670,47 +670,40 @@ gfxDWriteFontEntry::GetVariationInstance
 }
 
 gfxFont *
 gfxDWriteFontEntry::CreateFontInstance(const gfxFontStyle* aFontStyle)
 {
     bool needsBold = aFontStyle->NeedsSyntheticBold(this);
     DWRITE_FONT_SIMULATIONS sims =
         needsBold ? DWRITE_FONT_SIMULATIONS_BOLD : DWRITE_FONT_SIMULATIONS_NONE;
-    if (HasVariations() && !aFontStyle->variationSettings.IsEmpty()) {
-        // If we need to apply variations, we can't use the cached mUnscaledFont
-        // or mUnscaledFontBold here.
-        // XXX todo: consider caching a small number of variation instances?
-        RefPtr<IDWriteFontFace> fontFace;
-        nsresult rv = CreateFontFace(getter_AddRefs(fontFace),
-                                     aFontStyle,
-                                     sims);
-        if (NS_FAILED(rv)) {
-            return nullptr;
-        }
-        RefPtr<UnscaledFontDWrite> unscaledFont =
-            new UnscaledFontDWrite(fontFace, mIsSystemFont ? mFont : nullptr, sims);
-        return new gfxDWriteFont(unscaledFont, this, aFontStyle);
-    }
-
     ThreadSafeWeakPtr<UnscaledFontDWrite>& unscaledFontPtr =
         needsBold ? mUnscaledFontBold : mUnscaledFont;
     RefPtr<UnscaledFontDWrite> unscaledFont(unscaledFontPtr);
     if (!unscaledFont) {
         RefPtr<IDWriteFontFace> fontFace;
         nsresult rv = CreateFontFace(getter_AddRefs(fontFace), aFontStyle, sims);
         if (NS_FAILED(rv)) {
             return nullptr;
         }
         unscaledFont =
             new UnscaledFontDWrite(fontFace,
                                    mIsSystemFont ? mFont : nullptr, sims);
         unscaledFontPtr = unscaledFont;
     }
-    return new gfxDWriteFont(unscaledFont, this, aFontStyle);
+    RefPtr<IDWriteFontFace> fontFace;
+    if (HasVariations() && !aFontStyle->variationSettings.IsEmpty()) {
+        nsresult rv = CreateFontFace(getter_AddRefs(fontFace),
+                                     aFontStyle,
+                                     sims);
+        if (NS_FAILED(rv)) {
+            return nullptr;
+        }
+    }
+    return new gfxDWriteFont(unscaledFont, this, aFontStyle, fontFace);
 }
 
 nsresult
 gfxDWriteFontEntry::CreateFontFace(IDWriteFontFace **aFontFace,
                                    const gfxFontStyle* aFontStyle,
                                    DWRITE_FONT_SIMULATIONS aSimulations)
 {
     // Convert an OpenType font tag from our uint32_t representation
--- a/gfx/thebes/gfxDWriteFonts.cpp
+++ b/gfx/thebes/gfxDWriteFonts.cpp
@@ -76,27 +76,27 @@ GetSystemTextQuality()
   return DEFAULT_QUALITY;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 // gfxDWriteFont
 gfxDWriteFont::gfxDWriteFont(const RefPtr<UnscaledFontDWrite>& aUnscaledFont,
                              gfxFontEntry *aFontEntry,
                              const gfxFontStyle *aFontStyle,
+                             RefPtr<IDWriteFontFace> aFontFace,
                              AntialiasOption anAAOption)
     : gfxFont(aUnscaledFont, aFontEntry, aFontStyle, anAAOption)
+    , mFontFace(aFontFace ? aFontFace : aUnscaledFont->GetFontFace())
     , mCairoFontFace(nullptr)
     , mMetrics(nullptr)
     , mSpaceGlyph(0)
     , mUseSubpixelPositions(false)
     , mAllowManualShowGlyphs(true)
     , mAzureScaledFontUsedClearType(false)
 {
-    mFontFace = aUnscaledFont->GetFontFace();
-
     // If the IDWriteFontFace1 interface is available, we can use that for
     // faster glyph width retrieval.
     mFontFace->QueryInterface(__uuidof(IDWriteFontFace1),
                               (void**)getter_AddRefs(mFontFace1));
 
     ComputeMetrics(anAAOption);
 }
 
@@ -145,17 +145,17 @@ gfxDWriteFont::SystemTextQualityChanged(
   gfxPlatform::ForceGlobalReflow();
 }
 
 UniquePtr<gfxFont>
 gfxDWriteFont::CopyWithAntialiasOption(AntialiasOption anAAOption)
 {
     auto entry = static_cast<gfxDWriteFontEntry*>(mFontEntry.get());
     RefPtr<UnscaledFontDWrite> unscaledFont = static_cast<UnscaledFontDWrite*>(mUnscaledFont.get());
-    return MakeUnique<gfxDWriteFont>(unscaledFont, entry, &mStyle, anAAOption);
+    return MakeUnique<gfxDWriteFont>(unscaledFont, entry, &mStyle, mFontFace, anAAOption);
 }
 
 const gfxFont::Metrics&
 gfxDWriteFont::GetHorizontalMetrics()
 {
     return *mMetrics;
 }
 
--- a/gfx/thebes/gfxDWriteFonts.h
+++ b/gfx/thebes/gfxDWriteFonts.h
@@ -25,16 +25,17 @@ typedef _cairo_font_face cairo_font_face
  * \brief Class representing a font face for a font entry.
  */
 class gfxDWriteFont : public gfxFont
 {
 public:
     gfxDWriteFont(const RefPtr<mozilla::gfx::UnscaledFontDWrite>& aUnscaledFont,
                   gfxFontEntry *aFontEntry,
                   const gfxFontStyle *aFontStyle,
+                  RefPtr<IDWriteFontFace> aFontFace = nullptr,
                   AntialiasOption = kAntialiasDefault);
     ~gfxDWriteFont();
 
     static void UpdateSystemTextQuality();
     static void SystemTextQualityChanged();
 
     mozilla::UniquePtr<gfxFont>
     CopyWithAntialiasOption(AntialiasOption anAAOption) override;