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
|
2016-07-22 22:41:00 +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_OPENVR_H
|
|
|
|
#define GFX_VR_OPENVR_H
|
|
|
|
|
|
|
|
#include "nsTArray.h"
|
|
|
|
#include "nsIScreen.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "mozilla/RefPtr.h"
|
|
|
|
|
|
|
|
#include "mozilla/gfx/2D.h"
|
|
|
|
#include "mozilla/EnumeratedArray.h"
|
|
|
|
|
2017-02-28 03:59:30 +03:00
|
|
|
#include "openvr.h"
|
2016-07-22 22:41:00 +03:00
|
|
|
#include "gfxVR.h"
|
2018-05-08 21:31:28 +03:00
|
|
|
#include "VRDisplayLocal.h"
|
2016-07-22 22:41:00 +03:00
|
|
|
|
2017-07-04 23:50:40 +03:00
|
|
|
#if defined(XP_MACOSX)
|
|
|
|
class MacIOSurface;
|
|
|
|
#endif
|
2016-07-22 22:41:00 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace gfx {
|
2017-11-15 12:39:38 +03:00
|
|
|
class VRThread;
|
|
|
|
|
2016-07-22 22:41:00 +03:00
|
|
|
namespace impl {
|
|
|
|
|
2018-05-08 21:31:28 +03:00
|
|
|
class VRDisplayOpenVR : public VRDisplayLocal
|
2016-07-22 22:41:00 +03:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
void ZeroSensor() override;
|
2017-09-08 10:35:53 +03:00
|
|
|
bool GetIsHmdPresent();
|
2016-07-22 22:41:00 +03:00
|
|
|
|
|
|
|
protected:
|
2017-05-09 02:01:36 +03:00
|
|
|
virtual VRHMDSensorState GetSensorState() override;
|
2016-07-22 22:41:00 +03:00
|
|
|
virtual void StartPresentation() override;
|
|
|
|
virtual void StopPresentation() override;
|
|
|
|
#if defined(XP_WIN)
|
2017-07-22 03:30:34 +03:00
|
|
|
virtual bool SubmitFrame(ID3D11Texture2D* aSource,
|
2016-07-22 22:41:00 +03:00
|
|
|
const IntSize& aSize,
|
|
|
|
const gfx::Rect& aLeftEyeRect,
|
|
|
|
const gfx::Rect& aRightEyeRect) override;
|
2017-07-04 23:50:40 +03:00
|
|
|
#elif defined(XP_MACOSX)
|
|
|
|
virtual bool SubmitFrame(MacIOSurface* aMacIOSurface,
|
|
|
|
const IntSize& aSize,
|
|
|
|
const gfx::Rect& aLeftEyeRect,
|
|
|
|
const gfx::Rect& aRightEyeRect) override;
|
2016-07-22 22:41:00 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit VRDisplayOpenVR(::vr::IVRSystem *aVRSystem,
|
|
|
|
::vr::IVRChaperone *aVRChaperone,
|
|
|
|
::vr::IVRCompositor *aVRCompositor);
|
2017-10-11 00:42:37 +03:00
|
|
|
void Refresh();
|
2016-07-22 22:41:00 +03:00
|
|
|
protected:
|
|
|
|
virtual ~VRDisplayOpenVR();
|
|
|
|
void Destroy();
|
|
|
|
|
|
|
|
// not owned by us; global from OpenVR
|
|
|
|
::vr::IVRSystem *mVRSystem;
|
|
|
|
::vr::IVRChaperone *mVRChaperone;
|
|
|
|
::vr::IVRCompositor *mVRCompositor;
|
|
|
|
|
2017-08-28 13:43:25 +03:00
|
|
|
VRTelemetry mTelemetry;
|
2016-07-22 22:41:00 +03:00
|
|
|
bool mIsPresenting;
|
2017-09-08 10:35:53 +03:00
|
|
|
bool mIsHmdPresent;
|
2016-07-22 22:41:00 +03:00
|
|
|
|
|
|
|
void UpdateStageParameters();
|
2017-10-24 00:23:03 +03:00
|
|
|
void UpdateEyeParameters(gfx::Matrix4x4* aHeadToEyeTransforms = nullptr);
|
2018-05-08 21:31:28 +03:00
|
|
|
bool SubmitFrameOpenVRHandle(void* aTextureHandle,
|
|
|
|
::vr::ETextureType aTextureType,
|
|
|
|
const IntSize& aSize,
|
|
|
|
const gfx::Rect& aLeftEyeRect,
|
|
|
|
const gfx::Rect& aRightEyeRect);
|
2016-07-22 22:41:00 +03:00
|
|
|
};
|
|
|
|
|
2016-10-07 11:58:01 +03:00
|
|
|
class VRControllerOpenVR : public VRControllerHost
|
|
|
|
{
|
|
|
|
public:
|
2017-08-01 23:36:26 +03:00
|
|
|
explicit VRControllerOpenVR(dom::GamepadHand aHand, uint32_t aDisplayID, uint32_t aNumButtons,
|
|
|
|
uint32_t aNumTriggers, uint32_t aNumAxes,
|
2017-08-04 09:52:01 +03:00
|
|
|
const nsCString& aId);
|
2016-10-13 09:30:26 +03:00
|
|
|
void SetTrackedIndex(uint32_t aTrackedIndex);
|
|
|
|
uint32_t GetTrackedIndex();
|
2017-04-24 13:52:06 +03:00
|
|
|
float GetAxisMove(uint32_t aAxis);
|
|
|
|
void SetAxisMove(uint32_t aAxis, float aValue);
|
2017-08-01 23:36:26 +03:00
|
|
|
void SetTrigger(uint32_t aButton, float aValue);
|
|
|
|
float GetTrigger(uint32_t aButton);
|
2017-04-18 10:58:34 +03:00
|
|
|
void SetHand(dom::GamepadHand aHand);
|
2017-04-18 08:04:53 +03:00
|
|
|
void VibrateHaptic(::vr::IVRSystem* aVRSystem,
|
2017-02-02 09:57:58 +03:00
|
|
|
uint32_t aHapticIndex,
|
|
|
|
double aIntensity,
|
|
|
|
double aDuration,
|
2017-11-30 14:37:07 +03:00
|
|
|
const VRManagerPromise& aPromise);
|
2017-02-02 09:57:58 +03:00
|
|
|
void StopVibrateHaptic();
|
2017-12-07 14:20:49 +03:00
|
|
|
void ShutdownVibrateHapticThread();
|
2016-10-07 11:58:01 +03:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~VRControllerOpenVR();
|
2016-10-13 09:30:26 +03:00
|
|
|
|
2017-03-16 10:57:04 +03:00
|
|
|
private:
|
2017-04-18 08:04:53 +03:00
|
|
|
void UpdateVibrateHaptic(::vr::IVRSystem* aVRSystem,
|
2017-02-02 09:57:58 +03:00
|
|
|
uint32_t aHapticIndex,
|
|
|
|
double aIntensity,
|
|
|
|
double aDuration,
|
|
|
|
uint64_t aVibrateIndex,
|
2017-11-30 14:37:07 +03:00
|
|
|
const VRManagerPromise& aPromise);
|
|
|
|
void VibrateHapticComplete(const VRManagerPromise& aPromise);
|
2017-02-02 09:57:58 +03:00
|
|
|
|
2017-04-18 08:04:53 +03:00
|
|
|
// The index of tracked devices from ::vr::IVRSystem.
|
2016-10-13 09:30:26 +03:00
|
|
|
uint32_t mTrackedIndex;
|
2017-11-15 12:39:38 +03:00
|
|
|
RefPtr<VRThread> mVibrateThread;
|
2017-03-07 05:17:57 +03:00
|
|
|
Atomic<bool> mIsVibrateStopped;
|
2016-10-07 11:58:01 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace impl
|
|
|
|
|
2017-01-24 12:49:11 +03:00
|
|
|
class VRSystemManagerOpenVR : public VRSystemManager
|
2016-10-07 11:58:01 +03:00
|
|
|
{
|
|
|
|
public:
|
2017-01-24 12:49:11 +03:00
|
|
|
static already_AddRefed<VRSystemManagerOpenVR> Create();
|
2016-10-07 11:58:01 +03:00
|
|
|
|
|
|
|
virtual void Destroy() override;
|
2017-03-30 16:35:49 +03:00
|
|
|
virtual void Shutdown() override;
|
2017-10-11 00:42:37 +03:00
|
|
|
virtual void NotifyVSync() override;
|
|
|
|
virtual void Enumerate() override;
|
|
|
|
virtual bool ShouldInhibitEnumeration() override;
|
|
|
|
virtual void GetHMDs(nsTArray<RefPtr<VRDisplayHost>>& aHMDResult) override;
|
2017-03-22 04:58:06 +03:00
|
|
|
virtual bool GetIsPresenting() override;
|
2016-10-07 11:58:01 +03:00
|
|
|
virtual void HandleInput() override;
|
|
|
|
virtual void GetControllers(nsTArray<RefPtr<VRControllerHost>>&
|
|
|
|
aControllerResult) override;
|
2017-01-24 12:49:11 +03:00
|
|
|
virtual void ScanForControllers() override;
|
|
|
|
virtual void RemoveControllers() override;
|
2017-02-02 09:57:58 +03:00
|
|
|
virtual void VibrateHaptic(uint32_t aControllerIdx,
|
|
|
|
uint32_t aHapticIndex,
|
|
|
|
double aIntensity,
|
|
|
|
double aDuration,
|
2017-11-30 14:37:07 +03:00
|
|
|
const VRManagerPromise& aPromise) override;
|
2017-02-02 09:57:58 +03:00
|
|
|
virtual void StopVibrateHaptic(uint32_t aControllerIdx) override;
|
2016-10-07 11:58:01 +03:00
|
|
|
|
2017-01-24 12:49:11 +03:00
|
|
|
protected:
|
|
|
|
VRSystemManagerOpenVR();
|
2016-10-07 11:58:01 +03:00
|
|
|
|
2017-01-24 12:49:11 +03:00
|
|
|
private:
|
2017-03-16 10:57:04 +03:00
|
|
|
void HandleButtonPress(uint32_t aControllerIdx,
|
|
|
|
uint32_t aButton,
|
|
|
|
uint64_t aButtonMask,
|
2017-04-06 14:00:20 +03:00
|
|
|
uint64_t aButtonPressed,
|
|
|
|
uint64_t aButtonTouched);
|
2017-03-16 10:57:04 +03:00
|
|
|
void HandleTriggerPress(uint32_t aControllerIdx,
|
|
|
|
uint32_t aButton,
|
2017-08-01 23:36:26 +03:00
|
|
|
uint32_t aTrigger,
|
2017-04-19 08:14:13 +03:00
|
|
|
float aValue);
|
2017-03-16 10:57:04 +03:00
|
|
|
void HandleAxisMove(uint32_t aControllerIdx, uint32_t aAxis,
|
|
|
|
float aValue);
|
|
|
|
void HandlePoseTracking(uint32_t aControllerIdx,
|
|
|
|
const dom::GamepadPoseState& aPose,
|
|
|
|
VRControllerHost* aController);
|
2017-04-18 08:04:53 +03:00
|
|
|
dom::GamepadHand GetGamepadHandFromControllerRole(
|
|
|
|
::vr::ETrackedControllerRole aRole);
|
2017-08-04 09:52:01 +03:00
|
|
|
void GetControllerDeviceId(::vr::ETrackedDeviceClass aDeviceType,
|
|
|
|
::vr::TrackedDeviceIndex_t aDeviceIndex,
|
|
|
|
nsCString& aId);
|
2016-10-13 09:35:13 +03:00
|
|
|
|
2017-01-24 12:49:11 +03:00
|
|
|
// there can only be one
|
|
|
|
RefPtr<impl::VRDisplayOpenVR> mOpenVRHMD;
|
2016-10-07 11:58:01 +03:00
|
|
|
nsTArray<RefPtr<impl::VRControllerOpenVR>> mOpenVRController;
|
2017-04-18 08:04:53 +03:00
|
|
|
::vr::IVRSystem *mVRSystem;
|
2018-05-04 02:27:46 +03:00
|
|
|
bool mRuntimeCheckFailed;
|
2017-11-28 05:55:50 +03:00
|
|
|
bool mIsWindowsMR;
|
2016-10-07 11:58:01 +03:00
|
|
|
};
|
|
|
|
|
2016-07-22 22:41:00 +03:00
|
|
|
} // namespace gfx
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* GFX_VR_OPENVR_H */
|