2015-09-18 00:23:13 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
|
|
|
|
#include "VRManager.h"
|
|
|
|
#include "VRManagerParent.h"
|
|
|
|
#include "gfxVR.h"
|
|
|
|
#include "mozilla/ClearOnShutdown.h"
|
2016-04-13 03:39:28 +03:00
|
|
|
#include "mozilla/dom/VRDisplay.h"
|
2016-10-07 11:58:01 +03:00
|
|
|
#include "mozilla/dom/GamepadEventTypes.h"
|
2016-02-25 02:54:50 +03:00
|
|
|
#include "mozilla/layers/TextureHost.h"
|
2016-08-23 07:09:32 +03:00
|
|
|
#include "mozilla/Unused.h"
|
2015-09-18 00:23:13 +03:00
|
|
|
|
|
|
|
#include "gfxPrefs.h"
|
|
|
|
#include "gfxVR.h"
|
|
|
|
#if defined(XP_WIN)
|
|
|
|
#include "gfxVROculus.h"
|
|
|
|
#endif
|
2017-05-31 21:14:55 +03:00
|
|
|
#if defined(XP_WIN) || defined(XP_MACOSX) || (defined(XP_LINUX) && !defined(MOZ_WIDGET_ANDROID))
|
|
|
|
#include "gfxVROpenVR.h"
|
2016-04-27 00:18:21 +03:00
|
|
|
#include "gfxVROSVR.h"
|
2015-09-18 00:23:13 +03:00
|
|
|
#endif
|
2017-03-01 19:04:12 +03:00
|
|
|
#include "gfxVRPuppet.h"
|
2016-02-25 02:54:50 +03:00
|
|
|
#include "ipc/VRLayerParent.h"
|
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::gfx;
|
|
|
|
using namespace mozilla::layers;
|
|
|
|
using namespace mozilla::gl;
|
2015-09-18 00:23:13 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace gfx {
|
|
|
|
|
|
|
|
static StaticRefPtr<VRManager> sVRManagerSingleton;
|
|
|
|
|
|
|
|
/*static*/ void
|
|
|
|
VRManager::ManagerInit()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
if (sVRManagerSingleton == nullptr) {
|
|
|
|
sVRManagerSingleton = new VRManager();
|
|
|
|
ClearOnShutdown(&sVRManagerSingleton);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
VRManager::VRManager()
|
|
|
|
: mInitialized(false)
|
2017-03-03 20:27:22 +03:00
|
|
|
, mVRTestSystemCreated(false)
|
2015-09-18 00:23:13 +03:00
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(VRManager);
|
|
|
|
MOZ_ASSERT(sVRManagerSingleton == nullptr);
|
|
|
|
|
2017-01-24 12:49:11 +03:00
|
|
|
RefPtr<VRSystemManager> mgr;
|
2015-09-18 00:23:13 +03:00
|
|
|
|
2016-07-22 22:41:00 +03:00
|
|
|
/**
|
|
|
|
* We must add the VRDisplayManager's to mManagers in a careful order to
|
|
|
|
* ensure that we don't detect the same VRDisplay from multiple API's.
|
|
|
|
*
|
|
|
|
* Oculus comes first, as it will only enumerate Oculus HMD's and is the
|
|
|
|
* native interface for Oculus HMD's.
|
|
|
|
*
|
|
|
|
* OpenvR comes second, as it is the native interface for HTC Vive
|
|
|
|
* which is the most common HMD at this time.
|
|
|
|
*
|
|
|
|
* OSVR will be used if Oculus SDK and OpenVR don't detect any HMDS,
|
|
|
|
* to support everyone else.
|
|
|
|
*/
|
|
|
|
|
2015-09-18 00:23:13 +03:00
|
|
|
#if defined(XP_WIN)
|
2016-02-25 02:54:50 +03:00
|
|
|
// The Oculus runtime is supported only on Windows
|
2017-01-24 12:49:11 +03:00
|
|
|
mgr = VRSystemManagerOculus::Create();
|
2015-09-18 00:23:13 +03:00
|
|
|
if (mgr) {
|
|
|
|
mManagers.AppendElement(mgr);
|
|
|
|
}
|
2017-05-31 21:14:55 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(XP_WIN) || defined(XP_MACOSX) || (defined(XP_LINUX) && !defined(MOZ_WIDGET_ANDROID))
|
|
|
|
// OpenVR is cross platform compatible
|
2017-01-24 12:49:11 +03:00
|
|
|
mgr = VRSystemManagerOpenVR::Create();
|
2016-07-22 22:41:00 +03:00
|
|
|
if (mgr) {
|
|
|
|
mManagers.AppendElement(mgr);
|
2016-10-07 11:58:01 +03:00
|
|
|
}
|
|
|
|
|
2016-04-27 00:18:21 +03:00
|
|
|
// OSVR is cross platform compatible
|
2017-01-24 12:49:11 +03:00
|
|
|
mgr = VRSystemManagerOSVR::Create();
|
2016-07-22 22:41:00 +03:00
|
|
|
if (mgr) {
|
2016-04-27 00:18:21 +03:00
|
|
|
mManagers.AppendElement(mgr);
|
|
|
|
}
|
2015-09-18 00:23:13 +03:00
|
|
|
#endif
|
2016-10-24 13:09:11 +03:00
|
|
|
// Enable gamepad extensions while VR is enabled.
|
2016-11-26 18:06:34 +03:00
|
|
|
// Preference only can be set at the Parent process.
|
|
|
|
if (XRE_IsParentProcess() && gfxPrefs::VREnabled()) {
|
2016-10-24 13:09:11 +03:00
|
|
|
Preferences::SetBool("dom.gamepad.extensions.enabled", true);
|
|
|
|
}
|
2015-09-18 00:23:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
VRManager::~VRManager()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(!mInitialized);
|
|
|
|
MOZ_COUNT_DTOR(VRManager);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VRManager::Destroy()
|
|
|
|
{
|
2016-04-13 03:39:28 +03:00
|
|
|
mVRDisplays.Clear();
|
2017-01-24 12:49:11 +03:00
|
|
|
mVRControllers.Clear();
|
2015-09-18 00:23:13 +03:00
|
|
|
for (uint32_t i = 0; i < mManagers.Length(); ++i) {
|
|
|
|
mManagers[i]->Destroy();
|
|
|
|
}
|
2016-10-07 11:58:01 +03:00
|
|
|
|
2015-09-18 00:23:13 +03:00
|
|
|
mInitialized = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-03-30 16:35:49 +03:00
|
|
|
VRManager::Shutdown()
|
2015-09-18 00:23:13 +03:00
|
|
|
{
|
2017-03-30 16:35:49 +03:00
|
|
|
mVRDisplays.Clear();
|
|
|
|
mVRControllers.Clear();
|
2015-09-18 00:23:13 +03:00
|
|
|
for (uint32_t i = 0; i < mManagers.Length(); ++i) {
|
2017-03-30 16:35:49 +03:00
|
|
|
mManagers[i]->Shutdown();
|
2015-09-18 00:23:13 +03:00
|
|
|
}
|
2017-03-30 16:35:49 +03:00
|
|
|
}
|
2016-10-07 11:58:01 +03:00
|
|
|
|
2017-03-30 16:35:49 +03:00
|
|
|
void
|
|
|
|
VRManager::Init()
|
|
|
|
{
|
2015-09-18 00:23:13 +03:00
|
|
|
mInitialized = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */VRManager*
|
|
|
|
VRManager::Get()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(sVRManagerSingleton != nullptr);
|
|
|
|
|
|
|
|
return sVRManagerSingleton;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VRManager::AddVRManagerParent(VRManagerParent* aVRManagerParent)
|
|
|
|
{
|
|
|
|
if (mVRManagerParents.IsEmpty()) {
|
|
|
|
Init();
|
|
|
|
}
|
|
|
|
mVRManagerParents.PutEntry(aVRManagerParent);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VRManager::RemoveVRManagerParent(VRManagerParent* aVRManagerParent)
|
|
|
|
{
|
|
|
|
mVRManagerParents.RemoveEntry(aVRManagerParent);
|
|
|
|
if (mVRManagerParents.IsEmpty()) {
|
|
|
|
Destroy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VRManager::NotifyVsync(const TimeStamp& aVsyncTimestamp)
|
|
|
|
{
|
2016-02-25 02:54:50 +03:00
|
|
|
const double kVRDisplayRefreshMaxDuration = 5000; // milliseconds
|
2017-04-12 08:12:22 +03:00
|
|
|
const double kVRDisplayInactiveMaxDuration = 30000; // milliseconds
|
2016-02-25 02:54:50 +03:00
|
|
|
|
|
|
|
bool bHaveEventListener = false;
|
2017-02-06 11:12:52 +03:00
|
|
|
bool bHaveControllerListener = false;
|
2016-02-25 02:54:50 +03:00
|
|
|
|
|
|
|
for (auto iter = mVRManagerParents.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
VRManagerParent *vmp = iter.Get()->GetKey();
|
|
|
|
bHaveEventListener |= vmp->HaveEventListener();
|
2017-02-06 11:12:52 +03:00
|
|
|
bHaveControllerListener |= vmp->HaveControllerListener();
|
2016-02-25 02:54:50 +03:00
|
|
|
}
|
|
|
|
|
2017-05-09 02:01:36 +03:00
|
|
|
// VRDisplayHost::NotifyVSync may modify mVRDisplays, so we iterate
|
|
|
|
// through a local copy here.
|
|
|
|
nsTArray<RefPtr<VRDisplayHost>> displays;
|
2016-04-13 03:39:28 +03:00
|
|
|
for (auto iter = mVRDisplays.Iter(); !iter.Done(); iter.Next()) {
|
2017-05-09 02:01:36 +03:00
|
|
|
displays.AppendElement(iter.UserData());
|
|
|
|
}
|
|
|
|
for (const auto& display: displays) {
|
2016-02-25 02:54:50 +03:00
|
|
|
display->NotifyVSync();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bHaveEventListener) {
|
|
|
|
// If content has set an EventHandler to be notified of VR display events
|
|
|
|
// we must continually refresh the VR display enumeration to check
|
2016-07-05 01:46:49 +03:00
|
|
|
// for events that we must fire such as Window.onvrdisplayconnect
|
2016-02-25 02:54:50 +03:00
|
|
|
// Note that enumeration itself may activate display hardware, such
|
|
|
|
// as Oculus, so we only do this when we know we are displaying content
|
|
|
|
// that is looking for VR displays.
|
|
|
|
if (mLastRefreshTime.IsNull()) {
|
|
|
|
// This is the first vsync, must refresh VR displays
|
|
|
|
RefreshVRDisplays();
|
2017-02-06 11:12:52 +03:00
|
|
|
if (bHaveControllerListener) {
|
|
|
|
RefreshVRControllers();
|
|
|
|
}
|
2016-10-07 12:00:45 +03:00
|
|
|
mLastRefreshTime = TimeStamp::Now();
|
2016-02-25 02:54:50 +03:00
|
|
|
} else {
|
|
|
|
// We don't have to do this every frame, so check if we
|
|
|
|
// have refreshed recently.
|
|
|
|
TimeDuration duration = TimeStamp::Now() - mLastRefreshTime;
|
|
|
|
if (duration.ToMilliseconds() > kVRDisplayRefreshMaxDuration) {
|
|
|
|
RefreshVRDisplays();
|
2017-01-04 06:30:49 +03:00
|
|
|
if (bHaveControllerListener) {
|
|
|
|
RefreshVRControllers();
|
|
|
|
}
|
2016-10-07 12:00:45 +03:00
|
|
|
mLastRefreshTime = TimeStamp::Now();
|
2016-02-25 02:54:50 +03:00
|
|
|
}
|
|
|
|
}
|
2017-03-22 04:58:06 +03:00
|
|
|
|
|
|
|
if (bHaveControllerListener) {
|
|
|
|
for (const auto& manager: mManagers) {
|
|
|
|
if (!manager->GetIsPresenting()) {
|
|
|
|
manager->HandleInput();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-09-18 00:23:13 +03:00
|
|
|
}
|
2017-03-30 16:35:49 +03:00
|
|
|
|
2017-04-12 08:12:22 +03:00
|
|
|
// Shut down the VR devices when not in use
|
|
|
|
if (bHaveEventListener || bHaveControllerListener) {
|
|
|
|
// We are using a VR device, keep it alive
|
|
|
|
mLastActiveTime = TimeStamp::Now();
|
|
|
|
} else if (mLastActiveTime.IsNull()) {
|
2017-03-30 16:35:49 +03:00
|
|
|
Shutdown();
|
2017-04-12 08:12:22 +03:00
|
|
|
} else {
|
|
|
|
TimeDuration duration = TimeStamp::Now() - mLastActiveTime;
|
|
|
|
if (duration.ToMilliseconds() > kVRDisplayInactiveMaxDuration) {
|
|
|
|
Shutdown();
|
|
|
|
}
|
2017-03-30 16:35:49 +03:00
|
|
|
}
|
2015-09-18 00:23:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-02-25 02:54:50 +03:00
|
|
|
VRManager::NotifyVRVsync(const uint32_t& aDisplayID)
|
2015-09-18 00:23:13 +03:00
|
|
|
{
|
2017-03-22 04:58:06 +03:00
|
|
|
for (const auto& manager: mManagers) {
|
|
|
|
if (manager->GetIsPresenting()) {
|
|
|
|
manager->HandleInput();
|
|
|
|
}
|
2016-12-01 01:24:29 +03:00
|
|
|
}
|
2017-03-22 04:58:06 +03:00
|
|
|
|
2017-05-09 02:01:36 +03:00
|
|
|
RefPtr<VRDisplayHost> display = GetDisplay(aDisplayID);
|
|
|
|
if (display) {
|
|
|
|
display->StartFrame();
|
2016-02-25 02:54:50 +03:00
|
|
|
}
|
2017-05-09 02:01:36 +03:00
|
|
|
|
|
|
|
RefreshVRDisplays();
|
2016-02-25 02:54:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VRManager::RefreshVRDisplays(bool aMustDispatch)
|
|
|
|
{
|
|
|
|
nsTArray<RefPtr<gfx::VRDisplayHost> > displays;
|
2015-09-18 00:23:13 +03:00
|
|
|
|
2016-07-22 22:41:00 +03:00
|
|
|
/** We don't wish to enumerate the same display from multiple managers,
|
|
|
|
* so stop as soon as we get a display.
|
|
|
|
* It is still possible to get multiple displays from a single manager,
|
|
|
|
* but do not wish to mix-and-match for risk of reporting a duplicate.
|
|
|
|
*
|
|
|
|
* XXX - Perhaps there will be a better way to detect duplicate displays
|
|
|
|
* in the future.
|
|
|
|
*/
|
|
|
|
for (uint32_t i = 0; i < mManagers.Length() && displays.Length() == 0; ++i) {
|
2017-07-04 23:28:27 +03:00
|
|
|
if (mManagers[i]->GetHMDs(displays)) {
|
|
|
|
// GetHMDs returns true to indicate that no further enumeration from
|
|
|
|
// other managers should be performed. This prevents erraneous
|
|
|
|
// redundant enumeration of the same HMD by multiple managers.
|
|
|
|
break;
|
|
|
|
}
|
2015-09-18 00:23:13 +03:00
|
|
|
}
|
|
|
|
|
2016-02-25 02:54:50 +03:00
|
|
|
bool displayInfoChanged = false;
|
2017-07-04 23:28:27 +03:00
|
|
|
bool displaySetChanged = false;
|
2015-09-18 00:23:13 +03:00
|
|
|
|
2016-02-25 02:54:50 +03:00
|
|
|
if (displays.Length() != mVRDisplays.Count()) {
|
|
|
|
// Catch cases where a VR display has been removed
|
2017-07-04 23:28:27 +03:00
|
|
|
displaySetChanged = true;
|
2015-09-18 00:23:13 +03:00
|
|
|
}
|
|
|
|
|
2016-02-25 02:54:50 +03:00
|
|
|
for (const auto& display: displays) {
|
|
|
|
if (!GetDisplay(display->GetDisplayInfo().GetDisplayID())) {
|
|
|
|
// This is a new display
|
2017-07-04 23:28:27 +03:00
|
|
|
displaySetChanged = true;
|
2015-09-18 00:23:13 +03:00
|
|
|
break;
|
|
|
|
}
|
2016-02-25 02:54:50 +03:00
|
|
|
|
|
|
|
if (display->CheckClearDisplayInfoDirty()) {
|
|
|
|
// This display's info has changed
|
|
|
|
displayInfoChanged = true;
|
2015-09-18 00:23:13 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-04 23:28:27 +03:00
|
|
|
// Rebuild the HashMap if there are additions or removals
|
|
|
|
if (displaySetChanged) {
|
2016-04-13 03:39:28 +03:00
|
|
|
mVRDisplays.Clear();
|
2016-02-25 02:54:50 +03:00
|
|
|
for (const auto& display: displays) {
|
|
|
|
mVRDisplays.Put(display->GetDisplayInfo().GetDisplayID(), display);
|
2015-09-18 00:23:13 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-04 23:28:27 +03:00
|
|
|
if (displayInfoChanged || displaySetChanged || aMustDispatch) {
|
2016-02-25 02:54:50 +03:00
|
|
|
DispatchVRDisplayInfoUpdate();
|
|
|
|
}
|
2015-09-18 00:23:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-04-13 03:39:28 +03:00
|
|
|
VRManager::DispatchVRDisplayInfoUpdate()
|
2015-09-18 00:23:13 +03:00
|
|
|
{
|
2016-02-25 02:54:50 +03:00
|
|
|
nsTArray<VRDisplayInfo> update;
|
2016-07-05 01:52:21 +03:00
|
|
|
GetVRDisplayInfo(update);
|
2015-09-18 00:23:13 +03:00
|
|
|
|
|
|
|
for (auto iter = mVRManagerParents.Iter(); !iter.Done(); iter.Next()) {
|
2016-02-25 02:54:50 +03:00
|
|
|
Unused << iter.Get()->GetKey()->SendUpdateDisplayInfo(update);
|
2015-09-18 00:23:13 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-05 01:52:21 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get any VR displays that have already been enumerated without
|
|
|
|
* activating any new devices.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
VRManager::GetVRDisplayInfo(nsTArray<VRDisplayInfo>& aDisplayInfo)
|
|
|
|
{
|
|
|
|
aDisplayInfo.Clear();
|
|
|
|
for (auto iter = mVRDisplays.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
gfx::VRDisplayHost* display = iter.UserData();
|
|
|
|
aDisplayInfo.AppendElement(VRDisplayInfo(display->GetDisplayInfo()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-25 02:54:50 +03:00
|
|
|
RefPtr<gfx::VRDisplayHost>
|
|
|
|
VRManager::GetDisplay(const uint32_t& aDisplayID)
|
2015-09-18 00:23:13 +03:00
|
|
|
{
|
2016-02-25 02:54:50 +03:00
|
|
|
RefPtr<gfx::VRDisplayHost> display;
|
|
|
|
if (mVRDisplays.Get(aDisplayID, getter_AddRefs(display))) {
|
|
|
|
return display;
|
2015-09-18 00:23:13 +03:00
|
|
|
}
|
2016-02-25 02:54:50 +03:00
|
|
|
return nullptr;
|
2015-09-18 00:23:13 +03:00
|
|
|
}
|
|
|
|
|
2016-10-07 11:58:01 +03:00
|
|
|
RefPtr<gfx::VRControllerHost>
|
|
|
|
VRManager::GetController(const uint32_t& aControllerID)
|
|
|
|
{
|
|
|
|
RefPtr<gfx::VRControllerHost> controller;
|
|
|
|
if (mVRControllers.Get(aControllerID, getter_AddRefs(controller))) {
|
|
|
|
return controller;
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VRManager::GetVRControllerInfo(nsTArray<VRControllerInfo>& aControllerInfo)
|
|
|
|
{
|
|
|
|
aControllerInfo.Clear();
|
|
|
|
for (auto iter = mVRControllers.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
gfx::VRControllerHost* controller = iter.UserData();
|
|
|
|
aControllerInfo.AppendElement(VRControllerInfo(controller->GetControllerInfo()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-07 12:00:45 +03:00
|
|
|
void
|
|
|
|
VRManager::RefreshVRControllers()
|
|
|
|
{
|
|
|
|
nsTArray<RefPtr<gfx::VRControllerHost>> controllers;
|
|
|
|
|
2016-12-01 09:16:16 +03:00
|
|
|
ScanForControllers();
|
2016-11-28 11:57:58 +03:00
|
|
|
|
2017-01-24 12:49:11 +03:00
|
|
|
for (uint32_t i = 0; i < mManagers.Length()
|
2016-10-07 12:00:45 +03:00
|
|
|
&& controllers.Length() == 0; ++i) {
|
2017-01-24 12:49:11 +03:00
|
|
|
mManagers[i]->GetControllers(controllers);
|
2016-10-07 12:00:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool controllerInfoChanged = false;
|
|
|
|
|
|
|
|
if (controllers.Length() != mVRControllers.Count()) {
|
|
|
|
// Catch cases where VR controllers has been removed
|
|
|
|
controllerInfoChanged = true;
|
|
|
|
}
|
|
|
|
|
2017-03-22 04:58:06 +03:00
|
|
|
for (const auto& controller: controllers) {
|
2016-10-07 12:00:45 +03:00
|
|
|
if (!GetController(controller->GetControllerInfo().GetControllerID())) {
|
|
|
|
// This is a new controller
|
|
|
|
controllerInfoChanged = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (controllerInfoChanged) {
|
|
|
|
mVRControllers.Clear();
|
2017-03-22 04:58:06 +03:00
|
|
|
for (const auto& controller: controllers) {
|
2016-10-07 12:00:45 +03:00
|
|
|
mVRControllers.Put(controller->GetControllerInfo().GetControllerID(),
|
|
|
|
controller);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-07 11:58:01 +03:00
|
|
|
void
|
2016-12-01 09:16:16 +03:00
|
|
|
VRManager::ScanForControllers()
|
2016-10-07 11:58:01 +03:00
|
|
|
{
|
2017-01-24 12:49:11 +03:00
|
|
|
for (uint32_t i = 0; i < mManagers.Length(); ++i) {
|
|
|
|
mManagers[i]->ScanForControllers();
|
2016-10-07 11:58:01 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-01 09:16:16 +03:00
|
|
|
void
|
|
|
|
VRManager::RemoveControllers()
|
|
|
|
{
|
2017-01-24 12:49:11 +03:00
|
|
|
for (uint32_t i = 0; i < mManagers.Length(); ++i) {
|
|
|
|
mManagers[i]->RemoveControllers();
|
2016-12-01 09:16:16 +03:00
|
|
|
}
|
|
|
|
mVRControllers.Clear();
|
|
|
|
}
|
|
|
|
|
2017-03-03 20:27:22 +03:00
|
|
|
void
|
|
|
|
VRManager::CreateVRTestSystem()
|
|
|
|
{
|
|
|
|
if (mVRTestSystemCreated) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<VRSystemManager> mgr = VRSystemManagerPuppet::Create();
|
|
|
|
if (mgr) {
|
|
|
|
mManagers.AppendElement(mgr);
|
|
|
|
mVRTestSystemCreated = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-07 11:58:01 +03:00
|
|
|
template<class T>
|
|
|
|
void
|
2017-07-17 06:44:39 +03:00
|
|
|
VRManager::NotifyGamepadChange(uint32_t aIndex, const T& aInfo)
|
2016-10-07 11:58:01 +03:00
|
|
|
{
|
2017-07-17 06:44:39 +03:00
|
|
|
dom::GamepadChangeEventBody body(aInfo);
|
|
|
|
dom::GamepadChangeEvent e(aIndex, dom::GamepadServiceType::VR, body);
|
2016-10-07 11:58:01 +03:00
|
|
|
|
|
|
|
for (auto iter = mVRManagerParents.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
Unused << iter.Get()->GetKey()->SendGamepadUpdate(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-02 09:57:58 +03:00
|
|
|
void
|
|
|
|
VRManager::VibrateHaptic(uint32_t aControllerIdx, uint32_t aHapticIndex,
|
2017-02-02 09:59:44 +03:00
|
|
|
double aIntensity, double aDuration, uint32_t aPromiseID)
|
|
|
|
|
2017-02-02 09:57:58 +03:00
|
|
|
{
|
|
|
|
for (uint32_t i = 0; i < mManagers.Length(); ++i) {
|
|
|
|
mManagers[i]->VibrateHaptic(aControllerIdx, aHapticIndex,
|
2017-02-02 09:59:44 +03:00
|
|
|
aIntensity, aDuration, aPromiseID);
|
2017-02-02 09:57:58 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-07 05:17:57 +03:00
|
|
|
void
|
|
|
|
VRManager::StopVibrateHaptic(uint32_t aControllerIdx)
|
|
|
|
{
|
|
|
|
for (const auto& manager: mManagers) {
|
|
|
|
manager->StopVibrateHaptic(aControllerIdx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VRManager::NotifyVibrateHapticCompleted(uint32_t aPromiseID)
|
|
|
|
{
|
|
|
|
for (auto iter = mVRManagerParents.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
Unused << iter.Get()->GetKey()->SendReplyGamepadVibrateHaptic(aPromiseID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-23 11:55:30 +03:00
|
|
|
void
|
|
|
|
VRManager::DispatchSubmitFrameResult(uint32_t aDisplayID, const VRSubmitFrameResultInfo& aResult)
|
|
|
|
{
|
|
|
|
for (auto iter = mVRManagerParents.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
Unused << iter.Get()->GetKey()->SendDispatchSubmitFrameResult(aDisplayID, aResult);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-18 00:23:13 +03:00
|
|
|
} // namespace gfx
|
|
|
|
} // namespace mozilla
|