author Ethan Glasser-Camp <>
Mon, 05 Sep 2016 13:18:25 -0400
changeset 313090 9377cc9dc164dcadcd76c881484617310a461161
parent 309340 7b1349cb7487ce1b03a6f91c016315f9e8fdd0ec
child 331041 8767eeeef633415566a46297863287b908c1aaa9
permissions -rw-r--r--
Bug 1300591 - Update Kinto.js to v4.0.4, r=MattN MozReview-Commit-ID: B5pB3AmjjAL

/* -*- 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 */


#include "nsTArray.h"
#include "mozilla/RefPtr.h"

#include "mozilla/gfx/2D.h"
#include "mozilla/EnumeratedArray.h"

#include "gfxVR.h"
#include "VRDisplayHost.h"
#include "ovr_capi_dynamic.h"

struct ID3D11Device;

namespace mozilla {
namespace layers {
class CompositingRenderTargetD3D11;
struct VertexShaderConstants;
struct PixelShaderConstants;
namespace gfx {
namespace impl {

class VRDisplayOculus : public VRDisplayHost
  virtual void NotifyVSync() override;
  virtual VRHMDSensorState GetSensorState() override;
  virtual VRHMDSensorState GetImmediateSensorState() override;
  void ZeroSensor() override;

  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;

  explicit VRDisplayOculus(ovrSession aSession);

  virtual ~VRDisplayOculus();
  void Destroy();

  bool RequireSession();
  const ovrHmdDesc& GetHmdDesc();

  already_AddRefed<layers::CompositingRenderTargetD3D11> GetNextRenderTarget();

  VRHMDSensorState GetSensorState(double timeOffset);

  ovrHmdDesc mDesc;
  ovrSession mSession;
  ovrFovPort mFOVPort[2];
  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();

  struct Vertex
    float position[2];

} // namespace impl

class VRDisplayManagerOculus : public VRDisplayManager
  static already_AddRefed<VRDisplayManagerOculus> Create();
  virtual bool Init() override;
  virtual void Destroy() override;
  virtual void GetHMDs(nsTArray<RefPtr<VRDisplayHost> >& aHMDResult) override;
    : mOculusInitialized(false)
  { }

  RefPtr<impl::VRDisplayOculus> mHMDInfo;
  bool mOculusInitialized;
  RefPtr<nsIThread> mOculusThread;

} // namespace gfx
} // namespace mozilla

#endif /* GFX_VR_OCULUS_H */