2017-10-28 02:10:06 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2015-09-18 00:23:13 +03:00
|
|
|
* 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/. */
|
|
|
|
|
|
|
|
#ifndef GFX_VR_MANAGER_H
|
|
|
|
#define GFX_VR_MANAGER_H
|
|
|
|
|
|
|
|
#include "nsRefPtrHashtable.h"
|
|
|
|
#include "nsTArray.h"
|
|
|
|
#include "nsTHashtable.h"
|
2016-02-25 02:54:50 +03:00
|
|
|
#include "nsDataHashtable.h"
|
2015-09-18 00:23:13 +03:00
|
|
|
#include "mozilla/TimeStamp.h"
|
|
|
|
#include "gfxVR.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
2017-11-02 07:44:12 +03:00
|
|
|
namespace layers {
|
|
|
|
class TextureHost;
|
2016-02-25 02:54:50 +03:00
|
|
|
}
|
2015-09-18 00:23:13 +03:00
|
|
|
namespace gfx {
|
|
|
|
|
2016-02-25 02:54:50 +03:00
|
|
|
class VRLayerParent;
|
2015-09-18 00:23:13 +03:00
|
|
|
class VRManagerParent;
|
2016-02-25 02:54:50 +03:00
|
|
|
class VRDisplayHost;
|
2018-07-06 16:38:01 +03:00
|
|
|
#if defined(XP_WIN) || defined(XP_MACOSX) || (defined(XP_LINUX) && !defined(MOZ_WIDGET_ANDROID))
|
2018-05-08 21:31:28 +03:00
|
|
|
class VRService;
|
|
|
|
#endif
|
2017-11-22 01:18:16 +03:00
|
|
|
class VRSystemManagerPuppet;
|
2018-03-14 03:09:54 +03:00
|
|
|
class VRSystemManagerExternal;
|
2015-09-18 00:23:13 +03:00
|
|
|
|
|
|
|
class VRManager
|
|
|
|
{
|
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(mozilla::gfx::VRManager)
|
|
|
|
|
|
|
|
public:
|
|
|
|
static void ManagerInit();
|
|
|
|
static VRManager* Get();
|
|
|
|
|
|
|
|
void AddVRManagerParent(VRManagerParent* aVRManagerParent);
|
|
|
|
void RemoveVRManagerParent(VRManagerParent* aVRManagerParent);
|
|
|
|
|
|
|
|
void NotifyVsync(const TimeStamp& aVsyncTimestamp);
|
2016-02-25 02:54:50 +03:00
|
|
|
void NotifyVRVsync(const uint32_t& aDisplayID);
|
|
|
|
void RefreshVRDisplays(bool aMustDispatch = false);
|
2017-07-14 12:08:15 +03:00
|
|
|
void RefreshVRControllers();
|
2016-12-01 09:16:16 +03:00
|
|
|
void ScanForControllers();
|
|
|
|
void RemoveControllers();
|
2017-07-17 06:44:39 +03:00
|
|
|
template<class T> void NotifyGamepadChange(uint32_t aIndex, const T& aInfo);
|
2016-02-25 02:54:50 +03:00
|
|
|
RefPtr<gfx::VRDisplayHost> GetDisplay(const uint32_t& aDisplayID);
|
2016-07-05 01:52:21 +03:00
|
|
|
void GetVRDisplayInfo(nsTArray<VRDisplayInfo>& aDisplayInfo);
|
2016-10-07 11:58:01 +03:00
|
|
|
RefPtr<gfx::VRControllerHost> GetController(const uint32_t& aControllerID);
|
|
|
|
void GetVRControllerInfo(nsTArray<VRControllerInfo>& aControllerInfo);
|
2017-03-03 20:27:22 +03:00
|
|
|
void CreateVRTestSystem();
|
2017-11-22 01:18:16 +03:00
|
|
|
VRSystemManagerPuppet* GetPuppetManager();
|
2018-03-14 03:09:54 +03:00
|
|
|
VRSystemManagerExternal* GetExternalManager();
|
2017-11-22 01:18:16 +03:00
|
|
|
|
2017-02-02 09:57:58 +03:00
|
|
|
void VibrateHaptic(uint32_t aControllerIdx, uint32_t aHapticIndex,
|
2017-11-30 14:37:07 +03:00
|
|
|
double aIntensity, double aDuration, const VRManagerPromise& aPromise);
|
2017-03-07 05:17:57 +03:00
|
|
|
void StopVibrateHaptic(uint32_t aControllerIdx);
|
2017-11-30 14:37:07 +03:00
|
|
|
void NotifyVibrateHapticCompleted(const VRManagerPromise& aPromise);
|
2017-05-23 11:55:30 +03:00
|
|
|
void DispatchSubmitFrameResult(uint32_t aDisplayID, const VRSubmitFrameResultInfo& aResult);
|
2015-09-18 00:23:13 +03:00
|
|
|
|
|
|
|
protected:
|
|
|
|
VRManager();
|
|
|
|
~VRManager();
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
void Init();
|
|
|
|
void Destroy();
|
2017-03-30 16:35:49 +03:00
|
|
|
void Shutdown();
|
2015-09-18 00:23:13 +03:00
|
|
|
|
2016-04-13 03:39:28 +03:00
|
|
|
void DispatchVRDisplayInfoUpdate();
|
2017-10-11 00:42:37 +03:00
|
|
|
void UpdateRequestedDevices();
|
|
|
|
void EnumerateVRDisplays();
|
|
|
|
void CheckForInactiveTimeout();
|
2015-09-18 00:23:13 +03:00
|
|
|
|
|
|
|
typedef nsTHashtable<nsRefPtrHashKey<VRManagerParent>> VRManagerParentSet;
|
|
|
|
VRManagerParentSet mVRManagerParents;
|
|
|
|
|
2017-01-24 12:49:11 +03:00
|
|
|
typedef nsTArray<RefPtr<VRSystemManager>> VRSystemManagerArray;
|
|
|
|
VRSystemManagerArray mManagers;
|
2016-10-07 11:58:01 +03:00
|
|
|
|
2016-02-25 02:54:50 +03:00
|
|
|
typedef nsRefPtrHashtable<nsUint32HashKey, gfx::VRDisplayHost> VRDisplayHostHashMap;
|
|
|
|
VRDisplayHostHashMap mVRDisplays;
|
2015-09-18 00:23:13 +03:00
|
|
|
|
2016-10-07 11:58:01 +03:00
|
|
|
typedef nsRefPtrHashtable<nsUint32HashKey, gfx::VRControllerHost> VRControllerHostHashMap;
|
|
|
|
VRControllerHostHashMap mVRControllers;
|
|
|
|
|
2015-09-18 00:23:13 +03:00
|
|
|
Atomic<bool> mInitialized;
|
|
|
|
|
2017-10-11 00:42:37 +03:00
|
|
|
TimeStamp mLastControllerEnumerationTime;
|
|
|
|
TimeStamp mLastDisplayEnumerationTime;
|
2017-04-12 08:12:22 +03:00
|
|
|
TimeStamp mLastActiveTime;
|
2017-11-22 01:18:16 +03:00
|
|
|
RefPtr<VRSystemManagerPuppet> mPuppetManager;
|
2018-03-14 03:09:54 +03:00
|
|
|
RefPtr<VRSystemManagerExternal> mExternalManager;
|
2018-07-06 16:38:01 +03:00
|
|
|
#if defined(XP_WIN) || defined(XP_MACOSX) || (defined(XP_LINUX) && !defined(MOZ_WIDGET_ANDROID))
|
2018-05-08 21:31:28 +03:00
|
|
|
RefPtr<VRService> mVRService;
|
|
|
|
#endif
|
2017-10-11 00:42:37 +03:00
|
|
|
bool mVRDisplaysRequested;
|
|
|
|
bool mVRControllersRequested;
|
2015-09-18 00:23:13 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace gfx
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // GFX_VR_MANAGER_H
|