2017-10-28 02:10:06 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2015-09-18 00:23:13 +03:00
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef GFX_VR_MANAGER_H
|
|
|
|
#define GFX_VR_MANAGER_H
|
|
|
|
|
2019-08-01 20:12:16 +03:00
|
|
|
#include "nsIObserver.h"
|
2015-09-18 00:23:13 +03:00
|
|
|
#include "nsTArray.h"
|
2019-06-29 00:19:54 +03:00
|
|
|
#include "mozilla/Atomics.h"
|
|
|
|
#include "mozilla/layers/LayersSurfaces.h" // for SurfaceDescriptor
|
2015-09-18 00:23:13 +03:00
|
|
|
#include "mozilla/TimeStamp.h"
|
|
|
|
#include "gfxVR.h"
|
|
|
|
|
2018-09-26 01:56:10 +03:00
|
|
|
class nsITimer;
|
2015-09-18 00:23:13 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace gfx {
|
2016-02-25 02:54:50 +03:00
|
|
|
class VRLayerParent;
|
2015-09-18 00:23:13 +03:00
|
|
|
class VRManagerParent;
|
2019-06-29 00:19:54 +03:00
|
|
|
class VRServiceHost;
|
|
|
|
class VRThread;
|
2019-07-29 17:30:54 +03:00
|
|
|
class VRShMem;
|
2019-06-29 00:19:54 +03:00
|
|
|
|
|
|
|
enum class VRManagerState : uint32_t {
|
|
|
|
Disabled, // All VRManager activity is stopped
|
|
|
|
Idle, // No VR hardware has been activated, but background tasks are running
|
|
|
|
Enumeration, // Waiting for enumeration and startup of VR hardware
|
|
|
|
Active // VR hardware is active
|
|
|
|
};
|
2015-09-18 00:23:13 +03:00
|
|
|
|
2019-08-01 20:12:16 +03:00
|
|
|
class VRManager : nsIObserver {
|
2015-09-18 00:23:13 +03:00
|
|
|
public:
|
2019-08-01 20:12:16 +03:00
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIOBSERVER
|
|
|
|
|
2015-09-18 00:23:13 +03:00
|
|
|
static void ManagerInit();
|
|
|
|
static VRManager* Get();
|
|
|
|
|
|
|
|
void AddVRManagerParent(VRManagerParent* aVRManagerParent);
|
|
|
|
void RemoveVRManagerParent(VRManagerParent* aVRManagerParent);
|
|
|
|
|
|
|
|
void NotifyVsync(const TimeStamp& aVsyncTimestamp);
|
2019-06-29 00:19:54 +03:00
|
|
|
|
2016-02-25 02:54:50 +03:00
|
|
|
void RefreshVRDisplays(bool aMustDispatch = false);
|
2019-06-29 00:19:54 +03:00
|
|
|
void StopAllHaptics();
|
2017-11-22 01:18:16 +03:00
|
|
|
|
2017-02-02 09:57:58 +03:00
|
|
|
void VibrateHaptic(uint32_t aControllerIdx, uint32_t aHapticIndex,
|
2017-11-30 14:37:07 +03:00
|
|
|
double aIntensity, double aDuration,
|
|
|
|
const VRManagerPromise& aPromise);
|
2017-03-07 05:17:57 +03:00
|
|
|
void StopVibrateHaptic(uint32_t aControllerIdx);
|
2017-11-30 14:37:07 +03:00
|
|
|
void NotifyVibrateHapticCompleted(const VRManagerPromise& aPromise);
|
2018-07-31 04:41:25 +03:00
|
|
|
void StartVRNavigation(const uint32_t& aDisplayID);
|
|
|
|
void StopVRNavigation(const uint32_t& aDisplayID,
|
|
|
|
const TimeDuration& aTimeout);
|
2019-03-12 00:13:39 +03:00
|
|
|
void Shutdown();
|
2019-06-29 00:19:54 +03:00
|
|
|
#if !defined(MOZ_WIDGET_ANDROID)
|
2019-07-10 06:29:57 +03:00
|
|
|
bool RunPuppet(const nsTArray<uint64_t>& aBuffer,
|
2019-06-29 00:19:54 +03:00
|
|
|
VRManagerParent* aManagerParent);
|
|
|
|
void ResetPuppet(VRManagerParent* aManagerParent);
|
|
|
|
#endif
|
|
|
|
void AddLayer(VRLayerParent* aLayer);
|
|
|
|
void RemoveLayer(VRLayerParent* aLayer);
|
|
|
|
void SetGroupMask(uint32_t aGroupMask);
|
|
|
|
void SubmitFrame(VRLayerParent* aLayer,
|
|
|
|
const layers::SurfaceDescriptor& aTexture, uint64_t aFrameId,
|
|
|
|
const gfx::Rect& aLeftEyeRect,
|
|
|
|
const gfx::Rect& aRightEyeRect);
|
2019-04-12 07:42:28 +03:00
|
|
|
bool IsPresenting();
|
2015-09-18 00:23:13 +03:00
|
|
|
|
2019-06-29 00:19:54 +03:00
|
|
|
private:
|
2015-09-18 00:23:13 +03:00
|
|
|
VRManager();
|
2019-08-01 20:12:16 +03:00
|
|
|
virtual ~VRManager();
|
2019-03-12 00:13:39 +03:00
|
|
|
void Destroy();
|
2018-09-26 01:56:10 +03:00
|
|
|
void StartTasks();
|
|
|
|
void StopTasks();
|
|
|
|
static void TaskTimerCallback(nsITimer* aTimer, void* aClosure);
|
|
|
|
void RunTasks();
|
|
|
|
void Run1msTasks(double aDeltaTime);
|
|
|
|
void Run10msTasks();
|
|
|
|
void Run100msTasks();
|
|
|
|
uint32_t GetOptimalTaskInterval();
|
2019-06-29 00:19:54 +03:00
|
|
|
void PullState(const std::function<bool()>& aWaitCondition = nullptr);
|
|
|
|
void PushState(const bool aNotifyCond = false);
|
|
|
|
static uint32_t AllocateDisplayID();
|
2015-09-18 00:23:13 +03:00
|
|
|
|
2016-04-13 03:39:28 +03:00
|
|
|
void DispatchVRDisplayInfoUpdate();
|
2017-10-11 00:42:37 +03:00
|
|
|
void UpdateRequestedDevices();
|
|
|
|
void EnumerateVRDisplays();
|
|
|
|
void CheckForInactiveTimeout();
|
2019-06-29 00:19:54 +03:00
|
|
|
#if !defined(MOZ_WIDGET_ANDROID)
|
|
|
|
void CheckForPuppetCompletion();
|
|
|
|
#endif
|
|
|
|
void CheckForShutdown();
|
|
|
|
void CheckWatchDog();
|
|
|
|
void ExpireNavigationTransition();
|
|
|
|
void OpenShmem();
|
|
|
|
void CloseShmem();
|
|
|
|
void UpdateHaptics(double aDeltaTime);
|
|
|
|
void ClearHapticSlot(size_t aSlot);
|
|
|
|
void StartFrame();
|
|
|
|
void ShutdownSubmitThread();
|
|
|
|
void StartPresentation();
|
|
|
|
void StopPresentation();
|
|
|
|
void CancelCurrentSubmitTask();
|
|
|
|
|
|
|
|
void SubmitFrameInternal(const layers::SurfaceDescriptor& aTexture,
|
|
|
|
uint64_t aFrameId, const gfx::Rect& aLeftEyeRect,
|
|
|
|
const gfx::Rect& aRightEyeRect);
|
|
|
|
bool SubmitFrame(const layers::SurfaceDescriptor& aTexture, uint64_t aFrameId,
|
|
|
|
const gfx::Rect& aLeftEyeRect,
|
|
|
|
const gfx::Rect& aRightEyeRect);
|
|
|
|
|
|
|
|
Atomic<VRManagerState> mState;
|
2015-09-18 00:23:13 +03:00
|
|
|
typedef nsTHashtable<nsRefPtrHashKey<VRManagerParent>> VRManagerParentSet;
|
|
|
|
VRManagerParentSet mVRManagerParents;
|
2019-06-29 00:19:54 +03:00
|
|
|
#if !defined(MOZ_WIDGET_ANDROID)
|
|
|
|
VRManagerParentSet mManagerParentsWaitingForPuppetReset;
|
|
|
|
RefPtr<VRManagerParent> mManagerParentRunningPuppet;
|
|
|
|
#endif
|
|
|
|
// Weak reference to mLayers entries are cleared in
|
|
|
|
// VRLayerParent destructor
|
|
|
|
nsTArray<VRLayerParent*> mLayers;
|
2015-09-18 00:23:13 +03:00
|
|
|
|
2017-10-11 00:42:37 +03:00
|
|
|
TimeStamp mLastDisplayEnumerationTime;
|
2017-04-12 08:12:22 +03:00
|
|
|
TimeStamp mLastActiveTime;
|
2018-09-26 01:56:10 +03:00
|
|
|
TimeStamp mLastTickTime;
|
2019-06-29 00:19:54 +03:00
|
|
|
TimeStamp mEarliestRestartTime;
|
|
|
|
TimeStamp mVRNavigationTransitionEnd;
|
|
|
|
TimeStamp mLastFrameStart[kVRMaxLatencyFrames];
|
2018-09-26 01:56:10 +03:00
|
|
|
double mAccumulator100ms;
|
2017-10-11 00:42:37 +03:00
|
|
|
bool mVRDisplaysRequested;
|
2018-10-27 02:17:52 +03:00
|
|
|
bool mVRDisplaysRequestedNonFocus;
|
2017-10-11 00:42:37 +03:00
|
|
|
bool mVRControllersRequested;
|
2019-06-29 00:19:54 +03:00
|
|
|
bool mFrameStarted;
|
2018-09-26 01:56:10 +03:00
|
|
|
uint32_t mTaskInterval;
|
|
|
|
RefPtr<nsITimer> mTaskTimer;
|
2019-06-29 00:19:54 +03:00
|
|
|
mozilla::Monitor mCurrentSubmitTaskMonitor;
|
|
|
|
RefPtr<CancelableRunnable> mCurrentSubmitTask;
|
|
|
|
uint64_t mLastSubmittedFrameId;
|
|
|
|
uint64_t mLastStartedFrame;
|
|
|
|
bool mEnumerationCompleted;
|
2019-08-01 20:12:16 +03:00
|
|
|
bool mAppPaused;
|
2019-07-29 17:30:54 +03:00
|
|
|
|
|
|
|
// Note: mShmem doesn't support RefPtr; thus, do not share this private
|
|
|
|
// pointer so that its lifetime can still be controlled by VRManager
|
|
|
|
VRShMem* mShmem;
|
2019-07-15 06:29:11 +03:00
|
|
|
bool mVRProcessEnabled;
|
2019-07-29 17:30:54 +03:00
|
|
|
|
|
|
|
#if !defined(MOZ_WIDGET_ANDROID)
|
2019-06-29 00:19:54 +03:00
|
|
|
RefPtr<VRServiceHost> mServiceHost;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static Atomic<uint32_t> sDisplayBase;
|
|
|
|
RefPtr<VRThread> mSubmitThread;
|
|
|
|
VRTelemetry mTelemetry;
|
|
|
|
nsTArray<UniquePtr<VRManagerPromise>> mHapticPromises;
|
|
|
|
// Duration of haptic pulse time remaining (milliseconds)
|
|
|
|
double mHapticPulseRemaining[kVRHapticsMaxCount];
|
|
|
|
|
|
|
|
VRDisplayInfo mDisplayInfo;
|
|
|
|
VRDisplayInfo mLastUpdateDisplayInfo;
|
|
|
|
VRBrowserState mBrowserState;
|
|
|
|
VRHMDSensorState mLastSensorState;
|
2015-09-18 00:23:13 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace gfx
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // GFX_VR_MANAGER_H
|