зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1818417 - Tweak nsFontFaceLoader destruction to be more consistent. r=jfkthame
Differential Revision: https://phabricator.services.mozilla.com/D170744
This commit is contained in:
Родитель
ea7b7a528c
Коммит
d822650349
|
@ -87,24 +87,56 @@ FontFaceSetImpl::~FontFaceSetImpl() {
|
|||
Destroy();
|
||||
}
|
||||
|
||||
void FontFaceSetImpl::DestroyLoaders() {
|
||||
mMutex.AssertCurrentThreadIn();
|
||||
if (mLoaders.IsEmpty()) {
|
||||
return;
|
||||
}
|
||||
if (NS_IsMainThread()) {
|
||||
for (const auto& key : mLoaders.Keys()) {
|
||||
key->Cancel();
|
||||
}
|
||||
mLoaders.Clear();
|
||||
return;
|
||||
}
|
||||
|
||||
class DestroyLoadersRunnable final : public Runnable {
|
||||
public:
|
||||
explicit DestroyLoadersRunnable(FontFaceSetImpl* aFontFaceSet)
|
||||
: Runnable("FontFaceSetImpl::DestroyLoaders"),
|
||||
mFontFaceSet(aFontFaceSet) {}
|
||||
|
||||
protected:
|
||||
~DestroyLoadersRunnable() override = default;
|
||||
|
||||
NS_IMETHOD Run() override {
|
||||
RecursiveMutexAutoLock lock(mFontFaceSet->mMutex);
|
||||
mFontFaceSet->DestroyLoaders();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// We need to save a reference to the FontFaceSetImpl because the
|
||||
// loaders contain a non-owning reference to it.
|
||||
RefPtr<FontFaceSetImpl> mFontFaceSet;
|
||||
};
|
||||
|
||||
auto runnable = MakeRefPtr<DestroyLoadersRunnable>(this);
|
||||
NS_DispatchToMainThread(runnable);
|
||||
}
|
||||
|
||||
void FontFaceSetImpl::Destroy() {
|
||||
nsTArray<FontFaceRecord> nonRuleFaces;
|
||||
nsRefPtrHashtable<nsCStringHashKey, gfxUserFontFamily> fontFamilies;
|
||||
|
||||
{
|
||||
RecursiveMutexAutoLock lock(mMutex);
|
||||
for (const auto& key : mLoaders.Keys()) {
|
||||
key->Cancel();
|
||||
}
|
||||
|
||||
mLoaders.Clear();
|
||||
DestroyLoaders();
|
||||
nonRuleFaces = std::move(mNonRuleFaces);
|
||||
fontFamilies = std::move(mFontFamilies);
|
||||
mOwner = nullptr;
|
||||
}
|
||||
|
||||
gfxPlatformFontList* fp = gfxPlatformFontList::PlatformFontList();
|
||||
if (fp) {
|
||||
if (gfxPlatformFontList* fp = gfxPlatformFontList::PlatformFontList()) {
|
||||
fp->RemoveUserFontSet(this);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -79,6 +79,8 @@ class FontFaceSetImpl : public nsISupports, public gfxUserFontSet {
|
|||
|
||||
explicit FontFaceSetImpl(FontFaceSet* aOwner);
|
||||
|
||||
void DestroyLoaders();
|
||||
|
||||
public:
|
||||
virtual void Destroy();
|
||||
virtual bool IsOnOwningThread() = 0;
|
||||
|
|
|
@ -136,34 +136,6 @@ void FontFaceSetWorkerImpl::InitializeOnMainThread() {
|
|||
void FontFaceSetWorkerImpl::Destroy() {
|
||||
RecursiveMutexAutoLock lock(mMutex);
|
||||
|
||||
class DestroyLoadersRunnable final : public Runnable {
|
||||
public:
|
||||
explicit DestroyLoadersRunnable(FontFaceSetWorkerImpl* aFontFaceSet)
|
||||
: Runnable("FontFaceSetWorkerImpl::Destroy"),
|
||||
mFontFaceSet(aFontFaceSet) {}
|
||||
|
||||
protected:
|
||||
~DestroyLoadersRunnable() override = default;
|
||||
|
||||
NS_IMETHOD Run() override {
|
||||
RecursiveMutexAutoLock lock(mFontFaceSet->mMutex);
|
||||
for (const auto& key : mFontFaceSet->mLoaders.Keys()) {
|
||||
key->Cancel();
|
||||
}
|
||||
mFontFaceSet->mLoaders.Clear();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// We need to save a reference to the FontFaceSetWorkerImpl because the
|
||||
// loaders contain a non-owning reference to it.
|
||||
RefPtr<FontFaceSetWorkerImpl> mFontFaceSet;
|
||||
};
|
||||
|
||||
if (!mLoaders.IsEmpty() && !NS_IsMainThread()) {
|
||||
auto runnable = MakeRefPtr<DestroyLoadersRunnable>(this);
|
||||
NS_DispatchToMainThread(runnable);
|
||||
}
|
||||
|
||||
mWorkerRef = nullptr;
|
||||
FontFaceSetImpl::Destroy();
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче