2015-05-03 22:32:37 +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: */
|
2014-07-09 23:24:49 +04:00
|
|
|
/* 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 mozilla_dom_VRDevice_h_
|
|
|
|
#define mozilla_dom_VRDevice_h_
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include "mozilla/ErrorResult.h"
|
|
|
|
#include "mozilla/dom/TypedArray.h"
|
|
|
|
#include "mozilla/dom/VRDeviceBinding.h"
|
|
|
|
#include "mozilla/dom/DOMPoint.h"
|
|
|
|
#include "mozilla/dom/DOMRect.h"
|
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsTArray.h"
|
|
|
|
#include "nsWrapperCache.h"
|
|
|
|
|
|
|
|
#include "gfxVR.h"
|
2015-09-18 00:23:13 +03:00
|
|
|
#include "VRDeviceProxy.h"
|
2014-07-09 23:24:49 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2015-09-18 00:23:13 +03:00
|
|
|
class Navigator;
|
2014-07-09 23:24:49 +04:00
|
|
|
|
2015-04-01 23:02:20 +03:00
|
|
|
class VRFieldOfViewReadOnly : public nsWrapperCache
|
2014-07-09 23:24:49 +04:00
|
|
|
{
|
|
|
|
public:
|
2015-04-01 23:02:20 +03:00
|
|
|
VRFieldOfViewReadOnly(nsISupports* aParent,
|
|
|
|
double aUpDegrees, double aRightDegrees,
|
2014-07-09 23:24:49 +04:00
|
|
|
double aDownDegrees, double aLeftDegrees)
|
2015-04-01 23:02:20 +03:00
|
|
|
: mParent(aParent)
|
|
|
|
, mUpDegrees(aUpDegrees)
|
2014-07-09 23:24:49 +04:00
|
|
|
, mRightDegrees(aRightDegrees)
|
|
|
|
, mDownDegrees(aDownDegrees)
|
|
|
|
, mLeftDegrees(aLeftDegrees)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-04-01 23:02:20 +03:00
|
|
|
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(VRFieldOfViewReadOnly)
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(VRFieldOfViewReadOnly)
|
|
|
|
|
2014-07-09 23:24:49 +04:00
|
|
|
double UpDegrees() const { return mUpDegrees; }
|
|
|
|
double RightDegrees() const { return mRightDegrees; }
|
|
|
|
double DownDegrees() const { return mDownDegrees; }
|
|
|
|
double LeftDegrees() const { return mLeftDegrees; }
|
|
|
|
|
2015-04-01 23:02:20 +03:00
|
|
|
nsISupports* GetParentObject() const { return mParent; }
|
|
|
|
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
|
|
|
|
2014-07-09 23:24:49 +04:00
|
|
|
protected:
|
2015-04-01 23:02:20 +03:00
|
|
|
virtual ~VRFieldOfViewReadOnly() {}
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> mParent;
|
|
|
|
|
2014-07-09 23:24:49 +04:00
|
|
|
double mUpDegrees;
|
|
|
|
double mRightDegrees;
|
|
|
|
double mDownDegrees;
|
|
|
|
double mLeftDegrees;
|
|
|
|
};
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class VRFieldOfView final : public VRFieldOfViewReadOnly
|
2014-07-09 23:24:49 +04:00
|
|
|
{
|
|
|
|
public:
|
2015-04-01 23:02:20 +03:00
|
|
|
VRFieldOfView(nsISupports* aParent, const gfx::VRFieldOfView& aSrc)
|
|
|
|
: VRFieldOfViewReadOnly(aParent,
|
|
|
|
aSrc.upDegrees, aSrc.rightDegrees,
|
|
|
|
aSrc.downDegrees, aSrc.leftDegrees)
|
|
|
|
{}
|
|
|
|
|
|
|
|
explicit VRFieldOfView(nsISupports* aParent,
|
|
|
|
double aUpDegrees = 0.0, double aRightDegrees = 0.0,
|
2014-07-09 23:24:49 +04:00
|
|
|
double aDownDegrees = 0.0, double aLeftDegrees = 0.0)
|
2015-04-01 23:02:20 +03:00
|
|
|
: VRFieldOfViewReadOnly(aParent,
|
|
|
|
aUpDegrees, aRightDegrees, aDownDegrees, aLeftDegrees)
|
2014-07-09 23:24:49 +04:00
|
|
|
{}
|
|
|
|
|
2015-04-01 23:02:20 +03:00
|
|
|
static already_AddRefed<VRFieldOfView>
|
2014-07-09 23:24:49 +04:00
|
|
|
Constructor(const GlobalObject& aGlobal, const VRFieldOfViewInit& aParams,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
2015-04-01 23:02:20 +03:00
|
|
|
static already_AddRefed<VRFieldOfView>
|
2014-07-09 23:24:49 +04:00
|
|
|
Constructor(const GlobalObject& aGlobal,
|
|
|
|
double aUpDegrees, double aRightDegrees,
|
|
|
|
double aDownDegrees, double aLeftDegrees,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
2015-04-01 23:02:20 +03:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
2014-07-09 23:24:49 +04:00
|
|
|
|
|
|
|
void SetUpDegrees(double aVal) { mUpDegrees = aVal; }
|
|
|
|
void SetRightDegrees(double aVal) { mRightDegrees = aVal; }
|
|
|
|
void SetDownDegrees(double aVal) { mDownDegrees = aVal; }
|
|
|
|
void SetLeftDegrees(double aVal) { mLeftDegrees = aVal; }
|
|
|
|
};
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class VRPositionState final : public nsWrapperCache
|
2014-07-09 23:24:49 +04:00
|
|
|
{
|
|
|
|
~VRPositionState() {}
|
|
|
|
public:
|
2015-04-01 23:02:20 +03:00
|
|
|
VRPositionState(nsISupports* aParent, const gfx::VRHMDSensorState& aState);
|
2014-07-09 23:24:49 +04:00
|
|
|
|
|
|
|
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(VRPositionState)
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(VRPositionState)
|
|
|
|
|
|
|
|
double TimeStamp() const { return mTimeStamp; }
|
|
|
|
|
|
|
|
bool HasPosition() const { return mPosition != nullptr; }
|
|
|
|
DOMPoint* GetPosition() const { return mPosition; }
|
|
|
|
|
|
|
|
bool HasOrientation() const { return mOrientation != nullptr; }
|
|
|
|
DOMPoint* GetOrientation() const { return mOrientation; }
|
|
|
|
|
|
|
|
// these are created lazily
|
|
|
|
DOMPoint* GetLinearVelocity();
|
|
|
|
DOMPoint* GetLinearAcceleration();
|
|
|
|
DOMPoint* GetAngularVelocity();
|
|
|
|
DOMPoint* GetAngularAcceleration();
|
|
|
|
|
|
|
|
nsISupports* GetParentObject() const { return mParent; }
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
2014-07-09 23:24:49 +04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
nsCOMPtr<nsISupports> mParent;
|
|
|
|
|
|
|
|
double mTimeStamp;
|
|
|
|
gfx::VRHMDSensorState mVRState;
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DOMPoint> mPosition;
|
|
|
|
RefPtr<DOMPoint> mLinearVelocity;
|
|
|
|
RefPtr<DOMPoint> mLinearAcceleration;
|
2014-07-09 23:24:49 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DOMPoint> mOrientation;
|
|
|
|
RefPtr<DOMPoint> mAngularVelocity;
|
|
|
|
RefPtr<DOMPoint> mAngularAcceleration;
|
2014-07-09 23:24:49 +04:00
|
|
|
};
|
|
|
|
|
2015-04-01 23:02:20 +03:00
|
|
|
class VREyeParameters final : public nsWrapperCache
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
VREyeParameters(nsISupports* aParent,
|
|
|
|
const gfx::VRFieldOfView& aMinFOV,
|
|
|
|
const gfx::VRFieldOfView& aMaxFOV,
|
|
|
|
const gfx::VRFieldOfView& aRecFOV,
|
|
|
|
const gfx::Point3D& aEyeTranslation,
|
|
|
|
const gfx::VRFieldOfView& aCurFOV,
|
|
|
|
const gfx::IntRect& aRenderRect);
|
|
|
|
|
|
|
|
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(VREyeParameters)
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(VREyeParameters)
|
|
|
|
|
|
|
|
VRFieldOfView* MinimumFieldOfView();
|
|
|
|
VRFieldOfView* MaximumFieldOfView();
|
|
|
|
VRFieldOfView* RecommendedFieldOfView();
|
|
|
|
DOMPoint* EyeTranslation();
|
|
|
|
|
|
|
|
VRFieldOfView* CurrentFieldOfView();
|
|
|
|
DOMRect* RenderRect();
|
|
|
|
|
|
|
|
nsISupports* GetParentObject() const { return mParent; }
|
|
|
|
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
|
|
|
protected:
|
|
|
|
~VREyeParameters() {}
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> mParent;
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<VRFieldOfView> mMinFOV;
|
|
|
|
RefPtr<VRFieldOfView> mMaxFOV;
|
|
|
|
RefPtr<VRFieldOfView> mRecFOV;
|
|
|
|
RefPtr<DOMPoint> mEyeTranslation;
|
|
|
|
RefPtr<VRFieldOfView> mCurFOV;
|
|
|
|
RefPtr<DOMRect> mRenderRect;
|
2015-04-01 23:02:20 +03:00
|
|
|
};
|
|
|
|
|
2014-07-09 23:24:49 +04:00
|
|
|
class VRDevice : public nsISupports,
|
|
|
|
public nsWrapperCache
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(VRDevice)
|
|
|
|
|
|
|
|
void GetHardwareUnitId(nsAString& aHWID) const { aHWID = mHWID; }
|
|
|
|
void GetDeviceId(nsAString& aDeviceId) const { aDeviceId = mDeviceId; }
|
|
|
|
void GetDeviceName(nsAString& aDeviceName) const { aDeviceName = mDeviceName; }
|
|
|
|
|
|
|
|
bool IsValid() { return mValid; }
|
|
|
|
|
|
|
|
nsISupports* GetParentObject() const
|
|
|
|
{
|
|
|
|
return mParent;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum VRDeviceType {
|
|
|
|
HMD,
|
|
|
|
PositionSensor
|
|
|
|
};
|
|
|
|
|
|
|
|
VRDeviceType GetType() const { return mType; }
|
|
|
|
|
2015-09-18 00:23:13 +03:00
|
|
|
static bool RefreshVRDevices(dom::Navigator* aNavigator);
|
|
|
|
static void UpdateVRDevices(nsTArray<RefPtr<VRDevice> >& aDevices,
|
|
|
|
nsISupports* aParent);
|
|
|
|
|
|
|
|
gfx::VRDeviceProxy *GetHMD() {
|
|
|
|
return mHMD;
|
|
|
|
}
|
|
|
|
|
2014-07-09 23:24:49 +04:00
|
|
|
protected:
|
2015-09-18 00:23:13 +03:00
|
|
|
VRDevice(nsISupports* aParent,
|
|
|
|
gfx::VRDeviceProxy* aHMD,
|
|
|
|
VRDeviceType aType)
|
2014-07-09 23:24:49 +04:00
|
|
|
: mParent(aParent)
|
2015-09-18 00:23:13 +03:00
|
|
|
, mHMD(aHMD)
|
2014-07-09 23:24:49 +04:00
|
|
|
, mType(aType)
|
|
|
|
, mValid(false)
|
|
|
|
{
|
2015-09-18 00:23:13 +03:00
|
|
|
MOZ_COUNT_CTOR(VRDevice);
|
2014-07-09 23:24:49 +04:00
|
|
|
mHWID.AssignLiteral("uknown");
|
|
|
|
mDeviceId.AssignLiteral("unknown");
|
|
|
|
mDeviceName.AssignLiteral("unknown");
|
|
|
|
}
|
|
|
|
|
2015-09-18 00:23:13 +03:00
|
|
|
virtual ~VRDevice()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(VRDevice);
|
2014-07-09 23:24:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> mParent;
|
2015-09-18 00:23:13 +03:00
|
|
|
RefPtr<gfx::VRDeviceProxy> mHMD;
|
2014-07-09 23:24:49 +04:00
|
|
|
nsString mHWID;
|
|
|
|
nsString mDeviceId;
|
|
|
|
nsString mDeviceName;
|
|
|
|
|
|
|
|
VRDeviceType mType;
|
|
|
|
|
|
|
|
bool mValid;
|
|
|
|
};
|
|
|
|
|
|
|
|
class HMDVRDevice : public VRDevice
|
|
|
|
{
|
|
|
|
public:
|
2015-04-01 23:02:20 +03:00
|
|
|
virtual already_AddRefed<VREyeParameters> GetEyeParameters(VREye aEye) = 0;
|
2014-07-09 23:24:49 +04:00
|
|
|
|
|
|
|
virtual void SetFieldOfView(const VRFieldOfViewInit& aLeftFOV,
|
|
|
|
const VRFieldOfViewInit& aRightFOV,
|
|
|
|
double zNear, double zFar) = 0;
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
2014-07-09 23:24:49 +04:00
|
|
|
|
|
|
|
protected:
|
2015-09-18 00:23:13 +03:00
|
|
|
HMDVRDevice(nsISupports* aParent, gfx::VRDeviceProxy* aHMD)
|
|
|
|
: VRDevice(aParent, aHMD, VRDevice::HMD)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR_INHERITED(HMDVRDevice, VRDevice);
|
|
|
|
}
|
2014-07-09 23:24:49 +04:00
|
|
|
|
2015-09-18 00:23:13 +03:00
|
|
|
virtual ~HMDVRDevice()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR_INHERITED(HMDVRDevice, VRDevice);
|
|
|
|
}
|
|
|
|
};
|
2014-07-09 23:24:49 +04:00
|
|
|
|
2015-09-18 00:23:13 +03:00
|
|
|
class HMDInfoVRDevice : public HMDVRDevice
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
HMDInfoVRDevice(nsISupports* aParent, gfx::VRDeviceProxy* aHMD);
|
|
|
|
virtual ~HMDInfoVRDevice();
|
|
|
|
|
|
|
|
/* If a field of view that is set to all 0's is passed in,
|
|
|
|
* the recommended field of view for that eye is used.
|
|
|
|
*/
|
|
|
|
virtual void SetFieldOfView(const VRFieldOfViewInit& aLeftFOV,
|
|
|
|
const VRFieldOfViewInit& aRightFOV,
|
|
|
|
double zNear, double zFar) override;
|
|
|
|
virtual already_AddRefed<VREyeParameters> GetEyeParameters(VREye aEye) override;
|
2014-07-09 23:24:49 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
class PositionSensorVRDevice : public VRDevice
|
|
|
|
{
|
|
|
|
public:
|
2015-04-01 23:02:20 +03:00
|
|
|
virtual already_AddRefed<VRPositionState> GetState() = 0;
|
|
|
|
virtual already_AddRefed<VRPositionState> GetImmediateState() = 0;
|
|
|
|
virtual void ResetSensor() = 0;
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
2014-07-09 23:24:49 +04:00
|
|
|
|
|
|
|
protected:
|
2015-09-18 00:23:13 +03:00
|
|
|
explicit PositionSensorVRDevice(nsISupports* aParent, gfx::VRDeviceProxy* aHMD)
|
|
|
|
: VRDevice(aParent, aHMD, VRDevice::PositionSensor)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR_INHERITED(PositionSensorVRDevice, VRDevice);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~PositionSensorVRDevice()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR_INHERITED(PositionSensorVRDevice, VRDevice);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class HMDPositionVRDevice : public PositionSensorVRDevice
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
HMDPositionVRDevice(nsISupports* aParent, gfx::VRDeviceProxy* aHMD);
|
|
|
|
~HMDPositionVRDevice();
|
2014-07-09 23:24:49 +04:00
|
|
|
|
2015-09-18 00:23:13 +03:00
|
|
|
virtual already_AddRefed<VRPositionState> GetState() override;
|
|
|
|
virtual already_AddRefed<VRPositionState> GetImmediateState() override;
|
|
|
|
virtual void ResetSensor() override;
|
2014-07-09 23:24:49 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif
|