Bug 1376964 - Part 10: Allow style worker threads to pick fonts out of the user font cache. r=jfkthame draft
authorCameron McCormack <cam@mcc.id.au>
Wed, 12 Jul 2017 16:36:46 +0800
changeset 607483 c0b84679b49baf7106d9c8ee37550b99acfa0614
parent 607482 e177b5a2571659f59c6466d1685304a5f878b51d
child 637030 acfe408ac6bc73397aa8f690371e6c6ee5b35cfc
push id67987
push userbmo:cam@mcc.id.au
push dateWed, 12 Jul 2017 08:38:54 +0000
reviewersjfkthame
bugs1376964
milestone56.0a1
Bug 1376964 - Part 10: Allow style worker threads to pick fonts out of the user font cache. r=jfkthame MozReview-Commit-ID: FX0T5ltA2u4
gfx/thebes/gfxUserFontSet.cpp
--- a/gfx/thebes/gfxUserFontSet.cpp
+++ b/gfx/thebes/gfxUserFontSet.cpp
@@ -469,16 +469,22 @@ gfxUserFontEntry::ContinueLoad()
       // cases as well if possible, so that we don't have an additional restyle.
       // That doesn't work currently because nsIDocument::GetDocShell (called
       // from FontFaceSet::CheckFontLoad) dereferences a weak pointer, which is
       // not allowed in parallel traversal.
       IncrementGeneration();
     }
 }
 
+static bool
+IgnorePrincipal(gfxFontSrcURI* aURI)
+{
+    return aURI->InheritsSecurityContext();
+}
+
 void
 gfxUserFontEntry::DoLoadNextSrc(bool aForceAsync)
 {
     uint32_t numSrc = mSrcList.Length();
 
     // load each src entry in turn, until a local face is found
     // or a download begins successfully
     while (mSrcIndex < numSrc) {
@@ -530,19 +536,26 @@ gfxUserFontEntry::DoLoadNextSrc(bool aFo
         }
 
         // src url ==> start the load process
         else if (currSrc.mSourceType == gfxFontFaceSrc::eSourceType_URL) {
             if (gfxPlatform::GetPlatform()->IsFontFormatSupported(
                     currSrc.mFormatFlags)) {
 
                 if (ServoStyleSet* set = ServoStyleSet::Current()) {
-                    set->AppendTask(PostTraversalTask::LoadFontEntry(this));
-                    SetLoadState(STATUS_LOAD_PENDING);
-                    return;
+                    // Only support style worker threads synchronously getting
+                    // entries from the font cache when it's not a data: URI
+                    // @font-face that came from UA or user sheets, since we
+                    // were not able to call IsFontLoadAllowed ahead of time
+                    // for these entries.
+                    if (currSrc.mUseOriginPrincipal && IgnorePrincipal(currSrc.mURI)) {
+                        set->AppendTask(PostTraversalTask::LoadFontEntry(this));
+                        SetLoadState(STATUS_LOAD_PENDING);
+                        return;
+                    }
                 }
 
                 gfxFontSrcPrincipal* principal = nullptr;
                 bool bypassCache;
                 nsresult rv = mFontSet->CheckFontLoad(&currSrc, &principal,
                                                       &bypassCache);
 
                 if (NS_SUCCEEDED(rv) && principal != nullptr) {
@@ -562,16 +575,24 @@ gfxUserFontEntry::DoLoadNextSrc(bool aFo
                                      mFontSet, mSrcIndex,
                                      currSrc.mURI->GetSpecOrDefault().get(),
                                      NS_ConvertUTF16toUTF8(mFamilyName).get()));
                             }
                             return;
                         }
                     }
 
+                    if (ServoStyleSet* set = ServoStyleSet::Current()) {
+                        // If we need to start a font load and we're on a style
+                        // worker thread, we have to defer it.
+                        set->AppendTask(PostTraversalTask::LoadFontEntry(this));
+                        SetLoadState(STATUS_LOAD_PENDING);
+                        return;
+                    }
+
                     // record the principal returned by CheckFontLoad,
                     // for use when creating a channel
                     // and when caching the loaded entry
                     mPrincipal = principal;
 
                     bool loadDoesntSpin = false;
                     if (!aForceAsync) {
                         loadDoesntSpin = currSrc.mURI->SyncLoadIsOK();
@@ -1131,22 +1152,16 @@ gfxUserFontSet::UserFontCache::Flusher::
         }
     } else {
         NS_NOTREACHED("unexpected topic");
     }
 
     return NS_OK;
 }
 
-static bool
-IgnorePrincipal(gfxFontSrcURI* aURI)
-{
-    return aURI->InheritsSecurityContext();
-}
-
 bool
 gfxUserFontSet::UserFontCache::Entry::KeyEquals(const KeyTypePointer aKey) const
 {
     const gfxFontEntry* fe = aKey->mFontEntry;
 
     if (!mURI->Equals(aKey->mURI)) {
         return false;
     }