diff --git a/gfx/thebes/gfxFontInfoLoader.cpp b/gfx/thebes/gfxFontInfoLoader.cpp index ee32a961e45..3b33725495c 100644 --- a/gfx/thebes/gfxFontInfoLoader.cpp +++ b/gfx/thebes/gfxFontInfoLoader.cpp @@ -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 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 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 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 temp; - temp.swap(mFontLoaderThread); - temp->Shutdown(); + NS_DispatchToMainThread(new ShutdownThreadEvent(mFontLoaderThread)); + mFontLoaderThread = nullptr; } RemoveShutdownObserver(); CleanupLoader(); diff --git a/gfx/thebes/gfxPlatformFontList.cpp b/gfx/thebes/gfxPlatformFontList.cpp index 2f4890c0b2f..371f60fb0cb 100644 --- a/gfx/thebes/gfxPlatformFontList.cpp +++ b/gfx/thebes/gfxPlatformFontList.cpp @@ -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) {