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
|
2017-10-28 01:55:37 +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/. */
|
2016-02-25 02:54:50 +03:00
|
|
|
|
|
|
|
#ifndef GFX_VR_DISPLAY_HOST_H
|
|
|
|
#define GFX_VR_DISPLAY_HOST_H
|
|
|
|
|
|
|
|
#include "gfxVR.h"
|
|
|
|
#include "nsTArray.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "mozilla/RefPtr.h"
|
|
|
|
#include "mozilla/gfx/2D.h"
|
|
|
|
#include "mozilla/Atomics.h"
|
|
|
|
#include "mozilla/EnumeratedArray.h"
|
|
|
|
#include "mozilla/TimeStamp.h"
|
|
|
|
#include "mozilla/TypedEnumBits.h"
|
2016-10-24 13:09:11 +03:00
|
|
|
#include "mozilla/dom/GamepadPoseState.h"
|
2017-07-22 03:30:34 +03:00
|
|
|
#include "mozilla/layers/LayersSurfaces.h" // for SurfaceDescriptor
|
|
|
|
|
2017-09-19 02:19:49 +03:00
|
|
|
#if defined(XP_WIN)
|
|
|
|
# include <d3d11_1.h>
|
2017-07-22 03:30:34 +03:00
|
|
|
#elif defined(XP_MACOSX)
|
2017-07-04 23:50:40 +03:00
|
|
|
class MacIOSurface;
|
|
|
|
#endif
|
2016-02-25 02:54:50 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace gfx {
|
2017-11-17 11:06:59 +03:00
|
|
|
class VRThread;
|
2016-02-25 02:54:50 +03:00
|
|
|
class VRLayerParent;
|
|
|
|
|
|
|
|
class VRDisplayHost {
|
|
|
|
public:
|
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VRDisplayHost)
|
|
|
|
|
|
|
|
const VRDisplayInfo& GetDisplayInfo() const { return mDisplayInfo; }
|
|
|
|
|
|
|
|
void AddLayer(VRLayerParent* aLayer);
|
|
|
|
void RemoveLayer(VRLayerParent* aLayer);
|
|
|
|
|
|
|
|
virtual void ZeroSensor() = 0;
|
|
|
|
virtual void StartPresentation() = 0;
|
|
|
|
virtual void StopPresentation() = 0;
|
2018-07-31 04:41:25 +03:00
|
|
|
virtual void StartVRNavigation();
|
|
|
|
virtual void StopVRNavigation(const TimeDuration& aTimeout);
|
2017-10-11 00:42:37 +03:00
|
|
|
void NotifyVSync();
|
2018-09-26 01:56:10 +03:00
|
|
|
virtual void Run1msTasks(double aDeltaTime);
|
|
|
|
virtual void Run10msTasks();
|
|
|
|
virtual void Run100msTasks();
|
2016-02-25 02:54:50 +03:00
|
|
|
|
2017-05-09 02:01:36 +03:00
|
|
|
void StartFrame();
|
2016-02-25 02:54:50 +03:00
|
|
|
void SubmitFrame(VRLayerParent* aLayer,
|
2017-07-22 03:30:34 +03:00
|
|
|
const layers::SurfaceDescriptor& aTexture, uint64_t aFrameId,
|
2016-02-25 02:54:50 +03:00
|
|
|
const gfx::Rect& aLeftEyeRect,
|
|
|
|
const gfx::Rect& aRightEyeRect);
|
2019-02-23 01:04:00 +03:00
|
|
|
void CancelCurrentSubmitTask();
|
2016-02-25 02:54:50 +03:00
|
|
|
bool CheckClearDisplayInfoDirty();
|
2017-05-09 02:01:36 +03:00
|
|
|
void SetGroupMask(uint32_t aGroupMask);
|
2017-06-22 09:32:18 +03:00
|
|
|
bool GetIsConnected();
|
2016-02-25 02:54:50 +03:00
|
|
|
|
2017-09-19 02:19:49 +03:00
|
|
|
class AutoRestoreRenderState {
|
|
|
|
public:
|
|
|
|
explicit AutoRestoreRenderState(VRDisplayHost* aDisplay);
|
|
|
|
~AutoRestoreRenderState();
|
|
|
|
bool IsSuccess();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-09-19 02:19:49 +03:00
|
|
|
private:
|
|
|
|
RefPtr<VRDisplayHost> mDisplay;
|
|
|
|
#if defined(XP_WIN)
|
|
|
|
RefPtr<ID3DDeviceContextState> mPrevDeviceContextState;
|
|
|
|
#endif
|
|
|
|
bool mSuccess;
|
|
|
|
};
|
|
|
|
|
2016-02-25 02:54:50 +03:00
|
|
|
protected:
|
2016-10-04 11:22:42 +03:00
|
|
|
explicit VRDisplayHost(VRDeviceType aType);
|
2016-02-25 02:54:50 +03:00
|
|
|
virtual ~VRDisplayHost();
|
|
|
|
|
2018-05-08 21:31:28 +03:00
|
|
|
// This SubmitFrame() must be overridden by children and block until
|
|
|
|
// the next frame is ready to start and the resources in aTexture can
|
|
|
|
// safely be released.
|
|
|
|
virtual bool SubmitFrame(const layers::SurfaceDescriptor& aTexture,
|
2017-11-01 03:25:40 +03:00
|
|
|
uint64_t aFrameId, const gfx::Rect& aLeftEyeRect,
|
|
|
|
const gfx::Rect& aRightEyeRect) = 0;
|
2016-02-25 02:54:50 +03:00
|
|
|
|
|
|
|
VRDisplayInfo mDisplayInfo;
|
|
|
|
|
2017-11-09 05:54:36 +03:00
|
|
|
nsTArray<VRLayerParent*> mLayers;
|
2017-05-09 02:01:36 +03:00
|
|
|
// Weak reference to mLayers entries are cleared in
|
|
|
|
// VRLayerParent destructor
|
|
|
|
|
|
|
|
protected:
|
2018-12-18 22:39:44 +03:00
|
|
|
virtual VRHMDSensorState& GetSensorState() = 0;
|
2016-02-25 02:54:50 +03:00
|
|
|
|
2017-11-17 11:06:59 +03:00
|
|
|
RefPtr<VRThread> mSubmitThread;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-02-25 02:54:50 +03:00
|
|
|
private:
|
2017-11-17 11:06:59 +03:00
|
|
|
void SubmitFrameInternal(const layers::SurfaceDescriptor& aTexture,
|
|
|
|
uint64_t aFrameId, const gfx::Rect& aLeftEyeRect,
|
|
|
|
const gfx::Rect& aRightEyeRect);
|
2018-09-26 01:56:10 +03:00
|
|
|
void CheckWatchDog();
|
2017-11-17 11:06:59 +03:00
|
|
|
|
2016-02-25 02:54:50 +03:00
|
|
|
VRDisplayInfo mLastUpdateDisplayInfo;
|
2019-02-23 01:04:00 +03:00
|
|
|
|
|
|
|
mozilla::Monitor mCurrentSubmitTaskMonitor;
|
|
|
|
RefPtr<CancelableRunnable> mCurrentSubmitTask;
|
2017-07-15 02:08:49 +03:00
|
|
|
bool mFrameStarted;
|
2018-08-24 18:32:12 +03:00
|
|
|
#if defined(MOZ_WIDGET_ANDROID)
|
|
|
|
protected:
|
|
|
|
uint64_t mLastSubmittedFrameId;
|
|
|
|
uint64_t mLastStartedFrame;
|
|
|
|
#endif // defined(MOZ_WIDGET_ANDROID)
|
2017-09-19 02:19:49 +03:00
|
|
|
|
|
|
|
#if defined(XP_WIN)
|
|
|
|
protected:
|
|
|
|
bool CreateD3DObjects();
|
|
|
|
RefPtr<ID3D11Device1> mDevice;
|
|
|
|
RefPtr<ID3D11DeviceContext1> mContext;
|
|
|
|
ID3D11Device1* GetD3DDevice();
|
|
|
|
ID3D11DeviceContext1* GetD3DDeviceContext();
|
|
|
|
ID3DDeviceContextState* GetD3DDeviceContextState();
|
|
|
|
|
|
|
|
private:
|
|
|
|
RefPtr<ID3DDeviceContextState> mDeviceContextState;
|
|
|
|
#endif
|
2016-02-25 02:54:50 +03:00
|
|
|
};
|
|
|
|
|
2016-10-07 11:58:01 +03:00
|
|
|
class VRControllerHost {
|
|
|
|
public:
|
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VRControllerHost)
|
|
|
|
|
2016-10-13 09:30:26 +03:00
|
|
|
const VRControllerInfo& GetControllerInfo() const;
|
2016-11-08 03:15:01 +03:00
|
|
|
void SetButtonPressed(uint64_t aBit);
|
|
|
|
uint64_t GetButtonPressed();
|
2017-04-06 14:00:20 +03:00
|
|
|
void SetButtonTouched(uint64_t aBit);
|
|
|
|
uint64_t GetButtonTouched();
|
2016-10-24 13:09:11 +03:00
|
|
|
void SetPose(const dom::GamepadPoseState& aPose);
|
|
|
|
const dom::GamepadPoseState& GetPose();
|
2017-02-06 11:07:20 +03:00
|
|
|
dom::GamepadHand GetHand();
|
2017-02-02 09:57:58 +03:00
|
|
|
void SetVibrateIndex(uint64_t aIndex);
|
|
|
|
uint64_t GetVibrateIndex();
|
2016-10-07 11:58:01 +03:00
|
|
|
|
|
|
|
protected:
|
2017-07-14 12:01:09 +03:00
|
|
|
explicit VRControllerHost(VRDeviceType aType, dom::GamepadHand aHand,
|
|
|
|
uint32_t aDisplayID);
|
2016-10-07 11:58:01 +03:00
|
|
|
virtual ~VRControllerHost();
|
|
|
|
|
|
|
|
VRControllerInfo mControllerInfo;
|
2017-02-02 09:57:58 +03:00
|
|
|
uint64_t mVibrateIndex;
|
2016-10-24 13:09:11 +03:00
|
|
|
dom::GamepadPoseState mPose;
|
2016-10-07 11:58:01 +03:00
|
|
|
};
|
|
|
|
|
2016-02-25 02:54:50 +03:00
|
|
|
} // namespace gfx
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif /* GFX_VR_DISPLAY_HOST_H */
|