Bug 1367497 - Part 2: Make gfxFontCache use an expiration tracker that can assert the Servo font metrics mutex is locked. r=bevis,jfkthame

This commit is contained in:
Bevis Tseng 2017-08-15 10:04:32 +08:00
parent 4b1a41e00e
commit 13f67fed92
2 changed files with 61 additions and 12 deletions

View File

@ -173,8 +173,7 @@ gfxFontCache::Shutdown()
}
gfxFontCache::gfxFontCache(nsIEventTarget* aEventTarget)
: nsExpirationTracker<gfxFont,3>(FONT_TIMEOUT_SECONDS * 1000,
"gfxFontCache", aEventTarget)
: gfxFontCacheExpirationTracker(aEventTarget)
{
nsCOMPtr<nsIObserverService> obs = GetObserverService();
if (obs) {
@ -286,7 +285,7 @@ gfxFontCache::NotifyReleased(gfxFont *aFont)
}
void
gfxFontCache::NotifyExpired(gfxFont *aFont)
gfxFontCache::NotifyExpired(gfxFont* aFont)
{
aFont->ClearCachedWords();
RemoveObject(aFont);

View File

@ -33,6 +33,7 @@
#include "harfbuzz/hb.h"
#include "mozilla/gfx/2D.h"
#include "nsColor.h"
#include "mozilla/ServoUtils.h"
typedef struct _cairo cairo_t;
typedef struct _cairo_scaled_font cairo_scaled_font_t;
@ -255,12 +256,41 @@ struct FontCacheSizes {
size_t mShapedWords; // memory used by the per-font shapedWord caches
};
class gfxFontCache final : public nsExpirationTracker<gfxFont,3> {
class gfxFontCacheExpirationTracker
: public ExpirationTrackerImpl<gfxFont, 3,
::detail::PlaceholderLock,
::detail::PlaceholderAutoLock>
{
protected:
typedef ::detail::PlaceholderLock Lock;
typedef ::detail::PlaceholderAutoLock AutoLock;
Lock mLock;
AutoLock FakeLock()
{
return AutoLock(mLock);
}
Lock& GetMutex() override
{
mozilla::AssertIsMainThreadOrServoFontMetricsLocked();
return mLock;
}
public:
enum {
FONT_TIMEOUT_SECONDS = 10,
SHAPED_WORD_TIMEOUT_SECONDS = 60
};
enum { FONT_TIMEOUT_SECONDS = 10 };
gfxFontCacheExpirationTracker(nsIEventTarget* aEventTarget)
: ExpirationTrackerImpl<gfxFont, 3, Lock, AutoLock>(
FONT_TIMEOUT_SECONDS * 1000, "gfxFontCache", aEventTarget)
{
}
};
class gfxFontCache final : private gfxFontCacheExpirationTracker {
public:
enum { SHAPED_WORD_TIMEOUT_SECONDS = 60 };
explicit gfxFontCache(nsIEventTarget* aEventTarget);
~gfxFontCache();
@ -294,10 +324,6 @@ public:
// amount of time.
void NotifyReleased(gfxFont *aFont);
// This gets called when the timeout has expired on a zero-refcount
// font; we just delete it.
virtual void NotifyExpired(gfxFont *aFont) override;
// Cleans out the hashtable and removes expired fonts waiting for cleanup.
// Other gfxFont objects may be still in use but they will be pushed
// into the expiration queues and removed.
@ -314,6 +340,16 @@ public:
void AddSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf,
FontCacheSizes* aSizes) const;
void AgeAllGenerations()
{
AgeAllGenerationsLocked(FakeLock());
}
void RemoveObject(gfxFont* aFont)
{
RemoveObjectLocked(aFont, FakeLock());
}
protected:
class MemoryReporter final : public nsIMemoryReporter
{
@ -333,6 +369,20 @@ protected:
NS_DECL_NSIOBSERVER
};
nsresult AddObject(gfxFont* aFont)
{
return AddObjectLocked(aFont, FakeLock());
}
// This gets called when the timeout has expired on a zero-refcount
// font; we just delete it.
virtual void NotifyExpiredLocked(gfxFont* aFont, const AutoLock&) override
{
NotifyExpired(aFont);
}
void NotifyExpired(gfxFont* aFont);
void DestroyFont(gfxFont *aFont);
static gfxFontCache *gGlobalCache;