зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1481683 - Change gfx/vr/service and gfxvrExternal CRLF line break types to LF. r=kip
MozReview-Commit-ID: 4mFBUls14e7 Differential Revision: https://phabricator.services.mozilla.com/D8785 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
4eeeb8adf2
Коммит
14f9503ffe
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -1,155 +1,155 @@
|
|||
/* -*- 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
|
||||
* 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_EXTERNAL_H
|
||||
#define GFX_VR_EXTERNAL_H
|
||||
|
||||
#include "nsTArray.h"
|
||||
#include "nsIScreen.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "mozilla/RefPtr.h"
|
||||
|
||||
#include "mozilla/gfx/2D.h"
|
||||
#include "mozilla/EnumeratedArray.h"
|
||||
#include "mozilla/UniquePtr.h"
|
||||
|
||||
#include "gfxVR.h"
|
||||
#include "VRDisplayHost.h"
|
||||
|
||||
#if defined(XP_MACOSX)
|
||||
class MacIOSurface;
|
||||
#endif
|
||||
namespace mozilla {
|
||||
namespace gfx {
|
||||
namespace impl {
|
||||
|
||||
class VRDisplayExternal : public VRDisplayHost
|
||||
{
|
||||
public:
|
||||
void ZeroSensor() override;
|
||||
|
||||
protected:
|
||||
VRHMDSensorState GetSensorState() override;
|
||||
void StartPresentation() override;
|
||||
void StopPresentation() override;
|
||||
void StartVRNavigation() override;
|
||||
void StopVRNavigation(const TimeDuration& aTimeout) override;
|
||||
|
||||
bool SubmitFrame(const layers::SurfaceDescriptor& aTexture,
|
||||
uint64_t aFrameId,
|
||||
const gfx::Rect& aLeftEyeRect,
|
||||
const gfx::Rect& aRightEyeRect) override;
|
||||
|
||||
public:
|
||||
explicit VRDisplayExternal(const VRDisplayState& aDisplayState);
|
||||
void Refresh();
|
||||
const VRControllerState& GetLastControllerState(uint32_t aStateIndex) const;
|
||||
void VibrateHaptic(uint32_t aControllerIdx,
|
||||
uint32_t aHapticIndex,
|
||||
double aIntensity,
|
||||
double aDuration,
|
||||
const VRManagerPromise& aPromise);
|
||||
void StopVibrateHaptic(uint32_t aControllerIdx);
|
||||
void StopAllHaptics();
|
||||
void Run1msTasks(double aDeltaTime) override;
|
||||
void Run10msTasks() override;
|
||||
protected:
|
||||
virtual ~VRDisplayExternal();
|
||||
void Destroy();
|
||||
|
||||
private:
|
||||
bool PopulateLayerTexture(const layers::SurfaceDescriptor& aTexture,
|
||||
VRLayerTextureType* aTextureType,
|
||||
VRLayerTextureHandle* aTextureHandle);
|
||||
void PushState(bool aNotifyCond = false);
|
||||
#if defined(MOZ_WIDGET_ANDROID)
|
||||
bool PullState(const std::function<bool()>& aWaitCondition = nullptr);
|
||||
#else
|
||||
bool PullState();
|
||||
#endif
|
||||
void ClearHapticSlot(size_t aSlot);
|
||||
void ExpireNavigationTransition();
|
||||
void UpdateHaptics(double aDeltaTime);
|
||||
nsTArray<UniquePtr<VRManagerPromise>> mHapticPromises;
|
||||
// Duration of haptic pulse time remaining (milliseconds)
|
||||
double mHapticPulseRemaining[kVRHapticsMaxCount];
|
||||
VRTelemetry mTelemetry;
|
||||
TimeStamp mVRNavigationTransitionEnd;
|
||||
VRBrowserState mBrowserState;
|
||||
VRHMDSensorState mLastSensorState;
|
||||
};
|
||||
|
||||
} // namespace impl
|
||||
|
||||
class VRSystemManagerExternal : public VRSystemManager
|
||||
{
|
||||
public:
|
||||
static already_AddRefed<VRSystemManagerExternal> Create(VRExternalShmem* aAPIShmem = nullptr);
|
||||
|
||||
virtual void Destroy() override;
|
||||
virtual void Shutdown() override;
|
||||
virtual void Run100msTasks() override;
|
||||
virtual void Enumerate() override;
|
||||
virtual bool ShouldInhibitEnumeration() override;
|
||||
virtual void GetHMDs(nsTArray<RefPtr<VRDisplayHost>>& aHMDResult) override;
|
||||
virtual bool GetIsPresenting() override;
|
||||
virtual void HandleInput() override;
|
||||
virtual void GetControllers(nsTArray<RefPtr<VRControllerHost>>&
|
||||
aControllerResult) override;
|
||||
virtual void ScanForControllers() override;
|
||||
virtual void RemoveControllers() override;
|
||||
virtual void VibrateHaptic(uint32_t aControllerIdx,
|
||||
uint32_t aHapticIndex,
|
||||
double aIntensity,
|
||||
double aDuration,
|
||||
const VRManagerPromise& aPromise) override;
|
||||
virtual void StopVibrateHaptic(uint32_t aControllerIdx) override;
|
||||
#if defined(MOZ_WIDGET_ANDROID)
|
||||
bool PullState(VRDisplayState* aDisplayState,
|
||||
VRHMDSensorState* aSensorState = nullptr,
|
||||
VRControllerState* aControllerState = nullptr,
|
||||
const std::function<bool()>& aWaitCondition = nullptr);
|
||||
#else
|
||||
bool PullState(VRDisplayState* aDisplayState,
|
||||
VRHMDSensorState* aSensorState = nullptr,
|
||||
VRControllerState* aControllerState = nullptr);
|
||||
#endif
|
||||
void PushState(VRBrowserState* aBrowserState, const bool aNotifyCond = false);
|
||||
|
||||
protected:
|
||||
explicit VRSystemManagerExternal(VRExternalShmem* aAPIShmem = nullptr);
|
||||
virtual ~VRSystemManagerExternal();
|
||||
|
||||
private:
|
||||
// there can only be one
|
||||
RefPtr<impl::VRDisplayExternal> mDisplay;
|
||||
#if defined(XP_MACOSX)
|
||||
int mShmemFD;
|
||||
#elif defined(XP_WIN)
|
||||
base::ProcessHandle mShmemFile;
|
||||
#elif defined(MOZ_WIDGET_ANDROID)
|
||||
|
||||
bool mExternalStructFailed;
|
||||
bool mEnumerationCompleted;
|
||||
#endif
|
||||
bool mDoShutdown;
|
||||
|
||||
volatile VRExternalShmem* mExternalShmem;
|
||||
#if !defined(MOZ_WIDGET_ANDROID)
|
||||
bool mSameProcess;
|
||||
#endif
|
||||
TimeStamp mEarliestRestartTime;
|
||||
|
||||
void OpenShmem();
|
||||
void CloseShmem();
|
||||
void CheckForShutdown();
|
||||
};
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace mozilla
|
||||
|
||||
|
||||
#endif /* GFX_VR_EXTERNAL_H */
|
||||
/* -*- 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
|
||||
* 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_EXTERNAL_H
|
||||
#define GFX_VR_EXTERNAL_H
|
||||
|
||||
#include "nsTArray.h"
|
||||
#include "nsIScreen.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "mozilla/RefPtr.h"
|
||||
|
||||
#include "mozilla/gfx/2D.h"
|
||||
#include "mozilla/EnumeratedArray.h"
|
||||
#include "mozilla/UniquePtr.h"
|
||||
|
||||
#include "gfxVR.h"
|
||||
#include "VRDisplayHost.h"
|
||||
|
||||
#if defined(XP_MACOSX)
|
||||
class MacIOSurface;
|
||||
#endif
|
||||
namespace mozilla {
|
||||
namespace gfx {
|
||||
namespace impl {
|
||||
|
||||
class VRDisplayExternal : public VRDisplayHost
|
||||
{
|
||||
public:
|
||||
void ZeroSensor() override;
|
||||
|
||||
protected:
|
||||
VRHMDSensorState GetSensorState() override;
|
||||
void StartPresentation() override;
|
||||
void StopPresentation() override;
|
||||
void StartVRNavigation() override;
|
||||
void StopVRNavigation(const TimeDuration& aTimeout) override;
|
||||
|
||||
bool SubmitFrame(const layers::SurfaceDescriptor& aTexture,
|
||||
uint64_t aFrameId,
|
||||
const gfx::Rect& aLeftEyeRect,
|
||||
const gfx::Rect& aRightEyeRect) override;
|
||||
|
||||
public:
|
||||
explicit VRDisplayExternal(const VRDisplayState& aDisplayState);
|
||||
void Refresh();
|
||||
const VRControllerState& GetLastControllerState(uint32_t aStateIndex) const;
|
||||
void VibrateHaptic(uint32_t aControllerIdx,
|
||||
uint32_t aHapticIndex,
|
||||
double aIntensity,
|
||||
double aDuration,
|
||||
const VRManagerPromise& aPromise);
|
||||
void StopVibrateHaptic(uint32_t aControllerIdx);
|
||||
void StopAllHaptics();
|
||||
void Run1msTasks(double aDeltaTime) override;
|
||||
void Run10msTasks() override;
|
||||
protected:
|
||||
virtual ~VRDisplayExternal();
|
||||
void Destroy();
|
||||
|
||||
private:
|
||||
bool PopulateLayerTexture(const layers::SurfaceDescriptor& aTexture,
|
||||
VRLayerTextureType* aTextureType,
|
||||
VRLayerTextureHandle* aTextureHandle);
|
||||
void PushState(bool aNotifyCond = false);
|
||||
#if defined(MOZ_WIDGET_ANDROID)
|
||||
bool PullState(const std::function<bool()>& aWaitCondition = nullptr);
|
||||
#else
|
||||
bool PullState();
|
||||
#endif
|
||||
void ClearHapticSlot(size_t aSlot);
|
||||
void ExpireNavigationTransition();
|
||||
void UpdateHaptics(double aDeltaTime);
|
||||
nsTArray<UniquePtr<VRManagerPromise>> mHapticPromises;
|
||||
// Duration of haptic pulse time remaining (milliseconds)
|
||||
double mHapticPulseRemaining[kVRHapticsMaxCount];
|
||||
VRTelemetry mTelemetry;
|
||||
TimeStamp mVRNavigationTransitionEnd;
|
||||
VRBrowserState mBrowserState;
|
||||
VRHMDSensorState mLastSensorState;
|
||||
};
|
||||
|
||||
} // namespace impl
|
||||
|
||||
class VRSystemManagerExternal : public VRSystemManager
|
||||
{
|
||||
public:
|
||||
static already_AddRefed<VRSystemManagerExternal> Create(VRExternalShmem* aAPIShmem = nullptr);
|
||||
|
||||
virtual void Destroy() override;
|
||||
virtual void Shutdown() override;
|
||||
virtual void Run100msTasks() override;
|
||||
virtual void Enumerate() override;
|
||||
virtual bool ShouldInhibitEnumeration() override;
|
||||
virtual void GetHMDs(nsTArray<RefPtr<VRDisplayHost>>& aHMDResult) override;
|
||||
virtual bool GetIsPresenting() override;
|
||||
virtual void HandleInput() override;
|
||||
virtual void GetControllers(nsTArray<RefPtr<VRControllerHost>>&
|
||||
aControllerResult) override;
|
||||
virtual void ScanForControllers() override;
|
||||
virtual void RemoveControllers() override;
|
||||
virtual void VibrateHaptic(uint32_t aControllerIdx,
|
||||
uint32_t aHapticIndex,
|
||||
double aIntensity,
|
||||
double aDuration,
|
||||
const VRManagerPromise& aPromise) override;
|
||||
virtual void StopVibrateHaptic(uint32_t aControllerIdx) override;
|
||||
#if defined(MOZ_WIDGET_ANDROID)
|
||||
bool PullState(VRDisplayState* aDisplayState,
|
||||
VRHMDSensorState* aSensorState = nullptr,
|
||||
VRControllerState* aControllerState = nullptr,
|
||||
const std::function<bool()>& aWaitCondition = nullptr);
|
||||
#else
|
||||
bool PullState(VRDisplayState* aDisplayState,
|
||||
VRHMDSensorState* aSensorState = nullptr,
|
||||
VRControllerState* aControllerState = nullptr);
|
||||
#endif
|
||||
void PushState(VRBrowserState* aBrowserState, const bool aNotifyCond = false);
|
||||
|
||||
protected:
|
||||
explicit VRSystemManagerExternal(VRExternalShmem* aAPIShmem = nullptr);
|
||||
virtual ~VRSystemManagerExternal();
|
||||
|
||||
private:
|
||||
// there can only be one
|
||||
RefPtr<impl::VRDisplayExternal> mDisplay;
|
||||
#if defined(XP_MACOSX)
|
||||
int mShmemFD;
|
||||
#elif defined(XP_WIN)
|
||||
base::ProcessHandle mShmemFile;
|
||||
#elif defined(MOZ_WIDGET_ANDROID)
|
||||
|
||||
bool mExternalStructFailed;
|
||||
bool mEnumerationCompleted;
|
||||
#endif
|
||||
bool mDoShutdown;
|
||||
|
||||
volatile VRExternalShmem* mExternalShmem;
|
||||
#if !defined(MOZ_WIDGET_ANDROID)
|
||||
bool mSameProcess;
|
||||
#endif
|
||||
TimeStamp mEarliestRestartTime;
|
||||
|
||||
void OpenShmem();
|
||||
void CloseShmem();
|
||||
void CheckForShutdown();
|
||||
};
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace mozilla
|
||||
|
||||
|
||||
#endif /* GFX_VR_EXTERNAL_H */
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -1,114 +1,114 @@
|
|||
/* -*- 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
|
||||
* 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_SERVICE_OCULUSSESSION_H
|
||||
#define GFX_VR_SERVICE_OCULUSSESSION_H
|
||||
|
||||
#include "VRSession.h"
|
||||
|
||||
#include "mozilla/gfx/2D.h"
|
||||
#include "moz_external_vr.h"
|
||||
#include "nsTArray.h"
|
||||
#include "oculus/ovr_capi_dynamic.h"
|
||||
#include "prlink.h"
|
||||
#include "ShaderDefinitionsD3D11.h" // for VertexShaderConstants and PixelShaderConstants
|
||||
|
||||
struct ID3D11Device;
|
||||
|
||||
namespace mozilla {
|
||||
namespace layers {
|
||||
struct VertexShaderConstants;
|
||||
struct PixelShaderConstants;
|
||||
}
|
||||
namespace gfx {
|
||||
|
||||
class OculusSession : public VRSession
|
||||
{
|
||||
public:
|
||||
OculusSession();
|
||||
virtual ~OculusSession();
|
||||
|
||||
bool Initialize(mozilla::gfx::VRSystemState& aSystemState) override;
|
||||
void Shutdown() override;
|
||||
void ProcessEvents(mozilla::gfx::VRSystemState& aSystemState) override;
|
||||
void StartFrame(mozilla::gfx::VRSystemState& aSystemState) override;
|
||||
bool StartPresentation() override;
|
||||
void StopPresentation() override;
|
||||
bool SubmitFrame(const mozilla::gfx::VRLayer_Stereo_Immersive& aLayer,
|
||||
ID3D11Texture2D* aTexture) override;
|
||||
void VibrateHaptic(uint32_t aControllerIdx, uint32_t aHapticIndex,
|
||||
float aIntensity, float aDuration) override;
|
||||
void StopVibrateHaptic(uint32_t aControllerIdx) override;
|
||||
void StopAllHaptics() override;
|
||||
|
||||
private:
|
||||
bool LoadOvrLib();
|
||||
void UnloadOvrLib();
|
||||
bool StartLib(ovrInitFlags aFlags);
|
||||
void StopLib();
|
||||
bool StartSession();
|
||||
void StopSession();
|
||||
bool StartRendering();
|
||||
void StopRendering();
|
||||
bool CreateD3DObjects();
|
||||
bool CreateShaders();
|
||||
void DestroyShaders();
|
||||
void CoverTransitions();
|
||||
void UpdateVisibility();
|
||||
bool ChangeVisibility(bool bVisible);
|
||||
bool InitState(mozilla::gfx::VRSystemState& aSystemState);
|
||||
void UpdateStageParameters(mozilla::gfx::VRDisplayState& aState);
|
||||
void UpdateEyeParameters(mozilla::gfx::VRSystemState& aState);
|
||||
void UpdateHeadsetPose(mozilla::gfx::VRSystemState& aState);
|
||||
void UpdateControllers(VRSystemState& aState);
|
||||
void UpdateControllerInputs(VRSystemState& aState,
|
||||
const ovrInputState& aInputState);
|
||||
void UpdateHaptics();
|
||||
void EnumerateControllers(VRSystemState& aState,
|
||||
const ovrInputState& aInputState);
|
||||
void UpdateControllerPose(VRSystemState& aState,
|
||||
const ovrInputState& aInputState);
|
||||
void UpdateTelemetry(VRSystemState& aSystemState);
|
||||
bool IsPresentationReady() const;
|
||||
bool UpdateConstantBuffers();
|
||||
|
||||
PRLibrary* mOvrLib;
|
||||
ovrSession mSession;
|
||||
ovrInitFlags mInitFlags;
|
||||
ovrTextureSwapChain mTextureSet;
|
||||
nsTArray<RefPtr<ID3D11RenderTargetView>> mRTView;
|
||||
nsTArray<RefPtr<ID3D11Texture2D>> mTexture;
|
||||
nsTArray<RefPtr<ID3D11ShaderResourceView>> mSRV;
|
||||
|
||||
ID3D11VertexShader* mQuadVS;
|
||||
ID3D11PixelShader* mQuadPS;
|
||||
RefPtr<ID3D11SamplerState> mLinearSamplerState;
|
||||
layers::VertexShaderConstants mVSConstants;
|
||||
layers::PixelShaderConstants mPSConstants;
|
||||
RefPtr<ID3D11Buffer> mVSConstantBuffer;
|
||||
RefPtr<ID3D11Buffer> mPSConstantBuffer;
|
||||
RefPtr<ID3D11Buffer> mVertexBuffer;
|
||||
RefPtr<ID3D11InputLayout> mInputLayout;
|
||||
|
||||
IntSize mPresentationSize;
|
||||
ovrFovPort mFOVPort[2];
|
||||
|
||||
// Most recent HMD eye poses, from start of frame
|
||||
ovrPosef mFrameStartPose[2];
|
||||
|
||||
float mRemainingVibrateTime[2];
|
||||
float mHapticPulseIntensity[2];
|
||||
TimeStamp mLastHapticUpdate;
|
||||
|
||||
// The timestamp of the last ending presentation
|
||||
TimeStamp mLastPresentationEnd;
|
||||
bool mIsPresenting;
|
||||
};
|
||||
|
||||
} // namespace mozilla
|
||||
} // namespace gfx
|
||||
|
||||
#endif // GFX_VR_SERVICE_OCULUSSESSION_H
|
||||
/* -*- 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
|
||||
* 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_SERVICE_OCULUSSESSION_H
|
||||
#define GFX_VR_SERVICE_OCULUSSESSION_H
|
||||
|
||||
#include "VRSession.h"
|
||||
|
||||
#include "mozilla/gfx/2D.h"
|
||||
#include "moz_external_vr.h"
|
||||
#include "nsTArray.h"
|
||||
#include "oculus/ovr_capi_dynamic.h"
|
||||
#include "prlink.h"
|
||||
#include "ShaderDefinitionsD3D11.h" // for VertexShaderConstants and PixelShaderConstants
|
||||
|
||||
struct ID3D11Device;
|
||||
|
||||
namespace mozilla {
|
||||
namespace layers {
|
||||
struct VertexShaderConstants;
|
||||
struct PixelShaderConstants;
|
||||
}
|
||||
namespace gfx {
|
||||
|
||||
class OculusSession : public VRSession
|
||||
{
|
||||
public:
|
||||
OculusSession();
|
||||
virtual ~OculusSession();
|
||||
|
||||
bool Initialize(mozilla::gfx::VRSystemState& aSystemState) override;
|
||||
void Shutdown() override;
|
||||
void ProcessEvents(mozilla::gfx::VRSystemState& aSystemState) override;
|
||||
void StartFrame(mozilla::gfx::VRSystemState& aSystemState) override;
|
||||
bool StartPresentation() override;
|
||||
void StopPresentation() override;
|
||||
bool SubmitFrame(const mozilla::gfx::VRLayer_Stereo_Immersive& aLayer,
|
||||
ID3D11Texture2D* aTexture) override;
|
||||
void VibrateHaptic(uint32_t aControllerIdx, uint32_t aHapticIndex,
|
||||
float aIntensity, float aDuration) override;
|
||||
void StopVibrateHaptic(uint32_t aControllerIdx) override;
|
||||
void StopAllHaptics() override;
|
||||
|
||||
private:
|
||||
bool LoadOvrLib();
|
||||
void UnloadOvrLib();
|
||||
bool StartLib(ovrInitFlags aFlags);
|
||||
void StopLib();
|
||||
bool StartSession();
|
||||
void StopSession();
|
||||
bool StartRendering();
|
||||
void StopRendering();
|
||||
bool CreateD3DObjects();
|
||||
bool CreateShaders();
|
||||
void DestroyShaders();
|
||||
void CoverTransitions();
|
||||
void UpdateVisibility();
|
||||
bool ChangeVisibility(bool bVisible);
|
||||
bool InitState(mozilla::gfx::VRSystemState& aSystemState);
|
||||
void UpdateStageParameters(mozilla::gfx::VRDisplayState& aState);
|
||||
void UpdateEyeParameters(mozilla::gfx::VRSystemState& aState);
|
||||
void UpdateHeadsetPose(mozilla::gfx::VRSystemState& aState);
|
||||
void UpdateControllers(VRSystemState& aState);
|
||||
void UpdateControllerInputs(VRSystemState& aState,
|
||||
const ovrInputState& aInputState);
|
||||
void UpdateHaptics();
|
||||
void EnumerateControllers(VRSystemState& aState,
|
||||
const ovrInputState& aInputState);
|
||||
void UpdateControllerPose(VRSystemState& aState,
|
||||
const ovrInputState& aInputState);
|
||||
void UpdateTelemetry(VRSystemState& aSystemState);
|
||||
bool IsPresentationReady() const;
|
||||
bool UpdateConstantBuffers();
|
||||
|
||||
PRLibrary* mOvrLib;
|
||||
ovrSession mSession;
|
||||
ovrInitFlags mInitFlags;
|
||||
ovrTextureSwapChain mTextureSet;
|
||||
nsTArray<RefPtr<ID3D11RenderTargetView>> mRTView;
|
||||
nsTArray<RefPtr<ID3D11Texture2D>> mTexture;
|
||||
nsTArray<RefPtr<ID3D11ShaderResourceView>> mSRV;
|
||||
|
||||
ID3D11VertexShader* mQuadVS;
|
||||
ID3D11PixelShader* mQuadPS;
|
||||
RefPtr<ID3D11SamplerState> mLinearSamplerState;
|
||||
layers::VertexShaderConstants mVSConstants;
|
||||
layers::PixelShaderConstants mPSConstants;
|
||||
RefPtr<ID3D11Buffer> mVSConstantBuffer;
|
||||
RefPtr<ID3D11Buffer> mPSConstantBuffer;
|
||||
RefPtr<ID3D11Buffer> mVertexBuffer;
|
||||
RefPtr<ID3D11InputLayout> mInputLayout;
|
||||
|
||||
IntSize mPresentationSize;
|
||||
ovrFovPort mFOVPort[2];
|
||||
|
||||
// Most recent HMD eye poses, from start of frame
|
||||
ovrPosef mFrameStartPose[2];
|
||||
|
||||
float mRemainingVibrateTime[2];
|
||||
float mHapticPulseIntensity[2];
|
||||
TimeStamp mLastHapticUpdate;
|
||||
|
||||
// The timestamp of the last ending presentation
|
||||
TimeStamp mLastPresentationEnd;
|
||||
bool mIsPresenting;
|
||||
};
|
||||
|
||||
} // namespace mozilla
|
||||
} // namespace gfx
|
||||
|
||||
#endif // GFX_VR_SERVICE_OCULUSSESSION_H
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -1,97 +1,97 @@
|
|||
/* -*- 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
|
||||
* 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_SERVICE_OPENVRSESSION_H
|
||||
#define GFX_VR_SERVICE_OPENVRSESSION_H
|
||||
|
||||
#include "VRSession.h"
|
||||
|
||||
#include "openvr.h"
|
||||
#include "mozilla/TimeStamp.h"
|
||||
#include "moz_external_vr.h"
|
||||
|
||||
#if defined(XP_WIN)
|
||||
#include <d3d11_1.h>
|
||||
#endif
|
||||
class nsITimer;
|
||||
|
||||
namespace mozilla {
|
||||
namespace gfx {
|
||||
class VRThread;
|
||||
|
||||
static const int kNumOpenVRHaptics = 1;
|
||||
|
||||
class OpenVRSession : public VRSession
|
||||
{
|
||||
public:
|
||||
OpenVRSession();
|
||||
virtual ~OpenVRSession();
|
||||
|
||||
bool Initialize(mozilla::gfx::VRSystemState& aSystemState) override;
|
||||
void Shutdown() override;
|
||||
void ProcessEvents(mozilla::gfx::VRSystemState& aSystemState) override;
|
||||
void StartFrame(mozilla::gfx::VRSystemState& aSystemState) override;
|
||||
bool StartPresentation() override;
|
||||
void StopPresentation() override;
|
||||
void VibrateHaptic(uint32_t aControllerIdx, uint32_t aHapticIndex,
|
||||
float aIntensity, float aDuration) override;
|
||||
void StopVibrateHaptic(uint32_t aControllerIdx) override;
|
||||
void StopAllHaptics() override;
|
||||
|
||||
protected:
|
||||
#if defined(XP_WIN)
|
||||
bool SubmitFrame(const mozilla::gfx::VRLayer_Stereo_Immersive& aLayer,
|
||||
ID3D11Texture2D* aTexture) override;
|
||||
#elif defined(XP_MACOSX)
|
||||
bool SubmitFrame(const mozilla::gfx::VRLayer_Stereo_Immersive& aLayer,
|
||||
const VRLayerTextureHandle& aTexture) override;
|
||||
#endif
|
||||
|
||||
private:
|
||||
// OpenVR State
|
||||
::vr::IVRSystem* mVRSystem = nullptr;
|
||||
::vr::IVRChaperone* mVRChaperone = nullptr;
|
||||
::vr::IVRCompositor* mVRCompositor = nullptr;
|
||||
::vr::TrackedDeviceIndex_t mControllerDeviceIndex[kVRControllerMaxCount];
|
||||
float mHapticPulseRemaining[kVRControllerMaxCount][kNumOpenVRHaptics];
|
||||
float mHapticPulseIntensity[kVRControllerMaxCount][kNumOpenVRHaptics];
|
||||
bool mIsWindowsMR;
|
||||
TimeStamp mLastHapticUpdate;
|
||||
|
||||
bool InitState(mozilla::gfx::VRSystemState& aSystemState);
|
||||
void UpdateStageParameters(mozilla::gfx::VRDisplayState& aState);
|
||||
void UpdateEyeParameters(mozilla::gfx::VRSystemState& aState);
|
||||
void UpdateHeadsetPose(mozilla::gfx::VRSystemState& aState);
|
||||
void EnumerateControllers(VRSystemState& aState);
|
||||
void UpdateControllerPoses(VRSystemState& aState);
|
||||
void UpdateControllerButtons(VRSystemState& aState);
|
||||
void UpdateTelemetry(VRSystemState& aSystemState);
|
||||
|
||||
bool SubmitFrame(const VRLayerTextureHandle& aTextureHandle,
|
||||
::vr::ETextureType aTextureType,
|
||||
const VRLayerEyeRect& aLeftEyeRect,
|
||||
const VRLayerEyeRect& aRightEyeRect);
|
||||
#if defined(XP_WIN)
|
||||
bool CreateD3DObjects();
|
||||
#endif
|
||||
void GetControllerDeviceId(::vr::ETrackedDeviceClass aDeviceType,
|
||||
::vr::TrackedDeviceIndex_t aDeviceIndex,
|
||||
nsCString& aId);
|
||||
void UpdateHaptics();
|
||||
void StartHapticThread();
|
||||
void StopHapticThread();
|
||||
void StartHapticTimer();
|
||||
void StopHapticTimer();
|
||||
static void HapticTimerCallback(nsITimer* aTimer, void* aClosure);
|
||||
RefPtr<nsITimer> mHapticTimer;
|
||||
RefPtr<VRThread> mHapticThread;
|
||||
mozilla::Mutex mControllerHapticStateMutex;
|
||||
};
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // GFX_VR_SERVICE_OPENVRSESSION_H
|
||||
/* -*- 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
|
||||
* 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_SERVICE_OPENVRSESSION_H
|
||||
#define GFX_VR_SERVICE_OPENVRSESSION_H
|
||||
|
||||
#include "VRSession.h"
|
||||
|
||||
#include "openvr.h"
|
||||
#include "mozilla/TimeStamp.h"
|
||||
#include "moz_external_vr.h"
|
||||
|
||||
#if defined(XP_WIN)
|
||||
#include <d3d11_1.h>
|
||||
#endif
|
||||
class nsITimer;
|
||||
|
||||
namespace mozilla {
|
||||
namespace gfx {
|
||||
class VRThread;
|
||||
|
||||
static const int kNumOpenVRHaptics = 1;
|
||||
|
||||
class OpenVRSession : public VRSession
|
||||
{
|
||||
public:
|
||||
OpenVRSession();
|
||||
virtual ~OpenVRSession();
|
||||
|
||||
bool Initialize(mozilla::gfx::VRSystemState& aSystemState) override;
|
||||
void Shutdown() override;
|
||||
void ProcessEvents(mozilla::gfx::VRSystemState& aSystemState) override;
|
||||
void StartFrame(mozilla::gfx::VRSystemState& aSystemState) override;
|
||||
bool StartPresentation() override;
|
||||
void StopPresentation() override;
|
||||
void VibrateHaptic(uint32_t aControllerIdx, uint32_t aHapticIndex,
|
||||
float aIntensity, float aDuration) override;
|
||||
void StopVibrateHaptic(uint32_t aControllerIdx) override;
|
||||
void StopAllHaptics() override;
|
||||
|
||||
protected:
|
||||
#if defined(XP_WIN)
|
||||
bool SubmitFrame(const mozilla::gfx::VRLayer_Stereo_Immersive& aLayer,
|
||||
ID3D11Texture2D* aTexture) override;
|
||||
#elif defined(XP_MACOSX)
|
||||
bool SubmitFrame(const mozilla::gfx::VRLayer_Stereo_Immersive& aLayer,
|
||||
const VRLayerTextureHandle& aTexture) override;
|
||||
#endif
|
||||
|
||||
private:
|
||||
// OpenVR State
|
||||
::vr::IVRSystem* mVRSystem = nullptr;
|
||||
::vr::IVRChaperone* mVRChaperone = nullptr;
|
||||
::vr::IVRCompositor* mVRCompositor = nullptr;
|
||||
::vr::TrackedDeviceIndex_t mControllerDeviceIndex[kVRControllerMaxCount];
|
||||
float mHapticPulseRemaining[kVRControllerMaxCount][kNumOpenVRHaptics];
|
||||
float mHapticPulseIntensity[kVRControllerMaxCount][kNumOpenVRHaptics];
|
||||
bool mIsWindowsMR;
|
||||
TimeStamp mLastHapticUpdate;
|
||||
|
||||
bool InitState(mozilla::gfx::VRSystemState& aSystemState);
|
||||
void UpdateStageParameters(mozilla::gfx::VRDisplayState& aState);
|
||||
void UpdateEyeParameters(mozilla::gfx::VRSystemState& aState);
|
||||
void UpdateHeadsetPose(mozilla::gfx::VRSystemState& aState);
|
||||
void EnumerateControllers(VRSystemState& aState);
|
||||
void UpdateControllerPoses(VRSystemState& aState);
|
||||
void UpdateControllerButtons(VRSystemState& aState);
|
||||
void UpdateTelemetry(VRSystemState& aSystemState);
|
||||
|
||||
bool SubmitFrame(const VRLayerTextureHandle& aTextureHandle,
|
||||
::vr::ETextureType aTextureType,
|
||||
const VRLayerEyeRect& aLeftEyeRect,
|
||||
const VRLayerEyeRect& aRightEyeRect);
|
||||
#if defined(XP_WIN)
|
||||
bool CreateD3DObjects();
|
||||
#endif
|
||||
void GetControllerDeviceId(::vr::ETrackedDeviceClass aDeviceType,
|
||||
::vr::TrackedDeviceIndex_t aDeviceIndex,
|
||||
nsCString& aId);
|
||||
void UpdateHaptics();
|
||||
void StartHapticThread();
|
||||
void StopHapticThread();
|
||||
void StartHapticTimer();
|
||||
void StopHapticTimer();
|
||||
static void HapticTimerCallback(nsITimer* aTimer, void* aClosure);
|
||||
RefPtr<nsITimer> mHapticTimer;
|
||||
RefPtr<VRThread> mHapticThread;
|
||||
mozilla::Mutex mControllerHapticStateMutex;
|
||||
};
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // GFX_VR_SERVICE_OPENVRSESSION_H
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -1,92 +1,92 @@
|
|||
/* -*- 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
|
||||
* 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_SERVICE_VRSERVICE_H
|
||||
#define GFX_VR_SERVICE_VRSERVICE_H
|
||||
|
||||
#include "mozilla/Atomics.h"
|
||||
#include "moz_external_vr.h"
|
||||
#include "base/process.h" // for base::ProcessHandle
|
||||
|
||||
namespace base {
|
||||
class Thread;
|
||||
} // namespace base
|
||||
namespace mozilla {
|
||||
namespace gfx {
|
||||
|
||||
class VRSession;
|
||||
|
||||
static const int kVRFrameTimingHistoryDepth = 100;
|
||||
|
||||
class VRService
|
||||
{
|
||||
public:
|
||||
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VRService)
|
||||
static already_AddRefed<VRService> Create();
|
||||
|
||||
void Refresh();
|
||||
void Start();
|
||||
void Stop();
|
||||
VRExternalShmem* GetAPIShmem();
|
||||
|
||||
private:
|
||||
VRService();
|
||||
~VRService();
|
||||
|
||||
bool InitShmem();
|
||||
void PushState(const mozilla::gfx::VRSystemState& aState);
|
||||
void PullState(mozilla::gfx::VRBrowserState& aState);
|
||||
|
||||
/**
|
||||
* VRSystemState contains the most recent state of the VR
|
||||
* system, to be shared with the browser by Shmem.
|
||||
* mSystemState is the VR Service copy of this data, which
|
||||
* is memcpy'ed atomically to the Shmem.
|
||||
* VRSystemState is written by the VR Service, but read-only
|
||||
* by the browser.
|
||||
*/
|
||||
VRSystemState mSystemState;
|
||||
/**
|
||||
* VRBrowserState contains the most recent state of the browser.
|
||||
* mBrowserState is memcpy'ed from the Shmem atomically
|
||||
*/
|
||||
VRBrowserState mBrowserState;
|
||||
int64_t mBrowserGeneration;
|
||||
|
||||
UniquePtr<VRSession> mSession;
|
||||
base::Thread* mServiceThread;
|
||||
bool mShutdownRequested;
|
||||
|
||||
VRExternalShmem* MOZ_OWNING_REF mAPIShmem;
|
||||
base::ProcessHandle mTargetShmemFile;
|
||||
VRHapticState mLastHapticState[kVRHapticsMaxCount];
|
||||
TimeStamp mFrameStartTime[kVRFrameTimingHistoryDepth];
|
||||
// We store the value of gfxPrefs::VRProcessEnabled() in mVRProcessEnabled.
|
||||
// This allows us to read the value in the VRService destructor, after
|
||||
// gfxPrefs has been shut down. We should investigate why gfxPrefs
|
||||
// is shutting down earlier - See bug xxx
|
||||
bool mVRProcessEnabled;
|
||||
|
||||
bool IsInServiceThread();
|
||||
void UpdateHaptics();
|
||||
|
||||
/**
|
||||
* The VR Service thread is a state machine that always has one
|
||||
* task queued depending on the state.
|
||||
*
|
||||
* VR Service thread state task functions:
|
||||
*/
|
||||
void ServiceInitialize();
|
||||
void ServiceShutdown();
|
||||
void ServiceWaitForImmersive();
|
||||
void ServiceImmersiveMode();
|
||||
|
||||
};
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // GFX_VR_SERVICE_VRSERVICE_H
|
||||
/* -*- 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
|
||||
* 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_SERVICE_VRSERVICE_H
|
||||
#define GFX_VR_SERVICE_VRSERVICE_H
|
||||
|
||||
#include "mozilla/Atomics.h"
|
||||
#include "moz_external_vr.h"
|
||||
#include "base/process.h" // for base::ProcessHandle
|
||||
|
||||
namespace base {
|
||||
class Thread;
|
||||
} // namespace base
|
||||
namespace mozilla {
|
||||
namespace gfx {
|
||||
|
||||
class VRSession;
|
||||
|
||||
static const int kVRFrameTimingHistoryDepth = 100;
|
||||
|
||||
class VRService
|
||||
{
|
||||
public:
|
||||
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VRService)
|
||||
static already_AddRefed<VRService> Create();
|
||||
|
||||
void Refresh();
|
||||
void Start();
|
||||
void Stop();
|
||||
VRExternalShmem* GetAPIShmem();
|
||||
|
||||
private:
|
||||
VRService();
|
||||
~VRService();
|
||||
|
||||
bool InitShmem();
|
||||
void PushState(const mozilla::gfx::VRSystemState& aState);
|
||||
void PullState(mozilla::gfx::VRBrowserState& aState);
|
||||
|
||||
/**
|
||||
* VRSystemState contains the most recent state of the VR
|
||||
* system, to be shared with the browser by Shmem.
|
||||
* mSystemState is the VR Service copy of this data, which
|
||||
* is memcpy'ed atomically to the Shmem.
|
||||
* VRSystemState is written by the VR Service, but read-only
|
||||
* by the browser.
|
||||
*/
|
||||
VRSystemState mSystemState;
|
||||
/**
|
||||
* VRBrowserState contains the most recent state of the browser.
|
||||
* mBrowserState is memcpy'ed from the Shmem atomically
|
||||
*/
|
||||
VRBrowserState mBrowserState;
|
||||
int64_t mBrowserGeneration;
|
||||
|
||||
UniquePtr<VRSession> mSession;
|
||||
base::Thread* mServiceThread;
|
||||
bool mShutdownRequested;
|
||||
|
||||
VRExternalShmem* MOZ_OWNING_REF mAPIShmem;
|
||||
base::ProcessHandle mTargetShmemFile;
|
||||
VRHapticState mLastHapticState[kVRHapticsMaxCount];
|
||||
TimeStamp mFrameStartTime[kVRFrameTimingHistoryDepth];
|
||||
// We store the value of gfxPrefs::VRProcessEnabled() in mVRProcessEnabled.
|
||||
// This allows us to read the value in the VRService destructor, after
|
||||
// gfxPrefs has been shut down. We should investigate why gfxPrefs
|
||||
// is shutting down earlier - See bug xxx
|
||||
bool mVRProcessEnabled;
|
||||
|
||||
bool IsInServiceThread();
|
||||
void UpdateHaptics();
|
||||
|
||||
/**
|
||||
* The VR Service thread is a state machine that always has one
|
||||
* task queued depending on the state.
|
||||
*
|
||||
* VR Service thread state task functions:
|
||||
*/
|
||||
void ServiceInitialize();
|
||||
void ServiceShutdown();
|
||||
void ServiceWaitForImmersive();
|
||||
void ServiceImmersiveMode();
|
||||
|
||||
};
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // GFX_VR_SERVICE_VRSERVICE_H
|
||||
|
|
|
@ -1,160 +1,155 @@
|
|||
#include "VRSession.h"
|
||||
|
||||
#include "moz_external_vr.h"
|
||||
|
||||
#if defined(XP_WIN)
|
||||
#include <d3d11.h>
|
||||
#endif // defined(XP_WIN)
|
||||
|
||||
using namespace mozilla::gfx;
|
||||
|
||||
VRSession::VRSession()
|
||||
: mShouldQuit(false)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
VRSession::~VRSession()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#if defined(XP_WIN)
|
||||
bool
|
||||
VRSession::CreateD3DContext(RefPtr<ID3D11Device> aDevice)
|
||||
{
|
||||
if (!mDevice) {
|
||||
if (!aDevice) {
|
||||
NS_WARNING("VRSession::CreateD3DObjects failed to get a D3D11Device");
|
||||
return false;
|
||||
}
|
||||
if (FAILED(aDevice->QueryInterface(__uuidof(ID3D11Device1), getter_AddRefs(mDevice)))) {
|
||||
NS_WARNING("VRSession::CreateD3DObjects failed to get a D3D11Device1");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (!mContext) {
|
||||
mDevice->GetImmediateContext1(getter_AddRefs(mContext));
|
||||
if (!mContext) {
|
||||
NS_WARNING("VRSession::CreateD3DObjects failed to get an immediate context");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (!mDeviceContextState) {
|
||||
D3D_FEATURE_LEVEL featureLevels[] {
|
||||
D3D_FEATURE_LEVEL_11_1,
|
||||
D3D_FEATURE_LEVEL_11_0
|
||||
};
|
||||
mDevice->CreateDeviceContextState(0,
|
||||
featureLevels,
|
||||
2,
|
||||
D3D11_SDK_VERSION,
|
||||
__uuidof(ID3D11Device1),
|
||||
nullptr,
|
||||
getter_AddRefs(mDeviceContextState));
|
||||
}
|
||||
if (!mDeviceContextState) {
|
||||
NS_WARNING("VRSession::CreateD3DObjects failed to get a D3D11DeviceContextState");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
ID3D11Device1*
|
||||
VRSession::GetD3DDevice()
|
||||
{
|
||||
return mDevice;
|
||||
}
|
||||
|
||||
ID3D11DeviceContext1*
|
||||
VRSession::GetD3DDeviceContext()
|
||||
{
|
||||
return mContext;
|
||||
}
|
||||
|
||||
ID3DDeviceContextState*
|
||||
VRSession::GetD3DDeviceContextState()
|
||||
{
|
||||
return mDeviceContextState;
|
||||
}
|
||||
|
||||
#endif // defined(XP_WIN)
|
||||
|
||||
bool
|
||||
VRSession::SubmitFrame(const mozilla::gfx::VRLayer_Stereo_Immersive& aLayer)
|
||||
{
|
||||
#if defined(XP_WIN)
|
||||
|
||||
if (aLayer.mTextureType == VRLayerTextureType::LayerTextureType_D3D10SurfaceDescriptor) {
|
||||
RefPtr<ID3D11Texture2D> dxTexture;
|
||||
HRESULT hr = mDevice->OpenSharedResource((HANDLE)aLayer.mTextureHandle,
|
||||
__uuidof(ID3D11Texture2D),
|
||||
(void**)(ID3D11Texture2D**)getter_AddRefs(dxTexture));
|
||||
if (FAILED(hr) || !dxTexture) {
|
||||
NS_WARNING("Failed to open shared texture");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Similar to LockD3DTexture in TextureD3D11.cpp
|
||||
RefPtr<IDXGIKeyedMutex> mutex;
|
||||
dxTexture->QueryInterface((IDXGIKeyedMutex**)getter_AddRefs(mutex));
|
||||
if (mutex) {
|
||||
HRESULT hr = mutex->AcquireSync(0, 1000);
|
||||
if (hr == WAIT_TIMEOUT) {
|
||||
gfxDevCrash(LogReason::D3DLockTimeout) << "D3D lock mutex timeout";
|
||||
}
|
||||
else if (hr == WAIT_ABANDONED) {
|
||||
gfxCriticalNote << "GFX: D3D11 lock mutex abandoned";
|
||||
}
|
||||
if (FAILED(hr)) {
|
||||
NS_WARNING("Failed to lock the texture");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
bool success = SubmitFrame(aLayer, dxTexture);
|
||||
if (mutex) {
|
||||
HRESULT hr = mutex->ReleaseSync(0);
|
||||
if (FAILED(hr)) {
|
||||
NS_WARNING("Failed to unlock the texture");
|
||||
}
|
||||
}
|
||||
if (!success) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
#elif defined(XP_MACOSX)
|
||||
|
||||
if (aLayer.mTextureType == VRLayerTextureType::LayerTextureType_MacIOSurface) {
|
||||
return SubmitFrame(aLayer, aLayer.mTextureHandle);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void
|
||||
VRSession::UpdateTrigger(VRControllerState& aState, uint32_t aButtonIndex, float aValue, float aThreshold)
|
||||
{
|
||||
// For OpenVR, the threshold value of ButtonPressed and ButtonTouched is 0.55.
|
||||
// We prefer to let developers to set their own threshold for the adjustment.
|
||||
// Therefore, we don't check ButtonPressed and ButtonTouched with ButtonMask here.
|
||||
// we just check the button value is larger than the threshold value or not.
|
||||
uint64_t mask = (1ULL << aButtonIndex);
|
||||
aState.triggerValue[aButtonIndex] = aValue;
|
||||
if (aValue > aThreshold) {
|
||||
aState.buttonPressed |= mask;
|
||||
aState.buttonTouched |= mask;
|
||||
} else {
|
||||
aState.buttonPressed &= ~mask;
|
||||
aState.buttonTouched &= ~mask;
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
VRSession::ShouldQuit() const
|
||||
{
|
||||
return mShouldQuit;
|
||||
}
|
||||
#include "VRSession.h"
|
||||
|
||||
#include "moz_external_vr.h"
|
||||
|
||||
#if defined(XP_WIN)
|
||||
#include <d3d11.h>
|
||||
#endif // defined(XP_WIN)
|
||||
|
||||
using namespace mozilla::gfx;
|
||||
|
||||
VRSession::VRSession()
|
||||
: mShouldQuit(false)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#if defined(XP_WIN)
|
||||
bool
|
||||
VRSession::CreateD3DContext(RefPtr<ID3D11Device> aDevice)
|
||||
{
|
||||
if (!mDevice) {
|
||||
if (!aDevice) {
|
||||
NS_WARNING("VRSession::CreateD3DObjects failed to get a D3D11Device");
|
||||
return false;
|
||||
}
|
||||
if (FAILED(aDevice->QueryInterface(__uuidof(ID3D11Device1), getter_AddRefs(mDevice)))) {
|
||||
NS_WARNING("VRSession::CreateD3DObjects failed to get a D3D11Device1");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (!mContext) {
|
||||
mDevice->GetImmediateContext1(getter_AddRefs(mContext));
|
||||
if (!mContext) {
|
||||
NS_WARNING("VRSession::CreateD3DObjects failed to get an immediate context");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (!mDeviceContextState) {
|
||||
D3D_FEATURE_LEVEL featureLevels[] {
|
||||
D3D_FEATURE_LEVEL_11_1,
|
||||
D3D_FEATURE_LEVEL_11_0
|
||||
};
|
||||
mDevice->CreateDeviceContextState(0,
|
||||
featureLevels,
|
||||
2,
|
||||
D3D11_SDK_VERSION,
|
||||
__uuidof(ID3D11Device1),
|
||||
nullptr,
|
||||
getter_AddRefs(mDeviceContextState));
|
||||
}
|
||||
if (!mDeviceContextState) {
|
||||
NS_WARNING("VRSession::CreateD3DObjects failed to get a D3D11DeviceContextState");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
ID3D11Device1*
|
||||
VRSession::GetD3DDevice()
|
||||
{
|
||||
return mDevice;
|
||||
}
|
||||
|
||||
ID3D11DeviceContext1*
|
||||
VRSession::GetD3DDeviceContext()
|
||||
{
|
||||
return mContext;
|
||||
}
|
||||
|
||||
ID3DDeviceContextState*
|
||||
VRSession::GetD3DDeviceContextState()
|
||||
{
|
||||
return mDeviceContextState;
|
||||
}
|
||||
|
||||
#endif // defined(XP_WIN)
|
||||
|
||||
bool
|
||||
VRSession::SubmitFrame(const mozilla::gfx::VRLayer_Stereo_Immersive& aLayer)
|
||||
{
|
||||
#if defined(XP_WIN)
|
||||
|
||||
if (aLayer.mTextureType == VRLayerTextureType::LayerTextureType_D3D10SurfaceDescriptor) {
|
||||
RefPtr<ID3D11Texture2D> dxTexture;
|
||||
HRESULT hr = mDevice->OpenSharedResource((HANDLE)aLayer.mTextureHandle,
|
||||
__uuidof(ID3D11Texture2D),
|
||||
(void**)(ID3D11Texture2D**)getter_AddRefs(dxTexture));
|
||||
if (FAILED(hr) || !dxTexture) {
|
||||
NS_WARNING("Failed to open shared texture");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Similar to LockD3DTexture in TextureD3D11.cpp
|
||||
RefPtr<IDXGIKeyedMutex> mutex;
|
||||
dxTexture->QueryInterface((IDXGIKeyedMutex**)getter_AddRefs(mutex));
|
||||
if (mutex) {
|
||||
HRESULT hr = mutex->AcquireSync(0, 1000);
|
||||
if (hr == WAIT_TIMEOUT) {
|
||||
gfxDevCrash(LogReason::D3DLockTimeout) << "D3D lock mutex timeout";
|
||||
}
|
||||
else if (hr == WAIT_ABANDONED) {
|
||||
gfxCriticalNote << "GFX: D3D11 lock mutex abandoned";
|
||||
}
|
||||
if (FAILED(hr)) {
|
||||
NS_WARNING("Failed to lock the texture");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
bool success = SubmitFrame(aLayer, dxTexture);
|
||||
if (mutex) {
|
||||
HRESULT hr = mutex->ReleaseSync(0);
|
||||
if (FAILED(hr)) {
|
||||
NS_WARNING("Failed to unlock the texture");
|
||||
}
|
||||
}
|
||||
if (!success) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
#elif defined(XP_MACOSX)
|
||||
|
||||
if (aLayer.mTextureType == VRLayerTextureType::LayerTextureType_MacIOSurface) {
|
||||
return SubmitFrame(aLayer, aLayer.mTextureHandle);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void
|
||||
VRSession::UpdateTrigger(VRControllerState& aState, uint32_t aButtonIndex, float aValue, float aThreshold)
|
||||
{
|
||||
// For OpenVR, the threshold value of ButtonPressed and ButtonTouched is 0.55.
|
||||
// We prefer to let developers to set their own threshold for the adjustment.
|
||||
// Therefore, we don't check ButtonPressed and ButtonTouched with ButtonMask here.
|
||||
// we just check the button value is larger than the threshold value or not.
|
||||
uint64_t mask = (1ULL << aButtonIndex);
|
||||
aState.triggerValue[aButtonIndex] = aValue;
|
||||
if (aValue > aThreshold) {
|
||||
aState.buttonPressed |= mask;
|
||||
aState.buttonTouched |= mask;
|
||||
} else {
|
||||
aState.buttonPressed &= ~mask;
|
||||
aState.buttonTouched &= ~mask;
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
VRSession::ShouldQuit() const
|
||||
{
|
||||
return mShouldQuit;
|
||||
}
|
||||
|
|
|
@ -1,62 +1,62 @@
|
|||
/* -*- 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
|
||||
* 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_SERVICE_VRSESSION_H
|
||||
#define GFX_VR_SERVICE_VRSESSION_H
|
||||
|
||||
#include "moz_external_vr.h"
|
||||
|
||||
#if defined(XP_WIN)
|
||||
#include <d3d11_1.h>
|
||||
#elif defined(XP_MACOSX)
|
||||
class MacIOSurface;
|
||||
#endif
|
||||
|
||||
namespace mozilla {
|
||||
namespace gfx {
|
||||
|
||||
class VRSession
|
||||
{
|
||||
public:
|
||||
VRSession();
|
||||
virtual ~VRSession();
|
||||
|
||||
virtual bool Initialize(mozilla::gfx::VRSystemState& aSystemState) = 0;
|
||||
virtual void Shutdown() = 0;
|
||||
virtual void ProcessEvents(mozilla::gfx::VRSystemState& aSystemState) = 0;
|
||||
virtual void StartFrame(mozilla::gfx::VRSystemState& aSystemState) = 0;
|
||||
virtual bool StartPresentation() = 0;
|
||||
virtual void StopPresentation() = 0;
|
||||
virtual void VibrateHaptic(uint32_t aControllerIdx, uint32_t aHapticIndex,
|
||||
float aIntensity, float aDuration) = 0;
|
||||
virtual void StopVibrateHaptic(uint32_t aControllerIdx) = 0;
|
||||
virtual void StopAllHaptics() = 0;
|
||||
bool SubmitFrame(const mozilla::gfx::VRLayer_Stereo_Immersive& aLayer);
|
||||
bool ShouldQuit() const;
|
||||
|
||||
protected:
|
||||
bool mShouldQuit;
|
||||
#if defined(XP_WIN)
|
||||
virtual bool SubmitFrame(const mozilla::gfx::VRLayer_Stereo_Immersive& aLayer,
|
||||
ID3D11Texture2D* aTexture) = 0;
|
||||
bool CreateD3DContext(RefPtr<ID3D11Device> aDevice);
|
||||
RefPtr<ID3D11Device1> mDevice;
|
||||
RefPtr<ID3D11DeviceContext1> mContext;
|
||||
ID3D11Device1* GetD3DDevice();
|
||||
ID3D11DeviceContext1* GetD3DDeviceContext();
|
||||
ID3DDeviceContextState* GetD3DDeviceContextState();
|
||||
RefPtr<ID3DDeviceContextState> mDeviceContextState;
|
||||
#elif defined(XP_MACOSX)
|
||||
virtual bool SubmitFrame(const mozilla::gfx::VRLayer_Stereo_Immersive& aLayer,
|
||||
const VRLayerTextureHandle& aTexture) = 0;
|
||||
#endif
|
||||
void UpdateTrigger(VRControllerState& aState, uint32_t aButtonIndex, float aValue, float aThreshold);
|
||||
};
|
||||
|
||||
} // namespace mozilla
|
||||
} // namespace gfx
|
||||
|
||||
#endif // GFX_VR_SERVICE_VRSESSION_H
|
||||
/* -*- 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
|
||||
* 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_SERVICE_VRSESSION_H
|
||||
#define GFX_VR_SERVICE_VRSESSION_H
|
||||
|
||||
#include "moz_external_vr.h"
|
||||
|
||||
#if defined(XP_WIN)
|
||||
#include <d3d11_1.h>
|
||||
#elif defined(XP_MACOSX)
|
||||
class MacIOSurface;
|
||||
#endif
|
||||
|
||||
namespace mozilla {
|
||||
namespace gfx {
|
||||
|
||||
class VRSession
|
||||
{
|
||||
public:
|
||||
VRSession();
|
||||
virtual ~VRSession() = default;
|
||||
|
||||
virtual bool Initialize(mozilla::gfx::VRSystemState& aSystemState) = 0;
|
||||
virtual void Shutdown() = 0;
|
||||
virtual void ProcessEvents(mozilla::gfx::VRSystemState& aSystemState) = 0;
|
||||
virtual void StartFrame(mozilla::gfx::VRSystemState& aSystemState) = 0;
|
||||
virtual bool StartPresentation() = 0;
|
||||
virtual void StopPresentation() = 0;
|
||||
virtual void VibrateHaptic(uint32_t aControllerIdx, uint32_t aHapticIndex,
|
||||
float aIntensity, float aDuration) = 0;
|
||||
virtual void StopVibrateHaptic(uint32_t aControllerIdx) = 0;
|
||||
virtual void StopAllHaptics() = 0;
|
||||
bool SubmitFrame(const mozilla::gfx::VRLayer_Stereo_Immersive& aLayer);
|
||||
bool ShouldQuit() const;
|
||||
|
||||
protected:
|
||||
bool mShouldQuit;
|
||||
#if defined(XP_WIN)
|
||||
virtual bool SubmitFrame(const mozilla::gfx::VRLayer_Stereo_Immersive& aLayer,
|
||||
ID3D11Texture2D* aTexture) = 0;
|
||||
bool CreateD3DContext(RefPtr<ID3D11Device> aDevice);
|
||||
RefPtr<ID3D11Device1> mDevice;
|
||||
RefPtr<ID3D11DeviceContext1> mContext;
|
||||
ID3D11Device1* GetD3DDevice();
|
||||
ID3D11DeviceContext1* GetD3DDeviceContext();
|
||||
ID3DDeviceContextState* GetD3DDeviceContextState();
|
||||
RefPtr<ID3DDeviceContextState> mDeviceContextState;
|
||||
#elif defined(XP_MACOSX)
|
||||
virtual bool SubmitFrame(const mozilla::gfx::VRLayer_Stereo_Immersive& aLayer,
|
||||
const VRLayerTextureHandle& aTexture) = 0;
|
||||
#endif
|
||||
void UpdateTrigger(VRControllerState& aState, uint32_t aButtonIndex, float aValue, float aThreshold);
|
||||
};
|
||||
|
||||
} // namespace mozilla
|
||||
} // namespace gfx
|
||||
|
||||
#endif // GFX_VR_SERVICE_VRSESSION_H
|
||||
|
|
|
@ -1,45 +1,45 @@
|
|||
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
|
||||
# vim: set filetype=python:
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# 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/.
|
||||
|
||||
# Build Oculus support on Windows only
|
||||
if CONFIG['OS_TARGET'] == 'WINNT':
|
||||
SOURCES += [
|
||||
'OculusSession.cpp',
|
||||
]
|
||||
|
||||
# Build OSVR on all platforms except Android
|
||||
if CONFIG['OS_TARGET'] != 'Android':
|
||||
UNIFIED_SOURCES += [
|
||||
'OSVRSession.cpp',
|
||||
'VRService.cpp',
|
||||
'VRSession.cpp',
|
||||
]
|
||||
include('/ipc/chromium/chromium-config.mozbuild')
|
||||
|
||||
# Build OpenVR on Windows, Linux, and macOS desktop targets
|
||||
if CONFIG['OS_TARGET'] in ('WINNT', 'Linux', 'Darwin'):
|
||||
DIRS += [
|
||||
'openvr',
|
||||
]
|
||||
LOCAL_INCLUDES += [
|
||||
'/dom/base',
|
||||
'/gfx/layers/d3d11'
|
||||
]
|
||||
|
||||
# OpenVRSession includes MacIOSurface.h which includes Mac headers
|
||||
# which define Size and Points types in the root namespace that
|
||||
# often conflict with our own types.
|
||||
SOURCES += [
|
||||
'OpenVRSession.cpp'
|
||||
]
|
||||
|
||||
FINAL_LIBRARY = 'xul'
|
||||
|
||||
# This is intended as a temporary hack to enable VS2015 builds.
|
||||
if CONFIG['CC_TYPE'] in ('msvc', 'clang-cl'):
|
||||
# ovr_capi_dynamic.h '<unnamed-tag>': Alignment specifier is less than
|
||||
# actual alignment (8), and will be ignored
|
||||
CXXFLAGS += ['-wd4359']
|
||||
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
|
||||
# vim: set filetype=python:
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# 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/.
|
||||
|
||||
# Build Oculus support on Windows only
|
||||
if CONFIG['OS_TARGET'] == 'WINNT':
|
||||
SOURCES += [
|
||||
'OculusSession.cpp',
|
||||
]
|
||||
|
||||
# Build OSVR on all platforms except Android
|
||||
if CONFIG['OS_TARGET'] != 'Android':
|
||||
UNIFIED_SOURCES += [
|
||||
'OSVRSession.cpp',
|
||||
'VRService.cpp',
|
||||
'VRSession.cpp',
|
||||
]
|
||||
include('/ipc/chromium/chromium-config.mozbuild')
|
||||
|
||||
# Build OpenVR on Windows, Linux, and macOS desktop targets
|
||||
if CONFIG['OS_TARGET'] in ('WINNT', 'Linux', 'Darwin'):
|
||||
DIRS += [
|
||||
'openvr',
|
||||
]
|
||||
LOCAL_INCLUDES += [
|
||||
'/dom/base',
|
||||
'/gfx/layers/d3d11'
|
||||
]
|
||||
|
||||
# OpenVRSession includes MacIOSurface.h which includes Mac headers
|
||||
# which define Size and Points types in the root namespace that
|
||||
# often conflict with our own types.
|
||||
SOURCES += [
|
||||
'OpenVRSession.cpp'
|
||||
]
|
||||
|
||||
FINAL_LIBRARY = 'xul'
|
||||
|
||||
# This is intended as a temporary hack to enable VS2015 builds.
|
||||
if CONFIG['CC_TYPE'] in ('msvc', 'clang-cl'):
|
||||
# ovr_capi_dynamic.h '<unnamed-tag>': Alignment specifier is less than
|
||||
# actual alignment (8), and will be ignored
|
||||
CXXFLAGS += ['-wd4359']
|
||||
|
|
Загрузка…
Ссылка в новой задаче