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_VRSERVICE_H
8 #define GFX_VR_SERVICE_VRSERVICE_H
10 #include "moz_external_vr.h"
11 #include "base/process.h" // for base::ProcessHandle
12 #include "mozilla/Atomics.h"
13 #include "mozilla/TimeStamp.h"
14 #include "mozilla/UniquePtr.h"
19 class BackgroundHangMonitor
;
25 static const int kVRFrameTimingHistoryDepth
= 100;
29 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VRService
)
30 static already_AddRefed
<VRService
> Create(
31 volatile VRExternalShmem
* aShmem
= nullptr);
38 explicit VRService(volatile VRExternalShmem
* aShmem
);
41 void StopInternal(bool aFromDtor
);
44 void PushState(const mozilla::gfx::VRSystemState
& aState
);
45 void PullState(mozilla::gfx::VRBrowserState
& aState
);
48 * VRSystemState contains the most recent state of the VR
49 * system, to be shared with the browser by Shmem.
50 * mSystemState is the VR Service copy of this data, which
51 * is memcpy'ed atomically to the Shmem.
52 * VRSystemState is written by the VR Service, but read-only
55 VRSystemState mSystemState
;
57 * VRBrowserState contains the most recent state of the browser.
58 * mBrowserState is memcpy'ed from the Shmem atomically
60 VRBrowserState mBrowserState
;
62 UniquePtr
<VRSession
> mSession
;
63 nsCOMPtr
<nsIThread
> mServiceThread
;
64 // Only ever accessed on the service thread.
65 UniquePtr
<mozilla::BackgroundHangMonitor
> mBackgroundHangMonitor
;
67 Atomic
<bool> mShutdownRequested
;
69 // Note: mShmem doesn't support RefPtr; thus, do not share this private
70 // pointer so that its lifetime can still be controlled by VRService
72 VRHapticState mLastHapticState
[kVRHapticsMaxCount
];
73 TimeStamp mFrameStartTime
[kVRFrameTimingHistoryDepth
];
75 bool IsInServiceThread();
79 * The VR Service thread is a state machine that always has one
80 * task queued depending on the state.
82 * VR Service thread state task functions:
84 void ServiceInitialize();
85 void ServiceShutdown();
86 void ServiceWaitForImmersive();
87 void ServiceImmersiveMode();
91 } // namespace mozilla
93 #endif // GFX_VR_SERVICE_VRSERVICE_H