Merge mozilla-central to autoland. CLOSED TREE
[gecko.git] / gfx / vr / service / OculusSession.h
blob0ab70e1817f60debf4fdd9b87c3807cabe940613
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef GFX_VR_SERVICE_OCULUSSESSION_H
8 #define GFX_VR_SERVICE_OCULUSSESSION_H
10 #include "VRSession.h"
12 #include "moz_external_vr.h"
13 #include "mozilla/TimeStamp.h"
14 #include "mozilla/gfx/2D.h"
15 #include "nsTArray.h"
16 #include "oculus/ovr_capi_dynamic.h"
17 #include "prlink.h"
18 #include "ShaderDefinitionsD3D11.h" // for VertexShaderConstants and PixelShaderConstants
20 struct ID3D11Device;
22 namespace mozilla {
23 namespace layers {
24 struct VertexShaderConstants;
25 struct PixelShaderConstants;
26 } // namespace layers
27 namespace gfx {
29 class OculusSession : public VRSession {
30 public:
31 OculusSession();
32 virtual ~OculusSession();
34 bool Initialize(mozilla::gfx::VRSystemState& aSystemState,
35 bool aDetectRuntimesOnly) override;
36 void Shutdown() override;
37 void ProcessEvents(mozilla::gfx::VRSystemState& aSystemState) override;
38 void StartFrame(mozilla::gfx::VRSystemState& aSystemState) override;
39 bool StartPresentation() override;
40 void StopPresentation() override;
41 bool SubmitFrame(const mozilla::gfx::VRLayer_Stereo_Immersive& aLayer,
42 ID3D11Texture2D* aTexture) override;
43 void VibrateHaptic(uint32_t aControllerIdx, uint32_t aHapticIndex,
44 float aIntensity, float aDuration) override;
45 void StopVibrateHaptic(uint32_t aControllerIdx) override;
46 void StopAllHaptics() override;
48 private:
49 bool LoadOvrLib();
50 void UnloadOvrLib();
51 bool StartLib(ovrInitFlags aFlags);
52 void StopLib();
53 bool StartSession();
54 void StopSession();
55 bool StartRendering();
56 void StopRendering();
57 bool CreateD3DObjects();
58 bool CreateShaders();
59 void DestroyShaders();
60 void CoverTransitions();
61 void UpdateVisibility();
62 bool ChangeVisibility(bool bVisible);
63 bool InitState(mozilla::gfx::VRSystemState& aSystemState);
64 void UpdateStageParameters(mozilla::gfx::VRDisplayState& aState);
65 void UpdateEyeParameters(mozilla::gfx::VRSystemState& aState);
66 void UpdateHeadsetPose(mozilla::gfx::VRSystemState& aState);
67 void UpdateControllers(VRSystemState& aState);
68 void UpdateControllerInputs(VRSystemState& aState,
69 const ovrInputState& aInputState);
70 void UpdateHaptics();
71 void EnumerateControllers(VRSystemState& aState,
72 const ovrInputState& aInputState);
73 void UpdateControllerPose(VRSystemState& aState,
74 const ovrInputState& aInputState);
75 void UpdateTelemetry(VRSystemState& aSystemState);
76 bool IsPresentationReady() const;
77 bool UpdateConstantBuffers();
79 PRLibrary* mOvrLib;
80 ovrSession mSession;
81 ovrInitFlags mInitFlags;
82 ovrTextureSwapChain mTextureSet;
83 nsTArray<RefPtr<ID3D11RenderTargetView>> mRTView;
84 nsTArray<RefPtr<ID3D11Texture2D>> mTexture;
85 nsTArray<RefPtr<ID3D11ShaderResourceView>> mSRV;
87 ID3D11VertexShader* mQuadVS;
88 ID3D11PixelShader* mQuadPS;
89 RefPtr<ID3D11SamplerState> mLinearSamplerState;
90 layers::VertexShaderConstants mVSConstants;
91 layers::PixelShaderConstants mPSConstants;
92 RefPtr<ID3D11Buffer> mVSConstantBuffer;
93 RefPtr<ID3D11Buffer> mPSConstantBuffer;
94 RefPtr<ID3D11Buffer> mVertexBuffer;
95 RefPtr<ID3D11InputLayout> mInputLayout;
97 IntSize mPresentationSize;
98 ovrFovPort mFOVPort[2];
100 // Most recent HMD eye poses, from start of frame
101 ovrPosef mFrameStartPose[2];
103 float mRemainingVibrateTime[2];
104 float mHapticPulseIntensity[2];
105 TimeStamp mLastHapticUpdate;
107 // The timestamp of the last ending presentation
108 TimeStamp mLastPresentationEnd;
109 bool mIsPresenting;
112 } // namespace gfx
113 } // namespace mozilla
115 #endif // GFX_VR_SERVICE_OCULUSSESSION_H