mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 13:21:05 +00:00
Bug 1241769 - Use Singleton pattern to nsScreenManagerGonk r=mwu
This commit is contained in:
parent
af8cc983cf
commit
20e5ba100c
@ -27,6 +27,7 @@
|
||||
#include "HwcComposer2D.h"
|
||||
#include "VsyncSource.h"
|
||||
#include "nsWindow.h"
|
||||
#include "mozilla/ClearOnShutdown.h"
|
||||
#include "mozilla/layers/CompositorParent.h"
|
||||
#include "mozilla/Services.h"
|
||||
#include "mozilla/ProcessPriorityManager.h"
|
||||
@ -760,19 +761,33 @@ nsScreenManagerGonk::~nsScreenManagerGonk()
|
||||
{
|
||||
}
|
||||
|
||||
static StaticRefPtr<nsScreenManagerGonk> sScreenManagerGonk;
|
||||
|
||||
/* static */ already_AddRefed<nsScreenManagerGonk>
|
||||
nsScreenManagerGonk::GetInstance()
|
||||
{
|
||||
nsCOMPtr<nsIScreenManager> manager;
|
||||
manager = do_GetService("@mozilla.org/gfx/screenmanager;1");
|
||||
MOZ_ASSERT(manager);
|
||||
return already_AddRefed<nsScreenManagerGonk>(
|
||||
static_cast<nsScreenManagerGonk*>(manager.forget().take()));
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
// Avoid creating nsScreenManagerGonk from content process.
|
||||
if (!XRE_IsParentProcess()) {
|
||||
MOZ_CRASH("Non-chrome processes should not get here.");
|
||||
}
|
||||
|
||||
// Avoid creating multiple nsScreenManagerGonk instance inside main process.
|
||||
if (!sScreenManagerGonk) {
|
||||
sScreenManagerGonk = new nsScreenManagerGonk();
|
||||
ClearOnShutdown(&sScreenManagerGonk);
|
||||
}
|
||||
|
||||
RefPtr<nsScreenManagerGonk> screenMgr = sScreenManagerGonk.get();
|
||||
return screenMgr.forget();
|
||||
}
|
||||
|
||||
/* static */ already_AddRefed< nsScreenGonk>
|
||||
nsScreenManagerGonk::GetPrimaryScreen()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
RefPtr<nsScreenManagerGonk> manager = nsScreenManagerGonk::GetInstance();
|
||||
nsCOMPtr<nsIScreen> screen;
|
||||
manager->GetPrimaryScreen(getter_AddRefs(screen));
|
||||
|
@ -50,7 +50,7 @@ NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(GfxInfo, Init)
|
||||
}
|
||||
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsWindow)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsScreenManagerGonk)
|
||||
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsScreenManagerGonk, nsScreenManagerGonk::GetInstance)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(PuppetScreenManager)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsHTMLFormatConverter)
|
||||
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsIdleServiceGonk, nsIdleServiceGonk::GetInstance)
|
||||
|
Loading…
Reference in New Issue
Block a user