Bug 1778608 - Fix FontFaceSetWorkerImpl destruction off main thread. r=emilio

The loaders need to be destroyed on the main thread. Assertions for
gfxUserFontSet and gfxFontFamily need to be updated for workers.

Depends on D151342

Differential Revision: https://phabricator.services.mozilla.com/D151343
This commit is contained in:
Andrew Osmond 2022-07-08 17:34:46 +00:00
Родитель fc4e22dac5
Коммит ccb3289c49
3 изменённых файлов: 32 добавлений и 2 удалений

Просмотреть файл

@ -1918,7 +1918,7 @@ void gfxFontFamily::SearchAllFontsForChar(GlobalFontMatch* aMatchData) {
gfxFontFamily::~gfxFontFamily() {
// Should not be dropped by stylo, but the InitFontList thread might use
// a transient gfxFontFamily and that's OK.
MOZ_ASSERT(NS_IsMainThread() || gfxPlatformFontList::IsInitFontListThread());
MOZ_ASSERT(!gfxFontUtils::IsInServoTraversal());
}
// returns true if other names were found, false otherwise

Просмотреть файл

@ -250,7 +250,7 @@ size_t gfxUserFontData::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const {
/*virtual*/
gfxUserFontFamily::~gfxUserFontFamily() {
// Should not be dropped by stylo
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(!gfxFontUtils::IsInServoTraversal());
}
already_AddRefed<gfxFontSrcPrincipal> gfxFontFaceSrc::LoadPrincipal(

Просмотреть файл

@ -135,6 +135,36 @@ void FontFaceSetWorkerImpl::InitializeOnMainThread() {
void FontFaceSetWorkerImpl::Destroy() {
RecursiveMutexAutoLock lock(mMutex);
class DestroyRunnable final : public Runnable {
public:
DestroyRunnable(FontFaceSetWorkerImpl* aFontFaceSet,
nsTHashtable<nsPtrHashKey<nsFontFaceLoader>>&& aLoaders)
: Runnable("FontFaceSetWorkerImpl::Destroy"),
mFontFaceSet(aFontFaceSet),
mLoaders(std::move(aLoaders)) {}
protected:
~DestroyRunnable() override = default;
NS_IMETHOD Run() override {
for (const auto& key : mLoaders.Keys()) {
key->Cancel();
}
return NS_OK;
}
// We save a reference to the FontFaceSetWorkerImpl because the loaders
// contain a non-owning reference to it.
RefPtr<FontFaceSetWorkerImpl> mFontFaceSet;
nsTHashtable<nsPtrHashKey<nsFontFaceLoader>> mLoaders;
};
if (!mLoaders.IsEmpty() && !NS_IsMainThread()) {
auto runnable = MakeRefPtr<DestroyRunnable>(this, std::move(mLoaders));
NS_DispatchToMainThread(runnable);
}
mWorkerRef = nullptr;
FontFaceSetImpl::Destroy();
}