Bug 1567650 [wpt PR 17950] - [ElementTiming] Replace responseEnd with loadTime, a...
[gecko.git] / gfx / vr / service / OculusSession.h
blob1c2bd2ba7d5879fd5ca0d6adfdcd03e9c86485da
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 "mozilla/gfx/2D.h"
13 #include "moz_external_vr.h"
14 #include "nsTArray.h"
15 #include "oculus/ovr_capi_dynamic.h"
16 #include "prlink.h"
17 #include "ShaderDefinitionsD3D11.h" // for VertexShaderConstants and PixelShaderConstants
19 struct ID3D11Device;
21 namespace mozilla {
22 namespace layers {
23 struct VertexShaderConstants;
24 struct PixelShaderConstants;
25 } // namespace layers
26 namespace gfx {
28 class OculusSession : public VRSession {
29 public:
30 OculusSession();
31 virtual ~OculusSession();
33 bool Initialize(mozilla::gfx::VRSystemState& aSystemState) override;
34 void Shutdown() override;
35 void ProcessEvents(mozilla::gfx::VRSystemState& aSystemState) override;
36 void StartFrame(mozilla::gfx::VRSystemState& aSystemState) override;
37 bool StartPresentation() override;
38 void StopPresentation() override;
39 bool SubmitFrame(const mozilla::gfx::VRLayer_Stereo_Immersive& aLayer,
40 ID3D11Texture2D* aTexture) override;
41 void VibrateHaptic(uint32_t aControllerIdx, uint32_t aHapticIndex,
42 float aIntensity, float aDuration) override;
43 void StopVibrateHaptic(uint32_t aControllerIdx) override;
44 void StopAllHaptics() override;
46 private:
47 bool LoadOvrLib();
48 void UnloadOvrLib();
49 bool StartLib(ovrInitFlags aFlags);
50 void StopLib();
51 bool StartSession();
52 void StopSession();
53 bool StartRendering();
54 void StopRendering();
55 bool CreateD3DObjects();
56 bool CreateShaders();
57 void DestroyShaders();
58 void CoverTransitions();
59 void UpdateVisibility();
60 bool ChangeVisibility(bool bVisible);
61 bool InitState(mozilla::gfx::VRSystemState& aSystemState);
62 void UpdateStageParameters(mozilla::gfx::VRDisplayState& aState);
63 void UpdateEyeParameters(mozilla::gfx::VRSystemState& aState);
64 void UpdateHeadsetPose(mozilla::gfx::VRSystemState& aState);
65 void UpdateControllers(VRSystemState& aState);
66 void UpdateControllerInputs(VRSystemState& aState,
67 const ovrInputState& aInputState);
68 void UpdateHaptics();
69 void EnumerateControllers(VRSystemState& aState,
70 const ovrInputState& aInputState);
71 void UpdateControllerPose(VRSystemState& aState,
72 const ovrInputState& aInputState);
73 void UpdateTelemetry(VRSystemState& aSystemState);
74 bool IsPresentationReady() const;
75 bool UpdateConstantBuffers();
77 PRLibrary* mOvrLib;
78 ovrSession mSession;
79 ovrInitFlags mInitFlags;
80 ovrTextureSwapChain mTextureSet;
81 nsTArray<RefPtr<ID3D11RenderTargetView>> mRTView;
82 nsTArray<RefPtr<ID3D11Texture2D>> mTexture;
83 nsTArray<RefPtr<ID3D11ShaderResourceView>> mSRV;
85 ID3D11VertexShader* mQuadVS;
86 ID3D11PixelShader* mQuadPS;
87 RefPtr<ID3D11SamplerState> mLinearSamplerState;
88 layers::VertexShaderConstants mVSConstants;
89 layers::PixelShaderConstants mPSConstants;
90 RefPtr<ID3D11Buffer> mVSConstantBuffer;
91 RefPtr<ID3D11Buffer> mPSConstantBuffer;
92 RefPtr<ID3D11Buffer> mVertexBuffer;
93 RefPtr<ID3D11InputLayout> mInputLayout;
95 IntSize mPresentationSize;
96 ovrFovPort mFOVPort[2];
98 // Most recent HMD eye poses, from start of frame
99 ovrPosef mFrameStartPose[2];
101 float mRemainingVibrateTime[2];
102 float mHapticPulseIntensity[2];
103 TimeStamp mLastHapticUpdate;
105 // The timestamp of the last ending presentation
106 TimeStamp mLastPresentationEnd;
107 bool mIsPresenting;
110 } // namespace gfx
111 } // namespace mozilla
113 #endif // GFX_VR_SERVICE_OCULUSSESSION_H