2015-04-01 23:02:20 +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_OCULUS_H
|
|
|
|
#define GFX_VR_OCULUS_H
|
|
|
|
|
|
|
|
#include "nsTArray.h"
|
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
|
|
|
|
};
|
|
|
|
|
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;
|
2016-02-16 23:53:33 +03:00
|
|
|
virtual VRHMDSensorState GetSensorState() override;
|
2015-04-01 23:02:20 +03:00
|
|
|
void ZeroSensor() override;
|
|
|
|
|
2016-02-25 02:54:50 +03:00
|
|
|
protected:
|
|
|
|
virtual void StartPresentation() override;
|
|
|
|
virtual void StopPresentation() override;
|
|
|
|
virtual void SubmitFrame(mozilla::layers::TextureSourceD3D11* aSource,
|
|
|
|
const IntSize& aSize,
|
|
|
|
const VRHMDSensorState& aSensorState,
|
|
|
|
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:
|
|
|
|
explicit VRDisplayOculus(ovrSession aSession);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~VRDisplayOculus();
|
2015-04-01 23:02:20 +03:00
|
|
|
void Destroy();
|
|
|
|
|
2016-02-25 02:54:50 +03:00
|
|
|
bool RequireSession();
|
|
|
|
const ovrHmdDesc& GetHmdDesc();
|
2015-07-02 18:58:24 +03:00
|
|
|
|
2016-02-25 02:54:50 +03:00
|
|
|
already_AddRefed<layers::CompositingRenderTargetD3D11> GetNextRenderTarget();
|
2015-07-02 18:58:24 +03:00
|
|
|
|
2016-02-25 02:54:50 +03:00
|
|
|
VRHMDSensorState GetSensorState(double timeOffset);
|
2015-04-01 23:02:20 +03:00
|
|
|
|
2015-09-22 16:38:28 +03:00
|
|
|
ovrHmdDesc mDesc;
|
2016-02-25 02:54:50 +03:00
|
|
|
ovrSession mSession;
|
2015-04-01 23:02:20 +03:00
|
|
|
ovrFovPort mFOVPort[2];
|
2016-02-25 02:54:50 +03:00
|
|
|
ovrTextureSwapChain mTextureSet;
|
|
|
|
nsTArray<RefPtr<layers::CompositingRenderTargetD3D11>> mRenderTargets;
|
|
|
|
|
|
|
|
RefPtr<ID3D11Device> mDevice;
|
|
|
|
RefPtr<ID3D11DeviceContext> mContext;
|
|
|
|
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;
|
|
|
|
|
|
|
|
bool mIsPresenting;
|
2017-03-17 23:33:56 +03:00
|
|
|
float mEyeHeight;
|
|
|
|
|
2016-02-25 02:54:50 +03:00
|
|
|
bool UpdateConstantBuffers();
|
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-02-13 06:18:11 +03:00
|
|
|
explicit VRControllerOculus(dom::GamepadHand aHand);
|
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;
|
2016-02-25 02:54:50 +03:00
|
|
|
virtual void 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-01-24 12:49:11 +03:00
|
|
|
VRSystemManagerOculus()
|
2017-03-30 16:35:49 +03:00
|
|
|
: mOvrLib(nullptr), mSession(nullptr), mStarted(false)
|
2017-04-13 09:06:07 +03:00
|
|
|
{}
|
2015-09-18 00:23:13 +03:00
|
|
|
|
2017-03-30 16:35:49 +03:00
|
|
|
bool Startup();
|
|
|
|
bool LoadOvrLib();
|
|
|
|
void UnloadOvrLib();
|
|
|
|
|
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-03-30 16:35:49 +03:00
|
|
|
PRLibrary* mOvrLib;
|
2016-02-25 02:54:50 +03:00
|
|
|
RefPtr<impl::VRDisplayOculus> mHMDInfo;
|
2017-02-06 11:13:33 +03:00
|
|
|
nsTArray<RefPtr<impl::VRControllerOculus>> mOculusController;
|
2015-09-18 00:23:13 +03:00
|
|
|
RefPtr<nsIThread> mOculusThread;
|
2017-01-24 12:49:11 +03:00
|
|
|
ovrSession mSession;
|
2017-03-30 16:35:49 +03:00
|
|
|
bool mStarted;
|
2015-04-01 23:02:20 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace gfx
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif /* GFX_VR_OCULUS_H */
|