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-04-01 23:02:20 +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_OCULUS_H
|
|
|
|
#define GFX_VR_OCULUS_H
|
|
|
|
|
|
|
|
#include "nsTArray.h"
|
2017-07-04 23:28:27 +03:00
|
|
|
#include "nsISupportsImpl.h" // For NS_INLINE_DECL_REFCOUNTING
|
2015-10-18 08:24:48 +03:00
|
|
|
#include "mozilla/RefPtr.h"
|
2015-04-01 23:02:20 +03:00
|
|
|
|
|
|
|
#include "mozilla/gfx/2D.h"
|
|
|
|
#include "mozilla/EnumeratedArray.h"
|
|
|
|
|
|
|
|
#include "gfxVR.h"
|
2016-02-25 02:54:50 +03:00
|
|
|
#include "VRDisplayHost.h"
|
2015-04-01 23:02:20 +03:00
|
|
|
#include "ovr_capi_dynamic.h"
|
|
|
|
|
2016-02-25 02:54:50 +03:00
|
|
|
struct ID3D11Device;
|
|
|
|
|
2015-04-01 23:02:20 +03:00
|
|
|
namespace mozilla {
|
2016-02-25 02:54:50 +03:00
|
|
|
namespace layers {
|
|
|
|
class CompositingRenderTargetD3D11;
|
|
|
|
struct VertexShaderConstants;
|
|
|
|
struct PixelShaderConstants;
|
|
|
|
}
|
2015-04-01 23:02:20 +03:00
|
|
|
namespace gfx {
|
|
|
|
namespace impl {
|
|
|
|
|
2017-01-04 10:40:00 +03:00
|
|
|
enum class OculusControllerAxisType : uint16_t {
|
|
|
|
ThumbstickXAxis,
|
|
|
|
ThumbstickYAxis,
|
|
|
|
NumVRControllerAxisType
|
|
|
|
};
|
|
|
|
|
2017-07-04 23:28:27 +03:00
|
|
|
class VROculusSession
|
|
|
|
{
|
2017-11-02 07:44:12 +03:00
|
|
|
NS_INLINE_DECL_REFCOUNTING(VROculusSession);
|
2017-08-28 13:43:25 +03:00
|
|
|
friend class VRDisplayOculus;
|
2017-07-04 23:28:27 +03:00
|
|
|
public:
|
|
|
|
VROculusSession();
|
2017-10-16 08:30:46 +03:00
|
|
|
void Refresh(bool aForceRefresh = false);
|
2017-07-04 23:28:27 +03:00
|
|
|
bool IsTrackingReady() const;
|
|
|
|
bool IsRenderReady() const;
|
|
|
|
ovrSession Get();
|
|
|
|
void StartPresentation(const IntSize& aSize);
|
|
|
|
void StopPresentation();
|
|
|
|
void StopTracking();
|
|
|
|
bool IsQuitTimeoutActive();
|
|
|
|
already_AddRefed<layers::CompositingRenderTargetD3D11> GetNextRenderTarget();
|
|
|
|
ovrTextureSwapChain GetSwapChain();
|
|
|
|
|
|
|
|
private:
|
|
|
|
PRLibrary* mOvrLib;
|
|
|
|
ovrSession mSession;
|
|
|
|
ovrInitFlags mInitFlags;
|
|
|
|
ovrTextureSwapChain mTextureSet;
|
|
|
|
nsTArray<RefPtr<layers::CompositingRenderTargetD3D11>> mRenderTargets;
|
|
|
|
IntSize mPresentationSize;
|
|
|
|
RefPtr<ID3D11Device> mDevice;
|
|
|
|
// The timestamp of the last time Oculus set ShouldQuit to true.
|
|
|
|
TimeStamp mLastShouldQuit;
|
|
|
|
// The timestamp of the last ending presentation
|
|
|
|
TimeStamp mLastPresentationEnd;
|
2017-08-28 13:43:25 +03:00
|
|
|
VRTelemetry mTelemetry;
|
|
|
|
bool mPresenting;
|
2017-10-16 08:30:46 +03:00
|
|
|
bool mDrawBlack;
|
2017-07-04 23:28:27 +03:00
|
|
|
|
|
|
|
~VROculusSession();
|
|
|
|
void Uninitialize(bool aUnloadLib);
|
|
|
|
bool Initialize(ovrInitFlags aFlags);
|
|
|
|
bool LoadOvrLib();
|
|
|
|
void UnloadOvrLib();
|
|
|
|
bool StartSession();
|
|
|
|
void StopSession();
|
|
|
|
bool StartLib(ovrInitFlags aFlags);
|
|
|
|
void StopLib();
|
|
|
|
bool StartRendering();
|
|
|
|
void StopRendering();
|
|
|
|
};
|
|
|
|
|
2016-02-25 02:54:50 +03:00
|
|
|
class VRDisplayOculus : public VRDisplayHost
|
|
|
|
{
|
2015-04-01 23:02:20 +03:00
|
|
|
public:
|
2016-02-25 02:54:50 +03:00
|
|
|
virtual void NotifyVSync() override;
|
2015-04-01 23:02:20 +03:00
|
|
|
void ZeroSensor() override;
|
|
|
|
|
2016-02-25 02:54:50 +03:00
|
|
|
protected:
|
2017-05-09 02:01:36 +03:00
|
|
|
virtual VRHMDSensorState GetSensorState() override;
|
2016-02-25 02:54:50 +03:00
|
|
|
virtual void StartPresentation() override;
|
|
|
|
virtual void StopPresentation() override;
|
2017-07-22 03:30:34 +03:00
|
|
|
virtual bool SubmitFrame(ID3D11Texture2D* aSource,
|
2016-02-25 02:54:50 +03:00
|
|
|
const IntSize& aSize,
|
|
|
|
const gfx::Rect& aLeftEyeRect,
|
|
|
|
const gfx::Rect& aRightEyeRect) override;
|
2017-03-17 23:33:56 +03:00
|
|
|
void UpdateStageParameters();
|
2015-04-01 23:02:20 +03:00
|
|
|
|
2016-02-25 02:54:50 +03:00
|
|
|
public:
|
2017-07-04 23:28:27 +03:00
|
|
|
explicit VRDisplayOculus(VROculusSession* aSession);
|
|
|
|
void Destroy();
|
2016-02-25 02:54:50 +03:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~VRDisplayOculus();
|
2015-07-02 18:58:24 +03:00
|
|
|
|
2017-06-09 00:03:26 +03:00
|
|
|
VRHMDSensorState GetSensorState(double absTime);
|
2015-04-01 23:02:20 +03:00
|
|
|
|
2015-09-22 16:38:28 +03:00
|
|
|
ovrHmdDesc mDesc;
|
2017-07-04 23:28:27 +03:00
|
|
|
RefPtr<VROculusSession> mSession;
|
2015-04-01 23:02:20 +03:00
|
|
|
ovrFovPort mFOVPort[2];
|
2016-02-25 02:54:50 +03:00
|
|
|
|
|
|
|
ID3D11VertexShader* mQuadVS;
|
|
|
|
ID3D11PixelShader* mQuadPS;
|
|
|
|
RefPtr<ID3D11SamplerState> mLinearSamplerState;
|
|
|
|
layers::VertexShaderConstants mVSConstants;
|
|
|
|
layers::PixelShaderConstants mPSConstants;
|
|
|
|
RefPtr<ID3D11Buffer> mVSConstantBuffer;
|
|
|
|
RefPtr<ID3D11Buffer> mPSConstantBuffer;
|
|
|
|
RefPtr<ID3D11Buffer> mVertexBuffer;
|
|
|
|
RefPtr<ID3D11InputLayout> mInputLayout;
|
|
|
|
|
2017-03-17 23:33:56 +03:00
|
|
|
float mEyeHeight;
|
|
|
|
|
2016-02-25 02:54:50 +03:00
|
|
|
bool UpdateConstantBuffers();
|
2017-10-24 00:23:03 +03:00
|
|
|
void UpdateEyeParameters(gfx::Matrix4x4* aHeadToEyeTransforms = nullptr);
|
2016-02-16 23:53:33 +03:00
|
|
|
|
2016-02-25 02:54:50 +03:00
|
|
|
struct Vertex
|
|
|
|
{
|
|
|
|
float position[2];
|
|
|
|
};
|
2015-04-01 23:02:20 +03:00
|
|
|
};
|
|
|
|
|
2017-02-06 11:13:33 +03:00
|
|
|
class VRControllerOculus : public VRControllerHost
|
|
|
|
{
|
|
|
|
public:
|
2017-07-14 12:01:09 +03:00
|
|
|
explicit VRControllerOculus(dom::GamepadHand aHand, uint32_t aDisplayID);
|
2017-01-04 10:40:00 +03:00
|
|
|
float GetAxisMove(uint32_t aAxis);
|
|
|
|
void SetAxisMove(uint32_t aAxis, float aValue);
|
2017-03-16 10:54:00 +03:00
|
|
|
float GetIndexTrigger();
|
|
|
|
void SetIndexTrigger(float aValue);
|
|
|
|
float GetHandTrigger();
|
|
|
|
void SetHandTrigger(float aValue);
|
2017-03-29 12:58:11 +03:00
|
|
|
void VibrateHaptic(ovrSession aSession,
|
|
|
|
uint32_t aHapticIndex,
|
|
|
|
double aIntensity,
|
|
|
|
double aDuration,
|
|
|
|
uint32_t aPromiseID);
|
|
|
|
void StopVibrateHaptic();
|
2017-02-06 11:13:33 +03:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~VRControllerOculus();
|
2017-03-16 10:54:00 +03:00
|
|
|
|
|
|
|
private:
|
2017-03-29 12:58:11 +03:00
|
|
|
void UpdateVibrateHaptic(ovrSession aSession,
|
|
|
|
uint32_t aHapticIndex,
|
|
|
|
double aIntensity,
|
|
|
|
double aDuration,
|
|
|
|
uint64_t aVibrateIndex,
|
|
|
|
uint32_t aPromiseID);
|
|
|
|
void VibrateHapticComplete(ovrSession aSession, uint32_t aPromiseID, bool aStop);
|
|
|
|
|
2017-01-04 10:40:00 +03:00
|
|
|
float mAxisMove[static_cast<uint32_t>(
|
|
|
|
OculusControllerAxisType::NumVRControllerAxisType)];
|
2017-03-16 10:54:00 +03:00
|
|
|
float mIndexTrigger;
|
|
|
|
float mHandTrigger;
|
2017-03-29 12:58:11 +03:00
|
|
|
nsCOMPtr<nsIThread> mVibrateThread;
|
|
|
|
Atomic<bool> mIsVibrateStopped;
|
2017-02-06 11:13:33 +03:00
|
|
|
};
|
|
|
|
|
2015-04-01 23:02:20 +03:00
|
|
|
} // namespace impl
|
|
|
|
|
2017-01-24 12:49:11 +03:00
|
|
|
class VRSystemManagerOculus : public VRSystemManager
|
2015-04-01 23:02:20 +03:00
|
|
|
{
|
|
|
|
public:
|
2017-01-24 12:49:11 +03:00
|
|
|
static already_AddRefed<VRSystemManagerOculus> Create();
|
2015-04-01 23:02:20 +03:00
|
|
|
virtual void Destroy() override;
|
2017-03-30 16:35:49 +03:00
|
|
|
virtual void Shutdown() override;
|
2017-07-04 23:28:27 +03:00
|
|
|
virtual bool GetHMDs(nsTArray<RefPtr<VRDisplayHost> >& aHMDResult) override;
|
2017-03-22 04:58:06 +03:00
|
|
|
virtual bool GetIsPresenting() override;
|
2017-01-24 12:49:11 +03:00
|
|
|
virtual void HandleInput() override;
|
|
|
|
virtual void GetControllers(nsTArray<RefPtr<VRControllerHost>>&
|
|
|
|
aControllerResult) override;
|
|
|
|
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;
|
2017-01-24 12:49:11 +03:00
|
|
|
|
2015-04-01 23:02:20 +03:00
|
|
|
protected:
|
2017-07-04 23:28:27 +03:00
|
|
|
VRSystemManagerOculus();
|
2017-03-30 16:35:49 +03:00
|
|
|
|
2017-01-24 12:49:11 +03:00
|
|
|
private:
|
2017-03-16 10:54:00 +03:00
|
|
|
void HandleButtonPress(uint32_t aControllerIdx,
|
|
|
|
uint32_t aButton,
|
|
|
|
uint64_t aButtonMask,
|
2017-04-13 09:06:07 +03:00
|
|
|
uint64_t aButtonPressed,
|
|
|
|
uint64_t aButtonTouched);
|
2017-03-16 10:54:00 +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-19 08:14:13 +03:00
|
|
|
void HandleIndexTriggerPress(uint32_t aControllerIdx, uint32_t aButton, float aValue);
|
|
|
|
void HandleHandTriggerPress(uint32_t aControllerIdx, uint32_t aButton, float aValue);
|
2017-03-16 10:54:00 +03:00
|
|
|
void HandleTouchEvent(uint32_t aControllerIdx, uint32_t aButton,
|
|
|
|
uint64_t aTouchMask, uint64_t aTouched);
|
2017-07-27 10:42:59 +03:00
|
|
|
void GetControllerPoseState(uint32_t aHandIdx, dom::GamepadPoseState& aPoseState,
|
|
|
|
bool aForceUpdate = false);
|
|
|
|
|
2017-07-04 23:28:27 +03:00
|
|
|
RefPtr<impl::VRDisplayOculus> mDisplay;
|
2017-02-06 11:13:33 +03:00
|
|
|
nsTArray<RefPtr<impl::VRControllerOculus>> mOculusController;
|
2017-07-04 23:28:27 +03:00
|
|
|
RefPtr<impl::VROculusSession> mSession;
|
2015-04-01 23:02:20 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace gfx
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif /* GFX_VR_OCULUS_H */
|