From 520a92573ce79e3628762e4ce06e284d50c2e548 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Tue, 21 May 2024 07:21:19 +0200 Subject: Merging upstream version 115.11.0esr. Signed-off-by: Daniel Baumann --- layout/style/FontFaceImpl.cpp | 47 ++++++++++++++++++++++++++++--------------- layout/style/FontFaceImpl.h | 20 +++++++----------- 2 files changed, 38 insertions(+), 29 deletions(-) (limited to 'layout/style') diff --git a/layout/style/FontFaceImpl.cpp b/layout/style/FontFaceImpl.cpp index 30f16e4be8..bd7e6a595f 100644 --- a/layout/style/FontFaceImpl.cpp +++ b/layout/style/FontFaceImpl.cpp @@ -676,25 +676,40 @@ bool FontFaceImpl::IsInFontFaceSet(FontFaceSetImpl* aFontFaceSet) const { void FontFaceImpl::AddFontFaceSet(FontFaceSetImpl* aFontFaceSet) { MOZ_ASSERT(!IsInFontFaceSet(aFontFaceSet)); - if (mFontFaceSet == aFontFaceSet) { - mInFontFaceSet = true; + auto doAddFontFaceSet = [&]() { + if (mFontFaceSet == aFontFaceSet) { + mInFontFaceSet = true; + } else { + mOtherFontFaceSets.AppendElement(aFontFaceSet); + } + }; + + if (mUserFontEntry) { + AutoWriteLock lock(mUserFontEntry->Lock()); + doAddFontFaceSet(); } else { - mOtherFontFaceSets.AppendElement(aFontFaceSet); + doAddFontFaceSet(); } } void FontFaceImpl::RemoveFontFaceSet(FontFaceSetImpl* aFontFaceSet) { MOZ_ASSERT(IsInFontFaceSet(aFontFaceSet)); - if (mFontFaceSet == aFontFaceSet) { - mInFontFaceSet = false; - } else { - mOtherFontFaceSets.RemoveElement(aFontFaceSet); - } + auto doRemoveFontFaceSet = [&]() { + if (mFontFaceSet == aFontFaceSet) { + mInFontFaceSet = false; + } else { + mOtherFontFaceSets.RemoveElement(aFontFaceSet); + } + }; - // The caller should be holding a strong reference to the FontFaceSetImpl. if (mUserFontEntry) { - mUserFontEntry->CheckUserFontSet(); + AutoWriteLock lock(mUserFontEntry->Lock()); + doRemoveFontFaceSet(); + // The caller should be holding a strong reference to the FontFaceSetImpl. + mUserFontEntry->CheckUserFontSetLocked(); + } else { + doRemoveFontFaceSet(); } } @@ -737,7 +752,7 @@ void FontFaceImpl::Entry::SetLoadState(UserFontLoadState aLoadState) { nsTArray> fontFaces; { - MutexAutoLock lock(mMutex); + AutoReadLock lock(mLock); fontFaces.SetCapacity(mFontFaces.Length()); for (FontFaceImpl* f : mFontFaces) { fontFaces.AppendElement(f); @@ -759,7 +774,7 @@ void FontFaceImpl::Entry::SetLoadState(UserFontLoadState aLoadState) { /* virtual */ void FontFaceImpl::Entry::GetUserFontSets( nsTArray>& aResult) { - MutexAutoLock lock(mMutex); + AutoReadLock lock(mLock); aResult.Clear(); @@ -784,7 +799,7 @@ void FontFaceImpl::Entry::GetUserFontSets( /* virtual */ already_AddRefed FontFaceImpl::Entry::GetUserFontSet() const { - MutexAutoLock lock(mMutex); + AutoReadLock lock(mLock); if (mFontSet) { return do_AddRef(mFontSet); } @@ -817,7 +832,7 @@ void FontFaceImpl::Entry::CheckUserFontSetLocked() { } void FontFaceImpl::Entry::FindFontFaceOwners(nsTHashSet& aOwners) { - MutexAutoLock lock(mMutex); + AutoReadLock lock(mLock); for (FontFaceImpl* f : mFontFaces) { if (FontFace* owner = f->GetOwner()) { aOwners.Insert(owner); @@ -826,13 +841,13 @@ void FontFaceImpl::Entry::FindFontFaceOwners(nsTHashSet& aOwners) { } void FontFaceImpl::Entry::AddFontFace(FontFaceImpl* aFontFace) { - MutexAutoLock lock(mMutex); + AutoWriteLock lock(mLock); mFontFaces.AppendElement(aFontFace); CheckUserFontSetLocked(); } void FontFaceImpl::Entry::RemoveFontFace(FontFaceImpl* aFontFace) { - MutexAutoLock lock(mMutex); + AutoWriteLock lock(mLock); mFontFaces.RemoveElement(aFontFace); CheckUserFontSetLocked(); } diff --git a/layout/style/FontFaceImpl.h b/layout/style/FontFaceImpl.h index 70c06609e9..7f1279a248 100644 --- a/layout/style/FontFaceImpl.h +++ b/layout/style/FontFaceImpl.h @@ -10,7 +10,7 @@ #include "mozilla/dom/FontFaceBinding.h" #include "mozilla/FontPropertyTypes.h" #include "mozilla/Maybe.h" -#include "mozilla/Mutex.h" +#include "mozilla/RWLock.h" #include "mozilla/ServoStyleConsts.h" #include "gfxUserFontSet.h" #include "nsCSSPropertyID.h" @@ -50,21 +50,15 @@ class FontFaceImpl final { Entry(gfxUserFontSet* aFontSet, nsTArray&& aFontFaceSrcList, gfxUserFontAttributes&& aAttr) : gfxUserFontEntry(std::move(aFontFaceSrcList), std::move(aAttr)), - mMutex("FontFaceImpl::Entry::mMutex"), mFontSet(aFontSet) {} void SetLoadState(UserFontLoadState aLoadState) override; void GetUserFontSets(nsTArray>& aResult) override; already_AddRefed GetUserFontSet() const override; - void CheckUserFontSet() { - MutexAutoLock lock(mMutex); - CheckUserFontSetLocked(); - } - #ifdef DEBUG bool HasUserFontSet(gfxUserFontSet* aFontSet) const { - MutexAutoLock lock(mMutex); + AutoReadLock lock(mLock); return mFontSet == aFontSet; } #endif @@ -73,19 +67,19 @@ class FontFaceImpl final { void RemoveFontFace(FontFaceImpl* aOwner); void FindFontFaceOwners(nsTHashSet& aOwners); - protected: - void CheckUserFontSetLocked() MOZ_REQUIRES(mMutex); + RWLock& Lock() const MOZ_RETURN_CAPABILITY(mLock) { return mLock; } - mutable Mutex mMutex; + protected: + void CheckUserFontSetLocked() MOZ_REQUIRES(mLock); // Font set which owns this entry; - gfxUserFontSet* MOZ_NON_OWNING_REF mFontSet MOZ_GUARDED_BY(mMutex); + gfxUserFontSet* MOZ_NON_OWNING_REF mFontSet MOZ_GUARDED_BY(mLock); // The FontFace objects that use this user font entry. We need to store // an array of these, not just a single pointer, since the user font // cache can return the same entry for different FontFaces that have // the same descriptor values and come from the same origin. - AutoTArray mFontFaces MOZ_GUARDED_BY(mMutex); + AutoTArray mFontFaces MOZ_GUARDED_BY(mLock); }; #ifdef DEBUG -- cgit v1.2.3