Bug 1170061 - ClearOnShutdown for hwcomposer, r=sotaro

Call ClearOnShutdown while creaing HwcComposer2D object.
This commit is contained in:
Boris Chiou 2015-06-24 17:51:00 +02:00
Родитель c338afb947
Коммит b595350fe5
3 изменённых файлов: 29 добавлений и 3 удалений

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

@ -25,6 +25,7 @@
#include "HwcComposer2D.h"
#include "LayerScope.h"
#include "Units.h"
#include "mozilla/ClearOnShutdown.h"
#include "mozilla/layers/CompositorParent.h"
#include "mozilla/layers/LayerManagerComposite.h"
#include "mozilla/layers/PLayerTransaction.h"
@ -130,8 +131,24 @@ HwcComposer2D*
HwcComposer2D::GetInstance()
{
if (!sInstance) {
#ifdef HWC_DEBUG
// Make sure only create once
static int timesCreated = 0;
++timesCreated;
MOZ_ASSERT(timesCreated == 1);
#endif
LOGI("Creating new instance");
sInstance = new HwcComposer2D();
// If anyone uses the compositor thread to create HwcComposer2D,
// we just skip this function.
// If ClearOnShutdown() can handle objects in other threads
// in the future, we can remove this check.
if (NS_IsMainThread()) {
// If we create HwcComposer2D by the main thread, we can use
// ClearOnShutdown() to make sure it will be nullified properly.
ClearOnShutdown(&sInstance);
}
}
return sInstance;
}
@ -206,6 +223,7 @@ public:
} else {
screenManager->RemoveScreen(mType);
}
return NS_OK;
}
private:
GonkDisplay::DisplayType mType;

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

@ -87,7 +87,7 @@ nsWindow::nsWindow()
nsWindow::~nsWindow()
{
if (mScreen->IsPrimaryScreen()) {
HwcComposer2D::GetInstance()->SetCompositorParent(nullptr);
mComposer2D->SetCompositorParent(nullptr);
}
}
@ -356,6 +356,8 @@ nsWindow::Create(nsIWidget *aParent,
mBounds = mScreen->GetRect();
}
mComposer2D = HwcComposer2D::GetInstance();
if (!IS_TOPLEVEL()) {
return NS_OK;
}
@ -754,7 +756,7 @@ nsWindow::GetLayerManager(PLayerTransactionChild* aShadowManager,
CreateCompositor();
if (mCompositorParent && mScreen->IsPrimaryScreen()) {
HwcComposer2D::GetInstance()->SetCompositorParent(mCompositorParent);
mComposer2D->SetCompositorParent(mCompositorParent);
}
MOZ_ASSERT(mLayerManager);
return mLayerManager;
@ -831,5 +833,5 @@ nsWindow::GetComposer2D()
return nullptr;
}
return HwcComposer2D::GetInstance();
return mComposer2D;
}

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

@ -29,6 +29,10 @@ struct InputContext;
struct InputContextAction;
}
namespace mozilla {
class HwcComposer2D;
}
class nsScreenGonk;
class nsWindow : public nsBaseWidget
@ -159,6 +163,8 @@ private:
nsAutoPtr<mozilla::MultiTouchInput> mSynthesizedTouchInput;
nsRefPtr<nsScreenGonk> mScreen;
nsRefPtr<mozilla::HwcComposer2D> mComposer2D;
};
#endif /* nsWindow_h */