Bug 1766378 - Add missing thread-safety-analysis annotations in Windows font-list classes. r=lsalzman

The warnings were almost all due to missing REQUIRES annotations on various
method overrides; we were also failing to lock the mutex in the Windows
impls of LookupLocalFont, so that's now fixed.

Also cleaned up a bit of obsolete code in the GDI font backend (which we
probably should be removing altogether, but that's for another time).

Differential Revision: https://phabricator.services.mozilla.com/D144710
This commit is contained in:
Jonathan Kew 2022-04-26 18:31:54 +00:00
parent 8033908b2d
commit ddfacc1c2e
5 changed files with 57 additions and 69 deletions

View file

@ -1116,6 +1116,7 @@ Family* FontList::FindFamily(const nsCString& aName, bool aPrimaryNameOnly) {
// the "real" family names will have been found in AliasFamilies() above. // the "real" family names will have been found in AliasFamilies() above.
if (aName.Contains(' ')) { if (aName.Contains(' ')) {
auto pfl = gfxPlatformFontList::PlatformFontList(); auto pfl = gfxPlatformFontList::PlatformFontList();
pfl->mLock.AssertCurrentThreadIn();
if (header.mAliasCount) { if (header.mAliasCount) {
// Aliases have been fully loaded by the parent process, so just discard // Aliases have been fully loaded by the parent process, so just discard
// any stray mAliasTable and mLocalNameTable entries from earlier calls // any stray mAliasTable and mLocalNameTable entries from earlier calls

View file

@ -936,6 +936,8 @@ gfxFontEntry* gfxDWriteFontList::LookupLocalFont(
nsPresContext* aPresContext, const nsACString& aFontName, nsPresContext* aPresContext, const nsACString& aFontName,
WeightRange aWeightForEntry, StretchRange aStretchForEntry, WeightRange aWeightForEntry, StretchRange aStretchForEntry,
SlantStyleRange aStyleForEntry) { SlantStyleRange aStyleForEntry) {
AutoLock lock(mLock);
if (SharedFontList()) { if (SharedFontList()) {
return LookupInSharedFaceNameList(aPresContext, aFontName, aWeightForEntry, return LookupInSharedFaceNameList(aPresContext, aFontName, aWeightForEntry,
aStretchForEntry, aStyleForEntry); aStretchForEntry, aStyleForEntry);

View file

@ -63,7 +63,8 @@ class gfxDWriteFontFamily final : public gfxFontFamily {
mForceGDIClassic(false) {} mForceGDIClassic(false) {}
virtual ~gfxDWriteFontFamily(); virtual ~gfxDWriteFontFamily();
void FindStyleVariationsLocked(FontInfoData* aFontInfoData = nullptr) final; void FindStyleVariationsLocked(FontInfoData* aFontInfoData = nullptr)
REQUIRES(mLock) final;
void LocalizedName(nsACString& aLocalizedName) final; void LocalizedName(nsACString& aLocalizedName) final;
@ -206,10 +207,10 @@ class gfxDWriteFontEntry final : public gfxFontEntry {
void SetForceGDIClassic(bool aForce) { mForceGDIClassic = aForce; } void SetForceGDIClassic(bool aForce) { mForceGDIClassic = aForce; }
bool GetForceGDIClassic() { return mForceGDIClassic; } bool GetForceGDIClassic() { return mForceGDIClassic; }
virtual void AddSizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf, void AddSizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf,
FontListSizes* aSizes) const; FontListSizes* aSizes) const override;
virtual void AddSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf, void AddSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf,
FontListSizes* aSizes) const; FontListSizes* aSizes) const override;
protected: protected:
friend class gfxDWriteFont; friend class gfxDWriteFont;
@ -374,8 +375,8 @@ class gfxDWriteFontList final : public gfxPlatformFontList {
} }
// initialize font lists // initialize font lists
nsresult InitFontListForPlatform() override; nsresult InitFontListForPlatform() REQUIRES(mLock) override;
void InitSharedFontListForPlatform() override; void InitSharedFontListForPlatform() REQUIRES(mLock) override;
FontVisibility GetVisibilityForFamily(const nsACString& aName) const; FontVisibility GetVisibilityForFamily(const nsACString& aName) const;
@ -419,7 +420,8 @@ class gfxDWriteFontList final : public gfxPlatformFontList {
nsPresContext* aPresContext, mozilla::StyleGenericFontFamily aGeneric, nsPresContext* aPresContext, mozilla::StyleGenericFontFamily aGeneric,
const nsACString& aFamily, nsTArray<FamilyAndGeneric>* aOutput, const nsACString& aFamily, nsTArray<FamilyAndGeneric>* aOutput,
FindFamiliesFlags aFlags, gfxFontStyle* aStyle = nullptr, FindFamiliesFlags aFlags, gfxFontStyle* aStyle = nullptr,
nsAtom* aLanguage = nullptr, gfxFloat aDevToCssSize = 1.0) override; nsAtom* aLanguage = nullptr, gfxFloat aDevToCssSize = 1.0)
REQUIRES(mLock) override;
gfxFloat GetForceGDIClassicMaxFontSize() { gfxFloat GetForceGDIClassicMaxFontSize() {
return mForceGDIClassicMaxFontSize; return mForceGDIClassicMaxFontSize;
@ -433,7 +435,8 @@ class gfxDWriteFontList final : public gfxPlatformFontList {
protected: protected:
FontFamily GetDefaultFontForPlatform(nsPresContext* aPresContext, FontFamily GetDefaultFontForPlatform(nsPresContext* aPresContext,
const gfxFontStyle* aStyle, const gfxFontStyle* aStyle,
nsAtom* aLanguage = nullptr) override; nsAtom* aLanguage = nullptr)
REQUIRES(mLock) override;
// attempt to use platform-specific fallback for the given character, // attempt to use platform-specific fallback for the given character,
// return null if no usable result found // return null if no usable result found
@ -441,23 +444,25 @@ class gfxDWriteFontList final : public gfxPlatformFontList {
const uint32_t aCh, const uint32_t aCh,
Script aRunScript, Script aRunScript,
const gfxFontStyle* aMatchStyle, const gfxFontStyle* aMatchStyle,
FontFamily& aMatchedFamily) override; FontFamily& aMatchedFamily)
REQUIRES(mLock) override;
private: private:
friend class gfxDWriteFontFamily; friend class gfxDWriteFontFamily;
nsresult GetFontSubstitutes(); nsresult GetFontSubstitutes() REQUIRES(mLock);
void GetDirectWriteSubstitutes(); void GetDirectWriteSubstitutes() REQUIRES(mLock);
virtual bool UsesSystemFallback() { return true; } virtual bool UsesSystemFallback() { return true; }
void GetFontsFromCollection(IDWriteFontCollection* aCollection); void GetFontsFromCollection(IDWriteFontCollection* aCollection)
REQUIRES(mLock);
void AppendFamiliesFromCollection( void AppendFamiliesFromCollection(
IDWriteFontCollection* aCollection, IDWriteFontCollection* aCollection,
nsTArray<mozilla::fontlist::Family::InitData>& aFamilies, nsTArray<mozilla::fontlist::Family::InitData>& aFamilies,
const nsTArray<nsCString>* aForceClassicFams = nullptr); const nsTArray<nsCString>* aForceClassicFams = nullptr) REQUIRES(mLock);
#ifdef MOZ_BUNDLED_FONTS #ifdef MOZ_BUNDLED_FONTS
already_AddRefed<IDWriteFontCollection> CreateBundledFontsCollection( already_AddRefed<IDWriteFontCollection> CreateBundledFontsCollection(

View file

@ -111,10 +111,7 @@ GDIFontEntry::GDIFontEntry(const nsACString& aFaceName,
gfxWindowsFontType aFontType, SlantStyleRange aStyle, gfxWindowsFontType aFontType, SlantStyleRange aStyle,
WeightRange aWeight, StretchRange aStretch, WeightRange aWeight, StretchRange aStretch,
gfxUserFontData* aUserFontData) gfxUserFontData* aUserFontData)
: gfxFontEntry(aFaceName), : gfxFontEntry(aFaceName), mFontType(aFontType), mForceGDI(false) {
mFontType(aFontType),
mForceGDI(false),
mUnicodeRanges() {
mUserFontData.reset(aUserFontData); mUserFontData.reset(aUserFontData);
mStyleRange = aStyle; mStyleRange = aStyle;
mWeightRange = aWeight; mWeightRange = aWeight;
@ -372,7 +369,7 @@ GDIFontEntry* GDIFontEntry::CreateFontEntry(const nsACString& aName,
WeightRange aWeight, WeightRange aWeight,
StretchRange aStretch, StretchRange aStretch,
gfxUserFontData* aUserFontData) { gfxUserFontData* aUserFontData) {
// jtdfix - need to set charset, unicode ranges, pitch/family // jtdfix - need to set charset, pitch/family
return new GDIFontEntry(aName, aFontType, aStyle, aWeight, aStretch, return new GDIFontEntry(aName, aFontType, aStyle, aWeight, aStretch,
aUserFontData); aUserFontData);
@ -403,10 +400,11 @@ static bool ShouldIgnoreItalicStyle(const nsACString& aName) {
int CALLBACK GDIFontFamily::FamilyAddStylesProc( int CALLBACK GDIFontFamily::FamilyAddStylesProc(
const ENUMLOGFONTEXW* lpelfe, const NEWTEXTMETRICEXW* nmetrics, const ENUMLOGFONTEXW* lpelfe, const NEWTEXTMETRICEXW* nmetrics,
DWORD fontType, LPARAM data) { DWORD fontType, LPARAM data) NO_THREAD_SAFETY_ANALYSIS {
const NEWTEXTMETRICW& metrics = nmetrics->ntmTm; const NEWTEXTMETRICW& metrics = nmetrics->ntmTm;
LOGFONTW logFont = lpelfe->elfLogFont; LOGFONTW logFont = lpelfe->elfLogFont;
GDIFontFamily* ff = reinterpret_cast<GDIFontFamily*>(data); GDIFontFamily* ff = reinterpret_cast<GDIFontFamily*>(data);
MOZ_ASSERT(ff->mLock.LockedForWritingByCurrentThread());
if (logFont.lfItalic && ShouldIgnoreItalicStyle(ff->mName)) { if (logFont.lfItalic && ShouldIgnoreItalicStyle(ff->mName)) {
return 1; return 1;
@ -458,23 +456,8 @@ int CALLBACK GDIFontFamily::FamilyAddStylesProc(
return 1; return 1;
} }
MOZ_ASSERT(ff->mLock.LockedForWritingByCurrentThread());
ff->AddFontEntryLocked(fe); ff->AddFontEntryLocked(fe);
if (nmetrics->ntmFontSig.fsUsb[0] != 0x00000000 &&
nmetrics->ntmFontSig.fsUsb[1] != 0x00000000 &&
nmetrics->ntmFontSig.fsUsb[2] != 0x00000000 &&
nmetrics->ntmFontSig.fsUsb[3] != 0x00000000) {
// set the unicode ranges
uint32_t x = 0;
for (uint32_t i = 0; i < 4; ++i) {
DWORD range = nmetrics->ntmFontSig.fsUsb[i];
for (uint32_t k = 0; k < 32; ++k) {
fe->mUnicodeRanges.set(x++, (range & (1 << k)) != 0);
}
}
}
if (LOG_FONTLIST_ENABLED()) { if (LOG_FONTLIST_ENABLED()) {
LOG_FONTLIST( LOG_FONTLIST(
("(fontlist) added (%s) to family (%s)" ("(fontlist) added (%s) to family (%s)"
@ -649,6 +632,7 @@ int CALLBACK gfxGDIFontList::EnumFontFamExProc(ENUMLOGFONTEXW* lpelfe,
NS_ConvertUTF16toUTF8 key(name); NS_ConvertUTF16toUTF8 key(name);
gfxGDIFontList* fontList = PlatformFontList(); gfxGDIFontList* fontList = PlatformFontList();
fontList->mLock.AssertCurrentThreadIn();
if (!fontList->mFontFamilies.Contains(key)) { if (!fontList->mFontFamilies.Contains(key)) {
NS_ConvertUTF16toUTF8 faceName(lf.lfFaceName); NS_ConvertUTF16toUTF8 faceName(lf.lfFaceName);
@ -683,9 +667,9 @@ gfxFontEntry* gfxGDIFontList::LookupLocalFont(nsPresContext* aPresContext,
WeightRange aWeightForEntry, WeightRange aWeightForEntry,
StretchRange aStretchForEntry, StretchRange aStretchForEntry,
SlantStyleRange aStyleForEntry) { SlantStyleRange aStyleForEntry) {
gfxFontEntry* lookup; AutoLock lock(mLock);
lookup = LookupInFaceNameLists(aFontName); gfxFontEntry* lookup = LookupInFaceNameLists(aFontName);
if (!lookup) { if (!lookup) {
return nullptr; return nullptr;
} }

View file

@ -129,18 +129,14 @@ class GDIFontEntry final : public gfxFontEntry {
mFontType == GFX_FONT_TYPE_TT_OPENTYPE); mFontType == GFX_FONT_TYPE_TT_OPENTYPE);
} }
virtual bool SupportsRange(uint8_t range) { bool SkipDuringSystemFallback() override {
return mUnicodeRanges.test(range);
}
virtual bool SkipDuringSystemFallback() {
return !HasCmapTable(); // explicitly skip non-SFNT fonts return !HasCmapTable(); // explicitly skip non-SFNT fonts
} }
virtual bool TestCharacterMap(uint32_t aCh); bool TestCharacterMap(uint32_t aCh) override;
virtual void AddSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf, void AddSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf,
FontListSizes* aSizes) const; FontListSizes* aSizes) const override;
gfxFontEntry* Clone() const override; gfxFontEntry* Clone() const override;
@ -160,8 +156,6 @@ class GDIFontEntry final : public gfxFontEntry {
gfxWindowsFontType mFontType; gfxWindowsFontType mFontType;
bool mForceGDI; bool mForceGDI;
gfxSparseBitSet mUnicodeRanges;
protected: protected:
friend class gfxGDIFont; friend class gfxGDIFont;
@ -193,8 +187,8 @@ class GDIFontFamily final : public gfxFontFamily {
mWindowsPitch(0), mWindowsPitch(0),
mCharset() {} mCharset() {}
void FindStyleVariationsLocked( void FindStyleVariationsLocked(FontInfoData* aFontInfoData = nullptr)
FontInfoData* aFontInfoData = nullptr) override; REQUIRES(mLock) override;
bool FilterForFontList(nsAtom* aLangGroup, bool FilterForFontList(nsAtom* aLangGroup,
const nsACString& aGeneric) const final { const nsACString& aGeneric) const final {
@ -300,7 +294,7 @@ class gfxGDIFontList final : public gfxPlatformFontList {
} }
// initialize font lists // initialize font lists
virtual nsresult InitFontListForPlatform() override; nsresult InitFontListForPlatform() REQUIRES(mLock) override;
gfxFontFamily* CreateFontFamily(const nsACString& aName, gfxFontFamily* CreateFontFamily(const nsACString& aName,
FontVisibility aVisibility) const override; FontVisibility aVisibility) const override;
@ -309,43 +303,45 @@ class gfxGDIFontList final : public gfxPlatformFontList {
nsPresContext* aPresContext, mozilla::StyleGenericFontFamily aGeneric, nsPresContext* aPresContext, mozilla::StyleGenericFontFamily aGeneric,
const nsACString& aFamily, nsTArray<FamilyAndGeneric>* aOutput, const nsACString& aFamily, nsTArray<FamilyAndGeneric>* aOutput,
FindFamiliesFlags aFlags, gfxFontStyle* aStyle = nullptr, FindFamiliesFlags aFlags, gfxFontStyle* aStyle = nullptr,
nsAtom* aLanguage = nullptr, gfxFloat aDevToCssSize = 1.0) override; nsAtom* aLanguage = nullptr, gfxFloat aDevToCssSize = 1.0)
REQUIRES(mLock) override;
virtual gfxFontEntry* LookupLocalFont(nsPresContext* aPresContext, gfxFontEntry* LookupLocalFont(nsPresContext* aPresContext,
const nsACString& aFontName, const nsACString& aFontName,
WeightRange aWeightForEntry, WeightRange aWeightForEntry,
StretchRange aStretchForEntry, StretchRange aStretchForEntry,
SlantStyleRange aStyleForEntry); SlantStyleRange aStyleForEntry) override;
virtual gfxFontEntry* MakePlatformFont(const nsACString& aFontName, gfxFontEntry* MakePlatformFont(const nsACString& aFontName,
WeightRange aWeightForEntry, WeightRange aWeightForEntry,
StretchRange aStretchForEntry, StretchRange aStretchForEntry,
SlantStyleRange aStyleForEntry, SlantStyleRange aStyleForEntry,
const uint8_t* aFontData, const uint8_t* aFontData,
uint32_t aLength); uint32_t aLength) override;
virtual void AddSizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf, void AddSizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf,
FontListSizes* aSizes) const; FontListSizes* aSizes) const override;
virtual void AddSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf, void AddSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf,
FontListSizes* aSizes) const; FontListSizes* aSizes) const override;
protected: protected:
FontFamily GetDefaultFontForPlatform(nsPresContext* aPresContext, FontFamily GetDefaultFontForPlatform(nsPresContext* aPresContext,
const gfxFontStyle* aStyle, const gfxFontStyle* aStyle,
nsAtom* aLanguage = nullptr) override; nsAtom* aLanguage = nullptr)
REQUIRES(mLock) override;
private: private:
friend class gfxWindowsPlatform; friend class gfxWindowsPlatform;
gfxGDIFontList(); gfxGDIFontList();
nsresult GetFontSubstitutes(); nsresult GetFontSubstitutes() REQUIRES(mLock);
static int CALLBACK EnumFontFamExProc(ENUMLOGFONTEXW* lpelfe, static int CALLBACK EnumFontFamExProc(ENUMLOGFONTEXW* lpelfe,
NEWTEXTMETRICEXW* lpntme, NEWTEXTMETRICEXW* lpntme,
DWORD fontType, LPARAM lParam); DWORD fontType, LPARAM lParam);
virtual already_AddRefed<FontInfoData> CreateFontInfoData(); already_AddRefed<FontInfoData> CreateFontInfoData() override;
#ifdef MOZ_BUNDLED_FONTS #ifdef MOZ_BUNDLED_FONTS
void ActivateBundledFonts(); void ActivateBundledFonts();