2014-07-09 19:24:49 +00: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_H
|
|
|
|
#define GFX_VR_H
|
|
|
|
|
|
|
|
#include "nsTArray.h"
|
2015-04-07 17:26:44 +00:00
|
|
|
#include "nsString.h"
|
2014-07-09 19:24:49 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2015-10-18 05:24:48 +00:00
|
|
|
#include "mozilla/RefPtr.h"
|
2014-07-09 19:24:49 +00:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2015-04-07 17:26:44 +00:00
|
|
|
#include "mozilla/Atomics.h"
|
2015-09-17 21:23:13 +00:00
|
|
|
#include "mozilla/EnumeratedArray.h"
|
|
|
|
#include "mozilla/TimeStamp.h"
|
|
|
|
#include "mozilla/TypedEnumBits.h"
|
2014-07-09 19:24:49 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
2015-07-02 15:58:24 +00:00
|
|
|
namespace layers {
|
2016-02-24 23:54:50 +00:00
|
|
|
class PTextureParent;
|
2015-07-02 15:58:24 +00:00
|
|
|
}
|
2016-10-24 10:09:11 +00:00
|
|
|
namespace dom {
|
|
|
|
enum class GamepadMappingType : uint32_t;
|
|
|
|
struct GamepadPoseState;
|
|
|
|
}
|
2014-07-09 19:24:49 +00:00
|
|
|
namespace gfx {
|
2016-02-24 23:54:50 +00:00
|
|
|
class VRLayerParent;
|
|
|
|
class VRDisplayHost;
|
2016-10-07 08:58:01 +00:00
|
|
|
class VRControllerHost;
|
2014-07-09 19:24:49 +00:00
|
|
|
|
2016-10-04 08:22:42 +00:00
|
|
|
enum class VRDeviceType : uint16_t {
|
2014-07-09 19:24:49 +00:00
|
|
|
Oculus,
|
2016-07-22 19:41:00 +00:00
|
|
|
OpenVR,
|
2016-04-26 21:18:21 +00:00
|
|
|
OSVR,
|
2016-10-04 08:22:42 +00:00
|
|
|
NumVRDeviceTypes
|
2015-01-25 22:22:07 +00:00
|
|
|
};
|
2014-07-09 19:24:49 +00:00
|
|
|
|
2016-04-18 19:12:33 +00:00
|
|
|
enum class VRDisplayCapabilityFlags : uint16_t {
|
|
|
|
Cap_None = 0,
|
|
|
|
/**
|
|
|
|
* Cap_Position is set if the VRDisplay is capable of tracking its position.
|
|
|
|
*/
|
|
|
|
Cap_Position = 1 << 1,
|
|
|
|
/**
|
|
|
|
* Cap_Orientation is set if the VRDisplay is capable of tracking its orientation.
|
|
|
|
*/
|
|
|
|
Cap_Orientation = 1 << 2,
|
|
|
|
/**
|
|
|
|
* Cap_Present is set if the VRDisplay is capable of presenting content to an
|
|
|
|
* HMD or similar device. Can be used to indicate "magic window" devices that
|
|
|
|
* are capable of 6DoF tracking but for which requestPresent is not meaningful.
|
|
|
|
* If false then calls to requestPresent should always fail, and
|
|
|
|
* getEyeParameters should return null.
|
|
|
|
*/
|
|
|
|
Cap_Present = 1 << 3,
|
|
|
|
/**
|
|
|
|
* Cap_External is set if the VRDisplay is separate from the device's
|
|
|
|
* primary display. If presenting VR content will obscure
|
|
|
|
* other content on the device, this should be un-set. When
|
|
|
|
* un-set, the application should not attempt to mirror VR content
|
|
|
|
* or update non-VR UI because that content will not be visible.
|
|
|
|
*/
|
|
|
|
Cap_External = 1 << 4,
|
2016-07-22 19:41:00 +00:00
|
|
|
/**
|
|
|
|
* Cap_AngularAcceleration is set if the VRDisplay is capable of tracking its
|
|
|
|
* angular acceleration.
|
|
|
|
*/
|
|
|
|
Cap_AngularAcceleration = 1 << 5,
|
|
|
|
/**
|
|
|
|
* Cap_LinearAcceleration is set if the VRDisplay is capable of tracking its
|
|
|
|
* linear acceleration.
|
|
|
|
*/
|
|
|
|
Cap_LinearAcceleration = 1 << 6,
|
|
|
|
/**
|
|
|
|
* Cap_StageParameters is set if the VRDisplay is capable of room scale VR
|
|
|
|
* and can report the StageParameters to describe the space.
|
|
|
|
*/
|
|
|
|
Cap_StageParameters = 1 << 7,
|
2016-04-18 19:12:33 +00:00
|
|
|
/**
|
|
|
|
* Cap_All used for validity checking during IPC serialization
|
|
|
|
*/
|
2016-07-22 19:41:00 +00:00
|
|
|
Cap_All = (1 << 8) - 1
|
2015-09-17 21:23:13 +00:00
|
|
|
};
|
2016-04-18 19:12:33 +00:00
|
|
|
|
|
|
|
MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(VRDisplayCapabilityFlags)
|
2015-09-17 21:23:13 +00:00
|
|
|
|
2014-07-09 19:24:49 +00:00
|
|
|
struct VRFieldOfView {
|
|
|
|
VRFieldOfView() {}
|
|
|
|
VRFieldOfView(double up, double right, double down, double left)
|
|
|
|
: upDegrees(up), rightDegrees(right), downDegrees(down), leftDegrees(left)
|
|
|
|
{}
|
|
|
|
|
2016-07-22 19:41:00 +00:00
|
|
|
void SetFromTanRadians(double up, double right, double down, double left)
|
|
|
|
{
|
|
|
|
upDegrees = atan(up) * 180.0 / M_PI;
|
|
|
|
rightDegrees = atan(right) * 180.0 / M_PI;
|
|
|
|
downDegrees = atan(down) * 180.0 / M_PI;
|
|
|
|
leftDegrees = atan(left) * 180.0 / M_PI;
|
|
|
|
}
|
|
|
|
|
2014-07-09 19:24:49 +00:00
|
|
|
bool operator==(const VRFieldOfView& other) const {
|
|
|
|
return other.upDegrees == upDegrees &&
|
|
|
|
other.downDegrees == downDegrees &&
|
|
|
|
other.rightDegrees == rightDegrees &&
|
|
|
|
other.leftDegrees == leftDegrees;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator!=(const VRFieldOfView& other) const {
|
|
|
|
return !(*this == other);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsZero() const {
|
|
|
|
return upDegrees == 0.0 ||
|
|
|
|
rightDegrees == 0.0 ||
|
|
|
|
downDegrees == 0.0 ||
|
|
|
|
leftDegrees == 0.0;
|
|
|
|
}
|
|
|
|
|
2016-09-30 23:43:33 +00:00
|
|
|
Matrix4x4 ConstructProjectionMatrix(float zNear, float zFar, bool rightHanded) const;
|
2015-07-02 15:58:24 +00:00
|
|
|
|
2014-07-09 19:24:49 +00:00
|
|
|
double upDegrees;
|
|
|
|
double rightDegrees;
|
|
|
|
double downDegrees;
|
|
|
|
double leftDegrees;
|
|
|
|
};
|
|
|
|
|
2016-04-13 00:39:28 +00:00
|
|
|
struct VRDisplayInfo
|
2015-09-17 21:23:13 +00:00
|
|
|
{
|
2016-10-04 08:22:42 +00:00
|
|
|
VRDeviceType GetType() const { return mType; }
|
2016-02-24 23:54:50 +00:00
|
|
|
uint32_t GetDisplayID() const { return mDisplayID; }
|
|
|
|
const nsCString& GetDisplayName() const { return mDisplayName; }
|
2016-04-18 19:12:33 +00:00
|
|
|
VRDisplayCapabilityFlags GetCapabilities() const { return mCapabilityFlags; }
|
2014-07-09 19:24:49 +00:00
|
|
|
|
2015-09-17 21:23:13 +00:00
|
|
|
const IntSize& SuggestedEyeResolution() const { return mEyeResolution; }
|
|
|
|
const Point3D& GetEyeTranslation(uint32_t whichEye) const { return mEyeTranslation[whichEye]; }
|
|
|
|
const VRFieldOfView& GetEyeFOV(uint32_t whichEye) const { return mEyeFOV[whichEye]; }
|
2016-02-24 23:54:50 +00:00
|
|
|
bool GetIsConnected() const { return mIsConnected; }
|
|
|
|
bool GetIsPresenting() const { return mIsPresenting; }
|
2016-07-22 19:41:00 +00:00
|
|
|
const Size& GetStageSize() const { return mStageSize; }
|
|
|
|
const Matrix4x4& GetSittingToStandingTransform() const { return mSittingToStandingTransform; }
|
2015-09-17 21:23:13 +00:00
|
|
|
|
|
|
|
enum Eye {
|
|
|
|
Eye_Left,
|
|
|
|
Eye_Right,
|
|
|
|
NumEyes
|
|
|
|
};
|
|
|
|
|
2016-02-24 23:54:50 +00:00
|
|
|
uint32_t mDisplayID;
|
2016-10-04 08:22:42 +00:00
|
|
|
VRDeviceType mType;
|
2016-02-24 23:54:50 +00:00
|
|
|
nsCString mDisplayName;
|
2016-04-18 19:12:33 +00:00
|
|
|
VRDisplayCapabilityFlags mCapabilityFlags;
|
2016-04-13 00:39:28 +00:00
|
|
|
VRFieldOfView mEyeFOV[VRDisplayInfo::NumEyes];
|
|
|
|
Point3D mEyeTranslation[VRDisplayInfo::NumEyes];
|
2015-09-17 21:23:13 +00:00
|
|
|
IntSize mEyeResolution;
|
2016-02-24 23:54:50 +00:00
|
|
|
bool mIsConnected;
|
|
|
|
bool mIsPresenting;
|
2016-07-22 19:41:00 +00:00
|
|
|
Size mStageSize;
|
|
|
|
Matrix4x4 mSittingToStandingTransform;
|
2015-09-17 21:23:13 +00:00
|
|
|
|
2016-04-13 00:39:28 +00:00
|
|
|
bool operator==(const VRDisplayInfo& other) const {
|
2015-09-17 21:23:13 +00:00
|
|
|
return mType == other.mType &&
|
2016-02-24 23:54:50 +00:00
|
|
|
mDisplayID == other.mDisplayID &&
|
|
|
|
mDisplayName == other.mDisplayName &&
|
2016-04-18 19:12:33 +00:00
|
|
|
mCapabilityFlags == other.mCapabilityFlags &&
|
2015-09-17 21:23:13 +00:00
|
|
|
mEyeResolution == other.mEyeResolution &&
|
2016-02-24 23:54:50 +00:00
|
|
|
mIsConnected == other.mIsConnected &&
|
|
|
|
mIsPresenting == other.mIsPresenting &&
|
2015-09-17 21:23:13 +00:00
|
|
|
mEyeFOV[0] == other.mEyeFOV[0] &&
|
|
|
|
mEyeFOV[1] == other.mEyeFOV[1] &&
|
|
|
|
mEyeTranslation[0] == other.mEyeTranslation[0] &&
|
2016-07-22 19:41:00 +00:00
|
|
|
mEyeTranslation[1] == other.mEyeTranslation[1] &&
|
|
|
|
mStageSize == other.mStageSize &&
|
|
|
|
mSittingToStandingTransform == other.mSittingToStandingTransform;
|
2015-09-17 21:23:13 +00:00
|
|
|
}
|
|
|
|
|
2016-04-13 00:39:28 +00:00
|
|
|
bool operator!=(const VRDisplayInfo& other) const {
|
2015-09-17 21:23:13 +00:00
|
|
|
return !(*this == other);
|
|
|
|
}
|
2014-07-09 19:24:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct VRHMDSensorState {
|
|
|
|
double timestamp;
|
2016-01-09 02:50:10 +00:00
|
|
|
int32_t inputFrameID;
|
2016-04-18 19:12:33 +00:00
|
|
|
VRDisplayCapabilityFlags flags;
|
2014-07-09 19:24:49 +00:00
|
|
|
float orientation[4];
|
|
|
|
float position[3];
|
|
|
|
float angularVelocity[3];
|
|
|
|
float angularAcceleration[3];
|
|
|
|
float linearVelocity[3];
|
|
|
|
float linearAcceleration[3];
|
|
|
|
|
|
|
|
void Clear() {
|
|
|
|
memset(this, 0, sizeof(VRHMDSensorState));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-02-24 23:54:50 +00:00
|
|
|
class VRDisplayManager {
|
2015-07-02 15:58:24 +00:00
|
|
|
public:
|
2016-02-24 23:54:50 +00:00
|
|
|
static uint32_t AllocateDisplayID();
|
2015-07-02 15:58:24 +00:00
|
|
|
|
|
|
|
protected:
|
2016-02-24 23:54:50 +00:00
|
|
|
static Atomic<uint32_t> sDisplayBase;
|
2015-09-17 21:23:13 +00:00
|
|
|
|
2015-04-01 20:02:20 +00:00
|
|
|
public:
|
2016-02-24 23:54:50 +00:00
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VRDisplayManager)
|
2015-04-01 20:02:20 +00:00
|
|
|
|
|
|
|
virtual bool Init() = 0;
|
|
|
|
virtual void Destroy() = 0;
|
2016-02-24 23:54:50 +00:00
|
|
|
virtual void GetHMDs(nsTArray<RefPtr<VRDisplayHost>>& aHMDResult) = 0;
|
2015-04-01 20:02:20 +00:00
|
|
|
|
|
|
|
protected:
|
2016-02-24 23:54:50 +00:00
|
|
|
VRDisplayManager() { }
|
|
|
|
virtual ~VRDisplayManager() { }
|
2014-07-09 19:24:49 +00:00
|
|
|
};
|
|
|
|
|
2016-10-04 08:30:04 +00:00
|
|
|
struct VRControllerInfo
|
|
|
|
{
|
|
|
|
VRDeviceType GetType() const { return mType; }
|
|
|
|
uint32_t GetControllerID() const { return mControllerID; }
|
|
|
|
const nsCString& GetControllerName() const { return mControllerName; }
|
2016-11-04 07:53:01 +00:00
|
|
|
uint32_t GetMappingType() const { return mMappingType; }
|
2016-10-04 08:30:04 +00:00
|
|
|
uint32_t GetNumButtons() const { return mNumButtons; }
|
|
|
|
uint32_t GetNumAxes() const { return mNumAxes; }
|
|
|
|
|
|
|
|
uint32_t mControllerID;
|
|
|
|
VRDeviceType mType;
|
|
|
|
nsCString mControllerName;
|
2016-11-04 07:53:01 +00:00
|
|
|
uint32_t mMappingType;
|
2016-10-04 08:30:04 +00:00
|
|
|
uint32_t mNumButtons;
|
|
|
|
uint32_t mNumAxes;
|
|
|
|
|
|
|
|
bool operator==(const VRControllerInfo& other) const {
|
|
|
|
return mType == other.mType &&
|
|
|
|
mControllerID == other.mControllerID &&
|
|
|
|
mControllerName == other.mControllerName &&
|
|
|
|
mMappingType == other.mMappingType &&
|
|
|
|
mNumButtons == other.mNumButtons &&
|
|
|
|
mNumAxes == other.mNumAxes;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator!=(const VRControllerInfo& other) const {
|
|
|
|
return !(*this == other);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-10-07 08:58:01 +00:00
|
|
|
class VRControllerManager {
|
|
|
|
public:
|
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VRControllerManager)
|
|
|
|
|
|
|
|
static uint32_t AllocateControllerID();
|
|
|
|
virtual bool Init() = 0;
|
|
|
|
virtual void Destroy() = 0;
|
|
|
|
virtual void HandleInput() = 0;
|
|
|
|
virtual void GetControllers(nsTArray<RefPtr<VRControllerHost>>& aControllerResult) = 0;
|
|
|
|
virtual void ScanForDevices() = 0;
|
2016-10-14 09:39:51 +00:00
|
|
|
void NewButtonEvent(uint32_t aIndex, uint32_t aButton, bool aPressed);
|
2016-10-21 16:01:26 +00:00
|
|
|
void NewAxisMove(uint32_t aIndex, uint32_t aAxis, double aValue);
|
2016-10-24 10:09:11 +00:00
|
|
|
void NewPoseState(uint32_t aIndex, const dom::GamepadPoseState& aPose);
|
2016-11-04 07:53:01 +00:00
|
|
|
void AddGamepad(const char* aID, uint32_t aMapping,
|
2016-10-07 08:58:01 +00:00
|
|
|
uint32_t aNumButtons, uint32_t aNumAxes);
|
2016-10-28 08:00:12 +00:00
|
|
|
void RemoveGamepad(uint32_t aIndex);
|
2016-10-07 08:58:01 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
VRControllerManager() : mInstalled(false), mControllerCount(0) {}
|
|
|
|
virtual ~VRControllerManager() {}
|
|
|
|
|
|
|
|
bool mInstalled;
|
|
|
|
uint32_t mControllerCount;
|
|
|
|
static Atomic<uint32_t> sControllerBase;
|
2016-10-13 06:35:13 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
virtual void HandleButtonPress(uint32_t aControllerIdx,
|
|
|
|
uint64_t aButtonPressed) = 0;
|
2016-10-21 16:01:26 +00:00
|
|
|
virtual void HandleAxisMove(uint32_t aControllerIdx, uint32_t aAxis,
|
|
|
|
float aValue) = 0;
|
2016-10-24 10:09:11 +00:00
|
|
|
virtual void HandlePoseTracking(uint32_t aControllerIdx,
|
|
|
|
const dom::GamepadPoseState& aPose,
|
|
|
|
VRControllerHost* aController) = 0;
|
2016-10-07 08:58:01 +00:00
|
|
|
};
|
|
|
|
|
2014-07-09 19:24:49 +00:00
|
|
|
} // namespace gfx
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif /* GFX_VR_H */
|