Bug 1031202 - Factor out gfxMixedFontFamily lookup/creation into a helper function. r=jdaggett
☠☠ backed out by f0bc5656c80c ☠ ☠
authorCameron McCormack <cam@mcc.id.au>
Wed, 09 Jul 2014 21:04:15 +1000
changeset 193072 30954594c1dd25aa7915bc9acdf7660efb5c8c8f
parent 193071 dc4ff3a5afd1b1d85a31a5d124e04462919ff977
child 193073 5c7d59444dcadba3c2535b5c4bce44d15c1ed344
push id27107
push userryanvm@gmail.com
push dateWed, 09 Jul 2014 19:45:31 +0000
treeherdermozilla-central@6db315bcdb6a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdaggett
bugs1031202
milestone33.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 1031202 - Factor out gfxMixedFontFamily lookup/creation into a helper function. r=jdaggett
gfx/thebes/gfxFont.cpp
gfx/thebes/gfxPangoFonts.cpp
gfx/thebes/gfxUserFontSet.cpp
gfx/thebes/gfxUserFontSet.h
--- a/gfx/thebes/gfxFont.cpp
+++ b/gfx/thebes/gfxFont.cpp
@@ -5175,17 +5175,17 @@ gfxFontGroup::FindPlatformFont(const nsA
         // First, look up in the user font set...
         // If the fontSet matches the family, we must not look for a platform
         // font of the same name, even if we fail to actually get a fontEntry
         // here; we'll fall back to the next name in the CSS font-family list.
         if (mUserFontSet) {
             // If the fontSet matches the family, but the font has not yet finished
             // loading (nor has its load timeout fired), the fontGroup should wait
             // for the download, and not actually draw its text yet.
-            family = mUserFontSet->GetFamily(aName);
+            family = mUserFontSet->LookupFamily(aName);
             if (family) {
                 bool waitForUserFont = false;
                 fe = mUserFontSet->FindFontEntry(family, mStyle,
                                                  needsBold, waitForUserFont);
                 if (!fe && waitForUserFont) {
                     mSkipDrawing = true;
                 }
             }
--- a/gfx/thebes/gfxPangoFonts.cpp
+++ b/gfx/thebes/gfxPangoFonts.cpp
@@ -789,17 +789,17 @@ FindFontPatterns(gfxUserFontSet *mUserFo
     bool needsBold;
 
     gfxFontStyle style;
     style.style = aStyle;
     style.weight = aWeight;
     style.stretch = aStretch;
 
     gfxUserFcFontEntry *fontEntry = nullptr;
-    gfxFontFamily *family = mUserFontSet->GetFamily(utf16Family);
+    gfxFontFamily *family = mUserFontSet->LookupFamily(utf16Family);
     if (family) {
         fontEntry = static_cast<gfxUserFcFontEntry*>
             (mUserFontSet->FindFontEntry(family, style, needsBold,
                                          aWaitForUserFont));
 
         // Accept synthetic oblique for italic and oblique.
         if (!fontEntry && aStyle != NS_FONT_STYLE_NORMAL) {
             style.style = NS_FONT_STYLE_NORMAL;
--- a/gfx/thebes/gfxUserFontSet.cpp
+++ b/gfx/thebes/gfxUserFontSet.cpp
@@ -590,28 +590,19 @@ gfxUserFontSet::AddFontFace(const nsAStr
                             uint32_t aItalicStyle,
                             const nsTArray<gfxFontFeature>& aFeatureSettings,
                             uint32_t aLanguageOverride,
                             gfxSparseBitSet *aUnicodeRanges)
 {
     MOZ_ASSERT(aWeight != 0,
                "aWeight must not be 0; use NS_FONT_WEIGHT_NORMAL instead");
 
-    nsAutoString key(aFamilyName);
-    ToLowerCase(key);
-
-    bool found;
-
     // stretch, italic/oblique ==> zero implies normal
 
-    gfxMixedFontFamily *family = mFontFamilies.GetWeak(key, &found);
-    if (!family) {
-        family = new gfxMixedFontFamily(aFamilyName);
-        mFontFamilies.Put(key, family);
-    }
+    gfxMixedFontFamily* family = GetFamily(aFamilyName);
 
     // If there's already a proxy in the family whose descriptors all match,
     // we can just move it to the end of the list instead of adding a new
     // face that will always "shadow" the old one.
     // Note that we can't do this for "real" (non-proxy) entries, even if the
     // style descriptors match, as they might have had a different source list,
     // but we no longer have the old source list available to check.
     nsTArray<nsRefPtr<gfxFontEntry> >& fontList = family->GetFontList();
@@ -658,27 +649,17 @@ gfxUserFontSet::AddFontFace(const nsAStr
 
     return proxyEntry;
 }
 
 void
 gfxUserFontSet::AddFontFace(const nsAString& aFamilyName,
                             gfxFontEntry     *aFontEntry)
 {
-    nsAutoString key(aFamilyName);
-    ToLowerCase(key);
-
-    bool found;
-
-    gfxMixedFontFamily *family = mFontFamilies.GetWeak(key, &found);
-    if (!family) {
-        family = new gfxMixedFontFamily(aFamilyName);
-        mFontFamilies.Put(key, family);
-    }
-
+    gfxMixedFontFamily* family = GetFamily(aFamilyName);
     family->AddFontEntry(aFontEntry);
 }
 
 gfxFontEntry*
 gfxUserFontSet::FindFontEntry(gfxFontFamily *aFamily,
                               const gfxFontStyle& aFontStyle,
                               bool& aNeedsBold,
                               bool& aWaitForUserFont)
@@ -782,25 +763,39 @@ gfxUserFontSet::IncrementGeneration()
 void
 gfxUserFontSet::RebuildLocalRules()
 {
     if (mLocalRulesUsed) {
         DoRebuildUserFontSet();
     }
 }
 
-gfxFontFamily*
-gfxUserFontSet::GetFamily(const nsAString& aFamilyName) const
+gfxMixedFontFamily*
+gfxUserFontSet::LookupFamily(const nsAString& aFamilyName) const
 {
     nsAutoString key(aFamilyName);
     ToLowerCase(key);
 
     return mFontFamilies.GetWeak(key);
 }
 
+gfxMixedFontFamily*
+gfxUserFontSet::GetFamily(const nsAString& aFamilyName)
+{
+    nsAutoString key(aFamilyName);
+    ToLowerCase(key);
+
+    gfxMixedFontFamily* family = mFontFamilies.GetWeak(key);
+    if (!family) {
+        family = new gfxMixedFontFamily(aFamilyName);
+        mFontFamilies.Put(key, family);
+    }
+    return family;
+}
+
 struct FindFamilyCallbackData {
     gfxFontEntry  *mFontEntry;
     gfxFontFamily *mFamily;
 };
 
 static PLDHashOperator
 FindFamilyCallback(const nsAString&    aName,
                    gfxMixedFontFamily* aFamily,
--- a/gfx/thebes/gfxUserFontSet.h
+++ b/gfx/thebes/gfxUserFontSet.h
@@ -183,23 +183,25 @@ public:
                               gfxSparseBitSet *aUnicodeRanges = nullptr);
 
     // add in a font face for which we have the gfxFontEntry already
     void AddFontFace(const nsAString& aFamilyName, gfxFontEntry* aFontEntry);
 
     // Whether there is a face with this family name
     bool HasFamily(const nsAString& aFamilyName) const
     {
-        return GetFamily(aFamilyName) != nullptr;
+        return LookupFamily(aFamilyName) != nullptr;
     }
 
-    gfxFontFamily *GetFamily(const nsAString& aName) const;
+    // Look up and return the gfxMixedFontFamily in mFontFamilies with
+    // the given name
+    gfxMixedFontFamily* LookupFamily(const nsAString& aName) const;
 
     // Lookup a font entry for a given style, returns null if not loaded.
-    // aFamily must be a family returned by our GetFamily method.
+    // aFamily must be a family returned by our LookupFamily method.
     gfxFontEntry *FindFontEntry(gfxFontFamily *aFamily,
                                 const gfxFontStyle& aFontStyle,
                                 bool& aNeedsBold,
                                 bool& aWaitForUserFont);
 
     // Find a family (possibly one of several!) that owns the given entry.
     // This may be somewhat expensive, as it enumerates all the fonts in
     // the set. Currently used only by the Linux (gfxPangoFontGroup) backend,
@@ -425,16 +427,20 @@ protected:
                                 gfxProxyFontEntry *aProxy,
                                 const char *aMessage,
                                 uint32_t aFlags = nsIScriptError::errorFlag,
                                 nsresult aStatus = NS_OK) = 0;
 
     // helper method for performing the actual userfont set rebuild
     virtual void DoRebuildUserFontSet() = 0;
 
+    // creates a new gfxMixedFontFamily in mFontFamilies, or returns an existing
+    // family if there is one
+    gfxMixedFontFamily* GetFamily(const nsAString& aFamilyName);
+
     // font families defined by @font-face rules
     nsRefPtrHashtable<nsStringHashKey, gfxMixedFontFamily> mFontFamilies;
 
     uint64_t        mGeneration;
 
     // true when local names have been looked up, false otherwise
     bool mLocalRulesUsed;