From 124a6df32374465189452f162ba58aca8373eb42 Mon Sep 17 00:00:00 2001 From: Sotaro Ikeda Date: Sun, 22 Feb 2015 08:53:37 -0800 Subject: [PATCH] Bug 1133426 - Care about new CompositorChild and CompositorParent re-creation. --- widget/nsBaseWidget.cpp | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/widget/nsBaseWidget.cpp b/widget/nsBaseWidget.cpp index 89bbe74a3a21..5675f20a1a5b 100644 --- a/widget/nsBaseWidget.cpp +++ b/widget/nsBaseWidget.cpp @@ -181,21 +181,24 @@ nsBaseWidget::Shutdown() mShutdownObserver = nullptr; } -static void DeferredDestroyCompositor(CompositorParent* aCompositorParent, - CompositorChild* aCompositorChild) +static void DeferredDestroyCompositor(nsRefPtr aCompositorParent, + nsRefPtr aCompositorChild) { // Bug 848949 needs to be fixed before // we can close the channel properly //aCompositorChild->Close(); - aCompositorParent->Release(); - aCompositorChild->Release(); } void nsBaseWidget::DestroyCompositor() { if (mCompositorChild) { - mCompositorChild->SendWillStop(); - mCompositorChild->Destroy(); + nsRefPtr compositorChild = mCompositorChild.forget(); + nsRefPtr compositorParent = mCompositorParent.forget(); + + compositorChild->SendWillStop(); + // New LayerManager, CompositorParent and CompositorChild might be created + // as a result of internal GetLayerManager() call. + compositorChild->Destroy(); // The call just made to SendWillStop can result in IPC from the // CompositorParent to the CompositorChild (e.g. caused by the destruction @@ -204,13 +207,12 @@ void nsBaseWidget::DestroyCompositor() // events already in the MessageLoop get processed before the // CompositorChild is destroyed, so we add a task to the MessageLoop to // handle compositor desctruction. + + // The DefferedDestroyCompositor task takes ownership of compositorParent and + // will release them when it runs. MessageLoop::current()->PostTask(FROM_HERE, - NewRunnableFunction(DeferredDestroyCompositor, mCompositorParent, - mCompositorChild)); - // The DestroyCompositor task we just added to the MessageLoop will handle - // releasing mCompositorParent and mCompositorChild. - unused << mCompositorParent.forget(); - unused << mCompositorChild.forget(); + NewRunnableFunction(DeferredDestroyCompositor, compositorParent, + compositorChild)); } }