From 328078c4d259e52db1a4848c00ee0b420775c91c Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 8 Apr 2024 17:18:07 +0200 Subject: Adding upstream version 115.9.0esr. Signed-off-by: Daniel Baumann --- gfx/thebes/SharedFontList.cpp | 35 +++++++++++++++++++++++------------ gfx/thebes/SharedFontList.h | 3 ++- gfx/thebes/gfxUserFontSet.cpp | 13 +++++++++++-- 3 files changed, 36 insertions(+), 15 deletions(-) (limited to 'gfx/thebes') diff --git a/gfx/thebes/SharedFontList.cpp b/gfx/thebes/SharedFontList.cpp index f97e7e2832..83b389cd16 100644 --- a/gfx/thebes/SharedFontList.cpp +++ b/gfx/thebes/SharedFontList.cpp @@ -168,7 +168,11 @@ class SetCharMapRunnable : public mozilla::Runnable { void Face::SetCharacterMap(FontList* aList, gfxCharacterMap* aCharMap, const Family* aFamily) { if (!XRE_IsParentProcess()) { - std::pair familyIndex = aFamily->FindIndex(aList); + Maybe> familyIndex = aFamily->FindIndex(aList); + if (!familyIndex) { + NS_WARNING("Family index not found! Ignoring SetCharacterMap"); + return; + } const auto* faces = aFamily->Faces(aList); uint32_t faceIndex = 0; while (faceIndex < aFamily->NumFaces()) { @@ -177,14 +181,17 @@ void Face::SetCharacterMap(FontList* aList, gfxCharacterMap* aCharMap, } ++faceIndex; } - MOZ_RELEASE_ASSERT(faceIndex < aFamily->NumFaces(), "Face ptr not found!"); + if (faceIndex >= aFamily->NumFaces()) { + NS_WARNING("Face not found in family! Ignoring SetCharacterMap"); + return; + } if (NS_IsMainThread()) { dom::ContentChild::GetSingleton()->SendSetCharacterMap( - aList->GetGeneration(), familyIndex.first, familyIndex.second, + aList->GetGeneration(), familyIndex->first, familyIndex->second, faceIndex, *aCharMap); } else { NS_DispatchToMainThread(new SetCharMapRunnable( - aList->GetGeneration(), familyIndex, faceIndex, aCharMap)); + aList->GetGeneration(), familyIndex.value(), faceIndex, aCharMap)); } return; } @@ -629,16 +636,20 @@ void Family::SetupFamilyCharMap(FontList* aList) { if (!XRE_IsParentProcess()) { // |this| could be a Family record in either the Families() or Aliases() // arrays; FindIndex will map it back to its index and which array. - std::pair index = FindIndex(aList); + Maybe> index = FindIndex(aList); + if (!index) { + NS_WARNING("Family index not found! Ignoring SetupFamilyCharMap"); + return; + } if (NS_IsMainThread()) { dom::ContentChild::GetSingleton()->SendSetupFamilyCharMap( - aList->GetGeneration(), index.first, index.second); + aList->GetGeneration(), index->first, index->second); return; } NS_DispatchToMainThread(NS_NewRunnableFunction( "SetupFamilyCharMap callback", - [gen = aList->GetGeneration(), idx = index.first, - alias = index.second] { + [gen = aList->GetGeneration(), idx = index->first, + alias = index->second] { dom::ContentChild::GetSingleton()->SendSetupFamilyCharMap(gen, idx, alias); })); @@ -685,13 +696,13 @@ void Family::SetupFamilyCharMap(FontList* aList) { } } -std::pair Family::FindIndex(FontList* aList) const { +Maybe> Family::FindIndex(FontList* aList) const { const auto* start = aList->Families(); const auto* end = start + aList->NumFamilies(); if (this >= start && this < end) { uint32_t index = this - start; MOZ_RELEASE_ASSERT(start + index == this, "misaligned Family ptr!"); - return std::pair(index, false); + return Some(std::pair(index, false)); } start = aList->AliasFamilies(); @@ -699,10 +710,10 @@ std::pair Family::FindIndex(FontList* aList) const { if (this >= start && this < end) { uint32_t index = this - start; MOZ_RELEASE_ASSERT(start + index == this, "misaligned AliasFamily ptr!"); - return std::pair(index, true); + return Some(std::pair(index, true)); } - MOZ_CRASH("invalid font-list Family ptr!"); + return Nothing(); } FontList::FontList(uint32_t aGeneration) { diff --git a/gfx/thebes/SharedFontList.h b/gfx/thebes/SharedFontList.h index 279bbd1a57..289dd7364a 100644 --- a/gfx/thebes/SharedFontList.h +++ b/gfx/thebes/SharedFontList.h @@ -333,7 +333,8 @@ struct Family { // Return the index of this family in the font-list's Families() or // AliasFamilies() list, and which of those it belongs to. - std::pair FindIndex(FontList* aList) const; + // Returns Nothing if the family cannot be found. + mozilla::Maybe> FindIndex(FontList* aList) const; private: // Returns true if there are specifically-sized bitmap faces in the list, diff --git a/gfx/thebes/gfxUserFontSet.cpp b/gfx/thebes/gfxUserFontSet.cpp index 1d83a34977..0c7c6d24e1 100644 --- a/gfx/thebes/gfxUserFontSet.cpp +++ b/gfx/thebes/gfxUserFontSet.cpp @@ -18,6 +18,7 @@ #include "mozilla/gfx/2D.h" #include "gfxPlatformFontList.h" #include "mozilla/PostTraversalTask.h" +#include "mozilla/dom/WorkerCommon.h" #include "gfxOTSUtils.h" #include "nsIFontLoadCompleteCallback.h" #include "nsProxyRelease.h" @@ -786,9 +787,17 @@ bool gfxUserFontEntry::LoadPlatformFont(uint32_t aSrcIndex, } void gfxUserFontEntry::Load() { - if (mUserFontLoadState == STATUS_NOT_LOADED) { - LoadNextSrc(); + if (mUserFontLoadState != STATUS_NOT_LOADED) { + return; + } + if (dom::IsCurrentThreadRunningWorker()) { + // TODO: Maybe support loading the font entry in workers, at least for + // buffers or other sync sources? + NS_DispatchToMainThread(NewRunnableMethod("gfxUserFontEntry::Load", this, + &gfxUserFontEntry::Load)); + return; } + LoadNextSrc(); } void gfxUserFontEntry::IncrementGeneration() { -- cgit v1.2.3