Merge mozilla-central to autoland. CLOSED TREE
[gecko.git] / gfx / vr / service / VRSession.h
blobab446a26d7a4c82d47b4733ac334f1b1253aa4f3
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_VRSESSION_H
8 #define GFX_VR_SERVICE_VRSESSION_H
10 #include "moz_external_vr.h"
12 #if defined(XP_WIN)
13 # include <d3d11_1.h>
14 #elif defined(XP_MACOSX)
15 class MacIOSurface;
16 #endif
18 namespace mozilla {
19 namespace gfx {
21 class VRSession {
22 public:
23 VRSession();
25 // Since this class doesn't use smartpointers for its refcounted
26 // members (so that it can compile outside of mozilla-central),
27 // prevent copying the addresses without increasing the refcount.
28 VRSession(const VRSession&) = delete;
29 VRSession& operator=(const VRSession&) = delete;
31 #ifdef XP_WIN
32 virtual ~VRSession();
33 #else
34 virtual ~VRSession() = default;
35 #endif
37 static void UpdateTrigger(VRControllerState& aState, uint32_t aButtonIndex,
38 float aValue, float aThreshold);
39 /**
40 * In order to support WebXR's navigator.xr.IsSessionSupported call without
41 * displaying any permission dialogue, it is necessary to have a safe way to
42 * detect the capability of running a VR or AR session without activating XR
43 * runtimes or powering on hardware.
45 * API's such as OpenVR make no guarantee that hardware and software won't be
46 * left activated after enumerating devices, so each backend in gfx/vr/service
47 * must allow for more granular detection of capabilities.
49 * By passing true to bDetectRuntimesOnly, the initialization exits early
50 * after reporting the presence of XR runtime software. The Initialize method
51 * will only enumerate hardware and possibly return true when
52 * aDetectRuntimesOnly is false.
54 virtual bool Initialize(mozilla::gfx::VRSystemState& aSystemState,
55 bool aDetectRuntimesOnly) = 0;
56 virtual void Shutdown() = 0;
57 virtual void ProcessEvents(mozilla::gfx::VRSystemState& aSystemState) = 0;
58 virtual void StartFrame(mozilla::gfx::VRSystemState& aSystemState) = 0;
59 virtual bool StartPresentation() = 0;
60 virtual void StopPresentation() = 0;
61 virtual void VibrateHaptic(uint32_t aControllerIdx, uint32_t aHapticIndex,
62 float aIntensity, float aDuration) = 0;
63 virtual void StopVibrateHaptic(uint32_t aControllerIdx) = 0;
64 virtual void StopAllHaptics() = 0;
65 bool SubmitFrame(const mozilla::gfx::VRLayer_Stereo_Immersive& aLayer);
66 bool ShouldQuit() const;
68 protected:
69 bool mShouldQuit;
70 #if defined(XP_WIN)
71 virtual bool SubmitFrame(const mozilla::gfx::VRLayer_Stereo_Immersive& aLayer,
72 ID3D11Texture2D* aTexture) = 0;
73 bool CreateD3DContext(ID3D11Device* aDevice);
75 ID3D11Device1* GetD3DDevice();
76 ID3D11DeviceContext1* GetD3DDeviceContext();
77 ID3DDeviceContextState* GetD3DDeviceContextState();
79 ID3D11Device1* mDevice;
80 ID3D11DeviceContext1* mContext;
81 ID3DDeviceContextState* mDeviceContextState;
83 #elif defined(XP_MACOSX)
84 virtual bool SubmitFrame(const mozilla::gfx::VRLayer_Stereo_Immersive& aLayer,
85 const VRLayerTextureHandle& aTexture) = 0;
86 #endif
87 void SetControllerSelectionAndSqueezeFrameId(
88 VRControllerState& controllerState, uint64_t aFrameId);
91 } // namespace gfx
92 } // namespace mozilla
94 #endif // GFX_VR_SERVICE_VRSESSION_H