Bug 877534 - Use a shutdown listener to destroy the compositor from nsBaseWidget. r=roc

This prevents a case where the nsBaseWidget isn't destroyed until the cycle collector is shutdown,
and we are too late in the shutdown sequence to process the events that get queued during
Compositor teardown.
This commit is contained in:
Matt Woodrow 2013-06-17 14:50:32 +12:00
parent a7ebadcc0e
commit 2f54796673
2 changed files with 53 additions and 0 deletions

View File

@ -118,8 +118,31 @@ nsBaseWidget::nsBaseWidget()
#ifdef DEBUG #ifdef DEBUG
debug_RegisterPrefCallbacks(); debug_RegisterPrefCallbacks();
#endif #endif
mShutdownObserver = new WidgetShutdownObserver(this);
nsContentUtils::RegisterShutdownObserver(mShutdownObserver);
} }
NS_IMPL_ISUPPORTS1(WidgetShutdownObserver, nsIObserver)
NS_IMETHODIMP
WidgetShutdownObserver::Observe(nsISupports *aSubject,
const char *aTopic,
const PRUnichar *aData)
{
if (strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID) == 0) {
mWidget->Shutdown();
nsContentUtils::UnregisterShutdownObserver(this);
}
return NS_OK;
}
void
nsBaseWidget::Shutdown()
{
DestroyCompositor();
mShutdownObserver = nullptr;
}
static void DeferredDestroyCompositor(CompositorParent* aCompositorParent, static void DeferredDestroyCompositor(CompositorParent* aCompositorParent,
CompositorChild* aCompositorChild) CompositorChild* aCompositorChild)
@ -171,6 +194,10 @@ nsBaseWidget::~nsBaseWidget()
mLayerManager = nullptr; mLayerManager = nullptr;
} }
if (mShutdownObserver) {
nsContentUtils::UnregisterShutdownObserver(mShutdownObserver);
}
DestroyCompositor(); DestroyCompositor();
#ifdef NOISY_WIDGET_LEAKS #ifdef NOISY_WIDGET_LEAKS
@ -893,6 +920,12 @@ void nsBaseWidget::CreateCompositor(int aWidth, int aHeight)
// Recreating this is tricky, as we may still have an old and we need // Recreating this is tricky, as we may still have an old and we need
// to make sure it's properly destroyed by calling DestroyCompositor! // to make sure it's properly destroyed by calling DestroyCompositor!
// If we've already received a shutdown notification, don't try
// create a new compositor.
if (!mShutdownObserver) {
return;
}
mCompositorParent = NewCompositorParent(aWidth, aHeight); mCompositorParent = NewCompositorParent(aWidth, aHeight);
AsyncChannel *parentChannel = mCompositorParent->GetIPCChannel(); AsyncChannel *parentChannel = mCompositorParent->GetIPCChannel();
LayerManager* lm = new ClientLayerManager(this); LayerManager* lm = new ClientLayerManager(this);

View File

@ -15,6 +15,7 @@
#include "nsGUIEvent.h" #include "nsGUIEvent.h"
#include "nsAutoPtr.h" #include "nsAutoPtr.h"
#include "nsIRollupListener.h" #include "nsIRollupListener.h"
#include "nsIObserver.h"
#include <algorithm> #include <algorithm>
class nsIContent; class nsIContent;
class nsAutoRollup; class nsAutoRollup;
@ -38,6 +39,22 @@ namespace base {
class Thread; class Thread;
} }
class nsBaseWidget;
class WidgetShutdownObserver MOZ_FINAL : public nsIObserver
{
public:
WidgetShutdownObserver(nsBaseWidget* aWidget)
: mWidget(aWidget)
{ }
NS_DECL_ISUPPORTS
NS_DECL_NSIOBSERVER
private:
nsBaseWidget *mWidget;
};
/** /**
* Common widget implementation used as base class for native * Common widget implementation used as base class for native
* or crossplatform implementations of Widgets. * or crossplatform implementations of Widgets.
@ -254,6 +271,8 @@ public:
static nsIRollupListener* GetActiveRollupListener(); static nsIRollupListener* GetActiveRollupListener();
void Shutdown();
protected: protected:
virtual void ResolveIconName(const nsAString &aIconName, virtual void ResolveIconName(const nsAString &aIconName,
@ -356,6 +375,7 @@ protected:
nsRefPtr<LayerManager> mBasicLayerManager; nsRefPtr<LayerManager> mBasicLayerManager;
nsRefPtr<CompositorChild> mCompositorChild; nsRefPtr<CompositorChild> mCompositorChild;
nsRefPtr<CompositorParent> mCompositorParent; nsRefPtr<CompositorParent> mCompositorParent;
nsCOMPtr<WidgetShutdownObserver> mShutdownObserver;
nscolor mBackground; nscolor mBackground;
nscolor mForeground; nscolor mForeground;
nsCursor mCursor; nsCursor mCursor;