2016-07-22 22:41:00 +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/. */
|
|
|
|
|
|
|
|
#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-04-06 04:45:55 +03:00
|
|
|
#include "openvr/openvr.h"
|
2016-07-22 22:41:00 +03:00
|
|
|
#include "gfxVR.h"
|
|
|
|
|
|
|
|
// OpenVR Interfaces
|
|
|
|
namespace vr {
|
|
|
|
class IVRChaperone;
|
|
|
|
class IVRCompositor;
|
|
|
|
class IVRSystem;
|
|
|
|
struct TrackedDevicePose_t;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace gfx {
|
|
|
|
namespace impl {
|
|
|
|
|
|
|
|
class VRDisplayOpenVR : public VRDisplayHost
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual void NotifyVSync() override;
|
|
|
|
virtual VRHMDSensorState GetSensorState() override;
|
|
|
|
void ZeroSensor() override;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void StartPresentation() override;
|
|
|
|
virtual void StopPresentation() override;
|
|
|
|
#if defined(XP_WIN)
|
|
|
|
virtual void SubmitFrame(mozilla::layers::TextureSourceD3D11* aSource,
|
|
|
|
const IntSize& aSize,
|
|
|
|
const VRHMDSensorState& aSensorState,
|
|
|
|
const gfx::Rect& aLeftEyeRect,
|
|
|
|
const gfx::Rect& aRightEyeRect) override;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit VRDisplayOpenVR(::vr::IVRSystem *aVRSystem,
|
|
|
|
::vr::IVRChaperone *aVRChaperone,
|
|
|
|
::vr::IVRCompositor *aVRCompositor);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~VRDisplayOpenVR();
|
|
|
|
void Destroy();
|
|
|
|
|
|
|
|
VRHMDSensorState GetSensorState(double timeOffset);
|
|
|
|
|
|
|
|
// not owned by us; global from OpenVR
|
|
|
|
::vr::IVRSystem *mVRSystem;
|
|
|
|
::vr::IVRChaperone *mVRChaperone;
|
|
|
|
::vr::IVRCompositor *mVRCompositor;
|
|
|
|
|
|
|
|
bool mIsPresenting;
|
|
|
|
|
|
|
|
void UpdateStageParameters();
|
2016-10-19 01:18:10 +03:00
|
|
|
void PollEvents();
|
2016-07-22 22:41:00 +03:00
|
|
|
};
|
|
|
|
|
2016-10-07 11:58:01 +03:00
|
|
|
class VRControllerOpenVR : public VRControllerHost
|
|
|
|
{
|
|
|
|
public:
|
2017-03-16 10:57:04 +03:00
|
|
|
explicit VRControllerOpenVR(dom::GamepadHand aHand, uint32_t aNumButtons,
|
2017-04-06 04:45:55 +03:00
|
|
|
uint32_t aNumAxes, vr::ETrackedDeviceClass aDeviceType);
|
2016-10-13 09:30:26 +03:00
|
|
|
void SetTrackedIndex(uint32_t aTrackedIndex);
|
|
|
|
uint32_t GetTrackedIndex();
|
2017-03-16 10:57:04 +03:00
|
|
|
void SetTrigger(float aValue);
|
|
|
|
float GetTrigger();
|
2017-02-02 09:57:58 +03:00
|
|
|
void VibrateHaptic(vr::IVRSystem* aVRSystem,
|
|
|
|
uint32_t aHapticIndex,
|
|
|
|
double aIntensity,
|
|
|
|
double aDuration,
|
|
|
|
uint32_t aPromiseID);
|
|
|
|
void StopVibrateHaptic();
|
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-02-02 09:57:58 +03:00
|
|
|
void UpdateVibrateHaptic(vr::IVRSystem* aVRSystem,
|
|
|
|
uint32_t aHapticIndex,
|
|
|
|
double aIntensity,
|
|
|
|
double aDuration,
|
|
|
|
uint64_t aVibrateIndex,
|
|
|
|
uint32_t aPromiseID);
|
2017-03-07 05:17:57 +03:00
|
|
|
void VibrateHapticComplete(uint32_t aPromiseID);
|
2017-02-02 09:57:58 +03:00
|
|
|
|
2016-10-13 09:30:26 +03:00
|
|
|
// The index of tracked devices from vr::IVRSystem.
|
|
|
|
uint32_t mTrackedIndex;
|
2017-03-16 10:57:04 +03:00
|
|
|
float mTrigger;
|
2017-02-02 09:57:58 +03:00
|
|
|
nsCOMPtr<nsIThread> 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 bool Init() override;
|
|
|
|
virtual void Destroy() override;
|
2017-01-24 12:49:11 +03:00
|
|
|
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,
|
|
|
|
uint32_t aPromiseID) override;
|
|
|
|
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,
|
|
|
|
uint64_t aButtonMask,
|
|
|
|
float aValue,
|
2017-04-06 14:00:20 +03:00
|
|
|
uint64_t aButtonPressed,
|
|
|
|
uint64_t aButtonTouched);
|
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);
|
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;
|
|
|
|
vr::IVRSystem *mVRSystem;
|
2017-01-24 12:49:11 +03:00
|
|
|
bool mOpenVRInstalled;
|
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 */
|