Skip to content

Commit ba063e1

Browse files
committed
Backed out changeset e4cd98b5984d (bug 1779519) for causing build bustages. CLOSED TREE
1 parent b2f117c commit ba063e1

20 files changed

+277
-280
lines changed

accessible/base/TextAttrs.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ bool TextAttrsMgr::FontFamilyTextAttr::GetFontFamily(nsIFrame* aFrame,
410410
nsLayoutUtils::GetFontMetricsForFrame(aFrame, 1.0f);
411411

412412
gfxFontGroup* fontGroup = fm->GetThebesFontGroup();
413-
RefPtr<gfxFont> font = fontGroup->GetFirstValidFont();
413+
gfxFont* font = fontGroup->GetFirstValidFont();
414414
gfxFontEntry* fontEntry = font->GetFontEntry();
415415
aFamily.Append(NS_ConvertUTF8toUTF16(fontEntry->FamilyName()));
416416
return true;
@@ -551,7 +551,7 @@ FontWeight TextAttrsMgr::FontWeightTextAttr::GetFontWeight(nsIFrame* aFrame) {
551551
nsLayoutUtils::GetFontMetricsForFrame(aFrame, 1.0f);
552552

553553
gfxFontGroup* fontGroup = fm->GetThebesFontGroup();
554-
RefPtr<gfxFont> font = fontGroup->GetFirstValidFont();
554+
gfxFont* font = fontGroup->GetFirstValidFont();
555555

556556
// When there doesn't exist a bold font in the family and so the rendering of
557557
// a non-bold font face is changed so that the user sees what looks like a

dom/canvas/CanvasRenderingContext2D.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4245,9 +4245,9 @@ TextMetrics* CanvasRenderingContext2D::DrawOrMeasureText(
42454245

42464246
processor.mFontgrp
42474247
->UpdateUserFonts(); // ensure user font generation is current
4248-
RefPtr<gfxFont> font = processor.mFontgrp->GetFirstValidFont();
42494248
const gfxFont::Metrics& fontMetrics =
4250-
font->GetMetrics(nsFontMetrics::eHorizontal);
4249+
processor.mFontgrp->GetFirstValidFont()->GetMetrics(
4250+
nsFontMetrics::eHorizontal);
42514251

42524252
// calls bidi algo twice since it needs the full text width and the
42534253
// bounding boxes before rendering anything

gfx/src/nsFontMetrics.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,8 @@ void nsFontMetrics::Destroy() { mPresContext = nullptr; }
159159

160160
static const gfxFont::Metrics& GetMetrics(
161161
nsFontMetrics* aFontMetrics, nsFontMetrics::FontOrientation aOrientation) {
162-
RefPtr<gfxFont> font =
163-
aFontMetrics->GetThebesFontGroup()->GetFirstValidFont();
164-
return font->GetMetrics(aOrientation);
162+
return aFontMetrics->GetThebesFontGroup()->GetFirstValidFont()->GetMetrics(
163+
aOrientation);
165164
}
166165

167166
static const gfxFont::Metrics& GetMetrics(nsFontMetrics* aFontMetrics) {

gfx/thebes/gfxFont.cpp

Lines changed: 35 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -231,29 +231,21 @@ bool gfxFontCache::HashEntry::KeyEquals(const KeyTypePointer aKey) const {
231231
aKey->mUnicodeRangeMap->Equals(fontUnicodeRangeMap)));
232232
}
233233

234-
already_AddRefed<gfxFont> gfxFontCache::Lookup(
235-
const gfxFontEntry* aFontEntry, const gfxFontStyle* aStyle,
236-
const gfxCharacterMap* aUnicodeRangeMap) {
234+
gfxFont* gfxFontCache::Lookup(const gfxFontEntry* aFontEntry,
235+
const gfxFontStyle* aStyle,
236+
const gfxCharacterMap* aUnicodeRangeMap) {
237237
MutexAutoLock lock(mMutex);
238238

239239
Key key(aFontEntry, aStyle, aUnicodeRangeMap);
240240
HashEntry* entry = mFonts.GetEntry(key);
241241

242242
Telemetry::Accumulate(Telemetry::FONT_CACHE_HIT, entry != nullptr);
243243

244-
if (!entry) {
245-
return nullptr;
246-
}
247-
248-
RefPtr<gfxFont> font = entry->mFont;
249-
if (font->GetExpirationState()->IsTracked()) {
250-
RemoveObjectLocked(font, lock);
251-
}
252-
return font.forget();
244+
return entry ? entry->mFont : nullptr;
253245
}
254246

255247
void gfxFontCache::AddNew(gfxFont* aFont) {
256-
nsTArray<gfxFont*> discard;
248+
gfxFont* oldFont;
257249
{
258250
MutexAutoLock lock(mMutex);
259251

@@ -263,39 +255,28 @@ void gfxFontCache::AddNew(gfxFont* aFont) {
263255
if (!entry) {
264256
return;
265257
}
266-
gfxFont* oldFont = entry->mFont;
258+
oldFont = entry->mFont;
267259
entry->mFont = aFont;
268260
// Assert that we can find the entry we just put in (this fails if the key
269261
// has a NaN float value in it, e.g. 'sizeAdjust').
270262
MOZ_ASSERT(entry == mFonts.GetEntry(key));
263+
}
271264

272-
// If someone's asked us to replace an existing font entry, then that's a
273-
// bit weird, but let it happen, and expire the old font if it's not used.
274-
if (oldFont && oldFont->GetExpirationState()->IsTracked()) {
275-
// if oldFont == aFont, recount should be > 0,
276-
// so we shouldn't be here.
277-
NS_ASSERTION(aFont != oldFont, "new font is tracked for expiry!");
278-
NotifyExpiredLocked(oldFont, lock);
279-
discard = std::move(mTrackerDiscard);
280-
}
265+
// If someone's asked us to replace an existing font entry, then that's a
266+
// bit weird, but let it happen, and expire the old font if it's not used.
267+
if (oldFont && oldFont->GetExpirationState()->IsTracked()) {
268+
// if oldFont == aFont, recount should be > 0,
269+
// so we shouldn't be here.
270+
NS_ASSERTION(aFont != oldFont, "new font is tracked for expiry!");
271+
NotifyExpired(oldFont);
281272
}
282-
DestroyDiscard(discard);
283273
}
284274

285275
void gfxFontCache::NotifyReleased(gfxFont* aFont) {
286-
nsTArray<gfxFont*> discard;
287-
{
288-
MutexAutoLock lock(mMutex);
289-
if (NS_SUCCEEDED(AddObjectLocked(aFont, lock))) {
290-
return;
291-
}
292-
276+
if (NS_FAILED(AddObject(aFont))) {
293277
// We couldn't track it for some reason. Kill it now.
294-
DestroyFontLocked(aFont);
295-
discard = std::move(mTrackerDiscard);
278+
DestroyFont(aFont);
296279
}
297-
298-
DestroyDiscard(discard);
299280
// Note that we might have fonts that aren't in the hashtable, perhaps because
300281
// of OOM adding to the hashtable or because someone did an AddNew where
301282
// we already had a font. These fonts are added to the expiration tracker
@@ -304,17 +285,15 @@ void gfxFontCache::NotifyReleased(gfxFont* aFont) {
304285
}
305286

306287
void gfxFontCache::NotifyExpiredLocked(gfxFont* aFont, const AutoLock& aLock) {
288+
aFont->ClearCachedWords();
307289
RemoveObjectLocked(aFont, aLock);
308290
DestroyFontLocked(aFont);
309291
}
310292

311-
void gfxFontCache::NotifyHandlerEnd() {
312-
nsTArray<gfxFont*> discard;
313-
{
314-
MutexAutoLock lock(mMutex);
315-
discard = std::move(mTrackerDiscard);
316-
}
317-
DestroyDiscard(discard);
293+
void gfxFontCache::NotifyExpired(gfxFont* aFont) {
294+
aFont->ClearCachedWords();
295+
RemoveObject(aFont);
296+
DestroyFont(aFont);
318297
}
319298

320299
void gfxFontCache::DestroyFontLocked(gfxFont* aFont) {
@@ -326,38 +305,23 @@ void gfxFontCache::DestroyFontLocked(gfxFont* aFont) {
326305
}
327306
NS_ASSERTION(aFont->GetRefCount() == 0,
328307
"Destroying with non-zero ref count!");
329-
mTrackerDiscard.AppendElement(aFont);
330-
}
331-
332-
void gfxFontCache::DestroyDiscard(nsTArray<gfxFont*>& aDiscard) {
333-
for (auto* font : aDiscard) {
334-
NS_ASSERTION(font->GetRefCount() == 0,
335-
"Destroying with non-zero ref count!");
336-
font->ClearCachedWords();
337-
delete font;
338-
}
339-
aDiscard.Clear();
340-
}
341-
342-
void gfxFontCache::Flush() {
343-
nsTArray<gfxFont*> discard;
344-
{
345-
MutexAutoLock lock(mMutex);
346-
mFonts.Clear();
347-
AgeAllGenerationsLocked(lock);
348-
discard = std::move(mTrackerDiscard);
349-
}
350-
DestroyDiscard(discard);
308+
MutexAutoUnlock unlock(mMutex);
309+
delete aFont;
351310
}
352311

353-
void gfxFontCache::AgeAllGenerations() {
354-
nsTArray<gfxFont*> discard;
312+
void gfxFontCache::DestroyFont(gfxFont* aFont) {
355313
{
356314
MutexAutoLock lock(mMutex);
357-
AgeAllGenerationsLocked(lock);
358-
discard = std::move(mTrackerDiscard);
315+
Key key(aFont->GetFontEntry(), aFont->GetStyle(),
316+
aFont->GetUnicodeRangeMap());
317+
HashEntry* entry = mFonts.GetEntry(key);
318+
if (entry && entry->mFont == aFont) {
319+
mFonts.RemoveEntry(entry);
320+
}
359321
}
360-
DestroyDiscard(discard);
322+
NS_ASSERTION(aFont->GetRefCount() == 0,
323+
"Destroying with non-zero ref count!");
324+
delete aFont;
361325
}
362326

363327
/*static*/
@@ -3617,16 +3581,15 @@ bool gfxFont::InitFakeSmallCapsRun(
36173581
aSyntheticUpper);
36183582
}
36193583

3620-
already_AddRefed<gfxFont> gfxFont::GetSmallCapsFont() const {
3584+
gfxFont* gfxFont::GetSmallCapsFont() const {
36213585
gfxFontStyle style(*GetStyle());
36223586
style.size *= SMALL_CAPS_SCALE_FACTOR;
36233587
style.variantCaps = NS_FONT_VARIANT_CAPS_NORMAL;
36243588
gfxFontEntry* fe = GetFontEntry();
36253589
return fe->FindOrMakeFont(&style, mUnicodeRangeMap);
36263590
}
36273591

3628-
already_AddRefed<gfxFont> gfxFont::GetSubSuperscriptFont(
3629-
int32_t aAppUnitsPerDevPixel) const {
3592+
gfxFont* gfxFont::GetSubSuperscriptFont(int32_t aAppUnitsPerDevPixel) const {
36303593
gfxFontStyle style(*GetStyle());
36313594
style.AdjustForSubSuperscript(aAppUnitsPerDevPixel);
36323595
gfxFontEntry* fe = GetFontEntry();

gfx/thebes/gfxFont.h

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -317,9 +317,8 @@ class gfxFontCache final
317317

318318
// Look up a font in the cache. Returns null if there's nothing matching
319319
// in the cache
320-
already_AddRefed<gfxFont> Lookup(const gfxFontEntry* aFontEntry,
321-
const gfxFontStyle* aStyle,
322-
const gfxCharacterMap* aUnicodeRangeMap);
320+
gfxFont* Lookup(const gfxFontEntry* aFontEntry, const gfxFontStyle* aStyle,
321+
const gfxCharacterMap* aUnicodeRangeMap);
323322

324323
// We created a new font (presumably because Lookup returned null);
325324
// put it in the cache. The font's refcount should be nonzero. It is
@@ -335,7 +334,13 @@ class gfxFontCache final
335334
// Cleans out the hashtable and removes expired fonts waiting for cleanup.
336335
// Other gfxFont objects may be still in use but they will be pushed
337336
// into the expiration queues and removed.
338-
void Flush();
337+
void Flush() {
338+
{
339+
mozilla::MutexAutoLock lock(mMutex);
340+
mFonts.Clear();
341+
}
342+
AgeAllGenerations();
343+
}
339344

340345
void FlushShapedWordCaches();
341346
void NotifyGlyphsChanged();
@@ -369,7 +374,15 @@ class gfxFontCache final
369374
void AddSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf,
370375
FontCacheSizes* aSizes) const;
371376

372-
void AgeAllGenerations();
377+
void AgeAllGenerations() {
378+
AutoLock lock(mMutex);
379+
AgeAllGenerationsLocked(lock);
380+
}
381+
382+
void RemoveObject(gfxFont* aFont) {
383+
AutoLock lock(mMutex);
384+
RemoveObjectLocked(aFont, lock);
385+
}
373386

374387
protected:
375388
class MemoryReporter final : public nsIMemoryReporter {
@@ -398,10 +411,10 @@ class gfxFontCache final
398411
// font; we just delete it.
399412
void NotifyExpiredLocked(gfxFont* aFont, const AutoLock&)
400413
REQUIRES(mMutex) override;
401-
void NotifyHandlerEnd() override;
414+
void NotifyExpired(gfxFont* aFont);
402415

416+
void DestroyFont(gfxFont* aFont);
403417
void DestroyFontLocked(gfxFont* aFont) REQUIRES(mMutex);
404-
void DestroyDiscard(nsTArray<gfxFont*>& aDiscard);
405418

406419
static gfxFontCache* gGlobalCache;
407420

@@ -442,8 +455,6 @@ class gfxFontCache final
442455

443456
nsTHashtable<HashEntry> mFonts GUARDED_BY(mMutex);
444457

445-
nsTArray<gfxFont*> mTrackerDiscard GUARDED_BY(mMutex);
446-
447458
static void WordCacheExpirationTimerCallback(nsITimer* aTimer, void* aCache);
448459

449460
nsCOMPtr<nsITimer> mWordCacheExpirationTimer GUARDED_BY(mMutex);
@@ -1428,6 +1439,14 @@ class gfxFont {
14281439
14291440
nsrefcnt AddRef(void) {
14301441
MOZ_ASSERT(int32_t(mRefCnt) >= 0, "illegal refcnt");
1442+
nsExpirationState state;
1443+
{
1444+
mozilla::AutoReadLock lock(mLock);
1445+
state = mExpirationState;
1446+
}
1447+
if (state.IsTracked()) {
1448+
gfxFontCache::GetCache()->RemoveObject(this);
1449+
}
14311450
++mRefCnt;
14321451
NS_LOG_ADDREF(this, mRefCnt, "gfxFont", sizeof(*this));
14331452
return mRefCnt;
@@ -1947,8 +1966,7 @@ class gfxFont {
19471966
19481967
// Return a cloned font resized and offset to simulate sub/superscript
19491968
// glyphs. This does not add a reference to the returned font.
1950-
already_AddRefed<gfxFont> GetSubSuperscriptFont(
1951-
int32_t aAppUnitsPerDevPixel) const;
1969+
gfxFont* GetSubSuperscriptFont(int32_t aAppUnitsPerDevPixel) const;
19521970
19531971
bool HasColorGlyphFor(uint32_t aCh, uint32_t aNextCh);
19541972
@@ -1999,7 +2017,7 @@ class gfxFont {
19992017
// Return a font that is a "clone" of this one, but reduced to 80% size
20002018
// (and with variantCaps set to normal). This does not add a reference to
20012019
// the returned font.
2002-
already_AddRefed<gfxFont> GetSmallCapsFont() const;
2020+
gfxFont* GetSmallCapsFont() const;
20032021
20042022
// subclasses may provide (possibly hinted) glyph widths (in font units);
20052023
// if they do not override this, harfbuzz will use unhinted widths
@@ -2221,9 +2239,7 @@ class gfxFont {
22212239
// This is OK because we only multiply by this factor, never divide.
22222240
float mFUnitsConvFactor;
22232241
2224-
// This is guarded by gfxFontCache::GetCache()->GetMutex() but it is difficult
2225-
// to annotate that fact.
2226-
nsExpirationState mExpirationState;
2242+
nsExpirationState mExpirationState GUARDED_BY(mLock);
22272243
22282244
// Glyph ID of the font's <space> glyph, zero if missing
22292245
uint16_t mSpaceGlyph = 0;

gfx/thebes/gfxFontEntry.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,9 @@ nsCString gfxFontEntry::RealFaceName() {
266266
return Name();
267267
}
268268

269-
already_AddRefed<gfxFont> gfxFontEntry::FindOrMakeFont(
270-
const gfxFontStyle* aStyle, gfxCharacterMap* aUnicodeRangeMap) {
271-
RefPtr<gfxFont> font =
269+
gfxFont* gfxFontEntry::FindOrMakeFont(const gfxFontStyle* aStyle,
270+
gfxCharacterMap* aUnicodeRangeMap) {
271+
gfxFont* font =
272272
gfxFontCache::GetCache()->Lookup(this, aStyle, aUnicodeRangeMap);
273273

274274
if (!font) {
@@ -284,7 +284,7 @@ already_AddRefed<gfxFont> gfxFontEntry::FindOrMakeFont(
284284
font->SetUnicodeRangeMap(aUnicodeRangeMap);
285285
gfxFontCache::GetCache()->AddNew(font);
286286
}
287-
return font.forget();
287+
return font;
288288
}
289289

290290
uint16_t gfxFontEntry::UnitsPerEm() {

gfx/thebes/gfxFontEntry.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,8 @@ class gfxFontEntry {
329329
// cached instance; but we also don't return already_AddRefed, because
330330
// the caller may only need to use the font temporarily and doesn't need
331331
// a strong reference.
332-
already_AddRefed<gfxFont> FindOrMakeFont(
333-
const gfxFontStyle* aStyle, gfxCharacterMap* aUnicodeRangeMap = nullptr);
332+
gfxFont* FindOrMakeFont(const gfxFontStyle* aStyle,
333+
gfxCharacterMap* aUnicodeRangeMap = nullptr);
334334

335335
// Get an existing font table cache entry in aBlob if it has been
336336
// registered, or return false if not. Callers must call

0 commit comments

Comments
 (0)