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
Родитель d0d22b2a08
Коммит 6052d1cb31
2 изменённых файлов: 36 добавлений и 6 удалений

Просмотреть файл

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

Просмотреть файл

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