From da4c7e7ed675c3bf405668739c3012d140856109 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 15 May 2024 05:34:42 +0200 Subject: Adding upstream version 126.0. Signed-off-by: Daniel Baumann --- gfx/thebes/gfxUserFontSet.cpp | 43 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 9 deletions(-) (limited to 'gfx/thebes/gfxUserFontSet.cpp') diff --git a/gfx/thebes/gfxUserFontSet.cpp b/gfx/thebes/gfxUserFontSet.cpp index e9a2f513b3..c761bd9227 100644 --- a/gfx/thebes/gfxUserFontSet.cpp +++ b/gfx/thebes/gfxUserFontSet.cpp @@ -20,6 +20,7 @@ #include "mozilla/PostTraversalTask.h" #include "mozilla/dom/WorkerCommon.h" #include "gfxOTSUtils.h" +#include "nsFontFaceLoader.h" #include "nsIFontLoadCompleteCallback.h" #include "nsProxyRelease.h" #include "nsContentUtils.h" @@ -392,6 +393,12 @@ void gfxUserFontEntry::LoadNextSrc() { } void gfxUserFontEntry::ContinueLoad() { + if (mUserFontLoadState == STATUS_NOT_LOADED) { + // We must have been cancelled (possibly due to a font-list refresh) while + // the runnable was pending, so just bail out. + return; + } + MOZ_ASSERT(mUserFontLoadState == STATUS_LOAD_PENDING); MOZ_ASSERT(mSrcList[mCurrentSrcIndex].mSourceType == gfxFontFaceSrc::eSourceType_URL); @@ -974,7 +981,8 @@ gfxUserFontSet::gfxUserFontSet() mLocalRulesUsed(false), mRebuildLocalRules(false), mDownloadCount(0), - mDownloadSize(0) { + mDownloadSize(0), + mMutex("gfxUserFontSet") { IncrementGeneration(true); } @@ -1057,7 +1065,7 @@ void gfxUserFontSet::AddUserFontEntry(const nsCString& aFamilyName, } } -void gfxUserFontSet::IncrementGeneration(bool aIsRebuild) { +void gfxUserFontSet::IncrementGenerationLocked(bool aIsRebuild) { // add one, increment again if zero do { mGeneration = ++sFontSetGeneration; @@ -1097,6 +1105,10 @@ void gfxUserFontSet::ForgetLocalFaces() { } void gfxUserFontSet::ForgetLocalFace(gfxUserFontFamily* aFontFamily) { + // Entries for which we might need to cancel a current loader. + AutoTArray, 8> entriesToCancel; + + // Lock the font family while we iterate over its entries. aFontFamily->ReadLock(); const auto& fonts = aFontFamily->GetFontList(); for (const auto& f : fonts) { @@ -1107,14 +1119,28 @@ void gfxUserFontSet::ForgetLocalFace(gfxUserFontFamily* aFontFamily) { ufe->GetPlatformFontEntry()->IsLocalUserFont()) { ufe->mPlatformFontEntry = nullptr; } - // We need to re-evaluate the source list in the context of the new - // platform fontlist, whether or not the entry actually used a local() - // source last time, as one might be newly available. + // If the entry had a local source, we need to re-evaluate the source list + // in the context of the new platform fontlist, whether or not the entry + // actually used a local() source last time, as one might have been added. if (ufe->mSeenLocalSource) { - ufe->LoadCanceled(); + entriesToCancel.AppendElement(ufe); } } aFontFamily->ReadUnlock(); + + // Cancel any current loaders and reset the state of the affected entries. + for (auto& ufe : entriesToCancel) { + if (auto* loader = ufe->GetLoader()) { + // If there's a loader, we need to cancel it, because we'll trigger a + // fresh load if required when we re-resolve the font... + loader->Cancel(); + RemoveLoader(loader); + } else { + // ...otherwise, just reset our state so that we'll re-evaluate the + // source list from the beginning. + ufe->LoadCanceled(); + } + } } /////////////////////////////////////////////////////////////////////////////// @@ -1209,7 +1235,7 @@ void gfxUserFontSet::UserFontCache::CacheFont(gfxFontEntry* aFontEntry) { "caching a font associated with no family yet"); // if caching is disabled, simply return - if (Preferences::GetBool("gfx.downloadable_fonts.disable_cache")) { + if (StaticPrefs::gfx_downloadable_fonts_disable_cache()) { return; } @@ -1282,8 +1308,7 @@ void gfxUserFontSet::UserFontCache::ForgetFont(gfxFontEntry* aFontEntry) { gfxFontEntry* gfxUserFontSet::UserFontCache::GetFont( const gfxFontFaceSrc& aSrc, const gfxUserFontEntry& aUserFontEntry) { - if (!sUserFonts || - Preferences::GetBool("gfx.downloadable_fonts.disable_cache")) { + if (!sUserFonts || StaticPrefs::gfx_downloadable_fonts_disable_cache()) { return nullptr; } -- cgit v1.2.3