Bug 1874684 - Part 28: Return DateDuration from DifferenceISODateTime. r=mgaudet
[gecko.git] / gfx / vr / VRDisplayClient.h
blob19f8fdc41384e3b30a1c002502acc78d430c8c2c
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_DISPLAY_CLIENT_H
8 #define GFX_VR_DISPLAY_CLIENT_H
10 #include "nsCOMPtr.h"
11 #include "mozilla/Attributes.h"
12 #include "mozilla/RefPtr.h"
13 #include "mozilla/dom/VRDisplayBinding.h"
15 #include "gfxVR.h"
17 namespace mozilla {
18 namespace dom {
19 enum class XRReferenceSpaceType : uint8_t;
20 class XRSession;
21 } // namespace dom
22 namespace gfx {
23 class VRDisplayPresentation;
24 class VRManagerChild;
26 class VRDisplayClient {
27 public:
28 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VRDisplayClient)
30 explicit VRDisplayClient(const VRDisplayInfo& aDisplayInfo);
32 MOZ_CAN_RUN_SCRIPT void UpdateDisplayInfo(const VRDisplayInfo& aDisplayInfo);
33 void UpdateSubmitFrameResult(const VRSubmitFrameResultInfo& aResult);
35 const VRDisplayInfo& GetDisplayInfo() const { return mDisplayInfo; }
36 virtual const VRHMDSensorState& GetSensorState() const;
37 void GetSubmitFrameResult(VRSubmitFrameResultInfo& aResult);
39 already_AddRefed<VRDisplayPresentation> BeginPresentation(
40 const nsTArray<dom::VRLayer>& aLayers, uint32_t aGroup);
41 void PresentationCreated();
42 void PresentationDestroyed();
44 void SessionStarted(dom::XRSession* aSession);
45 void SessionEnded(dom::XRSession* aSession);
47 bool GetIsConnected() const;
49 void NotifyDisconnected();
50 void SetGroupMask(uint32_t aGroupMask);
52 bool IsPresentationGenerationCurrent() const;
53 void MakePresentationGenerationCurrent();
55 void StartVRNavigation();
56 void StopVRNavigation(const TimeDuration& aTimeout);
58 bool IsPresenting();
59 bool IsReferenceSpaceTypeSupported(dom::XRReferenceSpaceType aType) const;
60 gfx::VRAPIMode GetXRAPIMode() const;
61 void SetXRAPIMode(gfx::VRAPIMode aMode);
63 protected:
64 virtual ~VRDisplayClient();
66 MOZ_CAN_RUN_SCRIPT void FireEvents();
67 void FireGamepadEvents();
68 MOZ_CAN_RUN_SCRIPT void StartFrame();
70 VRDisplayInfo mDisplayInfo;
72 bool bLastEventWasMounted;
73 bool bLastEventWasPresenting;
75 int mPresentationCount;
76 uint64_t mLastEventFrameId;
77 uint32_t mLastPresentingGeneration;
79 // Difference between mDisplayInfo.mControllerState and
80 // mLastEventControllerState determines what gamepad events to fire when
81 // updated.
82 VRControllerState mLastEventControllerState[kVRControllerMaxCount];
84 /**
85 * mSessions is cleared in VRDisplayClient::SessionEnded.
86 * SessionEnded is guaranteed to be called by every XRSession
87 * when it is shutdown explicitly with the WebXR XRSession.end
88 * call, when all JS references on the XRSession are released, or
89 * when the window is closed.
91 nsTArray<RefPtr<dom::XRSession>> mSessions;
93 private:
94 void GamepadMappingForWebVR(VRControllerState& aControllerState);
96 VRSubmitFrameResultInfo mSubmitFrameResult;
97 gfx::VRAPIMode mAPIMode;
100 } // namespace gfx
101 } // namespace mozilla
103 #endif /* GFX_VR_DISPLAY_CLIENT_H */