2015-04-01 23:02:20 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
* 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_OCULUS_H
|
|
|
|
#define GFX_VR_OCULUS_H
|
|
|
|
|
|
|
|
#include "nsTArray.h"
|
2015-10-18 08:24:48 +03:00
|
|
|
#include "mozilla/RefPtr.h"
|
2015-04-01 23:02:20 +03:00
|
|
|
|
|
|
|
#include "mozilla/gfx/2D.h"
|
|
|
|
#include "mozilla/EnumeratedArray.h"
|
|
|
|
|
|
|
|
#include "gfxVR.h"
|
2016-02-25 02:54:50 +03:00
|
|
|
#include "VRDisplayHost.h"
|
2015-04-01 23:02:20 +03:00
|
|
|
#include "ovr_capi_dynamic.h"
|
|
|
|
|
2016-02-25 02:54:50 +03:00
|
|
|
struct ID3D11Device;
|
|
|
|
|
2015-04-01 23:02:20 +03:00
|
|
|
namespace mozilla {
|
2016-02-25 02:54:50 +03:00
|
|
|
namespace layers {
|
|
|
|
class CompositingRenderTargetD3D11;
|
|
|
|
struct VertexShaderConstants;
|
|
|
|
struct PixelShaderConstants;
|
|
|
|
}
|
2015-04-01 23:02:20 +03:00
|
|
|
namespace gfx {
|
|
|
|
namespace impl {
|
|
|
|
|
2016-02-25 02:54:50 +03:00
|
|
|
class VRDisplayOculus : public VRDisplayHost
|
|
|
|
{
|
2015-04-01 23:02:20 +03:00
|
|
|
public:
|
2016-02-25 02:54:50 +03:00
|
|
|
virtual void NotifyVSync() override;
|
2016-02-16 23:53:33 +03:00
|
|
|
virtual VRHMDSensorState GetSensorState() override;
|
|
|
|
virtual VRHMDSensorState GetImmediateSensorState() override;
|
2015-04-01 23:02:20 +03:00
|
|
|
void ZeroSensor() override;
|
|
|
|
|
2016-02-25 02:54:50 +03:00
|
|
|
protected:
|
|
|
|
virtual void StartPresentation() override;
|
|
|
|
virtual void StopPresentation() override;
|
|
|
|
virtual void SubmitFrame(mozilla::layers::TextureSourceD3D11* aSource,
|
|
|
|
const IntSize& aSize,
|
|
|
|
const VRHMDSensorState& aSensorState,
|
|
|
|
const gfx::Rect& aLeftEyeRect,
|
|
|
|
const gfx::Rect& aRightEyeRect) override;
|
2015-04-01 23:02:20 +03:00
|
|
|
|
2016-02-25 02:54:50 +03:00
|
|
|
public:
|
|
|
|
explicit VRDisplayOculus(ovrSession aSession);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~VRDisplayOculus();
|
2015-04-01 23:02:20 +03:00
|
|
|
void Destroy();
|
|
|
|
|
2016-02-25 02:54:50 +03:00
|
|
|
bool RequireSession();
|
|
|
|
const ovrHmdDesc& GetHmdDesc();
|
2015-07-02 18:58:24 +03:00
|
|
|
|
2016-02-25 02:54:50 +03:00
|
|
|
already_AddRefed<layers::CompositingRenderTargetD3D11> GetNextRenderTarget();
|
2015-07-02 18:58:24 +03:00
|
|
|
|
2016-02-25 02:54:50 +03:00
|
|
|
VRHMDSensorState GetSensorState(double timeOffset);
|
2015-04-01 23:02:20 +03:00
|
|
|
|
2015-09-22 16:38:28 +03:00
|
|
|
ovrHmdDesc mDesc;
|
2016-02-25 02:54:50 +03:00
|
|
|
ovrSession mSession;
|
2015-04-01 23:02:20 +03:00
|
|
|
ovrFovPort mFOVPort[2];
|
2016-02-25 02:54:50 +03:00
|
|
|
ovrTextureSwapChain mTextureSet;
|
|
|
|
nsTArray<RefPtr<layers::CompositingRenderTargetD3D11>> mRenderTargets;
|
|
|
|
|
|
|
|
RefPtr<ID3D11Device> mDevice;
|
|
|
|
RefPtr<ID3D11DeviceContext> mContext;
|
|
|
|
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;
|
|
|
|
|
|
|
|
bool mIsPresenting;
|
|
|
|
|
|
|
|
bool UpdateConstantBuffers();
|
2016-02-16 23:53:33 +03:00
|
|
|
|
2016-02-25 02:54:50 +03:00
|
|
|
struct Vertex
|
|
|
|
{
|
|
|
|
float position[2];
|
|
|
|
};
|
2015-04-01 23:02:20 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace impl
|
|
|
|
|
2016-02-25 02:54:50 +03:00
|
|
|
class VRDisplayManagerOculus : public VRDisplayManager
|
2015-04-01 23:02:20 +03:00
|
|
|
{
|
|
|
|
public:
|
2016-02-25 02:54:50 +03:00
|
|
|
static already_AddRefed<VRDisplayManagerOculus> Create();
|
2015-04-01 23:02:20 +03:00
|
|
|
virtual bool Init() override;
|
|
|
|
virtual void Destroy() override;
|
2016-02-25 02:54:50 +03:00
|
|
|
virtual void GetHMDs(nsTArray<RefPtr<VRDisplayHost> >& aHMDResult) override;
|
2015-04-01 23:02:20 +03:00
|
|
|
protected:
|
2016-02-25 02:54:50 +03:00
|
|
|
VRDisplayManagerOculus()
|
2015-09-18 00:23:13 +03:00
|
|
|
: mOculusInitialized(false)
|
|
|
|
{ }
|
|
|
|
|
2016-02-25 02:54:50 +03:00
|
|
|
RefPtr<impl::VRDisplayOculus> mHMDInfo;
|
2015-04-01 23:02:20 +03:00
|
|
|
bool mOculusInitialized;
|
2015-09-18 00:23:13 +03:00
|
|
|
RefPtr<nsIThread> mOculusThread;
|
2015-04-01 23:02:20 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace gfx
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif /* GFX_VR_OCULUS_H */
|