From 426f8dbfee8b9e9305d70d6a3016934e186ff038 Mon Sep 17 00:00:00 2001 From: Mason Chang Date: Mon, 6 Jun 2016 10:07:29 -0700 Subject: [PATCH] Bug 1276931. Add VsyncSource::Shutdown which shuts down global display. r=jrmuizel --- gfx/thebes/SoftwareVsyncSource.cpp | 1 - gfx/thebes/SoftwareVsyncSource.h | 2 +- gfx/thebes/VsyncSource.cpp | 6 +++++ gfx/thebes/VsyncSource.h | 2 ++ gfx/thebes/gfxAndroidPlatform.cpp | 6 +++++ gfx/thebes/gfxPlatform.cpp | 41 ++++++++++++++++-------------- gfx/thebes/gfxPlatformMac.cpp | 11 +++++--- gfx/thebes/gfxWindowsPlatform.cpp | 11 +++++--- 8 files changed, 53 insertions(+), 27 deletions(-) diff --git a/gfx/thebes/SoftwareVsyncSource.cpp b/gfx/thebes/SoftwareVsyncSource.cpp index d86ff9bbd2b9..477ea5bb0231 100644 --- a/gfx/thebes/SoftwareVsyncSource.cpp +++ b/gfx/thebes/SoftwareVsyncSource.cpp @@ -20,7 +20,6 @@ SoftwareVsyncSource::SoftwareVsyncSource() SoftwareVsyncSource::~SoftwareVsyncSource() { MOZ_ASSERT(NS_IsMainThread()); - mGlobalDisplay->Shutdown(); mGlobalDisplay = nullptr; } diff --git a/gfx/thebes/SoftwareVsyncSource.h b/gfx/thebes/SoftwareVsyncSource.h index 74e524abe4c3..c86b2568aadf 100644 --- a/gfx/thebes/SoftwareVsyncSource.h +++ b/gfx/thebes/SoftwareVsyncSource.h @@ -27,7 +27,7 @@ public: virtual void NotifyVsync(mozilla::TimeStamp aVsyncTimestamp) override; virtual mozilla::TimeDuration GetVsyncRate() override; void ScheduleNextVsync(mozilla::TimeStamp aVsyncTimestamp); - void Shutdown(); + void Shutdown() override; protected: ~SoftwareDisplay(); diff --git a/gfx/thebes/VsyncSource.cpp b/gfx/thebes/VsyncSource.cpp index 71734157b2f7..cb69db5607f2 100644 --- a/gfx/thebes/VsyncSource.cpp +++ b/gfx/thebes/VsyncSource.cpp @@ -143,5 +143,11 @@ VsyncSource::Display::GetRefreshTimerVsyncDispatcher() return mRefreshTimerVsyncDispatcher; } +void +VsyncSource::Shutdown() +{ + GetGlobalDisplay().Shutdown(); +} + } //namespace gfx } //namespace mozilla diff --git a/gfx/thebes/VsyncSource.h b/gfx/thebes/VsyncSource.h index 4c268ddbb53c..317f31134120 100644 --- a/gfx/thebes/VsyncSource.h +++ b/gfx/thebes/VsyncSource.h @@ -56,6 +56,7 @@ public: virtual void EnableVsync() = 0; virtual void DisableVsync() = 0; virtual bool IsVsyncEnabled() = 0; + virtual void Shutdown() = 0; private: void UpdateVsyncStatus(); @@ -71,6 +72,7 @@ public: RefPtr GetRefreshTimerVsyncDispatcher(); virtual Display& GetGlobalDisplay() = 0; // Works across all displays + void Shutdown(); protected: virtual ~VsyncSource() {} diff --git a/gfx/thebes/gfxAndroidPlatform.cpp b/gfx/thebes/gfxAndroidPlatform.cpp index eb7522ba7a4e..09503d4d089c 100644 --- a/gfx/thebes/gfxAndroidPlatform.cpp +++ b/gfx/thebes/gfxAndroidPlatform.cpp @@ -383,6 +383,12 @@ public: ~GonkDisplay() { + MOZ_ASSERT(NS_IsMainThread()); + } + + virtual void Shutdown() override + { + MOZ_ASSERT(NS_IsMainThread()); DisableVsync(); } diff --git a/gfx/thebes/gfxPlatform.cpp b/gfx/thebes/gfxPlatform.cpp index a1b675a9a112..82976983846c 100644 --- a/gfx/thebes/gfxPlatform.cpp +++ b/gfx/thebes/gfxPlatform.cpp @@ -785,6 +785,8 @@ static bool sLayersIPCIsUp = false; void gfxPlatform::Shutdown() { + // In some cases, gPlatform may not be created but Shutdown() called, + // e.g., during xpcshell tests. if (!gPlatform) { return; } @@ -804,29 +806,30 @@ gfxPlatform::Shutdown() // Free the various non-null transforms and loaded profiles ShutdownCMS(); - // In some cases, gPlatform may not be created but Shutdown() called, - // e.g., during xpcshell tests. - if (gPlatform) { - /* Unregister our CMS Override callback. */ - NS_ASSERTION(gPlatform->mSRGBOverrideObserver, "mSRGBOverrideObserver has alreay gone"); - Preferences::RemoveObserver(gPlatform->mSRGBOverrideObserver, GFX_PREF_CMS_FORCE_SRGB); - gPlatform->mSRGBOverrideObserver = nullptr; + /* Unregister our CMS Override callback. */ + NS_ASSERTION(gPlatform->mSRGBOverrideObserver, "mSRGBOverrideObserver has alreay gone"); + Preferences::RemoveObserver(gPlatform->mSRGBOverrideObserver, GFX_PREF_CMS_FORCE_SRGB); + gPlatform->mSRGBOverrideObserver = nullptr; - NS_ASSERTION(gPlatform->mFontPrefsObserver, "mFontPrefsObserver has alreay gone"); - Preferences::RemoveObservers(gPlatform->mFontPrefsObserver, kObservedPrefs); - gPlatform->mFontPrefsObserver = nullptr; + NS_ASSERTION(gPlatform->mFontPrefsObserver, "mFontPrefsObserver has alreay gone"); + Preferences::RemoveObservers(gPlatform->mFontPrefsObserver, kObservedPrefs); + gPlatform->mFontPrefsObserver = nullptr; - NS_ASSERTION(gPlatform->mMemoryPressureObserver, "mMemoryPressureObserver has already gone"); - nsCOMPtr obs = mozilla::services::GetObserverService(); - if (obs) { - obs->RemoveObserver(gPlatform->mMemoryPressureObserver, "memory-pressure"); - } - - gPlatform->mMemoryPressureObserver = nullptr; - gPlatform->mSkiaGlue = nullptr; - gPlatform->mVsyncSource = nullptr; + NS_ASSERTION(gPlatform->mMemoryPressureObserver, "mMemoryPressureObserver has already gone"); + nsCOMPtr obs = mozilla::services::GetObserverService(); + if (obs) { + obs->RemoveObserver(gPlatform->mMemoryPressureObserver, "memory-pressure"); } + gPlatform->mMemoryPressureObserver = nullptr; + gPlatform->mSkiaGlue = nullptr; + + if (XRE_IsParentProcess()) { + gPlatform->mVsyncSource->Shutdown(); + } + + gPlatform->mVsyncSource = nullptr; + #ifdef MOZ_WIDGET_ANDROID // Shut down the texture pool TexturePoolOGL::Shutdown(); diff --git a/gfx/thebes/gfxPlatformMac.cpp b/gfx/thebes/gfxPlatformMac.cpp index 57576cc3df93..18945d9e7365 100644 --- a/gfx/thebes/gfxPlatformMac.cpp +++ b/gfx/thebes/gfxPlatformMac.cpp @@ -416,9 +416,6 @@ public: ~OSXDisplay() { MOZ_ASSERT(NS_IsMainThread()); - mTimer->Cancel(); - mTimer = nullptr; - DisableVsync(); } static void RetryEnableVsync(nsITimer* aTimer, void* aOsxDisplay) @@ -514,6 +511,14 @@ public: return mVsyncRate; } + virtual void Shutdown() override + { + MOZ_ASSERT(NS_IsMainThread()); + mTimer->Cancel(); + mTimer = nullptr; + DisableVsync(); + } + // The vsync timestamps given by the CVDisplayLinkCallback are // in the future for the NEXT frame. Large parts of Gecko, such // as animations assume a timestamp at either now or in the past. diff --git a/gfx/thebes/gfxWindowsPlatform.cpp b/gfx/thebes/gfxWindowsPlatform.cpp index c712e9c39779..77c7d1e9d514 100755 --- a/gfx/thebes/gfxWindowsPlatform.cpp +++ b/gfx/thebes/gfxWindowsPlatform.cpp @@ -2732,6 +2732,14 @@ public: } } + virtual void Shutdown() override + { + MOZ_ASSERT(NS_IsMainThread()); + DisableVsync(); + mVsyncThread->Stop(); + delete mVsyncThread; + } + virtual void EnableVsync() override { MOZ_ASSERT(NS_IsMainThread()); @@ -2894,9 +2902,6 @@ public: virtual ~D3DVsyncDisplay() { MOZ_ASSERT(NS_IsMainThread()); - DisableVsync(); - mVsyncThread->Stop(); - delete mVsyncThread; } bool IsInVsyncThread()