Bug 1189158 - shutdown font loader thread in separate event. r=m_kato

This commit is contained in:
John Daggett 2015-07-31 10:10:31 +09:00
parent e59256c2b5
commit 2457a91642
2 changed files with 36 additions and 6 deletions

View File

@ -12,6 +12,12 @@
using namespace mozilla;
using services::GetObserverService;
#define LOG_FONTINIT(args) MOZ_LOG(gfxPlatform::GetLog(eGfxLog_fontinit), \
LogLevel::Debug, args)
#define LOG_FONTINIT_ENABLED() MOZ_LOG_TEST( \
gfxPlatform::GetLog(eGfxLog_fontinit), \
LogLevel::Debug)
void
FontInfoData::Load()
{
@ -57,6 +63,21 @@ class AsyncFontInfoLoader : public nsRunnable {
nsRefPtr<FontInfoLoadCompleteEvent> mCompleteEvent;
};
class ShutdownThreadEvent : public nsRunnable {
virtual ~ShutdownThreadEvent() {}
NS_DECL_ISUPPORTS_INHERITED
explicit ShutdownThreadEvent(nsIThread* aThread) : mThread(aThread) {}
NS_IMETHOD Run() override {
mThread->Shutdown();
return NS_OK;
}
nsCOMPtr<nsIThread> mThread;
};
NS_IMPL_ISUPPORTS_INHERITED0(ShutdownThreadEvent, nsRunnable);
// runs on main thread after async font info loading is done
nsresult
FontInfoLoadCompleteEvent::Run()
@ -106,6 +127,9 @@ gfxFontInfoLoader::StartLoader(uint32_t aDelay, uint32_t aInterval)
{
mInterval = aInterval;
NS_ASSERTION(!mFontInfo,
"fontinfo should be null when starting font loader");
// sanity check
if (mState != stateInitial &&
mState != stateTimerOff &&
@ -149,6 +173,11 @@ gfxFontInfoLoader::StartLoader(uint32_t aDelay, uint32_t aInterval)
nsCOMPtr<nsIRunnable> loadEvent = new AsyncFontInfoLoader(mFontInfo);
mFontLoaderThread->Dispatch(loadEvent.forget(), NS_DISPATCH_NORMAL);
if (LOG_FONTINIT_ENABLED()) {
LOG_FONTINIT(("(fontinit) fontloader started (fontinfo: %p)\n",
mFontInfo.get()));
}
}
void
@ -159,7 +188,7 @@ gfxFontInfoLoader::FinalizeLoader(FontInfoData *aFontInfo)
// thread has already Shutdown(), and likely before processing
// the Shutdown event it handled the load event and sent back
// our Completion event, thus we end up here.
if (mState != stateAsyncLoad) {
if (mState != stateAsyncLoad || mFontInfo != aFontInfo) {
return;
}
@ -189,11 +218,8 @@ gfxFontInfoLoader::CancelLoader()
mTimer = nullptr;
}
if (mFontLoaderThread) {
// NOTE: Shutdown() runs the event loop, and we can get timer events
// ensure that we can't try to do this twice!
nsCOMPtr<nsIThread> temp;
temp.swap(mFontLoaderThread);
temp->Shutdown();
NS_DispatchToMainThread(new ShutdownThreadEvent(mFontLoaderThread));
mFontLoaderThread = nullptr;
}
RemoveShutdownObserver();
CleanupLoader();

View File

@ -195,6 +195,10 @@ gfxPlatformFontList::~gfxPlatformFontList()
nsresult
gfxPlatformFontList::InitFontList()
{
if (LOG_FONTINIT_ENABLED()) {
LOG_FONTINIT(("(fontinit) system fontlist initialization\n"));
}
// rebuilding fontlist so clear out font/word caches
gfxFontCache *fontCache = gfxFontCache::GetCache();
if (fontCache) {