зеркало из https://github.com/mozilla/gecko-dev.git
Backed out 3 changesets (bug 1803406) for causing wd failures.
Backed out changeset d4cfac1ac9c6 (bug 1803406) Backed out changeset 30d9711bf362 (bug 1803406) Backed out changeset 3e5d60c6826a (bug 1803406)
This commit is contained in:
Родитель
9f59e6f7da
Коммит
1768901d9e
|
@ -185,13 +185,8 @@ class gfxMacPlatformFontList final : public gfxPlatformFontList {
|
|||
void InitSingleFaceList() MOZ_REQUIRES(mLock);
|
||||
void InitAliasesForSingleFaceList() MOZ_REQUIRES(mLock);
|
||||
|
||||
// Initialize system fonts: called from RegisterFonts thread before the
|
||||
// font list is instantiated.
|
||||
static void InitSystemFontNames();
|
||||
|
||||
// Create the gfxFontFamily entry for the system font, if needed (because
|
||||
// it is hidden from the normal font lookup APIs).
|
||||
void CreateSystemFontFamily() MOZ_REQUIRES(mLock);
|
||||
// initialize system fonts
|
||||
void InitSystemFontNames() MOZ_REQUIRES(mLock);
|
||||
|
||||
// helper function to lookup in both hidden system fonts and normal fonts
|
||||
gfxFontFamily* FindSystemFontFamily(const nsACString& aFamily)
|
||||
|
@ -252,15 +247,13 @@ class gfxMacPlatformFontList final : public gfxPlatformFontList {
|
|||
// default font for use with system-wide font fallback
|
||||
CTFontRef mDefaultFont;
|
||||
|
||||
// Font families that -apple-system maps to.
|
||||
// font families that -apple-system maps to
|
||||
// Pre-10.11 this was always a single font family, such as Lucida Grande
|
||||
// or Helvetica Neue. For OSX 10.11, Apple uses pair of families
|
||||
// for the UI, one for text sizes and another for display sizes.
|
||||
// These are set up early during startup (before gfxPlatform initialization),
|
||||
// and so locking is not required.
|
||||
static bool sUseSizeSensitiveSystemFont;
|
||||
static nsCString sSystemTextFontFamilyName;
|
||||
static nsCString sSystemDisplayFontFamilyName; // only used on OSX 10.11
|
||||
// for the UI, one for text sizes and another for display sizes
|
||||
bool mUseSizeSensitiveSystemFont;
|
||||
nsCString mSystemTextFontFamilyName;
|
||||
nsCString mSystemDisplayFontFamilyName; // only used on OSX 10.11
|
||||
|
||||
nsTArray<nsCString> mSingleFaceFonts;
|
||||
nsTArray<nsCString> mPreloadFonts;
|
||||
|
|
|
@ -255,10 +255,6 @@ constexpr nsLiteralCString kDeprecatedFontFamilies[] = {
|
|||
};
|
||||
#endif // USE_DEPRECATED_FONT_FAMILY_NAMES
|
||||
|
||||
bool gfxMacPlatformFontList::sUseSizeSensitiveSystemFont = false;
|
||||
nsCString gfxMacPlatformFontList::sSystemTextFontFamilyName;
|
||||
nsCString gfxMacPlatformFontList::sSystemDisplayFontFamilyName; // only used on OSX 10.11
|
||||
|
||||
// indexes into the NSArray objects that the Cocoa font manager returns
|
||||
// as the available members of a family
|
||||
#define INDEX_FONT_POSTSCRIPT_NAME 0
|
||||
|
@ -1052,7 +1048,7 @@ void gfxSingleFaceMacFontFamily::ReadOtherFamilyNames(gfxPlatformFontList* aPlat
|
|||
#pragma mark -
|
||||
|
||||
gfxMacPlatformFontList::gfxMacPlatformFontList()
|
||||
: gfxPlatformFontList(false), mDefaultFont(nullptr) {
|
||||
: gfxPlatformFontList(false), mDefaultFont(nullptr), mUseSizeSensitiveSystemFont(false) {
|
||||
CheckFamilyList(kBaseFonts);
|
||||
|
||||
#ifdef MOZ_BUNDLED_FONTS
|
||||
|
@ -1088,17 +1084,12 @@ gfxMacPlatformFontList::~gfxMacPlatformFontList() {
|
|||
if (mDefaultFont) {
|
||||
::CFRelease(mDefaultFont);
|
||||
}
|
||||
|
||||
// Discard strings that were initialized during startup; we won't be using
|
||||
// them any more, and they'll be reported as leaks otherwise.
|
||||
sSystemTextFontFamilyName.Truncate();
|
||||
sSystemDisplayFontFamilyName.Truncate();
|
||||
}
|
||||
|
||||
void gfxMacPlatformFontList::AddFamily(const nsACString& aFamilyName, FontVisibility aVisibility) {
|
||||
double sizeHint = 0.0;
|
||||
if (aVisibility == FontVisibility::Hidden && sUseSizeSensitiveSystemFont &&
|
||||
sSystemDisplayFontFamilyName.Equals(aFamilyName)) {
|
||||
if (aVisibility == FontVisibility::Hidden && mUseSizeSensitiveSystemFont &&
|
||||
mSystemDisplayFontFamilyName.Equals(aFamilyName)) {
|
||||
sizeHint = 128.0;
|
||||
}
|
||||
|
||||
|
@ -1192,36 +1183,20 @@ void gfxMacPlatformFontList::ActivateFontsFromDir(const nsACString& aDir,
|
|||
}
|
||||
} while (result != kCFURLEnumeratorEnd);
|
||||
|
||||
if (!CFArrayGetCount(urls)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If CTFontManagerRegisterFontURLs is available (10.15+) use this in preference to
|
||||
// the deprecated CTFontManagerRegisterFontsForURLs API.
|
||||
typedef bool (^FontRegistrationHandler)(CFArrayRef, bool);
|
||||
typedef void (*CTFontManagerRegisterFontURLsFn)(CFArrayRef, CTFontManagerScope, bool,
|
||||
FontRegistrationHandler);
|
||||
static CTFontManagerRegisterFontURLsFn CTFontManagerRegisterFontURLsPtr =
|
||||
(CTFontManagerRegisterFontURLsFn)dlsym(RTLD_DEFAULT, "CTFontManagerRegisterFontURLs");
|
||||
|
||||
if (CTFontManagerRegisterFontURLsPtr) {
|
||||
CTFontManagerRegisterFontURLsPtr(urls, kCTFontManagerScopeProcess, false, nullptr);
|
||||
} else {
|
||||
CTFontManagerRegisterFontsForURLs(urls, kCTFontManagerScopeProcess, nullptr);
|
||||
}
|
||||
CTFontManagerRegisterFontsForURLs(urls, kCTFontManagerScopeProcess, nullptr);
|
||||
}
|
||||
|
||||
void gfxMacPlatformFontList::ReadSystemFontList(dom::SystemFontList* aList)
|
||||
MOZ_NO_THREAD_SAFETY_ANALYSIS {
|
||||
// Note: We rely on the records for sSystemTextFontFamilyName and
|
||||
// sSystemDisplayFontFamilyName (if present) being *before* the main
|
||||
// Note: We rely on the records for mSystemTextFontFamilyName and
|
||||
// mSystemDisplayFontFamilyName (if present) being *before* the main
|
||||
// font list, so that those names are known in the content process
|
||||
// by the time we add the actual family records to the font list.
|
||||
aList->entries().AppendElement(FontFamilyListEntry(
|
||||
sSystemTextFontFamilyName, FontVisibility::Unknown, kTextSizeSystemFontFamily));
|
||||
if (sUseSizeSensitiveSystemFont) {
|
||||
mSystemTextFontFamilyName, FontVisibility::Unknown, kTextSizeSystemFontFamily));
|
||||
if (mUseSizeSensitiveSystemFont) {
|
||||
aList->entries().AppendElement(FontFamilyListEntry(
|
||||
sSystemDisplayFontFamilyName, FontVisibility::Unknown, kDisplaySizeSystemFontFamily));
|
||||
mSystemDisplayFontFamilyName, FontVisibility::Unknown, kDisplaySizeSystemFontFamily));
|
||||
}
|
||||
// Now collect the list of available families, with visibility attributes.
|
||||
for (auto f = mFontFamilies.Iter(); !f.Done(); f.Next()) {
|
||||
|
@ -1265,7 +1240,7 @@ nsresult gfxMacPlatformFontList::InitFontListForPlatform() {
|
|||
|
||||
Telemetry::AutoTimer<Telemetry::MAC_INITFONTLIST_TOTAL> timer;
|
||||
|
||||
CreateSystemFontFamily();
|
||||
InitSystemFontNames();
|
||||
|
||||
if (XRE_IsParentProcess()) {
|
||||
static bool firstTime = true;
|
||||
|
@ -1301,18 +1276,18 @@ nsresult gfxMacPlatformFontList::InitFontListForPlatform() {
|
|||
// On Catalina or later, we pre-initialize system font-family entries
|
||||
// in InitSystemFontNames(), so we can just skip them here.
|
||||
if (nsCocoaFeatures::OnCatalinaOrLater() &&
|
||||
(ffe.familyName() == sSystemTextFontFamilyName ||
|
||||
ffe.familyName() == sSystemDisplayFontFamilyName)) {
|
||||
(ffe.familyName() == mSystemTextFontFamilyName ||
|
||||
ffe.familyName() == mSystemDisplayFontFamilyName)) {
|
||||
continue;
|
||||
}
|
||||
AddFamily(ffe.familyName(), ffe.visibility());
|
||||
break;
|
||||
case kTextSizeSystemFontFamily:
|
||||
sSystemTextFontFamilyName = ffe.familyName();
|
||||
mSystemTextFontFamilyName = ffe.familyName();
|
||||
break;
|
||||
case kDisplaySizeSystemFontFamily:
|
||||
sSystemDisplayFontFamilyName = ffe.familyName();
|
||||
sUseSizeSensitiveSystemFont = true;
|
||||
mSystemDisplayFontFamilyName = ffe.familyName();
|
||||
mUseSizeSensitiveSystemFont = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1338,7 +1313,7 @@ void gfxMacPlatformFontList::InitSharedFontListForPlatform() {
|
|||
|
||||
gfxPlatformMac::WaitForFontRegistration();
|
||||
|
||||
CreateSystemFontFamily();
|
||||
InitSystemFontNames();
|
||||
|
||||
if (XRE_IsParentProcess()) {
|
||||
// Only the parent process listens for OS font-changed notifications;
|
||||
|
@ -1561,30 +1536,40 @@ static NSString* GetRealFamilyName(NSFont* aFont) {
|
|||
|
||||
const CGFloat kTextDisplayCrossover = 20.0; // use text family below this size
|
||||
|
||||
/* static */
|
||||
// Called from the RegisterFonts thread during startup; the platform font list
|
||||
// object does not yet exist, so we record the names in static members.
|
||||
void gfxMacPlatformFontList::InitSystemFontNames() {
|
||||
// On Catalina+, the system font uses optical sizing rather than individual
|
||||
// faces, so we don't need to look for a separate display-sized face.
|
||||
sUseSizeSensitiveSystemFont = !nsCocoaFeatures::OnCatalinaOrLater();
|
||||
mUseSizeSensitiveSystemFont = !nsCocoaFeatures::OnCatalinaOrLater();
|
||||
|
||||
// text font family
|
||||
NSFont* sys = [NSFont systemFontOfSize:0.0];
|
||||
NSString* textFamilyName = GetRealFamilyName(sys);
|
||||
nsAutoString familyName;
|
||||
nsCocoaUtils::GetStringForNSString(textFamilyName, familyName);
|
||||
CopyUTF16toUTF8(familyName, sSystemTextFontFamilyName);
|
||||
CopyUTF16toUTF8(familyName, mSystemTextFontFamilyName);
|
||||
|
||||
// On Catalina or later, we store an in-process gfxFontFamily for the system font
|
||||
// even if using the shared fontlist to manage "normal" fonts, because the hidden
|
||||
// system fonts may be excluded from the font list altogether.
|
||||
if (nsCocoaFeatures::OnCatalinaOrLater()) {
|
||||
// This family will be populated based on the given NSFont.
|
||||
RefPtr<gfxFontFamily> fam = new gfxMacFontFamily(mSystemTextFontFamilyName, sys);
|
||||
if (fam) {
|
||||
nsAutoCString key;
|
||||
GenerateFontListKey(mSystemTextFontFamilyName, key);
|
||||
mFontFamilies.InsertOrUpdate(key, std::move(fam));
|
||||
}
|
||||
}
|
||||
|
||||
// display font family, if on OSX 10.11 - 10.14
|
||||
if (sUseSizeSensitiveSystemFont) {
|
||||
if (mUseSizeSensitiveSystemFont) {
|
||||
NSFont* displaySys = [NSFont systemFontOfSize:128.0];
|
||||
NSString* displayFamilyName = GetRealFamilyName(displaySys);
|
||||
if ([displayFamilyName isEqualToString:textFamilyName]) {
|
||||
sUseSizeSensitiveSystemFont = false;
|
||||
mUseSizeSensitiveSystemFont = false;
|
||||
} else {
|
||||
nsCocoaUtils::GetStringForNSString(displayFamilyName, familyName);
|
||||
CopyUTF16toUTF8(familyName, sSystemDisplayFontFamilyName);
|
||||
CopyUTF16toUTF8(familyName, mSystemDisplayFontFamilyName);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1603,22 +1588,6 @@ void gfxMacPlatformFontList::InitSystemFontNames() {
|
|||
#endif
|
||||
}
|
||||
|
||||
void gfxMacPlatformFontList::CreateSystemFontFamily() {
|
||||
// On Catalina or later, we store an in-process gfxFontFamily for the system font
|
||||
// even if using the shared fontlist to manage "normal" fonts, because the hidden
|
||||
// system fonts may be excluded from the font list altogether.
|
||||
if (nsCocoaFeatures::OnCatalinaOrLater()) {
|
||||
// This family will be populated based on the given NSFont.
|
||||
RefPtr<gfxFontFamily> fam =
|
||||
new gfxMacFontFamily(sSystemTextFontFamilyName, [NSFont systemFontOfSize:0.0]);
|
||||
if (fam) {
|
||||
nsAutoCString key;
|
||||
GenerateFontListKey(sSystemTextFontFamilyName, key);
|
||||
mFontFamilies.InsertOrUpdate(key, std::move(fam));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
gfxFontFamily* gfxMacPlatformFontList::FindSystemFontFamily(const nsACString& aFamily) {
|
||||
nsAutoCString key;
|
||||
GenerateFontListKey(aFamily, key);
|
||||
|
@ -1878,10 +1847,10 @@ bool gfxMacPlatformFontList::FindAndAddFamiliesLocked(
|
|||
// may not be included there; we create a separate gfxFontFamily to manage
|
||||
// this family.
|
||||
const nsCString& systemFontFamilyName =
|
||||
sUseSizeSensitiveSystemFont && aStyle &&
|
||||
mUseSizeSensitiveSystemFont && aStyle &&
|
||||
(aStyle->size * aDevToCssSize) >= kTextDisplayCrossover
|
||||
? sSystemDisplayFontFamilyName
|
||||
: sSystemTextFontFamilyName;
|
||||
? mSystemDisplayFontFamilyName
|
||||
: mSystemTextFontFamilyName;
|
||||
if (SharedFontList() && !nsCocoaFeatures::OnCatalinaOrLater()) {
|
||||
FindFamiliesFlags flags = aFlags | FindFamiliesFlags::eSearchHiddenFamilies;
|
||||
return gfxPlatformFontList::FindAndAddFamiliesLocked(aPresContext, aGeneric,
|
||||
|
|
|
@ -99,8 +99,6 @@ void gfxPlatformMac::FontRegistrationCallback(void* aUnused) {
|
|||
for (const auto& dir : kLangFontsDirs) {
|
||||
gfxMacPlatformFontList::ActivateFontsFromDir(dir);
|
||||
}
|
||||
|
||||
gfxMacPlatformFontList::InitSystemFontNames();
|
||||
}
|
||||
|
||||
PRThread* gfxPlatformMac::sFontRegistrationThread = nullptr;
|
||||
|
@ -111,38 +109,23 @@ PRThread* gfxPlatformMac::sFontRegistrationThread = nullptr;
|
|||
our font list. */
|
||||
/* static */
|
||||
void gfxPlatformMac::RegisterSupplementalFonts() {
|
||||
switch (XRE_GetProcessType()) {
|
||||
case GeckoProcessType_Default:
|
||||
sFontRegistrationThread = PR_CreateThread(
|
||||
PR_USER_THREAD, FontRegistrationCallback, nullptr, PR_PRIORITY_NORMAL,
|
||||
PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, 0);
|
||||
break;
|
||||
|
||||
case GeckoProcessType_Content:
|
||||
// TODO: figure out if this matters to other process types (e.g. GPU?)
|
||||
//
|
||||
// We prefer to activate the fonts on a separate thread, to minimize
|
||||
// startup-time cost.
|
||||
// But at least on 10.14 (Mojave), doing font registration on a
|
||||
// separate thread in the content process seems crashy (bug 1708821),
|
||||
// despite the CTFontManager.h header claiming that it's thread-safe.
|
||||
// So we just do it immediately on the main thread, and accept the
|
||||
// startup-time hit.
|
||||
if (nsCocoaFeatures::OnCatalinaOrLater()) {
|
||||
sFontRegistrationThread = PR_CreateThread(
|
||||
PR_USER_THREAD, FontRegistrationCallback, nullptr,
|
||||
PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, 0);
|
||||
} else {
|
||||
for (const auto& dir : kLangFontsDirs) {
|
||||
gfxMacPlatformFontList::ActivateFontsFromDir(dir);
|
||||
}
|
||||
gfxMacPlatformFontList::InitSystemFontNames();
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
// Assume other process types don't actually need the full font list.
|
||||
break;
|
||||
if (XRE_IsParentProcess()) {
|
||||
sFontRegistrationThread = PR_CreateThread(
|
||||
PR_USER_THREAD, FontRegistrationCallback, nullptr, PR_PRIORITY_NORMAL,
|
||||
PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, 0);
|
||||
} else if (!nsCocoaFeatures::OnCatalinaOrLater()) {
|
||||
// On Catalina+, it appears to be sufficient to activate fonts in the
|
||||
// parent process; they are then also usable in child processes. But on
|
||||
// pre-Catalina systems we need to explicitly activate them in each child
|
||||
// process (per bug 1704273).
|
||||
//
|
||||
// But at least on 10.14 (Mojave), doing font registration on a separate
|
||||
// thread in the content process seems crashy (bug 1708821), despite the
|
||||
// CTFontManager.h header claiming that it's thread-safe. So we just do it
|
||||
// immediately on the main thread, and accept the startup-time hit (sigh).
|
||||
for (const auto& dir : kLangFontsDirs) {
|
||||
gfxMacPlatformFontList::ActivateFontsFromDir(dir);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче