mirror of
https://github.com/roytam1/UXP.git
synced 2026-05-26 14:54:25 +00:00
@@ -145,7 +145,6 @@
|
||||
#include "mozilla/dom/KeyframeEffectBinding.h"
|
||||
#include "mozilla/dom/WindowBinding.h"
|
||||
#include "mozilla/dom/ElementBinding.h"
|
||||
#include "mozilla/dom/VRDisplay.h"
|
||||
#include "mozilla/IntegerPrintfMacros.h"
|
||||
#include "mozilla/Preferences.h"
|
||||
#include "nsComputedDOMStyle.h"
|
||||
|
||||
@@ -44,7 +44,6 @@
|
||||
#include "mozilla/dom/ServiceWorkerContainer.h"
|
||||
#include "mozilla/dom/StorageManager.h"
|
||||
#include "mozilla/dom/TCPSocket.h"
|
||||
#include "mozilla/dom/VRDisplay.h"
|
||||
#include "mozilla/dom/workers/RuntimeService.h"
|
||||
#include "mozilla/Hal.h"
|
||||
#include "nsISiteSpecificUserAgent.h"
|
||||
@@ -1471,83 +1470,6 @@ Navigator::RequestGamepadServiceTest()
|
||||
}
|
||||
#endif
|
||||
|
||||
already_AddRefed<Promise>
|
||||
Navigator::GetVRDisplays(ErrorResult& aRv)
|
||||
{
|
||||
if (!mWindow || !mWindow->GetDocShell()) {
|
||||
aRv.Throw(NS_ERROR_UNEXPECTED);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
nsGlobalWindow* win = nsGlobalWindow::Cast(mWindow);
|
||||
win->NotifyVREventListenerAdded();
|
||||
|
||||
nsCOMPtr<nsIGlobalObject> go = do_QueryInterface(mWindow);
|
||||
RefPtr<Promise> p = Promise::Create(go, aRv);
|
||||
if (aRv.Failed()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// We pass mWindow's id to RefreshVRDisplays, so NotifyVRDisplaysUpdated will
|
||||
// be called asynchronously, resolving the promises in mVRGetDisplaysPromises.
|
||||
if (!VRDisplay::RefreshVRDisplays(win->WindowID())) {
|
||||
p->MaybeReject(NS_ERROR_FAILURE);
|
||||
return p.forget();
|
||||
}
|
||||
|
||||
mVRGetDisplaysPromises.AppendElement(p);
|
||||
return p.forget();
|
||||
}
|
||||
|
||||
void
|
||||
Navigator::GetActiveVRDisplays(nsTArray<RefPtr<VRDisplay>>& aDisplays) const
|
||||
{
|
||||
/**
|
||||
* Get only the active VR displays.
|
||||
* Callers do not wish to VRDisplay::RefreshVRDisplays, as the enumeration may
|
||||
* activate hardware that is not yet intended to be used.
|
||||
*/
|
||||
if (!mWindow || !mWindow->GetDocShell()) {
|
||||
return;
|
||||
}
|
||||
nsGlobalWindow* win = nsGlobalWindow::Cast(mWindow);
|
||||
win->NotifyVREventListenerAdded();
|
||||
nsTArray<RefPtr<VRDisplay>> displays;
|
||||
if (win->UpdateVRDisplays(displays)) {
|
||||
for (auto display : displays) {
|
||||
if (display->IsPresenting()) {
|
||||
aDisplays.AppendElement(display);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Navigator::NotifyVRDisplaysUpdated()
|
||||
{
|
||||
// Synchronize the VR devices and resolve the promises in
|
||||
// mVRGetDisplaysPromises
|
||||
nsGlobalWindow* win = nsGlobalWindow::Cast(mWindow);
|
||||
|
||||
nsTArray<RefPtr<VRDisplay>> vrDisplays;
|
||||
if (win->UpdateVRDisplays(vrDisplays)) {
|
||||
for (auto p : mVRGetDisplaysPromises) {
|
||||
p->MaybeResolve(vrDisplays);
|
||||
}
|
||||
} else {
|
||||
for (auto p : mVRGetDisplaysPromises) {
|
||||
p->MaybeReject(NS_ERROR_FAILURE);
|
||||
}
|
||||
}
|
||||
mVRGetDisplaysPromises.Clear();
|
||||
}
|
||||
|
||||
void
|
||||
Navigator::NotifyActiveVRDisplaysChanged()
|
||||
{
|
||||
NavigatorBinding::ClearCachedActiveVRDisplaysValue(this);
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
// Navigator::nsIMozNavigatorNetwork
|
||||
//*****************************************************************************
|
||||
|
||||
@@ -76,7 +76,6 @@ class Connection;
|
||||
class PowerManager;
|
||||
class Presentation;
|
||||
class LegacyMozTCPSocket;
|
||||
class VRDisplay;
|
||||
class StorageManager;
|
||||
|
||||
namespace time {
|
||||
@@ -204,8 +203,6 @@ public:
|
||||
void GetGamepads(nsTArray<RefPtr<Gamepad> >& aGamepads, ErrorResult& aRv);
|
||||
GamepadServiceTest* RequestGamepadServiceTest();
|
||||
#endif // MOZ_GAMEPAD
|
||||
already_AddRefed<Promise> GetVRDisplays(ErrorResult& aRv);
|
||||
void GetActiveVRDisplays(nsTArray<RefPtr<VRDisplay>>& aDisplays) const;
|
||||
#ifdef MOZ_TIME_MANAGER
|
||||
time::TimeManager* GetMozTime(ErrorResult& aRv);
|
||||
#endif // MOZ_TIME_MANAGER
|
||||
@@ -269,10 +266,6 @@ private:
|
||||
RefPtr<MediaKeySystemAccessManager> mMediaKeySystemAccessManager;
|
||||
#endif
|
||||
|
||||
public:
|
||||
void NotifyVRDisplaysUpdated();
|
||||
void NotifyActiveVRDisplaysChanged();
|
||||
|
||||
private:
|
||||
virtual ~Navigator();
|
||||
|
||||
|
||||
@@ -202,9 +202,6 @@
|
||||
#include "mozilla/dom/GamepadManager.h"
|
||||
#endif
|
||||
|
||||
#include "mozilla/dom/VRDisplay.h"
|
||||
#include "mozilla/dom/VREventObserver.h"
|
||||
|
||||
#include "nsRefreshDriver.h"
|
||||
#include "Layers.h"
|
||||
|
||||
@@ -1532,7 +1529,6 @@ nsGlobalWindow::nsGlobalWindow(nsGlobalWindow *aOuterWindow)
|
||||
mShowFocusRingForContent(false),
|
||||
mFocusByKeyOccurred(false),
|
||||
mHasGamepad(false),
|
||||
mHasVREvents(false),
|
||||
#ifdef MOZ_GAMEPAD
|
||||
mHasSeenGamepadInput(false),
|
||||
#endif
|
||||
@@ -1967,12 +1963,9 @@ nsGlobalWindow::CleanUp()
|
||||
if (IsInnerWindow()) {
|
||||
DisableGamepadUpdates();
|
||||
mHasGamepad = false;
|
||||
DisableVRUpdates();
|
||||
mHasVREvents = false;
|
||||
DisableIdleCallbackRequests();
|
||||
} else {
|
||||
MOZ_ASSERT(!mHasGamepad);
|
||||
MOZ_ASSERT(!mHasVREvents);
|
||||
}
|
||||
|
||||
if (mCleanMessageManager) {
|
||||
@@ -2118,9 +2111,6 @@ nsGlobalWindow::FreeInnerObjects(bool aForDocumentOpen)
|
||||
mHasGamepad = false;
|
||||
mGamepads.Clear();
|
||||
#endif
|
||||
DisableVRUpdates();
|
||||
mHasVREvents = false;
|
||||
mVRDisplays.Clear();
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
@@ -2275,7 +2265,6 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(nsGlobalWindow)
|
||||
#endif
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mCacheStorage)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mVRDisplays)
|
||||
|
||||
// Traverse stuff from nsPIDOMWindow
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mChromeEventHandler)
|
||||
@@ -2352,7 +2341,6 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsGlobalWindow)
|
||||
#endif
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mCacheStorage)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mVRDisplays)
|
||||
|
||||
// Unlink stuff from nsPIDOMWindow
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mChromeEventHandler)
|
||||
@@ -10507,24 +10495,6 @@ nsGlobalWindow::DisableGamepadUpdates()
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
nsGlobalWindow::EnableVRUpdates()
|
||||
{
|
||||
MOZ_ASSERT(IsInnerWindow());
|
||||
|
||||
if (mHasVREvents && !mVREventObserver) {
|
||||
mVREventObserver = new VREventObserver(this);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
nsGlobalWindow::DisableVRUpdates()
|
||||
{
|
||||
MOZ_ASSERT(IsInnerWindow());
|
||||
|
||||
mVREventObserver = nullptr;
|
||||
}
|
||||
|
||||
void
|
||||
nsGlobalWindow::SetChromeEventHandler(EventTarget* aChromeEventHandler)
|
||||
{
|
||||
@@ -12210,7 +12180,6 @@ nsGlobalWindow::Suspend()
|
||||
ac->RemoveWindowListener(mEnabledSensors[i], this);
|
||||
}
|
||||
DisableGamepadUpdates();
|
||||
DisableVRUpdates();
|
||||
|
||||
mozilla::dom::workers::SuspendWorkersForWindow(AsInner());
|
||||
|
||||
@@ -12274,7 +12243,6 @@ nsGlobalWindow::Resume()
|
||||
ac->AddWindowListener(mEnabledSensors[i], this);
|
||||
}
|
||||
EnableGamepadUpdates();
|
||||
EnableVRUpdates();
|
||||
|
||||
// Resume all of the AudioContexts for this window
|
||||
for (uint32_t i = 0; i < mAudioContexts.Length(); ++i) {
|
||||
@@ -14030,19 +13998,6 @@ nsGlobalWindow::SetHasGamepadEventListener(bool aHasGamepad/* = true*/)
|
||||
void
|
||||
nsGlobalWindow::EventListenerAdded(nsIAtom* aType)
|
||||
{
|
||||
if (aType == nsGkAtoms::onvrdisplayconnect ||
|
||||
aType == nsGkAtoms::onvrdisplaydisconnect ||
|
||||
aType == nsGkAtoms::onvrdisplaypresentchange) {
|
||||
NotifyVREventListenerAdded();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
nsGlobalWindow::NotifyVREventListenerAdded()
|
||||
{
|
||||
MOZ_ASSERT(IsInnerWindow());
|
||||
mHasVREvents = true;
|
||||
EnableVRUpdates();
|
||||
}
|
||||
|
||||
void
|
||||
@@ -14187,27 +14142,6 @@ nsGlobalWindow::SyncGamepadState()
|
||||
}
|
||||
#endif // MOZ_GAMEPAD
|
||||
|
||||
bool
|
||||
nsGlobalWindow::UpdateVRDisplays(nsTArray<RefPtr<mozilla::dom::VRDisplay>>& aDevices)
|
||||
{
|
||||
FORWARD_TO_INNER(UpdateVRDisplays, (aDevices), false);
|
||||
|
||||
VRDisplay::UpdateVRDisplays(mVRDisplays, AsInner());
|
||||
aDevices = mVRDisplays;
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
nsGlobalWindow::NotifyActiveVRDisplaysChanged()
|
||||
{
|
||||
MOZ_ASSERT(IsInnerWindow());
|
||||
|
||||
if (mNavigator) {
|
||||
mNavigator->NotifyActiveVRDisplaysChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// nsGlobalChromeWindow implementation
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_CLASS(nsGlobalChromeWindow)
|
||||
|
||||
@@ -135,8 +135,6 @@ class SpeechSynthesis;
|
||||
class TabGroup;
|
||||
class Timeout;
|
||||
class U2F;
|
||||
class VRDisplay;
|
||||
class VREventObserver;
|
||||
class WakeLock;
|
||||
#if defined(MOZ_WIDGET_ANDROID)
|
||||
class WindowOrientationObserver;
|
||||
@@ -745,18 +743,6 @@ public:
|
||||
void EnableGamepadUpdates();
|
||||
void DisableGamepadUpdates();
|
||||
|
||||
// Inner windows only.
|
||||
// Enable/disable updates for VR
|
||||
void EnableVRUpdates();
|
||||
void DisableVRUpdates();
|
||||
|
||||
// Update the VR displays for this window
|
||||
bool UpdateVRDisplays(nsTArray<RefPtr<mozilla::dom::VRDisplay>>& aDisplays);
|
||||
|
||||
// Inner windows only.
|
||||
// Called to inform that the set of active VR displays has changed.
|
||||
void NotifyActiveVRDisplaysChanged();
|
||||
|
||||
#define EVENT(name_, id_, type_, struct_) \
|
||||
mozilla::dom::EventHandlerNonNull* GetOn##name_() \
|
||||
{ \
|
||||
@@ -1832,9 +1818,6 @@ protected:
|
||||
// Indicates whether this window wants gamepad input events
|
||||
bool mHasGamepad : 1;
|
||||
|
||||
// Inner windows only.
|
||||
// Indicates whether this window wants VR events
|
||||
bool mHasVREvents : 1;
|
||||
#ifdef MOZ_GAMEPAD
|
||||
nsCheapSet<nsUint32HashKey> mGamepadIndexSet;
|
||||
nsRefPtrHashtable<nsUint32HashKey, mozilla::dom::Gamepad> mGamepads;
|
||||
@@ -1989,11 +1972,6 @@ protected:
|
||||
// This is the CC generation the last time we called CanSkip.
|
||||
uint32_t mCanSkipCCGeneration;
|
||||
|
||||
// The VR Displays for this window
|
||||
nsTArray<RefPtr<mozilla::dom::VRDisplay>> mVRDisplays;
|
||||
|
||||
nsAutoPtr<mozilla::dom::VREventObserver> mVREventObserver;
|
||||
|
||||
friend class nsDOMScriptableHelper;
|
||||
friend class nsDOMWindowUtils;
|
||||
friend class mozilla::dom::PostMessageEvent;
|
||||
|
||||
@@ -47,7 +47,6 @@
|
||||
#include "nsSVGEffects.h"
|
||||
#include "prenv.h"
|
||||
#include "ScopedGLHelpers.h"
|
||||
#include "VRManagerChild.h"
|
||||
#include "mozilla/layers/TextureClientSharedSurface.h"
|
||||
|
||||
// Local
|
||||
@@ -2239,84 +2238,6 @@ WebGLContext::GetUnpackSize(bool isFunc3D, uint32_t width, uint32_t height,
|
||||
return totalBytes;
|
||||
}
|
||||
|
||||
already_AddRefed<layers::SharedSurfaceTextureClient>
|
||||
WebGLContext::GetVRFrame()
|
||||
{
|
||||
if (!mLayerIsMirror) {
|
||||
/**
|
||||
* Do not allow VR frame submission until a mirroring canvas layer has
|
||||
* been returned by GetCanvasLayer
|
||||
*/
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
VRManagerChild* vrmc = VRManagerChild::Get();
|
||||
if (!vrmc) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Swap buffers as though composition has occurred.
|
||||
* We will then share the resulting front buffer to be submitted to the VR
|
||||
* compositor.
|
||||
*/
|
||||
BeginComposition();
|
||||
EndComposition();
|
||||
|
||||
gl::GLScreenBuffer* screen = gl->Screen();
|
||||
if (!screen) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
RefPtr<SharedSurfaceTextureClient> sharedSurface = screen->Front();
|
||||
if (!sharedSurface) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (sharedSurface && sharedSurface->GetAllocator() != vrmc) {
|
||||
RefPtr<SharedSurfaceTextureClient> dest =
|
||||
screen->Factory()->NewTexClient(sharedSurface->GetSize());
|
||||
if (!dest) {
|
||||
return nullptr;
|
||||
}
|
||||
gl::SharedSurface* destSurf = dest->Surf();
|
||||
destSurf->ProducerAcquire();
|
||||
SharedSurface::ProdCopy(sharedSurface->Surf(), dest->Surf(),
|
||||
screen->Factory());
|
||||
destSurf->ProducerRelease();
|
||||
|
||||
return dest.forget();
|
||||
}
|
||||
|
||||
return sharedSurface.forget();
|
||||
}
|
||||
|
||||
bool
|
||||
WebGLContext::StartVRPresentation()
|
||||
{
|
||||
VRManagerChild* vrmc = VRManagerChild::Get();
|
||||
if (!vrmc) {
|
||||
return false;
|
||||
}
|
||||
gl::GLScreenBuffer* screen = gl->Screen();
|
||||
if (!screen) {
|
||||
return false;
|
||||
}
|
||||
gl::SurfaceCaps caps = screen->mCaps;
|
||||
|
||||
UniquePtr<gl::SurfaceFactory> factory =
|
||||
gl::GLScreenBuffer::CreateFactory(gl,
|
||||
caps,
|
||||
vrmc,
|
||||
vrmc->GetBackendType(),
|
||||
TextureFlags::ORIGIN_BOTTOM_LEFT);
|
||||
|
||||
if (factory) {
|
||||
screen->Morph(Move(factory));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static inline size_t
|
||||
|
||||
@@ -656,9 +656,6 @@ public:
|
||||
void PixelStorei(GLenum pname, GLint param);
|
||||
void PolygonOffset(GLfloat factor, GLfloat units);
|
||||
|
||||
already_AddRefed<layers::SharedSurfaceTextureClient> GetVRFrame();
|
||||
bool StartVRPresentation();
|
||||
|
||||
////
|
||||
|
||||
webgl::PackingInfo
|
||||
|
||||
@@ -42,7 +42,6 @@
|
||||
#include "nsRefreshDriver.h"
|
||||
#include "nsStreamUtils.h"
|
||||
#include "ActiveLayerTracker.h"
|
||||
#include "VRManagerChild.h"
|
||||
#include "WebGL1Context.h"
|
||||
#include "WebGL2Context.h"
|
||||
|
||||
@@ -358,7 +357,6 @@ NS_IMPL_ISUPPORTS(HTMLCanvasElementObserver, nsIObserver)
|
||||
HTMLCanvasElement::HTMLCanvasElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
|
||||
: nsGenericHTMLElement(aNodeInfo),
|
||||
mResetLayer(true) ,
|
||||
mVRPresentationActive(false),
|
||||
mWriteOnly(false)
|
||||
{}
|
||||
|
||||
@@ -1111,7 +1109,7 @@ HTMLCanvasElement::GetCanvasLayer(nsDisplayListBuilder* aBuilder,
|
||||
static uint8_t sOffscreenCanvasLayerUserDataDummy = 0;
|
||||
|
||||
if (mCurrentContext) {
|
||||
return mCurrentContext->GetCanvasLayer(aBuilder, aOldLayer, aManager, mVRPresentationActive);
|
||||
return mCurrentContext->GetCanvasLayer(aBuilder, aOldLayer, aManager);
|
||||
}
|
||||
|
||||
if (mOffscreenCanvas) {
|
||||
@@ -1441,42 +1439,5 @@ HTMLCanvasElement::InvalidateFromAsyncCanvasRenderer(AsyncCanvasRenderer *aRende
|
||||
element->InvalidateCanvasContent(nullptr);
|
||||
}
|
||||
|
||||
void
|
||||
HTMLCanvasElement::StartVRPresentation()
|
||||
{
|
||||
WebGLContext* webgl = static_cast<WebGLContext*>(GetContextAtIndex(0));
|
||||
if (!webgl) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!webgl->StartVRPresentation()) {
|
||||
return;
|
||||
}
|
||||
|
||||
mVRPresentationActive = true;
|
||||
}
|
||||
|
||||
void
|
||||
HTMLCanvasElement::StopVRPresentation()
|
||||
{
|
||||
mVRPresentationActive = false;
|
||||
}
|
||||
|
||||
already_AddRefed<layers::SharedSurfaceTextureClient>
|
||||
HTMLCanvasElement::GetVRFrame()
|
||||
{
|
||||
if (GetCurrentContextType() != CanvasContextType::WebGL1 &&
|
||||
GetCurrentContextType() != CanvasContextType::WebGL2) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
WebGLContext* webgl = static_cast<WebGLContext*>(GetContextAtIndex(0));
|
||||
if (!webgl) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return webgl->GetVRFrame();
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
@@ -350,10 +350,6 @@ public:
|
||||
static void SetAttrFromAsyncCanvasRenderer(AsyncCanvasRenderer *aRenderer);
|
||||
static void InvalidateFromAsyncCanvasRenderer(AsyncCanvasRenderer *aRenderer);
|
||||
|
||||
void StartVRPresentation();
|
||||
void StopVRPresentation();
|
||||
already_AddRefed<layers::SharedSurfaceTextureClient> GetVRFrame();
|
||||
|
||||
protected:
|
||||
virtual ~HTMLCanvasElement();
|
||||
|
||||
|
||||
@@ -171,7 +171,6 @@
|
||||
#include "GMPServiceChild.h"
|
||||
#include "gfxPlatform.h"
|
||||
#include "nscore.h" // for NS_FREE_PERMANENT_DATA
|
||||
#include "VRManagerChild.h"
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::docshell;
|
||||
@@ -1148,7 +1147,6 @@ ContentChild::RecvGMPsChanged(nsTArray<GMPCapabilityData>&& capabilities)
|
||||
bool
|
||||
ContentChild::RecvInitRendering(Endpoint<PCompositorBridgeChild>&& aCompositor,
|
||||
Endpoint<PImageBridgeChild>&& aImageBridge,
|
||||
Endpoint<PVRManagerChild>&& aVRBridge,
|
||||
Endpoint<PVideoDecoderManagerChild>&& aVideoManager)
|
||||
{
|
||||
if (!CompositorBridgeChild::InitForContent(Move(aCompositor))) {
|
||||
@@ -1157,9 +1155,6 @@ ContentChild::RecvInitRendering(Endpoint<PCompositorBridgeChild>&& aCompositor,
|
||||
if (!ImageBridgeChild::InitForContent(Move(aImageBridge))) {
|
||||
return false;
|
||||
}
|
||||
if (!gfx::VRManagerChild::InitForContent(Move(aVRBridge))) {
|
||||
return false;
|
||||
}
|
||||
VideoDecoderManagerChild::InitForContent(Move(aVideoManager));
|
||||
return true;
|
||||
}
|
||||
@@ -1167,7 +1162,6 @@ ContentChild::RecvInitRendering(Endpoint<PCompositorBridgeChild>&& aCompositor,
|
||||
bool
|
||||
ContentChild::RecvReinitRendering(Endpoint<PCompositorBridgeChild>&& aCompositor,
|
||||
Endpoint<PImageBridgeChild>&& aImageBridge,
|
||||
Endpoint<PVRManagerChild>&& aVRBridge,
|
||||
Endpoint<PVideoDecoderManagerChild>&& aVideoManager)
|
||||
{
|
||||
nsTArray<RefPtr<TabChild>> tabs = TabChild::GetAll();
|
||||
@@ -1186,9 +1180,6 @@ ContentChild::RecvReinitRendering(Endpoint<PCompositorBridgeChild>&& aCompositor
|
||||
if (!ImageBridgeChild::ReinitForContent(Move(aImageBridge))) {
|
||||
return false;
|
||||
}
|
||||
if (!gfx::VRManagerChild::ReinitForContent(Move(aVRBridge))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Establish new PLayerTransactions.
|
||||
for (const auto& tabChild : tabs) {
|
||||
|
||||
@@ -152,15 +152,13 @@ public:
|
||||
RecvInitRendering(
|
||||
Endpoint<PCompositorBridgeChild>&& aCompositor,
|
||||
Endpoint<PImageBridgeChild>&& aImageBridge,
|
||||
Endpoint<PVRManagerChild>&& aVRBridge,
|
||||
Endpoint<PVideoDecoderManagerChild>&& aVideoManager) override;
|
||||
Endpoint<PVideoDecoderManagerChild>&& aVideoManager);
|
||||
|
||||
bool
|
||||
RecvReinitRendering(
|
||||
Endpoint<PCompositorBridgeChild>&& aCompositor,
|
||||
Endpoint<PImageBridgeChild>&& aImageBridge,
|
||||
Endpoint<PVRManagerChild>&& aVRBridge,
|
||||
Endpoint<PVideoDecoderManagerChild>&& aVideoManager) override;
|
||||
Endpoint<PVideoDecoderManagerChild>&& aVideoManager);
|
||||
|
||||
PProcessHangMonitorChild*
|
||||
AllocPProcessHangMonitorChild(Transport* aTransport,
|
||||
|
||||
@@ -2073,21 +2073,18 @@ ContentParent::InitInternal(ProcessPriority aInitialPriority,
|
||||
|
||||
Endpoint<PCompositorBridgeChild> compositor;
|
||||
Endpoint<PImageBridgeChild> imageBridge;
|
||||
Endpoint<PVRManagerChild> vrBridge;
|
||||
Endpoint<PVideoDecoderManagerChild> videoManager;
|
||||
|
||||
DebugOnly<bool> opened = gpm->CreateContentBridges(
|
||||
OtherPid(),
|
||||
&compositor,
|
||||
&imageBridge,
|
||||
&vrBridge,
|
||||
&videoManager);
|
||||
MOZ_ASSERT(opened);
|
||||
|
||||
Unused << SendInitRendering(
|
||||
Move(compositor),
|
||||
Move(imageBridge),
|
||||
Move(vrBridge),
|
||||
Move(videoManager));
|
||||
|
||||
gpm->AddListener(this);
|
||||
@@ -2201,21 +2198,18 @@ ContentParent::OnCompositorUnexpectedShutdown()
|
||||
|
||||
Endpoint<PCompositorBridgeChild> compositor;
|
||||
Endpoint<PImageBridgeChild> imageBridge;
|
||||
Endpoint<PVRManagerChild> vrBridge;
|
||||
Endpoint<PVideoDecoderManagerChild> videoManager;
|
||||
|
||||
DebugOnly<bool> opened = gpm->CreateContentBridges(
|
||||
OtherPid(),
|
||||
&compositor,
|
||||
&imageBridge,
|
||||
&vrBridge,
|
||||
&videoManager);
|
||||
MOZ_ASSERT(opened);
|
||||
|
||||
Unused << SendReinitRendering(
|
||||
Move(compositor),
|
||||
Move(imageBridge),
|
||||
Move(vrBridge),
|
||||
Move(videoManager));
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,6 @@ include protocol PRemoteSpellcheckEngine;
|
||||
include protocol PWebBrowserPersistDocument;
|
||||
include protocol PWebrtcGlobal;
|
||||
include protocol PPresentation;
|
||||
include protocol PVRManager;
|
||||
include protocol PVideoDecoderManager;
|
||||
include protocol PFlyWebPublishedServer;
|
||||
include DOMTypes;
|
||||
@@ -311,7 +310,6 @@ child:
|
||||
async InitRendering(
|
||||
Endpoint<PCompositorBridgeChild> compositor,
|
||||
Endpoint<PImageBridgeChild> imageBridge,
|
||||
Endpoint<PVRManagerChild> vr,
|
||||
Endpoint<PVideoDecoderManagerChild> video);
|
||||
|
||||
// Re-create the rendering stack using the given endpoints. This is sent
|
||||
@@ -320,7 +318,6 @@ child:
|
||||
async ReinitRendering(
|
||||
Endpoint<PCompositorBridgeChild> compositor,
|
||||
Endpoint<PImageBridgeChild> bridge,
|
||||
Endpoint<PVRManagerChild> vr,
|
||||
Endpoint<PVideoDecoderManagerChild> video);
|
||||
|
||||
/**
|
||||
|
||||
@@ -107,7 +107,6 @@
|
||||
#include "nsDeviceContext.h"
|
||||
#include "nsSandboxFlags.h"
|
||||
#include "FrameLayerBuilder.h"
|
||||
#include "VRManagerChild.h"
|
||||
#include "nsICommandParams.h"
|
||||
#include "nsISHistory.h"
|
||||
#include "nsQueryObject.h"
|
||||
@@ -2565,7 +2564,6 @@ TabChild::InitRenderingState(const TextureFactoryIdentifier& aTextureFactoryIden
|
||||
lf->SetShadowManager(shadowManager);
|
||||
lf->IdentifyTextureHost(mTextureFactoryIdentifier);
|
||||
ImageBridgeChild::IdentifyCompositorTextureHost(mTextureFactoryIdentifier);
|
||||
gfx::VRManagerChild::IdentifyTextureHost(mTextureFactoryIdentifier);
|
||||
}
|
||||
|
||||
mRemoteFrame = remoteFrame;
|
||||
|
||||
@@ -94,7 +94,6 @@ DIRS += [
|
||||
'xslt',
|
||||
'xul',
|
||||
'manifest',
|
||||
'vr',
|
||||
'u2f',
|
||||
'console',
|
||||
'performance',
|
||||
|
||||
@@ -1,802 +0,0 @@
|
||||
/* -*- 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/. */
|
||||
|
||||
#include "nsWrapperCache.h"
|
||||
|
||||
#include "mozilla/dom/Element.h"
|
||||
#include "mozilla/dom/ElementBinding.h"
|
||||
#include "mozilla/dom/Promise.h"
|
||||
#include "mozilla/dom/VRDisplay.h"
|
||||
#include "mozilla/HoldDropJSObjects.h"
|
||||
#include "mozilla/dom/VRDisplayBinding.h"
|
||||
#include "Navigator.h"
|
||||
#include "gfxVR.h"
|
||||
#include "VRDisplayClient.h"
|
||||
#include "VRManagerChild.h"
|
||||
#include "VRDisplayPresentation.h"
|
||||
#include "nsIObserverService.h"
|
||||
#include "nsIFrame.h"
|
||||
#include "nsISupportsPrimitives.h"
|
||||
|
||||
using namespace mozilla::gfx;
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
VRFieldOfView::VRFieldOfView(nsISupports* aParent,
|
||||
double aUpDegrees, double aRightDegrees,
|
||||
double aDownDegrees, double aLeftDegrees)
|
||||
: mParent(aParent)
|
||||
, mUpDegrees(aUpDegrees)
|
||||
, mRightDegrees(aRightDegrees)
|
||||
, mDownDegrees(aDownDegrees)
|
||||
, mLeftDegrees(aLeftDegrees)
|
||||
{
|
||||
}
|
||||
|
||||
VRFieldOfView::VRFieldOfView(nsISupports* aParent, const gfx::VRFieldOfView& aSrc)
|
||||
: mParent(aParent)
|
||||
, mUpDegrees(aSrc.upDegrees)
|
||||
, mRightDegrees(aSrc.rightDegrees)
|
||||
, mDownDegrees(aSrc.downDegrees)
|
||||
, mLeftDegrees(aSrc.leftDegrees)
|
||||
{
|
||||
}
|
||||
|
||||
bool
|
||||
VRDisplayCapabilities::HasPosition() const
|
||||
{
|
||||
return bool(mFlags & gfx::VRDisplayCapabilityFlags::Cap_Position);
|
||||
}
|
||||
|
||||
bool
|
||||
VRDisplayCapabilities::HasOrientation() const
|
||||
{
|
||||
return bool(mFlags & gfx::VRDisplayCapabilityFlags::Cap_Orientation);
|
||||
}
|
||||
|
||||
bool
|
||||
VRDisplayCapabilities::HasExternalDisplay() const
|
||||
{
|
||||
return bool(mFlags & gfx::VRDisplayCapabilityFlags::Cap_External);
|
||||
}
|
||||
|
||||
bool
|
||||
VRDisplayCapabilities::CanPresent() const
|
||||
{
|
||||
return bool(mFlags & gfx::VRDisplayCapabilityFlags::Cap_Present);
|
||||
}
|
||||
|
||||
uint32_t
|
||||
VRDisplayCapabilities::MaxLayers() const
|
||||
{
|
||||
return CanPresent() ? 1 : 0;
|
||||
}
|
||||
|
||||
/*static*/ bool
|
||||
VRDisplay::RefreshVRDisplays(uint64_t aWindowId)
|
||||
{
|
||||
gfx::VRManagerChild* vm = gfx::VRManagerChild::Get();
|
||||
return vm && vm->RefreshVRDisplaysWithCallback(aWindowId);
|
||||
}
|
||||
|
||||
/*static*/ void
|
||||
VRDisplay::UpdateVRDisplays(nsTArray<RefPtr<VRDisplay>>& aDisplays, nsPIDOMWindowInner* aWindow)
|
||||
{
|
||||
nsTArray<RefPtr<VRDisplay>> displays;
|
||||
|
||||
gfx::VRManagerChild* vm = gfx::VRManagerChild::Get();
|
||||
nsTArray<RefPtr<gfx::VRDisplayClient>> updatedDisplays;
|
||||
if (vm && vm->GetVRDisplays(updatedDisplays)) {
|
||||
for (size_t i = 0; i < updatedDisplays.Length(); i++) {
|
||||
RefPtr<gfx::VRDisplayClient> display = updatedDisplays[i];
|
||||
bool isNewDisplay = true;
|
||||
for (size_t j = 0; j < aDisplays.Length(); j++) {
|
||||
if (aDisplays[j]->GetClient()->GetDisplayInfo() == display->GetDisplayInfo()) {
|
||||
displays.AppendElement(aDisplays[j]);
|
||||
isNewDisplay = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (isNewDisplay) {
|
||||
displays.AppendElement(new VRDisplay(aWindow, display));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
aDisplays = displays;
|
||||
}
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(VRFieldOfView, mParent)
|
||||
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(VRFieldOfView, AddRef)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(VRFieldOfView, Release)
|
||||
|
||||
|
||||
JSObject*
|
||||
VRFieldOfView::WrapObject(JSContext* aCx,
|
||||
JS::Handle<JSObject*> aGivenProto)
|
||||
{
|
||||
return VRFieldOfViewBinding::Wrap(aCx, this, aGivenProto);
|
||||
}
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_CLASS(VREyeParameters)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(VREyeParameters)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mParent, mFOV)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
|
||||
tmp->mOffset = nullptr;
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(VREyeParameters)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mParent, mFOV)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(VREyeParameters)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER
|
||||
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mOffset)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(VREyeParameters, AddRef)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(VREyeParameters, Release)
|
||||
|
||||
VREyeParameters::VREyeParameters(nsISupports* aParent,
|
||||
const gfx::Point3D& aEyeTranslation,
|
||||
const gfx::VRFieldOfView& aFOV,
|
||||
const gfx::IntSize& aRenderSize)
|
||||
: mParent(aParent)
|
||||
, mEyeTranslation(aEyeTranslation)
|
||||
, mRenderSize(aRenderSize)
|
||||
{
|
||||
mFOV = new VRFieldOfView(aParent, aFOV);
|
||||
mozilla::HoldJSObjects(this);
|
||||
}
|
||||
|
||||
VREyeParameters::~VREyeParameters()
|
||||
{
|
||||
mozilla::DropJSObjects(this);
|
||||
}
|
||||
|
||||
VRFieldOfView*
|
||||
VREyeParameters::FieldOfView()
|
||||
{
|
||||
return mFOV;
|
||||
}
|
||||
|
||||
void
|
||||
VREyeParameters::GetOffset(JSContext* aCx, JS::MutableHandle<JSObject*> aRetval, ErrorResult& aRv)
|
||||
{
|
||||
if (!mOffset) {
|
||||
// Lazily create the Float32Array
|
||||
mOffset = dom::Float32Array::Create(aCx, this, 3, mEyeTranslation.components);
|
||||
if (!mOffset) {
|
||||
aRv.NoteJSContextException(aCx);
|
||||
return;
|
||||
}
|
||||
}
|
||||
aRetval.set(mOffset);
|
||||
}
|
||||
|
||||
JSObject*
|
||||
VREyeParameters::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
||||
{
|
||||
return VREyeParametersBinding::Wrap(aCx, this, aGivenProto);
|
||||
}
|
||||
|
||||
VRStageParameters::VRStageParameters(nsISupports* aParent,
|
||||
const gfx::Matrix4x4& aSittingToStandingTransform,
|
||||
const gfx::Size& aSize)
|
||||
: mParent(aParent)
|
||||
, mSittingToStandingTransform(aSittingToStandingTransform)
|
||||
, mSittingToStandingTransformArray(nullptr)
|
||||
, mSize(aSize)
|
||||
{
|
||||
mozilla::HoldJSObjects(this);
|
||||
}
|
||||
|
||||
VRStageParameters::~VRStageParameters()
|
||||
{
|
||||
mozilla::DropJSObjects(this);
|
||||
}
|
||||
|
||||
JSObject*
|
||||
VRStageParameters::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
||||
{
|
||||
return VRStageParametersBinding::Wrap(aCx, this, aGivenProto);
|
||||
}
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_CLASS(VRStageParameters)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(VRStageParameters)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mParent)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
|
||||
tmp->mSittingToStandingTransformArray = nullptr;
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(VRStageParameters)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mParent)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(VRStageParameters)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER
|
||||
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mSittingToStandingTransformArray)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(VRStageParameters, AddRef)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(VRStageParameters, Release)
|
||||
|
||||
void
|
||||
VRStageParameters::GetSittingToStandingTransform(JSContext* aCx,
|
||||
JS::MutableHandle<JSObject*> aRetval,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
if (!mSittingToStandingTransformArray) {
|
||||
// Lazily create the Float32Array
|
||||
mSittingToStandingTransformArray = dom::Float32Array::Create(aCx, this, 16,
|
||||
mSittingToStandingTransform.components);
|
||||
if (!mSittingToStandingTransformArray) {
|
||||
aRv.NoteJSContextException(aCx);
|
||||
return;
|
||||
}
|
||||
}
|
||||
aRetval.set(mSittingToStandingTransformArray);
|
||||
}
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(VRDisplayCapabilities, mParent)
|
||||
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(VRDisplayCapabilities, AddRef)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(VRDisplayCapabilities, Release)
|
||||
|
||||
JSObject*
|
||||
VRDisplayCapabilities::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
||||
{
|
||||
return VRDisplayCapabilitiesBinding::Wrap(aCx, this, aGivenProto);
|
||||
}
|
||||
|
||||
VRPose::VRPose(nsISupports* aParent, const gfx::VRHMDSensorState& aState)
|
||||
: Pose(aParent)
|
||||
, mVRState(aState)
|
||||
{
|
||||
mFrameId = aState.inputFrameID;
|
||||
mozilla::HoldJSObjects(this);
|
||||
}
|
||||
|
||||
VRPose::VRPose(nsISupports* aParent)
|
||||
: Pose(aParent)
|
||||
{
|
||||
mFrameId = 0;
|
||||
mVRState.Clear();
|
||||
mozilla::HoldJSObjects(this);
|
||||
}
|
||||
|
||||
VRPose::~VRPose()
|
||||
{
|
||||
mozilla::DropJSObjects(this);
|
||||
}
|
||||
|
||||
void
|
||||
VRPose::GetPosition(JSContext* aCx,
|
||||
JS::MutableHandle<JSObject*> aRetval,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
SetFloat32Array(aCx, aRetval, mPosition, mVRState.position, 3,
|
||||
!mPosition && bool(mVRState.flags & gfx::VRDisplayCapabilityFlags::Cap_Position),
|
||||
aRv);
|
||||
}
|
||||
|
||||
void
|
||||
VRPose::GetLinearVelocity(JSContext* aCx,
|
||||
JS::MutableHandle<JSObject*> aRetval,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
SetFloat32Array(aCx, aRetval, mLinearVelocity, mVRState.linearVelocity, 3,
|
||||
!mLinearVelocity && bool(mVRState.flags & gfx::VRDisplayCapabilityFlags::Cap_Position),
|
||||
aRv);
|
||||
}
|
||||
|
||||
void
|
||||
VRPose::GetLinearAcceleration(JSContext* aCx,
|
||||
JS::MutableHandle<JSObject*> aRetval,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
SetFloat32Array(aCx, aRetval, mLinearAcceleration, mVRState.linearAcceleration, 3,
|
||||
!mLinearAcceleration && bool(mVRState.flags & gfx::VRDisplayCapabilityFlags::Cap_LinearAcceleration),
|
||||
aRv);
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
VRPose::GetOrientation(JSContext* aCx,
|
||||
JS::MutableHandle<JSObject*> aRetval,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
SetFloat32Array(aCx, aRetval, mOrientation, mVRState.orientation, 4,
|
||||
!mOrientation && bool(mVRState.flags & gfx::VRDisplayCapabilityFlags::Cap_Orientation),
|
||||
aRv);
|
||||
}
|
||||
|
||||
void
|
||||
VRPose::GetAngularVelocity(JSContext* aCx,
|
||||
JS::MutableHandle<JSObject*> aRetval,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
SetFloat32Array(aCx, aRetval, mAngularVelocity, mVRState.angularVelocity, 3,
|
||||
!mAngularVelocity && bool(mVRState.flags & gfx::VRDisplayCapabilityFlags::Cap_Orientation),
|
||||
aRv);
|
||||
}
|
||||
|
||||
void
|
||||
VRPose::GetAngularAcceleration(JSContext* aCx,
|
||||
JS::MutableHandle<JSObject*> aRetval,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
SetFloat32Array(aCx, aRetval, mAngularAcceleration, mVRState.angularAcceleration, 3,
|
||||
!mAngularAcceleration && bool(mVRState.flags & gfx::VRDisplayCapabilityFlags::Cap_AngularAcceleration),
|
||||
aRv);
|
||||
}
|
||||
|
||||
JSObject*
|
||||
VRPose::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
||||
{
|
||||
return VRPoseBinding::Wrap(aCx, this, aGivenProto);
|
||||
}
|
||||
|
||||
/* virtual */ JSObject*
|
||||
VRDisplay::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
||||
{
|
||||
return VRDisplayBinding::Wrap(aCx, this, aGivenProto);
|
||||
}
|
||||
|
||||
VRDisplay::VRDisplay(nsPIDOMWindowInner* aWindow, gfx::VRDisplayClient* aClient)
|
||||
: DOMEventTargetHelper(aWindow)
|
||||
, mClient(aClient)
|
||||
, mDepthNear(0.01f) // Default value from WebVR Spec
|
||||
, mDepthFar(10000.0f) // Default value from WebVR Spec
|
||||
{
|
||||
const gfx::VRDisplayInfo& info = aClient->GetDisplayInfo();
|
||||
mDisplayId = info.GetDisplayID();
|
||||
mDisplayName = NS_ConvertASCIItoUTF16(info.GetDisplayName());
|
||||
mCapabilities = new VRDisplayCapabilities(aWindow, info.GetCapabilities());
|
||||
if (info.GetCapabilities() & gfx::VRDisplayCapabilityFlags::Cap_StageParameters) {
|
||||
mStageParameters = new VRStageParameters(aWindow,
|
||||
info.GetSittingToStandingTransform(),
|
||||
info.GetStageSize());
|
||||
}
|
||||
mozilla::HoldJSObjects(this);
|
||||
}
|
||||
|
||||
VRDisplay::~VRDisplay()
|
||||
{
|
||||
ExitPresentInternal();
|
||||
mozilla::DropJSObjects(this);
|
||||
}
|
||||
|
||||
void
|
||||
VRDisplay::LastRelease()
|
||||
{
|
||||
// We don't want to wait for the CC to free up the presentation
|
||||
// for use in other documents, so we do this in LastRelease().
|
||||
ExitPresentInternal();
|
||||
}
|
||||
|
||||
already_AddRefed<VREyeParameters>
|
||||
VRDisplay::GetEyeParameters(VREye aEye)
|
||||
{
|
||||
gfx::VRDisplayInfo::Eye eye = aEye == VREye::Left ? gfx::VRDisplayInfo::Eye_Left : gfx::VRDisplayInfo::Eye_Right;
|
||||
RefPtr<VREyeParameters> params =
|
||||
new VREyeParameters(GetParentObject(),
|
||||
mClient->GetDisplayInfo().GetEyeTranslation(eye),
|
||||
mClient->GetDisplayInfo().GetEyeFOV(eye),
|
||||
mClient->GetDisplayInfo().SuggestedEyeResolution());
|
||||
return params.forget();
|
||||
}
|
||||
|
||||
VRDisplayCapabilities*
|
||||
VRDisplay::Capabilities()
|
||||
{
|
||||
return mCapabilities;
|
||||
}
|
||||
|
||||
VRStageParameters*
|
||||
VRDisplay::GetStageParameters()
|
||||
{
|
||||
return mStageParameters;
|
||||
}
|
||||
|
||||
void
|
||||
VRDisplay::UpdateFrameInfo()
|
||||
{
|
||||
/**
|
||||
* The WebVR 1.1 spec Requires that VRDisplay.getPose and VRDisplay.getFrameData
|
||||
* must return the same values until the next VRDisplay.submitFrame.
|
||||
*
|
||||
* mFrameInfo is marked dirty at the end of the frame or start of a new
|
||||
* composition and lazily created here in order to receive mid-frame
|
||||
* pose-prediction updates while still ensuring conformance to the WebVR spec
|
||||
* requirements.
|
||||
*
|
||||
* If we are not presenting WebVR content, the frame will never end and we should
|
||||
* return the latest frame data always.
|
||||
*/
|
||||
if (mFrameInfo.IsDirty() || !mPresentation) {
|
||||
gfx::VRHMDSensorState state = mClient->GetSensorState();
|
||||
const gfx::VRDisplayInfo& info = mClient->GetDisplayInfo();
|
||||
mFrameInfo.Update(info, state, mDepthNear, mDepthFar);
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
VRDisplay::GetFrameData(VRFrameData& aFrameData)
|
||||
{
|
||||
UpdateFrameInfo();
|
||||
aFrameData.Update(mFrameInfo);
|
||||
return true;
|
||||
}
|
||||
|
||||
already_AddRefed<VRPose>
|
||||
VRDisplay::GetPose()
|
||||
{
|
||||
UpdateFrameInfo();
|
||||
RefPtr<VRPose> obj = new VRPose(GetParentObject(), mFrameInfo.mVRState);
|
||||
|
||||
return obj.forget();
|
||||
}
|
||||
|
||||
void
|
||||
VRDisplay::ResetPose()
|
||||
{
|
||||
mClient->ZeroSensor();
|
||||
}
|
||||
|
||||
already_AddRefed<Promise>
|
||||
VRDisplay::RequestPresent(const nsTArray<VRLayer>& aLayers, ErrorResult& aRv)
|
||||
{
|
||||
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetParentObject());
|
||||
if (!global) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
RefPtr<Promise> promise = Promise::Create(global, aRv);
|
||||
NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
|
||||
|
||||
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
|
||||
NS_ENSURE_TRUE(obs, nullptr);
|
||||
|
||||
if (mClient->GetIsPresenting()) {
|
||||
// Only one presentation allowed per VRDisplay
|
||||
// on a first-come-first-serve basis.
|
||||
promise->MaybeRejectWithUndefined();
|
||||
} else {
|
||||
mPresentation = mClient->BeginPresentation(aLayers);
|
||||
mFrameInfo.Clear();
|
||||
|
||||
nsresult rv = obs->AddObserver(this, "inner-window-destroyed", false);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
mPresentation = nullptr;
|
||||
promise->MaybeRejectWithUndefined();
|
||||
} else {
|
||||
promise->MaybeResolve(JS::UndefinedHandleValue);
|
||||
}
|
||||
}
|
||||
return promise.forget();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
VRDisplay::Observe(nsISupports* aSubject, const char* aTopic,
|
||||
const char16_t* aData)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
if (strcmp(aTopic, "inner-window-destroyed") == 0) {
|
||||
nsCOMPtr<nsISupportsPRUint64> wrapper = do_QueryInterface(aSubject);
|
||||
NS_ENSURE_TRUE(wrapper, NS_ERROR_FAILURE);
|
||||
|
||||
uint64_t innerID;
|
||||
nsresult rv = wrapper->GetData(&innerID);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (!GetOwner() || GetOwner()->WindowID() == innerID) {
|
||||
ExitPresentInternal();
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// This should not happen.
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
already_AddRefed<Promise>
|
||||
VRDisplay::ExitPresent(ErrorResult& aRv)
|
||||
{
|
||||
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetParentObject());
|
||||
if (!global) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
RefPtr<Promise> promise = Promise::Create(global, aRv);
|
||||
NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
|
||||
|
||||
if (!IsPresenting()) {
|
||||
// We can not exit a presentation outside of the context that
|
||||
// started the presentation.
|
||||
promise->MaybeRejectWithUndefined();
|
||||
} else {
|
||||
promise->MaybeResolve(JS::UndefinedHandleValue);
|
||||
ExitPresentInternal();
|
||||
}
|
||||
|
||||
return promise.forget();
|
||||
}
|
||||
|
||||
void
|
||||
VRDisplay::ExitPresentInternal()
|
||||
{
|
||||
mPresentation = nullptr;
|
||||
}
|
||||
|
||||
void
|
||||
VRDisplay::GetLayers(nsTArray<VRLayer>& result)
|
||||
{
|
||||
if (mPresentation) {
|
||||
mPresentation->GetDOMLayers(result);
|
||||
} else {
|
||||
result = nsTArray<VRLayer>();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
VRDisplay::SubmitFrame()
|
||||
{
|
||||
if (mPresentation) {
|
||||
mPresentation->SubmitFrame();
|
||||
}
|
||||
mFrameInfo.Clear();
|
||||
}
|
||||
|
||||
int32_t
|
||||
VRDisplay::RequestAnimationFrame(FrameRequestCallback& aCallback,
|
||||
ErrorResult& aError)
|
||||
{
|
||||
gfx::VRManagerChild* vm = gfx::VRManagerChild::Get();
|
||||
|
||||
int32_t handle;
|
||||
aError = vm->ScheduleFrameRequestCallback(aCallback, &handle);
|
||||
return handle;
|
||||
}
|
||||
|
||||
void
|
||||
VRDisplay::CancelAnimationFrame(int32_t aHandle, ErrorResult& aError)
|
||||
{
|
||||
gfx::VRManagerChild* vm = gfx::VRManagerChild::Get();
|
||||
vm->CancelFrameRequestCallback(aHandle);
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
VRDisplay::IsPresenting() const
|
||||
{
|
||||
// IsPresenting returns true only if this Javascript context is presenting
|
||||
// and will return false if another context is presenting.
|
||||
return mPresentation != nullptr;
|
||||
}
|
||||
|
||||
bool
|
||||
VRDisplay::IsConnected() const
|
||||
{
|
||||
return mClient->GetIsConnected();
|
||||
}
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_INHERITED(VRDisplay, DOMEventTargetHelper, mCapabilities, mStageParameters)
|
||||
|
||||
NS_IMPL_ADDREF_INHERITED(VRDisplay, DOMEventTargetHelper)
|
||||
NS_IMPL_RELEASE_INHERITED(VRDisplay, DOMEventTargetHelper)
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(VRDisplay)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIObserver)
|
||||
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, DOMEventTargetHelper)
|
||||
NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_CLASS(VRFrameData)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(VRFrameData)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mParent, mPose)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
|
||||
tmp->mLeftProjectionMatrix = nullptr;
|
||||
tmp->mLeftViewMatrix = nullptr;
|
||||
tmp->mRightProjectionMatrix = nullptr;
|
||||
tmp->mRightViewMatrix = nullptr;
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(VRFrameData)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mParent, mPose)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(VRFrameData)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER
|
||||
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mLeftProjectionMatrix)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mLeftViewMatrix)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mRightProjectionMatrix)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mRightViewMatrix)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(VRFrameData, AddRef)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(VRFrameData, Release)
|
||||
|
||||
VRFrameData::VRFrameData(nsISupports* aParent)
|
||||
: mParent(aParent)
|
||||
, mLeftProjectionMatrix(nullptr)
|
||||
, mLeftViewMatrix(nullptr)
|
||||
, mRightProjectionMatrix(nullptr)
|
||||
, mRightViewMatrix(nullptr)
|
||||
{
|
||||
mozilla::HoldJSObjects(this);
|
||||
mPose = new VRPose(aParent);
|
||||
}
|
||||
|
||||
VRFrameData::~VRFrameData()
|
||||
{
|
||||
mozilla::DropJSObjects(this);
|
||||
}
|
||||
|
||||
/* static */ already_AddRefed<VRFrameData>
|
||||
VRFrameData::Constructor(const GlobalObject& aGlobal, ErrorResult& aRv)
|
||||
{
|
||||
RefPtr<VRFrameData> obj = new VRFrameData(aGlobal.GetAsSupports());
|
||||
return obj.forget();
|
||||
}
|
||||
|
||||
JSObject*
|
||||
VRFrameData::WrapObject(JSContext* aCx,
|
||||
JS::Handle<JSObject*> aGivenProto)
|
||||
{
|
||||
return VRFrameDataBinding::Wrap(aCx, this, aGivenProto);
|
||||
}
|
||||
|
||||
VRPose*
|
||||
VRFrameData::Pose()
|
||||
{
|
||||
return mPose;
|
||||
}
|
||||
|
||||
void
|
||||
VRFrameData::LazyCreateMatrix(JS::Heap<JSObject*>& aArray, gfx::Matrix4x4& aMat, JSContext* aCx,
|
||||
JS::MutableHandle<JSObject*> aRetval, ErrorResult& aRv)
|
||||
{
|
||||
if (!aArray) {
|
||||
// Lazily create the Float32Array
|
||||
aArray = dom::Float32Array::Create(aCx, this, 16, aMat.components);
|
||||
if (!aArray) {
|
||||
aRv.NoteJSContextException(aCx);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (aArray) {
|
||||
JS::ExposeObjectToActiveJS(aArray);
|
||||
}
|
||||
aRetval.set(aArray);
|
||||
}
|
||||
|
||||
double
|
||||
VRFrameData::Timestamp() const
|
||||
{
|
||||
// Converting from seconds to milliseconds
|
||||
return mFrameInfo.mVRState.timestamp * 1000.0f;
|
||||
}
|
||||
|
||||
void
|
||||
VRFrameData::GetLeftProjectionMatrix(JSContext* aCx,
|
||||
JS::MutableHandle<JSObject*> aRetval,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
LazyCreateMatrix(mLeftProjectionMatrix, mFrameInfo.mLeftProjection, aCx,
|
||||
aRetval, aRv);
|
||||
}
|
||||
|
||||
void
|
||||
VRFrameData::GetLeftViewMatrix(JSContext* aCx,
|
||||
JS::MutableHandle<JSObject*> aRetval,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
LazyCreateMatrix(mLeftViewMatrix, mFrameInfo.mLeftView, aCx, aRetval, aRv);
|
||||
}
|
||||
|
||||
void
|
||||
VRFrameData::GetRightProjectionMatrix(JSContext* aCx,
|
||||
JS::MutableHandle<JSObject*> aRetval,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
LazyCreateMatrix(mRightProjectionMatrix, mFrameInfo.mRightProjection, aCx,
|
||||
aRetval, aRv);
|
||||
}
|
||||
|
||||
void
|
||||
VRFrameData::GetRightViewMatrix(JSContext* aCx,
|
||||
JS::MutableHandle<JSObject*> aRetval,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
LazyCreateMatrix(mRightViewMatrix, mFrameInfo.mRightView, aCx, aRetval, aRv);
|
||||
}
|
||||
|
||||
void
|
||||
VRFrameData::Update(const VRFrameInfo& aFrameInfo)
|
||||
{
|
||||
mFrameInfo = aFrameInfo;
|
||||
|
||||
mLeftProjectionMatrix = nullptr;
|
||||
mLeftViewMatrix = nullptr;
|
||||
mRightProjectionMatrix = nullptr;
|
||||
mRightViewMatrix = nullptr;
|
||||
|
||||
mPose = new VRPose(GetParentObject(), mFrameInfo.mVRState);
|
||||
}
|
||||
|
||||
void
|
||||
VRFrameInfo::Update(const gfx::VRDisplayInfo& aInfo,
|
||||
const gfx::VRHMDSensorState& aState,
|
||||
float aDepthNear,
|
||||
float aDepthFar)
|
||||
{
|
||||
mVRState = aState;
|
||||
|
||||
gfx::Quaternion qt;
|
||||
if (mVRState.flags & gfx::VRDisplayCapabilityFlags::Cap_Orientation) {
|
||||
qt.x = mVRState.orientation[0];
|
||||
qt.y = mVRState.orientation[1];
|
||||
qt.z = mVRState.orientation[2];
|
||||
qt.w = mVRState.orientation[3];
|
||||
}
|
||||
gfx::Point3D pos;
|
||||
if (mVRState.flags & gfx::VRDisplayCapabilityFlags::Cap_Position) {
|
||||
pos.x = -mVRState.position[0];
|
||||
pos.y = -mVRState.position[1];
|
||||
pos.z = -mVRState.position[2];
|
||||
}
|
||||
gfx::Matrix4x4 matHead;
|
||||
matHead.SetRotationFromQuaternion(qt);
|
||||
matHead.PreTranslate(pos);
|
||||
|
||||
mLeftView = matHead;
|
||||
mLeftView.PostTranslate(-aInfo.mEyeTranslation[gfx::VRDisplayInfo::Eye_Left]);
|
||||
|
||||
mRightView = matHead;
|
||||
mRightView.PostTranslate(-aInfo.mEyeTranslation[gfx::VRDisplayInfo::Eye_Right]);
|
||||
|
||||
// Avoid division by zero within ConstructProjectionMatrix
|
||||
const float kEpsilon = 0.00001f;
|
||||
if (fabs(aDepthFar - aDepthNear) < kEpsilon) {
|
||||
aDepthFar = aDepthNear + kEpsilon;
|
||||
}
|
||||
|
||||
const gfx::VRFieldOfView leftFOV = aInfo.mEyeFOV[gfx::VRDisplayInfo::Eye_Left];
|
||||
mLeftProjection = leftFOV.ConstructProjectionMatrix(aDepthNear, aDepthFar, true);
|
||||
const gfx::VRFieldOfView rightFOV = aInfo.mEyeFOV[gfx::VRDisplayInfo::Eye_Right];
|
||||
mRightProjection = rightFOV.ConstructProjectionMatrix(aDepthNear, aDepthFar, true);
|
||||
}
|
||||
|
||||
VRFrameInfo::VRFrameInfo()
|
||||
{
|
||||
mVRState.Clear();
|
||||
}
|
||||
|
||||
bool
|
||||
VRFrameInfo::IsDirty()
|
||||
{
|
||||
return mVRState.timestamp == 0;
|
||||
}
|
||||
|
||||
void
|
||||
VRFrameInfo::Clear()
|
||||
{
|
||||
mVRState.Clear();
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
@@ -1,362 +0,0 @@
|
||||
/* -*- 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 mozilla_dom_VRDisplay_h_
|
||||
#define mozilla_dom_VRDisplay_h_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "mozilla/ErrorResult.h"
|
||||
#include "mozilla/dom/TypedArray.h"
|
||||
#include "mozilla/dom/VRDisplayBinding.h"
|
||||
#include "mozilla/DOMEventTargetHelper.h"
|
||||
#include "mozilla/dom/DOMPoint.h"
|
||||
#include "mozilla/dom/DOMRect.h"
|
||||
#include "mozilla/dom/Pose.h"
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsString.h"
|
||||
#include "nsTArray.h"
|
||||
|
||||
#include "gfxVR.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace gfx {
|
||||
class VRDisplayClient;
|
||||
class VRDisplayPresentation;
|
||||
struct VRFieldOfView;
|
||||
enum class VRDisplayCapabilityFlags : uint16_t;
|
||||
struct VRHMDSensorState;
|
||||
}
|
||||
namespace dom {
|
||||
class Navigator;
|
||||
|
||||
class VRFieldOfView final : public nsWrapperCache
|
||||
{
|
||||
public:
|
||||
VRFieldOfView(nsISupports* aParent,
|
||||
double aUpDegrees, double aRightDegrees,
|
||||
double aDownDegrees, double aLeftDegrees);
|
||||
VRFieldOfView(nsISupports* aParent, const gfx::VRFieldOfView& aSrc);
|
||||
|
||||
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(VRFieldOfView)
|
||||
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(VRFieldOfView)
|
||||
|
||||
double UpDegrees() const { return mUpDegrees; }
|
||||
double RightDegrees() const { return mRightDegrees; }
|
||||
double DownDegrees() const { return mDownDegrees; }
|
||||
double LeftDegrees() const { return mLeftDegrees; }
|
||||
|
||||
nsISupports* GetParentObject() const { return mParent; }
|
||||
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
||||
|
||||
protected:
|
||||
virtual ~VRFieldOfView() {}
|
||||
|
||||
nsCOMPtr<nsISupports> mParent;
|
||||
|
||||
double mUpDegrees;
|
||||
double mRightDegrees;
|
||||
double mDownDegrees;
|
||||
double mLeftDegrees;
|
||||
};
|
||||
|
||||
class VRDisplayCapabilities final : public nsWrapperCache
|
||||
{
|
||||
public:
|
||||
VRDisplayCapabilities(nsISupports* aParent, const gfx::VRDisplayCapabilityFlags& aFlags)
|
||||
: mParent(aParent)
|
||||
, mFlags(aFlags)
|
||||
{
|
||||
}
|
||||
|
||||
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(VRDisplayCapabilities)
|
||||
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(VRDisplayCapabilities)
|
||||
|
||||
nsISupports* GetParentObject() const
|
||||
{
|
||||
return mParent;
|
||||
}
|
||||
|
||||
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
||||
|
||||
bool HasPosition() const;
|
||||
bool HasOrientation() const;
|
||||
bool HasExternalDisplay() const;
|
||||
bool CanPresent() const;
|
||||
uint32_t MaxLayers() const;
|
||||
|
||||
protected:
|
||||
~VRDisplayCapabilities() {}
|
||||
nsCOMPtr<nsISupports> mParent;
|
||||
gfx::VRDisplayCapabilityFlags mFlags;
|
||||
};
|
||||
|
||||
class VRPose final : public Pose
|
||||
{
|
||||
|
||||
public:
|
||||
VRPose(nsISupports* aParent, const gfx::VRHMDSensorState& aState);
|
||||
explicit VRPose(nsISupports* aParent);
|
||||
|
||||
uint32_t FrameID() const { return mFrameId; }
|
||||
|
||||
virtual void GetPosition(JSContext* aCx,
|
||||
JS::MutableHandle<JSObject*> aRetval,
|
||||
ErrorResult& aRv) override;
|
||||
virtual void GetLinearVelocity(JSContext* aCx,
|
||||
JS::MutableHandle<JSObject*> aRetval,
|
||||
ErrorResult& aRv) override;
|
||||
virtual void GetLinearAcceleration(JSContext* aCx,
|
||||
JS::MutableHandle<JSObject*> aRetval,
|
||||
ErrorResult& aRv) override;
|
||||
virtual void GetOrientation(JSContext* aCx,
|
||||
JS::MutableHandle<JSObject*> aRetval,
|
||||
ErrorResult& aRv) override;
|
||||
virtual void GetAngularVelocity(JSContext* aCx,
|
||||
JS::MutableHandle<JSObject*> aRetval,
|
||||
ErrorResult& aRv) override;
|
||||
virtual void GetAngularAcceleration(JSContext* aCx,
|
||||
JS::MutableHandle<JSObject*> aRetval,
|
||||
ErrorResult& aRv) override;
|
||||
|
||||
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
||||
|
||||
protected:
|
||||
~VRPose();
|
||||
|
||||
uint32_t mFrameId;
|
||||
gfx::VRHMDSensorState mVRState;
|
||||
};
|
||||
|
||||
struct VRFrameInfo
|
||||
{
|
||||
VRFrameInfo();
|
||||
|
||||
void Update(const gfx::VRDisplayInfo& aInfo,
|
||||
const gfx::VRHMDSensorState& aState,
|
||||
float aDepthNear,
|
||||
float aDepthFar);
|
||||
|
||||
void Clear();
|
||||
bool IsDirty();
|
||||
|
||||
gfx::VRHMDSensorState mVRState;
|
||||
gfx::Matrix4x4 mLeftProjection;
|
||||
gfx::Matrix4x4 mLeftView;
|
||||
gfx::Matrix4x4 mRightProjection;
|
||||
gfx::Matrix4x4 mRightView;
|
||||
|
||||
};
|
||||
|
||||
class VRFrameData final : public nsWrapperCache
|
||||
{
|
||||
public:
|
||||
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(VRFrameData)
|
||||
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(VRFrameData)
|
||||
|
||||
explicit VRFrameData(nsISupports* aParent);
|
||||
static already_AddRefed<VRFrameData> Constructor(const GlobalObject& aGlobal,
|
||||
ErrorResult& aRv);
|
||||
|
||||
void Update(const VRFrameInfo& aFrameInfo);
|
||||
|
||||
// WebIDL Members
|
||||
double Timestamp() const;
|
||||
void GetLeftProjectionMatrix(JSContext* aCx,
|
||||
JS::MutableHandle<JSObject*> aRetval,
|
||||
ErrorResult& aRv);
|
||||
void GetLeftViewMatrix(JSContext* aCx,
|
||||
JS::MutableHandle<JSObject*> aRetval,
|
||||
ErrorResult& aRv);
|
||||
void GetRightProjectionMatrix(JSContext* aCx,
|
||||
JS::MutableHandle<JSObject*> aRetval,
|
||||
ErrorResult& aRv);
|
||||
void GetRightViewMatrix(JSContext* aCx,
|
||||
JS::MutableHandle<JSObject*> aRetval,
|
||||
ErrorResult& aRv);
|
||||
|
||||
VRPose* Pose();
|
||||
|
||||
// WebIDL Boilerplate
|
||||
nsISupports* GetParentObject() const { return mParent; }
|
||||
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
||||
|
||||
protected:
|
||||
~VRFrameData();
|
||||
nsCOMPtr<nsISupports> mParent;
|
||||
|
||||
VRFrameInfo mFrameInfo;
|
||||
RefPtr<VRPose> mPose;
|
||||
JS::Heap<JSObject*> mLeftProjectionMatrix;
|
||||
JS::Heap<JSObject*> mLeftViewMatrix;
|
||||
JS::Heap<JSObject*> mRightProjectionMatrix;
|
||||
JS::Heap<JSObject*> mRightViewMatrix;
|
||||
|
||||
void LazyCreateMatrix(JS::Heap<JSObject*>& aArray, gfx::Matrix4x4& aMat,
|
||||
JSContext* aCx, JS::MutableHandle<JSObject*> aRetval,
|
||||
ErrorResult& aRv);
|
||||
};
|
||||
|
||||
class VRStageParameters final : public nsWrapperCache
|
||||
{
|
||||
public:
|
||||
VRStageParameters(nsISupports* aParent,
|
||||
const gfx::Matrix4x4& aSittingToStandingTransform,
|
||||
const gfx::Size& aSize);
|
||||
|
||||
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(VRStageParameters)
|
||||
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(VRStageParameters)
|
||||
|
||||
void GetSittingToStandingTransform(JSContext* aCx,
|
||||
JS::MutableHandle<JSObject*> aRetval,
|
||||
ErrorResult& aRv);
|
||||
float SizeX() const { return mSize.width; }
|
||||
float SizeZ() const { return mSize.height; }
|
||||
|
||||
nsISupports* GetParentObject() const { return mParent; }
|
||||
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
||||
|
||||
protected:
|
||||
~VRStageParameters();
|
||||
|
||||
nsCOMPtr<nsISupports> mParent;
|
||||
|
||||
gfx::Matrix4x4 mSittingToStandingTransform;
|
||||
JS::Heap<JSObject*> mSittingToStandingTransformArray;
|
||||
gfx::Size mSize;
|
||||
};
|
||||
|
||||
class VREyeParameters final : public nsWrapperCache
|
||||
{
|
||||
public:
|
||||
VREyeParameters(nsISupports* aParent,
|
||||
const gfx::Point3D& aEyeTranslation,
|
||||
const gfx::VRFieldOfView& aFOV,
|
||||
const gfx::IntSize& aRenderSize);
|
||||
|
||||
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(VREyeParameters)
|
||||
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(VREyeParameters)
|
||||
|
||||
void GetOffset(JSContext* aCx, JS::MutableHandle<JSObject*> aRetVal,
|
||||
ErrorResult& aRv);
|
||||
|
||||
VRFieldOfView* FieldOfView();
|
||||
|
||||
uint32_t RenderWidth() const { return mRenderSize.width; }
|
||||
uint32_t RenderHeight() const { return mRenderSize.height; }
|
||||
|
||||
nsISupports* GetParentObject() const { return mParent; }
|
||||
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
||||
protected:
|
||||
~VREyeParameters();
|
||||
|
||||
nsCOMPtr<nsISupports> mParent;
|
||||
|
||||
|
||||
gfx::Point3D mEyeTranslation;
|
||||
gfx::IntSize mRenderSize;
|
||||
JS::Heap<JSObject*> mOffset;
|
||||
RefPtr<VRFieldOfView> mFOV;
|
||||
};
|
||||
|
||||
class VRDisplay final : public DOMEventTargetHelper
|
||||
, public nsIObserver
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
NS_DECL_NSIOBSERVER
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(VRDisplay, DOMEventTargetHelper)
|
||||
|
||||
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
||||
|
||||
bool IsPresenting() const;
|
||||
bool IsConnected() const;
|
||||
|
||||
VRDisplayCapabilities* Capabilities();
|
||||
VRStageParameters* GetStageParameters();
|
||||
|
||||
uint32_t DisplayId() const { return mDisplayId; }
|
||||
void GetDisplayName(nsAString& aDisplayName) const { aDisplayName = mDisplayName; }
|
||||
|
||||
static bool RefreshVRDisplays(uint64_t aWindowId);
|
||||
static void UpdateVRDisplays(nsTArray<RefPtr<VRDisplay> >& aDisplays,
|
||||
nsPIDOMWindowInner* aWindow);
|
||||
|
||||
gfx::VRDisplayClient *GetClient() {
|
||||
return mClient;
|
||||
}
|
||||
|
||||
virtual already_AddRefed<VREyeParameters> GetEyeParameters(VREye aEye);
|
||||
|
||||
bool GetFrameData(VRFrameData& aFrameData);
|
||||
already_AddRefed<VRPose> GetPose();
|
||||
void ResetPose();
|
||||
|
||||
double DepthNear() {
|
||||
return mDepthNear;
|
||||
}
|
||||
|
||||
double DepthFar() {
|
||||
return mDepthFar;
|
||||
}
|
||||
|
||||
void SetDepthNear(double aDepthNear) {
|
||||
// XXX When we start sending depth buffers to VRLayer's we will want
|
||||
// to communicate this with the VRDisplayHost
|
||||
mDepthNear = aDepthNear;
|
||||
}
|
||||
|
||||
void SetDepthFar(double aDepthFar) {
|
||||
// XXX When we start sending depth buffers to VRLayer's we will want
|
||||
// to communicate this with the VRDisplayHost
|
||||
mDepthFar = aDepthFar;
|
||||
}
|
||||
|
||||
already_AddRefed<Promise> RequestPresent(const nsTArray<VRLayer>& aLayers, ErrorResult& aRv);
|
||||
already_AddRefed<Promise> ExitPresent(ErrorResult& aRv);
|
||||
void GetLayers(nsTArray<VRLayer>& result);
|
||||
void SubmitFrame();
|
||||
|
||||
int32_t RequestAnimationFrame(mozilla::dom::FrameRequestCallback& aCallback,
|
||||
mozilla::ErrorResult& aError);
|
||||
void CancelAnimationFrame(int32_t aHandle, mozilla::ErrorResult& aError);
|
||||
|
||||
protected:
|
||||
VRDisplay(nsPIDOMWindowInner* aWindow, gfx::VRDisplayClient* aClient);
|
||||
virtual ~VRDisplay();
|
||||
virtual void LastRelease() override;
|
||||
|
||||
void ExitPresentInternal();
|
||||
void UpdateFrameInfo();
|
||||
|
||||
RefPtr<gfx::VRDisplayClient> mClient;
|
||||
|
||||
uint32_t mDisplayId;
|
||||
nsString mDisplayName;
|
||||
|
||||
RefPtr<VRDisplayCapabilities> mCapabilities;
|
||||
RefPtr<VRStageParameters> mStageParameters;
|
||||
|
||||
double mDepthNear;
|
||||
double mDepthFar;
|
||||
|
||||
RefPtr<gfx::VRDisplayPresentation> mPresentation;
|
||||
|
||||
/**
|
||||
* The WebVR 1.1 spec Requires that VRDisplay.getPose and VRDisplay.getFrameData
|
||||
* must return the same values until the next VRDisplay.submitFrame.
|
||||
* mFrameInfo is updated only on the first call to either function within one
|
||||
* frame. Subsequent calls before the next SubmitFrame or ExitPresent call
|
||||
* will use these cached values.
|
||||
*/
|
||||
VRFrameInfo mFrameInfo;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif
|
||||
@@ -1,79 +0,0 @@
|
||||
/* -*- 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/. */
|
||||
|
||||
#include "VREventObserver.h"
|
||||
|
||||
#include "nsContentUtils.h"
|
||||
#include "nsGlobalWindow.h"
|
||||
#include "VRManagerChild.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
using namespace gfx;
|
||||
|
||||
/**
|
||||
* This class is used by nsGlobalWindow to implement window.onvrdisplayconnected,
|
||||
* window.onvrdisplaydisconnected, and window.onvrdisplaypresentchange.
|
||||
*/
|
||||
VREventObserver::VREventObserver(nsGlobalWindow* aGlobalWindow)
|
||||
: mWindow(aGlobalWindow)
|
||||
{
|
||||
MOZ_ASSERT(aGlobalWindow && aGlobalWindow->IsInnerWindow());
|
||||
|
||||
VRManagerChild* vmc = VRManagerChild::Get();
|
||||
if (vmc) {
|
||||
vmc->AddListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
VREventObserver::~VREventObserver()
|
||||
{
|
||||
VRManagerChild* vmc = VRManagerChild::Get();
|
||||
if (vmc) {
|
||||
vmc->RemoveListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
VREventObserver::NotifyVRDisplayConnect()
|
||||
{
|
||||
/**
|
||||
* We do not call nsGlobalWindow::NotifyActiveVRDisplaysChanged here, as we
|
||||
* can assume that a newly enumerated display is not presenting WebVR
|
||||
* content.
|
||||
*/
|
||||
if (mWindow->AsInner()->IsCurrentInnerWindow()) {
|
||||
MOZ_ASSERT(nsContentUtils::IsSafeToRunScript());
|
||||
mWindow->GetOuterWindow()->DispatchCustomEvent(
|
||||
NS_LITERAL_STRING("vrdisplayconnected"));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
VREventObserver::NotifyVRDisplayDisconnect()
|
||||
{
|
||||
if (mWindow->AsInner()->IsCurrentInnerWindow()) {
|
||||
mWindow->NotifyActiveVRDisplaysChanged();
|
||||
MOZ_ASSERT(nsContentUtils::IsSafeToRunScript());
|
||||
mWindow->GetOuterWindow()->DispatchCustomEvent(
|
||||
NS_LITERAL_STRING("vrdisplaydisconnected"));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
VREventObserver::NotifyVRDisplayPresentChange()
|
||||
{
|
||||
if (mWindow->AsInner()->IsCurrentInnerWindow()) {
|
||||
mWindow->NotifyActiveVRDisplaysChanged();
|
||||
MOZ_ASSERT(nsContentUtils::IsSafeToRunScript());
|
||||
mWindow->GetOuterWindow()->DispatchCustomEvent(
|
||||
NS_LITERAL_STRING("vrdisplaypresentchange"));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
@@ -1,33 +0,0 @@
|
||||
/* -*- 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 mozilla_dom_VREventObserver_h
|
||||
#define mozilla_dom_VREventObserver_h
|
||||
|
||||
class nsGlobalWindow;
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
class VREventObserver final
|
||||
{
|
||||
public:
|
||||
~VREventObserver();
|
||||
explicit VREventObserver(nsGlobalWindow* aGlobalWindow);
|
||||
|
||||
void NotifyVRDisplayConnect();
|
||||
void NotifyVRDisplayDisconnect();
|
||||
void NotifyVRDisplayPresentChange();
|
||||
|
||||
private:
|
||||
// Weak pointer, instance is owned by mWindow.
|
||||
nsGlobalWindow* MOZ_NON_OWNING_REF mWindow;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_dom_VREventObserver_h
|
||||
@@ -1,22 +0,0 @@
|
||||
# -*- 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/.
|
||||
|
||||
EXPORTS.mozilla.dom += [
|
||||
'VRDisplay.h',
|
||||
'VREventObserver.h',
|
||||
]
|
||||
|
||||
UNIFIED_SOURCES = [
|
||||
'VRDisplay.cpp',
|
||||
'VREventObserver.cpp',
|
||||
]
|
||||
|
||||
include('/ipc/chromium/chromium-config.mozbuild')
|
||||
|
||||
FINAL_LIBRARY = 'xul'
|
||||
LOCAL_INCLUDES += [
|
||||
'/dom/base'
|
||||
]
|
||||
@@ -268,14 +268,6 @@ partial interface Navigator {
|
||||
};
|
||||
#endif // MOZ_GAMEPAD
|
||||
|
||||
partial interface Navigator {
|
||||
[Throws, Pref="dom.vr.enabled"]
|
||||
Promise<sequence<VRDisplay>> getVRDisplays();
|
||||
// TODO: Use FrozenArray once available. (Bug 1236777)
|
||||
[Frozen, Cached, Pure, Pref="dom.vr.enabled"]
|
||||
readonly attribute sequence<VRDisplay> activeVRDisplays;
|
||||
};
|
||||
|
||||
#ifdef MOZ_TIME_MANAGER
|
||||
// nsIDOMMozNavigatorTime
|
||||
partial interface Navigator {
|
||||
|
||||
@@ -1,286 +0,0 @@
|
||||
/* -*- Mode: IDL; tab-width: 2; 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/. */
|
||||
|
||||
enum VREye {
|
||||
"left",
|
||||
"right"
|
||||
};
|
||||
|
||||
[Pref="dom.vr.enabled",
|
||||
HeaderFile="mozilla/dom/VRDisplay.h"]
|
||||
interface VRFieldOfView {
|
||||
readonly attribute double upDegrees;
|
||||
readonly attribute double rightDegrees;
|
||||
readonly attribute double downDegrees;
|
||||
readonly attribute double leftDegrees;
|
||||
};
|
||||
|
||||
typedef (HTMLCanvasElement or OffscreenCanvas) VRSource;
|
||||
|
||||
dictionary VRLayer {
|
||||
/**
|
||||
* XXX - When WebVR in WebWorkers is implemented, HTMLCanvasElement below
|
||||
* should be replaced with VRSource.
|
||||
*/
|
||||
HTMLCanvasElement? source = null;
|
||||
|
||||
/**
|
||||
* The left and right viewports contain 4 values defining the viewport
|
||||
* rectangles within the canvas to present to the eye in UV space.
|
||||
* [0] left offset of the viewport (0.0 - 1.0)
|
||||
* [1] top offset of the viewport (0.0 - 1.0)
|
||||
* [2] width of the viewport (0.0 - 1.0)
|
||||
* [3] height of the viewport (0.0 - 1.0)
|
||||
*
|
||||
* When no values are passed, they will be processed as though the left
|
||||
* and right sides of the viewport were passed:
|
||||
*
|
||||
* leftBounds: [0.0, 0.0, 0.5, 1.0]
|
||||
* rightBounds: [0.5, 0.0, 0.5, 1.0]
|
||||
*/
|
||||
sequence<float> leftBounds = [];
|
||||
sequence<float> rightBounds = [];
|
||||
};
|
||||
|
||||
/**
|
||||
* Values describing the capabilities of a VRDisplay.
|
||||
* These are expected to be static per-device/per-user.
|
||||
*/
|
||||
[Pref="dom.vr.enabled",
|
||||
HeaderFile="mozilla/dom/VRDisplay.h"]
|
||||
interface VRDisplayCapabilities {
|
||||
/**
|
||||
* hasPosition is true if the VRDisplay is capable of tracking its position.
|
||||
*/
|
||||
readonly attribute boolean hasPosition;
|
||||
|
||||
/**
|
||||
* hasOrientation is true if the VRDisplay is capable of tracking its orientation.
|
||||
*/
|
||||
readonly attribute boolean hasOrientation;
|
||||
|
||||
/**
|
||||
* Whether the VRDisplay is separate from the device’s
|
||||
* primary display. If presenting VR content will obscure
|
||||
* other content on the device, this should be false. When
|
||||
* false, the application should not attempt to mirror VR content
|
||||
* or update non-VR UI because that content will not be visible.
|
||||
*/
|
||||
readonly attribute boolean hasExternalDisplay;
|
||||
|
||||
/**
|
||||
* Whether the VRDisplay is capable of presenting content to an HMD or similar device.
|
||||
* Can be used to indicate “magic window” devices that are capable of 6DoF tracking but for
|
||||
* which requestPresent is not meaningful. If false then calls to requestPresent should
|
||||
* always fail, and getEyeParameters should return null.
|
||||
*/
|
||||
readonly attribute boolean canPresent;
|
||||
|
||||
/**
|
||||
* Indicates the maximum length of the array that requestPresent() will accept. MUST be 1 if
|
||||
canPresent is true, 0 otherwise.
|
||||
*/
|
||||
readonly attribute unsigned long maxLayers;
|
||||
};
|
||||
|
||||
/**
|
||||
* Values describing the the stage / play area for devices
|
||||
* that support room-scale experiences.
|
||||
*/
|
||||
[Pref="dom.vr.enabled",
|
||||
HeaderFile="mozilla/dom/VRDisplay.h"]
|
||||
interface VRStageParameters {
|
||||
/**
|
||||
* A 16-element array containing the components of a column-major 4x4
|
||||
* affine transform matrix. This matrix transforms the sitting-space position
|
||||
* returned by get{Immediate}Pose() to a standing-space position.
|
||||
*/
|
||||
[Throws] readonly attribute Float32Array sittingToStandingTransform;
|
||||
|
||||
/**
|
||||
* Dimensions of the play-area bounds. The bounds are defined
|
||||
* as an axis-aligned rectangle on the floor.
|
||||
* The center of the rectangle is at (0,0,0) in standing-space
|
||||
* coordinates.
|
||||
* These bounds are defined for safety purposes.
|
||||
* Content should not require the user to move beyond these
|
||||
* bounds; however, it is possible for the user to ignore
|
||||
* the bounds resulting in position values outside of
|
||||
* this rectangle.
|
||||
*/
|
||||
readonly attribute float sizeX;
|
||||
readonly attribute float sizeZ;
|
||||
};
|
||||
|
||||
[Pref="dom.vr.enabled",
|
||||
HeaderFile="mozilla/dom/VRDisplay.h"]
|
||||
interface VRPose
|
||||
{
|
||||
/**
|
||||
* position, linearVelocity, and linearAcceleration are 3-component vectors.
|
||||
* position is relative to a sitting space. Transforming this point with
|
||||
* VRStageParameters.sittingToStandingTransform converts this to standing space.
|
||||
*/
|
||||
[Constant, Throws] readonly attribute Float32Array? position;
|
||||
[Constant, Throws] readonly attribute Float32Array? linearVelocity;
|
||||
[Constant, Throws] readonly attribute Float32Array? linearAcceleration;
|
||||
|
||||
/* orientation is a 4-entry array representing the components of a quaternion. */
|
||||
[Constant, Throws] readonly attribute Float32Array? orientation;
|
||||
/* angularVelocity and angularAcceleration are the components of 3-dimensional vectors. */
|
||||
[Constant, Throws] readonly attribute Float32Array? angularVelocity;
|
||||
[Constant, Throws] readonly attribute Float32Array? angularAcceleration;
|
||||
};
|
||||
|
||||
[Constructor,
|
||||
Pref="dom.vr.enabled",
|
||||
HeaderFile="mozilla/dom/VRDisplay.h"]
|
||||
interface VRFrameData {
|
||||
readonly attribute DOMHighResTimeStamp timestamp;
|
||||
|
||||
[Throws, Pure] readonly attribute Float32Array leftProjectionMatrix;
|
||||
[Throws, Pure] readonly attribute Float32Array leftViewMatrix;
|
||||
|
||||
[Throws, Pure] readonly attribute Float32Array rightProjectionMatrix;
|
||||
[Throws, Pure] readonly attribute Float32Array rightViewMatrix;
|
||||
|
||||
[Pure] readonly attribute VRPose pose;
|
||||
};
|
||||
|
||||
[Pref="dom.vr.enabled",
|
||||
HeaderFile="mozilla/dom/VRDisplay.h"]
|
||||
interface VREyeParameters {
|
||||
/**
|
||||
* offset is a 3-component vector representing an offset to
|
||||
* translate the eye. This value may vary from frame
|
||||
* to frame if the user adjusts their headset ipd.
|
||||
*/
|
||||
[Constant, Throws] readonly attribute Float32Array offset;
|
||||
|
||||
/* These values may vary as the user adjusts their headset ipd. */
|
||||
[Constant] readonly attribute VRFieldOfView fieldOfView;
|
||||
|
||||
/**
|
||||
* renderWidth and renderHeight specify the recommended render target
|
||||
* size of each eye viewport, in pixels. If multiple eyes are rendered
|
||||
* in a single render target, then the render target should be made large
|
||||
* enough to fit both viewports.
|
||||
*/
|
||||
[Constant] readonly attribute unsigned long renderWidth;
|
||||
[Constant] readonly attribute unsigned long renderHeight;
|
||||
};
|
||||
|
||||
[Pref="dom.vr.enabled",
|
||||
HeaderFile="mozilla/dom/VRDisplay.h"]
|
||||
interface VRDisplay : EventTarget {
|
||||
readonly attribute boolean isConnected;
|
||||
readonly attribute boolean isPresenting;
|
||||
|
||||
/**
|
||||
* Dictionary of capabilities describing the VRDisplay.
|
||||
*/
|
||||
[Constant] readonly attribute VRDisplayCapabilities capabilities;
|
||||
|
||||
/**
|
||||
* If this VRDisplay supports room-scale experiences, the optional
|
||||
* stage attribute contains details on the room-scale parameters.
|
||||
*/
|
||||
readonly attribute VRStageParameters? stageParameters;
|
||||
|
||||
/* Return the current VREyeParameters for the given eye. */
|
||||
VREyeParameters getEyeParameters(VREye whichEye);
|
||||
|
||||
/**
|
||||
* An identifier for this distinct VRDisplay. Used as an
|
||||
* association point in the Gamepad API.
|
||||
*/
|
||||
[Constant] readonly attribute unsigned long displayId;
|
||||
|
||||
/**
|
||||
* A display name, a user-readable name identifying it.
|
||||
*/
|
||||
[Constant] readonly attribute DOMString displayName;
|
||||
|
||||
/**
|
||||
* Populates the passed VRFrameData with the information required to render
|
||||
* the current frame.
|
||||
*/
|
||||
boolean getFrameData(VRFrameData frameData);
|
||||
|
||||
/**
|
||||
* Return a VRPose containing the future predicted pose of the VRDisplay
|
||||
* when the current frame will be presented. Subsequent calls to getPose()
|
||||
* MUST return a VRPose with the same values until the next call to
|
||||
* submitFrame().
|
||||
*
|
||||
* The VRPose will contain the position, orientation, velocity,
|
||||
* and acceleration of each of these properties.
|
||||
*/
|
||||
[NewObject] VRPose getPose();
|
||||
|
||||
/**
|
||||
* Reset the pose for this display, treating its current position and
|
||||
* orientation as the "origin/zero" values. VRPose.position,
|
||||
* VRPose.orientation, and VRStageParameters.sittingToStandingTransform may be
|
||||
* updated when calling resetPose(). This should be called in only
|
||||
* sitting-space experiences.
|
||||
*/
|
||||
void resetPose();
|
||||
|
||||
/**
|
||||
* z-depth defining the near plane of the eye view frustum
|
||||
* enables mapping of values in the render target depth
|
||||
* attachment to scene coordinates. Initially set to 0.01.
|
||||
*/
|
||||
attribute double depthNear;
|
||||
|
||||
/**
|
||||
* z-depth defining the far plane of the eye view frustum
|
||||
* enables mapping of values in the render target depth
|
||||
* attachment to scene coordinates. Initially set to 10000.0.
|
||||
*/
|
||||
attribute double depthFar;
|
||||
|
||||
/**
|
||||
* The callback passed to `requestAnimationFrame` will be called
|
||||
* any time a new frame should be rendered. When the VRDisplay is
|
||||
* presenting the callback will be called at the native refresh
|
||||
* rate of the HMD. When not presenting this function acts
|
||||
* identically to how window.requestAnimationFrame acts. Content should
|
||||
* make no assumptions of frame rate or vsync behavior as the HMD runs
|
||||
* asynchronously from other displays and at differing refresh rates.
|
||||
*/
|
||||
[Throws] long requestAnimationFrame(FrameRequestCallback callback);
|
||||
|
||||
/**
|
||||
* Passing the value returned by `requestAnimationFrame` to
|
||||
* `cancelAnimationFrame` will unregister the callback.
|
||||
*/
|
||||
[Throws] void cancelAnimationFrame(long handle);
|
||||
|
||||
/**
|
||||
* Begin presenting to the VRDisplay. Must be called in response to a user gesture.
|
||||
* Repeat calls while already presenting will update the VRLayers being displayed.
|
||||
*/
|
||||
[Throws] Promise<void> requestPresent(sequence<VRLayer> layers);
|
||||
|
||||
/**
|
||||
* Stops presenting to the VRDisplay.
|
||||
*/
|
||||
[Throws] Promise<void> exitPresent();
|
||||
|
||||
/**
|
||||
* Get the layers currently being presented.
|
||||
*/
|
||||
sequence<VRLayer> getLayers();
|
||||
|
||||
/**
|
||||
* The VRLayer provided to the VRDisplay will be captured and presented
|
||||
* in the HMD. Calling this function has the same effect on the source
|
||||
* canvas as any other operation that uses its source image, and canvases
|
||||
* created without preserveDrawingBuffer set to true will be cleared.
|
||||
*/
|
||||
void submitFrame();
|
||||
};
|
||||
@@ -555,7 +555,6 @@ WEBIDL_FILES = [
|
||||
'VideoStreamTrack.webidl',
|
||||
'VideoTrack.webidl',
|
||||
'VideoTrackList.webidl',
|
||||
'VRDisplay.webidl',
|
||||
'VTTCue.webidl',
|
||||
'VTTRegion.webidl',
|
||||
'WaveShaperNode.webidl',
|
||||
|
||||
@@ -28,8 +28,6 @@
|
||||
#include "nsThreadManager.h"
|
||||
#include "prenv.h"
|
||||
#include "ProcessUtils.h"
|
||||
#include "VRManager.h"
|
||||
#include "VRManagerParent.h"
|
||||
#include "VsyncBridgeParent.h"
|
||||
#if defined(XP_WIN)
|
||||
# include "DeviceManagerD3D9.h"
|
||||
@@ -100,7 +98,6 @@ GPUParent::Init(base::ProcessId aParentPid,
|
||||
CompositorThreadHolder::Start();
|
||||
APZThreadUtils::SetControllerThread(CompositorThreadHolder::Loop());
|
||||
APZCTreeManager::InitializeGlobalState();
|
||||
VRManager::ManagerInit();
|
||||
LayerTreeOwnerTracker::Initialize();
|
||||
mozilla::ipc::SetThisProcessName("GPU Process");
|
||||
#ifdef XP_WIN
|
||||
@@ -202,13 +199,6 @@ GPUParent::RecvInitImageBridge(Endpoint<PImageBridgeParent>&& aEndpoint)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
GPUParent::RecvInitVRManager(Endpoint<PVRManagerParent>&& aEndpoint)
|
||||
{
|
||||
VRManagerParent::CreateForGPUProcess(Move(aEndpoint));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
GPUParent::RecvUpdatePref(const GfxPrefSetting& setting)
|
||||
{
|
||||
@@ -301,12 +291,6 @@ GPUParent::RecvNewContentImageBridge(Endpoint<PImageBridgeParent>&& aEndpoint)
|
||||
return ImageBridgeParent::CreateForContent(Move(aEndpoint));
|
||||
}
|
||||
|
||||
bool
|
||||
GPUParent::RecvNewContentVRManager(Endpoint<PVRManagerParent>&& aEndpoint)
|
||||
{
|
||||
return VRManagerParent::CreateForContent(Move(aEndpoint));
|
||||
}
|
||||
|
||||
bool
|
||||
GPUParent::RecvNewContentVideoDecoderManager(Endpoint<PVideoDecoderManagerParent>&& aEndpoint)
|
||||
{
|
||||
|
||||
@@ -32,7 +32,6 @@ public:
|
||||
const DevicePrefs& devicePrefs) override;
|
||||
bool RecvInitVsyncBridge(Endpoint<PVsyncBridgeParent>&& aVsyncEndpoint) override;
|
||||
bool RecvInitImageBridge(Endpoint<PImageBridgeParent>&& aEndpoint) override;
|
||||
bool RecvInitVRManager(Endpoint<PVRManagerParent>&& aEndpoint) override;
|
||||
bool RecvUpdatePref(const GfxPrefSetting& pref) override;
|
||||
bool RecvUpdateVar(const GfxVarUpdate& pref) override;
|
||||
bool RecvNewWidgetCompositor(
|
||||
@@ -43,7 +42,6 @@ public:
|
||||
const IntSize& aSurfaceSize) override;
|
||||
bool RecvNewContentCompositorBridge(Endpoint<PCompositorBridgeParent>&& aEndpoint) override;
|
||||
bool RecvNewContentImageBridge(Endpoint<PImageBridgeParent>&& aEndpoint) override;
|
||||
bool RecvNewContentVRManager(Endpoint<PVRManagerParent>&& aEndpoint) override;
|
||||
bool RecvNewContentVideoDecoderManager(Endpoint<PVideoDecoderManagerParent>&& aEndpoint) override;
|
||||
bool RecvGetDeviceStatus(GPUDeviceData* aOutStatus) override;
|
||||
bool RecvAddLayerTreeIdMapping(nsTArray<LayerTreeIdMapping>&& aMappings) override;
|
||||
|
||||
@@ -22,8 +22,6 @@
|
||||
#endif
|
||||
#include "nsBaseWidget.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "VRManagerChild.h"
|
||||
#include "VRManagerParent.h"
|
||||
#include "VsyncBridgeChild.h"
|
||||
#include "VsyncIOThreadHolder.h"
|
||||
#include "VsyncSource.h"
|
||||
@@ -196,36 +194,6 @@ GPUProcessManager::EnsureImageBridgeChild()
|
||||
ImageBridgeChild::InitWithGPUProcess(Move(childPipe));
|
||||
}
|
||||
|
||||
void
|
||||
GPUProcessManager::EnsureVRManager()
|
||||
{
|
||||
if (VRManagerChild::IsCreated()) {
|
||||
return;
|
||||
}
|
||||
|
||||
EnsureGPUReady();
|
||||
|
||||
if (!mGPUChild) {
|
||||
VRManagerChild::InitSameProcess();
|
||||
return;
|
||||
}
|
||||
|
||||
ipc::Endpoint<PVRManagerParent> parentPipe;
|
||||
ipc::Endpoint<PVRManagerChild> childPipe;
|
||||
nsresult rv = PVRManager::CreateEndpoints(
|
||||
mGPUChild->OtherPid(),
|
||||
base::GetCurrentProcId(),
|
||||
&parentPipe,
|
||||
&childPipe);
|
||||
if (NS_FAILED(rv)) {
|
||||
DisableGPUProcess("Failed to create PVRManager endpoints");
|
||||
return;
|
||||
}
|
||||
|
||||
mGPUChild->SendInitVRManager(Move(parentPipe));
|
||||
VRManagerChild::InitWithGPUProcess(Move(childPipe));
|
||||
}
|
||||
|
||||
void
|
||||
GPUProcessManager::OnProcessLaunchComplete(GPUProcessHost* aHost)
|
||||
{
|
||||
@@ -488,7 +456,6 @@ GPUProcessManager::CreateTopLevelCompositor(nsBaseWidget* aWidget,
|
||||
|
||||
EnsureGPUReady();
|
||||
EnsureImageBridgeChild();
|
||||
EnsureVRManager();
|
||||
|
||||
if (mGPUChild) {
|
||||
RefPtr<CompositorSession> session = CreateRemoteSession(
|
||||
@@ -599,12 +566,10 @@ bool
|
||||
GPUProcessManager::CreateContentBridges(base::ProcessId aOtherProcess,
|
||||
ipc::Endpoint<PCompositorBridgeChild>* aOutCompositor,
|
||||
ipc::Endpoint<PImageBridgeChild>* aOutImageBridge,
|
||||
ipc::Endpoint<PVRManagerChild>* aOutVRBridge,
|
||||
ipc::Endpoint<dom::PVideoDecoderManagerChild>* aOutVideoManager)
|
||||
{
|
||||
if (!CreateContentCompositorBridge(aOtherProcess, aOutCompositor) ||
|
||||
!CreateContentImageBridge(aOtherProcess, aOutImageBridge) ||
|
||||
!CreateContentVRManager(aOtherProcess, aOutVRBridge))
|
||||
!CreateContentImageBridge(aOtherProcess, aOutImageBridge))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -692,40 +657,6 @@ GPUProcessManager::GPUProcessPid()
|
||||
return gpuPid;
|
||||
}
|
||||
|
||||
bool
|
||||
GPUProcessManager::CreateContentVRManager(base::ProcessId aOtherProcess,
|
||||
ipc::Endpoint<PVRManagerChild>* aOutEndpoint)
|
||||
{
|
||||
EnsureVRManager();
|
||||
|
||||
base::ProcessId gpuPid = mGPUChild
|
||||
? mGPUChild->OtherPid()
|
||||
: base::GetCurrentProcId();
|
||||
|
||||
ipc::Endpoint<PVRManagerParent> parentPipe;
|
||||
ipc::Endpoint<PVRManagerChild> childPipe;
|
||||
nsresult rv = PVRManager::CreateEndpoints(
|
||||
gpuPid,
|
||||
aOtherProcess,
|
||||
&parentPipe,
|
||||
&childPipe);
|
||||
if (NS_FAILED(rv)) {
|
||||
gfxCriticalNote << "Could not create content compositor bridge: " << hexa(int(rv));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (mGPUChild) {
|
||||
mGPUChild->SendNewContentVRManager(Move(parentPipe));
|
||||
} else {
|
||||
if (!VRManagerParent::CreateForContent(Move(parentPipe))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
*aOutEndpoint = Move(childPipe);
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
GPUProcessManager::CreateContentVideoDecoderManager(base::ProcessId aOtherProcess,
|
||||
ipc::Endpoint<dom::PVideoDecoderManagerChild>* aOutEndpoint)
|
||||
|
||||
@@ -45,7 +45,6 @@ namespace gfx {
|
||||
|
||||
class GPUChild;
|
||||
class GPUProcessListener;
|
||||
class PVRManagerChild;
|
||||
class VsyncBridgeChild;
|
||||
class VsyncIOThreadHolder;
|
||||
|
||||
@@ -91,7 +90,6 @@ public:
|
||||
base::ProcessId aOtherProcess,
|
||||
ipc::Endpoint<PCompositorBridgeChild>* aOutCompositor,
|
||||
ipc::Endpoint<PImageBridgeChild>* aOutImageBridge,
|
||||
ipc::Endpoint<PVRManagerChild>* aOutVRBridge,
|
||||
ipc::Endpoint<dom::PVideoDecoderManagerChild>* aOutVideoManager);
|
||||
|
||||
// This returns a reference to the APZCTreeManager to which
|
||||
@@ -156,8 +154,6 @@ private:
|
||||
ipc::Endpoint<PCompositorBridgeChild>* aOutEndpoint);
|
||||
bool CreateContentImageBridge(base::ProcessId aOtherProcess,
|
||||
ipc::Endpoint<PImageBridgeChild>* aOutEndpoint);
|
||||
bool CreateContentVRManager(base::ProcessId aOtherProcess,
|
||||
ipc::Endpoint<PVRManagerChild>* aOutEndpoint);
|
||||
void CreateContentVideoDecoderManager(base::ProcessId aOtherProcess,
|
||||
ipc::Endpoint<dom::PVideoDecoderManagerChild>* aOutEndPoint);
|
||||
|
||||
@@ -182,7 +178,6 @@ private:
|
||||
void ShutdownVsyncIOThread();
|
||||
|
||||
void EnsureImageBridgeChild();
|
||||
void EnsureVRManager();
|
||||
|
||||
RefPtr<CompositorSession> CreateRemoteSession(
|
||||
nsBaseWidget* aWidget,
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
include GraphicsMessages;
|
||||
include protocol PCompositorBridge;
|
||||
include protocol PImageBridge;
|
||||
include protocol PVRManager;
|
||||
include protocol PVsyncBridge;
|
||||
include protocol PVideoDecoderManager;
|
||||
|
||||
@@ -47,7 +46,6 @@ parent:
|
||||
|
||||
async InitVsyncBridge(Endpoint<PVsyncBridgeParent> endpoint);
|
||||
async InitImageBridge(Endpoint<PImageBridgeParent> endpoint);
|
||||
async InitVRManager(Endpoint<PVRManagerParent> endpoint);
|
||||
|
||||
// Called to update a gfx preference or variable.
|
||||
async UpdatePref(GfxPrefSetting pref);
|
||||
@@ -63,7 +61,6 @@ parent:
|
||||
// Create a new content-process compositor bridge.
|
||||
async NewContentCompositorBridge(Endpoint<PCompositorBridgeParent> endpoint);
|
||||
async NewContentImageBridge(Endpoint<PImageBridgeParent> endpoint);
|
||||
async NewContentVRManager(Endpoint<PVRManagerParent> endpoint);
|
||||
async NewContentVideoDecoderManager(Endpoint<PVideoDecoderManagerParent> endpoint);
|
||||
|
||||
// Called to notify the GPU process of who owns a layersId.
|
||||
|
||||
@@ -1160,8 +1160,7 @@ CompositingRenderTargetD3D11::CompositingRenderTargetD3D11(ID3D11Texture2D* aTex
|
||||
mFormatOverride = aFormatOverride;
|
||||
|
||||
// If we happen to have a typeless underlying DXGI surface, we need to be explicit
|
||||
// about the format here. (Such a surface could come from an external source, such
|
||||
// as the Oculus compositor)
|
||||
// about the format here. (Such a surface could come from an external source)
|
||||
CD3D11_RENDER_TARGET_VIEW_DESC rtvDesc(D3D11_RTV_DIMENSION_TEXTURE2D, mFormatOverride);
|
||||
D3D11_RENDER_TARGET_VIEW_DESC *desc = aFormatOverride == DXGI_FORMAT_UNKNOWN ? nullptr : &rtvDesc;
|
||||
|
||||
|
||||
@@ -30,7 +30,6 @@
|
||||
#include "mozilla/gfx/2D.h" // for DrawTarget
|
||||
#include "mozilla/gfx/Point.h" // for IntSize
|
||||
#include "mozilla/gfx/Rect.h" // for IntSize
|
||||
#include "VRManager.h" // for VRManager
|
||||
#include "mozilla/ipc/Transport.h" // for Transport
|
||||
#include "mozilla/layers/APZCTreeManager.h" // for APZCTreeManager
|
||||
#include "mozilla/layers/APZCTreeManagerParent.h" // for APZCTreeManagerParent
|
||||
@@ -475,7 +474,6 @@ CompositorVsyncScheduler::Composite(TimeStamp aVsyncTimestamp)
|
||||
}
|
||||
|
||||
DispatchTouchEvents(aVsyncTimestamp);
|
||||
DispatchVREvents(aVsyncTimestamp);
|
||||
|
||||
if (mNeedsComposite || mAsapScheduling) {
|
||||
mNeedsComposite = 0;
|
||||
@@ -541,15 +539,6 @@ CompositorVsyncScheduler::DispatchTouchEvents(TimeStamp aVsyncTimestamp)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
CompositorVsyncScheduler::DispatchVREvents(TimeStamp aVsyncTimestamp)
|
||||
{
|
||||
MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
|
||||
|
||||
VRManager* vm = VRManager::Get();
|
||||
vm->NotifyVsync(aVsyncTimestamp);
|
||||
}
|
||||
|
||||
void
|
||||
CompositorVsyncScheduler::ScheduleTask(already_AddRefed<CancelableRunnable> aTask,
|
||||
int aTime)
|
||||
|
||||
@@ -12,11 +12,6 @@
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
namespace gfx {
|
||||
// See VRManagerChild.cpp
|
||||
void ReleaseVRManagerParentSingleton();
|
||||
} // namespace gfx
|
||||
|
||||
namespace layers {
|
||||
|
||||
static StaticRefPtr<CompositorThreadHolder> sCompositorThreadHolder;
|
||||
@@ -130,7 +125,6 @@ CompositorThreadHolder::Shutdown()
|
||||
MOZ_ASSERT(sCompositorThreadHolder, "The compositor thread has already been shut down!");
|
||||
|
||||
ReleaseImageBridgeParentSingleton();
|
||||
gfx::ReleaseVRManagerParentSingleton();
|
||||
MediaSystemResourceService::Shutdown();
|
||||
|
||||
sCompositorThreadHolder = nullptr;
|
||||
|
||||
@@ -30,7 +30,6 @@
|
||||
#include "mozilla/gfx/2D.h" // for DrawTarget
|
||||
#include "mozilla/gfx/Point.h" // for IntSize
|
||||
#include "mozilla/gfx/Rect.h" // for IntSize
|
||||
#include "VRManager.h" // for VRManager
|
||||
#include "mozilla/ipc/Transport.h" // for Transport
|
||||
#include "mozilla/layers/APZCTreeManager.h" // for APZCTreeManager
|
||||
#include "mozilla/layers/APZCTreeManagerParent.h" // for APZCTreeManagerParent
|
||||
|
||||
@@ -9,7 +9,6 @@ include LayersSurfaces;
|
||||
include protocol PLayerTransaction;
|
||||
include protocol PCompositorBridge;
|
||||
include protocol PImageBridge;
|
||||
include protocol PVRManager;
|
||||
include protocol PVideoBridge;
|
||||
include "mozilla/GfxMessageUtils.h";
|
||||
|
||||
@@ -23,7 +22,7 @@ namespace layers {
|
||||
* PTexture is the IPDL glue between a TextureClient and a TextureHost.
|
||||
*/
|
||||
sync protocol PTexture {
|
||||
manager PImageBridge or PCompositorBridge or PVRManager or PVideoBridge;
|
||||
manager PImageBridge or PCompositorBridge or PVideoBridge;
|
||||
|
||||
child:
|
||||
async __delete__();
|
||||
|
||||
@@ -20,7 +20,6 @@ DIRS += [
|
||||
'ots/src',
|
||||
'thebes',
|
||||
'ipc',
|
||||
'vr',
|
||||
'config',
|
||||
]
|
||||
|
||||
|
||||
@@ -131,8 +131,6 @@ class mozilla::gl::SkiaGLGlue : public GenericAtomicRefCounted {
|
||||
#include "SoftwareVsyncSource.h"
|
||||
#include "nscore.h" // for NS_FREE_PERMANENT_DATA
|
||||
#include "mozilla/dom/ContentChild.h"
|
||||
#include "gfxVR.h"
|
||||
#include "VRManagerChild.h"
|
||||
#include "mozilla/gfx/GPUParent.h"
|
||||
#include "prsystem.h"
|
||||
|
||||
@@ -492,8 +490,6 @@ gfxPlatform::gfxPlatform()
|
||||
contentMask, BackendType::CAIRO);
|
||||
|
||||
mTotalSystemMemory = PR_GetPhysicalMemorySize();
|
||||
|
||||
VRManager::ManagerInit();
|
||||
}
|
||||
|
||||
gfxPlatform*
|
||||
@@ -900,14 +896,12 @@ gfxPlatform::ShutdownLayersIPC()
|
||||
sLayersIPCIsUp = false;
|
||||
|
||||
if (XRE_IsContentProcess()) {
|
||||
gfx::VRManagerChild::ShutDown();
|
||||
// cf bug 1215265.
|
||||
if (gfxPrefs::ChildProcessShutdown()) {
|
||||
layers::CompositorBridgeChild::ShutDown();
|
||||
layers::ImageBridgeChild::ShutDown();
|
||||
}
|
||||
} else if (XRE_IsParentProcess()) {
|
||||
gfx::VRManagerChild::ShutDown();
|
||||
layers::CompositorBridgeChild::ShutDown();
|
||||
layers::ImageBridgeChild::ShutDown();
|
||||
|
||||
|
||||
@@ -1,143 +0,0 @@
|
||||
/* -*- 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/. */
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "prlink.h"
|
||||
#include "prmem.h"
|
||||
#include "prenv.h"
|
||||
#include "gfxPrefs.h"
|
||||
#include "nsString.h"
|
||||
#include "mozilla/Preferences.h"
|
||||
#include "mozilla/Unused.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
#include "nsIScreenManager.h"
|
||||
|
||||
#ifdef XP_WIN
|
||||
#include "../layers/d3d11/CompositorD3D11.h"
|
||||
#endif
|
||||
|
||||
#include "VRDisplayClient.h"
|
||||
#include "VRDisplayPresentation.h"
|
||||
#include "VRManagerChild.h"
|
||||
#include "VRLayerChild.h"
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::gfx;
|
||||
|
||||
VRDisplayClient::VRDisplayClient(const VRDisplayInfo& aDisplayInfo)
|
||||
: mDisplayInfo(aDisplayInfo)
|
||||
, bLastEventWasPresenting(false)
|
||||
, mPresentationCount(0)
|
||||
{
|
||||
MOZ_COUNT_CTOR(VRDisplayClient);
|
||||
}
|
||||
|
||||
VRDisplayClient::~VRDisplayClient() {
|
||||
MOZ_COUNT_DTOR(VRDisplayClient);
|
||||
}
|
||||
|
||||
void
|
||||
VRDisplayClient::UpdateDisplayInfo(const VRDisplayInfo& aDisplayInfo)
|
||||
{
|
||||
mDisplayInfo = aDisplayInfo;
|
||||
}
|
||||
|
||||
already_AddRefed<VRDisplayPresentation>
|
||||
VRDisplayClient::BeginPresentation(const nsTArray<mozilla::dom::VRLayer>& aLayers)
|
||||
{
|
||||
++mPresentationCount;
|
||||
RefPtr<VRDisplayPresentation> presentation = new VRDisplayPresentation(this, aLayers);
|
||||
return presentation.forget();
|
||||
}
|
||||
|
||||
void
|
||||
VRDisplayClient::PresentationDestroyed()
|
||||
{
|
||||
--mPresentationCount;
|
||||
}
|
||||
|
||||
void
|
||||
VRDisplayClient::ZeroSensor()
|
||||
{
|
||||
VRManagerChild *vm = VRManagerChild::Get();
|
||||
vm->SendResetSensor(mDisplayInfo.mDisplayID);
|
||||
}
|
||||
|
||||
VRHMDSensorState
|
||||
VRDisplayClient::GetSensorState()
|
||||
{
|
||||
VRHMDSensorState sensorState;
|
||||
VRManagerChild *vm = VRManagerChild::Get();
|
||||
Unused << vm->SendGetSensorState(mDisplayInfo.mDisplayID, &sensorState);
|
||||
return sensorState;
|
||||
}
|
||||
|
||||
VRHMDSensorState
|
||||
VRDisplayClient::GetImmediateSensorState()
|
||||
{
|
||||
VRHMDSensorState sensorState;
|
||||
|
||||
VRManagerChild *vm = VRManagerChild::Get();
|
||||
Unused << vm->SendGetImmediateSensorState(mDisplayInfo.mDisplayID, &sensorState);
|
||||
return sensorState;
|
||||
}
|
||||
|
||||
const double kVRDisplayRAFMaxDuration = 32; // milliseconds
|
||||
|
||||
void
|
||||
VRDisplayClient::NotifyVsync()
|
||||
{
|
||||
VRManagerChild *vm = VRManagerChild::Get();
|
||||
|
||||
bool isPresenting = GetIsPresenting();
|
||||
|
||||
bool bShouldCallback = !isPresenting;
|
||||
if (mLastVSyncTime.IsNull()) {
|
||||
bShouldCallback = true;
|
||||
} else {
|
||||
TimeDuration duration = TimeStamp::Now() - mLastVSyncTime;
|
||||
if (duration.ToMilliseconds() > kVRDisplayRAFMaxDuration) {
|
||||
bShouldCallback = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (bShouldCallback) {
|
||||
vm->RunFrameRequestCallbacks();
|
||||
mLastVSyncTime = TimeStamp::Now();
|
||||
}
|
||||
|
||||
// Check if we need to trigger onVRDisplayPresentChange event
|
||||
if (bLastEventWasPresenting != isPresenting) {
|
||||
bLastEventWasPresenting = isPresenting;
|
||||
vm->FireDOMVRDisplayPresentChangeEvent();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
VRDisplayClient::NotifyVRVsync()
|
||||
{
|
||||
VRManagerChild *vm = VRManagerChild::Get();
|
||||
vm->RunFrameRequestCallbacks();
|
||||
mLastVSyncTime = TimeStamp::Now();
|
||||
}
|
||||
|
||||
bool
|
||||
VRDisplayClient::GetIsConnected() const
|
||||
{
|
||||
return mDisplayInfo.GetIsConnected();
|
||||
}
|
||||
|
||||
bool
|
||||
VRDisplayClient::GetIsPresenting() const
|
||||
{
|
||||
return mDisplayInfo.GetIsPresenting();
|
||||
}
|
||||
|
||||
void
|
||||
VRDisplayClient::NotifyDisconnected()
|
||||
{
|
||||
mDisplayInfo.mIsConnected = false;
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
/* -*- 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_DISPLAY_CLIENT_H
|
||||
#define GFX_VR_DISPLAY_CLIENT_H
|
||||
|
||||
#include "nsIScreen.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "mozilla/RefPtr.h"
|
||||
#include "mozilla/dom/VRDisplayBinding.h"
|
||||
|
||||
#include "gfxVR.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace gfx {
|
||||
class VRDisplayPresentation;
|
||||
class VRManagerChild;
|
||||
|
||||
class VRDisplayClient
|
||||
{
|
||||
public:
|
||||
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VRDisplayClient)
|
||||
|
||||
explicit VRDisplayClient(const VRDisplayInfo& aDisplayInfo);
|
||||
|
||||
void UpdateDisplayInfo(const VRDisplayInfo& aDisplayInfo);
|
||||
|
||||
const VRDisplayInfo& GetDisplayInfo() const { return mDisplayInfo; }
|
||||
virtual VRHMDSensorState GetSensorState();
|
||||
virtual VRHMDSensorState GetImmediateSensorState();
|
||||
|
||||
virtual void ZeroSensor();
|
||||
|
||||
already_AddRefed<VRDisplayPresentation> BeginPresentation(const nsTArray<dom::VRLayer>& aLayers);
|
||||
void PresentationDestroyed();
|
||||
|
||||
void NotifyVsync();
|
||||
void NotifyVRVsync();
|
||||
|
||||
bool GetIsConnected() const;
|
||||
bool GetIsPresenting() const;
|
||||
|
||||
void NotifyDisconnected();
|
||||
|
||||
protected:
|
||||
virtual ~VRDisplayClient();
|
||||
|
||||
VRDisplayInfo mDisplayInfo;
|
||||
|
||||
bool bLastEventWasPresenting;
|
||||
|
||||
TimeStamp mLastVSyncTime;
|
||||
int mPresentationCount;
|
||||
};
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace mozilla
|
||||
|
||||
#endif /* GFX_VR_DISPLAY_CLIENT_H */
|
||||
@@ -1,201 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; 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/. */
|
||||
|
||||
#include "VRDisplayHost.h"
|
||||
#include "gfxVR.h"
|
||||
|
||||
#if defined(XP_WIN)
|
||||
|
||||
#include <d3d11.h>
|
||||
#include "gfxWindowsPlatform.h"
|
||||
#include "../layers/d3d11/CompositorD3D11.h"
|
||||
#include "mozilla/layers/TextureD3D11.h"
|
||||
|
||||
#endif
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::gfx;
|
||||
using namespace mozilla::layers;
|
||||
|
||||
VRDisplayHost::VRDisplayHost(VRDeviceType aType)
|
||||
: mInputFrameID(0)
|
||||
{
|
||||
MOZ_COUNT_CTOR(VRDisplayHost);
|
||||
mDisplayInfo.mType = aType;
|
||||
mDisplayInfo.mDisplayID = VRDisplayManager::AllocateDisplayID();
|
||||
mDisplayInfo.mIsPresenting = false;
|
||||
|
||||
for (int i = 0; i < kMaxLatencyFrames; i++) {
|
||||
mLastSensorState[i].Clear();
|
||||
}
|
||||
}
|
||||
|
||||
VRDisplayHost::~VRDisplayHost()
|
||||
{
|
||||
MOZ_COUNT_DTOR(VRDisplayHost);
|
||||
}
|
||||
|
||||
void
|
||||
VRDisplayHost::AddLayer(VRLayerParent *aLayer)
|
||||
{
|
||||
mLayers.AppendElement(aLayer);
|
||||
if (mLayers.Length() == 1) {
|
||||
StartPresentation();
|
||||
}
|
||||
mDisplayInfo.mIsPresenting = mLayers.Length() > 0;
|
||||
|
||||
// Ensure that the content process receives the change immediately
|
||||
VRManager* vm = VRManager::Get();
|
||||
vm->RefreshVRDisplays();
|
||||
}
|
||||
|
||||
void
|
||||
VRDisplayHost::RemoveLayer(VRLayerParent *aLayer)
|
||||
{
|
||||
mLayers.RemoveElement(aLayer);
|
||||
if (mLayers.Length() == 0) {
|
||||
StopPresentation();
|
||||
}
|
||||
mDisplayInfo.mIsPresenting = mLayers.Length() > 0;
|
||||
|
||||
// Ensure that the content process receives the change immediately
|
||||
VRManager* vm = VRManager::Get();
|
||||
vm->RefreshVRDisplays();
|
||||
}
|
||||
|
||||
#if defined(XP_WIN)
|
||||
|
||||
void
|
||||
VRDisplayHost::SubmitFrame(VRLayerParent* aLayer, const int32_t& aInputFrameID,
|
||||
PTextureParent* aTexture, const gfx::Rect& aLeftEyeRect,
|
||||
const gfx::Rect& aRightEyeRect)
|
||||
{
|
||||
// aInputFrameID is no longer controlled by content with the WebVR 1.1 API
|
||||
// update; however, we will later use this code to enable asynchronous
|
||||
// submission of multiple layers to be composited. This will enable
|
||||
// us to build browser UX that remains responsive even when content does
|
||||
// not consistently submit frames.
|
||||
|
||||
int32_t inputFrameID = aInputFrameID;
|
||||
if (inputFrameID == 0) {
|
||||
inputFrameID = mInputFrameID;
|
||||
}
|
||||
if (inputFrameID < 0) {
|
||||
// Sanity check to prevent invalid memory access on builds with assertions
|
||||
// disabled.
|
||||
inputFrameID = 0;
|
||||
}
|
||||
|
||||
VRHMDSensorState sensorState = mLastSensorState[inputFrameID % kMaxLatencyFrames];
|
||||
// It is possible to get a cache miss on mLastSensorState if latency is
|
||||
// longer than kMaxLatencyFrames. An optimization would be to find a frame
|
||||
// that is closer than the one selected with the modulus.
|
||||
// If we hit this; however, latency is already so high that the site is
|
||||
// un-viewable and a more accurate pose prediction is not likely to
|
||||
// compensate.
|
||||
|
||||
TextureHost* th = TextureHost::AsTextureHost(aTexture);
|
||||
// WebVR doesn't use the compositor to compose the frame, so use
|
||||
// AutoLockTextureHostWithoutCompositor here.
|
||||
AutoLockTextureHostWithoutCompositor autoLock(th);
|
||||
if (autoLock.Failed()) {
|
||||
NS_WARNING("Failed to lock the VR layer texture");
|
||||
return;
|
||||
}
|
||||
|
||||
CompositableTextureSourceRef source;
|
||||
if (!th->BindTextureSource(source)) {
|
||||
NS_WARNING("The TextureHost was successfully locked but can't provide a TextureSource");
|
||||
return;
|
||||
}
|
||||
MOZ_ASSERT(source);
|
||||
|
||||
IntSize texSize = source->GetSize();
|
||||
|
||||
TextureSourceD3D11* sourceD3D11 = source->AsSourceD3D11();
|
||||
if (!sourceD3D11) {
|
||||
NS_WARNING("WebVR support currently only implemented for D3D11");
|
||||
return;
|
||||
}
|
||||
|
||||
SubmitFrame(sourceD3D11, texSize, sensorState, aLeftEyeRect, aRightEyeRect);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
void
|
||||
VRDisplayHost::SubmitFrame(VRLayerParent* aLayer, const int32_t& aInputFrameID,
|
||||
PTextureParent* aTexture, const gfx::Rect& aLeftEyeRect,
|
||||
const gfx::Rect& aRightEyeRect)
|
||||
{
|
||||
NS_WARNING("WebVR only supported in Windows.");
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
bool
|
||||
VRDisplayHost::CheckClearDisplayInfoDirty()
|
||||
{
|
||||
if (mDisplayInfo == mLastUpdateDisplayInfo) {
|
||||
return false;
|
||||
}
|
||||
mLastUpdateDisplayInfo = mDisplayInfo;
|
||||
return true;
|
||||
}
|
||||
|
||||
VRControllerHost::VRControllerHost(VRDeviceType aType)
|
||||
{
|
||||
MOZ_COUNT_CTOR(VRControllerHost);
|
||||
mControllerInfo.mType = aType;
|
||||
mControllerInfo.mControllerID = VRDisplayManager::AllocateDisplayID();
|
||||
}
|
||||
|
||||
VRControllerHost::~VRControllerHost()
|
||||
{
|
||||
MOZ_COUNT_DTOR(VRControllerHost);
|
||||
}
|
||||
|
||||
const VRControllerInfo&
|
||||
VRControllerHost::GetControllerInfo() const
|
||||
{
|
||||
return mControllerInfo;
|
||||
}
|
||||
|
||||
void
|
||||
VRControllerHost::SetIndex(uint32_t aIndex)
|
||||
{
|
||||
mIndex = aIndex;
|
||||
}
|
||||
|
||||
uint32_t
|
||||
VRControllerHost::GetIndex()
|
||||
{
|
||||
return mIndex;
|
||||
}
|
||||
|
||||
void
|
||||
VRControllerHost::SetButtonPressed(uint64_t aBit)
|
||||
{
|
||||
mButtonPressed = aBit;
|
||||
}
|
||||
|
||||
uint64_t
|
||||
VRControllerHost::GetButtonPressed()
|
||||
{
|
||||
return mButtonPressed;
|
||||
}
|
||||
|
||||
void
|
||||
VRControllerHost::SetPose(const dom::GamepadPoseState& aPose)
|
||||
{
|
||||
mPose = aPose;
|
||||
}
|
||||
|
||||
const dom::GamepadPoseState&
|
||||
VRControllerHost::GetPose()
|
||||
{
|
||||
return mPose;
|
||||
}
|
||||
|
||||
@@ -1,114 +0,0 @@
|
||||
/* -*- 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_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"
|
||||
#include "mozilla/dom/GamepadPoseState.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace layers {
|
||||
class PTextureParent;
|
||||
#if defined(XP_WIN)
|
||||
class TextureSourceD3D11;
|
||||
#endif
|
||||
} // namespace layers
|
||||
namespace gfx {
|
||||
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 VRHMDSensorState GetSensorState() = 0;
|
||||
virtual VRHMDSensorState GetImmediateSensorState() = 0;
|
||||
virtual void ZeroSensor() = 0;
|
||||
virtual void StartPresentation() = 0;
|
||||
virtual void StopPresentation() = 0;
|
||||
virtual void NotifyVSync() { };
|
||||
|
||||
void SubmitFrame(VRLayerParent* aLayer,
|
||||
const int32_t& aInputFrameID,
|
||||
mozilla::layers::PTextureParent* aTexture,
|
||||
const gfx::Rect& aLeftEyeRect,
|
||||
const gfx::Rect& aRightEyeRect);
|
||||
|
||||
bool CheckClearDisplayInfoDirty();
|
||||
|
||||
protected:
|
||||
explicit VRDisplayHost(VRDeviceType aType);
|
||||
virtual ~VRDisplayHost();
|
||||
|
||||
#if defined(XP_WIN)
|
||||
virtual void SubmitFrame(mozilla::layers::TextureSourceD3D11* aSource,
|
||||
const IntSize& aSize,
|
||||
const VRHMDSensorState& aSensorState,
|
||||
const gfx::Rect& aLeftEyeRect,
|
||||
const gfx::Rect& aRightEyeRect) = 0;
|
||||
#endif
|
||||
|
||||
VRDisplayInfo mDisplayInfo;
|
||||
|
||||
nsTArray<RefPtr<VRLayerParent>> mLayers;
|
||||
// Weak reference to mLayers entries are cleared in VRLayerParent destructor
|
||||
|
||||
// The maximum number of frames of latency that we would expect before we
|
||||
// should give up applying pose prediction.
|
||||
// If latency is greater than one second, then the experience is not likely
|
||||
// to be corrected by pose prediction. Setting this value too
|
||||
// high may result in unnecessary memory allocation.
|
||||
// As the current fastest refresh rate is 90hz, 100 is selected as a
|
||||
// conservative value.
|
||||
static const int kMaxLatencyFrames = 100;
|
||||
VRHMDSensorState mLastSensorState[kMaxLatencyFrames];
|
||||
int32_t mInputFrameID;
|
||||
|
||||
private:
|
||||
VRDisplayInfo mLastUpdateDisplayInfo;
|
||||
};
|
||||
|
||||
class VRControllerHost {
|
||||
public:
|
||||
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VRControllerHost)
|
||||
|
||||
const VRControllerInfo& GetControllerInfo() const;
|
||||
void SetIndex(uint32_t aIndex);
|
||||
uint32_t GetIndex();
|
||||
void SetButtonPressed(uint64_t aBit);
|
||||
uint64_t GetButtonPressed();
|
||||
void SetPose(const dom::GamepadPoseState& aPose);
|
||||
const dom::GamepadPoseState& GetPose();
|
||||
|
||||
protected:
|
||||
explicit VRControllerHost(VRDeviceType aType);
|
||||
virtual ~VRControllerHost();
|
||||
|
||||
VRControllerInfo mControllerInfo;
|
||||
// The controller index in VRControllerManager.
|
||||
uint32_t mIndex;
|
||||
// The current button pressed bit of button mask.
|
||||
uint64_t mButtonPressed;
|
||||
dom::GamepadPoseState mPose;
|
||||
};
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace mozilla
|
||||
|
||||
#endif /* GFX_VR_DISPLAY_HOST_H */
|
||||
@@ -1,112 +0,0 @@
|
||||
/* -*- 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/. */
|
||||
|
||||
#include "VRDisplayPresentation.h"
|
||||
|
||||
#include "mozilla/Unused.h"
|
||||
#include "VRDisplayClient.h"
|
||||
#include "VRLayerChild.h"
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::gfx;
|
||||
|
||||
VRDisplayPresentation::VRDisplayPresentation(VRDisplayClient *aDisplayClient,
|
||||
const nsTArray<mozilla::dom::VRLayer>& aLayers)
|
||||
: mDisplayClient(aDisplayClient)
|
||||
, mDOMLayers(aLayers)
|
||||
{
|
||||
CreateLayers();
|
||||
}
|
||||
|
||||
void
|
||||
VRDisplayPresentation::CreateLayers()
|
||||
{
|
||||
if (mLayers.Length()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (dom::VRLayer& layer : mDOMLayers) {
|
||||
dom::HTMLCanvasElement* canvasElement = layer.mSource;
|
||||
if (!canvasElement) {
|
||||
/// XXX In the future we will support WebVR in WebWorkers here
|
||||
continue;
|
||||
}
|
||||
|
||||
Rect leftBounds(0.0, 0.0, 0.5, 1.0);
|
||||
if (layer.mLeftBounds.Length() == 4) {
|
||||
leftBounds.x = layer.mLeftBounds[0];
|
||||
leftBounds.y = layer.mLeftBounds[1];
|
||||
leftBounds.width = layer.mLeftBounds[2];
|
||||
leftBounds.height = layer.mLeftBounds[3];
|
||||
} else if (layer.mLeftBounds.Length() != 0) {
|
||||
/**
|
||||
* We ignore layers with an incorrect number of values.
|
||||
* In the future, VRDisplay.requestPresent may throw in
|
||||
* this case. See https://github.com/w3c/webvr/issues/71
|
||||
*/
|
||||
continue;
|
||||
}
|
||||
|
||||
Rect rightBounds(0.5, 0.0, 0.5, 1.0);
|
||||
if (layer.mRightBounds.Length() == 4) {
|
||||
rightBounds.x = layer.mRightBounds[0];
|
||||
rightBounds.y = layer.mRightBounds[1];
|
||||
rightBounds.width = layer.mRightBounds[2];
|
||||
rightBounds.height = layer.mRightBounds[3];
|
||||
} else if (layer.mRightBounds.Length() != 0) {
|
||||
/**
|
||||
* We ignore layers with an incorrect number of values.
|
||||
* In the future, VRDisplay.requestPresent may throw in
|
||||
* this case. See https://github.com/w3c/webvr/issues/71
|
||||
*/
|
||||
continue;
|
||||
}
|
||||
|
||||
VRManagerChild *manager = VRManagerChild::Get();
|
||||
if (!manager) {
|
||||
NS_WARNING("VRManagerChild::Get returned null!");
|
||||
continue;
|
||||
}
|
||||
|
||||
RefPtr<VRLayerChild> vrLayer = static_cast<VRLayerChild*>(manager->CreateVRLayer(mDisplayClient->GetDisplayInfo().GetDisplayID(), leftBounds, rightBounds));
|
||||
if (!vrLayer) {
|
||||
NS_WARNING("CreateVRLayer returned null!");
|
||||
continue;
|
||||
}
|
||||
|
||||
vrLayer->Initialize(canvasElement);
|
||||
|
||||
mLayers.AppendElement(vrLayer);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
VRDisplayPresentation::DestroyLayers()
|
||||
{
|
||||
for (VRLayerChild* layer : mLayers) {
|
||||
Unused << layer->SendDestroy();
|
||||
}
|
||||
mLayers.Clear();
|
||||
}
|
||||
|
||||
void
|
||||
VRDisplayPresentation::GetDOMLayers(nsTArray<dom::VRLayer>& result)
|
||||
{
|
||||
result = mDOMLayers;
|
||||
}
|
||||
|
||||
VRDisplayPresentation::~VRDisplayPresentation()
|
||||
{
|
||||
DestroyLayers();
|
||||
mDisplayClient->PresentationDestroyed();
|
||||
}
|
||||
|
||||
void VRDisplayPresentation::SubmitFrame()
|
||||
{
|
||||
for (VRLayerChild *layer : mLayers) {
|
||||
layer->SubmitFrame();
|
||||
break; // Currently only one layer supported, submit only the first
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
/* -*- 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_DISPLAY_PRESENTATION_H
|
||||
#define GFX_VR_DISPLAY_PRESENTATION_H
|
||||
|
||||
#include "mozilla/RefPtr.h"
|
||||
#include "mozilla/dom/VRDisplayBinding.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace gfx {
|
||||
class VRDisplayClient;
|
||||
class VRLayerChild;
|
||||
|
||||
class VRDisplayPresentation final
|
||||
{
|
||||
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VRDisplayPresentation)
|
||||
|
||||
public:
|
||||
VRDisplayPresentation(VRDisplayClient *aDisplayClient, const nsTArray<dom::VRLayer>& aLayers);
|
||||
void SubmitFrame();
|
||||
void GetDOMLayers(nsTArray<dom::VRLayer>& result);
|
||||
|
||||
private:
|
||||
~VRDisplayPresentation();
|
||||
void CreateLayers();
|
||||
void DestroyLayers();
|
||||
|
||||
RefPtr<VRDisplayClient> mDisplayClient;
|
||||
nsTArray<dom::VRLayer> mDOMLayers;
|
||||
nsTArray<RefPtr<VRLayerChild>> mLayers;
|
||||
};
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace mozilla
|
||||
|
||||
#endif /* GFX_VR_DISPLAY_PRESENTAITON_H */
|
||||
@@ -1,393 +0,0 @@
|
||||
/* -*- 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/. */
|
||||
|
||||
|
||||
#include "VRManager.h"
|
||||
#include "VRManagerParent.h"
|
||||
#include "gfxVR.h"
|
||||
#include "gfxVROpenVR.h"
|
||||
#include "mozilla/ClearOnShutdown.h"
|
||||
#include "mozilla/dom/VRDisplay.h"
|
||||
#include "mozilla/dom/GamepadEventTypes.h"
|
||||
#include "mozilla/layers/TextureHost.h"
|
||||
#include "mozilla/Unused.h"
|
||||
|
||||
#include "gfxPrefs.h"
|
||||
#include "gfxVR.h"
|
||||
#if defined(XP_WIN)
|
||||
#include "gfxVROculus.h"
|
||||
#endif
|
||||
#if defined(XP_WIN) || defined(XP_MACOSX) || defined(XP_LINUX)
|
||||
#include "gfxVROSVR.h"
|
||||
#endif
|
||||
#include "ipc/VRLayerParent.h"
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::gfx;
|
||||
using namespace mozilla::layers;
|
||||
using namespace mozilla::gl;
|
||||
|
||||
namespace mozilla {
|
||||
namespace gfx {
|
||||
|
||||
static StaticRefPtr<VRManager> sVRManagerSingleton;
|
||||
|
||||
/*static*/ void
|
||||
VRManager::ManagerInit()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
if (sVRManagerSingleton == nullptr) {
|
||||
sVRManagerSingleton = new VRManager();
|
||||
ClearOnShutdown(&sVRManagerSingleton);
|
||||
}
|
||||
}
|
||||
|
||||
VRManager::VRManager()
|
||||
: mInitialized(false)
|
||||
{
|
||||
MOZ_COUNT_CTOR(VRManager);
|
||||
MOZ_ASSERT(sVRManagerSingleton == nullptr);
|
||||
|
||||
RefPtr<VRDisplayManager> mgr;
|
||||
RefPtr<VRControllerManager> controllerMgr;
|
||||
|
||||
/**
|
||||
* We must add the VRDisplayManager's to mManagers in a careful order to
|
||||
* ensure that we don't detect the same VRDisplay from multiple API's.
|
||||
*
|
||||
* Oculus comes first, as it will only enumerate Oculus HMD's and is the
|
||||
* native interface for Oculus HMD's.
|
||||
*
|
||||
* OpenvR comes second, as it is the native interface for HTC Vive
|
||||
* which is the most common HMD at this time.
|
||||
*
|
||||
* OSVR will be used if Oculus SDK and OpenVR don't detect any HMDS,
|
||||
* to support everyone else.
|
||||
*/
|
||||
|
||||
#if defined(XP_WIN)
|
||||
// The Oculus runtime is supported only on Windows
|
||||
mgr = VRDisplayManagerOculus::Create();
|
||||
if (mgr) {
|
||||
mManagers.AppendElement(mgr);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(XP_WIN) || defined(XP_MACOSX) || defined(XP_LINUX)
|
||||
// OpenVR is cross platform compatible
|
||||
mgr = VRDisplayManagerOpenVR::Create();
|
||||
if (mgr) {
|
||||
mManagers.AppendElement(mgr);
|
||||
}
|
||||
|
||||
controllerMgr = VRControllerManagerOpenVR::Create();
|
||||
if (mgr) {
|
||||
mControllerManagers.AppendElement(controllerMgr);
|
||||
}
|
||||
|
||||
// OSVR is cross platform compatible
|
||||
mgr = VRDisplayManagerOSVR::Create();
|
||||
if (mgr) {
|
||||
mManagers.AppendElement(mgr);
|
||||
}
|
||||
#endif
|
||||
// Enable gamepad extensions while VR is enabled.
|
||||
if (gfxPrefs::VREnabled()) {
|
||||
Preferences::SetBool("dom.gamepad.extensions.enabled", true);
|
||||
}
|
||||
}
|
||||
|
||||
VRManager::~VRManager()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(!mInitialized);
|
||||
MOZ_COUNT_DTOR(VRManager);
|
||||
}
|
||||
|
||||
void
|
||||
VRManager::Destroy()
|
||||
{
|
||||
mVRDisplays.Clear();
|
||||
for (uint32_t i = 0; i < mManagers.Length(); ++i) {
|
||||
mManagers[i]->Destroy();
|
||||
}
|
||||
|
||||
mVRControllers.Clear();
|
||||
for (uint32_t i = 0; i < mControllerManagers.Length(); ++i) {
|
||||
mControllerManagers[i]->Destroy();
|
||||
}
|
||||
mInitialized = false;
|
||||
}
|
||||
|
||||
void
|
||||
VRManager::Init()
|
||||
{
|
||||
for (uint32_t i = 0; i < mManagers.Length(); ++i) {
|
||||
mManagers[i]->Init();
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < mControllerManagers.Length(); ++i) {
|
||||
mControllerManagers[i]->Init();
|
||||
}
|
||||
mInitialized = true;
|
||||
}
|
||||
|
||||
/* static */VRManager*
|
||||
VRManager::Get()
|
||||
{
|
||||
MOZ_ASSERT(sVRManagerSingleton != nullptr);
|
||||
|
||||
return sVRManagerSingleton;
|
||||
}
|
||||
|
||||
void
|
||||
VRManager::AddVRManagerParent(VRManagerParent* aVRManagerParent)
|
||||
{
|
||||
if (mVRManagerParents.IsEmpty()) {
|
||||
Init();
|
||||
}
|
||||
mVRManagerParents.PutEntry(aVRManagerParent);
|
||||
}
|
||||
|
||||
void
|
||||
VRManager::RemoveVRManagerParent(VRManagerParent* aVRManagerParent)
|
||||
{
|
||||
mVRManagerParents.RemoveEntry(aVRManagerParent);
|
||||
if (mVRManagerParents.IsEmpty()) {
|
||||
Destroy();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
VRManager::NotifyVsync(const TimeStamp& aVsyncTimestamp)
|
||||
{
|
||||
const double kVRDisplayRefreshMaxDuration = 5000; // milliseconds
|
||||
|
||||
bool bHaveEventListener = false;
|
||||
|
||||
for (auto iter = mVRManagerParents.Iter(); !iter.Done(); iter.Next()) {
|
||||
VRManagerParent *vmp = iter.Get()->GetKey();
|
||||
if (mVRDisplays.Count()) {
|
||||
Unused << vmp->SendNotifyVSync();
|
||||
}
|
||||
bHaveEventListener |= vmp->HaveEventListener();
|
||||
}
|
||||
|
||||
for (auto iter = mVRDisplays.Iter(); !iter.Done(); iter.Next()) {
|
||||
gfx::VRDisplayHost* display = iter.UserData();
|
||||
display->NotifyVSync();
|
||||
}
|
||||
|
||||
if (bHaveEventListener) {
|
||||
for (uint32_t i = 0; i < mControllerManagers.Length(); ++i) {
|
||||
mControllerManagers[i]->HandleInput();
|
||||
}
|
||||
// If content has set an EventHandler to be notified of VR display events
|
||||
// we must continually refresh the VR display enumeration to check
|
||||
// for events that we must fire such as Window.onvrdisplayconnect
|
||||
// Note that enumeration itself may activate display hardware, such
|
||||
// as Oculus, so we only do this when we know we are displaying content
|
||||
// that is looking for VR displays.
|
||||
if (mLastRefreshTime.IsNull()) {
|
||||
// This is the first vsync, must refresh VR displays
|
||||
RefreshVRDisplays();
|
||||
RefreshVRControllers();
|
||||
mLastRefreshTime = TimeStamp::Now();
|
||||
} else {
|
||||
// We don't have to do this every frame, so check if we
|
||||
// have refreshed recently.
|
||||
TimeDuration duration = TimeStamp::Now() - mLastRefreshTime;
|
||||
if (duration.ToMilliseconds() > kVRDisplayRefreshMaxDuration) {
|
||||
RefreshVRDisplays();
|
||||
RefreshVRControllers();
|
||||
mLastRefreshTime = TimeStamp::Now();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
VRManager::NotifyVRVsync(const uint32_t& aDisplayID)
|
||||
{
|
||||
for (auto iter = mVRManagerParents.Iter(); !iter.Done(); iter.Next()) {
|
||||
Unused << iter.Get()->GetKey()->SendNotifyVRVSync(aDisplayID);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
VRManager::RefreshVRDisplays(bool aMustDispatch)
|
||||
{
|
||||
nsTArray<RefPtr<gfx::VRDisplayHost> > displays;
|
||||
|
||||
/** We don't wish to enumerate the same display from multiple managers,
|
||||
* so stop as soon as we get a display.
|
||||
* It is still possible to get multiple displays from a single manager,
|
||||
* but do not wish to mix-and-match for risk of reporting a duplicate.
|
||||
*
|
||||
* XXX - Perhaps there will be a better way to detect duplicate displays
|
||||
* in the future.
|
||||
*/
|
||||
for (uint32_t i = 0; i < mManagers.Length() && displays.Length() == 0; ++i) {
|
||||
mManagers[i]->GetHMDs(displays);
|
||||
}
|
||||
|
||||
bool displayInfoChanged = false;
|
||||
|
||||
if (displays.Length() != mVRDisplays.Count()) {
|
||||
// Catch cases where a VR display has been removed
|
||||
displayInfoChanged = true;
|
||||
}
|
||||
|
||||
for (const auto& display: displays) {
|
||||
if (!GetDisplay(display->GetDisplayInfo().GetDisplayID())) {
|
||||
// This is a new display
|
||||
displayInfoChanged = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (display->CheckClearDisplayInfoDirty()) {
|
||||
// This display's info has changed
|
||||
displayInfoChanged = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (displayInfoChanged) {
|
||||
mVRDisplays.Clear();
|
||||
for (const auto& display: displays) {
|
||||
mVRDisplays.Put(display->GetDisplayInfo().GetDisplayID(), display);
|
||||
}
|
||||
}
|
||||
|
||||
if (displayInfoChanged || aMustDispatch) {
|
||||
DispatchVRDisplayInfoUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
VRManager::DispatchVRDisplayInfoUpdate()
|
||||
{
|
||||
nsTArray<VRDisplayInfo> update;
|
||||
GetVRDisplayInfo(update);
|
||||
|
||||
for (auto iter = mVRManagerParents.Iter(); !iter.Done(); iter.Next()) {
|
||||
Unused << iter.Get()->GetKey()->SendUpdateDisplayInfo(update);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get any VR displays that have already been enumerated without
|
||||
* activating any new devices.
|
||||
*/
|
||||
void
|
||||
VRManager::GetVRDisplayInfo(nsTArray<VRDisplayInfo>& aDisplayInfo)
|
||||
{
|
||||
aDisplayInfo.Clear();
|
||||
for (auto iter = mVRDisplays.Iter(); !iter.Done(); iter.Next()) {
|
||||
gfx::VRDisplayHost* display = iter.UserData();
|
||||
aDisplayInfo.AppendElement(VRDisplayInfo(display->GetDisplayInfo()));
|
||||
}
|
||||
}
|
||||
|
||||
RefPtr<gfx::VRDisplayHost>
|
||||
VRManager::GetDisplay(const uint32_t& aDisplayID)
|
||||
{
|
||||
RefPtr<gfx::VRDisplayHost> display;
|
||||
if (mVRDisplays.Get(aDisplayID, getter_AddRefs(display))) {
|
||||
return display;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void
|
||||
VRManager::SubmitFrame(VRLayerParent* aLayer, layers::PTextureParent* aTexture,
|
||||
const gfx::Rect& aLeftEyeRect,
|
||||
const gfx::Rect& aRightEyeRect)
|
||||
{
|
||||
TextureHost* th = TextureHost::AsTextureHost(aTexture);
|
||||
mLastFrame = th;
|
||||
RefPtr<VRDisplayHost> display = GetDisplay(aLayer->GetDisplayID());
|
||||
if (display) {
|
||||
display->SubmitFrame(aLayer, 0, aTexture, aLeftEyeRect, aRightEyeRect);
|
||||
}
|
||||
}
|
||||
|
||||
RefPtr<gfx::VRControllerHost>
|
||||
VRManager::GetController(const uint32_t& aControllerID)
|
||||
{
|
||||
RefPtr<gfx::VRControllerHost> controller;
|
||||
if (mVRControllers.Get(aControllerID, getter_AddRefs(controller))) {
|
||||
return controller;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void
|
||||
VRManager::GetVRControllerInfo(nsTArray<VRControllerInfo>& aControllerInfo)
|
||||
{
|
||||
aControllerInfo.Clear();
|
||||
for (auto iter = mVRControllers.Iter(); !iter.Done(); iter.Next()) {
|
||||
gfx::VRControllerHost* controller = iter.UserData();
|
||||
aControllerInfo.AppendElement(VRControllerInfo(controller->GetControllerInfo()));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
VRManager::RefreshVRControllers()
|
||||
{
|
||||
nsTArray<RefPtr<gfx::VRControllerHost>> controllers;
|
||||
|
||||
for (uint32_t i = 0; i < mControllerManagers.Length()
|
||||
&& controllers.Length() == 0; ++i) {
|
||||
mControllerManagers[i]->GetControllers(controllers);
|
||||
}
|
||||
|
||||
bool controllerInfoChanged = false;
|
||||
|
||||
if (controllers.Length() != mVRControllers.Count()) {
|
||||
// Catch cases where VR controllers has been removed
|
||||
controllerInfoChanged = true;
|
||||
}
|
||||
|
||||
for (const auto& controller : controllers) {
|
||||
if (!GetController(controller->GetControllerInfo().GetControllerID())) {
|
||||
// This is a new controller
|
||||
controllerInfoChanged = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (controllerInfoChanged) {
|
||||
mVRControllers.Clear();
|
||||
for (const auto& controller : controllers) {
|
||||
mVRControllers.Put(controller->GetControllerInfo().GetControllerID(),
|
||||
controller);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
VRManager::ScanForDevices()
|
||||
{
|
||||
for (uint32_t i = 0; i < mControllerManagers.Length(); ++i) {
|
||||
mControllerManagers[i]->ScanForDevices();
|
||||
}
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void
|
||||
VRManager::NotifyGamepadChange(const T& aInfo)
|
||||
{
|
||||
dom::GamepadChangeEvent e(aInfo);
|
||||
|
||||
for (auto iter = mVRManagerParents.Iter(); !iter.Done(); iter.Next()) {
|
||||
Unused << iter.Get()->GetKey()->SendGamepadUpdate(e);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace mozilla
|
||||
@@ -1,88 +0,0 @@
|
||||
/* -*- 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_MANAGER_H
|
||||
#define GFX_VR_MANAGER_H
|
||||
|
||||
#include "nsRefPtrHashtable.h"
|
||||
#include "nsTArray.h"
|
||||
#include "nsTHashtable.h"
|
||||
#include "nsDataHashtable.h"
|
||||
#include "mozilla/TimeStamp.h"
|
||||
#include "gfxVR.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace layers {
|
||||
class TextureHost;
|
||||
}
|
||||
namespace gfx {
|
||||
|
||||
class VRLayerParent;
|
||||
class VRManagerParent;
|
||||
class VRDisplayHost;
|
||||
class VRControllerManager;
|
||||
|
||||
class VRManager
|
||||
{
|
||||
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(mozilla::gfx::VRManager)
|
||||
|
||||
public:
|
||||
static void ManagerInit();
|
||||
static VRManager* Get();
|
||||
|
||||
void AddVRManagerParent(VRManagerParent* aVRManagerParent);
|
||||
void RemoveVRManagerParent(VRManagerParent* aVRManagerParent);
|
||||
|
||||
void NotifyVsync(const TimeStamp& aVsyncTimestamp);
|
||||
void NotifyVRVsync(const uint32_t& aDisplayID);
|
||||
void RefreshVRDisplays(bool aMustDispatch = false);
|
||||
void ScanForDevices();
|
||||
template<class T> void NotifyGamepadChange(const T& aInfo);
|
||||
RefPtr<gfx::VRDisplayHost> GetDisplay(const uint32_t& aDisplayID);
|
||||
void GetVRDisplayInfo(nsTArray<VRDisplayInfo>& aDisplayInfo);
|
||||
|
||||
void SubmitFrame(VRLayerParent* aLayer, layers::PTextureParent* aTexture,
|
||||
const gfx::Rect& aLeftEyeRect,
|
||||
const gfx::Rect& aRightEyeRect);
|
||||
RefPtr<gfx::VRControllerHost> GetController(const uint32_t& aControllerID);
|
||||
void GetVRControllerInfo(nsTArray<VRControllerInfo>& aControllerInfo);
|
||||
|
||||
protected:
|
||||
VRManager();
|
||||
~VRManager();
|
||||
|
||||
private:
|
||||
RefPtr<layers::TextureHost> mLastFrame;
|
||||
|
||||
void Init();
|
||||
void Destroy();
|
||||
|
||||
void DispatchVRDisplayInfoUpdate();
|
||||
void RefreshVRControllers();
|
||||
|
||||
typedef nsTHashtable<nsRefPtrHashKey<VRManagerParent>> VRManagerParentSet;
|
||||
VRManagerParentSet mVRManagerParents;
|
||||
|
||||
typedef nsTArray<RefPtr<VRDisplayManager>> VRDisplayManagerArray;
|
||||
VRDisplayManagerArray mManagers;
|
||||
|
||||
typedef nsTArray<RefPtr<VRControllerManager>> VRControllerManagerArray;
|
||||
VRControllerManagerArray mControllerManagers;
|
||||
|
||||
typedef nsRefPtrHashtable<nsUint32HashKey, gfx::VRDisplayHost> VRDisplayHostHashMap;
|
||||
VRDisplayHostHashMap mVRDisplays;
|
||||
|
||||
typedef nsRefPtrHashtable<nsUint32HashKey, gfx::VRControllerHost> VRControllerHostHashMap;
|
||||
VRControllerHostHashMap mVRControllers;
|
||||
|
||||
Atomic<bool> mInitialized;
|
||||
|
||||
TimeStamp mLastRefreshTime;
|
||||
};
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // GFX_VR_MANAGER_H
|
||||
@@ -1,127 +0,0 @@
|
||||
/* -*- 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/. */
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "gfxVR.h"
|
||||
#ifdef MOZ_GAMEPAD
|
||||
#include "mozilla/dom/GamepadEventTypes.h"
|
||||
#include "mozilla/dom/GamepadBinding.h"
|
||||
#endif
|
||||
|
||||
#ifndef M_PI
|
||||
# define M_PI 3.14159265358979323846
|
||||
#endif
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::gfx;
|
||||
|
||||
Atomic<uint32_t> VRDisplayManager::sDisplayBase(0);
|
||||
Atomic<uint32_t> VRControllerManager::sControllerBase(0);
|
||||
|
||||
/* static */ uint32_t
|
||||
VRDisplayManager::AllocateDisplayID()
|
||||
{
|
||||
return ++sDisplayBase;
|
||||
}
|
||||
|
||||
Matrix4x4
|
||||
VRFieldOfView::ConstructProjectionMatrix(float zNear, float zFar,
|
||||
bool rightHanded) const
|
||||
{
|
||||
float upTan = tan(upDegrees * M_PI / 180.0);
|
||||
float downTan = tan(downDegrees * M_PI / 180.0);
|
||||
float leftTan = tan(leftDegrees * M_PI / 180.0);
|
||||
float rightTan = tan(rightDegrees * M_PI / 180.0);
|
||||
|
||||
float handednessScale = rightHanded ? -1.0 : 1.0;
|
||||
|
||||
float pxscale = 2.0f / (leftTan + rightTan);
|
||||
float pxoffset = (leftTan - rightTan) * pxscale * 0.5;
|
||||
float pyscale = 2.0f / (upTan + downTan);
|
||||
float pyoffset = (upTan - downTan) * pyscale * 0.5;
|
||||
|
||||
Matrix4x4 mobj;
|
||||
float *m = &mobj._11;
|
||||
|
||||
m[0*4+0] = pxscale;
|
||||
m[2*4+0] = pxoffset * handednessScale;
|
||||
|
||||
m[1*4+1] = pyscale;
|
||||
m[2*4+1] = -pyoffset * handednessScale;
|
||||
|
||||
m[2*4+2] = zFar / (zNear - zFar) * -handednessScale;
|
||||
m[3*4+2] = (zFar * zNear) / (zNear - zFar);
|
||||
|
||||
m[2*4+3] = handednessScale;
|
||||
m[3*4+3] = 0.0f;
|
||||
|
||||
return mobj;
|
||||
}
|
||||
|
||||
/* static */ uint32_t
|
||||
VRControllerManager::AllocateControllerID()
|
||||
{
|
||||
return ++sControllerBase;
|
||||
}
|
||||
|
||||
void
|
||||
VRControllerManager::AddGamepad(const char* aID, uint32_t aMapping,
|
||||
uint32_t aNumButtons, uint32_t aNumAxes)
|
||||
{
|
||||
dom::GamepadAdded a(NS_ConvertUTF8toUTF16(nsDependentCString(aID)), mControllerCount,
|
||||
aMapping, dom::GamepadServiceType::VR, aNumButtons,
|
||||
aNumAxes);
|
||||
|
||||
VRManager* vm = VRManager::Get();
|
||||
MOZ_ASSERT(vm);
|
||||
vm->NotifyGamepadChange<dom::GamepadAdded>(a);
|
||||
}
|
||||
|
||||
void
|
||||
VRControllerManager::RemoveGamepad(uint32_t aIndex)
|
||||
{
|
||||
dom::GamepadRemoved a(aIndex, dom::GamepadServiceType::VR);
|
||||
|
||||
VRManager* vm = VRManager::Get();
|
||||
MOZ_ASSERT(vm);
|
||||
vm->NotifyGamepadChange<dom::GamepadRemoved>(a);
|
||||
}
|
||||
|
||||
void
|
||||
VRControllerManager::NewButtonEvent(uint32_t aIndex, uint32_t aButton,
|
||||
bool aPressed)
|
||||
{
|
||||
dom::GamepadButtonInformation a(aIndex, dom::GamepadServiceType::VR,
|
||||
aButton, aPressed, aPressed ? 1.0L : 0.0L);
|
||||
|
||||
VRManager* vm = VRManager::Get();
|
||||
MOZ_ASSERT(vm);
|
||||
vm->NotifyGamepadChange<dom::GamepadButtonInformation>(a);
|
||||
}
|
||||
|
||||
void
|
||||
VRControllerManager::NewAxisMove(uint32_t aIndex, uint32_t aAxis,
|
||||
double aValue)
|
||||
{
|
||||
dom::GamepadAxisInformation a(aIndex, dom::GamepadServiceType::VR,
|
||||
aAxis, aValue);
|
||||
|
||||
VRManager* vm = VRManager::Get();
|
||||
MOZ_ASSERT(vm);
|
||||
vm->NotifyGamepadChange<dom::GamepadAxisInformation>(a);
|
||||
}
|
||||
|
||||
void
|
||||
VRControllerManager::NewPoseState(uint32_t aIndex,
|
||||
const dom::GamepadPoseState& aPose)
|
||||
{
|
||||
dom::GamepadPoseInformation a(aIndex, dom::GamepadServiceType::VR,
|
||||
aPose);
|
||||
|
||||
VRManager* vm = VRManager::Get();
|
||||
MOZ_ASSERT(vm);
|
||||
vm->NotifyGamepadChange<dom::GamepadPoseInformation>(a);
|
||||
}
|
||||
-285
@@ -1,285 +0,0 @@
|
||||
/* -*- 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_H
|
||||
#define GFX_VR_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"
|
||||
|
||||
namespace mozilla {
|
||||
namespace layers {
|
||||
class PTextureParent;
|
||||
}
|
||||
namespace dom {
|
||||
enum class GamepadMappingType : uint32_t;
|
||||
struct GamepadPoseState;
|
||||
}
|
||||
namespace gfx {
|
||||
class VRLayerParent;
|
||||
class VRDisplayHost;
|
||||
class VRControllerHost;
|
||||
|
||||
enum class VRDeviceType : uint16_t {
|
||||
Oculus,
|
||||
OpenVR,
|
||||
OSVR,
|
||||
NumVRDeviceTypes
|
||||
};
|
||||
|
||||
enum class VRDisplayCapabilityFlags : uint16_t {
|
||||
Cap_None = 0,
|
||||
/**
|
||||
* Cap_Position is set if the VRDisplay is capable of tracking its position.
|
||||
*/
|
||||
Cap_Position = 1 << 1,
|
||||
/**
|
||||
* Cap_Orientation is set if the VRDisplay is capable of tracking its orientation.
|
||||
*/
|
||||
Cap_Orientation = 1 << 2,
|
||||
/**
|
||||
* Cap_Present is set if the VRDisplay is capable of presenting content to an
|
||||
* HMD or similar device. Can be used to indicate "magic window" devices that
|
||||
* are capable of 6DoF tracking but for which requestPresent is not meaningful.
|
||||
* If false then calls to requestPresent should always fail, and
|
||||
* getEyeParameters should return null.
|
||||
*/
|
||||
Cap_Present = 1 << 3,
|
||||
/**
|
||||
* Cap_External is set if the VRDisplay is separate from the device's
|
||||
* primary display. If presenting VR content will obscure
|
||||
* other content on the device, this should be un-set. When
|
||||
* un-set, the application should not attempt to mirror VR content
|
||||
* or update non-VR UI because that content will not be visible.
|
||||
*/
|
||||
Cap_External = 1 << 4,
|
||||
/**
|
||||
* Cap_AngularAcceleration is set if the VRDisplay is capable of tracking its
|
||||
* angular acceleration.
|
||||
*/
|
||||
Cap_AngularAcceleration = 1 << 5,
|
||||
/**
|
||||
* Cap_LinearAcceleration is set if the VRDisplay is capable of tracking its
|
||||
* linear acceleration.
|
||||
*/
|
||||
Cap_LinearAcceleration = 1 << 6,
|
||||
/**
|
||||
* Cap_StageParameters is set if the VRDisplay is capable of room scale VR
|
||||
* and can report the StageParameters to describe the space.
|
||||
*/
|
||||
Cap_StageParameters = 1 << 7,
|
||||
/**
|
||||
* Cap_All used for validity checking during IPC serialization
|
||||
*/
|
||||
Cap_All = (1 << 8) - 1
|
||||
};
|
||||
|
||||
MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(VRDisplayCapabilityFlags)
|
||||
|
||||
struct VRFieldOfView {
|
||||
VRFieldOfView() {}
|
||||
VRFieldOfView(double up, double right, double down, double left)
|
||||
: upDegrees(up), rightDegrees(right), downDegrees(down), leftDegrees(left)
|
||||
{}
|
||||
|
||||
void SetFromTanRadians(double up, double right, double down, double left)
|
||||
{
|
||||
upDegrees = atan(up) * 180.0 / M_PI;
|
||||
rightDegrees = atan(right) * 180.0 / M_PI;
|
||||
downDegrees = atan(down) * 180.0 / M_PI;
|
||||
leftDegrees = atan(left) * 180.0 / M_PI;
|
||||
}
|
||||
|
||||
bool operator==(const VRFieldOfView& other) const {
|
||||
return other.upDegrees == upDegrees &&
|
||||
other.downDegrees == downDegrees &&
|
||||
other.rightDegrees == rightDegrees &&
|
||||
other.leftDegrees == leftDegrees;
|
||||
}
|
||||
|
||||
bool operator!=(const VRFieldOfView& other) const {
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
bool IsZero() const {
|
||||
return upDegrees == 0.0 ||
|
||||
rightDegrees == 0.0 ||
|
||||
downDegrees == 0.0 ||
|
||||
leftDegrees == 0.0;
|
||||
}
|
||||
|
||||
Matrix4x4 ConstructProjectionMatrix(float zNear, float zFar, bool rightHanded) const;
|
||||
|
||||
double upDegrees;
|
||||
double rightDegrees;
|
||||
double downDegrees;
|
||||
double leftDegrees;
|
||||
};
|
||||
|
||||
struct VRDisplayInfo
|
||||
{
|
||||
VRDeviceType GetType() const { return mType; }
|
||||
uint32_t GetDisplayID() const { return mDisplayID; }
|
||||
const nsCString& GetDisplayName() const { return mDisplayName; }
|
||||
VRDisplayCapabilityFlags GetCapabilities() const { return mCapabilityFlags; }
|
||||
|
||||
const IntSize& SuggestedEyeResolution() const { return mEyeResolution; }
|
||||
const Point3D& GetEyeTranslation(uint32_t whichEye) const { return mEyeTranslation[whichEye]; }
|
||||
const VRFieldOfView& GetEyeFOV(uint32_t whichEye) const { return mEyeFOV[whichEye]; }
|
||||
bool GetIsConnected() const { return mIsConnected; }
|
||||
bool GetIsPresenting() const { return mIsPresenting; }
|
||||
const Size& GetStageSize() const { return mStageSize; }
|
||||
const Matrix4x4& GetSittingToStandingTransform() const { return mSittingToStandingTransform; }
|
||||
|
||||
enum Eye {
|
||||
Eye_Left,
|
||||
Eye_Right,
|
||||
NumEyes
|
||||
};
|
||||
|
||||
uint32_t mDisplayID;
|
||||
VRDeviceType mType;
|
||||
nsCString mDisplayName;
|
||||
VRDisplayCapabilityFlags mCapabilityFlags;
|
||||
VRFieldOfView mEyeFOV[VRDisplayInfo::NumEyes];
|
||||
Point3D mEyeTranslation[VRDisplayInfo::NumEyes];
|
||||
IntSize mEyeResolution;
|
||||
bool mIsConnected;
|
||||
bool mIsPresenting;
|
||||
Size mStageSize;
|
||||
Matrix4x4 mSittingToStandingTransform;
|
||||
|
||||
bool operator==(const VRDisplayInfo& other) const {
|
||||
return mType == other.mType &&
|
||||
mDisplayID == other.mDisplayID &&
|
||||
mDisplayName == other.mDisplayName &&
|
||||
mCapabilityFlags == other.mCapabilityFlags &&
|
||||
mEyeResolution == other.mEyeResolution &&
|
||||
mIsConnected == other.mIsConnected &&
|
||||
mIsPresenting == other.mIsPresenting &&
|
||||
mEyeFOV[0] == other.mEyeFOV[0] &&
|
||||
mEyeFOV[1] == other.mEyeFOV[1] &&
|
||||
mEyeTranslation[0] == other.mEyeTranslation[0] &&
|
||||
mEyeTranslation[1] == other.mEyeTranslation[1] &&
|
||||
mStageSize == other.mStageSize &&
|
||||
mSittingToStandingTransform == other.mSittingToStandingTransform;
|
||||
}
|
||||
|
||||
bool operator!=(const VRDisplayInfo& other) const {
|
||||
return !(*this == other);
|
||||
}
|
||||
};
|
||||
|
||||
struct VRHMDSensorState {
|
||||
double timestamp;
|
||||
int32_t inputFrameID;
|
||||
VRDisplayCapabilityFlags flags;
|
||||
float orientation[4];
|
||||
float position[3];
|
||||
float angularVelocity[3];
|
||||
float angularAcceleration[3];
|
||||
float linearVelocity[3];
|
||||
float linearAcceleration[3];
|
||||
|
||||
void Clear() {
|
||||
memset(this, 0, sizeof(VRHMDSensorState));
|
||||
}
|
||||
};
|
||||
|
||||
class VRDisplayManager {
|
||||
public:
|
||||
static uint32_t AllocateDisplayID();
|
||||
|
||||
protected:
|
||||
static Atomic<uint32_t> sDisplayBase;
|
||||
|
||||
public:
|
||||
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VRDisplayManager)
|
||||
|
||||
virtual bool Init() = 0;
|
||||
virtual void Destroy() = 0;
|
||||
virtual void GetHMDs(nsTArray<RefPtr<VRDisplayHost>>& aHMDResult) = 0;
|
||||
|
||||
protected:
|
||||
VRDisplayManager() { }
|
||||
virtual ~VRDisplayManager() { }
|
||||
};
|
||||
|
||||
struct VRControllerInfo
|
||||
{
|
||||
VRDeviceType GetType() const { return mType; }
|
||||
uint32_t GetControllerID() const { return mControllerID; }
|
||||
const nsCString& GetControllerName() const { return mControllerName; }
|
||||
uint32_t GetMappingType() const { return mMappingType; }
|
||||
uint32_t GetNumButtons() const { return mNumButtons; }
|
||||
uint32_t GetNumAxes() const { return mNumAxes; }
|
||||
|
||||
uint32_t mControllerID;
|
||||
VRDeviceType mType;
|
||||
nsCString mControllerName;
|
||||
uint32_t mMappingType;
|
||||
uint32_t mNumButtons;
|
||||
uint32_t mNumAxes;
|
||||
|
||||
bool operator==(const VRControllerInfo& other) const {
|
||||
return mType == other.mType &&
|
||||
mControllerID == other.mControllerID &&
|
||||
mControllerName == other.mControllerName &&
|
||||
mMappingType == other.mMappingType &&
|
||||
mNumButtons == other.mNumButtons &&
|
||||
mNumAxes == other.mNumAxes;
|
||||
}
|
||||
|
||||
bool operator!=(const VRControllerInfo& other) const {
|
||||
return !(*this == other);
|
||||
}
|
||||
};
|
||||
|
||||
class VRControllerManager {
|
||||
public:
|
||||
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VRControllerManager)
|
||||
|
||||
static uint32_t AllocateControllerID();
|
||||
virtual bool Init() = 0;
|
||||
virtual void Destroy() = 0;
|
||||
virtual void HandleInput() = 0;
|
||||
virtual void GetControllers(nsTArray<RefPtr<VRControllerHost>>& aControllerResult) = 0;
|
||||
virtual void ScanForDevices() = 0;
|
||||
void NewButtonEvent(uint32_t aIndex, uint32_t aButton, bool aPressed);
|
||||
void NewAxisMove(uint32_t aIndex, uint32_t aAxis, double aValue);
|
||||
void NewPoseState(uint32_t aIndex, const dom::GamepadPoseState& aPose);
|
||||
void AddGamepad(const char* aID, uint32_t aMapping,
|
||||
uint32_t aNumButtons, uint32_t aNumAxes);
|
||||
void RemoveGamepad(uint32_t aIndex);
|
||||
|
||||
protected:
|
||||
VRControllerManager() : mInstalled(false), mControllerCount(0) {}
|
||||
virtual ~VRControllerManager() {}
|
||||
|
||||
bool mInstalled;
|
||||
uint32_t mControllerCount;
|
||||
static Atomic<uint32_t> sControllerBase;
|
||||
|
||||
private:
|
||||
virtual void HandleButtonPress(uint32_t aControllerIdx,
|
||||
uint64_t aButtonPressed) = 0;
|
||||
virtual void HandleAxisMove(uint32_t aControllerIdx, uint32_t aAxis,
|
||||
float aValue) = 0;
|
||||
virtual void HandlePoseTracking(uint32_t aControllerIdx,
|
||||
const dom::GamepadPoseState& aPose,
|
||||
VRControllerHost* aController) = 0;
|
||||
};
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace mozilla
|
||||
|
||||
#endif /* GFX_VR_H */
|
||||
@@ -1,529 +0,0 @@
|
||||
/* -*- 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/. */
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "prlink.h"
|
||||
#include "prmem.h"
|
||||
#include "prenv.h"
|
||||
#include "gfxPrefs.h"
|
||||
#include "nsString.h"
|
||||
#include "mozilla/Preferences.h"
|
||||
|
||||
#include "mozilla/gfx/Quaternion.h"
|
||||
|
||||
#ifdef XP_WIN
|
||||
#include "../layers/d3d11/CompositorD3D11.h"
|
||||
#include "../layers/d3d11/TextureD3D11.h"
|
||||
#endif
|
||||
|
||||
#include "gfxVROSVR.h"
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265358979323846
|
||||
#endif
|
||||
|
||||
using namespace mozilla::layers;
|
||||
using namespace mozilla::gfx;
|
||||
using namespace mozilla::gfx::impl;
|
||||
|
||||
namespace {
|
||||
// need to typedef functions that will be used in the code below
|
||||
extern "C" {
|
||||
typedef OSVR_ClientContext (*pfn_osvrClientInit)(
|
||||
const char applicationIdentifier[], uint32_t flags);
|
||||
typedef OSVR_ReturnCode (*pfn_osvrClientShutdown)(OSVR_ClientContext ctx);
|
||||
typedef OSVR_ReturnCode (*pfn_osvrClientUpdate)(OSVR_ClientContext ctx);
|
||||
typedef OSVR_ReturnCode (*pfn_osvrClientCheckStatus)(OSVR_ClientContext ctx);
|
||||
typedef OSVR_ReturnCode (*pfn_osvrClientGetInterface)(
|
||||
OSVR_ClientContext ctx, const char path[], OSVR_ClientInterface* iface);
|
||||
typedef OSVR_ReturnCode (*pfn_osvrClientFreeInterface)(
|
||||
OSVR_ClientContext ctx, OSVR_ClientInterface iface);
|
||||
typedef OSVR_ReturnCode (*pfn_osvrGetOrientationState)(
|
||||
OSVR_ClientInterface iface, OSVR_TimeValue* timestamp,
|
||||
OSVR_OrientationState* state);
|
||||
typedef OSVR_ReturnCode (*pfn_osvrGetPositionState)(OSVR_ClientInterface iface,
|
||||
OSVR_TimeValue* timestamp,
|
||||
OSVR_PositionState* state);
|
||||
typedef OSVR_ReturnCode (*pfn_osvrClientGetDisplay)(OSVR_ClientContext ctx,
|
||||
OSVR_DisplayConfig* disp);
|
||||
typedef OSVR_ReturnCode (*pfn_osvrClientFreeDisplay)(OSVR_DisplayConfig disp);
|
||||
typedef OSVR_ReturnCode (*pfn_osvrClientGetNumEyesForViewer)(
|
||||
OSVR_DisplayConfig disp, OSVR_ViewerCount viewer, OSVR_EyeCount* eyes);
|
||||
typedef OSVR_ReturnCode (*pfn_osvrClientGetViewerEyePose)(
|
||||
OSVR_DisplayConfig disp, OSVR_ViewerCount viewer, OSVR_EyeCount eye,
|
||||
OSVR_Pose3* pose);
|
||||
typedef OSVR_ReturnCode (*pfn_osvrClientGetDisplayDimensions)(
|
||||
OSVR_DisplayConfig disp, OSVR_DisplayInputCount displayInputIndex,
|
||||
OSVR_DisplayDimension* width, OSVR_DisplayDimension* height);
|
||||
typedef OSVR_ReturnCode (
|
||||
*pfn_osvrClientGetViewerEyeSurfaceProjectionClippingPlanes)(
|
||||
OSVR_DisplayConfig disp, OSVR_ViewerCount viewer, OSVR_EyeCount eye,
|
||||
OSVR_SurfaceCount surface, double* left, double* right, double* bottom,
|
||||
double* top);
|
||||
typedef OSVR_ReturnCode (*pfn_osvrClientGetRelativeViewportForViewerEyeSurface)(
|
||||
OSVR_DisplayConfig disp, OSVR_ViewerCount viewer, OSVR_EyeCount eye,
|
||||
OSVR_SurfaceCount surface, OSVR_ViewportDimension* left,
|
||||
OSVR_ViewportDimension* bottom, OSVR_ViewportDimension* width,
|
||||
OSVR_ViewportDimension* height);
|
||||
typedef OSVR_ReturnCode (*pfn_osvrClientGetViewerEyeSurfaceProjectionMatrixf)(
|
||||
OSVR_DisplayConfig disp, OSVR_ViewerCount viewer, OSVR_EyeCount eye,
|
||||
OSVR_SurfaceCount surface, float near, float far,
|
||||
OSVR_MatrixConventions flags, float* matrix);
|
||||
typedef OSVR_ReturnCode (*pfn_osvrClientCheckDisplayStartup)(
|
||||
OSVR_DisplayConfig disp);
|
||||
typedef OSVR_ReturnCode (*pfn_osvrClientSetRoomRotationUsingHead)(
|
||||
OSVR_ClientContext ctx);
|
||||
}
|
||||
|
||||
static pfn_osvrClientInit osvr_ClientInit = nullptr;
|
||||
static pfn_osvrClientShutdown osvr_ClientShutdown = nullptr;
|
||||
static pfn_osvrClientUpdate osvr_ClientUpdate = nullptr;
|
||||
static pfn_osvrClientCheckStatus osvr_ClientCheckStatus = nullptr;
|
||||
static pfn_osvrClientGetInterface osvr_ClientGetInterface = nullptr;
|
||||
static pfn_osvrClientFreeInterface osvr_ClientFreeInterface = nullptr;
|
||||
static pfn_osvrGetOrientationState osvr_GetOrientationState = nullptr;
|
||||
static pfn_osvrGetPositionState osvr_GetPositionState = nullptr;
|
||||
static pfn_osvrClientGetDisplay osvr_ClientGetDisplay = nullptr;
|
||||
static pfn_osvrClientFreeDisplay osvr_ClientFreeDisplay = nullptr;
|
||||
static pfn_osvrClientGetNumEyesForViewer osvr_ClientGetNumEyesForViewer =
|
||||
nullptr;
|
||||
static pfn_osvrClientGetViewerEyePose osvr_ClientGetViewerEyePose = nullptr;
|
||||
static pfn_osvrClientGetDisplayDimensions osvr_ClientGetDisplayDimensions =
|
||||
nullptr;
|
||||
static pfn_osvrClientGetViewerEyeSurfaceProjectionClippingPlanes
|
||||
osvr_ClientGetViewerEyeSurfaceProjectionClippingPlanes = nullptr;
|
||||
static pfn_osvrClientGetRelativeViewportForViewerEyeSurface
|
||||
osvr_ClientGetRelativeViewportForViewerEyeSurface = nullptr;
|
||||
static pfn_osvrClientGetViewerEyeSurfaceProjectionMatrixf
|
||||
osvr_ClientGetViewerEyeSurfaceProjectionMatrixf = nullptr;
|
||||
static pfn_osvrClientCheckDisplayStartup osvr_ClientCheckDisplayStartup =
|
||||
nullptr;
|
||||
static pfn_osvrClientSetRoomRotationUsingHead
|
||||
osvr_ClientSetRoomRotationUsingHead = nullptr;
|
||||
|
||||
bool
|
||||
LoadOSVRRuntime()
|
||||
{
|
||||
static PRLibrary* osvrUtilLib = nullptr;
|
||||
static PRLibrary* osvrCommonLib = nullptr;
|
||||
static PRLibrary* osvrClientLib = nullptr;
|
||||
static PRLibrary* osvrClientKitLib = nullptr;
|
||||
//this looks up the path in the about:config setting, from greprefs.js or modules\libpref\init\all.js
|
||||
nsAdoptingCString osvrUtilPath =
|
||||
mozilla::Preferences::GetCString("gfx.vr.osvr.utilLibPath");
|
||||
nsAdoptingCString osvrCommonPath =
|
||||
mozilla::Preferences::GetCString("gfx.vr.osvr.commonLibPath");
|
||||
nsAdoptingCString osvrClientPath =
|
||||
mozilla::Preferences::GetCString("gfx.vr.osvr.clientLibPath");
|
||||
nsAdoptingCString osvrClientKitPath =
|
||||
mozilla::Preferences::GetCString("gfx.vr.osvr.clientKitLibPath");
|
||||
|
||||
//we need all the libs to be valid
|
||||
if ((!osvrUtilPath) || (!osvrCommonPath) || (!osvrClientPath) ||
|
||||
(!osvrClientKitPath)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
osvrUtilLib = PR_LoadLibrary(osvrUtilPath.BeginReading());
|
||||
osvrCommonLib = PR_LoadLibrary(osvrCommonPath.BeginReading());
|
||||
osvrClientLib = PR_LoadLibrary(osvrClientPath.BeginReading());
|
||||
osvrClientKitLib = PR_LoadLibrary(osvrClientKitPath.BeginReading());
|
||||
|
||||
if (!osvrUtilLib) {
|
||||
printf_stderr("[OSVR] Failed to load OSVR Util library!\n");
|
||||
return false;
|
||||
}
|
||||
if (!osvrCommonLib) {
|
||||
printf_stderr("[OSVR] Failed to load OSVR Common library!\n");
|
||||
return false;
|
||||
}
|
||||
if (!osvrClientLib) {
|
||||
printf_stderr("[OSVR] Failed to load OSVR Client library!\n");
|
||||
return false;
|
||||
}
|
||||
if (!osvrClientKitLib) {
|
||||
printf_stderr("[OSVR] Failed to load OSVR ClientKit library!\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
// make sure all functions that we'll be using are available
|
||||
#define REQUIRE_FUNCTION(_x) \
|
||||
do { \
|
||||
*(void**) & osvr_##_x = \
|
||||
(void*)PR_FindSymbol(osvrClientKitLib, "osvr" #_x); \
|
||||
if (!osvr_##_x) { \
|
||||
printf_stderr("osvr" #_x " symbol missing\n"); \
|
||||
goto fail; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
REQUIRE_FUNCTION(ClientInit);
|
||||
REQUIRE_FUNCTION(ClientShutdown);
|
||||
REQUIRE_FUNCTION(ClientUpdate);
|
||||
REQUIRE_FUNCTION(ClientCheckStatus);
|
||||
REQUIRE_FUNCTION(ClientGetInterface);
|
||||
REQUIRE_FUNCTION(ClientFreeInterface);
|
||||
REQUIRE_FUNCTION(GetOrientationState);
|
||||
REQUIRE_FUNCTION(GetPositionState);
|
||||
REQUIRE_FUNCTION(ClientGetDisplay);
|
||||
REQUIRE_FUNCTION(ClientFreeDisplay);
|
||||
REQUIRE_FUNCTION(ClientGetNumEyesForViewer);
|
||||
REQUIRE_FUNCTION(ClientGetViewerEyePose);
|
||||
REQUIRE_FUNCTION(ClientGetDisplayDimensions);
|
||||
REQUIRE_FUNCTION(ClientGetViewerEyeSurfaceProjectionClippingPlanes);
|
||||
REQUIRE_FUNCTION(ClientGetRelativeViewportForViewerEyeSurface);
|
||||
REQUIRE_FUNCTION(ClientGetViewerEyeSurfaceProjectionMatrixf);
|
||||
REQUIRE_FUNCTION(ClientCheckDisplayStartup);
|
||||
REQUIRE_FUNCTION(ClientSetRoomRotationUsingHead);
|
||||
|
||||
#undef REQUIRE_FUNCTION
|
||||
|
||||
return true;
|
||||
|
||||
fail:
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
mozilla::gfx::VRFieldOfView
|
||||
SetFromTanRadians(double left, double right, double bottom, double top)
|
||||
{
|
||||
mozilla::gfx::VRFieldOfView fovInfo;
|
||||
fovInfo.leftDegrees = atan(left) * 180.0 / M_PI;
|
||||
fovInfo.rightDegrees = atan(right) * 180.0 / M_PI;
|
||||
fovInfo.upDegrees = atan(top) * 180.0 / M_PI;
|
||||
fovInfo.downDegrees = atan(bottom) * 180.0 / M_PI;
|
||||
return fovInfo;
|
||||
}
|
||||
|
||||
VRDisplayOSVR::VRDisplayOSVR(OSVR_ClientContext* context,
|
||||
OSVR_ClientInterface* iface,
|
||||
OSVR_DisplayConfig* display)
|
||||
: VRDisplayHost(VRDeviceType::OSVR)
|
||||
, m_ctx(context)
|
||||
, m_iface(iface)
|
||||
, m_display(display)
|
||||
{
|
||||
|
||||
MOZ_COUNT_CTOR_INHERITED(VRDisplayOSVR, VRDisplayHost);
|
||||
|
||||
mDisplayInfo.mIsConnected = true;
|
||||
mDisplayInfo.mDisplayName.AssignLiteral("OSVR HMD");
|
||||
mDisplayInfo.mCapabilityFlags = VRDisplayCapabilityFlags::Cap_None;
|
||||
mDisplayInfo.mCapabilityFlags =
|
||||
VRDisplayCapabilityFlags::Cap_Orientation | VRDisplayCapabilityFlags::Cap_Position;
|
||||
|
||||
mDisplayInfo.mCapabilityFlags |= VRDisplayCapabilityFlags::Cap_External;
|
||||
mDisplayInfo.mCapabilityFlags |= VRDisplayCapabilityFlags::Cap_Present;
|
||||
|
||||
// XXX OSVR display topology allows for more than one viewer
|
||||
// will assume only one viewer for now (most likely stay that way)
|
||||
|
||||
OSVR_EyeCount numEyes;
|
||||
osvr_ClientGetNumEyesForViewer(*m_display, 0, &numEyes);
|
||||
|
||||
for (uint8_t eye = 0; eye < numEyes; eye++) {
|
||||
double left, right, bottom, top;
|
||||
// XXX for now there is only one surface per eye
|
||||
osvr_ClientGetViewerEyeSurfaceProjectionClippingPlanes(
|
||||
*m_display, 0, eye, 0, &left, &right, &bottom, &top);
|
||||
mDisplayInfo.mEyeFOV[eye] =
|
||||
SetFromTanRadians(-left, right, -bottom, top);
|
||||
}
|
||||
|
||||
// XXX Assuming there is only one display input for now
|
||||
// however, it's possible to have more than one (dSight with 2 HDMI inputs)
|
||||
OSVR_DisplayDimension width, height;
|
||||
osvr_ClientGetDisplayDimensions(*m_display, 0, &width, &height);
|
||||
|
||||
|
||||
for (uint8_t eye = 0; eye < numEyes; eye++) {
|
||||
|
||||
OSVR_ViewportDimension l, b, w, h;
|
||||
osvr_ClientGetRelativeViewportForViewerEyeSurface(*m_display, 0, eye, 0, &l,
|
||||
&b, &w, &h);
|
||||
mDisplayInfo.mEyeResolution.width = w;
|
||||
mDisplayInfo.mEyeResolution.height = h;
|
||||
OSVR_Pose3 eyePose;
|
||||
// Viewer eye pose may not be immediately available, update client context until we get it
|
||||
OSVR_ReturnCode ret =
|
||||
osvr_ClientGetViewerEyePose(*m_display, 0, eye, &eyePose);
|
||||
while (ret != OSVR_RETURN_SUCCESS) {
|
||||
osvr_ClientUpdate(*m_ctx);
|
||||
ret = osvr_ClientGetViewerEyePose(*m_display, 0, eye, &eyePose);
|
||||
}
|
||||
mDisplayInfo.mEyeTranslation[eye].x = eyePose.translation.data[0];
|
||||
mDisplayInfo.mEyeTranslation[eye].y = eyePose.translation.data[1];
|
||||
mDisplayInfo.mEyeTranslation[eye].z = eyePose.translation.data[2];
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
VRDisplayOSVR::Destroy()
|
||||
{
|
||||
// destroy non-owning pointers
|
||||
m_ctx = nullptr;
|
||||
m_iface = nullptr;
|
||||
m_display = nullptr;
|
||||
}
|
||||
|
||||
void
|
||||
VRDisplayOSVR::ZeroSensor()
|
||||
{
|
||||
// recenter pose aka reset yaw
|
||||
osvr_ClientSetRoomRotationUsingHead(*m_ctx);
|
||||
}
|
||||
|
||||
VRHMDSensorState
|
||||
VRDisplayOSVR::GetSensorState()
|
||||
{
|
||||
|
||||
//update client context before anything
|
||||
//this usually goes into app's mainloop
|
||||
osvr_ClientUpdate(*m_ctx);
|
||||
|
||||
VRHMDSensorState result;
|
||||
OSVR_TimeValue timestamp;
|
||||
result.Clear();
|
||||
|
||||
OSVR_OrientationState orientation;
|
||||
|
||||
OSVR_ReturnCode ret =
|
||||
osvr_GetOrientationState(*m_iface, ×tamp, &orientation);
|
||||
|
||||
result.timestamp = timestamp.seconds;
|
||||
|
||||
if (ret == OSVR_RETURN_SUCCESS) {
|
||||
result.flags |= VRDisplayCapabilityFlags::Cap_Orientation;
|
||||
result.orientation[0] = orientation.data[1];
|
||||
result.orientation[1] = orientation.data[2];
|
||||
result.orientation[2] = orientation.data[3];
|
||||
result.orientation[3] = orientation.data[0];
|
||||
}
|
||||
|
||||
OSVR_PositionState position;
|
||||
ret = osvr_GetPositionState(*m_iface, ×tamp, &position);
|
||||
if (ret == OSVR_RETURN_SUCCESS) {
|
||||
result.flags |= VRDisplayCapabilityFlags::Cap_Position;
|
||||
result.position[0] = position.data[0];
|
||||
result.position[1] = position.data[1];
|
||||
result.position[2] = position.data[2];
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
VRHMDSensorState
|
||||
VRDisplayOSVR::GetImmediateSensorState()
|
||||
{
|
||||
return GetSensorState();
|
||||
}
|
||||
|
||||
#if defined(XP_WIN)
|
||||
|
||||
void
|
||||
VRDisplayOSVR::SubmitFrame(TextureSourceD3D11* aSource,
|
||||
const IntSize& aSize,
|
||||
const VRHMDSensorState& aSensorState,
|
||||
const gfx::Rect& aLeftEyeRect,
|
||||
const gfx::Rect& aRightEyeRect)
|
||||
{
|
||||
// XXX Add code to submit frame
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void
|
||||
VRDisplayOSVR::StartPresentation()
|
||||
{
|
||||
// XXX Add code to start VR Presentation
|
||||
}
|
||||
|
||||
void
|
||||
VRDisplayOSVR::StopPresentation()
|
||||
{
|
||||
// XXX Add code to end VR Presentation
|
||||
}
|
||||
|
||||
already_AddRefed<VRDisplayManagerOSVR>
|
||||
VRDisplayManagerOSVR::Create()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
if (!gfxPrefs::VREnabled() || !gfxPrefs::VROSVREnabled()) {
|
||||
return nullptr;
|
||||
}
|
||||
if (!LoadOSVRRuntime()) {
|
||||
return nullptr;
|
||||
}
|
||||
RefPtr<VRDisplayManagerOSVR> manager = new VRDisplayManagerOSVR();
|
||||
return manager.forget();
|
||||
}
|
||||
|
||||
void
|
||||
VRDisplayManagerOSVR::CheckOSVRStatus()
|
||||
{
|
||||
if (mOSVRInitialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
// client context must be initialized first
|
||||
InitializeClientContext();
|
||||
|
||||
// update client context
|
||||
osvr_ClientUpdate(m_ctx);
|
||||
|
||||
// initialize interface and display if they are not initialized yet
|
||||
InitializeInterface();
|
||||
InitializeDisplay();
|
||||
|
||||
// OSVR is fully initialized now
|
||||
if (mClientContextInitialized && mDisplayConfigInitialized &&
|
||||
mInterfaceInitialized) {
|
||||
mOSVRInitialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
VRDisplayManagerOSVR::InitializeClientContext()
|
||||
{
|
||||
// already initialized
|
||||
if (mClientContextInitialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
// first time creating
|
||||
if (!m_ctx) {
|
||||
// get client context
|
||||
m_ctx = osvr_ClientInit("com.osvr.webvr", 0);
|
||||
// update context
|
||||
osvr_ClientUpdate(m_ctx);
|
||||
// verify we are connected
|
||||
if (OSVR_RETURN_SUCCESS == osvr_ClientCheckStatus(m_ctx)) {
|
||||
mClientContextInitialized = true;
|
||||
}
|
||||
}
|
||||
// client context exists but not up and running yet
|
||||
else {
|
||||
// update context
|
||||
osvr_ClientUpdate(m_ctx);
|
||||
if (OSVR_RETURN_SUCCESS == osvr_ClientCheckStatus(m_ctx)) {
|
||||
mClientContextInitialized = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
VRDisplayManagerOSVR::InitializeInterface()
|
||||
{
|
||||
// already initialized
|
||||
if (mInterfaceInitialized) {
|
||||
return;
|
||||
}
|
||||
//Client context must be initialized before getting interface
|
||||
if (mClientContextInitialized) {
|
||||
// m_iface will remain nullptr if no interface is returned
|
||||
if (OSVR_RETURN_SUCCESS ==
|
||||
osvr_ClientGetInterface(m_ctx, "/me/head", &m_iface)) {
|
||||
mInterfaceInitialized = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
VRDisplayManagerOSVR::InitializeDisplay()
|
||||
{
|
||||
// display is fully configured
|
||||
if (mDisplayConfigInitialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
//Client context must be initialized before getting interface
|
||||
if (mClientContextInitialized) {
|
||||
// first time creating display object
|
||||
if (m_display == nullptr) {
|
||||
|
||||
OSVR_ReturnCode ret = osvr_ClientGetDisplay(m_ctx, &m_display);
|
||||
|
||||
if (ret == OSVR_RETURN_SUCCESS) {
|
||||
osvr_ClientUpdate(m_ctx);
|
||||
// display object may have been created but not fully startup
|
||||
if (OSVR_RETURN_SUCCESS == osvr_ClientCheckDisplayStartup(m_display)) {
|
||||
mDisplayConfigInitialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Typically once we get Display object, pose data is available after
|
||||
// clientUpdate but sometimes it takes ~ 200 ms to get
|
||||
// a succesfull connection, so we might have to run a few update cycles
|
||||
} else {
|
||||
|
||||
if (OSVR_RETURN_SUCCESS == osvr_ClientCheckDisplayStartup(m_display)) {
|
||||
mDisplayConfigInitialized = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
VRDisplayManagerOSVR::Init()
|
||||
{
|
||||
|
||||
// OSVR server should be running in the background
|
||||
// It would load plugins and take care of detecting HMDs
|
||||
if (!mOSVRInitialized) {
|
||||
nsIThread* thread = nullptr;
|
||||
NS_GetCurrentThread(&thread);
|
||||
mOSVRThread = already_AddRefed<nsIThread>(thread);
|
||||
|
||||
// initialize client context
|
||||
InitializeClientContext();
|
||||
// try to initialize interface
|
||||
InitializeInterface();
|
||||
// try to initialize display object
|
||||
InitializeDisplay();
|
||||
// verify all components are initialized
|
||||
CheckOSVRStatus();
|
||||
}
|
||||
|
||||
return mOSVRInitialized;
|
||||
}
|
||||
|
||||
void
|
||||
VRDisplayManagerOSVR::Destroy()
|
||||
{
|
||||
if (mOSVRInitialized) {
|
||||
MOZ_ASSERT(NS_GetCurrentThread() == mOSVRThread);
|
||||
mOSVRThread = nullptr;
|
||||
mHMDInfo = nullptr;
|
||||
mOSVRInitialized = false;
|
||||
}
|
||||
// client context may not have been initialized
|
||||
if (m_ctx) {
|
||||
osvr_ClientFreeDisplay(m_display);
|
||||
}
|
||||
// osvr checks that m_ctx or m_iface are not null
|
||||
osvr_ClientFreeInterface(m_ctx, m_iface);
|
||||
osvr_ClientShutdown(m_ctx);
|
||||
}
|
||||
|
||||
void
|
||||
VRDisplayManagerOSVR::GetHMDs(nsTArray<RefPtr<VRDisplayHost>>& aHMDResult)
|
||||
{
|
||||
// make sure context, interface and display are initialized
|
||||
CheckOSVRStatus();
|
||||
|
||||
if (!mOSVRInitialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
mHMDInfo = new VRDisplayOSVR(&m_ctx, &m_iface, &m_display);
|
||||
|
||||
if (mHMDInfo) {
|
||||
aHMDResult.AppendElement(mHMDInfo);
|
||||
}
|
||||
}
|
||||
@@ -1,107 +0,0 @@
|
||||
/* -*- 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_OSVR_H
|
||||
#define GFX_VR_OSVR_H
|
||||
|
||||
#include "nsTArray.h"
|
||||
#include "mozilla/RefPtr.h"
|
||||
#include "nsThreadUtils.h"
|
||||
|
||||
#include "mozilla/gfx/2D.h"
|
||||
#include "mozilla/EnumeratedArray.h"
|
||||
|
||||
#include "VRDisplayHost.h"
|
||||
|
||||
#include <osvr/ClientKit/ClientKitC.h>
|
||||
#include <osvr/ClientKit/DisplayC.h>
|
||||
|
||||
namespace mozilla {
|
||||
namespace gfx {
|
||||
namespace impl {
|
||||
|
||||
class VRDisplayOSVR : public VRDisplayHost
|
||||
{
|
||||
public:
|
||||
VRHMDSensorState GetSensorState() override;
|
||||
VRHMDSensorState GetImmediateSensorState() override;
|
||||
void ZeroSensor() override;
|
||||
|
||||
protected:
|
||||
virtual void StartPresentation() override;
|
||||
virtual void StopPresentation() override;
|
||||
|
||||
#if defined(XP_WIN)
|
||||
virtual void SubmitFrame(TextureSourceD3D11* aSource,
|
||||
const IntSize& aSize,
|
||||
const VRHMDSensorState& aSensorState,
|
||||
const gfx::Rect& aLeftEyeRect,
|
||||
const gfx::Rect& aRightEyeRect) override;
|
||||
#endif
|
||||
|
||||
public:
|
||||
explicit VRDisplayOSVR(OSVR_ClientContext* context,
|
||||
OSVR_ClientInterface* iface,
|
||||
OSVR_DisplayConfig* display);
|
||||
|
||||
protected:
|
||||
virtual ~VRDisplayOSVR()
|
||||
{
|
||||
Destroy();
|
||||
MOZ_COUNT_DTOR_INHERITED(VRDisplayOSVR, VRDisplayHost);
|
||||
}
|
||||
void Destroy();
|
||||
|
||||
OSVR_ClientContext* m_ctx;
|
||||
OSVR_ClientInterface* m_iface;
|
||||
OSVR_DisplayConfig* m_display;
|
||||
};
|
||||
|
||||
} // namespace impl
|
||||
|
||||
class VRDisplayManagerOSVR : public VRDisplayManager
|
||||
{
|
||||
public:
|
||||
static already_AddRefed<VRDisplayManagerOSVR> Create();
|
||||
virtual bool Init() override;
|
||||
virtual void Destroy() override;
|
||||
virtual void GetHMDs(nsTArray<RefPtr<VRDisplayHost>>& aHMDResult) override;
|
||||
|
||||
protected:
|
||||
VRDisplayManagerOSVR()
|
||||
: mOSVRInitialized(false)
|
||||
, mClientContextInitialized(false)
|
||||
, mDisplayConfigInitialized(false)
|
||||
, mInterfaceInitialized(false)
|
||||
, m_ctx(nullptr)
|
||||
, m_iface(nullptr)
|
||||
, m_display(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
RefPtr<impl::VRDisplayOSVR> mHMDInfo;
|
||||
bool mOSVRInitialized;
|
||||
bool mClientContextInitialized;
|
||||
bool mDisplayConfigInitialized;
|
||||
bool mInterfaceInitialized;
|
||||
RefPtr<nsIThread> mOSVRThread;
|
||||
|
||||
OSVR_ClientContext m_ctx;
|
||||
OSVR_ClientInterface m_iface;
|
||||
OSVR_DisplayConfig m_display;
|
||||
|
||||
private:
|
||||
// check if all components are initialized
|
||||
// and if not, it will try to initialize them
|
||||
void CheckOSVRStatus();
|
||||
void InitializeClientContext();
|
||||
void InitializeDisplay();
|
||||
void InitializeInterface();
|
||||
};
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace mozilla
|
||||
|
||||
#endif /* GFX_VR_OSVR_H */
|
||||
@@ -1,896 +0,0 @@
|
||||
/* -*- 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 XP_WIN
|
||||
#error "Oculus 1.3 runtime support only available for Windows"
|
||||
#endif
|
||||
|
||||
#include <math.h>
|
||||
|
||||
|
||||
#include "prlink.h"
|
||||
#include "prmem.h"
|
||||
#include "prenv.h"
|
||||
#include "gfxPrefs.h"
|
||||
#include "nsString.h"
|
||||
#include "mozilla/DebugOnly.h"
|
||||
#include "mozilla/Preferences.h"
|
||||
#include "mozilla/TimeStamp.h"
|
||||
#include "mozilla/gfx/DeviceManagerDx.h"
|
||||
#include "ipc/VRLayerParent.h"
|
||||
|
||||
#include "mozilla/gfx/Quaternion.h"
|
||||
|
||||
#include <d3d11.h>
|
||||
#include "CompositorD3D11.h"
|
||||
#include "TextureD3D11.h"
|
||||
|
||||
#include "gfxVROculus.h"
|
||||
|
||||
/** XXX The DX11 objects and quad blitting could be encapsulated
|
||||
* into a separate object if either Oculus starts supporting
|
||||
* non-Windows platforms or the blit is needed by other HMD\
|
||||
* drivers.
|
||||
* Alternately, we could remove the extra blit for
|
||||
* Oculus as well with some more refactoring.
|
||||
*/
|
||||
|
||||
// See CompositorD3D11Shaders.h
|
||||
struct ShaderBytes { const void* mData; size_t mLength; };
|
||||
extern ShaderBytes sRGBShader;
|
||||
extern ShaderBytes sLayerQuadVS;
|
||||
#ifndef M_PI
|
||||
# define M_PI 3.14159265358979323846
|
||||
#endif
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::gfx;
|
||||
using namespace mozilla::gfx::impl;
|
||||
using namespace mozilla::layers;
|
||||
|
||||
namespace {
|
||||
|
||||
#ifdef OVR_CAPI_LIMITED_MOZILLA
|
||||
static pfn_ovr_Initialize ovr_Initialize = nullptr;
|
||||
static pfn_ovr_Shutdown ovr_Shutdown = nullptr;
|
||||
static pfn_ovr_GetLastErrorInfo ovr_GetLastErrorInfo = nullptr;
|
||||
static pfn_ovr_GetVersionString ovr_GetVersionString = nullptr;
|
||||
static pfn_ovr_TraceMessage ovr_TraceMessage = nullptr;
|
||||
static pfn_ovr_GetHmdDesc ovr_GetHmdDesc = nullptr;
|
||||
static pfn_ovr_GetTrackerCount ovr_GetTrackerCount = nullptr;
|
||||
static pfn_ovr_GetTrackerDesc ovr_GetTrackerDesc = nullptr;
|
||||
static pfn_ovr_Create ovr_Create = nullptr;
|
||||
static pfn_ovr_Destroy ovr_Destroy = nullptr;
|
||||
static pfn_ovr_GetSessionStatus ovr_GetSessionStatus = nullptr;
|
||||
static pfn_ovr_SetTrackingOriginType ovr_SetTrackingOriginType = nullptr;
|
||||
static pfn_ovr_GetTrackingOriginType ovr_GetTrackingOriginType = nullptr;
|
||||
static pfn_ovr_RecenterTrackingOrigin ovr_RecenterTrackingOrigin = nullptr;
|
||||
static pfn_ovr_ClearShouldRecenterFlag ovr_ClearShouldRecenterFlag = nullptr;
|
||||
static pfn_ovr_GetTrackingState ovr_GetTrackingState = nullptr;
|
||||
static pfn_ovr_GetTrackerPose ovr_GetTrackerPose = nullptr;
|
||||
static pfn_ovr_GetInputState ovr_GetInputState = nullptr;
|
||||
static pfn_ovr_GetConnectedControllerTypes ovr_GetConnectedControllerTypes = nullptr;
|
||||
static pfn_ovr_SetControllerVibration ovr_SetControllerVibration = nullptr;
|
||||
static pfn_ovr_GetTextureSwapChainLength ovr_GetTextureSwapChainLength = nullptr;
|
||||
static pfn_ovr_GetTextureSwapChainCurrentIndex ovr_GetTextureSwapChainCurrentIndex = nullptr;
|
||||
static pfn_ovr_GetTextureSwapChainDesc ovr_GetTextureSwapChainDesc = nullptr;
|
||||
static pfn_ovr_CommitTextureSwapChain ovr_CommitTextureSwapChain = nullptr;
|
||||
static pfn_ovr_DestroyTextureSwapChain ovr_DestroyTextureSwapChain = nullptr;
|
||||
static pfn_ovr_DestroyMirrorTexture ovr_DestroyMirrorTexture = nullptr;
|
||||
static pfn_ovr_GetFovTextureSize ovr_GetFovTextureSize = nullptr;
|
||||
static pfn_ovr_GetRenderDesc ovr_GetRenderDesc = nullptr;
|
||||
static pfn_ovr_SubmitFrame ovr_SubmitFrame = nullptr;
|
||||
static pfn_ovr_GetPredictedDisplayTime ovr_GetPredictedDisplayTime = nullptr;
|
||||
static pfn_ovr_GetTimeInSeconds ovr_GetTimeInSeconds = nullptr;
|
||||
static pfn_ovr_GetBool ovr_GetBool = nullptr;
|
||||
static pfn_ovr_SetBool ovr_SetBool = nullptr;
|
||||
static pfn_ovr_GetInt ovr_GetInt = nullptr;
|
||||
static pfn_ovr_SetInt ovr_SetInt = nullptr;
|
||||
static pfn_ovr_GetFloat ovr_GetFloat = nullptr;
|
||||
static pfn_ovr_SetFloat ovr_SetFloat = nullptr;
|
||||
static pfn_ovr_GetFloatArray ovr_GetFloatArray = nullptr;
|
||||
static pfn_ovr_SetFloatArray ovr_SetFloatArray = nullptr;
|
||||
static pfn_ovr_GetString ovr_GetString = nullptr;
|
||||
static pfn_ovr_SetString ovr_SetString = nullptr;
|
||||
|
||||
#ifdef XP_WIN
|
||||
static pfn_ovr_CreateTextureSwapChainDX ovr_CreateTextureSwapChainDX = nullptr;
|
||||
static pfn_ovr_GetTextureSwapChainBufferDX ovr_GetTextureSwapChainBufferDX = nullptr;
|
||||
static pfn_ovr_CreateMirrorTextureDX ovr_CreateMirrorTextureDX = nullptr;
|
||||
static pfn_ovr_GetMirrorTextureBufferDX ovr_GetMirrorTextureBufferDX = nullptr;
|
||||
#endif
|
||||
|
||||
static pfn_ovr_CreateTextureSwapChainGL ovr_CreateTextureSwapChainGL = nullptr;
|
||||
static pfn_ovr_GetTextureSwapChainBufferGL ovr_GetTextureSwapChainBufferGL = nullptr;
|
||||
static pfn_ovr_CreateMirrorTextureGL ovr_CreateMirrorTextureGL = nullptr;
|
||||
static pfn_ovr_GetMirrorTextureBufferGL ovr_GetMirrorTextureBufferGL = nullptr;
|
||||
|
||||
#ifdef HAVE_64BIT_BUILD
|
||||
#define BUILD_BITS 64
|
||||
#else
|
||||
#define BUILD_BITS 32
|
||||
#endif
|
||||
|
||||
#define OVR_PRODUCT_VERSION 1
|
||||
#define OVR_MAJOR_VERSION 3
|
||||
#define OVR_MINOR_VERSION 1
|
||||
|
||||
static bool
|
||||
InitializeOculusCAPI()
|
||||
{
|
||||
static PRLibrary *ovrlib = nullptr;
|
||||
|
||||
if (!ovrlib) {
|
||||
nsTArray<nsCString> libSearchPaths;
|
||||
nsCString libName;
|
||||
nsCString searchPath;
|
||||
|
||||
#if defined(_WIN32)
|
||||
static const char dirSep = '\\';
|
||||
#else
|
||||
static const char dirSep = '/';
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32)
|
||||
static const int pathLen = 260;
|
||||
searchPath.SetCapacity(pathLen);
|
||||
int realLen = ::GetSystemDirectoryA(searchPath.BeginWriting(), pathLen);
|
||||
if (realLen != 0 && realLen < pathLen) {
|
||||
searchPath.SetLength(realLen);
|
||||
libSearchPaths.AppendElement(searchPath);
|
||||
}
|
||||
libName.AppendPrintf("LibOVRRT%d_%d.dll", BUILD_BITS, OVR_PRODUCT_VERSION);
|
||||
#elif defined(__APPLE__)
|
||||
searchPath.Truncate();
|
||||
searchPath.AppendPrintf("/Library/Frameworks/LibOVRRT_%d.framework/Versions/%d", OVR_PRODUCT_VERSION, OVR_MAJOR_VERSION);
|
||||
libSearchPaths.AppendElement(searchPath);
|
||||
|
||||
if (PR_GetEnv("HOME")) {
|
||||
searchPath.Truncate();
|
||||
searchPath.AppendPrintf("%s/Library/Frameworks/LibOVRRT_%d.framework/Versions/%d", PR_GetEnv("HOME"), OVR_PRODUCT_VERSION, OVR_MAJOR_VERSION);
|
||||
libSearchPaths.AppendElement(searchPath);
|
||||
}
|
||||
// The following will match the va_list overload of AppendPrintf if the product version is 0
|
||||
// That's bad times.
|
||||
//libName.AppendPrintf("LibOVRRT_%d", OVR_PRODUCT_VERSION);
|
||||
libName.Append("LibOVRRT_");
|
||||
libName.AppendInt(OVR_PRODUCT_VERSION);
|
||||
#else
|
||||
libSearchPaths.AppendElement(nsCString("/usr/local/lib"));
|
||||
libSearchPaths.AppendElement(nsCString("/usr/lib"));
|
||||
libName.AppendPrintf("libOVRRT%d_%d.so.%d", BUILD_BITS, OVR_PRODUCT_VERSION, OVR_MAJOR_VERSION);
|
||||
#endif
|
||||
|
||||
// If the pref is present, we override libName
|
||||
nsAdoptingCString prefLibPath = mozilla::Preferences::GetCString("dom.vr.ovr_lib_path");
|
||||
if (prefLibPath && prefLibPath.get()) {
|
||||
libSearchPaths.InsertElementsAt(0, 1, prefLibPath);
|
||||
}
|
||||
|
||||
nsAdoptingCString prefLibName = mozilla::Preferences::GetCString("dom.vr.ovr_lib_name");
|
||||
if (prefLibName && prefLibName.get()) {
|
||||
libName.Assign(prefLibName);
|
||||
}
|
||||
|
||||
// search the path/module dir
|
||||
libSearchPaths.InsertElementsAt(0, 1, nsCString());
|
||||
|
||||
// If the env var is present, we override libName
|
||||
if (PR_GetEnv("OVR_LIB_PATH")) {
|
||||
searchPath = PR_GetEnv("OVR_LIB_PATH");
|
||||
libSearchPaths.InsertElementsAt(0, 1, searchPath);
|
||||
}
|
||||
|
||||
if (PR_GetEnv("OVR_LIB_NAME")) {
|
||||
libName = PR_GetEnv("OVR_LIB_NAME");
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < libSearchPaths.Length(); ++i) {
|
||||
nsCString& libPath = libSearchPaths[i];
|
||||
nsCString fullName;
|
||||
if (libPath.Length() == 0) {
|
||||
fullName.Assign(libName);
|
||||
} else {
|
||||
fullName.AppendPrintf("%s%c%s", libPath.BeginReading(), dirSep, libName.BeginReading());
|
||||
}
|
||||
|
||||
ovrlib = PR_LoadLibrary(fullName.BeginReading());
|
||||
if (ovrlib)
|
||||
break;
|
||||
}
|
||||
|
||||
if (!ovrlib) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// was it already initialized?
|
||||
if (ovr_Initialize)
|
||||
return true;
|
||||
|
||||
#define REQUIRE_FUNCTION(_x) do { \
|
||||
*(void **)&_x = (void *) PR_FindSymbol(ovrlib, #_x); \
|
||||
if (!_x) { printf_stderr(#_x " symbol missing\n"); goto fail; } \
|
||||
} while (0)
|
||||
|
||||
REQUIRE_FUNCTION(ovr_Initialize);
|
||||
REQUIRE_FUNCTION(ovr_Shutdown);
|
||||
REQUIRE_FUNCTION(ovr_GetLastErrorInfo);
|
||||
REQUIRE_FUNCTION(ovr_GetVersionString);
|
||||
REQUIRE_FUNCTION(ovr_TraceMessage);
|
||||
REQUIRE_FUNCTION(ovr_GetHmdDesc);
|
||||
REQUIRE_FUNCTION(ovr_GetTrackerCount);
|
||||
REQUIRE_FUNCTION(ovr_GetTrackerDesc);
|
||||
REQUIRE_FUNCTION(ovr_Create);
|
||||
REQUIRE_FUNCTION(ovr_Destroy);
|
||||
REQUIRE_FUNCTION(ovr_GetSessionStatus);
|
||||
REQUIRE_FUNCTION(ovr_SetTrackingOriginType);
|
||||
REQUIRE_FUNCTION(ovr_GetTrackingOriginType);
|
||||
REQUIRE_FUNCTION(ovr_RecenterTrackingOrigin);
|
||||
REQUIRE_FUNCTION(ovr_ClearShouldRecenterFlag);
|
||||
REQUIRE_FUNCTION(ovr_GetTrackingState);
|
||||
REQUIRE_FUNCTION(ovr_GetTrackerPose);
|
||||
REQUIRE_FUNCTION(ovr_GetInputState);
|
||||
REQUIRE_FUNCTION(ovr_GetConnectedControllerTypes);
|
||||
REQUIRE_FUNCTION(ovr_SetControllerVibration);
|
||||
REQUIRE_FUNCTION(ovr_GetTextureSwapChainLength);
|
||||
REQUIRE_FUNCTION(ovr_GetTextureSwapChainCurrentIndex);
|
||||
REQUIRE_FUNCTION(ovr_GetTextureSwapChainDesc);
|
||||
REQUIRE_FUNCTION(ovr_CommitTextureSwapChain);
|
||||
REQUIRE_FUNCTION(ovr_DestroyTextureSwapChain);
|
||||
REQUIRE_FUNCTION(ovr_DestroyMirrorTexture);
|
||||
REQUIRE_FUNCTION(ovr_GetFovTextureSize);
|
||||
REQUIRE_FUNCTION(ovr_GetRenderDesc);
|
||||
REQUIRE_FUNCTION(ovr_SubmitFrame);
|
||||
REQUIRE_FUNCTION(ovr_GetPredictedDisplayTime);
|
||||
REQUIRE_FUNCTION(ovr_GetTimeInSeconds);
|
||||
REQUIRE_FUNCTION(ovr_GetBool);
|
||||
REQUIRE_FUNCTION(ovr_SetBool);
|
||||
REQUIRE_FUNCTION(ovr_GetInt);
|
||||
REQUIRE_FUNCTION(ovr_SetInt);
|
||||
REQUIRE_FUNCTION(ovr_GetFloat);
|
||||
REQUIRE_FUNCTION(ovr_SetFloat);
|
||||
REQUIRE_FUNCTION(ovr_GetFloatArray);
|
||||
REQUIRE_FUNCTION(ovr_SetFloatArray);
|
||||
REQUIRE_FUNCTION(ovr_GetString);
|
||||
REQUIRE_FUNCTION(ovr_SetString);
|
||||
|
||||
#ifdef XP_WIN
|
||||
|
||||
REQUIRE_FUNCTION(ovr_CreateTextureSwapChainDX);
|
||||
REQUIRE_FUNCTION(ovr_GetTextureSwapChainBufferDX);
|
||||
REQUIRE_FUNCTION(ovr_CreateMirrorTextureDX);
|
||||
REQUIRE_FUNCTION(ovr_GetMirrorTextureBufferDX);
|
||||
|
||||
#endif
|
||||
|
||||
REQUIRE_FUNCTION(ovr_CreateTextureSwapChainGL);
|
||||
REQUIRE_FUNCTION(ovr_GetTextureSwapChainBufferGL);
|
||||
REQUIRE_FUNCTION(ovr_CreateMirrorTextureGL);
|
||||
REQUIRE_FUNCTION(ovr_GetMirrorTextureBufferGL);
|
||||
|
||||
#undef REQUIRE_FUNCTION
|
||||
|
||||
return true;
|
||||
|
||||
fail:
|
||||
ovr_Initialize = nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
#else
|
||||
#include <OVR_Version.h>
|
||||
// we're statically linked; it's available
|
||||
static bool InitializeOculusCAPI()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
ovrFovPort
|
||||
ToFovPort(const VRFieldOfView& aFOV)
|
||||
{
|
||||
ovrFovPort fovPort;
|
||||
fovPort.LeftTan = tan(aFOV.leftDegrees * M_PI / 180.0);
|
||||
fovPort.RightTan = tan(aFOV.rightDegrees * M_PI / 180.0);
|
||||
fovPort.UpTan = tan(aFOV.upDegrees * M_PI / 180.0);
|
||||
fovPort.DownTan = tan(aFOV.downDegrees * M_PI / 180.0);
|
||||
return fovPort;
|
||||
}
|
||||
|
||||
VRFieldOfView
|
||||
FromFovPort(const ovrFovPort& aFOV)
|
||||
{
|
||||
VRFieldOfView fovInfo;
|
||||
fovInfo.leftDegrees = atan(aFOV.LeftTan) * 180.0 / M_PI;
|
||||
fovInfo.rightDegrees = atan(aFOV.RightTan) * 180.0 / M_PI;
|
||||
fovInfo.upDegrees = atan(aFOV.UpTan) * 180.0 / M_PI;
|
||||
fovInfo.downDegrees = atan(aFOV.DownTan) * 180.0 / M_PI;
|
||||
return fovInfo;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
VRDisplayOculus::VRDisplayOculus(ovrSession aSession)
|
||||
: VRDisplayHost(VRDeviceType::Oculus)
|
||||
, mSession(aSession)
|
||||
, mTextureSet(nullptr)
|
||||
, mQuadVS(nullptr)
|
||||
, mQuadPS(nullptr)
|
||||
, mLinearSamplerState(nullptr)
|
||||
, mVSConstantBuffer(nullptr)
|
||||
, mPSConstantBuffer(nullptr)
|
||||
, mVertexBuffer(nullptr)
|
||||
, mInputLayout(nullptr)
|
||||
, mIsPresenting(false)
|
||||
{
|
||||
MOZ_COUNT_CTOR_INHERITED(VRDisplayOculus, VRDisplayHost);
|
||||
|
||||
mDisplayInfo.mDisplayName.AssignLiteral("Oculus VR HMD");
|
||||
mDisplayInfo.mIsConnected = true;
|
||||
|
||||
mDesc = ovr_GetHmdDesc(aSession);
|
||||
|
||||
mDisplayInfo.mCapabilityFlags = VRDisplayCapabilityFlags::Cap_None;
|
||||
if (mDesc.AvailableTrackingCaps & ovrTrackingCap_Orientation) {
|
||||
mDisplayInfo.mCapabilityFlags |= VRDisplayCapabilityFlags::Cap_Orientation;
|
||||
mDisplayInfo.mCapabilityFlags |= VRDisplayCapabilityFlags::Cap_AngularAcceleration;
|
||||
}
|
||||
if (mDesc.AvailableTrackingCaps & ovrTrackingCap_Position) {
|
||||
mDisplayInfo.mCapabilityFlags |= VRDisplayCapabilityFlags::Cap_Position;
|
||||
mDisplayInfo.mCapabilityFlags |= VRDisplayCapabilityFlags::Cap_LinearAcceleration;
|
||||
}
|
||||
mDisplayInfo.mCapabilityFlags |= VRDisplayCapabilityFlags::Cap_External;
|
||||
mDisplayInfo.mCapabilityFlags |= VRDisplayCapabilityFlags::Cap_Present;
|
||||
|
||||
mFOVPort[VRDisplayInfo::Eye_Left] = mDesc.DefaultEyeFov[ovrEye_Left];
|
||||
mFOVPort[VRDisplayInfo::Eye_Right] = mDesc.DefaultEyeFov[ovrEye_Right];
|
||||
|
||||
mDisplayInfo.mEyeFOV[VRDisplayInfo::Eye_Left] = FromFovPort(mFOVPort[VRDisplayInfo::Eye_Left]);
|
||||
mDisplayInfo.mEyeFOV[VRDisplayInfo::Eye_Right] = FromFovPort(mFOVPort[VRDisplayInfo::Eye_Right]);
|
||||
|
||||
float pixelsPerDisplayPixel = 1.0;
|
||||
ovrSizei texSize[2];
|
||||
|
||||
// get eye parameters and create the mesh
|
||||
for (uint32_t eye = 0; eye < VRDisplayInfo::NumEyes; eye++) {
|
||||
|
||||
ovrEyeRenderDesc renderDesc = ovr_GetRenderDesc(mSession, (ovrEyeType)eye, mFOVPort[eye]);
|
||||
|
||||
// As of Oculus 0.6.0, the HmdToEyeOffset values are correct and don't need to be negated.
|
||||
mDisplayInfo.mEyeTranslation[eye] = Point3D(renderDesc.HmdToEyeOffset.x, renderDesc.HmdToEyeOffset.y, renderDesc.HmdToEyeOffset.z);
|
||||
|
||||
texSize[eye] = ovr_GetFovTextureSize(mSession, (ovrEyeType)eye, mFOVPort[eye], pixelsPerDisplayPixel);
|
||||
}
|
||||
|
||||
// take the max of both for eye resolution
|
||||
mDisplayInfo.mEyeResolution.width = std::max(texSize[VRDisplayInfo::Eye_Left].w, texSize[VRDisplayInfo::Eye_Right].w);
|
||||
mDisplayInfo.mEyeResolution.height = std::max(texSize[VRDisplayInfo::Eye_Left].h, texSize[VRDisplayInfo::Eye_Right].h);
|
||||
}
|
||||
|
||||
VRDisplayOculus::~VRDisplayOculus() {
|
||||
StopPresentation();
|
||||
Destroy();
|
||||
MOZ_COUNT_DTOR_INHERITED(VRDisplayOculus, VRDisplayHost);
|
||||
}
|
||||
|
||||
void
|
||||
VRDisplayOculus::Destroy()
|
||||
{
|
||||
if (mSession) {
|
||||
ovr_Destroy(mSession);
|
||||
mSession = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
VRDisplayOculus::ZeroSensor()
|
||||
{
|
||||
ovr_RecenterTrackingOrigin(mSession);
|
||||
}
|
||||
|
||||
VRHMDSensorState
|
||||
VRDisplayOculus::GetSensorState()
|
||||
{
|
||||
mInputFrameID++;
|
||||
|
||||
VRHMDSensorState result;
|
||||
double frameDelta = 0.0f;
|
||||
if (gfxPrefs::VRPosePredictionEnabled()) {
|
||||
// XXX We might need to call ovr_GetPredictedDisplayTime even if we don't use the result.
|
||||
// If we don't call it, the Oculus driver will spew out many warnings...
|
||||
double predictedFrameTime = ovr_GetPredictedDisplayTime(mSession, mInputFrameID);
|
||||
frameDelta = predictedFrameTime - ovr_GetTimeInSeconds();
|
||||
}
|
||||
result = GetSensorState(frameDelta);
|
||||
result.inputFrameID = mInputFrameID;
|
||||
mLastSensorState[result.inputFrameID % kMaxLatencyFrames] = result;
|
||||
return result;
|
||||
}
|
||||
|
||||
VRHMDSensorState
|
||||
VRDisplayOculus::GetImmediateSensorState()
|
||||
{
|
||||
return GetSensorState(0.0);
|
||||
}
|
||||
|
||||
VRHMDSensorState
|
||||
VRDisplayOculus::GetSensorState(double timeOffset)
|
||||
{
|
||||
VRHMDSensorState result;
|
||||
result.Clear();
|
||||
|
||||
ovrTrackingState state = ovr_GetTrackingState(mSession, timeOffset, true);
|
||||
ovrPoseStatef& pose(state.HeadPose);
|
||||
|
||||
result.timestamp = pose.TimeInSeconds;
|
||||
|
||||
if (state.StatusFlags & ovrStatus_OrientationTracked) {
|
||||
result.flags |= VRDisplayCapabilityFlags::Cap_Orientation;
|
||||
|
||||
result.orientation[0] = pose.ThePose.Orientation.x;
|
||||
result.orientation[1] = pose.ThePose.Orientation.y;
|
||||
result.orientation[2] = pose.ThePose.Orientation.z;
|
||||
result.orientation[3] = pose.ThePose.Orientation.w;
|
||||
|
||||
result.angularVelocity[0] = pose.AngularVelocity.x;
|
||||
result.angularVelocity[1] = pose.AngularVelocity.y;
|
||||
result.angularVelocity[2] = pose.AngularVelocity.z;
|
||||
|
||||
result.flags |= VRDisplayCapabilityFlags::Cap_AngularAcceleration;
|
||||
|
||||
result.angularAcceleration[0] = pose.AngularAcceleration.x;
|
||||
result.angularAcceleration[1] = pose.AngularAcceleration.y;
|
||||
result.angularAcceleration[2] = pose.AngularAcceleration.z;
|
||||
}
|
||||
|
||||
if (state.StatusFlags & ovrStatus_PositionTracked) {
|
||||
result.flags |= VRDisplayCapabilityFlags::Cap_Position;
|
||||
|
||||
result.position[0] = pose.ThePose.Position.x;
|
||||
result.position[1] = pose.ThePose.Position.y;
|
||||
result.position[2] = pose.ThePose.Position.z;
|
||||
|
||||
result.linearVelocity[0] = pose.LinearVelocity.x;
|
||||
result.linearVelocity[1] = pose.LinearVelocity.y;
|
||||
result.linearVelocity[2] = pose.LinearVelocity.z;
|
||||
|
||||
result.flags |= VRDisplayCapabilityFlags::Cap_LinearAcceleration;
|
||||
|
||||
result.linearAcceleration[0] = pose.LinearAcceleration.x;
|
||||
result.linearAcceleration[1] = pose.LinearAcceleration.y;
|
||||
result.linearAcceleration[2] = pose.LinearAcceleration.z;
|
||||
}
|
||||
result.flags |= VRDisplayCapabilityFlags::Cap_External;
|
||||
result.flags |= VRDisplayCapabilityFlags::Cap_Present;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void
|
||||
VRDisplayOculus::StartPresentation()
|
||||
{
|
||||
if (mIsPresenting) {
|
||||
return;
|
||||
}
|
||||
mIsPresenting = true;
|
||||
|
||||
/**
|
||||
* The presentation format is determined by content, which describes the
|
||||
* left and right eye rectangles in the VRLayer. The default, if no
|
||||
* coordinates are passed is to place the left and right eye textures
|
||||
* side-by-side within the buffer.
|
||||
*
|
||||
* XXX - An optimization would be to dynamically resize this buffer
|
||||
* to accomodate sites that are choosing to render in a lower
|
||||
* resolution or are using space outside of the left and right
|
||||
* eye textures for other purposes. (Bug 1291443)
|
||||
*/
|
||||
ovrTextureSwapChainDesc desc;
|
||||
memset(&desc, 0, sizeof(desc));
|
||||
desc.Type = ovrTexture_2D;
|
||||
desc.ArraySize = 1;
|
||||
desc.Format = OVR_FORMAT_B8G8R8A8_UNORM_SRGB;
|
||||
desc.Width = mDisplayInfo.mEyeResolution.width * 2;
|
||||
desc.Height = mDisplayInfo.mEyeResolution.height;
|
||||
desc.MipLevels = 1;
|
||||
desc.SampleCount = 1;
|
||||
desc.StaticImage = false;
|
||||
desc.MiscFlags = ovrTextureMisc_DX_Typeless;
|
||||
desc.BindFlags = ovrTextureBind_DX_RenderTarget;
|
||||
|
||||
if (!mDevice) {
|
||||
mDevice = gfx::DeviceManagerDx::Get()->GetCompositorDevice();
|
||||
if (!mDevice) {
|
||||
NS_WARNING("Failed to get a D3D11Device for Oculus");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
mDevice->GetImmediateContext(getter_AddRefs(mContext));
|
||||
if (!mContext) {
|
||||
NS_WARNING("Failed to get immediate context for Oculus");
|
||||
return;
|
||||
}
|
||||
|
||||
if (FAILED(mDevice->CreateVertexShader(sLayerQuadVS.mData, sLayerQuadVS.mLength, nullptr, &mQuadVS))) {
|
||||
NS_WARNING("Failed to create vertex shader for Oculus");
|
||||
return;
|
||||
}
|
||||
|
||||
if (FAILED(mDevice->CreatePixelShader(sRGBShader.mData, sRGBShader.mLength, nullptr, &mQuadPS))) {
|
||||
NS_WARNING("Failed to create pixel shader for Oculus");
|
||||
return;
|
||||
}
|
||||
|
||||
CD3D11_BUFFER_DESC cBufferDesc(sizeof(layers::VertexShaderConstants),
|
||||
D3D11_BIND_CONSTANT_BUFFER,
|
||||
D3D11_USAGE_DYNAMIC,
|
||||
D3D11_CPU_ACCESS_WRITE);
|
||||
|
||||
if (FAILED(mDevice->CreateBuffer(&cBufferDesc, nullptr, getter_AddRefs(mVSConstantBuffer)))) {
|
||||
NS_WARNING("Failed to vertex shader constant buffer for Oculus");
|
||||
return;
|
||||
}
|
||||
|
||||
cBufferDesc.ByteWidth = sizeof(layers::PixelShaderConstants);
|
||||
if (FAILED(mDevice->CreateBuffer(&cBufferDesc, nullptr, getter_AddRefs(mPSConstantBuffer)))) {
|
||||
NS_WARNING("Failed to pixel shader constant buffer for Oculus");
|
||||
return;
|
||||
}
|
||||
|
||||
CD3D11_SAMPLER_DESC samplerDesc(D3D11_DEFAULT);
|
||||
if (FAILED(mDevice->CreateSamplerState(&samplerDesc, getter_AddRefs(mLinearSamplerState)))) {
|
||||
NS_WARNING("Failed to create sampler state for Oculus");
|
||||
return;
|
||||
}
|
||||
|
||||
D3D11_INPUT_ELEMENT_DESC layout[] =
|
||||
{
|
||||
{ "POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
|
||||
};
|
||||
|
||||
if (FAILED(mDevice->CreateInputLayout(layout,
|
||||
sizeof(layout) / sizeof(D3D11_INPUT_ELEMENT_DESC),
|
||||
sLayerQuadVS.mData,
|
||||
sLayerQuadVS.mLength,
|
||||
getter_AddRefs(mInputLayout)))) {
|
||||
NS_WARNING("Failed to create input layout for Oculus");
|
||||
return;
|
||||
}
|
||||
|
||||
ovrResult orv = ovr_CreateTextureSwapChainDX(mSession, mDevice, &desc, &mTextureSet);
|
||||
if (orv != ovrSuccess) {
|
||||
NS_WARNING("ovr_CreateTextureSwapChainDX failed");
|
||||
return;
|
||||
}
|
||||
|
||||
int textureCount = 0;
|
||||
orv = ovr_GetTextureSwapChainLength(mSession, mTextureSet, &textureCount);
|
||||
if (orv != ovrSuccess) {
|
||||
NS_WARNING("ovr_GetTextureSwapChainLength failed");
|
||||
return;
|
||||
}
|
||||
|
||||
Vertex vertices[] = { { { 0.0, 0.0 } },{ { 1.0, 0.0 } },{ { 0.0, 1.0 } },{ { 1.0, 1.0 } } };
|
||||
CD3D11_BUFFER_DESC bufferDesc(sizeof(vertices), D3D11_BIND_VERTEX_BUFFER);
|
||||
D3D11_SUBRESOURCE_DATA data;
|
||||
data.pSysMem = (void*)vertices;
|
||||
|
||||
if (FAILED(mDevice->CreateBuffer(&bufferDesc, &data, getter_AddRefs(mVertexBuffer)))) {
|
||||
NS_WARNING("Failed to create vertex buffer for Oculus");
|
||||
return;
|
||||
}
|
||||
|
||||
mRenderTargets.SetLength(textureCount);
|
||||
|
||||
memset(&mVSConstants, 0, sizeof(mVSConstants));
|
||||
memset(&mPSConstants, 0, sizeof(mPSConstants));
|
||||
|
||||
for (int i = 0; i < textureCount; ++i) {
|
||||
RefPtr<CompositingRenderTargetD3D11> rt;
|
||||
ID3D11Texture2D* texture = nullptr;
|
||||
orv = ovr_GetTextureSwapChainBufferDX(mSession, mTextureSet, i, IID_PPV_ARGS(&texture));
|
||||
MOZ_ASSERT(orv == ovrSuccess, "ovr_GetTextureSwapChainBufferDX failed.");
|
||||
rt = new CompositingRenderTargetD3D11(texture, IntPoint(0, 0), DXGI_FORMAT_B8G8R8A8_UNORM);
|
||||
rt->SetSize(IntSize(mDisplayInfo.mEyeResolution.width * 2, mDisplayInfo.mEyeResolution.height));
|
||||
mRenderTargets[i] = rt;
|
||||
texture->Release();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
VRDisplayOculus::StopPresentation()
|
||||
{
|
||||
if (!mIsPresenting) {
|
||||
return;
|
||||
}
|
||||
mIsPresenting = false;
|
||||
|
||||
ovr_SubmitFrame(mSession, 0, nullptr, nullptr, 0);
|
||||
|
||||
if (mTextureSet) {
|
||||
ovr_DestroyTextureSwapChain(mSession, mTextureSet);
|
||||
mTextureSet = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
/*static*/ already_AddRefed<VRDisplayManagerOculus>
|
||||
VRDisplayManagerOculus::Create()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
if (!gfxPrefs::VREnabled() || !gfxPrefs::VROculusEnabled())
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!InitializeOculusCAPI()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
RefPtr<VRDisplayManagerOculus> manager = new VRDisplayManagerOculus();
|
||||
return manager.forget();
|
||||
}
|
||||
|
||||
bool
|
||||
VRDisplayManagerOculus::Init()
|
||||
{
|
||||
if (!mOculusInitialized) {
|
||||
nsIThread* thread = nullptr;
|
||||
NS_GetCurrentThread(&thread);
|
||||
mOculusThread = already_AddRefed<nsIThread>(thread);
|
||||
|
||||
ovrInitParams params;
|
||||
memset(¶ms, 0, sizeof(params));
|
||||
params.Flags = ovrInit_RequestVersion;
|
||||
params.RequestedMinorVersion = OVR_MINOR_VERSION;
|
||||
params.LogCallback = nullptr;
|
||||
params.ConnectionTimeoutMS = 0;
|
||||
|
||||
ovrResult orv = ovr_Initialize(¶ms);
|
||||
|
||||
if (orv == ovrSuccess) {
|
||||
mOculusInitialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
return mOculusInitialized;
|
||||
}
|
||||
|
||||
void
|
||||
VRDisplayManagerOculus::Destroy()
|
||||
{
|
||||
if (mOculusInitialized) {
|
||||
MOZ_ASSERT(NS_GetCurrentThread() == mOculusThread);
|
||||
mOculusThread = nullptr;
|
||||
|
||||
mHMDInfo = nullptr;
|
||||
|
||||
ovr_Shutdown();
|
||||
mOculusInitialized = false;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
VRDisplayManagerOculus::GetHMDs(nsTArray<RefPtr<VRDisplayHost>>& aHMDResult)
|
||||
{
|
||||
if (!mOculusInitialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
// ovr_Create can be slow when no HMD is present and we wish
|
||||
// to keep the same oculus session when possible, so we detect
|
||||
// presence of an HMD with ovr_GetHmdDesc before calling ovr_Create
|
||||
ovrHmdDesc desc = ovr_GetHmdDesc(NULL);
|
||||
if (desc.Type == ovrHmd_None) {
|
||||
// No HMD connected.
|
||||
mHMDInfo = nullptr;
|
||||
} else if (mHMDInfo == nullptr) {
|
||||
// HMD Detected
|
||||
ovrSession session;
|
||||
ovrGraphicsLuid luid;
|
||||
ovrResult orv = ovr_Create(&session, &luid);
|
||||
if (orv == ovrSuccess) {
|
||||
mHMDInfo = new VRDisplayOculus(session);
|
||||
}
|
||||
}
|
||||
|
||||
if (mHMDInfo) {
|
||||
aHMDResult.AppendElement(mHMDInfo);
|
||||
}
|
||||
}
|
||||
|
||||
already_AddRefed<CompositingRenderTargetD3D11>
|
||||
VRDisplayOculus::GetNextRenderTarget()
|
||||
{
|
||||
int currentRenderTarget = 0;
|
||||
DebugOnly<ovrResult> orv = ovr_GetTextureSwapChainCurrentIndex(mSession, mTextureSet, ¤tRenderTarget);
|
||||
MOZ_ASSERT(orv == ovrSuccess, "ovr_GetTextureSwapChainCurrentIndex failed.");
|
||||
|
||||
mRenderTargets[currentRenderTarget]->ClearOnBind();
|
||||
RefPtr<CompositingRenderTargetD3D11> rt = mRenderTargets[currentRenderTarget];
|
||||
return rt.forget();
|
||||
}
|
||||
|
||||
bool
|
||||
VRDisplayOculus::UpdateConstantBuffers()
|
||||
{
|
||||
HRESULT hr;
|
||||
D3D11_MAPPED_SUBRESOURCE resource;
|
||||
resource.pData = nullptr;
|
||||
|
||||
hr = mContext->Map(mVSConstantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &resource);
|
||||
if (FAILED(hr) || !resource.pData) {
|
||||
return false;
|
||||
}
|
||||
*(VertexShaderConstants*)resource.pData = mVSConstants;
|
||||
mContext->Unmap(mVSConstantBuffer, 0);
|
||||
resource.pData = nullptr;
|
||||
|
||||
hr = mContext->Map(mPSConstantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &resource);
|
||||
if (FAILED(hr) || !resource.pData) {
|
||||
return false;
|
||||
}
|
||||
*(PixelShaderConstants*)resource.pData = mPSConstants;
|
||||
mContext->Unmap(mPSConstantBuffer, 0);
|
||||
|
||||
ID3D11Buffer *buffer = mVSConstantBuffer;
|
||||
mContext->VSSetConstantBuffers(0, 1, &buffer);
|
||||
buffer = mPSConstantBuffer;
|
||||
mContext->PSSetConstantBuffers(0, 1, &buffer);
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
VRDisplayOculus::SubmitFrame(TextureSourceD3D11* aSource,
|
||||
const IntSize& aSize,
|
||||
const VRHMDSensorState& aSensorState,
|
||||
const gfx::Rect& aLeftEyeRect,
|
||||
const gfx::Rect& aRightEyeRect)
|
||||
{
|
||||
if (!mIsPresenting) {
|
||||
return;
|
||||
}
|
||||
if (mRenderTargets.IsEmpty()) {
|
||||
/**
|
||||
* XXX - We should resolve fail the promise returned by
|
||||
* VRDisplay.requestPresent() when the DX11 resources fail allocation
|
||||
* in VRDisplayOculus::StartPresentation().
|
||||
* Bailing out here prevents the crash but content should be aware
|
||||
* that frames are not being presented.
|
||||
* See Bug 1299309.
|
||||
**/
|
||||
return;
|
||||
}
|
||||
MOZ_ASSERT(mDevice);
|
||||
MOZ_ASSERT(mContext);
|
||||
|
||||
RefPtr<CompositingRenderTargetD3D11> surface = GetNextRenderTarget();
|
||||
|
||||
surface->BindRenderTarget(mContext);
|
||||
|
||||
Matrix viewMatrix = Matrix::Translation(-1.0, 1.0);
|
||||
viewMatrix.PreScale(2.0f / float(aSize.width), 2.0f / float(aSize.height));
|
||||
viewMatrix.PreScale(1.0f, -1.0f);
|
||||
Matrix4x4 projection = Matrix4x4::From2D(viewMatrix);
|
||||
projection._33 = 0.0f;
|
||||
|
||||
Matrix transform2d;
|
||||
gfx::Matrix4x4 transform = gfx::Matrix4x4::From2D(transform2d);
|
||||
|
||||
D3D11_VIEWPORT viewport;
|
||||
viewport.MinDepth = 0.0f;
|
||||
viewport.MaxDepth = 1.0f;
|
||||
viewport.Width = aSize.width;
|
||||
viewport.Height = aSize.height;
|
||||
viewport.TopLeftX = 0;
|
||||
viewport.TopLeftY = 0;
|
||||
|
||||
D3D11_RECT scissor;
|
||||
scissor.left = 0;
|
||||
scissor.right = aSize.width;
|
||||
scissor.top = 0;
|
||||
scissor.bottom = aSize.height;
|
||||
|
||||
memcpy(&mVSConstants.layerTransform, &transform._11, sizeof(mVSConstants.layerTransform));
|
||||
memcpy(&mVSConstants.projection, &projection._11, sizeof(mVSConstants.projection));
|
||||
mVSConstants.renderTargetOffset[0] = 0.0f;
|
||||
mVSConstants.renderTargetOffset[1] = 0.0f;
|
||||
mVSConstants.layerQuad = Rect(0.0f, 0.0f, aSize.width, aSize.height);
|
||||
mVSConstants.textureCoords = Rect(0.0f, 1.0f, 1.0f, -1.0f);
|
||||
|
||||
mPSConstants.layerOpacity[0] = 1.0f;
|
||||
|
||||
ID3D11Buffer* vbuffer = mVertexBuffer;
|
||||
UINT vsize = sizeof(Vertex);
|
||||
UINT voffset = 0;
|
||||
mContext->IASetVertexBuffers(0, 1, &vbuffer, &vsize, &voffset);
|
||||
mContext->IASetIndexBuffer(nullptr, DXGI_FORMAT_R16_UINT, 0);
|
||||
mContext->IASetInputLayout(mInputLayout);
|
||||
mContext->RSSetViewports(1, &viewport);
|
||||
mContext->RSSetScissorRects(1, &scissor);
|
||||
mContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
|
||||
mContext->VSSetShader(mQuadVS, nullptr, 0);
|
||||
mContext->PSSetShader(mQuadPS, nullptr, 0);
|
||||
ID3D11ShaderResourceView* srView = aSource->GetShaderResourceView();
|
||||
mContext->PSSetShaderResources(0 /* 0 == TexSlot::RGB */, 1, &srView);
|
||||
// XXX Use Constant from TexSlot in CompositorD3D11.cpp?
|
||||
|
||||
ID3D11SamplerState *sampler = mLinearSamplerState;
|
||||
mContext->PSSetSamplers(0, 1, &sampler);
|
||||
|
||||
if (!UpdateConstantBuffers()) {
|
||||
NS_WARNING("Failed to update constant buffers for Oculus");
|
||||
return;
|
||||
}
|
||||
|
||||
mContext->Draw(4, 0);
|
||||
|
||||
ovrResult orv = ovr_CommitTextureSwapChain(mSession, mTextureSet);
|
||||
if (orv != ovrSuccess) {
|
||||
NS_WARNING("ovr_CommitTextureSwapChain failed.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
ovrLayerEyeFov layer;
|
||||
memset(&layer, 0, sizeof(layer));
|
||||
layer.Header.Type = ovrLayerType_EyeFov;
|
||||
layer.Header.Flags = 0;
|
||||
layer.ColorTexture[0] = mTextureSet;
|
||||
layer.ColorTexture[1] = nullptr;
|
||||
layer.Fov[0] = mFOVPort[0];
|
||||
layer.Fov[1] = mFOVPort[1];
|
||||
layer.Viewport[0].Pos.x = aSize.width * aLeftEyeRect.x;
|
||||
layer.Viewport[0].Pos.y = aSize.height * aLeftEyeRect.y;
|
||||
layer.Viewport[0].Size.w = aSize.width * aLeftEyeRect.width;
|
||||
layer.Viewport[0].Size.h = aSize.height * aLeftEyeRect.height;
|
||||
layer.Viewport[1].Pos.x = aSize.width * aRightEyeRect.x;
|
||||
layer.Viewport[1].Pos.y = aSize.height * aRightEyeRect.y;
|
||||
layer.Viewport[1].Size.w = aSize.width * aRightEyeRect.width;
|
||||
layer.Viewport[1].Size.h = aSize.height * aRightEyeRect.height;
|
||||
|
||||
const Point3D& l = mDisplayInfo.mEyeTranslation[0];
|
||||
const Point3D& r = mDisplayInfo.mEyeTranslation[1];
|
||||
const ovrVector3f hmdToEyeViewOffset[2] = { { l.x, l.y, l.z },
|
||||
{ r.x, r.y, r.z } };
|
||||
|
||||
for (uint32_t i = 0; i < 2; ++i) {
|
||||
Quaternion o(aSensorState.orientation[0],
|
||||
aSensorState.orientation[1],
|
||||
aSensorState.orientation[2],
|
||||
aSensorState.orientation[3]);
|
||||
Point3D vo(hmdToEyeViewOffset[i].x, hmdToEyeViewOffset[i].y, hmdToEyeViewOffset[i].z);
|
||||
Point3D p = o.RotatePoint(vo);
|
||||
layer.RenderPose[i].Orientation.x = o.x;
|
||||
layer.RenderPose[i].Orientation.y = o.y;
|
||||
layer.RenderPose[i].Orientation.z = o.z;
|
||||
layer.RenderPose[i].Orientation.w = o.w;
|
||||
layer.RenderPose[i].Position.x = p.x + aSensorState.position[0];
|
||||
layer.RenderPose[i].Position.y = p.y + aSensorState.position[1];
|
||||
layer.RenderPose[i].Position.z = p.z + aSensorState.position[2];
|
||||
}
|
||||
|
||||
ovrLayerHeader *layers = &layer.Header;
|
||||
orv = ovr_SubmitFrame(mSession, aSensorState.inputFrameID, nullptr, &layers, 1);
|
||||
|
||||
if (orv != ovrSuccess) {
|
||||
printf_stderr("ovr_SubmitFrame failed.\n");
|
||||
}
|
||||
|
||||
// Trigger the next VSync immediately
|
||||
VRManager *vm = VRManager::Get();
|
||||
MOZ_ASSERT(vm);
|
||||
vm->NotifyVRVsync(mDisplayInfo.mDisplayID);
|
||||
}
|
||||
|
||||
void
|
||||
VRDisplayOculus::NotifyVSync()
|
||||
{
|
||||
ovrSessionStatus sessionStatus;
|
||||
ovrResult ovr = ovr_GetSessionStatus(mSession, &sessionStatus);
|
||||
mDisplayInfo.mIsConnected = (ovr == ovrSuccess && sessionStatus.HmdPresent);
|
||||
}
|
||||
@@ -1,111 +0,0 @@
|
||||
/* -*- 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"
|
||||
#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
|
||||
{
|
||||
public:
|
||||
virtual void NotifyVSync() override;
|
||||
virtual VRHMDSensorState GetSensorState() override;
|
||||
virtual VRHMDSensorState GetImmediateSensorState() override;
|
||||
void ZeroSensor() override;
|
||||
|
||||
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;
|
||||
|
||||
public:
|
||||
explicit VRDisplayOculus(ovrSession aSession);
|
||||
|
||||
protected:
|
||||
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
|
||||
{
|
||||
public:
|
||||
static already_AddRefed<VRDisplayManagerOculus> Create();
|
||||
virtual bool Init() override;
|
||||
virtual void Destroy() override;
|
||||
virtual void GetHMDs(nsTArray<RefPtr<VRDisplayHost> >& aHMDResult) override;
|
||||
protected:
|
||||
VRDisplayManagerOculus()
|
||||
: mOculusInitialized(false)
|
||||
{ }
|
||||
|
||||
RefPtr<impl::VRDisplayOculus> mHMDInfo;
|
||||
bool mOculusInitialized;
|
||||
RefPtr<nsIThread> mOculusThread;
|
||||
};
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace mozilla
|
||||
|
||||
#endif /* GFX_VR_OCULUS_H */
|
||||
@@ -1,749 +0,0 @@
|
||||
/* -*- 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/. */
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "prlink.h"
|
||||
#include "prmem.h"
|
||||
#include "prenv.h"
|
||||
#include "gfxPrefs.h"
|
||||
#include "nsString.h"
|
||||
#include "mozilla/Preferences.h"
|
||||
|
||||
#include "mozilla/gfx/Quaternion.h"
|
||||
|
||||
#ifdef XP_WIN
|
||||
#include "CompositorD3D11.h"
|
||||
#include "TextureD3D11.h"
|
||||
#endif // XP_WIN
|
||||
|
||||
#include "gfxVROpenVR.h"
|
||||
|
||||
#include "nsServiceManagerUtils.h"
|
||||
#include "nsIScreenManager.h"
|
||||
#include "openvr/openvr.h"
|
||||
|
||||
#ifdef MOZ_GAMEPAD
|
||||
#include "mozilla/dom/GamepadEventTypes.h"
|
||||
#include "mozilla/dom/GamepadBinding.h"
|
||||
#endif
|
||||
|
||||
#ifndef M_PI
|
||||
# define M_PI 3.14159265358979323846
|
||||
#endif
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::gfx;
|
||||
using namespace mozilla::gfx::impl;
|
||||
using namespace mozilla::layers;
|
||||
using namespace mozilla::dom;
|
||||
|
||||
namespace {
|
||||
extern "C" {
|
||||
typedef uint32_t (VR_CALLTYPE * pfn_VR_InitInternal)(::vr::HmdError *peError, ::vr::EVRApplicationType eApplicationType);
|
||||
typedef void (VR_CALLTYPE * pfn_VR_ShutdownInternal)();
|
||||
typedef bool (VR_CALLTYPE * pfn_VR_IsHmdPresent)();
|
||||
typedef bool (VR_CALLTYPE * pfn_VR_IsRuntimeInstalled)();
|
||||
typedef const char * (VR_CALLTYPE * pfn_VR_GetStringForHmdError)(::vr::HmdError error);
|
||||
typedef void * (VR_CALLTYPE * pfn_VR_GetGenericInterface)(const char *pchInterfaceVersion, ::vr::HmdError *peError);
|
||||
} // extern "C"
|
||||
} // namespace
|
||||
|
||||
static pfn_VR_InitInternal vr_InitInternal = nullptr;
|
||||
static pfn_VR_ShutdownInternal vr_ShutdownInternal = nullptr;
|
||||
static pfn_VR_IsHmdPresent vr_IsHmdPresent = nullptr;
|
||||
static pfn_VR_IsRuntimeInstalled vr_IsRuntimeInstalled = nullptr;
|
||||
static pfn_VR_GetStringForHmdError vr_GetStringForHmdError = nullptr;
|
||||
static pfn_VR_GetGenericInterface vr_GetGenericInterface = nullptr;
|
||||
|
||||
// EButton_System, EButton_DPad_xx, and EButton_A
|
||||
// can not be triggered in Steam Vive in OpenVR SDK 1.0.3.
|
||||
const uint64_t gOpenVRButtonMask[] = {
|
||||
// vr::ButtonMaskFromId(vr::EVRButtonId::k_EButton_System),
|
||||
vr::ButtonMaskFromId(vr::EVRButtonId::k_EButton_ApplicationMenu),
|
||||
vr::ButtonMaskFromId(vr::EVRButtonId::k_EButton_Grip),
|
||||
// vr::ButtonMaskFromId(vr::EVRButtonId::k_EButton_DPad_Left),
|
||||
// vr::ButtonMaskFromId(vr::EVRButtonId::k_EButton_DPad_Up),
|
||||
// vr::ButtonMaskFromId(vr::EVRButtonId::k_EButton_DPad_Right),
|
||||
// vr::ButtonMaskFromId(vr::EVRButtonId::k_EButton_DPad_Down),
|
||||
// vr::ButtonMaskFromId(vr::EVRButtonId::k_EButton_A),
|
||||
vr::ButtonMaskFromId(vr::EVRButtonId::k_EButton_SteamVR_Touchpad),
|
||||
vr::ButtonMaskFromId(vr::EVRButtonId::k_EButton_SteamVR_Trigger)
|
||||
};
|
||||
|
||||
const uint32_t gNumOpenVRButtonMask = sizeof(gOpenVRButtonMask) /
|
||||
sizeof(uint64_t);
|
||||
|
||||
enum class VRControllerAxisType : uint16_t {
|
||||
TrackpadXAxis,
|
||||
TrackpadYAxis,
|
||||
Trigger,
|
||||
NumVRControllerAxisType
|
||||
};
|
||||
|
||||
#define VRControllerAxis(aButtonId) (aButtonId - vr::EVRButtonId::k_EButton_Axis0)
|
||||
|
||||
const uint32_t gOpenVRAxes[] = {
|
||||
VRControllerAxis(vr::EVRButtonId::k_EButton_Axis0),
|
||||
VRControllerAxis(vr::EVRButtonId::k_EButton_Axis0),
|
||||
VRControllerAxis(vr::EVRButtonId::k_EButton_Axis1)
|
||||
};
|
||||
|
||||
const uint32_t gNumOpenVRAxis = sizeof(gOpenVRAxes) /
|
||||
sizeof(uint32_t);
|
||||
|
||||
|
||||
bool
|
||||
LoadOpenVRRuntime()
|
||||
{
|
||||
static PRLibrary *openvrLib = nullptr;
|
||||
|
||||
nsAdoptingCString openvrPath = Preferences::GetCString("gfx.vr.openvr-runtime");
|
||||
if (!openvrPath)
|
||||
return false;
|
||||
|
||||
openvrLib = PR_LoadLibrary(openvrPath.BeginReading());
|
||||
if (!openvrLib)
|
||||
return false;
|
||||
|
||||
#define REQUIRE_FUNCTION(_x) do { \
|
||||
*(void **)&vr_##_x = (void *) PR_FindSymbol(openvrLib, "VR_" #_x); \
|
||||
if (!vr_##_x) { printf_stderr("VR_" #_x " symbol missing\n"); return false; } \
|
||||
} while (0)
|
||||
|
||||
REQUIRE_FUNCTION(InitInternal);
|
||||
REQUIRE_FUNCTION(ShutdownInternal);
|
||||
REQUIRE_FUNCTION(IsHmdPresent);
|
||||
REQUIRE_FUNCTION(IsRuntimeInstalled);
|
||||
REQUIRE_FUNCTION(GetStringForHmdError);
|
||||
REQUIRE_FUNCTION(GetGenericInterface);
|
||||
|
||||
#undef REQUIRE_FUNCTION
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
VRDisplayOpenVR::VRDisplayOpenVR(::vr::IVRSystem *aVRSystem,
|
||||
::vr::IVRChaperone *aVRChaperone,
|
||||
::vr::IVRCompositor *aVRCompositor)
|
||||
: VRDisplayHost(VRDeviceType::OpenVR)
|
||||
, mVRSystem(aVRSystem)
|
||||
, mVRChaperone(aVRChaperone)
|
||||
, mVRCompositor(aVRCompositor)
|
||||
, mIsPresenting(false)
|
||||
{
|
||||
MOZ_COUNT_CTOR_INHERITED(VRDisplayOpenVR, VRDisplayHost);
|
||||
|
||||
mDisplayInfo.mDisplayName.AssignLiteral("OpenVR HMD");
|
||||
mDisplayInfo.mIsConnected = true;
|
||||
mDisplayInfo.mCapabilityFlags = VRDisplayCapabilityFlags::Cap_None |
|
||||
VRDisplayCapabilityFlags::Cap_Orientation |
|
||||
VRDisplayCapabilityFlags::Cap_Position |
|
||||
VRDisplayCapabilityFlags::Cap_External |
|
||||
VRDisplayCapabilityFlags::Cap_Present |
|
||||
VRDisplayCapabilityFlags::Cap_StageParameters;
|
||||
|
||||
mVRCompositor->SetTrackingSpace(::vr::TrackingUniverseSeated);
|
||||
|
||||
uint32_t w, h;
|
||||
mVRSystem->GetRecommendedRenderTargetSize(&w, &h);
|
||||
mDisplayInfo.mEyeResolution.width = w;
|
||||
mDisplayInfo.mEyeResolution.height = h;
|
||||
|
||||
// SteamVR gives the application a single FOV to use; it's not configurable as with Oculus
|
||||
for (uint32_t eye = 0; eye < 2; ++eye) {
|
||||
// get l/r/t/b clip plane coordinates
|
||||
float l, r, t, b;
|
||||
mVRSystem->GetProjectionRaw(static_cast<::vr::Hmd_Eye>(eye), &l, &r, &t, &b);
|
||||
mDisplayInfo.mEyeFOV[eye].SetFromTanRadians(-t, r, b, -l);
|
||||
|
||||
::vr::HmdMatrix34_t eyeToHead = mVRSystem->GetEyeToHeadTransform(static_cast<::vr::Hmd_Eye>(eye));
|
||||
|
||||
mDisplayInfo.mEyeTranslation[eye].x = eyeToHead.m[0][3];
|
||||
mDisplayInfo.mEyeTranslation[eye].y = eyeToHead.m[1][3];
|
||||
mDisplayInfo.mEyeTranslation[eye].z = eyeToHead.m[2][3];
|
||||
}
|
||||
|
||||
UpdateStageParameters();
|
||||
}
|
||||
|
||||
VRDisplayOpenVR::~VRDisplayOpenVR()
|
||||
{
|
||||
Destroy();
|
||||
MOZ_COUNT_DTOR_INHERITED(VRDisplayOpenVR, VRDisplayHost);
|
||||
}
|
||||
|
||||
void
|
||||
VRDisplayOpenVR::Destroy()
|
||||
{
|
||||
StopPresentation();
|
||||
vr_ShutdownInternal();
|
||||
}
|
||||
|
||||
void
|
||||
VRDisplayOpenVR::UpdateStageParameters()
|
||||
{
|
||||
float sizeX = 0.0f;
|
||||
float sizeZ = 0.0f;
|
||||
if (mVRChaperone->GetPlayAreaSize(&sizeX, &sizeZ)) {
|
||||
::vr::HmdMatrix34_t t = mVRSystem->GetSeatedZeroPoseToStandingAbsoluteTrackingPose();
|
||||
mDisplayInfo.mStageSize.width = sizeX;
|
||||
mDisplayInfo.mStageSize.height = sizeZ;
|
||||
|
||||
mDisplayInfo.mSittingToStandingTransform._11 = t.m[0][0];
|
||||
mDisplayInfo.mSittingToStandingTransform._12 = t.m[1][0];
|
||||
mDisplayInfo.mSittingToStandingTransform._13 = t.m[2][0];
|
||||
mDisplayInfo.mSittingToStandingTransform._14 = 0.0f;
|
||||
|
||||
mDisplayInfo.mSittingToStandingTransform._21 = t.m[0][1];
|
||||
mDisplayInfo.mSittingToStandingTransform._22 = t.m[1][1];
|
||||
mDisplayInfo.mSittingToStandingTransform._23 = t.m[2][1];
|
||||
mDisplayInfo.mSittingToStandingTransform._24 = 0.0f;
|
||||
|
||||
mDisplayInfo.mSittingToStandingTransform._31 = t.m[0][2];
|
||||
mDisplayInfo.mSittingToStandingTransform._32 = t.m[1][2];
|
||||
mDisplayInfo.mSittingToStandingTransform._33 = t.m[2][2];
|
||||
mDisplayInfo.mSittingToStandingTransform._34 = 0.0f;
|
||||
|
||||
mDisplayInfo.mSittingToStandingTransform._41 = t.m[0][3];
|
||||
mDisplayInfo.mSittingToStandingTransform._42 = t.m[1][3];
|
||||
mDisplayInfo.mSittingToStandingTransform._43 = t.m[2][3];
|
||||
mDisplayInfo.mSittingToStandingTransform._44 = 1.0f;
|
||||
} else {
|
||||
// If we fail, fall back to reasonable defaults.
|
||||
// 1m x 1m space, 0.75m high in seated position
|
||||
|
||||
mDisplayInfo.mStageSize.width = 1.0f;
|
||||
mDisplayInfo.mStageSize.height = 1.0f;
|
||||
|
||||
mDisplayInfo.mSittingToStandingTransform._11 = 1.0f;
|
||||
mDisplayInfo.mSittingToStandingTransform._12 = 0.0f;
|
||||
mDisplayInfo.mSittingToStandingTransform._13 = 0.0f;
|
||||
mDisplayInfo.mSittingToStandingTransform._14 = 0.0f;
|
||||
|
||||
mDisplayInfo.mSittingToStandingTransform._21 = 0.0f;
|
||||
mDisplayInfo.mSittingToStandingTransform._22 = 1.0f;
|
||||
mDisplayInfo.mSittingToStandingTransform._23 = 0.0f;
|
||||
mDisplayInfo.mSittingToStandingTransform._24 = 0.0f;
|
||||
|
||||
mDisplayInfo.mSittingToStandingTransform._31 = 0.0f;
|
||||
mDisplayInfo.mSittingToStandingTransform._32 = 0.0f;
|
||||
mDisplayInfo.mSittingToStandingTransform._33 = 1.0f;
|
||||
mDisplayInfo.mSittingToStandingTransform._34 = 0.0f;
|
||||
|
||||
mDisplayInfo.mSittingToStandingTransform._41 = 0.0f;
|
||||
mDisplayInfo.mSittingToStandingTransform._42 = 0.75f;
|
||||
mDisplayInfo.mSittingToStandingTransform._43 = 0.0f;
|
||||
mDisplayInfo.mSittingToStandingTransform._44 = 1.0f;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
VRDisplayOpenVR::ZeroSensor()
|
||||
{
|
||||
mVRSystem->ResetSeatedZeroPose();
|
||||
UpdateStageParameters();
|
||||
}
|
||||
|
||||
VRHMDSensorState
|
||||
VRDisplayOpenVR::GetSensorState()
|
||||
{
|
||||
return GetSensorState(0.0f);
|
||||
}
|
||||
|
||||
VRHMDSensorState
|
||||
VRDisplayOpenVR::GetImmediateSensorState()
|
||||
{
|
||||
return GetSensorState(0.0f);
|
||||
}
|
||||
|
||||
VRHMDSensorState
|
||||
VRDisplayOpenVR::GetSensorState(double timeOffset)
|
||||
{
|
||||
{
|
||||
::vr::VREvent_t event;
|
||||
while (mVRSystem->PollNextEvent(&event, sizeof(event))) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
::vr::TrackedDevicePose_t poses[::vr::k_unMaxTrackedDeviceCount];
|
||||
// Note: We *must* call WaitGetPoses in order for any rendering to happen at all
|
||||
mVRCompositor->WaitGetPoses(poses, ::vr::k_unMaxTrackedDeviceCount, nullptr, 0);
|
||||
|
||||
VRHMDSensorState result;
|
||||
result.Clear();
|
||||
result.timestamp = PR_Now();
|
||||
|
||||
if (poses[::vr::k_unTrackedDeviceIndex_Hmd].bDeviceIsConnected &&
|
||||
poses[::vr::k_unTrackedDeviceIndex_Hmd].bPoseIsValid &&
|
||||
poses[::vr::k_unTrackedDeviceIndex_Hmd].eTrackingResult == ::vr::TrackingResult_Running_OK)
|
||||
{
|
||||
const ::vr::TrackedDevicePose_t& pose = poses[::vr::k_unTrackedDeviceIndex_Hmd];
|
||||
|
||||
gfx::Matrix4x4 m;
|
||||
// NOTE! mDeviceToAbsoluteTracking is a 3x4 matrix, not 4x4. But
|
||||
// because of its arrangement, we can copy the 12 elements in and
|
||||
// then transpose them to the right place. We do this so we can
|
||||
// pull out a Quaternion.
|
||||
memcpy(&m._11, &pose.mDeviceToAbsoluteTracking, sizeof(float) * 12);
|
||||
m.Transpose();
|
||||
|
||||
gfx::Quaternion rot;
|
||||
rot.SetFromRotationMatrix(m);
|
||||
rot.Invert();
|
||||
|
||||
result.flags |= VRDisplayCapabilityFlags::Cap_Orientation;
|
||||
result.orientation[0] = rot.x;
|
||||
result.orientation[1] = rot.y;
|
||||
result.orientation[2] = rot.z;
|
||||
result.orientation[3] = rot.w;
|
||||
result.angularVelocity[0] = pose.vAngularVelocity.v[0];
|
||||
result.angularVelocity[1] = pose.vAngularVelocity.v[1];
|
||||
result.angularVelocity[2] = pose.vAngularVelocity.v[2];
|
||||
|
||||
result.flags |= VRDisplayCapabilityFlags::Cap_Position;
|
||||
result.position[0] = m._41;
|
||||
result.position[1] = m._42;
|
||||
result.position[2] = m._43;
|
||||
result.linearVelocity[0] = pose.vVelocity.v[0];
|
||||
result.linearVelocity[1] = pose.vVelocity.v[1];
|
||||
result.linearVelocity[2] = pose.vVelocity.v[2];
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void
|
||||
VRDisplayOpenVR::StartPresentation()
|
||||
{
|
||||
if (mIsPresenting) {
|
||||
return;
|
||||
}
|
||||
mIsPresenting = true;
|
||||
}
|
||||
|
||||
void
|
||||
VRDisplayOpenVR::StopPresentation()
|
||||
{
|
||||
if (!mIsPresenting) {
|
||||
return;
|
||||
}
|
||||
|
||||
mVRCompositor->ClearLastSubmittedFrame();
|
||||
|
||||
mIsPresenting = false;
|
||||
}
|
||||
|
||||
|
||||
#if defined(XP_WIN)
|
||||
|
||||
void
|
||||
VRDisplayOpenVR::SubmitFrame(TextureSourceD3D11* aSource,
|
||||
const IntSize& aSize,
|
||||
const VRHMDSensorState& aSensorState,
|
||||
const gfx::Rect& aLeftEyeRect,
|
||||
const gfx::Rect& aRightEyeRect)
|
||||
{
|
||||
if (!mIsPresenting) {
|
||||
return;
|
||||
}
|
||||
|
||||
::vr::Texture_t tex;
|
||||
tex.handle = (void *)aSource->GetD3D11Texture();
|
||||
tex.eType = ::vr::EGraphicsAPIConvention::API_DirectX;
|
||||
tex.eColorSpace = ::vr::EColorSpace::ColorSpace_Auto;
|
||||
|
||||
::vr::VRTextureBounds_t bounds;
|
||||
bounds.uMin = aLeftEyeRect.x;
|
||||
bounds.vMin = 1.0 - aLeftEyeRect.y;
|
||||
bounds.uMax = aLeftEyeRect.x + aLeftEyeRect.width;
|
||||
bounds.vMax = 1.0 - aLeftEyeRect.y - aLeftEyeRect.height;
|
||||
|
||||
::vr::EVRCompositorError err;
|
||||
err = mVRCompositor->Submit(::vr::EVREye::Eye_Left, &tex, &bounds);
|
||||
if (err != ::vr::EVRCompositorError::VRCompositorError_None) {
|
||||
printf_stderr("OpenVR Compositor Submit() failed.\n");
|
||||
}
|
||||
|
||||
bounds.uMin = aRightEyeRect.x;
|
||||
bounds.vMin = 1.0 - aRightEyeRect.y;
|
||||
bounds.uMax = aRightEyeRect.x + aRightEyeRect.width;
|
||||
bounds.vMax = 1.0 - aRightEyeRect.y - aRightEyeRect.height;
|
||||
|
||||
err = mVRCompositor->Submit(::vr::EVREye::Eye_Right, &tex, &bounds);
|
||||
if (err != ::vr::EVRCompositorError::VRCompositorError_None) {
|
||||
printf_stderr("OpenVR Compositor Submit() failed.\n");
|
||||
}
|
||||
|
||||
mVRCompositor->PostPresentHandoff();
|
||||
|
||||
// Trigger the next VSync immediately
|
||||
VRManager *vm = VRManager::Get();
|
||||
MOZ_ASSERT(vm);
|
||||
vm->NotifyVRVsync(mDisplayInfo.mDisplayID);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void
|
||||
VRDisplayOpenVR::NotifyVSync()
|
||||
{
|
||||
// We update mIsConneced once per frame.
|
||||
mDisplayInfo.mIsConnected = vr_IsHmdPresent();
|
||||
}
|
||||
|
||||
VRDisplayManagerOpenVR::VRDisplayManagerOpenVR()
|
||||
: mOpenVRInstalled(false)
|
||||
{
|
||||
}
|
||||
|
||||
/*static*/ already_AddRefed<VRDisplayManagerOpenVR>
|
||||
VRDisplayManagerOpenVR::Create()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
if (!gfxPrefs::VREnabled() || !gfxPrefs::VROpenVREnabled()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!LoadOpenVRRuntime()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
RefPtr<VRDisplayManagerOpenVR> manager = new VRDisplayManagerOpenVR();
|
||||
return manager.forget();
|
||||
}
|
||||
|
||||
bool
|
||||
VRDisplayManagerOpenVR::Init()
|
||||
{
|
||||
if (mOpenVRInstalled)
|
||||
return true;
|
||||
|
||||
if (!vr_IsRuntimeInstalled())
|
||||
return false;
|
||||
|
||||
mOpenVRInstalled = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
VRDisplayManagerOpenVR::Destroy()
|
||||
{
|
||||
if (mOpenVRInstalled) {
|
||||
if (mOpenVRHMD) {
|
||||
mOpenVRHMD = nullptr;
|
||||
}
|
||||
mOpenVRInstalled = false;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
VRDisplayManagerOpenVR::GetHMDs(nsTArray<RefPtr<VRDisplayHost>>& aHMDResult)
|
||||
{
|
||||
if (!mOpenVRInstalled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!vr_IsHmdPresent()) {
|
||||
if (mOpenVRHMD) {
|
||||
mOpenVRHMD = nullptr;
|
||||
}
|
||||
} else if (mOpenVRHMD == nullptr) {
|
||||
::vr::HmdError err;
|
||||
|
||||
vr_InitInternal(&err, ::vr::EVRApplicationType::VRApplication_Scene);
|
||||
if (err) {
|
||||
return;
|
||||
}
|
||||
|
||||
::vr::IVRSystem *system = (::vr::IVRSystem *)vr_GetGenericInterface(::vr::IVRSystem_Version, &err);
|
||||
if (err || !system) {
|
||||
vr_ShutdownInternal();
|
||||
return;
|
||||
}
|
||||
::vr::IVRChaperone *chaperone = (::vr::IVRChaperone *)vr_GetGenericInterface(::vr::IVRChaperone_Version, &err);
|
||||
if (err || !chaperone) {
|
||||
vr_ShutdownInternal();
|
||||
return;
|
||||
}
|
||||
::vr::IVRCompositor *compositor = (::vr::IVRCompositor*)vr_GetGenericInterface(::vr::IVRCompositor_Version, &err);
|
||||
if (err || !compositor) {
|
||||
vr_ShutdownInternal();
|
||||
return;
|
||||
}
|
||||
|
||||
mOpenVRHMD = new VRDisplayOpenVR(system, chaperone, compositor);
|
||||
}
|
||||
|
||||
if (mOpenVRHMD) {
|
||||
aHMDResult.AppendElement(mOpenVRHMD);
|
||||
}
|
||||
}
|
||||
|
||||
VRControllerOpenVR::VRControllerOpenVR()
|
||||
: VRControllerHost(VRDeviceType::OpenVR)
|
||||
{
|
||||
MOZ_COUNT_CTOR_INHERITED(VRControllerOpenVR, VRControllerHost);
|
||||
mControllerInfo.mControllerName.AssignLiteral("OpenVR HMD");
|
||||
#ifdef MOZ_GAMEPAD
|
||||
mControllerInfo.mMappingType = static_cast<uint32_t>(GamepadMappingType::_empty);
|
||||
#else
|
||||
mControllerInfo.mMappingType = 0;
|
||||
#endif
|
||||
mControllerInfo.mNumButtons = gNumOpenVRButtonMask;
|
||||
mControllerInfo.mNumAxes = gNumOpenVRAxis;
|
||||
}
|
||||
|
||||
VRControllerOpenVR::~VRControllerOpenVR()
|
||||
{
|
||||
MOZ_COUNT_DTOR_INHERITED(VRControllerOpenVR, VRControllerHost);
|
||||
}
|
||||
|
||||
void
|
||||
VRControllerOpenVR::SetTrackedIndex(uint32_t aTrackedIndex)
|
||||
{
|
||||
mTrackedIndex = aTrackedIndex;
|
||||
}
|
||||
|
||||
uint32_t
|
||||
VRControllerOpenVR::GetTrackedIndex()
|
||||
{
|
||||
return mTrackedIndex;
|
||||
}
|
||||
|
||||
VRControllerManagerOpenVR::VRControllerManagerOpenVR()
|
||||
: mOpenVRInstalled(false), mVRSystem(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
VRControllerManagerOpenVR::~VRControllerManagerOpenVR()
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
|
||||
/*static*/ already_AddRefed<VRControllerManagerOpenVR>
|
||||
VRControllerManagerOpenVR::Create()
|
||||
{
|
||||
if (!gfxPrefs::VREnabled() || !gfxPrefs::VROpenVREnabled()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
RefPtr<VRControllerManagerOpenVR> manager = new VRControllerManagerOpenVR();
|
||||
return manager.forget();
|
||||
}
|
||||
|
||||
bool
|
||||
VRControllerManagerOpenVR::Init()
|
||||
{
|
||||
if (mOpenVRInstalled)
|
||||
return true;
|
||||
|
||||
if (!vr_IsRuntimeInstalled())
|
||||
return false;
|
||||
|
||||
// Loading the OpenVR Runtime
|
||||
vr::EVRInitError err = vr::VRInitError_None;
|
||||
|
||||
vr_InitInternal(&err, vr::VRApplication_Scene);
|
||||
if (err != vr::VRInitError_None) {
|
||||
return false;
|
||||
}
|
||||
|
||||
mVRSystem = (vr::IVRSystem *)vr_GetGenericInterface(vr::IVRSystem_Version, &err);
|
||||
if ((err != vr::VRInitError_None) || !mVRSystem) {
|
||||
vr_ShutdownInternal();
|
||||
return false;
|
||||
}
|
||||
|
||||
mOpenVRInstalled = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
VRControllerManagerOpenVR::Destroy()
|
||||
{
|
||||
mOpenVRController.Clear();
|
||||
mOpenVRInstalled = false;
|
||||
}
|
||||
|
||||
void
|
||||
VRControllerManagerOpenVR::HandleInput()
|
||||
{
|
||||
RefPtr<impl::VRControllerOpenVR> controller;
|
||||
vr::VRControllerState_t state;
|
||||
uint32_t axis = 0;
|
||||
|
||||
if (!mOpenVRInstalled) {
|
||||
return;
|
||||
}
|
||||
|
||||
MOZ_ASSERT(mVRSystem);
|
||||
|
||||
vr::TrackedDevicePose_t poses[vr::k_unMaxTrackedDeviceCount];
|
||||
mVRSystem->GetDeviceToAbsoluteTrackingPose(vr::TrackingUniverseSeated, 0.0f,
|
||||
poses, vr::k_unMaxTrackedDeviceCount);
|
||||
// Process OpenVR controller state
|
||||
for (uint32_t i = 0; i < mOpenVRController.Length(); ++i) {
|
||||
controller = mOpenVRController[i];
|
||||
|
||||
MOZ_ASSERT(mVRSystem->GetTrackedDeviceClass(controller->GetTrackedIndex())
|
||||
== vr::TrackedDeviceClass_Controller);
|
||||
|
||||
if (mVRSystem->GetControllerState(controller->GetTrackedIndex(), &state)) {
|
||||
HandleButtonPress(controller->GetIndex(), state.ulButtonPressed);
|
||||
|
||||
axis = static_cast<uint32_t>(VRControllerAxisType::TrackpadXAxis);
|
||||
HandleAxisMove(controller->GetIndex(), axis,
|
||||
state.rAxis[gOpenVRAxes[axis]].x);
|
||||
|
||||
axis = static_cast<uint32_t>(VRControllerAxisType::TrackpadYAxis);
|
||||
HandleAxisMove(controller->GetIndex(), axis,
|
||||
state.rAxis[gOpenVRAxes[axis]].y);
|
||||
|
||||
axis = static_cast<uint32_t>(VRControllerAxisType::Trigger);
|
||||
HandleAxisMove(controller->GetIndex(), axis,
|
||||
state.rAxis[gOpenVRAxes[axis]].x);
|
||||
}
|
||||
|
||||
// Start to process pose
|
||||
const ::vr::TrackedDevicePose_t& pose = poses[controller->GetTrackedIndex()];
|
||||
|
||||
if (pose.bDeviceIsConnected && pose.bPoseIsValid &&
|
||||
pose.eTrackingResult == vr::TrackingResult_Running_OK) {
|
||||
gfx::Matrix4x4 m;
|
||||
|
||||
// NOTE! mDeviceToAbsoluteTracking is a 3x4 matrix, not 4x4. But
|
||||
// because of its arrangement, we can copy the 12 elements in and
|
||||
// then transpose them to the right place. We do this so we can
|
||||
// pull out a Quaternion.
|
||||
memcpy(&m.components, &pose.mDeviceToAbsoluteTracking, sizeof(float) * 12);
|
||||
m.Transpose();
|
||||
|
||||
gfx::Quaternion rot;
|
||||
rot.SetFromRotationMatrix(m);
|
||||
rot.Invert();
|
||||
|
||||
GamepadPoseState poseState;
|
||||
poseState.flags |= GamepadCapabilityFlags::Cap_Orientation;
|
||||
poseState.orientation[0] = rot.x;
|
||||
poseState.orientation[1] = rot.y;
|
||||
poseState.orientation[2] = rot.z;
|
||||
poseState.orientation[3] = rot.w;
|
||||
poseState.angularVelocity[0] = pose.vAngularVelocity.v[0];
|
||||
poseState.angularVelocity[1] = pose.vAngularVelocity.v[1];
|
||||
poseState.angularVelocity[2] = pose.vAngularVelocity.v[2];
|
||||
|
||||
poseState.flags |= GamepadCapabilityFlags::Cap_Position;
|
||||
poseState.position[0] = m._41;
|
||||
poseState.position[1] = m._42;
|
||||
poseState.position[2] = m._43;
|
||||
poseState.linearVelocity[0] = pose.vVelocity.v[0];
|
||||
poseState.linearVelocity[1] = pose.vVelocity.v[1];
|
||||
poseState.linearVelocity[2] = pose.vVelocity.v[2];
|
||||
HandlePoseTracking(controller->GetIndex(), poseState, controller);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
VRControllerManagerOpenVR::HandleButtonPress(uint32_t aControllerIdx,
|
||||
uint64_t aButtonPressed)
|
||||
{
|
||||
uint64_t buttonMask = 0;
|
||||
RefPtr<impl::VRControllerOpenVR> controller;
|
||||
controller = mOpenVRController[aControllerIdx];
|
||||
uint64_t diff = (controller->GetButtonPressed() ^ aButtonPressed);
|
||||
|
||||
if (!diff) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < gNumOpenVRButtonMask; ++i) {
|
||||
buttonMask = gOpenVRButtonMask[i];
|
||||
|
||||
if (diff & buttonMask) {
|
||||
// diff & aButtonPressed would be true while a new button press
|
||||
// event, otherwise it is an old press event and needs to notify
|
||||
// the button has been released.
|
||||
NewButtonEvent(aControllerIdx, i, diff & aButtonPressed);
|
||||
}
|
||||
}
|
||||
|
||||
controller->SetButtonPressed(aButtonPressed);
|
||||
}
|
||||
|
||||
void
|
||||
VRControllerManagerOpenVR::HandleAxisMove(uint32_t aControllerIdx, uint32_t aAxis,
|
||||
float aValue)
|
||||
{
|
||||
if (aValue != 0.0f) {
|
||||
NewAxisMove(aControllerIdx, aAxis, aValue);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
VRControllerManagerOpenVR::HandlePoseTracking(uint32_t aControllerIdx,
|
||||
const GamepadPoseState& aPose,
|
||||
VRControllerHost* aController)
|
||||
{
|
||||
if (aPose != aController->GetPose()) {
|
||||
aController->SetPose(aPose);
|
||||
NewPoseState(aControllerIdx, aPose);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
VRControllerManagerOpenVR::GetControllers(nsTArray<RefPtr<VRControllerHost>>& aControllerResult)
|
||||
{
|
||||
if (!mOpenVRInstalled) {
|
||||
return;
|
||||
}
|
||||
|
||||
aControllerResult.Clear();
|
||||
for (uint32_t i = 0; i < mOpenVRController.Length(); ++i) {
|
||||
aControllerResult.AppendElement(mOpenVRController[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
VRControllerManagerOpenVR::ScanForDevices()
|
||||
{
|
||||
// Remove the existing gamepads
|
||||
for (uint32_t i = 0; i < mOpenVRController.Length(); ++i) {
|
||||
RemoveGamepad(mOpenVRController[i]->GetIndex());
|
||||
}
|
||||
mControllerCount = 0;
|
||||
mOpenVRController.Clear();
|
||||
|
||||
if (!mVRSystem)
|
||||
return;
|
||||
|
||||
// Basically, we would have HMDs in the tracked devices, but we are just interested in the controllers.
|
||||
for ( vr::TrackedDeviceIndex_t trackedDevice = vr::k_unTrackedDeviceIndex_Hmd + 1;
|
||||
trackedDevice < vr::k_unMaxTrackedDeviceCount; ++trackedDevice ) {
|
||||
if (!mVRSystem->IsTrackedDeviceConnected(trackedDevice)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (mVRSystem->GetTrackedDeviceClass(trackedDevice) != vr::TrackedDeviceClass_Controller) {
|
||||
continue;
|
||||
}
|
||||
|
||||
RefPtr<VRControllerOpenVR> openVRController = new VRControllerOpenVR();
|
||||
openVRController->SetIndex(mControllerCount);
|
||||
openVRController->SetTrackedIndex(trackedDevice);
|
||||
mOpenVRController.AppendElement(openVRController);
|
||||
|
||||
// Only in MOZ_GAMEPAD platform, We add gamepads.
|
||||
#ifdef MOZ_GAMEPAD
|
||||
// Not already present, add it.
|
||||
AddGamepad("OpenVR Gamepad", static_cast<uint32_t>(GamepadMappingType::_empty),
|
||||
gNumOpenVRButtonMask, gNumOpenVRAxis);
|
||||
++mControllerCount;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -1,140 +0,0 @@
|
||||
/* -*- 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_OPENVR_H
|
||||
#define GFX_VR_OPENVR_H
|
||||
|
||||
#include "nsTArray.h"
|
||||
#include "nsIScreen.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "mozilla/RefPtr.h"
|
||||
|
||||
#include "mozilla/gfx/2D.h"
|
||||
#include "mozilla/EnumeratedArray.h"
|
||||
|
||||
#include "gfxVR.h"
|
||||
|
||||
// OpenVR Interfaces
|
||||
namespace vr {
|
||||
class IVRChaperone;
|
||||
class IVRCompositor;
|
||||
class IVRSystem;
|
||||
struct TrackedDevicePose_t;
|
||||
}
|
||||
|
||||
namespace mozilla {
|
||||
namespace gfx {
|
||||
namespace impl {
|
||||
|
||||
class VRDisplayOpenVR : public VRDisplayHost
|
||||
{
|
||||
public:
|
||||
virtual void NotifyVSync() override;
|
||||
virtual VRHMDSensorState GetSensorState() override;
|
||||
virtual VRHMDSensorState GetImmediateSensorState() override;
|
||||
void ZeroSensor() override;
|
||||
|
||||
protected:
|
||||
virtual void StartPresentation() override;
|
||||
virtual void StopPresentation() override;
|
||||
#if defined(XP_WIN)
|
||||
virtual void SubmitFrame(mozilla::layers::TextureSourceD3D11* aSource,
|
||||
const IntSize& aSize,
|
||||
const VRHMDSensorState& aSensorState,
|
||||
const gfx::Rect& aLeftEyeRect,
|
||||
const gfx::Rect& aRightEyeRect) override;
|
||||
#endif
|
||||
|
||||
public:
|
||||
explicit VRDisplayOpenVR(::vr::IVRSystem *aVRSystem,
|
||||
::vr::IVRChaperone *aVRChaperone,
|
||||
::vr::IVRCompositor *aVRCompositor);
|
||||
|
||||
protected:
|
||||
virtual ~VRDisplayOpenVR();
|
||||
void Destroy();
|
||||
|
||||
VRHMDSensorState GetSensorState(double timeOffset);
|
||||
|
||||
// not owned by us; global from OpenVR
|
||||
::vr::IVRSystem *mVRSystem;
|
||||
::vr::IVRChaperone *mVRChaperone;
|
||||
::vr::IVRCompositor *mVRCompositor;
|
||||
|
||||
bool mIsPresenting;
|
||||
|
||||
void UpdateStageParameters();
|
||||
};
|
||||
|
||||
} // namespace impl
|
||||
|
||||
class VRDisplayManagerOpenVR : public VRDisplayManager
|
||||
{
|
||||
public:
|
||||
static already_AddRefed<VRDisplayManagerOpenVR> Create();
|
||||
|
||||
virtual bool Init() override;
|
||||
virtual void Destroy() override;
|
||||
virtual void GetHMDs(nsTArray<RefPtr<VRDisplayHost> >& aHMDResult) override;
|
||||
protected:
|
||||
VRDisplayManagerOpenVR();
|
||||
|
||||
// there can only be one
|
||||
RefPtr<impl::VRDisplayOpenVR> mOpenVRHMD;
|
||||
bool mOpenVRInstalled;
|
||||
};
|
||||
|
||||
namespace impl {
|
||||
|
||||
class VRControllerOpenVR : public VRControllerHost
|
||||
{
|
||||
public:
|
||||
explicit VRControllerOpenVR();
|
||||
void SetTrackedIndex(uint32_t aTrackedIndex);
|
||||
uint32_t GetTrackedIndex();
|
||||
|
||||
protected:
|
||||
virtual ~VRControllerOpenVR();
|
||||
|
||||
// The index of tracked devices from vr::IVRSystem.
|
||||
uint32_t mTrackedIndex;
|
||||
};
|
||||
|
||||
} // namespace impl
|
||||
|
||||
class VRControllerManagerOpenVR : public VRControllerManager
|
||||
{
|
||||
public:
|
||||
static already_AddRefed<VRControllerManagerOpenVR> Create();
|
||||
|
||||
virtual bool Init() override;
|
||||
virtual void Destroy() override;
|
||||
virtual void HandleInput() override;
|
||||
virtual void GetControllers(nsTArray<RefPtr<VRControllerHost>>&
|
||||
aControllerResult) override;
|
||||
virtual void ScanForDevices() override;
|
||||
|
||||
private:
|
||||
VRControllerManagerOpenVR();
|
||||
~VRControllerManagerOpenVR();
|
||||
|
||||
virtual void HandleButtonPress(uint32_t aControllerIdx,
|
||||
uint64_t aButtonPressed) override;
|
||||
virtual void HandleAxisMove(uint32_t aControllerIdx, uint32_t aAxis,
|
||||
float aValue) override;
|
||||
virtual void HandlePoseTracking(uint32_t aControllerIdx,
|
||||
const dom::GamepadPoseState& aPose,
|
||||
VRControllerHost* aController) override;
|
||||
|
||||
bool mOpenVRInstalled;
|
||||
nsTArray<RefPtr<impl::VRControllerOpenVR>> mOpenVRController;
|
||||
vr::IVRSystem *mVRSystem;
|
||||
};
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace mozilla
|
||||
|
||||
|
||||
#endif /* GFX_VR_OPENVR_H */
|
||||
@@ -1,27 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
* vim: sw=2 ts=8 et :
|
||||
*/
|
||||
/* 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/. */
|
||||
|
||||
include protocol PVRManager;
|
||||
include protocol PTexture;
|
||||
|
||||
namespace mozilla {
|
||||
namespace gfx {
|
||||
|
||||
async protocol PVRLayer
|
||||
{
|
||||
manager PVRManager;
|
||||
|
||||
parent:
|
||||
async SubmitFrame(PTexture aTexture);
|
||||
async Destroy();
|
||||
|
||||
child:
|
||||
async __delete__();
|
||||
};
|
||||
|
||||
} // gfx
|
||||
} // mozilla
|
||||
@@ -1,86 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
* vim: sw=2 ts=8 et :
|
||||
*/
|
||||
/* 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/. */
|
||||
|
||||
include LayersSurfaces;
|
||||
include protocol PLayer;
|
||||
include protocol PTexture;
|
||||
include protocol PVRLayer;
|
||||
include LayersMessages;
|
||||
include GamepadEventTypes;
|
||||
|
||||
include "VRMessageUtils.h";
|
||||
|
||||
using struct mozilla::gfx::VRFieldOfView from "gfxVR.h";
|
||||
using struct mozilla::gfx::VRDisplayInfo from "gfxVR.h";
|
||||
using struct mozilla::gfx::VRSensorUpdate from "gfxVR.h";
|
||||
using struct mozilla::gfx::VRHMDSensorState from "gfxVR.h";
|
||||
using struct mozilla::gfx::VRControllerInfo from "gfxVR.h";
|
||||
using mozilla::layers::LayersBackend from "mozilla/layers/LayersTypes.h";
|
||||
using mozilla::layers::TextureFlags from "mozilla/layers/CompositorTypes.h";
|
||||
|
||||
|
||||
namespace mozilla {
|
||||
namespace gfx {
|
||||
|
||||
/**
|
||||
* The PVRManager protocol is used to enable communication of VR display
|
||||
* enumeration and sensor state between the compositor thread and
|
||||
* content threads/processes.
|
||||
*/
|
||||
sync protocol PVRManager
|
||||
{
|
||||
manages PTexture;
|
||||
manages PVRLayer;
|
||||
|
||||
parent:
|
||||
async PTexture(SurfaceDescriptor aSharedData, LayersBackend aBackend,
|
||||
TextureFlags aTextureFlags, uint64_t aSerial);
|
||||
|
||||
async PVRLayer(uint32_t aDisplayID, float aLeftEyeX, float aLeftEyeY, float aLeftEyeWidth, float aLeftEyeHeight, float aRightEyeX, float aRightEyeY, float aRightEyeWidth, float aRightEyeHeight);
|
||||
|
||||
// (Re)Enumerate VR Displays. An updated list of VR displays will be returned
|
||||
// asynchronously to children via UpdateDisplayInfo.
|
||||
async RefreshDisplays();
|
||||
|
||||
// GetDisplays synchronously returns the VR displays that have already been
|
||||
// enumerated by RefreshDisplays() but does not enumerate new ones.
|
||||
sync GetDisplays() returns(VRDisplayInfo[] aDisplayInfo);
|
||||
|
||||
// Reset the sensor of the display identified by aDisplayID so that the current
|
||||
// sensor state is the "Zero" position.
|
||||
async ResetSensor(uint32_t aDisplayID);
|
||||
|
||||
sync GetSensorState(uint32_t aDisplayID) returns(VRHMDSensorState aState);
|
||||
sync GetImmediateSensorState(uint32_t aDisplayID) returns(VRHMDSensorState aState);
|
||||
sync SetHaveEventListener(bool aHaveEventListener);
|
||||
|
||||
async ControllerListenerAdded();
|
||||
async ControllerListenerRemoved();
|
||||
// GetControllers synchronously returns the VR controllers that have already been
|
||||
// enumerated by RefreshVRControllers() but does not enumerate new ones.
|
||||
sync GetControllers() returns(VRControllerInfo[] aControllerInfo);
|
||||
|
||||
child:
|
||||
|
||||
async ParentAsyncMessages(AsyncParentMessageData[] aMessages);
|
||||
|
||||
// Notify children of updated VR display enumeration and details. This will
|
||||
// be sent to all children when the parent receives RefreshDisplays, even
|
||||
// if no changes have been detected. This ensures that Promises exposed
|
||||
// through DOM calls are always resolved.
|
||||
async UpdateDisplayInfo(VRDisplayInfo[] aDisplayUpdates);
|
||||
|
||||
async NotifyVSync();
|
||||
async NotifyVRVSync(uint32_t aDisplayID);
|
||||
async GamepadUpdate(GamepadChangeEvent aGamepadEvent);
|
||||
|
||||
async __delete__();
|
||||
|
||||
};
|
||||
|
||||
} // gfx
|
||||
} // mozilla
|
||||
@@ -1,86 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; 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/. */
|
||||
|
||||
#include "VRLayerChild.h"
|
||||
#include "GLScreenBuffer.h"
|
||||
#include "mozilla/layers/TextureClientSharedSurface.h"
|
||||
#include "SharedSurface.h" // for SharedSurface
|
||||
#include "SharedSurfaceGL.h" // for SharedSurface
|
||||
#include "mozilla/layers/LayersMessages.h" // for TimedTexture
|
||||
#include "nsICanvasRenderingContextInternal.h"
|
||||
#include "mozilla/dom/HTMLCanvasElement.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace gfx {
|
||||
|
||||
VRLayerChild::VRLayerChild(uint32_t aVRDisplayID, VRManagerChild* aVRManagerChild)
|
||||
: mVRDisplayID(aVRDisplayID)
|
||||
, mCanvasElement(nullptr)
|
||||
, mShSurfClient(nullptr)
|
||||
, mFront(nullptr)
|
||||
{
|
||||
MOZ_COUNT_CTOR(VRLayerChild);
|
||||
}
|
||||
|
||||
VRLayerChild::~VRLayerChild()
|
||||
{
|
||||
if (mCanvasElement) {
|
||||
mCanvasElement->StopVRPresentation();
|
||||
}
|
||||
|
||||
ClearSurfaces();
|
||||
|
||||
MOZ_COUNT_DTOR(VRLayerChild);
|
||||
}
|
||||
|
||||
void
|
||||
VRLayerChild::Initialize(dom::HTMLCanvasElement* aCanvasElement)
|
||||
{
|
||||
MOZ_ASSERT(aCanvasElement);
|
||||
mCanvasElement = aCanvasElement;
|
||||
mCanvasElement->StartVRPresentation();
|
||||
|
||||
VRManagerChild *vrmc = VRManagerChild::Get();
|
||||
vrmc->RunFrameRequestCallbacks();
|
||||
}
|
||||
|
||||
void
|
||||
VRLayerChild::SubmitFrame()
|
||||
{
|
||||
if (!mCanvasElement) {
|
||||
return;
|
||||
}
|
||||
|
||||
mShSurfClient = mCanvasElement->GetVRFrame();
|
||||
if (!mShSurfClient) {
|
||||
return;
|
||||
}
|
||||
|
||||
gl::SharedSurface* surf = mShSurfClient->Surf();
|
||||
if (surf->mType == gl::SharedSurfaceType::Basic) {
|
||||
gfxCriticalError() << "SharedSurfaceType::Basic not supported for WebVR";
|
||||
return;
|
||||
}
|
||||
|
||||
mFront = mShSurfClient;
|
||||
mShSurfClient = nullptr;
|
||||
|
||||
mFront->SetAddedToCompositableClient();
|
||||
VRManagerChild* vrmc = VRManagerChild::Get();
|
||||
mFront->SyncWithObject(vrmc->GetSyncObject());
|
||||
MOZ_ALWAYS_TRUE(mFront->InitIPDLActor(vrmc));
|
||||
|
||||
SendSubmitFrame(mFront->GetIPDLActor());
|
||||
}
|
||||
|
||||
void
|
||||
VRLayerChild::ClearSurfaces()
|
||||
{
|
||||
mFront = nullptr;
|
||||
mShSurfClient = nullptr;
|
||||
}
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace mozilla
|
||||
@@ -1,53 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; 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_LAYERCHILD_H
|
||||
#define GFX_VR_LAYERCHILD_H
|
||||
|
||||
#include "VRManagerChild.h"
|
||||
|
||||
#include "mozilla/RefPtr.h"
|
||||
#include "mozilla/gfx/PVRLayerChild.h"
|
||||
#include "GLContext.h"
|
||||
#include "gfxVR.h"
|
||||
|
||||
class nsICanvasRenderingContextInternal;
|
||||
|
||||
namespace mozilla {
|
||||
class WebGLContext;
|
||||
namespace dom {
|
||||
class HTMLCanvasElement;
|
||||
}
|
||||
namespace layers {
|
||||
class SharedSurfaceTextureClient;
|
||||
}
|
||||
namespace gl {
|
||||
class SurfaceFactory;
|
||||
}
|
||||
namespace gfx {
|
||||
|
||||
class VRLayerChild : public PVRLayerChild {
|
||||
NS_INLINE_DECL_REFCOUNTING(VRLayerChild)
|
||||
|
||||
public:
|
||||
VRLayerChild(uint32_t aVRDisplayID, VRManagerChild* aVRManagerChild);
|
||||
void Initialize(dom::HTMLCanvasElement* aCanvasElement);
|
||||
void SubmitFrame();
|
||||
|
||||
protected:
|
||||
virtual ~VRLayerChild();
|
||||
void ClearSurfaces();
|
||||
|
||||
uint32_t mVRDisplayID;
|
||||
|
||||
RefPtr<dom::HTMLCanvasElement> mCanvasElement;
|
||||
RefPtr<layers::SharedSurfaceTextureClient> mShSurfClient;
|
||||
RefPtr<layers::TextureClient> mFront;
|
||||
};
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace mozilla
|
||||
|
||||
#endif
|
||||
@@ -1,59 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; 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/. */
|
||||
|
||||
|
||||
#include "VRLayerParent.h"
|
||||
#include "mozilla/Unused.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace gfx {
|
||||
|
||||
VRLayerParent::VRLayerParent(uint32_t aVRDisplayID, const Rect& aLeftEyeRect, const Rect& aRightEyeRect)
|
||||
: mIPCOpen(true)
|
||||
, mVRDisplayID(aVRDisplayID)
|
||||
, mLeftEyeRect(aLeftEyeRect)
|
||||
, mRightEyeRect(aRightEyeRect)
|
||||
{
|
||||
MOZ_COUNT_CTOR(VRLayerParent);
|
||||
}
|
||||
|
||||
VRLayerParent::~VRLayerParent()
|
||||
{
|
||||
MOZ_COUNT_DTOR(VRLayerParent);
|
||||
}
|
||||
|
||||
bool
|
||||
VRLayerParent::RecvDestroy()
|
||||
{
|
||||
Destroy();
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
VRLayerParent::ActorDestroy(ActorDestroyReason aWhy)
|
||||
{
|
||||
mIPCOpen = false;
|
||||
}
|
||||
|
||||
void
|
||||
VRLayerParent::Destroy()
|
||||
{
|
||||
if (mIPCOpen) {
|
||||
Unused << PVRLayerParent::Send__delete__(this);
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
VRLayerParent::RecvSubmitFrame(PTextureParent* texture)
|
||||
{
|
||||
VRManager* vm = VRManager::Get();
|
||||
vm->SubmitFrame(this, texture, mLeftEyeRect, mRightEyeRect);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace mozilla
|
||||
@@ -1,43 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; 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_LAYERPARENT_H
|
||||
#define GFX_VR_LAYERPARENT_H
|
||||
|
||||
#include "VRManager.h"
|
||||
|
||||
#include "mozilla/RefPtr.h"
|
||||
#include "mozilla/gfx/PVRLayerParent.h"
|
||||
#include "gfxVR.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace gfx {
|
||||
|
||||
class VRLayerParent : public PVRLayerParent {
|
||||
NS_INLINE_DECL_REFCOUNTING(VRLayerParent)
|
||||
|
||||
public:
|
||||
VRLayerParent(uint32_t aVRDisplayID, const Rect& aLeftEyeRect, const Rect& aRightEyeRect);
|
||||
virtual bool RecvSubmitFrame(PTextureParent* texture) override;
|
||||
virtual bool RecvDestroy() override;
|
||||
uint32_t GetDisplayID() const { return mVRDisplayID; }
|
||||
protected:
|
||||
virtual void ActorDestroy(ActorDestroyReason aWhy) override;
|
||||
|
||||
virtual ~VRLayerParent();
|
||||
void Destroy();
|
||||
|
||||
bool mIPCOpen;
|
||||
|
||||
uint32_t mVRDisplayID;
|
||||
gfx::IntSize mSize;
|
||||
gfx::Rect mLeftEyeRect;
|
||||
gfx::Rect mRightEyeRect;
|
||||
};
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace mozilla
|
||||
|
||||
#endif
|
||||
@@ -1,593 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
* vim: sw=2 ts=8 et :
|
||||
*/
|
||||
/* 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/. */
|
||||
|
||||
#include "VRManagerChild.h"
|
||||
#include "VRManagerParent.h"
|
||||
#include "VRDisplayClient.h"
|
||||
#include "nsGlobalWindow.h"
|
||||
#include "mozilla/StaticPtr.h"
|
||||
#include "mozilla/layers/CompositorThread.h" // for CompositorThread
|
||||
#include "mozilla/dom/Navigator.h"
|
||||
#include "mozilla/dom/VREventObserver.h"
|
||||
#include "mozilla/dom/WindowBinding.h" // for FrameRequestCallback
|
||||
#include "mozilla/dom/ContentChild.h"
|
||||
#include "mozilla/layers/TextureClient.h"
|
||||
#include "nsContentUtils.h"
|
||||
|
||||
#ifdef MOZ_GAMEPAD
|
||||
#include "mozilla/dom/GamepadManager.h"
|
||||
#endif
|
||||
|
||||
using layers::TextureClient;
|
||||
|
||||
namespace {
|
||||
const nsTArray<RefPtr<dom::VREventObserver>>::index_type kNoIndex =
|
||||
nsTArray<RefPtr<dom::VREventObserver> >::NoIndex;
|
||||
} // namespace
|
||||
|
||||
namespace mozilla {
|
||||
namespace gfx {
|
||||
|
||||
static StaticRefPtr<VRManagerChild> sVRManagerChildSingleton;
|
||||
static StaticRefPtr<VRManagerParent> sVRManagerParentSingleton;
|
||||
|
||||
void ReleaseVRManagerParentSingleton() {
|
||||
sVRManagerParentSingleton = nullptr;
|
||||
}
|
||||
|
||||
VRManagerChild::VRManagerChild()
|
||||
: TextureForwarder()
|
||||
, mDisplaysInitialized(false)
|
||||
, mInputFrameID(-1)
|
||||
, mMessageLoop(MessageLoop::current())
|
||||
, mFrameRequestCallbackCounter(0)
|
||||
, mBackend(layers::LayersBackend::LAYERS_NONE)
|
||||
{
|
||||
MOZ_COUNT_CTOR(VRManagerChild);
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
mStartTimeStamp = TimeStamp::Now();
|
||||
}
|
||||
|
||||
VRManagerChild::~VRManagerChild()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_COUNT_DTOR(VRManagerChild);
|
||||
}
|
||||
|
||||
/*static*/ void
|
||||
VRManagerChild::IdentifyTextureHost(const TextureFactoryIdentifier& aIdentifier)
|
||||
{
|
||||
if (sVRManagerChildSingleton) {
|
||||
sVRManagerChildSingleton->mBackend = aIdentifier.mParentBackend;
|
||||
sVRManagerChildSingleton->mSyncObject = SyncObject::CreateSyncObject(aIdentifier.mSyncHandle);
|
||||
}
|
||||
}
|
||||
|
||||
layers::LayersBackend
|
||||
VRManagerChild::GetBackendType() const
|
||||
{
|
||||
return mBackend;
|
||||
}
|
||||
|
||||
/*static*/ VRManagerChild*
|
||||
VRManagerChild::Get()
|
||||
{
|
||||
MOZ_ASSERT(sVRManagerChildSingleton);
|
||||
return sVRManagerChildSingleton;
|
||||
}
|
||||
|
||||
/* static */ bool
|
||||
VRManagerChild::IsCreated()
|
||||
{
|
||||
return !!sVRManagerChildSingleton;
|
||||
}
|
||||
|
||||
/* static */ bool
|
||||
VRManagerChild::InitForContent(Endpoint<PVRManagerChild>&& aEndpoint)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(!sVRManagerChildSingleton);
|
||||
|
||||
RefPtr<VRManagerChild> child(new VRManagerChild());
|
||||
if (!aEndpoint.Bind(child)) {
|
||||
NS_RUNTIMEABORT("Couldn't Open() Compositor channel.");
|
||||
return false;
|
||||
}
|
||||
sVRManagerChildSingleton = child;
|
||||
return true;
|
||||
}
|
||||
|
||||
/* static */ bool
|
||||
VRManagerChild::ReinitForContent(Endpoint<PVRManagerChild>&& aEndpoint)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
ShutDown();
|
||||
|
||||
return InitForContent(Move(aEndpoint));
|
||||
}
|
||||
|
||||
/*static*/ void
|
||||
VRManagerChild::InitSameProcess()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(!sVRManagerChildSingleton);
|
||||
|
||||
sVRManagerChildSingleton = new VRManagerChild();
|
||||
sVRManagerParentSingleton = VRManagerParent::CreateSameProcess();
|
||||
sVRManagerChildSingleton->Open(sVRManagerParentSingleton->GetIPCChannel(),
|
||||
mozilla::layers::CompositorThreadHolder::Loop(),
|
||||
mozilla::ipc::ChildSide);
|
||||
}
|
||||
|
||||
/* static */ void
|
||||
VRManagerChild::InitWithGPUProcess(Endpoint<PVRManagerChild>&& aEndpoint)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(!sVRManagerChildSingleton);
|
||||
|
||||
sVRManagerChildSingleton = new VRManagerChild();
|
||||
if (!aEndpoint.Bind(sVRManagerChildSingleton)) {
|
||||
NS_RUNTIMEABORT("Couldn't Open() Compositor channel.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/*static*/ void
|
||||
VRManagerChild::ShutDown()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
if (sVRManagerChildSingleton) {
|
||||
sVRManagerChildSingleton->Destroy();
|
||||
sVRManagerChildSingleton = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
/*static*/ void
|
||||
VRManagerChild::DeferredDestroy(RefPtr<VRManagerChild> aVRManagerChild)
|
||||
{
|
||||
aVRManagerChild->Close();
|
||||
}
|
||||
|
||||
void
|
||||
VRManagerChild::Destroy()
|
||||
{
|
||||
mTexturesWaitingRecycled.Clear();
|
||||
|
||||
// Keep ourselves alive until everything has been shut down
|
||||
RefPtr<VRManagerChild> selfRef = this;
|
||||
|
||||
// The DeferredDestroyVRManager task takes ownership of
|
||||
// the VRManagerChild and will release it when it runs.
|
||||
MessageLoop::current()->PostTask(
|
||||
NewRunnableFunction(DeferredDestroy, selfRef));
|
||||
}
|
||||
|
||||
layers::PTextureChild*
|
||||
VRManagerChild::AllocPTextureChild(const SurfaceDescriptor&,
|
||||
const LayersBackend&,
|
||||
const TextureFlags&,
|
||||
const uint64_t&)
|
||||
{
|
||||
return TextureClient::CreateIPDLActor();
|
||||
}
|
||||
|
||||
bool
|
||||
VRManagerChild::DeallocPTextureChild(PTextureChild* actor)
|
||||
{
|
||||
return TextureClient::DestroyIPDLActor(actor);
|
||||
}
|
||||
|
||||
PVRLayerChild*
|
||||
VRManagerChild::AllocPVRLayerChild(const uint32_t& aDisplayID,
|
||||
const float& aLeftEyeX,
|
||||
const float& aLeftEyeY,
|
||||
const float& aLeftEyeWidth,
|
||||
const float& aLeftEyeHeight,
|
||||
const float& aRightEyeX,
|
||||
const float& aRightEyeY,
|
||||
const float& aRightEyeWidth,
|
||||
const float& aRightEyeHeight)
|
||||
{
|
||||
RefPtr<VRLayerChild> layer = new VRLayerChild(aDisplayID, this);
|
||||
return layer.forget().take();
|
||||
}
|
||||
|
||||
bool
|
||||
VRManagerChild::DeallocPVRLayerChild(PVRLayerChild* actor)
|
||||
{
|
||||
delete actor;
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
VRManagerChild::UpdateDisplayInfo(nsTArray<VRDisplayInfo>& aDisplayUpdates)
|
||||
{
|
||||
bool bDisplayConnected = false;
|
||||
bool bDisplayDisconnected = false;
|
||||
|
||||
// Check if any displays have been disconnected
|
||||
for (auto& display : mDisplays) {
|
||||
bool found = false;
|
||||
for (auto& displayUpdate : aDisplayUpdates) {
|
||||
if (display->GetDisplayInfo().GetDisplayID() == displayUpdate.GetDisplayID()) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
display->NotifyDisconnected();
|
||||
bDisplayDisconnected = true;
|
||||
}
|
||||
}
|
||||
|
||||
// mDisplays could be a hashed container for more scalability, but not worth
|
||||
// it now as we expect < 10 entries.
|
||||
nsTArray<RefPtr<VRDisplayClient>> displays;
|
||||
for (VRDisplayInfo& displayUpdate : aDisplayUpdates) {
|
||||
bool isNewDisplay = true;
|
||||
for (auto& display : mDisplays) {
|
||||
const VRDisplayInfo& prevInfo = display->GetDisplayInfo();
|
||||
if (prevInfo.GetDisplayID() == displayUpdate.GetDisplayID()) {
|
||||
if (displayUpdate.GetIsConnected() && !prevInfo.GetIsConnected()) {
|
||||
bDisplayConnected = true;
|
||||
}
|
||||
if (!displayUpdate.GetIsConnected() && prevInfo.GetIsConnected()) {
|
||||
bDisplayDisconnected = true;
|
||||
}
|
||||
display->UpdateDisplayInfo(displayUpdate);
|
||||
displays.AppendElement(display);
|
||||
isNewDisplay = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (isNewDisplay) {
|
||||
displays.AppendElement(new VRDisplayClient(displayUpdate));
|
||||
bDisplayConnected = true;
|
||||
}
|
||||
}
|
||||
|
||||
mDisplays = displays;
|
||||
|
||||
if (bDisplayConnected) {
|
||||
FireDOMVRDisplayConnectEvent();
|
||||
}
|
||||
if (bDisplayDisconnected) {
|
||||
FireDOMVRDisplayDisconnectEvent();
|
||||
}
|
||||
|
||||
mDisplaysInitialized = true;
|
||||
}
|
||||
|
||||
bool
|
||||
VRManagerChild::RecvUpdateDisplayInfo(nsTArray<VRDisplayInfo>&& aDisplayUpdates)
|
||||
{
|
||||
UpdateDisplayInfo(aDisplayUpdates);
|
||||
for (auto& windowId : mNavigatorCallbacks) {
|
||||
/** We must call NotifyVRDisplaysUpdated for every
|
||||
* window's Navigator in mNavigatorCallbacks to ensure that
|
||||
* the promise returned by Navigator.GetVRDevices
|
||||
* can resolve. This must happen even if no changes
|
||||
* to VRDisplays have been detected here.
|
||||
*/
|
||||
nsGlobalWindow* window = nsGlobalWindow::GetInnerWindowWithId(windowId);
|
||||
if (!window) {
|
||||
continue;
|
||||
}
|
||||
ErrorResult result;
|
||||
dom::Navigator* nav = window->GetNavigator(result);
|
||||
if (NS_WARN_IF(result.Failed())) {
|
||||
continue;
|
||||
}
|
||||
nav->NotifyVRDisplaysUpdated();
|
||||
}
|
||||
mNavigatorCallbacks.Clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
VRManagerChild::GetVRDisplays(nsTArray<RefPtr<VRDisplayClient>>& aDisplays)
|
||||
{
|
||||
if (!mDisplaysInitialized) {
|
||||
/**
|
||||
* If we haven't received any asynchronous callback after requesting
|
||||
* display enumeration with RefreshDisplays, get the existing displays
|
||||
* that have already been enumerated by other VRManagerChild instances.
|
||||
*/
|
||||
nsTArray<VRDisplayInfo> displays;
|
||||
Unused << SendGetDisplays(&displays);
|
||||
UpdateDisplayInfo(displays);
|
||||
}
|
||||
aDisplays = mDisplays;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
VRManagerChild::RefreshVRDisplaysWithCallback(uint64_t aWindowId)
|
||||
{
|
||||
bool success = SendRefreshDisplays();
|
||||
if (success) {
|
||||
mNavigatorCallbacks.AppendElement(aWindowId);
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
int
|
||||
VRManagerChild::GetInputFrameID()
|
||||
{
|
||||
return mInputFrameID;
|
||||
}
|
||||
|
||||
bool
|
||||
VRManagerChild::RecvParentAsyncMessages(InfallibleTArray<AsyncParentMessageData>&& aMessages)
|
||||
{
|
||||
for (InfallibleTArray<AsyncParentMessageData>::index_type i = 0; i < aMessages.Length(); ++i) {
|
||||
const AsyncParentMessageData& message = aMessages[i];
|
||||
|
||||
switch (message.type()) {
|
||||
case AsyncParentMessageData::TOpNotifyNotUsed: {
|
||||
const OpNotifyNotUsed& op = message.get_OpNotifyNotUsed();
|
||||
NotifyNotUsed(op.TextureId(), op.fwdTransactionId());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
NS_ERROR("unknown AsyncParentMessageData type");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
PTextureChild*
|
||||
VRManagerChild::CreateTexture(const SurfaceDescriptor& aSharedData,
|
||||
LayersBackend aLayersBackend,
|
||||
TextureFlags aFlags,
|
||||
uint64_t aSerial)
|
||||
{
|
||||
return SendPTextureConstructor(aSharedData, aLayersBackend, aFlags, aSerial);
|
||||
}
|
||||
|
||||
void
|
||||
VRManagerChild::CancelWaitForRecycle(uint64_t aTextureId)
|
||||
{
|
||||
RefPtr<TextureClient> client = mTexturesWaitingRecycled.Get(aTextureId);
|
||||
if (!client) {
|
||||
return;
|
||||
}
|
||||
mTexturesWaitingRecycled.Remove(aTextureId);
|
||||
}
|
||||
|
||||
void
|
||||
VRManagerChild::NotifyNotUsed(uint64_t aTextureId, uint64_t aFwdTransactionId)
|
||||
{
|
||||
RefPtr<TextureClient> client = mTexturesWaitingRecycled.Get(aTextureId);
|
||||
if (!client) {
|
||||
return;
|
||||
}
|
||||
mTexturesWaitingRecycled.Remove(aTextureId);
|
||||
}
|
||||
|
||||
bool
|
||||
VRManagerChild::AllocShmem(size_t aSize,
|
||||
ipc::SharedMemory::SharedMemoryType aType,
|
||||
ipc::Shmem* aShmem)
|
||||
{
|
||||
return PVRManagerChild::AllocShmem(aSize, aType, aShmem);
|
||||
}
|
||||
|
||||
bool
|
||||
VRManagerChild::AllocUnsafeShmem(size_t aSize,
|
||||
ipc::SharedMemory::SharedMemoryType aType,
|
||||
ipc::Shmem* aShmem)
|
||||
{
|
||||
return PVRManagerChild::AllocUnsafeShmem(aSize, aType, aShmem);
|
||||
}
|
||||
|
||||
bool
|
||||
VRManagerChild::DeallocShmem(ipc::Shmem& aShmem)
|
||||
{
|
||||
return PVRManagerChild::DeallocShmem(aShmem);
|
||||
}
|
||||
|
||||
PVRLayerChild*
|
||||
VRManagerChild::CreateVRLayer(uint32_t aDisplayID, const Rect& aLeftEyeRect, const Rect& aRightEyeRect)
|
||||
{
|
||||
return SendPVRLayerConstructor(aDisplayID,
|
||||
aLeftEyeRect.x, aLeftEyeRect.y, aLeftEyeRect.width, aLeftEyeRect.height,
|
||||
aRightEyeRect.x, aRightEyeRect.y, aRightEyeRect.width, aRightEyeRect.height);
|
||||
}
|
||||
|
||||
|
||||
// XXX TODO - VRManagerChild::FrameRequest is the same as nsIDocument::FrameRequest, should we consolodate these?
|
||||
struct VRManagerChild::FrameRequest
|
||||
{
|
||||
FrameRequest(mozilla::dom::FrameRequestCallback& aCallback,
|
||||
int32_t aHandle) :
|
||||
mCallback(&aCallback),
|
||||
mHandle(aHandle)
|
||||
{}
|
||||
|
||||
// Conversion operator so that we can append these to a
|
||||
// FrameRequestCallbackList
|
||||
operator const RefPtr<mozilla::dom::FrameRequestCallback>& () const {
|
||||
return mCallback;
|
||||
}
|
||||
|
||||
// Comparator operators to allow RemoveElementSorted with an
|
||||
// integer argument on arrays of FrameRequest
|
||||
bool operator==(int32_t aHandle) const {
|
||||
return mHandle == aHandle;
|
||||
}
|
||||
bool operator<(int32_t aHandle) const {
|
||||
return mHandle < aHandle;
|
||||
}
|
||||
|
||||
RefPtr<mozilla::dom::FrameRequestCallback> mCallback;
|
||||
int32_t mHandle;
|
||||
};
|
||||
|
||||
nsresult
|
||||
VRManagerChild::ScheduleFrameRequestCallback(mozilla::dom::FrameRequestCallback& aCallback,
|
||||
int32_t *aHandle)
|
||||
{
|
||||
if (mFrameRequestCallbackCounter == INT32_MAX) {
|
||||
// Can't increment without overflowing; bail out
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
int32_t newHandle = ++mFrameRequestCallbackCounter;
|
||||
|
||||
DebugOnly<FrameRequest*> request =
|
||||
mFrameRequestCallbacks.AppendElement(FrameRequest(aCallback, newHandle));
|
||||
NS_ASSERTION(request, "This is supposed to be infallible!");
|
||||
|
||||
*aHandle = newHandle;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
VRManagerChild::CancelFrameRequestCallback(int32_t aHandle)
|
||||
{
|
||||
// mFrameRequestCallbacks is stored sorted by handle
|
||||
mFrameRequestCallbacks.RemoveElementSorted(aHandle);
|
||||
}
|
||||
|
||||
bool
|
||||
VRManagerChild::RecvNotifyVSync()
|
||||
{
|
||||
for (auto& display : mDisplays) {
|
||||
display->NotifyVsync();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
VRManagerChild::RecvNotifyVRVSync(const uint32_t& aDisplayID)
|
||||
{
|
||||
for (auto& display : mDisplays) {
|
||||
if (display->GetDisplayInfo().GetDisplayID() == aDisplayID) {
|
||||
display->NotifyVRVsync();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
VRManagerChild::RecvGamepadUpdate(const GamepadChangeEvent& aGamepadEvent)
|
||||
{
|
||||
#ifdef MOZ_GAMEPAD
|
||||
// VRManagerChild could be at other processes, but GamepadManager
|
||||
// only exists at the content process or the same process
|
||||
// in non-e10s mode.
|
||||
MOZ_ASSERT(XRE_IsContentProcess() || IsSameProcess());
|
||||
|
||||
RefPtr<GamepadManager> gamepadManager(GamepadManager::GetService());
|
||||
if (gamepadManager) {
|
||||
gamepadManager->Update(aGamepadEvent);
|
||||
}
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
VRManagerChild::RunFrameRequestCallbacks()
|
||||
{
|
||||
TimeStamp nowTime = TimeStamp::Now();
|
||||
mozilla::TimeDuration duration = nowTime - mStartTimeStamp;
|
||||
DOMHighResTimeStamp timeStamp = duration.ToMilliseconds();
|
||||
|
||||
|
||||
nsTArray<FrameRequest> callbacks;
|
||||
callbacks.AppendElements(mFrameRequestCallbacks);
|
||||
mFrameRequestCallbacks.Clear();
|
||||
for (auto& callback : callbacks) {
|
||||
callback.mCallback->Call(timeStamp);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
VRManagerChild::FireDOMVRDisplayConnectEvent()
|
||||
{
|
||||
nsContentUtils::AddScriptRunner(NewRunnableMethod(this,
|
||||
&VRManagerChild::FireDOMVRDisplayConnectEventInternal));
|
||||
}
|
||||
|
||||
void
|
||||
VRManagerChild::FireDOMVRDisplayDisconnectEvent()
|
||||
{
|
||||
nsContentUtils::AddScriptRunner(NewRunnableMethod(this,
|
||||
&VRManagerChild::FireDOMVRDisplayDisconnectEventInternal));
|
||||
}
|
||||
|
||||
void
|
||||
VRManagerChild::FireDOMVRDisplayPresentChangeEvent()
|
||||
{
|
||||
nsContentUtils::AddScriptRunner(NewRunnableMethod(this,
|
||||
&VRManagerChild::FireDOMVRDisplayPresentChangeEventInternal));
|
||||
}
|
||||
|
||||
void
|
||||
VRManagerChild::FireDOMVRDisplayConnectEventInternal()
|
||||
{
|
||||
for (auto& listener : mListeners) {
|
||||
listener->NotifyVRDisplayConnect();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
VRManagerChild::FireDOMVRDisplayDisconnectEventInternal()
|
||||
{
|
||||
for (auto& listener : mListeners) {
|
||||
listener->NotifyVRDisplayDisconnect();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
VRManagerChild::FireDOMVRDisplayPresentChangeEventInternal()
|
||||
{
|
||||
for (auto& listener : mListeners) {
|
||||
listener->NotifyVRDisplayPresentChange();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
VRManagerChild::AddListener(dom::VREventObserver* aObserver)
|
||||
{
|
||||
MOZ_ASSERT(aObserver);
|
||||
|
||||
if (mListeners.IndexOf(aObserver) != kNoIndex) {
|
||||
return; // already exists
|
||||
}
|
||||
|
||||
mListeners.AppendElement(aObserver);
|
||||
if (mListeners.Length() == 1) {
|
||||
Unused << SendSetHaveEventListener(true);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
VRManagerChild::RemoveListener(dom::VREventObserver* aObserver)
|
||||
{
|
||||
MOZ_ASSERT(aObserver);
|
||||
|
||||
mListeners.RemoveElement(aObserver);
|
||||
if (mListeners.IsEmpty()) {
|
||||
Unused << SendSetHaveEventListener(false);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
VRManagerChild::HandleFatalError(const char* aName, const char* aMsg) const
|
||||
{
|
||||
dom::ContentChild::FatalErrorIfNotUsingGPUProcess(aName, aMsg, OtherPid());
|
||||
}
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace mozilla
|
||||
@@ -1,185 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
* vim: sw=2 ts=8 et :
|
||||
*/
|
||||
/* 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 MOZILLA_GFX_VR_VRMANAGERCHILD_H
|
||||
#define MOZILLA_GFX_VR_VRMANAGERCHILD_H
|
||||
|
||||
#include "mozilla/gfx/PVRManagerChild.h"
|
||||
#include "mozilla/ipc/SharedMemory.h" // for SharedMemory, etc
|
||||
#include "ThreadSafeRefcountingWithMainThreadDestruction.h"
|
||||
#include "mozilla/layers/ISurfaceAllocator.h" // for ISurfaceAllocator
|
||||
#include "mozilla/layers/LayersTypes.h" // for LayersBackend
|
||||
#include "mozilla/layers/TextureForwarder.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
class GamepadManager;
|
||||
class Navigator;
|
||||
class VRDisplay;
|
||||
class VREventObserver;
|
||||
} // namespace dom
|
||||
namespace layers {
|
||||
class PCompositableChild;
|
||||
class TextureClient;
|
||||
}
|
||||
namespace gfx {
|
||||
class VRLayerChild;
|
||||
class VRDisplayClient;
|
||||
|
||||
class VRManagerChild : public PVRManagerChild
|
||||
, public layers::TextureForwarder
|
||||
, public layers::KnowsCompositor
|
||||
{
|
||||
public:
|
||||
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VRManagerChild, override);
|
||||
|
||||
TextureForwarder* GetTextureForwarder() override { return this; }
|
||||
LayersIPCActor* GetLayersIPCActor() override { return this; }
|
||||
|
||||
static VRManagerChild* Get();
|
||||
|
||||
// Indicate that an observer wants to receive VR events.
|
||||
void AddListener(dom::VREventObserver* aObserver);
|
||||
// Indicate that an observer should no longer receive VR events.
|
||||
void RemoveListener(dom::VREventObserver* aObserver);
|
||||
|
||||
int GetInputFrameID();
|
||||
bool GetVRDisplays(nsTArray<RefPtr<VRDisplayClient> >& aDisplays);
|
||||
bool RefreshVRDisplaysWithCallback(uint64_t aWindowId);
|
||||
|
||||
static void InitSameProcess();
|
||||
static void InitWithGPUProcess(Endpoint<PVRManagerChild>&& aEndpoint);
|
||||
static bool InitForContent(Endpoint<PVRManagerChild>&& aEndpoint);
|
||||
static bool ReinitForContent(Endpoint<PVRManagerChild>&& aEndpoint);
|
||||
static void ShutDown();
|
||||
|
||||
static bool IsCreated();
|
||||
|
||||
virtual PTextureChild* CreateTexture(const SurfaceDescriptor& aSharedData,
|
||||
layers::LayersBackend aLayersBackend,
|
||||
TextureFlags aFlags,
|
||||
uint64_t aSerial) override;
|
||||
virtual void CancelWaitForRecycle(uint64_t aTextureId) override;
|
||||
|
||||
PVRLayerChild* CreateVRLayer(uint32_t aDisplayID, const Rect& aLeftEyeRect, const Rect& aRightEyeRect);
|
||||
|
||||
static void IdentifyTextureHost(const layers::TextureFactoryIdentifier& aIdentifier);
|
||||
layers::LayersBackend GetBackendType() const;
|
||||
layers::SyncObject* GetSyncObject() { return mSyncObject; }
|
||||
|
||||
virtual MessageLoop* GetMessageLoop() const override { return mMessageLoop; }
|
||||
virtual base::ProcessId GetParentPid() const override { return OtherPid(); }
|
||||
|
||||
nsresult ScheduleFrameRequestCallback(mozilla::dom::FrameRequestCallback& aCallback,
|
||||
int32_t *aHandle);
|
||||
void CancelFrameRequestCallback(int32_t aHandle);
|
||||
void RunFrameRequestCallbacks();
|
||||
|
||||
void UpdateDisplayInfo(nsTArray<VRDisplayInfo>& aDisplayUpdates);
|
||||
void FireDOMVRDisplayConnectEvent();
|
||||
void FireDOMVRDisplayDisconnectEvent();
|
||||
void FireDOMVRDisplayPresentChangeEvent();
|
||||
|
||||
virtual void HandleFatalError(const char* aName, const char* aMsg) const override;
|
||||
|
||||
protected:
|
||||
explicit VRManagerChild();
|
||||
~VRManagerChild();
|
||||
void Destroy();
|
||||
static void DeferredDestroy(RefPtr<VRManagerChild> aVRManagerChild);
|
||||
|
||||
virtual PTextureChild* AllocPTextureChild(const SurfaceDescriptor& aSharedData,
|
||||
const layers::LayersBackend& aLayersBackend,
|
||||
const TextureFlags& aFlags,
|
||||
const uint64_t& aSerial) override;
|
||||
virtual bool DeallocPTextureChild(PTextureChild* actor) override;
|
||||
|
||||
virtual PVRLayerChild* AllocPVRLayerChild(const uint32_t& aDisplayID,
|
||||
const float& aLeftEyeX,
|
||||
const float& aLeftEyeY,
|
||||
const float& aLeftEyeWidth,
|
||||
const float& aLeftEyeHeight,
|
||||
const float& aRightEyeX,
|
||||
const float& aRightEyeY,
|
||||
const float& aRightEyeWidth,
|
||||
const float& aRightEyeHeight) override;
|
||||
virtual bool DeallocPVRLayerChild(PVRLayerChild* actor) override;
|
||||
|
||||
virtual bool RecvUpdateDisplayInfo(nsTArray<VRDisplayInfo>&& aDisplayUpdates) override;
|
||||
|
||||
virtual bool RecvParentAsyncMessages(InfallibleTArray<AsyncParentMessageData>&& aMessages) override;
|
||||
|
||||
virtual bool RecvNotifyVSync() override;
|
||||
virtual bool RecvNotifyVRVSync(const uint32_t& aDisplayID) override;
|
||||
virtual bool RecvGamepadUpdate(const GamepadChangeEvent& aGamepadEvent) override;
|
||||
|
||||
// ShmemAllocator
|
||||
|
||||
virtual bool AllocShmem(size_t aSize,
|
||||
ipc::SharedMemory::SharedMemoryType aType,
|
||||
ipc::Shmem* aShmem) override;
|
||||
|
||||
virtual bool AllocUnsafeShmem(size_t aSize,
|
||||
ipc::SharedMemory::SharedMemoryType aType,
|
||||
ipc::Shmem* aShmem) override;
|
||||
|
||||
virtual bool DeallocShmem(ipc::Shmem& aShmem) override;
|
||||
|
||||
virtual bool IsSameProcess() const override
|
||||
{
|
||||
return OtherPid() == base::GetCurrentProcId();
|
||||
}
|
||||
|
||||
friend class layers::CompositorBridgeChild;
|
||||
|
||||
private:
|
||||
|
||||
void FireDOMVRDisplayConnectEventInternal();
|
||||
void FireDOMVRDisplayDisconnectEventInternal();
|
||||
void FireDOMVRDisplayPresentChangeEventInternal();
|
||||
/**
|
||||
* Notify id of Texture When host side end its use. Transaction id is used to
|
||||
* make sure if there is no newer usage.
|
||||
*/
|
||||
void NotifyNotUsed(uint64_t aTextureId, uint64_t aFwdTransactionId);
|
||||
|
||||
nsTArray<RefPtr<VRDisplayClient> > mDisplays;
|
||||
bool mDisplaysInitialized;
|
||||
nsTArray<uint64_t> mNavigatorCallbacks;
|
||||
|
||||
int32_t mInputFrameID;
|
||||
|
||||
MessageLoop* mMessageLoop;
|
||||
|
||||
struct FrameRequest;
|
||||
|
||||
nsTArray<FrameRequest> mFrameRequestCallbacks;
|
||||
/**
|
||||
* The current frame request callback handle
|
||||
*/
|
||||
int32_t mFrameRequestCallbackCounter;
|
||||
mozilla::TimeStamp mStartTimeStamp;
|
||||
|
||||
// Array of Weak pointers, instance is owned by nsGlobalWindow::mVREventObserver.
|
||||
nsTArray<dom::VREventObserver*> mListeners;
|
||||
|
||||
/**
|
||||
* Hold TextureClients refs until end of their usages on host side.
|
||||
* It defer calling of TextureClient recycle callback.
|
||||
*/
|
||||
nsDataHashtable<nsUint64HashKey, RefPtr<layers::TextureClient> > mTexturesWaitingRecycled;
|
||||
|
||||
layers::LayersBackend mBackend;
|
||||
RefPtr<layers::SyncObject> mSyncObject;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(VRManagerChild);
|
||||
};
|
||||
|
||||
} // namespace mozilla
|
||||
} // namespace gfx
|
||||
|
||||
#endif // MOZILLA_GFX_VR_VRMANAGERCHILD_H
|
||||
@@ -1,332 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
* vim: sw=2 ts=8 et :
|
||||
*/
|
||||
/* 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/. */
|
||||
|
||||
#include "VRManagerParent.h"
|
||||
#include "ipc/VRLayerParent.h"
|
||||
#include "mozilla/gfx/PVRManagerParent.h"
|
||||
#include "mozilla/ipc/ProtocolTypes.h"
|
||||
#include "mozilla/ipc/ProtocolUtils.h" // for IToplevelProtocol
|
||||
#include "mozilla/TimeStamp.h" // for TimeStamp
|
||||
#include "mozilla/layers/CompositorThread.h"
|
||||
#include "mozilla/Unused.h"
|
||||
#include "VRManager.h"
|
||||
|
||||
namespace mozilla {
|
||||
using namespace layers;
|
||||
namespace gfx {
|
||||
|
||||
VRManagerParent::VRManagerParent(ProcessId aChildProcessId, bool aIsContentChild)
|
||||
: HostIPCAllocator()
|
||||
, mHaveEventListener(false)
|
||||
, mIsContentChild(aIsContentChild)
|
||||
{
|
||||
MOZ_COUNT_CTOR(VRManagerParent);
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
SetOtherProcessId(aChildProcessId);
|
||||
}
|
||||
|
||||
VRManagerParent::~VRManagerParent()
|
||||
{
|
||||
MOZ_ASSERT(!mVRManagerHolder);
|
||||
|
||||
MOZ_COUNT_DTOR(VRManagerParent);
|
||||
}
|
||||
|
||||
PTextureParent*
|
||||
VRManagerParent::AllocPTextureParent(const SurfaceDescriptor& aSharedData,
|
||||
const LayersBackend& aLayersBackend,
|
||||
const TextureFlags& aFlags,
|
||||
const uint64_t& aSerial)
|
||||
{
|
||||
return layers::TextureHost::CreateIPDLActor(this, aSharedData, aLayersBackend, aFlags, aSerial);
|
||||
}
|
||||
|
||||
bool
|
||||
VRManagerParent::DeallocPTextureParent(PTextureParent* actor)
|
||||
{
|
||||
return layers::TextureHost::DestroyIPDLActor(actor);
|
||||
}
|
||||
|
||||
PVRLayerParent*
|
||||
VRManagerParent::AllocPVRLayerParent(const uint32_t& aDisplayID,
|
||||
const float& aLeftEyeX,
|
||||
const float& aLeftEyeY,
|
||||
const float& aLeftEyeWidth,
|
||||
const float& aLeftEyeHeight,
|
||||
const float& aRightEyeX,
|
||||
const float& aRightEyeY,
|
||||
const float& aRightEyeWidth,
|
||||
const float& aRightEyeHeight)
|
||||
{
|
||||
RefPtr<VRLayerParent> layer;
|
||||
layer = new VRLayerParent(aDisplayID,
|
||||
Rect(aLeftEyeX, aLeftEyeY, aLeftEyeWidth, aLeftEyeHeight),
|
||||
Rect(aRightEyeX, aRightEyeY, aRightEyeWidth, aRightEyeHeight));
|
||||
VRManager* vm = VRManager::Get();
|
||||
RefPtr<gfx::VRDisplayHost> display = vm->GetDisplay(aDisplayID);
|
||||
if (display) {
|
||||
display->AddLayer(layer);
|
||||
}
|
||||
return layer.forget().take();
|
||||
}
|
||||
|
||||
bool
|
||||
VRManagerParent::DeallocPVRLayerParent(PVRLayerParent* actor)
|
||||
{
|
||||
gfx::VRLayerParent* layer = static_cast<gfx::VRLayerParent*>(actor);
|
||||
|
||||
VRManager* vm = VRManager::Get();
|
||||
RefPtr<gfx::VRDisplayHost> display = vm->GetDisplay(layer->GetDisplayID());
|
||||
if (display) {
|
||||
display->RemoveLayer(layer);
|
||||
}
|
||||
|
||||
delete actor;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
VRManagerParent::AllocShmem(size_t aSize,
|
||||
ipc::SharedMemory::SharedMemoryType aType,
|
||||
ipc::Shmem* aShmem)
|
||||
{
|
||||
return PVRManagerParent::AllocShmem(aSize, aType, aShmem);
|
||||
}
|
||||
|
||||
bool
|
||||
VRManagerParent::AllocUnsafeShmem(size_t aSize,
|
||||
ipc::SharedMemory::SharedMemoryType aType,
|
||||
ipc::Shmem* aShmem)
|
||||
{
|
||||
return PVRManagerParent::AllocUnsafeShmem(aSize, aType, aShmem);
|
||||
}
|
||||
|
||||
void
|
||||
VRManagerParent::DeallocShmem(ipc::Shmem& aShmem)
|
||||
{
|
||||
PVRManagerParent::DeallocShmem(aShmem);
|
||||
}
|
||||
|
||||
bool
|
||||
VRManagerParent::IsSameProcess() const
|
||||
{
|
||||
return OtherPid() == base::GetCurrentProcId();
|
||||
}
|
||||
|
||||
void
|
||||
VRManagerParent::NotifyNotUsed(PTextureParent* aTexture, uint64_t aTransactionId)
|
||||
{
|
||||
MOZ_ASSERT_UNREACHABLE("unexpected to be called");
|
||||
}
|
||||
|
||||
void
|
||||
VRManagerParent::SendAsyncMessage(const InfallibleTArray<AsyncParentMessageData>& aMessage)
|
||||
{
|
||||
MOZ_ASSERT_UNREACHABLE("unexpected to be called");
|
||||
}
|
||||
|
||||
base::ProcessId
|
||||
VRManagerParent::GetChildProcessId()
|
||||
{
|
||||
return OtherPid();
|
||||
}
|
||||
|
||||
void
|
||||
VRManagerParent::RegisterWithManager()
|
||||
{
|
||||
VRManager* vm = VRManager::Get();
|
||||
vm->AddVRManagerParent(this);
|
||||
mVRManagerHolder = vm;
|
||||
}
|
||||
|
||||
void
|
||||
VRManagerParent::UnregisterFromManager()
|
||||
{
|
||||
VRManager* vm = VRManager::Get();
|
||||
vm->RemoveVRManagerParent(this);
|
||||
mVRManagerHolder = nullptr;
|
||||
}
|
||||
|
||||
/* static */ bool
|
||||
VRManagerParent::CreateForContent(Endpoint<PVRManagerParent>&& aEndpoint)
|
||||
{
|
||||
MessageLoop* loop = layers::CompositorThreadHolder::Loop();
|
||||
|
||||
RefPtr<VRManagerParent> vmp = new VRManagerParent(aEndpoint.OtherPid(), true);
|
||||
loop->PostTask(NewRunnableMethod<Endpoint<PVRManagerParent>&&>(
|
||||
vmp, &VRManagerParent::Bind, Move(aEndpoint)));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
VRManagerParent::Bind(Endpoint<PVRManagerParent>&& aEndpoint)
|
||||
{
|
||||
if (!aEndpoint.Bind(this)) {
|
||||
return;
|
||||
}
|
||||
mSelfRef = this;
|
||||
|
||||
RegisterWithManager();
|
||||
}
|
||||
|
||||
/*static*/ void
|
||||
VRManagerParent::RegisterVRManagerInCompositorThread(VRManagerParent* aVRManager)
|
||||
{
|
||||
aVRManager->RegisterWithManager();
|
||||
}
|
||||
|
||||
/*static*/ VRManagerParent*
|
||||
VRManagerParent::CreateSameProcess()
|
||||
{
|
||||
MessageLoop* loop = mozilla::layers::CompositorThreadHolder::Loop();
|
||||
RefPtr<VRManagerParent> vmp = new VRManagerParent(base::GetCurrentProcId(), false);
|
||||
vmp->mCompositorThreadHolder = layers::CompositorThreadHolder::GetSingleton();
|
||||
vmp->mSelfRef = vmp;
|
||||
loop->PostTask(NewRunnableFunction(RegisterVRManagerInCompositorThread, vmp.get()));
|
||||
return vmp.get();
|
||||
}
|
||||
|
||||
bool
|
||||
VRManagerParent::CreateForGPUProcess(Endpoint<PVRManagerParent>&& aEndpoint)
|
||||
{
|
||||
MessageLoop* loop = mozilla::layers::CompositorThreadHolder::Loop();
|
||||
|
||||
RefPtr<VRManagerParent> vmp = new VRManagerParent(aEndpoint.OtherPid(), false);
|
||||
vmp->mCompositorThreadHolder = layers::CompositorThreadHolder::GetSingleton();
|
||||
loop->PostTask(NewRunnableMethod<Endpoint<PVRManagerParent>&&>(
|
||||
vmp, &VRManagerParent::Bind, Move(aEndpoint)));
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
VRManagerParent::DeferredDestroy()
|
||||
{
|
||||
mCompositorThreadHolder = nullptr;
|
||||
mSelfRef = nullptr;
|
||||
}
|
||||
|
||||
void
|
||||
VRManagerParent::ActorDestroy(ActorDestroyReason why)
|
||||
{
|
||||
UnregisterFromManager();
|
||||
MessageLoop::current()->PostTask(NewRunnableMethod(this, &VRManagerParent::DeferredDestroy));
|
||||
}
|
||||
|
||||
void
|
||||
VRManagerParent::OnChannelConnected(int32_t aPid)
|
||||
{
|
||||
mCompositorThreadHolder = layers::CompositorThreadHolder::GetSingleton();
|
||||
}
|
||||
|
||||
bool
|
||||
VRManagerParent::RecvRefreshDisplays()
|
||||
{
|
||||
// This is called to refresh the VR Displays for Navigator.GetVRDevices().
|
||||
// We must pass "true" to VRManager::RefreshVRDisplays()
|
||||
// to ensure that the promise returned by Navigator.GetVRDevices
|
||||
// can resolve even if there are no changes to the VR Displays.
|
||||
VRManager* vm = VRManager::Get();
|
||||
vm->RefreshVRDisplays(true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
VRManagerParent::RecvGetDisplays(nsTArray<VRDisplayInfo> *aDisplays)
|
||||
{
|
||||
VRManager* vm = VRManager::Get();
|
||||
vm->GetVRDisplayInfo(*aDisplays);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
VRManagerParent::RecvResetSensor(const uint32_t& aDisplayID)
|
||||
{
|
||||
VRManager* vm = VRManager::Get();
|
||||
RefPtr<gfx::VRDisplayHost> display = vm->GetDisplay(aDisplayID);
|
||||
if (display != nullptr) {
|
||||
display->ZeroSensor();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
VRManagerParent::RecvGetSensorState(const uint32_t& aDisplayID, VRHMDSensorState* aState)
|
||||
{
|
||||
VRManager* vm = VRManager::Get();
|
||||
RefPtr<gfx::VRDisplayHost> display = vm->GetDisplay(aDisplayID);
|
||||
if (display != nullptr) {
|
||||
*aState = display->GetSensorState();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
VRManagerParent::RecvGetImmediateSensorState(const uint32_t& aDisplayID, VRHMDSensorState* aState)
|
||||
{
|
||||
VRManager* vm = VRManager::Get();
|
||||
RefPtr<gfx::VRDisplayHost> display = vm->GetDisplay(aDisplayID);
|
||||
if (display != nullptr) {
|
||||
*aState = display->GetImmediateSensorState();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
VRManagerParent::HaveEventListener()
|
||||
{
|
||||
return mHaveEventListener;
|
||||
}
|
||||
|
||||
bool
|
||||
VRManagerParent::RecvSetHaveEventListener(const bool& aHaveEventListener)
|
||||
{
|
||||
mHaveEventListener = aHaveEventListener;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
VRManagerParent::RecvControllerListenerAdded()
|
||||
{
|
||||
VRManager* vm = VRManager::Get();
|
||||
// Ask the connected gamepads to be added to GamepadManager
|
||||
vm->ScanForDevices();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
VRManagerParent::RecvControllerListenerRemoved()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
VRManagerParent::RecvGetControllers(nsTArray<VRControllerInfo> *aControllers)
|
||||
{
|
||||
VRManager* vm = VRManager::Get();
|
||||
vm->GetVRControllerInfo(*aControllers);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
VRManagerParent::SendGamepadUpdate(const GamepadChangeEvent& aGamepadEvent)
|
||||
{
|
||||
// GamepadManager only exists at the content process
|
||||
// or the same process in non-e10s mode.
|
||||
if (mIsContentChild || IsSameProcess()) {
|
||||
return PVRManagerParent::SendGamepadUpdate(aGamepadEvent);
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace mozilla
|
||||
@@ -1,118 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
* vim: sw=2 ts=8 et :
|
||||
*/
|
||||
/* 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 MOZILLA_GFX_VR_VRMANAGERPARENT_H
|
||||
#define MOZILLA_GFX_VR_VRMANAGERPARENT_H
|
||||
|
||||
#include "mozilla/layers/CompositableTransactionParent.h"
|
||||
#include "mozilla/layers/CompositorThread.h" // for CompositorThreadHolder
|
||||
#include "mozilla/gfx/PVRManagerParent.h" // for PVRManagerParent
|
||||
#include "mozilla/gfx/PVRLayerParent.h" // for PVRLayerParent
|
||||
#include "mozilla/ipc/ProtocolUtils.h" // for IToplevelProtocol
|
||||
#include "mozilla/TimeStamp.h" // for TimeStamp
|
||||
#include "gfxVR.h" // for VRFieldOfView
|
||||
|
||||
namespace mozilla {
|
||||
using namespace layers;
|
||||
namespace gfx {
|
||||
|
||||
class VRManager;
|
||||
|
||||
class VRManagerParent final : public PVRManagerParent
|
||||
, public HostIPCAllocator
|
||||
, public ShmemAllocator
|
||||
{
|
||||
public:
|
||||
explicit VRManagerParent(ProcessId aChildProcessId, bool aIsContentChild);
|
||||
|
||||
static VRManagerParent* CreateSameProcess();
|
||||
static bool CreateForGPUProcess(Endpoint<PVRManagerParent>&& aEndpoint);
|
||||
static bool CreateForContent(Endpoint<PVRManagerParent>&& aEndpoint);
|
||||
|
||||
virtual base::ProcessId GetChildProcessId() override;
|
||||
|
||||
// ShmemAllocator
|
||||
|
||||
virtual ShmemAllocator* AsShmemAllocator() override { return this; }
|
||||
|
||||
virtual bool AllocShmem(size_t aSize,
|
||||
ipc::SharedMemory::SharedMemoryType aType,
|
||||
ipc::Shmem* aShmem) override;
|
||||
|
||||
virtual bool AllocUnsafeShmem(size_t aSize,
|
||||
ipc::SharedMemory::SharedMemoryType aType,
|
||||
ipc::Shmem* aShmem) override;
|
||||
|
||||
virtual void DeallocShmem(ipc::Shmem& aShmem) override;
|
||||
|
||||
virtual bool IsSameProcess() const override;
|
||||
bool HaveEventListener();
|
||||
|
||||
virtual void NotifyNotUsed(PTextureParent* aTexture, uint64_t aTransactionId) override;
|
||||
virtual void SendAsyncMessage(const InfallibleTArray<AsyncParentMessageData>& aMessage) override;
|
||||
bool SendGamepadUpdate(const GamepadChangeEvent& aGamepadEvent);
|
||||
|
||||
protected:
|
||||
~VRManagerParent();
|
||||
|
||||
virtual PTextureParent* AllocPTextureParent(const SurfaceDescriptor& aSharedData,
|
||||
const LayersBackend& aLayersBackend,
|
||||
const TextureFlags& aFlags,
|
||||
const uint64_t& aSerial) override;
|
||||
virtual bool DeallocPTextureParent(PTextureParent* actor) override;
|
||||
|
||||
virtual PVRLayerParent* AllocPVRLayerParent(const uint32_t& aDisplayID,
|
||||
const float& aLeftEyeX,
|
||||
const float& aLeftEyeY,
|
||||
const float& aLeftEyeWidth,
|
||||
const float& aLeftEyeHeight,
|
||||
const float& aRightEyeX,
|
||||
const float& aRightEyeY,
|
||||
const float& aRightEyeWidth,
|
||||
const float& aRightEyeHeight) override;
|
||||
virtual bool DeallocPVRLayerParent(PVRLayerParent* actor) override;
|
||||
|
||||
virtual void ActorDestroy(ActorDestroyReason why) override;
|
||||
void OnChannelConnected(int32_t pid) override;
|
||||
|
||||
virtual bool RecvRefreshDisplays() override;
|
||||
virtual bool RecvGetDisplays(nsTArray<VRDisplayInfo> *aDisplays) override;
|
||||
virtual bool RecvResetSensor(const uint32_t& aDisplayID) override;
|
||||
virtual bool RecvGetSensorState(const uint32_t& aDisplayID, VRHMDSensorState* aState) override;
|
||||
virtual bool RecvGetImmediateSensorState(const uint32_t& aDisplayID, VRHMDSensorState* aState) override;
|
||||
virtual bool RecvSetHaveEventListener(const bool& aHaveEventListener) override;
|
||||
virtual bool RecvControllerListenerAdded() override;
|
||||
virtual bool RecvControllerListenerRemoved() override;
|
||||
virtual bool RecvGetControllers(nsTArray<VRControllerInfo> *aControllers) override;
|
||||
|
||||
private:
|
||||
void RegisterWithManager();
|
||||
void UnregisterFromManager();
|
||||
|
||||
void Bind(Endpoint<PVRManagerParent>&& aEndpoint);
|
||||
|
||||
static void RegisterVRManagerInCompositorThread(VRManagerParent* aVRManager);
|
||||
|
||||
void DeferredDestroy();
|
||||
|
||||
// This keeps us alive until ActorDestroy(), at which point we do a
|
||||
// deferred destruction of ourselves.
|
||||
RefPtr<VRManagerParent> mSelfRef;
|
||||
|
||||
// Keep the compositor thread alive, until we have destroyed ourselves.
|
||||
RefPtr<layers::CompositorThreadHolder> mCompositorThreadHolder;
|
||||
|
||||
// Keep the VRManager alive, until we have destroyed ourselves.
|
||||
RefPtr<VRManager> mVRManagerHolder;
|
||||
bool mHaveEventListener;
|
||||
bool mIsContentChild;
|
||||
};
|
||||
|
||||
} // namespace mozilla
|
||||
} // namespace gfx
|
||||
|
||||
#endif // MOZILLA_GFX_VR_VRMANAGERPARENT_H
|
||||
@@ -1,193 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set sw=2 ts=8 et 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 mozilla_gfx_vr_VRMessageUtils_h
|
||||
#define mozilla_gfx_vr_VRMessageUtils_h
|
||||
|
||||
#include "ipc/IPCMessageUtils.h"
|
||||
#include "mozilla/GfxMessageUtils.h"
|
||||
#include "VRManager.h"
|
||||
|
||||
#include "gfxVR.h"
|
||||
|
||||
namespace IPC {
|
||||
|
||||
template<>
|
||||
struct ParamTraits<mozilla::gfx::VRDeviceType> :
|
||||
public ContiguousEnumSerializer<mozilla::gfx::VRDeviceType,
|
||||
mozilla::gfx::VRDeviceType(0),
|
||||
mozilla::gfx::VRDeviceType(mozilla::gfx::VRDeviceType::NumVRDeviceTypes)> {};
|
||||
|
||||
template<>
|
||||
struct ParamTraits<mozilla::gfx::VRDisplayCapabilityFlags> :
|
||||
public BitFlagsEnumSerializer<mozilla::gfx::VRDisplayCapabilityFlags,
|
||||
mozilla::gfx::VRDisplayCapabilityFlags::Cap_All> {};
|
||||
|
||||
template <>
|
||||
struct ParamTraits<mozilla::gfx::VRDisplayInfo>
|
||||
{
|
||||
typedef mozilla::gfx::VRDisplayInfo paramType;
|
||||
|
||||
static void Write(Message* aMsg, const paramType& aParam)
|
||||
{
|
||||
WriteParam(aMsg, aParam.mType);
|
||||
WriteParam(aMsg, aParam.mDisplayID);
|
||||
WriteParam(aMsg, aParam.mDisplayName);
|
||||
WriteParam(aMsg, aParam.mCapabilityFlags);
|
||||
WriteParam(aMsg, aParam.mEyeResolution);
|
||||
WriteParam(aMsg, aParam.mIsConnected);
|
||||
WriteParam(aMsg, aParam.mIsPresenting);
|
||||
WriteParam(aMsg, aParam.mStageSize);
|
||||
WriteParam(aMsg, aParam.mSittingToStandingTransform);
|
||||
for (int i = 0; i < mozilla::gfx::VRDisplayInfo::NumEyes; i++) {
|
||||
WriteParam(aMsg, aParam.mEyeFOV[i]);
|
||||
WriteParam(aMsg, aParam.mEyeTranslation[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
|
||||
{
|
||||
if (!ReadParam(aMsg, aIter, &(aResult->mType)) ||
|
||||
!ReadParam(aMsg, aIter, &(aResult->mDisplayID)) ||
|
||||
!ReadParam(aMsg, aIter, &(aResult->mDisplayName)) ||
|
||||
!ReadParam(aMsg, aIter, &(aResult->mCapabilityFlags)) ||
|
||||
!ReadParam(aMsg, aIter, &(aResult->mEyeResolution)) ||
|
||||
!ReadParam(aMsg, aIter, &(aResult->mIsConnected)) ||
|
||||
!ReadParam(aMsg, aIter, &(aResult->mIsPresenting)) ||
|
||||
!ReadParam(aMsg, aIter, &(aResult->mStageSize)) ||
|
||||
!ReadParam(aMsg, aIter, &(aResult->mSittingToStandingTransform))) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < mozilla::gfx::VRDisplayInfo::NumEyes; i++) {
|
||||
if (!ReadParam(aMsg, aIter, &(aResult->mEyeFOV[i])) ||
|
||||
!ReadParam(aMsg, aIter, &(aResult->mEyeTranslation[i]))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct ParamTraits<mozilla::gfx::VRHMDSensorState>
|
||||
{
|
||||
typedef mozilla::gfx::VRHMDSensorState paramType;
|
||||
|
||||
static void Write(Message* aMsg, const paramType& aParam)
|
||||
{
|
||||
WriteParam(aMsg, aParam.timestamp);
|
||||
WriteParam(aMsg, aParam.inputFrameID);
|
||||
WriteParam(aMsg, aParam.flags);
|
||||
WriteParam(aMsg, aParam.orientation[0]);
|
||||
WriteParam(aMsg, aParam.orientation[1]);
|
||||
WriteParam(aMsg, aParam.orientation[2]);
|
||||
WriteParam(aMsg, aParam.orientation[3]);
|
||||
WriteParam(aMsg, aParam.position[0]);
|
||||
WriteParam(aMsg, aParam.position[1]);
|
||||
WriteParam(aMsg, aParam.position[2]);
|
||||
WriteParam(aMsg, aParam.angularVelocity[0]);
|
||||
WriteParam(aMsg, aParam.angularVelocity[1]);
|
||||
WriteParam(aMsg, aParam.angularVelocity[2]);
|
||||
WriteParam(aMsg, aParam.angularAcceleration[0]);
|
||||
WriteParam(aMsg, aParam.angularAcceleration[1]);
|
||||
WriteParam(aMsg, aParam.angularAcceleration[2]);
|
||||
WriteParam(aMsg, aParam.linearVelocity[0]);
|
||||
WriteParam(aMsg, aParam.linearVelocity[1]);
|
||||
WriteParam(aMsg, aParam.linearVelocity[2]);
|
||||
WriteParam(aMsg, aParam.linearAcceleration[0]);
|
||||
WriteParam(aMsg, aParam.linearAcceleration[1]);
|
||||
WriteParam(aMsg, aParam.linearAcceleration[2]);
|
||||
}
|
||||
|
||||
static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
|
||||
{
|
||||
if (!ReadParam(aMsg, aIter, &(aResult->timestamp)) ||
|
||||
!ReadParam(aMsg, aIter, &(aResult->inputFrameID)) ||
|
||||
!ReadParam(aMsg, aIter, &(aResult->flags)) ||
|
||||
!ReadParam(aMsg, aIter, &(aResult->orientation[0])) ||
|
||||
!ReadParam(aMsg, aIter, &(aResult->orientation[1])) ||
|
||||
!ReadParam(aMsg, aIter, &(aResult->orientation[2])) ||
|
||||
!ReadParam(aMsg, aIter, &(aResult->orientation[3])) ||
|
||||
!ReadParam(aMsg, aIter, &(aResult->position[0])) ||
|
||||
!ReadParam(aMsg, aIter, &(aResult->position[1])) ||
|
||||
!ReadParam(aMsg, aIter, &(aResult->position[2])) ||
|
||||
!ReadParam(aMsg, aIter, &(aResult->angularVelocity[0])) ||
|
||||
!ReadParam(aMsg, aIter, &(aResult->angularVelocity[1])) ||
|
||||
!ReadParam(aMsg, aIter, &(aResult->angularVelocity[2])) ||
|
||||
!ReadParam(aMsg, aIter, &(aResult->angularAcceleration[0])) ||
|
||||
!ReadParam(aMsg, aIter, &(aResult->angularAcceleration[1])) ||
|
||||
!ReadParam(aMsg, aIter, &(aResult->angularAcceleration[2])) ||
|
||||
!ReadParam(aMsg, aIter, &(aResult->linearVelocity[0])) ||
|
||||
!ReadParam(aMsg, aIter, &(aResult->linearVelocity[1])) ||
|
||||
!ReadParam(aMsg, aIter, &(aResult->linearVelocity[2])) ||
|
||||
!ReadParam(aMsg, aIter, &(aResult->linearAcceleration[0])) ||
|
||||
!ReadParam(aMsg, aIter, &(aResult->linearAcceleration[1])) ||
|
||||
!ReadParam(aMsg, aIter, &(aResult->linearAcceleration[2]))) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct ParamTraits<mozilla::gfx::VRFieldOfView>
|
||||
{
|
||||
typedef mozilla::gfx::VRFieldOfView paramType;
|
||||
|
||||
static void Write(Message* aMsg, const paramType& aParam)
|
||||
{
|
||||
WriteParam(aMsg, aParam.upDegrees);
|
||||
WriteParam(aMsg, aParam.rightDegrees);
|
||||
WriteParam(aMsg, aParam.downDegrees);
|
||||
WriteParam(aMsg, aParam.leftDegrees);
|
||||
}
|
||||
|
||||
static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
|
||||
{
|
||||
if (!ReadParam(aMsg, aIter, &(aResult->upDegrees)) ||
|
||||
!ReadParam(aMsg, aIter, &(aResult->rightDegrees)) ||
|
||||
!ReadParam(aMsg, aIter, &(aResult->downDegrees)) ||
|
||||
!ReadParam(aMsg, aIter, &(aResult->leftDegrees))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct ParamTraits<mozilla::gfx::VRControllerInfo>
|
||||
{
|
||||
typedef mozilla::gfx::VRControllerInfo paramType;
|
||||
|
||||
static void Write(Message* aMsg, const paramType& aParam)
|
||||
{
|
||||
WriteParam(aMsg, aParam.mType);
|
||||
WriteParam(aMsg, aParam.mControllerID);
|
||||
WriteParam(aMsg, aParam.mControllerName);
|
||||
WriteParam(aMsg, aParam.mMappingType);
|
||||
WriteParam(aMsg, aParam.mNumButtons);
|
||||
WriteParam(aMsg, aParam.mNumAxes);
|
||||
}
|
||||
|
||||
static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
|
||||
{
|
||||
if (!ReadParam(aMsg, aIter, &(aResult->mType)) ||
|
||||
!ReadParam(aMsg, aIter, &(aResult->mControllerID)) ||
|
||||
!ReadParam(aMsg, aIter, &(aResult->mControllerName)) ||
|
||||
!ReadParam(aMsg, aIter, &(aResult->mMappingType)) ||
|
||||
!ReadParam(aMsg, aIter, &(aResult->mNumButtons)) ||
|
||||
!ReadParam(aMsg, aIter, &(aResult->mNumAxes))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
} // namespace IPC
|
||||
|
||||
#endif // mozilla_gfx_vr_VRMessageUtils_h
|
||||
@@ -1,71 +0,0 @@
|
||||
# -*- 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/.
|
||||
|
||||
EXPORTS += [
|
||||
'gfxVR.h',
|
||||
'ipc/VRLayerChild.h',
|
||||
'ipc/VRManagerChild.h',
|
||||
'ipc/VRManagerParent.h',
|
||||
'ipc/VRMessageUtils.h',
|
||||
'VRDisplayClient.h',
|
||||
'VRDisplayPresentation.h',
|
||||
'VRManager.h',
|
||||
]
|
||||
|
||||
LOCAL_INCLUDES += [
|
||||
'/dom/base',
|
||||
'/gfx/layers/d3d11',
|
||||
'/gfx/thebes',
|
||||
]
|
||||
|
||||
UNIFIED_SOURCES += [
|
||||
'gfxVR.cpp',
|
||||
'gfxVROpenVR.cpp',
|
||||
'gfxVROSVR.cpp',
|
||||
'ipc/VRLayerChild.cpp',
|
||||
'ipc/VRLayerParent.cpp',
|
||||
'ipc/VRManagerChild.cpp',
|
||||
'ipc/VRManagerParent.cpp',
|
||||
'VRDisplayClient.cpp',
|
||||
'VRDisplayHost.cpp',
|
||||
'VRDisplayPresentation.cpp',
|
||||
'VRManager.cpp',
|
||||
]
|
||||
|
||||
if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'windows':
|
||||
SOURCES += [
|
||||
'gfxVROculus.cpp',
|
||||
]
|
||||
|
||||
IPDL_SOURCES = [
|
||||
'ipc/PVRLayer.ipdl',
|
||||
'ipc/PVRManager.ipdl',
|
||||
]
|
||||
|
||||
# For building with the real SDK instead of our local hack
|
||||
#SOURCES += [
|
||||
# 'OVR_CAPI_Util.cpp',
|
||||
# 'OVR_CAPIShim.c',
|
||||
# 'OVR_StereoProjection.cpp',
|
||||
#]
|
||||
#
|
||||
#CXXFLAGS += ["-Ic:/proj/ovr/OculusSDK-0.6.0-beta/LibOVR/Include"]
|
||||
#CFLAGS += ["-Ic:/proj/ovr/OculusSDK-0.6.0-beta/LibOVR/Include"]
|
||||
|
||||
CXXFLAGS += CONFIG['MOZ_CAIRO_CFLAGS']
|
||||
CXXFLAGS += CONFIG['TK_CFLAGS']
|
||||
CFLAGS += CONFIG['MOZ_CAIRO_CFLAGS']
|
||||
CFLAGS += CONFIG['TK_CFLAGS']
|
||||
|
||||
include('/ipc/chromium/chromium-config.mozbuild')
|
||||
|
||||
FINAL_LIBRARY = 'xul'
|
||||
|
||||
# This is intended as a temporary hack to enable VS2015 builds.
|
||||
if CONFIG['_MSC_VER']:
|
||||
# ovr_capi_dynamic.h '<unnamed-tag>': Alignment specifier is less than
|
||||
# actual alignment (8), and will be ignored
|
||||
CXXFLAGS += ['-wd4359']
|
||||
@@ -1,27 +0,0 @@
|
||||
Copyright (c) 2015, Valve Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors
|
||||
may be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
@@ -1,2 +0,0 @@
|
||||
See https://github.com/ValveSoftware/openvr/
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,37 +0,0 @@
|
||||
/** @file
|
||||
@brief Header
|
||||
|
||||
Must be c-safe!
|
||||
|
||||
@date 2014
|
||||
|
||||
@author
|
||||
Sensics, Inc.
|
||||
<http://sensics.com/osvr>
|
||||
*/
|
||||
|
||||
/*
|
||||
// Copyright 2014 Sensics, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef INCLUDED_ClientKitC_h_GUID_8D7DF104_892D_4CB5_2302_7C6BB5BC985C
|
||||
#define INCLUDED_ClientKitC_h_GUID_8D7DF104_892D_4CB5_2302_7C6BB5BC985C
|
||||
|
||||
#include <osvr/ClientKit/ContextC.h>
|
||||
#include <osvr/ClientKit/InterfaceC.h>
|
||||
#include <osvr/ClientKit/InterfaceCallbackC.h>
|
||||
#include <osvr/ClientKit/SystemCallbackC.h>
|
||||
|
||||
#endif
|
||||
@@ -1,96 +0,0 @@
|
||||
/** @file
|
||||
@brief Header
|
||||
|
||||
Must be c-safe!
|
||||
|
||||
@todo Apply annotation macros
|
||||
|
||||
@date 2014
|
||||
|
||||
@author
|
||||
Sensics, Inc.
|
||||
<http://sensics.com/osvr>
|
||||
*/
|
||||
|
||||
/*
|
||||
// Copyright 2014 Sensics, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef INCLUDED_ContextC_h_GUID_3790F330_2425_4486_4C9F_20C300D7DED3
|
||||
#define INCLUDED_ContextC_h_GUID_3790F330_2425_4486_4C9F_20C300D7DED3
|
||||
|
||||
/* Internal Includes */
|
||||
#include <osvr/ClientKit/Export.h>
|
||||
#include <osvr/Util/APIBaseC.h>
|
||||
#include <osvr/Util/ReturnCodesC.h>
|
||||
#include <osvr/Util/AnnotationMacrosC.h>
|
||||
#include <osvr/Util/StdInt.h>
|
||||
#include <osvr/Util/ClientOpaqueTypesC.h>
|
||||
|
||||
/* Library/third-party includes */
|
||||
/* none */
|
||||
|
||||
/* Standard includes */
|
||||
/* none */
|
||||
|
||||
OSVR_EXTERN_C_BEGIN
|
||||
|
||||
/** @addtogroup ClientKit
|
||||
@{
|
||||
*/
|
||||
|
||||
/** @brief Initialize the library.
|
||||
|
||||
@param applicationIdentifier A null terminated string identifying your
|
||||
application. Reverse DNS format strongly suggested.
|
||||
@param flags initialization options (reserved) - pass 0 for now.
|
||||
|
||||
@returns Client context - will be needed for subsequent calls
|
||||
*/
|
||||
OSVR_CLIENTKIT_EXPORT OSVR_ClientContext osvrClientInit(
|
||||
const char applicationIdentifier[], uint32_t flags OSVR_CPP_ONLY(= 0));
|
||||
|
||||
/** @brief Updates the state of the context - call regularly in your mainloop.
|
||||
|
||||
@param ctx Client context
|
||||
*/
|
||||
OSVR_CLIENTKIT_EXPORT OSVR_ReturnCode osvrClientUpdate(OSVR_ClientContext ctx);
|
||||
|
||||
/** @brief Checks to see if the client context is fully started up and connected
|
||||
properly to a server.
|
||||
|
||||
If this reports that the client context is not OK, there may not be a server
|
||||
running, or you may just have to call osvrClientUpdate() a few times to
|
||||
permit startup to finish. The return value of this call will not change from
|
||||
failure to success without calling osvrClientUpdate().
|
||||
|
||||
@param ctx Client context
|
||||
|
||||
@return OSVR_RETURN_FAILURE if not yet fully connected/initialized, or if
|
||||
some other error (null context) occurs.
|
||||
*/
|
||||
OSVR_CLIENTKIT_EXPORT OSVR_ReturnCode
|
||||
osvrClientCheckStatus(OSVR_ClientContext ctx);
|
||||
|
||||
/** @brief Shutdown the library.
|
||||
@param ctx Client context
|
||||
*/
|
||||
OSVR_CLIENTKIT_EXPORT OSVR_ReturnCode
|
||||
osvrClientShutdown(OSVR_ClientContext ctx);
|
||||
|
||||
/** @} */
|
||||
OSVR_EXTERN_C_END
|
||||
|
||||
#endif
|
||||
@@ -1,506 +0,0 @@
|
||||
/** @file
|
||||
@brief Header
|
||||
|
||||
Must be c-safe!
|
||||
|
||||
@date 2015
|
||||
|
||||
@author
|
||||
Sensics, Inc.
|
||||
<http://sensics.com/osvr>
|
||||
*/
|
||||
|
||||
/*
|
||||
// Copyright 2015 Sensics, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef INCLUDED_DisplayC_h_GUID_8658EDC9_32A2_49A2_5F5C_10F67852AE74
|
||||
#define INCLUDED_DisplayC_h_GUID_8658EDC9_32A2_49A2_5F5C_10F67852AE74
|
||||
|
||||
/* Internal Includes */
|
||||
#include <osvr/ClientKit/Export.h>
|
||||
#include <osvr/Util/APIBaseC.h>
|
||||
#include <osvr/Util/ReturnCodesC.h>
|
||||
#include <osvr/Util/ClientOpaqueTypesC.h>
|
||||
#include <osvr/Util/RenderingTypesC.h>
|
||||
#include <osvr/Util/MatrixConventionsC.h>
|
||||
#include <osvr/Util/Pose3C.h>
|
||||
#include <osvr/Util/BoolC.h>
|
||||
#include <osvr/Util/RadialDistortionParametersC.h>
|
||||
|
||||
/* Library/third-party includes */
|
||||
/* none */
|
||||
|
||||
/* Standard includes */
|
||||
/* none */
|
||||
|
||||
OSVR_EXTERN_C_BEGIN
|
||||
/** @addtogroup ClientKit
|
||||
@{
|
||||
@name Display API
|
||||
@{
|
||||
*/
|
||||
|
||||
/** @brief Opaque type of a display configuration. */
|
||||
typedef struct OSVR_DisplayConfigObject *OSVR_DisplayConfig;
|
||||
|
||||
/** @brief Allocates a display configuration object populated with data from the
|
||||
OSVR system.
|
||||
|
||||
Before this call will succeed, your application will need to be correctly
|
||||
and fully connected to an OSVR server. You may consider putting this call in
|
||||
a loop alternating with osvrClientUpdate() until this call succeeds.
|
||||
|
||||
Data provided by a display configuration object:
|
||||
|
||||
- The logical display topology (number and relationship of viewers, eyes,
|
||||
and surfaces), which remains constant throughout the life of the
|
||||
configuration object. (A method of notification of change here is TBD).
|
||||
- Pose data for viewers (not required for rendering) and pose/view data for
|
||||
eyes (used for rendering) which is based on tracker data: if used, these
|
||||
should be queried every frame.
|
||||
- Projection matrix data for surfaces, which while in current practice may
|
||||
be relatively unchanging, we are not guaranteeing them to be constant:
|
||||
these should be queried every frame.
|
||||
- Video-input-relative viewport size/location for a surface: would like this
|
||||
to be variable, but probably not feasible. If you have input, please
|
||||
comment on the dev mailing list.
|
||||
- Per-surface distortion strategy priorities/availabilities: constant. Note
|
||||
the following, though...
|
||||
- Per-surface distortion strategy parameters: variable, request each frame.
|
||||
(Could make constant with a notification if needed?)
|
||||
|
||||
Important note: While most of this data is immediately available if you are
|
||||
successful in getting a display config object, the pose-based data (viewer
|
||||
pose, eye pose, eye view matrix) needs tracker state, so at least one (and in
|
||||
practice, typically more) osvrClientUpdate() must be performed before a new
|
||||
tracker report is available to populate that state. See
|
||||
osvrClientCheckDisplayStartup() to query if all startup data is available.
|
||||
|
||||
@todo Decide if relative viewport should be constant in a display config,
|
||||
and update docs accordingly.
|
||||
|
||||
@todo Decide if distortion params should be constant in a display config,
|
||||
and update docs accordingly.
|
||||
|
||||
@return OSVR_RETURN_FAILURE if invalid parameters were passed or some other
|
||||
error occurred, in which case the output argument is unmodified.
|
||||
*/
|
||||
OSVR_CLIENTKIT_EXPORT OSVR_ReturnCode
|
||||
osvrClientGetDisplay(OSVR_ClientContext ctx, OSVR_DisplayConfig *disp);
|
||||
|
||||
/** @brief Frees a display configuration object. The corresponding context must
|
||||
still be open.
|
||||
|
||||
If you fail to call this, it will be automatically called as part of
|
||||
clean-up when the corresponding context is closed.
|
||||
|
||||
@return OSVR_RETURN_FAILURE if a null config was passed, or if the given
|
||||
display object was already freed.
|
||||
*/
|
||||
OSVR_CLIENTKIT_EXPORT OSVR_ReturnCode
|
||||
osvrClientFreeDisplay(OSVR_DisplayConfig disp);
|
||||
|
||||
/** @brief Checks to see if a display is fully configured and ready, including
|
||||
having received its first pose update.
|
||||
|
||||
Once this first succeeds, it will continue to succeed for the lifetime of
|
||||
the display config object, so it is not necessary to keep calling once you
|
||||
get a successful result.
|
||||
|
||||
@return OSVR_RETURN_FAILURE if a null config was passed, or if the given
|
||||
display config object was otherwise not ready for full use.
|
||||
*/
|
||||
OSVR_CLIENTKIT_EXPORT OSVR_ReturnCode
|
||||
osvrClientCheckDisplayStartup(OSVR_DisplayConfig disp);
|
||||
|
||||
/** @brief A display config can have one or more display inputs to pass pixels
|
||||
over (HDMI/DVI connections, etc): retrieve the number of display inputs in
|
||||
the current configuration.
|
||||
|
||||
@param disp Display config object.
|
||||
@param[out] numDisplayInputs Number of display inputs in the logical display
|
||||
topology, **constant** throughout the active, valid lifetime of a display
|
||||
config object.
|
||||
|
||||
@sa OSVR_DisplayInputCount
|
||||
|
||||
@return OSVR_RETURN_FAILURE if invalid parameters were passed, in
|
||||
which case the output argument is unmodified.
|
||||
*/
|
||||
OSVR_CLIENTKIT_EXPORT OSVR_ReturnCode osvrClientGetNumDisplayInputs(
|
||||
OSVR_DisplayConfig disp, OSVR_DisplayInputCount *numDisplayInputs);
|
||||
|
||||
/** @brief Retrieve the pixel dimensions of a given display input for a display
|
||||
config
|
||||
|
||||
@param disp Display config object.
|
||||
@param displayInputIndex The zero-based index of the display input.
|
||||
@param[out] width Width (in pixels) of the display input.
|
||||
@param[out] height Height (in pixels) of the display input.
|
||||
|
||||
The out parameters are **constant** throughout the active, valid lifetime of
|
||||
a display config object.
|
||||
|
||||
@sa OSVR_DisplayDimension
|
||||
|
||||
@return OSVR_RETURN_FAILURE if invalid parameters were passed, in
|
||||
which case the output arguments are unmodified.
|
||||
*/
|
||||
OSVR_CLIENTKIT_EXPORT OSVR_ReturnCode osvrClientGetDisplayDimensions(
|
||||
OSVR_DisplayConfig disp, OSVR_DisplayInputCount displayInputIndex,
|
||||
OSVR_DisplayDimension *width, OSVR_DisplayDimension *height);
|
||||
|
||||
/** @brief A display config can have one (or theoretically more) viewers:
|
||||
retrieve the viewer count.
|
||||
|
||||
@param disp Display config object.
|
||||
@param[out] viewers Number of viewers in the logical display topology,
|
||||
**constant** throughout the active, valid lifetime of a display config
|
||||
object.
|
||||
|
||||
@sa OSVR_ViewerCount
|
||||
|
||||
@return OSVR_RETURN_FAILURE if invalid parameters were passed, in which case
|
||||
the output argument is unmodified.
|
||||
*/
|
||||
OSVR_CLIENTKIT_EXPORT OSVR_ReturnCode
|
||||
osvrClientGetNumViewers(OSVR_DisplayConfig disp, OSVR_ViewerCount *viewers);
|
||||
|
||||
/** @brief Get the pose of a viewer in a display config.
|
||||
|
||||
Note that there may not necessarily be any surfaces rendered from this pose
|
||||
(it's the unused "center" eye in a stereo configuration, for instance) so
|
||||
only use this if it makes integration into your engine or existing
|
||||
applications (not originally designed for stereo) easier.
|
||||
|
||||
Will only succeed if osvrClientCheckDisplayStartup() succeeds.
|
||||
|
||||
@return OSVR_RETURN_FAILURE if invalid parameters were passed or no pose was
|
||||
yet available, in which case the pose argument is unmodified.
|
||||
*/
|
||||
OSVR_CLIENTKIT_EXPORT OSVR_ReturnCode osvrClientGetViewerPose(
|
||||
OSVR_DisplayConfig disp, OSVR_ViewerCount viewer, OSVR_Pose3 *pose);
|
||||
|
||||
/** @brief Each viewer in a display config can have one or more "eyes" which
|
||||
have a substantially similar pose: get the count.
|
||||
|
||||
@param disp Display config object.
|
||||
@param viewer Viewer ID
|
||||
@param[out] eyes Number of eyes for this viewer in the logical display
|
||||
topology, **constant** throughout the active, valid lifetime of a display
|
||||
config object
|
||||
|
||||
@sa OSVR_EyeCount
|
||||
|
||||
@return OSVR_RETURN_FAILURE if invalid parameters were passed, in which case
|
||||
the output argument is unmodified.
|
||||
*/
|
||||
OSVR_CLIENTKIT_EXPORT OSVR_ReturnCode osvrClientGetNumEyesForViewer(
|
||||
OSVR_DisplayConfig disp, OSVR_ViewerCount viewer, OSVR_EyeCount *eyes);
|
||||
|
||||
/** @brief Get the "viewpoint" for the given eye of a viewer in a display
|
||||
config.
|
||||
|
||||
Will only succeed if osvrClientCheckDisplayStartup() succeeds.
|
||||
|
||||
@param disp Display config object
|
||||
@param viewer Viewer ID
|
||||
@param eye Eye ID
|
||||
@param[out] pose Room-space pose (not relative to pose of the viewer)
|
||||
|
||||
@return OSVR_RETURN_FAILURE if invalid parameters were passed or no pose was
|
||||
yet available, in which case the pose argument is unmodified.
|
||||
*/
|
||||
OSVR_CLIENTKIT_EXPORT OSVR_ReturnCode
|
||||
osvrClientGetViewerEyePose(OSVR_DisplayConfig disp, OSVR_ViewerCount viewer,
|
||||
OSVR_EyeCount eye, OSVR_Pose3 *pose);
|
||||
|
||||
/** @brief Get the view matrix (inverse of pose) for the given eye of a
|
||||
viewer in a display config - matrix of **doubles**.
|
||||
|
||||
Will only succeed if osvrClientCheckDisplayStartup() succeeds.
|
||||
|
||||
@param disp Display config object
|
||||
@param viewer Viewer ID
|
||||
@param eye Eye ID
|
||||
@param flags Bitwise OR of matrix convention flags (see @ref MatrixFlags)
|
||||
@param[out] mat Pass a double[::OSVR_MATRIX_SIZE] to get the transformation
|
||||
matrix from room space to eye space (not relative to pose of the viewer)
|
||||
|
||||
@return OSVR_RETURN_FAILURE if invalid parameters were passed or no pose was
|
||||
yet available, in which case the output argument is unmodified.
|
||||
*/
|
||||
OSVR_CLIENTKIT_EXPORT OSVR_ReturnCode osvrClientGetViewerEyeViewMatrixd(
|
||||
OSVR_DisplayConfig disp, OSVR_ViewerCount viewer, OSVR_EyeCount eye,
|
||||
OSVR_MatrixConventions flags, double *mat);
|
||||
|
||||
/** @brief Get the view matrix (inverse of pose) for the given eye of a
|
||||
viewer in a display config - matrix of **floats**.
|
||||
|
||||
Will only succeed if osvrClientCheckDisplayStartup() succeeds.
|
||||
|
||||
@param disp Display config object
|
||||
@param viewer Viewer ID
|
||||
@param eye Eye ID
|
||||
@param flags Bitwise OR of matrix convention flags (see @ref MatrixFlags)
|
||||
@param[out] mat Pass a float[::OSVR_MATRIX_SIZE] to get the transformation
|
||||
matrix from room space to eye space (not relative to pose of the viewer)
|
||||
|
||||
@return OSVR_RETURN_FAILURE if invalid parameters were passed or no pose was
|
||||
yet available, in which case the output argument is unmodified.
|
||||
*/
|
||||
OSVR_CLIENTKIT_EXPORT OSVR_ReturnCode osvrClientGetViewerEyeViewMatrixf(
|
||||
OSVR_DisplayConfig disp, OSVR_ViewerCount viewer, OSVR_EyeCount eye,
|
||||
OSVR_MatrixConventions flags, float *mat);
|
||||
|
||||
/** @brief Each eye of each viewer in a display config has one or more surfaces
|
||||
(aka "screens") on which content should be rendered.
|
||||
|
||||
@param disp Display config object
|
||||
@param viewer Viewer ID
|
||||
@param eye Eye ID
|
||||
@param[out] surfaces Number of surfaces (numbered [0, surfaces - 1]) for the
|
||||
given viewer and eye. **Constant** throughout the active, valid lifetime of
|
||||
a display config object.
|
||||
|
||||
@sa OSVR_SurfaceCount
|
||||
|
||||
@return OSVR_RETURN_FAILURE if invalid parameters were passed, in which case
|
||||
the output argument is unmodified.
|
||||
*/
|
||||
OSVR_CLIENTKIT_EXPORT OSVR_ReturnCode osvrClientGetNumSurfacesForViewerEye(
|
||||
OSVR_DisplayConfig disp, OSVR_ViewerCount viewer, OSVR_EyeCount eye,
|
||||
OSVR_SurfaceCount *surfaces);
|
||||
|
||||
/** @brief Get the dimensions/location of the viewport **within the display
|
||||
input** for a surface seen by an eye of a viewer in a display config. (This
|
||||
does not include other video inputs that may be on a single virtual desktop,
|
||||
etc. or explicitly account for display configurations that use multiple
|
||||
video inputs. It does not necessarily indicate that a viewport in the sense
|
||||
of glViewport must be created with these parameters, though the parameter
|
||||
order matches for convenience.)
|
||||
|
||||
@param disp Display config object
|
||||
@param viewer Viewer ID
|
||||
@param eye Eye ID
|
||||
@param surface Surface ID
|
||||
@param[out] left Output: Distance in pixels from the left of the video input
|
||||
to the left of the viewport.
|
||||
@param[out] bottom Output: Distance in pixels from the bottom of the video
|
||||
input to the bottom of the viewport.
|
||||
@param[out] width Output: Width of viewport in pixels.
|
||||
@param[out] height Output: Height of viewport in pixels.
|
||||
|
||||
|
||||
@return OSVR_RETURN_FAILURE if invalid parameters were passed, in which case
|
||||
the output arguments are unmodified.
|
||||
*/
|
||||
OSVR_CLIENTKIT_EXPORT OSVR_ReturnCode
|
||||
osvrClientGetRelativeViewportForViewerEyeSurface(
|
||||
OSVR_DisplayConfig disp, OSVR_ViewerCount viewer, OSVR_EyeCount eye,
|
||||
OSVR_SurfaceCount surface, OSVR_ViewportDimension *left,
|
||||
OSVR_ViewportDimension *bottom, OSVR_ViewportDimension *width,
|
||||
OSVR_ViewportDimension *height);
|
||||
|
||||
/** @brief Get the index of the display input for a surface seen by an eye of a
|
||||
viewer in a display config.
|
||||
|
||||
This is the OSVR-assigned display input: it may not (and in practice,
|
||||
usually will not) match any platform-specific display indices. This function
|
||||
exists to associate surfaces with video inputs as enumerated by
|
||||
osvrClientGetNumDisplayInputs().
|
||||
|
||||
@param disp Display config object
|
||||
@param viewer Viewer ID
|
||||
@param eye Eye ID
|
||||
@param surface Surface ID
|
||||
@param[out] displayInput Zero-based index of the display input pixels for
|
||||
this surface are tranmitted over.
|
||||
|
||||
This association is **constant** throughout the active, valid lifetime of a
|
||||
display config object.
|
||||
|
||||
@sa osvrClientGetNumDisplayInputs(),
|
||||
osvrClientGetRelativeViewportForViewerEyeSurface()
|
||||
|
||||
@return OSVR_RETURN_FAILURE if invalid parameters were passed, in which
|
||||
case the output argument is unmodified.
|
||||
*/
|
||||
OSVR_CLIENTKIT_EXPORT OSVR_ReturnCode
|
||||
osvrClientGetViewerEyeSurfaceDisplayInputIndex(
|
||||
OSVR_DisplayConfig disp, OSVR_ViewerCount viewer, OSVR_EyeCount eye,
|
||||
OSVR_SurfaceCount surface, OSVR_DisplayInputCount *displayInput);
|
||||
|
||||
/** @brief Get the projection matrix for a surface seen by an eye of a viewer
|
||||
in a display config. (double version)
|
||||
|
||||
@param disp Display config object
|
||||
@param viewer Viewer ID
|
||||
@param eye Eye ID
|
||||
@param surface Surface ID
|
||||
@param near Distance from viewpoint to near clipping plane - must be
|
||||
positive.
|
||||
@param far Distance from viewpoint to far clipping plane - must be positive
|
||||
and not equal to near, typically greater than near.
|
||||
@param flags Bitwise OR of matrix convention flags (see @ref MatrixFlags)
|
||||
@param[out] matrix Output projection matrix: supply an array of 16
|
||||
(::OSVR_MATRIX_SIZE) doubles.
|
||||
|
||||
@return OSVR_RETURN_FAILURE if invalid parameters were passed, in which case
|
||||
the output argument is unmodified.
|
||||
*/
|
||||
OSVR_CLIENTKIT_EXPORT OSVR_ReturnCode
|
||||
osvrClientGetViewerEyeSurfaceProjectionMatrixd(
|
||||
OSVR_DisplayConfig disp, OSVR_ViewerCount viewer, OSVR_EyeCount eye,
|
||||
OSVR_SurfaceCount surface, double near, double far,
|
||||
OSVR_MatrixConventions flags, double *matrix);
|
||||
|
||||
/** @brief Get the projection matrix for a surface seen by an eye of a viewer
|
||||
in a display config. (float version)
|
||||
|
||||
@param disp Display config object
|
||||
@param viewer Viewer ID
|
||||
@param eye Eye ID
|
||||
@param surface Surface ID
|
||||
@param near Distance to near clipping plane - must be nonzero, typically
|
||||
positive.
|
||||
@param far Distance to far clipping plane - must be nonzero, typically
|
||||
positive and greater than near.
|
||||
@param flags Bitwise OR of matrix convention flags (see @ref MatrixFlags)
|
||||
@param[out] matrix Output projection matrix: supply an array of 16
|
||||
(::OSVR_MATRIX_SIZE) floats.
|
||||
|
||||
@return OSVR_RETURN_FAILURE if invalid parameters were passed, in which case
|
||||
the output argument is unmodified.
|
||||
*/
|
||||
OSVR_CLIENTKIT_EXPORT OSVR_ReturnCode
|
||||
osvrClientGetViewerEyeSurfaceProjectionMatrixf(
|
||||
OSVR_DisplayConfig disp, OSVR_ViewerCount viewer, OSVR_EyeCount eye,
|
||||
OSVR_SurfaceCount surface, float near, float far,
|
||||
OSVR_MatrixConventions flags, float *matrix);
|
||||
|
||||
/** @brief Get the clipping planes (positions at unit distance) for a surface
|
||||
seen by an eye of a viewer
|
||||
in a display config.
|
||||
|
||||
This is only for use in integrations that cannot accept a fully-formulated
|
||||
projection matrix as returned by
|
||||
osvrClientGetViewerEyeSurfaceProjectionMatrixf() or
|
||||
osvrClientGetViewerEyeSurfaceProjectionMatrixd(), and may not necessarily
|
||||
provide the same optimizations.
|
||||
|
||||
As all the planes are given at unit (1) distance, before passing these
|
||||
planes to a consuming function in your application/engine, you will typically
|
||||
divide them by your near clipping plane distance.
|
||||
|
||||
@param disp Display config object
|
||||
@param viewer Viewer ID
|
||||
@param eye Eye ID
|
||||
@param surface Surface ID
|
||||
@param[out] left Distance to left clipping plane
|
||||
@param[out] right Distance to right clipping plane
|
||||
@param[out] bottom Distance to bottom clipping plane
|
||||
@param[out] top Distance to top clipping plane
|
||||
|
||||
@return OSVR_RETURN_FAILURE if invalid parameters were passed, in which case
|
||||
the output arguments are unmodified.
|
||||
*/
|
||||
OSVR_CLIENTKIT_EXPORT OSVR_ReturnCode
|
||||
osvrClientGetViewerEyeSurfaceProjectionClippingPlanes(
|
||||
OSVR_DisplayConfig disp, OSVR_ViewerCount viewer, OSVR_EyeCount eye,
|
||||
OSVR_SurfaceCount surface, double *left, double *right, double *bottom,
|
||||
double *top);
|
||||
|
||||
/** @brief Determines if a surface seen by an eye of a viewer in a display
|
||||
config requests some distortion to be performed.
|
||||
|
||||
This simply reports true or false, and does not specify which kind of
|
||||
distortion implementations have been parameterized for this display. For
|
||||
each distortion implementation your application supports, you'll want to
|
||||
call the corresponding priority function to find out if it is available.
|
||||
|
||||
@param disp Display config object
|
||||
@param viewer Viewer ID
|
||||
@param eye Eye ID
|
||||
@param surface Surface ID
|
||||
@param[out] distortionRequested Output parameter: whether distortion is
|
||||
requested. **Constant** throughout the active, valid lifetime of a display
|
||||
config object.
|
||||
|
||||
@return OSVR_RETURN_FAILURE if invalid parameters were passed, in which case
|
||||
the output argument is unmodified.
|
||||
*/
|
||||
OSVR_CLIENTKIT_EXPORT OSVR_ReturnCode
|
||||
osvrClientDoesViewerEyeSurfaceWantDistortion(OSVR_DisplayConfig disp,
|
||||
OSVR_ViewerCount viewer,
|
||||
OSVR_EyeCount eye,
|
||||
OSVR_SurfaceCount surface,
|
||||
OSVR_CBool *distortionRequested);
|
||||
|
||||
/** @brief Returns the priority/availability of radial distortion parameters for
|
||||
a surface seen by an eye of a viewer in a display config.
|
||||
|
||||
If osvrClientDoesViewerEyeSurfaceWantDistortion() reports false, then the
|
||||
display does not request distortion of any sort, and thus neither this nor
|
||||
any other distortion strategy priority function will report an "available"
|
||||
priority.
|
||||
|
||||
@param disp Display config object
|
||||
@param viewer Viewer ID
|
||||
@param eye Eye ID
|
||||
@param surface Surface ID
|
||||
@param[out] priority Output: the priority level. Negative values
|
||||
(canonically OSVR_DISTORTION_PRIORITY_UNAVAILABLE) indicate this technique
|
||||
not available, higher values indicate higher preference for the given
|
||||
technique based on the device's description. **Constant** throughout the
|
||||
active, valid lifetime of a display config object.
|
||||
|
||||
@return OSVR_RETURN_FAILURE if invalid parameters were passed, in which case
|
||||
the output argument is unmodified.
|
||||
*/
|
||||
OSVR_CLIENTKIT_EXPORT OSVR_ReturnCode
|
||||
osvrClientGetViewerEyeSurfaceRadialDistortionPriority(
|
||||
OSVR_DisplayConfig disp, OSVR_ViewerCount viewer, OSVR_EyeCount eye,
|
||||
OSVR_SurfaceCount surface, OSVR_DistortionPriority *priority);
|
||||
|
||||
/** @brief Returns the radial distortion parameters, if known/requested, for a
|
||||
surface seen by an eye of a viewer in a display config.
|
||||
|
||||
Will only succeed if osvrClientGetViewerEyeSurfaceRadialDistortionPriority()
|
||||
reports a non-negative priority.
|
||||
|
||||
@param disp Display config object
|
||||
@param viewer Viewer ID
|
||||
@param eye Eye ID
|
||||
@param surface Surface ID
|
||||
@param[out] params Output: the parameters for radial distortion
|
||||
|
||||
@return OSVR_RETURN_FAILURE if this surface does not have these parameters
|
||||
described, or if invalid parameters were passed, in which case the output
|
||||
argument is unmodified.
|
||||
*/
|
||||
OSVR_CLIENTKIT_EXPORT OSVR_ReturnCode
|
||||
osvrClientGetViewerEyeSurfaceRadialDistortion(
|
||||
OSVR_DisplayConfig disp, OSVR_ViewerCount viewer, OSVR_EyeCount eye,
|
||||
OSVR_SurfaceCount surface, OSVR_RadialDistortionParameters *params);
|
||||
|
||||
/** @}
|
||||
@}
|
||||
*/
|
||||
|
||||
OSVR_EXTERN_C_END
|
||||
|
||||
#endif
|
||||
@@ -1,138 +0,0 @@
|
||||
/** @file
|
||||
@brief Automatically-generated export header - do not edit!
|
||||
|
||||
@date 2016
|
||||
|
||||
@author
|
||||
Sensics, Inc.
|
||||
<http://sensics.com/osvr>
|
||||
*/
|
||||
|
||||
// Copyright 2016 Sensics, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef OSVR_CLIENTKIT_EXPORT_H
|
||||
#define OSVR_CLIENTKIT_EXPORT_H
|
||||
|
||||
#ifdef OSVR_CLIENTKIT_STATIC_DEFINE
|
||||
# define OSVR_CLIENTKIT_EXPORT
|
||||
# define OSVR_CLIENTKIT_NO_EXPORT
|
||||
#endif
|
||||
|
||||
/* Per-compiler advance preventative definition */
|
||||
#if defined(__BORLANDC__) || defined(__CODEGEARC__) || defined(__HP_aCC) || \
|
||||
defined(__PGI) || defined(__WATCOMC__)
|
||||
/* Compilers that don't support deprecated, according to CMake. */
|
||||
# ifndef OSVR_CLIENTKIT_DEPRECATED
|
||||
# define OSVR_CLIENTKIT_DEPRECATED
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Check for attribute support */
|
||||
#if defined(__INTEL_COMPILER)
|
||||
/* Checking before GNUC because Intel implements GNU extensions,
|
||||
* so it chooses to define __GNUC__ as well. */
|
||||
# if __INTEL_COMPILER >= 1200
|
||||
/* Intel compiler 12.0 or newer can handle these attributes per CMake */
|
||||
# define OSVR_CLIENTKIT_EXPORT_HEADER_SUPPORTS_ATTRIBUTES
|
||||
# endif
|
||||
|
||||
#elif defined(__GNUC__)
|
||||
# if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
|
||||
/* GCC 4.2+ */
|
||||
# define OSVR_CLIENTKIT_EXPORT_HEADER_SUPPORTS_ATTRIBUTES
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Per-platform defines */
|
||||
#if defined(_MSC_VER)
|
||||
/* MSVC on Windows */
|
||||
|
||||
#ifndef OSVR_CLIENTKIT_EXPORT
|
||||
# ifdef osvrClientKit_EXPORTS
|
||||
/* We are building this library */
|
||||
# define OSVR_CLIENTKIT_EXPORT __declspec(dllexport)
|
||||
# else
|
||||
/* We are using this library */
|
||||
# define OSVR_CLIENTKIT_EXPORT __declspec(dllimport)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef OSVR_CLIENTKIT_DEPRECATED
|
||||
# define OSVR_CLIENTKIT_DEPRECATED __declspec(deprecated)
|
||||
#endif
|
||||
|
||||
#elif defined(_WIN32) && defined(__GNUC__)
|
||||
/* GCC-compatible on Windows */
|
||||
|
||||
#ifndef OSVR_CLIENTKIT_EXPORT
|
||||
# ifdef osvrClientKit_EXPORTS
|
||||
/* We are building this library */
|
||||
# define OSVR_CLIENTKIT_EXPORT __attribute__((dllexport))
|
||||
# else
|
||||
/* We are using this library */
|
||||
# define OSVR_CLIENTKIT_EXPORT __attribute__((dllimport))
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef OSVR_CLIENTKIT_DEPRECATED
|
||||
# define OSVR_CLIENTKIT_DEPRECATED __attribute__((__deprecated__))
|
||||
#endif
|
||||
|
||||
#elif defined(OSVR_CLIENTKIT_EXPORT_HEADER_SUPPORTS_ATTRIBUTES) || \
|
||||
(defined(__APPLE__) && defined(__MACH__))
|
||||
/* GCC4.2+ compatible (assuming something *nix-like) and Mac OS X */
|
||||
/* (The first macro is defined at the top of the file, if applicable) */
|
||||
/* see https://gcc.gnu.org/wiki/Visibility */
|
||||
|
||||
#ifndef OSVR_CLIENTKIT_EXPORT
|
||||
/* We are building/using this library */
|
||||
# define OSVR_CLIENTKIT_EXPORT __attribute__((visibility("default")))
|
||||
#endif
|
||||
|
||||
#ifndef OSVR_CLIENTKIT_NO_EXPORT
|
||||
# define OSVR_CLIENTKIT_NO_EXPORT __attribute__((visibility("hidden")))
|
||||
#endif
|
||||
|
||||
#ifndef OSVR_CLIENTKIT_DEPRECATED
|
||||
# define OSVR_CLIENTKIT_DEPRECATED __attribute__((__deprecated__))
|
||||
#endif
|
||||
|
||||
#endif
|
||||
/* End of platform ifdefs */
|
||||
|
||||
/* fallback def */
|
||||
#ifndef OSVR_CLIENTKIT_EXPORT
|
||||
# define OSVR_CLIENTKIT_EXPORT
|
||||
#endif
|
||||
|
||||
/* fallback def */
|
||||
#ifndef OSVR_CLIENTKIT_NO_EXPORT
|
||||
# define OSVR_CLIENTKIT_NO_EXPORT
|
||||
#endif
|
||||
|
||||
/* fallback def */
|
||||
#ifndef OSVR_CLIENTKIT_DEPRECATED_EXPORT
|
||||
# define OSVR_CLIENTKIT_DEPRECATED_EXPORT OSVR_CLIENTKIT_EXPORT OSVR_CLIENTKIT_DEPRECATED
|
||||
#endif
|
||||
|
||||
/* fallback def */
|
||||
#ifndef OSVR_CLIENTKIT_DEPRECATED_NO_EXPORT
|
||||
# define OSVR_CLIENTKIT_DEPRECATED_NO_EXPORT OSVR_CLIENTKIT_NO_EXPORT OSVR_CLIENTKIT_DEPRECATED
|
||||
#endif
|
||||
|
||||
/* Clean up after ourselves */
|
||||
#undef OSVR_CLIENTKIT_EXPORT_HEADER_SUPPORTS_ATTRIBUTES
|
||||
|
||||
#endif
|
||||
@@ -1,75 +0,0 @@
|
||||
/** @file
|
||||
@brief Header
|
||||
|
||||
Must be c-safe!
|
||||
|
||||
@date 2014
|
||||
|
||||
@author
|
||||
Sensics, Inc.
|
||||
<http://sensics.com/osvr>
|
||||
*/
|
||||
|
||||
/*
|
||||
// Copyright 2014 Sensics, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef INCLUDED_InterfaceC_h_GUID_D90BBAA6_AD62_499D_C023_2F6ED8987C17
|
||||
#define INCLUDED_InterfaceC_h_GUID_D90BBAA6_AD62_499D_C023_2F6ED8987C17
|
||||
|
||||
/* Internal Includes */
|
||||
#include <osvr/ClientKit/Export.h>
|
||||
#include <osvr/Util/APIBaseC.h>
|
||||
#include <osvr/Util/ReturnCodesC.h>
|
||||
#include <osvr/Util/AnnotationMacrosC.h>
|
||||
#include <osvr/Util/ClientOpaqueTypesC.h>
|
||||
|
||||
/* Library/third-party includes */
|
||||
/* none */
|
||||
|
||||
/* Standard includes */
|
||||
/* none */
|
||||
|
||||
OSVR_EXTERN_C_BEGIN
|
||||
/** @addtogroup ClientKit
|
||||
@{
|
||||
*/
|
||||
|
||||
/** @brief Get the interface associated with the given path.
|
||||
@param ctx Client context
|
||||
@param path A resource path (null-terminated string)
|
||||
@param[out] iface The interface object. May be freed when no longer needed,
|
||||
otherwise it will be freed when the context is closed.
|
||||
*/
|
||||
OSVR_CLIENTKIT_EXPORT OSVR_ReturnCode
|
||||
osvrClientGetInterface(OSVR_ClientContext ctx, const char path[],
|
||||
OSVR_ClientInterface *iface);
|
||||
|
||||
/** @brief Free an interface object before context closure.
|
||||
|
||||
@param ctx Client context
|
||||
@param iface The interface object
|
||||
|
||||
@returns OSVR_RETURN_SUCCESS unless a null context or interface was passed
|
||||
or the given interface was not found in the context (i.e. had already been
|
||||
freed)
|
||||
*/
|
||||
OSVR_CLIENTKIT_EXPORT OSVR_ReturnCode
|
||||
osvrClientFreeInterface(OSVR_ClientContext ctx, OSVR_ClientInterface iface);
|
||||
|
||||
/** @} */
|
||||
OSVR_EXTERN_C_END
|
||||
|
||||
#endif
|
||||
@@ -1,77 +0,0 @@
|
||||
/** @file
|
||||
@brief Header
|
||||
|
||||
Must be c-safe!
|
||||
|
||||
@date 2014
|
||||
|
||||
@author
|
||||
Sensics, Inc.
|
||||
<http://sensics.com/osvr>
|
||||
*/
|
||||
|
||||
/*
|
||||
// Copyright 2014 Sensics, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef INCLUDED_InterfaceCallbacksC_h_GUID_8F16E6CB_F998_4ABC_5B6B_4FC1E4B71BC9
|
||||
#define INCLUDED_InterfaceCallbacksC_h_GUID_8F16E6CB_F998_4ABC_5B6B_4FC1E4B71BC9
|
||||
|
||||
/* Internal Includes */
|
||||
#include <osvr/ClientKit/Export.h>
|
||||
#include <osvr/Util/APIBaseC.h>
|
||||
#include <osvr/Util/ReturnCodesC.h>
|
||||
#include <osvr/Util/AnnotationMacrosC.h>
|
||||
#include <osvr/Util/ClientOpaqueTypesC.h>
|
||||
#include <osvr/Util/ClientCallbackTypesC.h>
|
||||
|
||||
/* Library/third-party includes */
|
||||
/* none */
|
||||
|
||||
/* Standard includes */
|
||||
/* none */
|
||||
|
||||
OSVR_EXTERN_C_BEGIN
|
||||
|
||||
#define OSVR_INTERFACE_CALLBACK_METHOD(TYPE) \
|
||||
/** @brief Register a callback for TYPE reports on an interface */ \
|
||||
OSVR_CLIENTKIT_EXPORT OSVR_ReturnCode osvrRegister##TYPE##Callback( \
|
||||
OSVR_ClientInterface iface, OSVR_##TYPE##Callback cb, void *userdata);
|
||||
|
||||
OSVR_INTERFACE_CALLBACK_METHOD(Pose)
|
||||
OSVR_INTERFACE_CALLBACK_METHOD(Position)
|
||||
OSVR_INTERFACE_CALLBACK_METHOD(Orientation)
|
||||
OSVR_INTERFACE_CALLBACK_METHOD(Velocity)
|
||||
OSVR_INTERFACE_CALLBACK_METHOD(LinearVelocity)
|
||||
OSVR_INTERFACE_CALLBACK_METHOD(AngularVelocity)
|
||||
OSVR_INTERFACE_CALLBACK_METHOD(Acceleration)
|
||||
OSVR_INTERFACE_CALLBACK_METHOD(LinearAcceleration)
|
||||
OSVR_INTERFACE_CALLBACK_METHOD(AngularAcceleration)
|
||||
OSVR_INTERFACE_CALLBACK_METHOD(Button)
|
||||
OSVR_INTERFACE_CALLBACK_METHOD(Analog)
|
||||
OSVR_INTERFACE_CALLBACK_METHOD(Imaging)
|
||||
OSVR_INTERFACE_CALLBACK_METHOD(Location2D)
|
||||
OSVR_INTERFACE_CALLBACK_METHOD(Direction)
|
||||
OSVR_INTERFACE_CALLBACK_METHOD(EyeTracker2D)
|
||||
OSVR_INTERFACE_CALLBACK_METHOD(EyeTracker3D)
|
||||
OSVR_INTERFACE_CALLBACK_METHOD(EyeTrackerBlink)
|
||||
OSVR_INTERFACE_CALLBACK_METHOD(NaviVelocity)
|
||||
OSVR_INTERFACE_CALLBACK_METHOD(NaviPosition)
|
||||
|
||||
#undef OSVR_INTERFACE_CALLBACK_METHOD
|
||||
|
||||
OSVR_EXTERN_C_END
|
||||
|
||||
#endif
|
||||
@@ -1,79 +0,0 @@
|
||||
/** @file
|
||||
@brief Header
|
||||
|
||||
Must be c-safe!
|
||||
|
||||
@date 2014
|
||||
|
||||
@author
|
||||
Sensics, Inc.
|
||||
<http://sensics.com/osvr>
|
||||
*/
|
||||
|
||||
/*
|
||||
// Copyright 2014 Sensics, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef INCLUDED_InterfaceStateC_h_GUID_8F85D178_74B9_4AA9_4E9E_243089411408
|
||||
#define INCLUDED_InterfaceStateC_h_GUID_8F85D178_74B9_4AA9_4E9E_243089411408
|
||||
|
||||
/* Internal Includes */
|
||||
#include <osvr/ClientKit/Export.h>
|
||||
#include <osvr/Util/APIBaseC.h>
|
||||
#include <osvr/Util/ReturnCodesC.h>
|
||||
#include <osvr/Util/AnnotationMacrosC.h>
|
||||
#include <osvr/Util/ClientOpaqueTypesC.h>
|
||||
#include <osvr/Util/ClientReportTypesC.h>
|
||||
#include <osvr/Util/TimeValueC.h>
|
||||
|
||||
/* Library/third-party includes */
|
||||
/* none */
|
||||
|
||||
/* Standard includes */
|
||||
/* none */
|
||||
|
||||
OSVR_EXTERN_C_BEGIN
|
||||
|
||||
#define OSVR_CALLBACK_METHODS(TYPE) \
|
||||
/** @brief Get TYPE state from an interface, returning failure if none \
|
||||
* exists */ \
|
||||
OSVR_CLIENTKIT_EXPORT OSVR_ReturnCode osvrGet##TYPE##State( \
|
||||
OSVR_ClientInterface iface, struct OSVR_TimeValue *timestamp, \
|
||||
OSVR_##TYPE##State *state);
|
||||
|
||||
OSVR_CALLBACK_METHODS(Pose)
|
||||
OSVR_CALLBACK_METHODS(Position)
|
||||
OSVR_CALLBACK_METHODS(Orientation)
|
||||
OSVR_CALLBACK_METHODS(Velocity)
|
||||
OSVR_CALLBACK_METHODS(LinearVelocity)
|
||||
OSVR_CALLBACK_METHODS(AngularVelocity)
|
||||
OSVR_CALLBACK_METHODS(Acceleration)
|
||||
OSVR_CALLBACK_METHODS(LinearAcceleration)
|
||||
OSVR_CALLBACK_METHODS(AngularAcceleration)
|
||||
OSVR_CALLBACK_METHODS(Button)
|
||||
OSVR_CALLBACK_METHODS(Analog)
|
||||
OSVR_CALLBACK_METHODS(Location2D)
|
||||
OSVR_CALLBACK_METHODS(Direction)
|
||||
OSVR_CALLBACK_METHODS(EyeTracker2D)
|
||||
OSVR_CALLBACK_METHODS(EyeTracker3D)
|
||||
OSVR_CALLBACK_METHODS(EyeTrackerBlink)
|
||||
OSVR_CALLBACK_METHODS(NaviVelocity)
|
||||
OSVR_CALLBACK_METHODS(NaviPosition)
|
||||
|
||||
#undef OSVR_CALLBACK_METHODS
|
||||
|
||||
OSVR_EXTERN_C_END
|
||||
|
||||
#endif
|
||||
@@ -1,47 +0,0 @@
|
||||
/** @file
|
||||
@brief Header
|
||||
|
||||
Must be c-safe!
|
||||
|
||||
@date 2014
|
||||
|
||||
@author
|
||||
Sensics, Inc.
|
||||
<http://sensics.com/osvr>
|
||||
*/
|
||||
|
||||
/*
|
||||
// Copyright 2014 Sensics, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef INCLUDED_SystemCallbackC_h_GUID_543F3F04_343E_4389_08A0_DEA988EC23F7
|
||||
#define INCLUDED_SystemCallbackC_h_GUID_543F3F04_343E_4389_08A0_DEA988EC23F7
|
||||
|
||||
/* Internal Includes */
|
||||
#include <osvr/ClientKit/Export.h>
|
||||
#include <osvr/Util/APIBaseC.h>
|
||||
#include <osvr/Util/ReturnCodesC.h>
|
||||
#include <osvr/Util/AnnotationMacrosC.h>
|
||||
|
||||
/* Library/third-party includes */
|
||||
/* none */
|
||||
|
||||
/* Standard includes */
|
||||
/* none */
|
||||
|
||||
OSVR_EXTERN_C_BEGIN
|
||||
OSVR_EXTERN_C_END
|
||||
|
||||
#endif
|
||||
@@ -1,75 +0,0 @@
|
||||
/** @file
|
||||
@brief Header controlling the OSVR transformation hierarchy
|
||||
|
||||
Must be c-safe!
|
||||
|
||||
@date 2015
|
||||
|
||||
@author
|
||||
Sensics, Inc.
|
||||
<http://sensics.com/osvr>
|
||||
*/
|
||||
|
||||
/*
|
||||
// Copyright 2015 Sensics, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef INCLUDED_TransformsC_h_GUID_5B5B7438_42D4_4095_E48A_90E2CC13498E
|
||||
#define INCLUDED_TransformsC_h_GUID_5B5B7438_42D4_4095_E48A_90E2CC13498E
|
||||
|
||||
/* Internal Includes */
|
||||
#include <osvr/ClientKit/Export.h>
|
||||
#include <osvr/Util/APIBaseC.h>
|
||||
#include <osvr/Util/ReturnCodesC.h>
|
||||
#include <osvr/Util/ClientOpaqueTypesC.h>
|
||||
|
||||
/* Library/third-party includes */
|
||||
/* none */
|
||||
|
||||
/* Standard includes */
|
||||
/* none */
|
||||
|
||||
OSVR_EXTERN_C_BEGIN
|
||||
|
||||
/** @addtogroup ClientKit
|
||||
@{
|
||||
*/
|
||||
|
||||
/** @brief Updates the internal "room to world" transformation (applied to all
|
||||
tracker data for this client context instance) based on the user's head
|
||||
orientation, so that the direction the user is facing becomes -Z to your
|
||||
application. Only rotates about the Y axis (yaw).
|
||||
|
||||
Note that this method internally calls osvrClientUpdate() to get a head pose
|
||||
so your callbacks may be called during its execution!
|
||||
|
||||
@param ctx Client context
|
||||
*/
|
||||
OSVR_CLIENTKIT_EXPORT OSVR_ReturnCode
|
||||
osvrClientSetRoomRotationUsingHead(OSVR_ClientContext ctx);
|
||||
|
||||
/** @brief Clears/resets the internal "room to world" transformation back to an
|
||||
identity transformation - that is, clears the effect of any other
|
||||
manipulation of the room to world transform.
|
||||
|
||||
@param ctx Client context
|
||||
*/
|
||||
OSVR_CLIENTKIT_EXPORT OSVR_ReturnCode
|
||||
osvrClientClearRoomToWorldTransform(OSVR_ClientContext ctx);
|
||||
|
||||
/** @} */
|
||||
OSVR_EXTERN_C_END
|
||||
|
||||
#endif
|
||||
@@ -1,50 +0,0 @@
|
||||
/** @file
|
||||
@brief Header providing basic C macros for defining API headers.
|
||||
|
||||
Must be c-safe!
|
||||
|
||||
@date 2014
|
||||
|
||||
@author
|
||||
Sensics, Inc.
|
||||
<http://sensics.com/osvr>
|
||||
*/
|
||||
|
||||
/*
|
||||
// Copyright 2014 Sensics, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef INCLUDED_APIBaseC_h_GUID_C5A2E769_2ADC_429E_D250_DF0883E6E5DB
|
||||
#define INCLUDED_APIBaseC_h_GUID_C5A2E769_2ADC_429E_D250_DF0883E6E5DB
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define OSVR_C_ONLY(X)
|
||||
#define OSVR_CPP_ONLY(X) X
|
||||
#define OSVR_EXTERN_C_BEGIN extern "C" {
|
||||
#define OSVR_EXTERN_C_END }
|
||||
#define OSVR_INLINE inline
|
||||
#else
|
||||
#define OSVR_C_ONLY(X) X
|
||||
#define OSVR_CPP_ONLY(X)
|
||||
#define OSVR_EXTERN_C_BEGIN
|
||||
#define OSVR_EXTERN_C_END
|
||||
#ifdef _MSC_VER
|
||||
#define OSVR_INLINE static __inline
|
||||
#else
|
||||
#define OSVR_INLINE static inline
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,232 +0,0 @@
|
||||
/** @file
|
||||
@brief Header containing macros for source-level annotation.
|
||||
|
||||
In theory, supporting MSVC SAL, as well as compatible GCC and
|
||||
Clang attributes. In practice, expanded as time allows and requires.
|
||||
|
||||
Must be c-safe!
|
||||
|
||||
@date 2014
|
||||
|
||||
@author
|
||||
Sensics, Inc.
|
||||
<http://sensics.com/osvr>
|
||||
*/
|
||||
|
||||
/*
|
||||
// Copyright 2014 Sensics, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef INCLUDED_AnnotationMacrosC_h_GUID_48538D9B_35E3_4E9A_D2B0_D83D51DD5900
|
||||
#define INCLUDED_AnnotationMacrosC_h_GUID_48538D9B_35E3_4E9A_D2B0_D83D51DD5900
|
||||
|
||||
#ifndef OSVR_DISABLE_ANALYSIS
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1700)
|
||||
/* Visual C++ (2012 and newer) */
|
||||
/* Using SAL attribute format:
|
||||
* http://msdn.microsoft.com/en-us/library/ms182032(v=vs.120).aspx */
|
||||
|
||||
#include <sal.h>
|
||||
|
||||
#define OSVR_IN _In_
|
||||
#define OSVR_IN_PTR _In_
|
||||
#define OSVR_IN_OPT _In_opt_
|
||||
#define OSVR_IN_STRZ _In_z_
|
||||
#define OSVR_IN_READS(NUM_ELEMENTS) _In_reads_(NUM_ELEMENTS)
|
||||
|
||||
#define OSVR_OUT _Out_
|
||||
#define OSVR_OUT_PTR _Outptr_
|
||||
#define OSVR_OUT_OPT _Out_opt_
|
||||
|
||||
#define OSVR_INOUT _Inout_
|
||||
#define OSVR_INOUT_PTR _Inout_
|
||||
|
||||
#define OSVR_RETURN_WARN_UNUSED _Must_inspect_result_
|
||||
#define OSVR_RETURN_SUCCESS_CONDITION(X) _Return_type_success_(X)
|
||||
|
||||
/* end of msvc section */
|
||||
#elif defined(__GNUC__) && (__GNUC__ >= 4)
|
||||
/* section for GCC and GCC-alikes */
|
||||
|
||||
#if defined(__clang__)
|
||||
/* clang-specific section */
|
||||
#endif
|
||||
|
||||
#define OSVR_FUNC_NONNULL(X) __attribute__((__nonnull__ X))
|
||||
#define OSVR_RETURN_WARN_UNUSED __attribute__((warn_unused_result))
|
||||
|
||||
/* end of gcc section and compiler detection */
|
||||
#endif
|
||||
|
||||
/* end of ndef disable analysis */
|
||||
#endif
|
||||
|
||||
/* Fallback declarations */
|
||||
/**
|
||||
@defgroup annotation_macros Static analysis annotation macros
|
||||
@brief Wrappers for Microsoft's SAL annotations and others
|
||||
@ingroup Util
|
||||
|
||||
Use of these is optional, but recommended particularly for C APIs,
|
||||
as well as any methods handling a buffer with a length.
|
||||
@{
|
||||
*/
|
||||
/** @name Parameter annotations
|
||||
|
||||
These indicate the role and valid values for parameters to functions.
|
||||
|
||||
At most one of these should be placed before a parameter's type name in the
|
||||
function parameter list, in both the declaration and definition. (They must
|
||||
match!)
|
||||
@{
|
||||
*/
|
||||
/** @def OSVR_IN
|
||||
@brief Indicates a required function parameter that serves only as input.
|
||||
*/
|
||||
#ifndef OSVR_IN
|
||||
#define OSVR_IN
|
||||
#endif
|
||||
|
||||
/** @def OSVR_IN_PTR
|
||||
@brief Indicates a required pointer (non-null) function parameter that
|
||||
serves only as input.
|
||||
*/
|
||||
#ifndef OSVR_IN_PTR
|
||||
#define OSVR_IN_PTR
|
||||
#endif
|
||||
|
||||
/** @def OSVR_IN_OPT
|
||||
@brief Indicates a function parameter (pointer) that serves only as input,
|
||||
but is optional and might be NULL.
|
||||
*/
|
||||
#ifndef OSVR_IN_OPT
|
||||
#define OSVR_IN_OPT
|
||||
#endif
|
||||
|
||||
/** @def OSVR_IN_STRZ
|
||||
@brief Indicates a null-terminated string function parameter that serves
|
||||
only as input.
|
||||
*/
|
||||
#ifndef OSVR_IN_STRZ
|
||||
#define OSVR_IN_STRZ
|
||||
#endif
|
||||
|
||||
/** @def OSVR_IN_READS(NUM_ELEMENTS)
|
||||
@brief Indicates a buffer containing input with the specified number of
|
||||
elements.
|
||||
|
||||
The specified number of elements is typically the name of another parameter.
|
||||
*/
|
||||
#ifndef OSVR_IN_READS
|
||||
#define OSVR_IN_READS(NUM_ELEMENTS)
|
||||
#endif
|
||||
|
||||
/** @def OSVR_OUT
|
||||
@brief Indicates a required function parameter that serves only as output.
|
||||
In C code, since this usually means "pointer", you probably want
|
||||
OSVR_OUT_PTR instead.
|
||||
*/
|
||||
#ifndef OSVR_OUT
|
||||
#define OSVR_OUT
|
||||
#endif
|
||||
|
||||
/** @def OSVR_OUT_PTR
|
||||
@brief Indicates a required pointer (non-null) function parameter that
|
||||
serves only as output.
|
||||
*/
|
||||
#ifndef OSVR_OUT_PTR
|
||||
#define OSVR_OUT_PTR
|
||||
#endif
|
||||
|
||||
/** @def OSVR_OUT_OPT
|
||||
@brief Indicates a function parameter (pointer) that serves only as output,
|
||||
but is optional and might be NULL
|
||||
*/
|
||||
#ifndef OSVR_OUT_OPT
|
||||
#define OSVR_OUT_OPT
|
||||
#endif
|
||||
|
||||
/** @def OSVR_INOUT
|
||||
@brief Indicates a required function parameter that is both read and written
|
||||
to.
|
||||
|
||||
In C code, since this usually means "pointer", you probably want
|
||||
OSVR_INOUT_PTR instead.
|
||||
*/
|
||||
#ifndef OSVR_INOUT
|
||||
#define OSVR_INOUT
|
||||
#endif
|
||||
|
||||
/** @def OSVR_INOUT_PTR
|
||||
@brief Indicates a required pointer (non-null) function parameter that is
|
||||
both read and written to.
|
||||
*/
|
||||
#ifndef OSVR_INOUT_PTR
|
||||
#define OSVR_INOUT_PTR
|
||||
#endif
|
||||
|
||||
/* End of parameter annotations. */
|
||||
/** @} */
|
||||
|
||||
/** @name Function annotations
|
||||
|
||||
These indicate particular relevant aspects about a function. Some
|
||||
duplicate the effective meaning of parameter annotations: applying both
|
||||
allows the fullest extent of static analysis tools to analyze the code,
|
||||
and in some compilers, generate warnings.
|
||||
|
||||
@{
|
||||
*/
|
||||
/** @def OSVR_FUNC_NONNULL(X)
|
||||
@brief Indicates the parameter(s) that must be non-null.
|
||||
|
||||
@param X A parenthesized list of parameters by number (1-based index)
|
||||
|
||||
Should be placed after a function declaration (but before the
|
||||
semicolon). Repeating in the definition is not needed.
|
||||
*/
|
||||
#ifndef OSVR_FUNC_NONNULL
|
||||
#define OSVR_FUNC_NONNULL(X)
|
||||
#endif
|
||||
|
||||
/** @def OSVR_RETURN_WARN_UNUSED
|
||||
@brief Indicates the function has a return value that must be used (either a
|
||||
security problem or an obvious bug if not).
|
||||
|
||||
Should be placed before the return value (and virtual keyword, if
|
||||
applicable) in both declaration and definition.
|
||||
*/
|
||||
#ifndef OSVR_RETURN_WARN_UNUSED
|
||||
#define OSVR_RETURN_WARN_UNUSED
|
||||
#endif
|
||||
/* End of function annotations. */
|
||||
/** @} */
|
||||
|
||||
/** @def OSVR_RETURN_SUCCESS_CONDITION
|
||||
@brief Applied to a typedef, indicates the condition for `return` under
|
||||
which a function returning it should be considered to have succeeded (thus
|
||||
holding certain specifications).
|
||||
|
||||
Should be placed before the typename in a typedef, with the parameter
|
||||
including the keyword `return` to substitute for the return value.
|
||||
*/
|
||||
#ifndef OSVR_RETURN_SUCCESS_CONDITION
|
||||
#define OSVR_RETURN_SUCCESS_CONDITION(X)
|
||||
#endif
|
||||
|
||||
/* End of annotation group. */
|
||||
/** @} */
|
||||
#endif
|
||||
@@ -1,59 +0,0 @@
|
||||
/** @file
|
||||
@brief Header providing a C-safe "bool" type, because we can't depend on
|
||||
Visual Studio providing proper C99 support in external-facing APIs.
|
||||
|
||||
Must be c-safe!
|
||||
|
||||
@date 2015
|
||||
|
||||
@author
|
||||
Sensics, Inc.
|
||||
<http://sensics.com/osvr>
|
||||
*/
|
||||
|
||||
/*
|
||||
// Copyright 2015 Sensics, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef INCLUDED_BoolC_h_GUID_4F97BE90_2758_4BA5_B0FC_0CA92DEBA210
|
||||
#define INCLUDED_BoolC_h_GUID_4F97BE90_2758_4BA5_B0FC_0CA92DEBA210
|
||||
|
||||
/* Internal Includes */
|
||||
#include <osvr/Util/APIBaseC.h>
|
||||
#include <osvr/Util/StdInt.h>
|
||||
|
||||
/* Library/third-party includes */
|
||||
/* none */
|
||||
|
||||
/* Standard includes */
|
||||
/* none */
|
||||
|
||||
OSVR_EXTERN_C_BEGIN
|
||||
/** @addtogroup Util
|
||||
@{
|
||||
*/
|
||||
|
||||
/** @brief A pre-C99-safe bool type. Canonical values for true and false are
|
||||
* provided. Interpretation of other values is not defined. */
|
||||
typedef uint8_t OSVR_CBool;
|
||||
/** @brief Canonical "true" value for OSVR_CBool */
|
||||
#define OSVR_TRUE (1)
|
||||
/** @brief Canonical "false" value for OSVR_CBool */
|
||||
#define OSVR_FALSE (0)
|
||||
|
||||
/** @} */
|
||||
OSVR_EXTERN_C_END
|
||||
|
||||
#endif
|
||||
@@ -1,57 +0,0 @@
|
||||
/** @file
|
||||
@brief Header
|
||||
|
||||
Must be c-safe!
|
||||
|
||||
@date 2015
|
||||
|
||||
@author
|
||||
Sensics, Inc.
|
||||
<http://sensics.com/osvr>
|
||||
*/
|
||||
|
||||
/*
|
||||
// Copyright 2015 Sensics, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef INCLUDED_ChannelCountC_h_GUID_CF7E5EE7_28B0_4B99_E823_DD701904B5D1
|
||||
#define INCLUDED_ChannelCountC_h_GUID_CF7E5EE7_28B0_4B99_E823_DD701904B5D1
|
||||
|
||||
/* Internal Includes */
|
||||
#include <osvr/Util/StdInt.h>
|
||||
#include <osvr/Util/APIBaseC.h>
|
||||
|
||||
/* Library/third-party includes */
|
||||
/* none */
|
||||
|
||||
/* Standard includes */
|
||||
/* none */
|
||||
|
||||
OSVR_EXTERN_C_BEGIN
|
||||
|
||||
/** @addtogroup PluginKit
|
||||
@{
|
||||
*/
|
||||
|
||||
/** @brief The integer type specifying a number of channels/sensors or a
|
||||
channel/sensor index.
|
||||
*/
|
||||
typedef uint32_t OSVR_ChannelCount;
|
||||
|
||||
/** @} */
|
||||
|
||||
OSVR_EXTERN_C_END
|
||||
|
||||
#endif
|
||||
@@ -1,140 +0,0 @@
|
||||
/** @file
|
||||
@brief Header
|
||||
|
||||
Must be c-safe!
|
||||
|
||||
GENERATED - do not edit by hand!
|
||||
|
||||
@date 2014
|
||||
|
||||
@author
|
||||
Sensics, Inc.
|
||||
<http://sensics.com/osvr>
|
||||
*/
|
||||
|
||||
/*
|
||||
// Copyright 2014 Sensics, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef INCLUDED_ClientCallbackTypesC_h_GUID_4D43A675_C8A4_4BBF_516F_59E6C785E4EF
|
||||
#define INCLUDED_ClientCallbackTypesC_h_GUID_4D43A675_C8A4_4BBF_516F_59E6C785E4EF
|
||||
|
||||
/* Internal Includes */
|
||||
#include <osvr/Util/ClientReportTypesC.h>
|
||||
#include <osvr/Util/ImagingReportTypesC.h>
|
||||
#include <osvr/Util/ReturnCodesC.h>
|
||||
#include <osvr/Util/TimeValueC.h>
|
||||
|
||||
/* Library/third-party includes */
|
||||
/* none */
|
||||
|
||||
/* Standard includes */
|
||||
/* none */
|
||||
|
||||
OSVR_EXTERN_C_BEGIN
|
||||
|
||||
/** @addtogroup ClientKit
|
||||
@{
|
||||
*/
|
||||
|
||||
/** @name Report callback types
|
||||
@{
|
||||
*/
|
||||
|
||||
/* generated file - do not edit! */
|
||||
/** @brief C function type for a Pose callback */
|
||||
typedef void (*OSVR_PoseCallback)(void *userdata,
|
||||
const struct OSVR_TimeValue *timestamp,
|
||||
const struct OSVR_PoseReport *report);
|
||||
/** @brief C function type for a Position callback */
|
||||
typedef void (*OSVR_PositionCallback)(void *userdata,
|
||||
const struct OSVR_TimeValue *timestamp,
|
||||
const struct OSVR_PositionReport *report);
|
||||
/** @brief C function type for a Orientation callback */
|
||||
typedef void (*OSVR_OrientationCallback)(void *userdata,
|
||||
const struct OSVR_TimeValue *timestamp,
|
||||
const struct OSVR_OrientationReport *report);
|
||||
/** @brief C function type for a Velocity callback */
|
||||
typedef void (*OSVR_VelocityCallback)(void *userdata,
|
||||
const struct OSVR_TimeValue *timestamp,
|
||||
const struct OSVR_VelocityReport *report);
|
||||
/** @brief C function type for a LinearVelocity callback */
|
||||
typedef void (*OSVR_LinearVelocityCallback)(void *userdata,
|
||||
const struct OSVR_TimeValue *timestamp,
|
||||
const struct OSVR_LinearVelocityReport *report);
|
||||
/** @brief C function type for a AngularVelocity callback */
|
||||
typedef void (*OSVR_AngularVelocityCallback)(void *userdata,
|
||||
const struct OSVR_TimeValue *timestamp,
|
||||
const struct OSVR_AngularVelocityReport *report);
|
||||
/** @brief C function type for a Acceleration callback */
|
||||
typedef void (*OSVR_AccelerationCallback)(void *userdata,
|
||||
const struct OSVR_TimeValue *timestamp,
|
||||
const struct OSVR_AccelerationReport *report);
|
||||
/** @brief C function type for a LinearAcceleration callback */
|
||||
typedef void (*OSVR_LinearAccelerationCallback)(void *userdata,
|
||||
const struct OSVR_TimeValue *timestamp,
|
||||
const struct OSVR_LinearAccelerationReport *report);
|
||||
/** @brief C function type for a AngularAcceleration callback */
|
||||
typedef void (*OSVR_AngularAccelerationCallback)(void *userdata,
|
||||
const struct OSVR_TimeValue *timestamp,
|
||||
const struct OSVR_AngularAccelerationReport *report);
|
||||
/** @brief C function type for a Button callback */
|
||||
typedef void (*OSVR_ButtonCallback)(void *userdata,
|
||||
const struct OSVR_TimeValue *timestamp,
|
||||
const struct OSVR_ButtonReport *report);
|
||||
/** @brief C function type for a Analog callback */
|
||||
typedef void (*OSVR_AnalogCallback)(void *userdata,
|
||||
const struct OSVR_TimeValue *timestamp,
|
||||
const struct OSVR_AnalogReport *report);
|
||||
/** @brief C function type for a Imaging callback */
|
||||
typedef void (*OSVR_ImagingCallback)(void *userdata,
|
||||
const struct OSVR_TimeValue *timestamp,
|
||||
const struct OSVR_ImagingReport *report);
|
||||
/** @brief C function type for a Location2D callback */
|
||||
typedef void (*OSVR_Location2DCallback)(void *userdata,
|
||||
const struct OSVR_TimeValue *timestamp,
|
||||
const struct OSVR_Location2DReport *report);
|
||||
/** @brief C function type for a Direction callback */
|
||||
typedef void (*OSVR_DirectionCallback)(void *userdata,
|
||||
const struct OSVR_TimeValue *timestamp,
|
||||
const struct OSVR_DirectionReport *report);
|
||||
/** @brief C function type for a EyeTracker2D callback */
|
||||
typedef void (*OSVR_EyeTracker2DCallback)(void *userdata,
|
||||
const struct OSVR_TimeValue *timestamp,
|
||||
const struct OSVR_EyeTracker2DReport *report);
|
||||
/** @brief C function type for a EyeTracker3D callback */
|
||||
typedef void (*OSVR_EyeTracker3DCallback)(void *userdata,
|
||||
const struct OSVR_TimeValue *timestamp,
|
||||
const struct OSVR_EyeTracker3DReport *report);
|
||||
/** @brief C function type for a EyeTrackerBlink callback */
|
||||
typedef void (*OSVR_EyeTrackerBlinkCallback)(void *userdata,
|
||||
const struct OSVR_TimeValue *timestamp,
|
||||
const struct OSVR_EyeTrackerBlinkReport *report);
|
||||
/** @brief C function type for a NaviVelocity callback */
|
||||
typedef void (*OSVR_NaviVelocityCallback)(void *userdata,
|
||||
const struct OSVR_TimeValue *timestamp,
|
||||
const struct OSVR_NaviVelocityReport *report);
|
||||
/** @brief C function type for a NaviPosition callback */
|
||||
typedef void (*OSVR_NaviPositionCallback)(void *userdata,
|
||||
const struct OSVR_TimeValue *timestamp,
|
||||
const struct OSVR_NaviPositionReport *report);
|
||||
|
||||
/** @} */
|
||||
|
||||
/** @} */
|
||||
|
||||
OSVR_EXTERN_C_END
|
||||
|
||||
#endif
|
||||
@@ -1,69 +0,0 @@
|
||||
/** @file
|
||||
@brief Header declaring opaque types used by @ref Client and @ref ClientKit
|
||||
|
||||
Must be c-safe!
|
||||
|
||||
@date 2014
|
||||
|
||||
@author
|
||||
Sensics, Inc.
|
||||
<http://sensics.com/osvr>
|
||||
*/
|
||||
|
||||
/*
|
||||
// Copyright 2014 Sensics, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef INCLUDED_ClientOpaqueTypesC_h_GUID_24B79ED2_5751_4BA2_1690_BBD250EBC0C1
|
||||
#define INCLUDED_ClientOpaqueTypesC_h_GUID_24B79ED2_5751_4BA2_1690_BBD250EBC0C1
|
||||
|
||||
/* Internal Includes */
|
||||
#include <osvr/Util/APIBaseC.h>
|
||||
|
||||
/* Library/third-party includes */
|
||||
/* none */
|
||||
|
||||
/* Standard includes */
|
||||
/* none */
|
||||
|
||||
OSVR_EXTERN_C_BEGIN
|
||||
|
||||
/** @addtogroup ClientKit
|
||||
@{
|
||||
*/
|
||||
/** @brief Opaque handle that should be retained by your application. You need
|
||||
only and exactly one.
|
||||
|
||||
Created by osvrClientInit() at application start.
|
||||
|
||||
You are required to clean up this handle with osvrClientShutdown().
|
||||
*/
|
||||
typedef struct OSVR_ClientContextObject *OSVR_ClientContext;
|
||||
|
||||
/** @brief Opaque handle to an interface used for registering callbacks and
|
||||
getting status.
|
||||
|
||||
You are not required to clean up this handle (it will be automatically
|
||||
cleaned up when the context is), but you can if you are no longer using it,
|
||||
using osvrClientFreeInterface() to inform the context that you no longer need
|
||||
this interface.
|
||||
*/
|
||||
typedef struct OSVR_ClientInterfaceObject *OSVR_ClientInterface;
|
||||
|
||||
/** @} */
|
||||
|
||||
OSVR_EXTERN_C_END
|
||||
|
||||
#endif
|
||||
@@ -1,348 +0,0 @@
|
||||
/** @file
|
||||
@brief Header
|
||||
|
||||
Must be c-safe!
|
||||
|
||||
@date 2014
|
||||
|
||||
@author
|
||||
Sensics, Inc.
|
||||
<http://sensics.com/osvr>
|
||||
*/
|
||||
|
||||
/*
|
||||
// Copyright 2014 Sensics, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef INCLUDED_ClientReportTypesC_h_GUID_E79DAB07_78B7_4795_1EB9_CA6EEB274AEE
|
||||
#define INCLUDED_ClientReportTypesC_h_GUID_E79DAB07_78B7_4795_1EB9_CA6EEB274AEE
|
||||
|
||||
/* Internal Includes */
|
||||
#include <osvr/Util/APIBaseC.h>
|
||||
#include <osvr/Util/Pose3C.h>
|
||||
#include <osvr/Util/StdInt.h>
|
||||
|
||||
#include <osvr/Util/Vec2C.h>
|
||||
#include <osvr/Util/Vec3C.h>
|
||||
#include <osvr/Util/ChannelCountC.h>
|
||||
#include <osvr/Util/BoolC.h>
|
||||
|
||||
/* Library/third-party includes */
|
||||
/* none */
|
||||
|
||||
/* Standard includes */
|
||||
/* none */
|
||||
|
||||
OSVR_EXTERN_C_BEGIN
|
||||
|
||||
/** @addtogroup ClientKit
|
||||
@{
|
||||
*/
|
||||
|
||||
/** @name State types
|
||||
@{
|
||||
*/
|
||||
/** @brief Type of position state */
|
||||
typedef OSVR_Vec3 OSVR_PositionState;
|
||||
|
||||
/** @brief Type of orientation state */
|
||||
typedef OSVR_Quaternion OSVR_OrientationState;
|
||||
|
||||
/** @brief Type of pose state */
|
||||
typedef OSVR_Pose3 OSVR_PoseState;
|
||||
|
||||
/** @brief Type of linear velocity state */
|
||||
typedef OSVR_Vec3 OSVR_LinearVelocityState;
|
||||
|
||||
/** @brief The quaternion represents the incremental rotation taking place over
|
||||
a period of dt seconds. Use of dt (which does not necessarily
|
||||
have to be 1, as other velocity/acceleration representations imply) and an
|
||||
incremental quaternion allows device reports to be scaled to avoid aliasing
|
||||
*/
|
||||
typedef struct OSVR_IncrementalQuaternion {
|
||||
OSVR_Quaternion incrementalRotation;
|
||||
double dt;
|
||||
} OSVR_IncrementalQuaternion;
|
||||
|
||||
/** @brief Type of angular velocity state: an incremental quaternion, providing
|
||||
the incremental rotation taking place due to velocity over a period of dt
|
||||
seconds.
|
||||
*/
|
||||
typedef OSVR_IncrementalQuaternion OSVR_AngularVelocityState;
|
||||
|
||||
/** @brief Struct for combined velocity state */
|
||||
typedef struct OSVR_VelocityState {
|
||||
OSVR_LinearVelocityState linearVelocity;
|
||||
/** @brief Whether the data source reports valid data for
|
||||
#OSVR_VelocityState::linearVelocity */
|
||||
OSVR_CBool linearVelocityValid;
|
||||
|
||||
OSVR_AngularVelocityState angularVelocity;
|
||||
/** @brief Whether the data source reports valid data for
|
||||
#OSVR_VelocityState::angularVelocity */
|
||||
OSVR_CBool angularVelocityValid;
|
||||
} OSVR_VelocityState;
|
||||
|
||||
/** @brief Type of linear acceleration state */
|
||||
typedef OSVR_Vec3 OSVR_LinearAccelerationState;
|
||||
|
||||
/** @brief Type of angular acceleration state
|
||||
*/
|
||||
typedef OSVR_IncrementalQuaternion OSVR_AngularAccelerationState;
|
||||
|
||||
/** @brief Struct for combined acceleration state */
|
||||
typedef struct OSVR_AccelerationState {
|
||||
OSVR_LinearAccelerationState linearAcceleration;
|
||||
/** @brief Whether the data source reports valid data for
|
||||
#OSVR_AccelerationState::linearAcceleration */
|
||||
OSVR_CBool linearAccelerationValid;
|
||||
|
||||
OSVR_AngularAccelerationState angularAcceleration;
|
||||
/** @brief Whether the data source reports valid data for
|
||||
#OSVR_AccelerationState::angularAcceleration */
|
||||
OSVR_CBool angularAccelerationValid;
|
||||
} OSVR_AccelerationState;
|
||||
|
||||
/** @brief Type of button state */
|
||||
typedef uint8_t OSVR_ButtonState;
|
||||
|
||||
/** @brief OSVR_ButtonState value indicating "button down" */
|
||||
#define OSVR_BUTTON_PRESSED (1)
|
||||
|
||||
/** @brief OSVR_ButtonState value indicating "button up" */
|
||||
#define OSVR_BUTTON_NOT_PRESSED (0)
|
||||
|
||||
/** @brief Type of analog channel state */
|
||||
typedef double OSVR_AnalogState;
|
||||
|
||||
/** @} */
|
||||
|
||||
/** @name Report types
|
||||
@{
|
||||
*/
|
||||
/** @brief Report type for a position callback on a tracker interface */
|
||||
typedef struct OSVR_PositionReport {
|
||||
/** @brief Identifies the sensor that the report comes from */
|
||||
int32_t sensor;
|
||||
/** @brief The position vector */
|
||||
OSVR_PositionState xyz;
|
||||
} OSVR_PositionReport;
|
||||
|
||||
/** @brief Report type for an orientation callback on a tracker interface */
|
||||
typedef struct OSVR_OrientationReport {
|
||||
/** @brief Identifies the sensor that the report comes from */
|
||||
int32_t sensor;
|
||||
/** @brief The rotation unit quaternion */
|
||||
OSVR_OrientationState rotation;
|
||||
} OSVR_OrientationReport;
|
||||
|
||||
/** @brief Report type for a pose (position and orientation) callback on a
|
||||
tracker interface
|
||||
*/
|
||||
typedef struct OSVR_PoseReport {
|
||||
/** @brief Identifies the sensor that the report comes from */
|
||||
int32_t sensor;
|
||||
/** @brief The pose structure, containing a position vector and a rotation
|
||||
quaternion
|
||||
*/
|
||||
OSVR_PoseState pose;
|
||||
} OSVR_PoseReport;
|
||||
|
||||
/** @brief Report type for a velocity (linear and angular) callback on a
|
||||
tracker interface
|
||||
*/
|
||||
typedef struct OSVR_VelocityReport {
|
||||
/** @brief Identifies the sensor that the report comes from */
|
||||
int32_t sensor;
|
||||
/** @brief The data state - note that not all fields are neccesarily valid,
|
||||
use the `Valid` members to check the status of the other fields.
|
||||
*/
|
||||
OSVR_VelocityState state;
|
||||
} OSVR_VelocityReport;
|
||||
|
||||
/** @brief Report type for a linear velocity callback on a tracker interface
|
||||
*/
|
||||
typedef struct OSVR_LinearVelocityReport {
|
||||
/** @brief Identifies the sensor that the report comes from */
|
||||
int32_t sensor;
|
||||
/** @brief The state itself */
|
||||
OSVR_LinearVelocityState state;
|
||||
} OSVR_LinearVelocityReport;
|
||||
|
||||
/** @brief Report type for an angular velocity callback on a tracker interface
|
||||
*/
|
||||
typedef struct OSVR_AngularVelocityReport {
|
||||
/** @brief Identifies the sensor that the report comes from */
|
||||
int32_t sensor;
|
||||
/** @brief The state itself */
|
||||
OSVR_AngularVelocityState state;
|
||||
} OSVR_AngularVelocityReport;
|
||||
|
||||
/** @brief Report type for an acceleration (linear and angular) callback on a
|
||||
tracker interface
|
||||
*/
|
||||
typedef struct OSVR_AccelerationReport {
|
||||
/** @brief Identifies the sensor that the report comes from */
|
||||
int32_t sensor;
|
||||
/** @brief The data state - note that not all fields are neccesarily valid,
|
||||
use the `Valid` members to check the status of the other fields.
|
||||
*/
|
||||
OSVR_AccelerationState state;
|
||||
} OSVR_AccelerationReport;
|
||||
|
||||
/** @brief Report type for a linear acceleration callback on a tracker interface
|
||||
*/
|
||||
typedef struct OSVR_LinearAccelerationReport {
|
||||
/** @brief Identifies the sensor that the report comes from */
|
||||
int32_t sensor;
|
||||
/** @brief The state itself */
|
||||
OSVR_LinearAccelerationState state;
|
||||
} OSVR_LinearAccelerationReport;
|
||||
|
||||
/** @brief Report type for an angular acceleration callback on a tracker
|
||||
interface
|
||||
*/
|
||||
typedef struct OSVR_AngularAccelerationReport {
|
||||
/** @brief Identifies the sensor that the report comes from */
|
||||
int32_t sensor;
|
||||
/** @brief The state itself */
|
||||
OSVR_AngularAccelerationState state;
|
||||
} OSVR_AngularAccelerationReport;
|
||||
|
||||
/** @brief Report type for a callback on a button interface */
|
||||
typedef struct OSVR_ButtonReport {
|
||||
/** @brief Identifies the sensor that the report comes from */
|
||||
int32_t sensor;
|
||||
/** @brief The button state: 1 is pressed, 0 is not pressed. */
|
||||
OSVR_ButtonState state;
|
||||
} OSVR_ButtonReport;
|
||||
|
||||
/** @brief Report type for a callback on an analog interface */
|
||||
typedef struct OSVR_AnalogReport {
|
||||
/** @brief Identifies the sensor/channel that the report comes from */
|
||||
int32_t sensor;
|
||||
/** @brief The analog state. */
|
||||
OSVR_AnalogState state;
|
||||
} OSVR_AnalogReport;
|
||||
|
||||
/** @brief Type of location within a 2D region/surface, in normalized
|
||||
coordinates (in range [0, 1] in standard OSVR coordinate system)
|
||||
*/
|
||||
typedef OSVR_Vec2 OSVR_Location2DState;
|
||||
|
||||
/** @brief Report type for 2D location */
|
||||
typedef struct OSVR_Location2DReport {
|
||||
OSVR_ChannelCount sensor;
|
||||
OSVR_Location2DState location;
|
||||
} OSVR_Location2DReport;
|
||||
|
||||
/** @brief Type of unit directional vector in 3D with no particular origin */
|
||||
typedef OSVR_Vec3 OSVR_DirectionState;
|
||||
|
||||
/** @brief Report type for 3D Direction vector */
|
||||
typedef struct OSVR_DirectionReport {
|
||||
OSVR_ChannelCount sensor;
|
||||
OSVR_DirectionState direction;
|
||||
} OSVR_DirectionReport;
|
||||
|
||||
/** @brief Type of eye gaze direction in 3D which contains 3D vector (position)
|
||||
containing gaze base point of the user's respective eye in 3D device
|
||||
coordinates.
|
||||
*/
|
||||
typedef OSVR_PositionState OSVR_EyeGazeBasePoint3DState;
|
||||
|
||||
/** @brief Type of eye gaze position in 2D which contains users's gaze/point of
|
||||
regard in normalized display coordinates (in range [0, 1] in standard OSVR
|
||||
coordinate system)
|
||||
*/
|
||||
typedef OSVR_Location2DState OSVR_EyeGazePosition2DState;
|
||||
|
||||
// typedef OSVR_DirectionState OSVR_EyeGazeBasePoint3DState;
|
||||
|
||||
/** @brief Type of 3D vector (direction vector) containing the normalized gaze
|
||||
direction of user's respective eye */
|
||||
typedef OSVR_DirectionState OSVR_EyeGazeDirectionState;
|
||||
|
||||
/** @brief State for 3D gaze report */
|
||||
typedef struct OSVR_EyeTracker3DState {
|
||||
OSVR_CBool directionValid;
|
||||
OSVR_DirectionState direction;
|
||||
OSVR_CBool basePointValid;
|
||||
OSVR_PositionState basePoint;
|
||||
} OSVR_EyeTracker3DState;
|
||||
|
||||
/** @brief Report type for 3D gaze report */
|
||||
typedef struct OSVR_EyeTracker3DReport {
|
||||
OSVR_ChannelCount sensor;
|
||||
OSVR_EyeTracker3DState state;
|
||||
} OSVR_EyeTracker3DReport;
|
||||
|
||||
/** @brief State for 2D location report */
|
||||
typedef OSVR_Location2DState OSVR_EyeTracker2DState;
|
||||
|
||||
/** @brief Report type for 2D location report */
|
||||
typedef struct OSVR_EyeTracker2DReport {
|
||||
OSVR_ChannelCount sensor;
|
||||
OSVR_EyeTracker2DState state;
|
||||
} OSVR_EyeTracker2DReport;
|
||||
|
||||
/** @brief State for a blink event */
|
||||
typedef OSVR_ButtonState OSVR_EyeTrackerBlinkState;
|
||||
|
||||
/** @brief OSVR_EyeTrackerBlinkState value indicating an eyes blink had occurred
|
||||
*/
|
||||
#define OSVR_EYE_BLINK (1)
|
||||
|
||||
/** @brief OSVR_EyeTrackerBlinkState value indicating eyes are not blinking */
|
||||
#define OSVR_EYE_NO_BLINK (0)
|
||||
|
||||
/** @brief Report type for a blink event */
|
||||
typedef struct OSVR_EyeTrackerBlinkReport {
|
||||
OSVR_ChannelCount sensor;
|
||||
OSVR_EyeTrackerBlinkState state;
|
||||
} OSVR_EyeTrackerBlinkReport;
|
||||
|
||||
/** @brief Report type for an Imaging callback (forward declaration) */
|
||||
struct OSVR_ImagingReport;
|
||||
|
||||
/** @brief Type of Navigation Velocity state */
|
||||
typedef OSVR_Vec2 OSVR_NaviVelocityState;
|
||||
|
||||
/** @brief Type of Navigation Position state */
|
||||
typedef OSVR_Vec2 OSVR_NaviPositionState;
|
||||
|
||||
/** @brief Report type for an navigation velocity callback on a tracker
|
||||
* interface */
|
||||
typedef struct OSVR_NaviVelocityReport {
|
||||
OSVR_ChannelCount sensor;
|
||||
/** @brief The 2D vector in world coordinate system, in meters/second */
|
||||
OSVR_NaviVelocityState state;
|
||||
} OSVR_NaviVelocityReport;
|
||||
|
||||
/** @brief Report type for an navigation position callback on a tracker
|
||||
* interface */
|
||||
typedef struct OSVR_NaviPositionReport {
|
||||
OSVR_ChannelCount sensor;
|
||||
/** @brief The 2D vector in world coordinate system, in meters, relative to
|
||||
* starting position */
|
||||
OSVR_NaviPositionState state;
|
||||
} OSVR_NaviPositionReport;
|
||||
|
||||
/** @} */
|
||||
|
||||
/** @} */
|
||||
OSVR_EXTERN_C_END
|
||||
|
||||
#endif
|
||||
@@ -1,138 +0,0 @@
|
||||
/** @file
|
||||
@brief Automatically-generated export header - do not edit!
|
||||
|
||||
@date 2016
|
||||
|
||||
@author
|
||||
Sensics, Inc.
|
||||
<http://sensics.com/osvr>
|
||||
*/
|
||||
|
||||
// Copyright 2016 Sensics, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef OSVR_UTIL_EXPORT_H
|
||||
#define OSVR_UTIL_EXPORT_H
|
||||
|
||||
#ifdef OSVR_UTIL_STATIC_DEFINE
|
||||
# define OSVR_UTIL_EXPORT
|
||||
# define OSVR_UTIL_NO_EXPORT
|
||||
#endif
|
||||
|
||||
/* Per-compiler advance preventative definition */
|
||||
#if defined(__BORLANDC__) || defined(__CODEGEARC__) || defined(__HP_aCC) || \
|
||||
defined(__PGI) || defined(__WATCOMC__)
|
||||
/* Compilers that don't support deprecated, according to CMake. */
|
||||
# ifndef OSVR_UTIL_DEPRECATED
|
||||
# define OSVR_UTIL_DEPRECATED
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Check for attribute support */
|
||||
#if defined(__INTEL_COMPILER)
|
||||
/* Checking before GNUC because Intel implements GNU extensions,
|
||||
* so it chooses to define __GNUC__ as well. */
|
||||
# if __INTEL_COMPILER >= 1200
|
||||
/* Intel compiler 12.0 or newer can handle these attributes per CMake */
|
||||
# define OSVR_UTIL_EXPORT_HEADER_SUPPORTS_ATTRIBUTES
|
||||
# endif
|
||||
|
||||
#elif defined(__GNUC__)
|
||||
# if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
|
||||
/* GCC 4.2+ */
|
||||
# define OSVR_UTIL_EXPORT_HEADER_SUPPORTS_ATTRIBUTES
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Per-platform defines */
|
||||
#if defined(_MSC_VER)
|
||||
/* MSVC on Windows */
|
||||
|
||||
#ifndef OSVR_UTIL_EXPORT
|
||||
# ifdef osvrUtil_EXPORTS
|
||||
/* We are building this library */
|
||||
# define OSVR_UTIL_EXPORT __declspec(dllexport)
|
||||
# else
|
||||
/* We are using this library */
|
||||
# define OSVR_UTIL_EXPORT __declspec(dllimport)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef OSVR_UTIL_DEPRECATED
|
||||
# define OSVR_UTIL_DEPRECATED __declspec(deprecated)
|
||||
#endif
|
||||
|
||||
#elif defined(_WIN32) && defined(__GNUC__)
|
||||
/* GCC-compatible on Windows */
|
||||
|
||||
#ifndef OSVR_UTIL_EXPORT
|
||||
# ifdef osvrUtil_EXPORTS
|
||||
/* We are building this library */
|
||||
# define OSVR_UTIL_EXPORT __attribute__((dllexport))
|
||||
# else
|
||||
/* We are using this library */
|
||||
# define OSVR_UTIL_EXPORT __attribute__((dllimport))
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef OSVR_UTIL_DEPRECATED
|
||||
# define OSVR_UTIL_DEPRECATED __attribute__((__deprecated__))
|
||||
#endif
|
||||
|
||||
#elif defined(OSVR_UTIL_EXPORT_HEADER_SUPPORTS_ATTRIBUTES) || \
|
||||
(defined(__APPLE__) && defined(__MACH__))
|
||||
/* GCC4.2+ compatible (assuming something *nix-like) and Mac OS X */
|
||||
/* (The first macro is defined at the top of the file, if applicable) */
|
||||
/* see https://gcc.gnu.org/wiki/Visibility */
|
||||
|
||||
#ifndef OSVR_UTIL_EXPORT
|
||||
/* We are building/using this library */
|
||||
# define OSVR_UTIL_EXPORT __attribute__((visibility("default")))
|
||||
#endif
|
||||
|
||||
#ifndef OSVR_UTIL_NO_EXPORT
|
||||
# define OSVR_UTIL_NO_EXPORT __attribute__((visibility("hidden")))
|
||||
#endif
|
||||
|
||||
#ifndef OSVR_UTIL_DEPRECATED
|
||||
# define OSVR_UTIL_DEPRECATED __attribute__((__deprecated__))
|
||||
#endif
|
||||
|
||||
#endif
|
||||
/* End of platform ifdefs */
|
||||
|
||||
/* fallback def */
|
||||
#ifndef OSVR_UTIL_EXPORT
|
||||
# define OSVR_UTIL_EXPORT
|
||||
#endif
|
||||
|
||||
/* fallback def */
|
||||
#ifndef OSVR_UTIL_NO_EXPORT
|
||||
# define OSVR_UTIL_NO_EXPORT
|
||||
#endif
|
||||
|
||||
/* fallback def */
|
||||
#ifndef OSVR_UTIL_DEPRECATED_EXPORT
|
||||
# define OSVR_UTIL_DEPRECATED_EXPORT OSVR_UTIL_EXPORT OSVR_UTIL_DEPRECATED
|
||||
#endif
|
||||
|
||||
/* fallback def */
|
||||
#ifndef OSVR_UTIL_DEPRECATED_NO_EXPORT
|
||||
# define OSVR_UTIL_DEPRECATED_NO_EXPORT OSVR_UTIL_NO_EXPORT OSVR_UTIL_DEPRECATED
|
||||
#endif
|
||||
|
||||
/* Clean up after ourselves */
|
||||
#undef OSVR_UTIL_EXPORT_HEADER_SUPPORTS_ATTRIBUTES
|
||||
|
||||
#endif
|
||||
@@ -1,91 +0,0 @@
|
||||
/** @file
|
||||
@brief Header
|
||||
|
||||
Must be c-safe!
|
||||
|
||||
@date 2015
|
||||
|
||||
@author
|
||||
Sensics, Inc.
|
||||
<http://sensics.com/osvr>
|
||||
*/
|
||||
|
||||
/*
|
||||
// Copyright 2015 Sensics, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef INCLUDED_ImagingReportTypesC_h_GUID_746A7BF8_B92D_4585_CA72_DC5391DEDF24
|
||||
#define INCLUDED_ImagingReportTypesC_h_GUID_746A7BF8_B92D_4585_CA72_DC5391DEDF24
|
||||
|
||||
/* Internal Includes */
|
||||
#include <osvr/Util/APIBaseC.h>
|
||||
#include <osvr/Util/StdInt.h>
|
||||
#include <osvr/Util/ChannelCountC.h>
|
||||
|
||||
/* Library/third-party includes */
|
||||
/* none */
|
||||
|
||||
/* Standard includes */
|
||||
/* none */
|
||||
|
||||
OSVR_EXTERN_C_BEGIN
|
||||
|
||||
/** @addtogroup ClientKit
|
||||
@{
|
||||
*/
|
||||
typedef uint32_t OSVR_ImageDimension;
|
||||
typedef uint8_t OSVR_ImageChannels;
|
||||
typedef uint8_t OSVR_ImageDepth;
|
||||
|
||||
/** @brief Type for raw buffer access to image data */
|
||||
typedef unsigned char OSVR_ImageBufferElement;
|
||||
|
||||
typedef enum OSVR_ImagingValueType {
|
||||
OSVR_IVT_UNSIGNED_INT = 0,
|
||||
OSVR_IVT_SIGNED_INT = 1,
|
||||
OSVR_IVT_FLOATING_POINT = 2
|
||||
} OSVR_ImagingValueType;
|
||||
|
||||
typedef struct OSVR_ImagingMetadata {
|
||||
/** @brief height in pixels */
|
||||
OSVR_ImageDimension height;
|
||||
/** @brief width in pixels */
|
||||
OSVR_ImageDimension width;
|
||||
/** @brief number of channels of data for each pixel */
|
||||
OSVR_ImageChannels channels;
|
||||
/** @brief the depth (size) in bytes of each channel - valid values are 1,
|
||||
* 2, 4, and 8 */
|
||||
OSVR_ImageDepth depth;
|
||||
/** @brief Whether values are unsigned ints, signed ints, or floating point
|
||||
*/
|
||||
OSVR_ImagingValueType type;
|
||||
|
||||
} OSVR_ImagingMetadata;
|
||||
|
||||
typedef struct OSVR_ImagingState {
|
||||
OSVR_ImagingMetadata metadata;
|
||||
OSVR_ImageBufferElement *data;
|
||||
} OSVR_ImagingState;
|
||||
|
||||
typedef struct OSVR_ImagingReport {
|
||||
OSVR_ChannelCount sensor;
|
||||
OSVR_ImagingState state;
|
||||
} OSVR_ImagingReport;
|
||||
|
||||
/** @} */
|
||||
|
||||
OSVR_EXTERN_C_END
|
||||
|
||||
#endif
|
||||
@@ -1,190 +0,0 @@
|
||||
/** @file
|
||||
@brief Header
|
||||
|
||||
Must be c-safe!
|
||||
|
||||
@date 2015
|
||||
|
||||
@author
|
||||
Sensics, Inc.
|
||||
<http://sensics.com/osvr>
|
||||
*/
|
||||
|
||||
/*
|
||||
// Copyright 2015 Sensics, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef INCLUDED_MatrixConventionsC_h_GUID_6FC7A4C6_E6C5_4A96_1C28_C3D21B909681
|
||||
#define INCLUDED_MatrixConventionsC_h_GUID_6FC7A4C6_E6C5_4A96_1C28_C3D21B909681
|
||||
|
||||
/* Internal Includes */
|
||||
#include <osvr/Util/Export.h>
|
||||
#include <osvr/Util/APIBaseC.h>
|
||||
#include <osvr/Util/StdInt.h>
|
||||
#include <osvr/Util/Pose3C.h>
|
||||
#include <osvr/Util/ReturnCodesC.h>
|
||||
|
||||
/* Library/third-party includes */
|
||||
/* none */
|
||||
|
||||
/* Standard includes */
|
||||
/* none */
|
||||
|
||||
OSVR_EXTERN_C_BEGIN
|
||||
|
||||
/** @defgroup MatrixConvention Matrix conventions and bit flags
|
||||
@ingroup UtilMath
|
||||
*/
|
||||
|
||||
/** @brief Type for passing matrix convention flags.
|
||||
@ingroup MatrixConvention
|
||||
*/
|
||||
typedef uint16_t OSVR_MatrixConventions;
|
||||
|
||||
#ifndef OSVR_DOXYGEN_EXTERNAL
|
||||
/** @brief Bitmasks for testing matrix conventions.
|
||||
@ingroup MatrixConvention
|
||||
*/
|
||||
typedef enum OSVR_MatrixMasks {
|
||||
OSVR_MATRIX_MASK_ROWMAJOR = 0x1,
|
||||
OSVR_MATRIX_MASK_ROWVECTORS = 0x2,
|
||||
OSVR_MATRIX_MASK_LHINPUT = 0x4,
|
||||
OSVR_MATRIX_MASK_UNSIGNEDZ = 0x8
|
||||
} OSVR_MatrixMasks;
|
||||
#endif
|
||||
|
||||
/** @defgroup MatrixFlags Matrix flags
|
||||
@ingroup MatrixConvention
|
||||
|
||||
Bit flags for specifying matrix options. Only one option may be specified
|
||||
per enum, with all the specified options combined with bitwise-or `|`.
|
||||
|
||||
Most methods that take matrix flags only obey ::OSVR_MatrixOrderingFlags and
|
||||
::OSVR_MatrixVectorFlags - the flags that affect memory order. The remaining
|
||||
flags are for use with projection matrix generation API methods.
|
||||
|
||||
@{
|
||||
*/
|
||||
/** @brief Flag bit controlling output memory order */
|
||||
typedef enum OSVR_MatrixOrderingFlags {
|
||||
/** @brief Column-major memory order (default) */
|
||||
OSVR_MATRIX_COLMAJOR = 0x0,
|
||||
/** @brief Row-major memory order */
|
||||
OSVR_MATRIX_ROWMAJOR = OSVR_MATRIX_MASK_ROWMAJOR
|
||||
} OSVR_MatrixOrderingFlags;
|
||||
|
||||
/** @brief Flag bit controlling expected input to matrices.
|
||||
(Related to ::OSVR_MatrixOrderingFlags - setting one to non-default results
|
||||
in an output change, but setting both to non-default results in effectively
|
||||
no change in the output. If this blows your mind, just ignore this aside and
|
||||
carry on.)
|
||||
*/
|
||||
typedef enum OSVR_MatrixVectorFlags {
|
||||
/** @brief Matrix transforms column vectors (default) */
|
||||
OSVR_MATRIX_COLVECTORS = 0x0,
|
||||
/** @brief Matrix transforms row vectors */
|
||||
OSVR_MATRIX_ROWVECTORS = OSVR_MATRIX_MASK_ROWVECTORS
|
||||
} OSVR_MatrixVectorFlags;
|
||||
|
||||
/** @brief Flag bit to indicate coordinate system input to projection matrix */
|
||||
typedef enum OSVR_ProjectionMatrixInputFlags {
|
||||
/** @brief Matrix takes vectors from a right-handed coordinate system
|
||||
(default) */
|
||||
OSVR_MATRIX_RHINPUT = 0x0,
|
||||
/** @brief Matrix takes vectors from a left-handed coordinate system */
|
||||
OSVR_MATRIX_LHINPUT = OSVR_MATRIX_MASK_LHINPUT
|
||||
|
||||
} OSVR_ProjectionMatrixInputFlags;
|
||||
|
||||
/** @brief Flag bit to indicate the desired post-projection Z value convention
|
||||
*/
|
||||
typedef enum OSVR_ProjectionMatrixZFlags {
|
||||
/** @brief Matrix maps the near and far planes to signed Z values (in the
|
||||
range [-1, 1]) (default)*/
|
||||
OSVR_MATRIX_SIGNEDZ = 0x0,
|
||||
/** @brief Matrix maps the near and far planes to unsigned Z values (in the
|
||||
range [0, 1]) */
|
||||
OSVR_MATRIX_UNSIGNEDZ = OSVR_MATRIX_MASK_UNSIGNEDZ
|
||||
} OSVR_ProjectionMatrixZFlags;
|
||||
/** @} */ /* end of matrix flags group */
|
||||
|
||||
enum {
|
||||
/** @brief Constant for the number of elements in the matrices we use - 4x4.
|
||||
@ingroup MatrixConvention
|
||||
*/
|
||||
OSVR_MATRIX_SIZE = 16
|
||||
};
|
||||
|
||||
/** @addtogroup UtilMath
|
||||
@{
|
||||
*/
|
||||
/** @brief Set a matrix of doubles based on a Pose3.
|
||||
@param pose The Pose3 to convert
|
||||
@param flags Memory ordering flag - see @ref MatrixFlags
|
||||
@param[out] mat an array of 16 doubles
|
||||
*/
|
||||
OSVR_UTIL_EXPORT OSVR_ReturnCode osvrPose3ToMatrixd(
|
||||
OSVR_Pose3 const *pose, OSVR_MatrixConventions flags, double *mat);
|
||||
|
||||
/** @brief Set a matrix of floats based on a Pose3.
|
||||
@param pose The Pose3 to convert
|
||||
@param flags Memory ordering flag - see @ref MatrixFlags
|
||||
@param[out] mat an array of 16 floats
|
||||
*/
|
||||
OSVR_UTIL_EXPORT OSVR_ReturnCode osvrPose3ToMatrixf(
|
||||
OSVR_Pose3 const *pose, OSVR_MatrixConventions flags, float *mat);
|
||||
/** @} */
|
||||
|
||||
OSVR_EXTERN_C_END
|
||||
|
||||
#ifdef __cplusplus
|
||||
/** @brief Set a matrix based on a Pose3. (C++-only overload - detecting scalar
|
||||
* type) */
|
||||
inline OSVR_ReturnCode osvrPose3ToMatrix(OSVR_Pose3 const *pose,
|
||||
OSVR_MatrixConventions flags,
|
||||
double *mat) {
|
||||
return osvrPose3ToMatrixd(pose, flags, mat);
|
||||
}
|
||||
|
||||
/** @brief Set a matrix based on a Pose3. (C++-only overload - detecting scalar
|
||||
* type) */
|
||||
inline OSVR_ReturnCode osvrPose3ToMatrix(OSVR_Pose3 const *pose,
|
||||
OSVR_MatrixConventions flags,
|
||||
float *mat) {
|
||||
return osvrPose3ToMatrixf(pose, flags, mat);
|
||||
}
|
||||
|
||||
/** @brief Set a matrix based on a Pose3. (C++-only overload - detects scalar
|
||||
* and takes array rather than pointer) */
|
||||
template <typename Scalar>
|
||||
inline OSVR_ReturnCode osvrPose3ToMatrix(OSVR_Pose3 const *pose,
|
||||
OSVR_MatrixConventions flags,
|
||||
Scalar mat[OSVR_MATRIX_SIZE]) {
|
||||
return osvrPose3ToMatrix(pose, flags, &(mat[0]));
|
||||
}
|
||||
/** @brief Set a matrix based on a Pose3. (C++-only overload - detects scalar,
|
||||
* takes array, takes pose by reference) */
|
||||
template <typename Scalar>
|
||||
inline OSVR_ReturnCode osvrPose3ToMatrix(OSVR_Pose3 const &pose,
|
||||
OSVR_MatrixConventions flags,
|
||||
Scalar mat[OSVR_MATRIX_SIZE]) {
|
||||
return osvrPose3ToMatrix(&pose, flags, &(mat[0]));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
#endif
|
||||
@@ -1,88 +0,0 @@
|
||||
/** @file
|
||||
@brief Auto-configured header
|
||||
|
||||
If this filename ends in `.h`, don't edit it: your edits will
|
||||
be lost next time this file is regenerated!
|
||||
|
||||
Must be c-safe!
|
||||
|
||||
@date 2014
|
||||
|
||||
@author
|
||||
Sensics, Inc.
|
||||
<http://sensics.com/osvr>
|
||||
*/
|
||||
|
||||
/*
|
||||
// Copyright 2014 Sensics, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef INCLUDED_PlatformConfig_h_GUID_0D10E644_8114_4294_A839_699F39E1F0E0
|
||||
#define INCLUDED_PlatformConfig_h_GUID_0D10E644_8114_4294_A839_699F39E1F0E0
|
||||
|
||||
/** @def OSVR_HAVE_STRUCT_TIMEVAL_IN_WINSOCK2_H
|
||||
@brief Does the system have struct timeval in <winsock2.h>?
|
||||
*/
|
||||
#define OSVR_HAVE_STRUCT_TIMEVAL_IN_WINSOCK2_H
|
||||
|
||||
/** @def OSVR_HAVE_STRUCT_TIMEVAL_IN_SYS_TIME_H
|
||||
@brief Does the system have struct timeval in <sys/time.h>?
|
||||
*/
|
||||
|
||||
/*
|
||||
MinGW and similar environments have both winsock and sys/time.h, so
|
||||
we hide this define for disambiguation at the top level.
|
||||
*/
|
||||
#ifndef OSVR_HAVE_STRUCT_TIMEVAL_IN_WINSOCK2_H
|
||||
/* #undef OSVR_HAVE_STRUCT_TIMEVAL_IN_SYS_TIME_H */
|
||||
#endif
|
||||
|
||||
#if defined(OSVR_HAVE_STRUCT_TIMEVAL_IN_SYS_TIME_H) || \
|
||||
defined(OSVR_HAVE_STRUCT_TIMEVAL_IN_WINSOCK2_H)
|
||||
#define OSVR_HAVE_STRUCT_TIMEVAL
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Platform-specific variables.
|
||||
*
|
||||
* Prefer testing for specific compiler or platform features instead of relying
|
||||
* on these variables.
|
||||
*
|
||||
*/
|
||||
//@{
|
||||
/* #undef OSVR_AIX */
|
||||
/* #undef OSVR_ANDROID */
|
||||
/* #undef OSVR_BSDOS */
|
||||
/* #undef OSVR_FREEBSD */
|
||||
/* #undef OSVR_HPUX */
|
||||
/* #undef OSVR_IRIX */
|
||||
/* #undef OSVR_LINUX */
|
||||
/* #undef OSVR_KFREEBSD */
|
||||
/* #undef OSVR_NETBSD */
|
||||
/* #undef OSVR_OPENBSD */
|
||||
/* #undef OSVR_OFS1 */
|
||||
/* #undef OSVR_SCO_SV */
|
||||
/* #undef OSVR_UNIXWARE */
|
||||
/* #undef OSVR_XENIX */
|
||||
/* #undef OSVR_SUNOS */
|
||||
/* #undef OSVR_TRU64 */
|
||||
/* #undef OSVR_ULTRIX */
|
||||
/* #undef OSVR_CYGWIN */
|
||||
/* #undef OSVR_MACOSX */
|
||||
#define OSVR_WINDOWS
|
||||
//@}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,70 +0,0 @@
|
||||
/** @file
|
||||
@brief Header
|
||||
|
||||
Must be c-safe!
|
||||
|
||||
@date 2014
|
||||
|
||||
@author
|
||||
Sensics, Inc.
|
||||
<http://sensics.com/osvr>
|
||||
*/
|
||||
|
||||
/*
|
||||
// Copyright 2014 Sensics, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef INCLUDED_Pose3C_h_GUID_066CFCE2_229C_4194_5D2B_2602CCD5C439
|
||||
#define INCLUDED_Pose3C_h_GUID_066CFCE2_229C_4194_5D2B_2602CCD5C439
|
||||
|
||||
/* Internal Includes */
|
||||
|
||||
/* Internal Includes */
|
||||
#include <osvr/Util/APIBaseC.h>
|
||||
#include <osvr/Util/Vec3C.h>
|
||||
#include <osvr/Util/QuaternionC.h>
|
||||
|
||||
/* Library/third-party includes */
|
||||
/* none */
|
||||
|
||||
/* Standard includes */
|
||||
/* none */
|
||||
|
||||
OSVR_EXTERN_C_BEGIN
|
||||
|
||||
/** @addtogroup UtilMath
|
||||
@{
|
||||
*/
|
||||
|
||||
/** @brief A structure defining a 3D (6DOF) rigid body pose: translation and
|
||||
rotation.
|
||||
*/
|
||||
typedef struct OSVR_Pose3 {
|
||||
/** @brief Position vector */
|
||||
OSVR_Vec3 translation;
|
||||
/** @brief Orientation as a unit quaternion */
|
||||
OSVR_Quaternion rotation;
|
||||
} OSVR_Pose3;
|
||||
|
||||
/** @brief Set a pose to identity */
|
||||
OSVR_INLINE void osvrPose3SetIdentity(OSVR_Pose3 *pose) {
|
||||
osvrQuatSetIdentity(&(pose->rotation));
|
||||
osvrVec3Zero(&(pose->translation));
|
||||
}
|
||||
/** @} */
|
||||
|
||||
OSVR_EXTERN_C_END
|
||||
|
||||
#endif
|
||||
@@ -1,92 +0,0 @@
|
||||
/** @file
|
||||
@brief Header
|
||||
|
||||
Must be c-safe!
|
||||
|
||||
@date 2014
|
||||
|
||||
@author
|
||||
Sensics, Inc.
|
||||
<http://sensics.com/osvr>
|
||||
*/
|
||||
|
||||
/*
|
||||
// Copyright 2014 Sensics, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef INCLUDED_QuaternionC_h_GUID_1470A5FE_8209_41A6_C19E_46077FDF9C66
|
||||
#define INCLUDED_QuaternionC_h_GUID_1470A5FE_8209_41A6_C19E_46077FDF9C66
|
||||
|
||||
/* Internal Includes */
|
||||
#include <osvr/Util/APIBaseC.h>
|
||||
|
||||
/* Library/third-party includes */
|
||||
/* none */
|
||||
|
||||
/* Standard includes */
|
||||
/* none */
|
||||
|
||||
OSVR_EXTERN_C_BEGIN
|
||||
|
||||
/** @addtogroup UtilMath
|
||||
@{
|
||||
*/
|
||||
/** @brief A structure defining a quaternion, often a unit quaternion
|
||||
* representing 3D rotation.
|
||||
*/
|
||||
typedef struct OSVR_Quaternion {
|
||||
/** @brief Internal data - direct access not recommended */
|
||||
double data[4];
|
||||
} OSVR_Quaternion;
|
||||
|
||||
#define OSVR_QUAT_MEMBER(COMPONENT, INDEX) \
|
||||
/** @brief Accessor for quaternion component COMPONENT */ \
|
||||
OSVR_INLINE double osvrQuatGet##COMPONENT(OSVR_Quaternion const *q) { \
|
||||
return q->data[INDEX]; \
|
||||
} \
|
||||
/** @brief Setter for quaternion component COMPONENT */ \
|
||||
OSVR_INLINE void osvrQuatSet##COMPONENT(OSVR_Quaternion *q, double val) { \
|
||||
q->data[INDEX] = val; \
|
||||
}
|
||||
|
||||
OSVR_QUAT_MEMBER(W, 0)
|
||||
OSVR_QUAT_MEMBER(X, 1)
|
||||
OSVR_QUAT_MEMBER(Y, 2)
|
||||
OSVR_QUAT_MEMBER(Z, 3)
|
||||
|
||||
#undef OSVR_QUAT_MEMBER
|
||||
|
||||
/** @brief Set a quaternion to the identity rotation */
|
||||
OSVR_INLINE void osvrQuatSetIdentity(OSVR_Quaternion *q) {
|
||||
osvrQuatSetW(q, 1);
|
||||
osvrQuatSetX(q, 0);
|
||||
osvrQuatSetY(q, 0);
|
||||
osvrQuatSetZ(q, 0);
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
||||
OSVR_EXTERN_C_END
|
||||
|
||||
#ifdef __cplusplus
|
||||
template <typename StreamType>
|
||||
inline StreamType &operator<<(StreamType &os, OSVR_Quaternion const &quat) {
|
||||
os << "(" << osvrQuatGetW(&quat) << ", (" << osvrQuatGetX(&quat) << ", "
|
||||
<< osvrQuatGetY(&quat) << ", " << osvrQuatGetZ(&quat) << "))";
|
||||
return os;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,84 +0,0 @@
|
||||
/** @file
|
||||
@brief Header
|
||||
|
||||
Must be c-safe!
|
||||
|
||||
@date 2014
|
||||
|
||||
@author
|
||||
Sensics, Inc.
|
||||
<http://sensics.com/osvr>
|
||||
*/
|
||||
|
||||
/*
|
||||
// Copyright 2014 Sensics, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef INCLUDED_QuatlibInteropC_h_GUID_85D92019_F0CC_419C_5F6D_F5A3134AA5D4
|
||||
#define INCLUDED_QuatlibInteropC_h_GUID_85D92019_F0CC_419C_5F6D_F5A3134AA5D4
|
||||
|
||||
/* Internal Includes */
|
||||
#include <osvr/Util/APIBaseC.h>
|
||||
#include <osvr/Util/Pose3C.h>
|
||||
|
||||
/* Library/third-party includes */
|
||||
#include <quat.h>
|
||||
|
||||
/* Standard includes */
|
||||
#include <string.h>
|
||||
|
||||
OSVR_EXTERN_C_BEGIN
|
||||
|
||||
/** @addtogroup UtilMath
|
||||
@{
|
||||
*/
|
||||
OSVR_INLINE void osvrQuatToQuatlib(q_type dest, OSVR_Quaternion const *src) {
|
||||
dest[Q_W] = osvrQuatGetW(src);
|
||||
dest[Q_X] = osvrQuatGetX(src);
|
||||
dest[Q_Y] = osvrQuatGetY(src);
|
||||
dest[Q_Z] = osvrQuatGetZ(src);
|
||||
}
|
||||
|
||||
OSVR_INLINE void osvrQuatFromQuatlib(OSVR_Quaternion *dest, q_type const src) {
|
||||
osvrQuatSetW(dest, src[Q_W]);
|
||||
osvrQuatSetX(dest, src[Q_X]);
|
||||
osvrQuatSetY(dest, src[Q_Y]);
|
||||
osvrQuatSetZ(dest, src[Q_Z]);
|
||||
}
|
||||
|
||||
OSVR_INLINE void osvrVec3ToQuatlib(q_vec_type dest, OSVR_Vec3 const *src) {
|
||||
memcpy((void *)(dest), (void const *)(src->data), sizeof(double) * 3);
|
||||
}
|
||||
|
||||
OSVR_INLINE void osvrVec3FromQuatlib(OSVR_Vec3 *dest, q_vec_type const src) {
|
||||
memcpy((void *)(dest->data), (void const *)(src), sizeof(double) * 3);
|
||||
}
|
||||
|
||||
OSVR_INLINE void osvrPose3ToQuatlib(q_xyz_quat_type *dest,
|
||||
OSVR_Pose3 const *src) {
|
||||
osvrVec3ToQuatlib(dest->xyz, &(src->translation));
|
||||
osvrQuatToQuatlib(dest->quat, &(src->rotation));
|
||||
}
|
||||
|
||||
OSVR_INLINE void osvrPose3FromQuatlib(OSVR_Pose3 *dest,
|
||||
q_xyz_quat_type const *src) {
|
||||
osvrVec3FromQuatlib(&(dest->translation), src->xyz);
|
||||
osvrQuatFromQuatlib(&(dest->rotation), src->quat);
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
||||
OSVR_EXTERN_C_END
|
||||
#endif
|
||||
@@ -1,62 +0,0 @@
|
||||
/** @file
|
||||
@brief Header
|
||||
|
||||
Must be c-safe!
|
||||
|
||||
@date 2015
|
||||
|
||||
@author
|
||||
Sensics, Inc.
|
||||
<http://sensics.com/osvr>
|
||||
*/
|
||||
|
||||
/*
|
||||
// Copyright 2015 Sensics, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef INCLUDED_RadialDistortionParametersC_h_GUID_925BCEB1_BACA_4DA7_5133_FFF560C72EBD
|
||||
#define INCLUDED_RadialDistortionParametersC_h_GUID_925BCEB1_BACA_4DA7_5133_FFF560C72EBD
|
||||
|
||||
/* Internal Includes */
|
||||
#include <osvr/Util/APIBaseC.h>
|
||||
#include <osvr/Util/Vec2C.h>
|
||||
#include <osvr/Util/Vec3C.h>
|
||||
|
||||
/* Library/third-party includes */
|
||||
/* none */
|
||||
|
||||
/* Standard includes */
|
||||
/* none */
|
||||
|
||||
OSVR_EXTERN_C_BEGIN
|
||||
|
||||
/** @addtogroup UtilMath
|
||||
@{
|
||||
*/
|
||||
|
||||
/** @brief Parameters for a per-color-component radial distortion shader
|
||||
*/
|
||||
typedef struct OSVR_RadialDistortionParameters {
|
||||
/** @brief Vector of K1 coefficients for the R, G, B channels*/
|
||||
OSVR_Vec3 k1;
|
||||
/** @brief Center of projection for the radial distortion, relative to the
|
||||
bounds of this surface.
|
||||
*/
|
||||
OSVR_Vec2 centerOfProjection;
|
||||
} OSVR_RadialDistortionParameters;
|
||||
|
||||
OSVR_EXTERN_C_END
|
||||
|
||||
#endif
|
||||
@@ -1,134 +0,0 @@
|
||||
/** @file
|
||||
@brief Header with integer types for Viewer, Eye, and Surface
|
||||
counts/indices, as well as viewport information.
|
||||
|
||||
Must be c-safe!
|
||||
|
||||
@date 2015
|
||||
|
||||
@author
|
||||
Sensics, Inc.
|
||||
<http://sensics.com/osvr>
|
||||
*/
|
||||
|
||||
/*
|
||||
// Copyright 2015 Sensics, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef INCLUDED_RenderingTypesC_h_GUID_6689A6CA_76AC_48AC_A0D0_2902BC95AC35
|
||||
#define INCLUDED_RenderingTypesC_h_GUID_6689A6CA_76AC_48AC_A0D0_2902BC95AC35
|
||||
|
||||
/* Internal Includes */
|
||||
#include <osvr/Util/StdInt.h>
|
||||
#include <osvr/Util/APIBaseC.h>
|
||||
|
||||
/* Library/third-party includes */
|
||||
/* none */
|
||||
|
||||
/* Standard includes */
|
||||
/* none */
|
||||
|
||||
OSVR_EXTERN_C_BEGIN
|
||||
|
||||
/** @addtogroup PluginKit
|
||||
@{
|
||||
*/
|
||||
|
||||
/** @brief A count or index for a display input in a display config.
|
||||
*/
|
||||
typedef uint8_t OSVR_DisplayInputCount;
|
||||
|
||||
/** @brief The integer type used in specification of size or location of a
|
||||
display input, in pixels.
|
||||
*/
|
||||
typedef int32_t OSVR_DisplayDimension;
|
||||
|
||||
/** @brief The integer type specifying a number of viewers in a system.
|
||||
|
||||
A "head" is a viewer (though not all viewers are necessarily heads).
|
||||
|
||||
The count is output from osvrClientGetNumViewers().
|
||||
|
||||
When used as an ID/index, it is zero-based, so values range from 0 to (count
|
||||
- 1) inclusive.
|
||||
|
||||
The most frequent count is 1, though higher values are theoretically
|
||||
possible. If you do not handle higher values, do still check and alert the
|
||||
user if their system reports a higher number, as your application may not
|
||||
behave as the user expects.
|
||||
*/
|
||||
typedef uint32_t OSVR_ViewerCount;
|
||||
|
||||
/** @brief The integer type specifying the number of eyes (viewpoints) of a
|
||||
viewer.
|
||||
|
||||
The count for a given viewer is output from osvrClientGetNumEyesForViewer().
|
||||
|
||||
When used as an ID/index, it is zero-based,so values range from 0 to (count
|
||||
- 1) inclusive, for a given viewer.
|
||||
|
||||
Use as an ID/index is not meaningful except in conjunction with the ID of
|
||||
the corresponding viewer. (that is, there is no overall "eye 0", but "viewer
|
||||
0, eye 0" is meaningful.)
|
||||
|
||||
In practice, the most frequent counts are 1 (e.g. mono) and 2 (e.g. stereo),
|
||||
and for example the latter results in eyes with ID 0 and 1 for the viewer.
|
||||
There is no innate or consistent semantics/meaning ("left" or "right") to
|
||||
indices guaranteed at this time, and applications should not try to infer
|
||||
any.
|
||||
*/
|
||||
typedef uint8_t OSVR_EyeCount;
|
||||
|
||||
/** @brief The integer type specifying the number of surfaces seen by a viewer's
|
||||
eye.
|
||||
|
||||
The count for a given viewer and eye is output from
|
||||
osvrClientGetNumSurfacesForViewerEye(). Note that the count is not
|
||||
necessarily equal between eyes of a viewer.
|
||||
|
||||
When used as an ID/index, it is zero-based, so values range from 0 to (count
|
||||
- 1) inclusive, for a given viewer and eye.
|
||||
|
||||
Use as an ID/index is not meaningful except in conjunction with the IDs of
|
||||
the corresponding viewer and eye. (that is, there is no overall "surface 0",
|
||||
but "viewer 0, eye 0, surface 0" is meaningful.)
|
||||
*/
|
||||
typedef uint32_t OSVR_SurfaceCount;
|
||||
|
||||
/** @brief The integer type used in specification of size or location of a
|
||||
viewport.
|
||||
*/
|
||||
typedef int32_t OSVR_ViewportDimension;
|
||||
|
||||
/** @brief The integer type used to indicate relative priorities of a display
|
||||
distortion strategy. Negative values are defined to mean that strategy is
|
||||
unavailable.
|
||||
|
||||
@sa OSVR_DISTORTION_PRIORITY_UNAVAILABLE
|
||||
*/
|
||||
typedef int32_t OSVR_DistortionPriority;
|
||||
|
||||
/** @brief The constant to return as an OSVR_DistortionPriority if a given
|
||||
strategy is not available for a surface.
|
||||
|
||||
@sa OSVR_DistortionPriority
|
||||
*/
|
||||
#define OSVR_DISTORTION_PRIORITY_UNAVAILABLE (-1)
|
||||
|
||||
/** @} */
|
||||
|
||||
OSVR_EXTERN_C_END
|
||||
|
||||
#endif
|
||||
@@ -1,57 +0,0 @@
|
||||
/** @file
|
||||
@brief Header declaring a type and values for simple C return codes.
|
||||
|
||||
Must be c-safe!
|
||||
|
||||
@date 2014
|
||||
|
||||
@author
|
||||
Sensics, Inc.
|
||||
<http://sensics.com/osvr>
|
||||
*/
|
||||
|
||||
/*
|
||||
// Copyright 2014 Sensics, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef INCLUDED_ReturnCodesC_h_GUID_C81A2FDE_E5BB_4AAA_70A4_C616DD7C141A
|
||||
#define INCLUDED_ReturnCodesC_h_GUID_C81A2FDE_E5BB_4AAA_70A4_C616DD7C141A
|
||||
|
||||
/* Internal Includes */
|
||||
#include <osvr/Util/APIBaseC.h>
|
||||
#include <osvr/Util/AnnotationMacrosC.h>
|
||||
|
||||
OSVR_EXTERN_C_BEGIN
|
||||
|
||||
/** @addtogroup PluginKit
|
||||
@{
|
||||
*/
|
||||
/** @name Return Codes
|
||||
@{
|
||||
*/
|
||||
/** @brief The "success" value for an OSVR_ReturnCode */
|
||||
#define OSVR_RETURN_SUCCESS (0)
|
||||
/** @brief The "failure" value for an OSVR_ReturnCode */
|
||||
#define OSVR_RETURN_FAILURE (1)
|
||||
/** @brief Return type from C API OSVR functions. */
|
||||
typedef OSVR_RETURN_SUCCESS_CONDITION(
|
||||
return == OSVR_RETURN_SUCCESS) char OSVR_ReturnCode;
|
||||
/** @} */
|
||||
|
||||
/** @} */ /* end of group */
|
||||
|
||||
OSVR_EXTERN_C_END
|
||||
|
||||
#endif
|
||||
@@ -1,42 +0,0 @@
|
||||
/** @file
|
||||
@brief Header wrapping the C99 standard `stdint` header.
|
||||
|
||||
Must be c-safe!
|
||||
|
||||
@date 2014
|
||||
|
||||
@author
|
||||
Sensics, Inc.
|
||||
<http://sensics.com/osvr>
|
||||
*/
|
||||
|
||||
/*
|
||||
// Copyright 2014 Sensics, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef INCLUDED_StdInt_h_GUID_C1AAF35C_C704_4DB7_14AC_615730C4619B
|
||||
#define INCLUDED_StdInt_h_GUID_C1AAF35C_C704_4DB7_14AC_615730C4619B
|
||||
|
||||
/* IWYU pragma: begin_exports */
|
||||
|
||||
#if !defined(_MSC_VER) || (defined(_MSC_VER) && _MSC_VER >= 1600)
|
||||
#include <stdint.h>
|
||||
#else
|
||||
#include "MSStdIntC.h"
|
||||
#endif
|
||||
|
||||
/* IWYU pragma: end_exports */
|
||||
|
||||
#endif
|
||||
@@ -1,271 +0,0 @@
|
||||
/** @file
|
||||
@brief Header defining a dependency-free, cross-platform substitute for
|
||||
struct timeval
|
||||
|
||||
Must be c-safe!
|
||||
|
||||
@date 2014
|
||||
|
||||
@author
|
||||
Sensics, Inc.
|
||||
<http://sensics.com/osvr>
|
||||
*/
|
||||
|
||||
/*
|
||||
// Copyright 2014 Sensics, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef INCLUDED_TimeValueC_h_GUID_A02C6917_124D_4CB3_E63E_07F2DA7144E9
|
||||
#define INCLUDED_TimeValueC_h_GUID_A02C6917_124D_4CB3_E63E_07F2DA7144E9
|
||||
|
||||
/* Internal Includes */
|
||||
#include <osvr/Util/Export.h>
|
||||
#include <osvr/Util/APIBaseC.h>
|
||||
#include <osvr/Util/AnnotationMacrosC.h>
|
||||
#include <osvr/Util/PlatformConfig.h>
|
||||
#include <osvr/Util/StdInt.h>
|
||||
#include <osvr/Util/BoolC.h>
|
||||
|
||||
/* Library/third-party includes */
|
||||
/* none */
|
||||
|
||||
/* Standard includes */
|
||||
/* none */
|
||||
|
||||
OSVR_EXTERN_C_BEGIN
|
||||
|
||||
/** @defgroup UtilTime Timestamp interaction
|
||||
@ingroup Util
|
||||
|
||||
This provides a level of interoperability with struct timeval on systems
|
||||
with that facility. It provides a neutral representation with sufficiently
|
||||
large types.
|
||||
|
||||
For C++ code, use of std::chrono or boost::chrono instead is recommended.
|
||||
|
||||
Note that these time values may not necessarily correlate between processes
|
||||
so should not be used to estimate or measure latency, etc.
|
||||
|
||||
@{
|
||||
*/
|
||||
|
||||
/** @brief The signed integer type storing the seconds in a struct
|
||||
OSVR_TimeValue */
|
||||
typedef int64_t OSVR_TimeValue_Seconds;
|
||||
/** @brief The signed integer type storing the microseconds in a struct
|
||||
OSVR_TimeValue */
|
||||
typedef int32_t OSVR_TimeValue_Microseconds;
|
||||
|
||||
/** @brief Standardized, portable parallel to struct timeval for representing
|
||||
both absolute times and time intervals.
|
||||
|
||||
Where interpreted as an absolute time, its meaning is to be considered the
|
||||
same as that of the POSIX struct timeval:
|
||||
time since 00:00 Coordinated Universal Time (UTC), January 1, 1970.
|
||||
|
||||
For best results, please keep normalized. Output of all functions here
|
||||
is normalized.
|
||||
*/
|
||||
typedef struct OSVR_TimeValue {
|
||||
/** @brief Seconds portion of the time value. */
|
||||
OSVR_TimeValue_Seconds seconds;
|
||||
/** @brief Microseconds portion of the time value. */
|
||||
OSVR_TimeValue_Microseconds microseconds;
|
||||
} OSVR_TimeValue;
|
||||
|
||||
#ifdef OSVR_HAVE_STRUCT_TIMEVAL
|
||||
/** @brief Gets the current time in the TimeValue. Parallel to gettimeofday. */
|
||||
OSVR_UTIL_EXPORT void osvrTimeValueGetNow(OSVR_OUT OSVR_TimeValue *dest)
|
||||
OSVR_FUNC_NONNULL((1));
|
||||
|
||||
struct timeval; /* forward declaration */
|
||||
|
||||
/** @brief Converts from a TimeValue struct to your system's struct timeval.
|
||||
|
||||
@param dest Pointer to an empty struct timeval for your platform.
|
||||
@param src A pointer to an OSVR_TimeValue you'd like to convert from.
|
||||
|
||||
If either parameter is NULL, the function will return without doing
|
||||
anything.
|
||||
*/
|
||||
OSVR_UTIL_EXPORT void
|
||||
osvrTimeValueToStructTimeval(OSVR_OUT struct timeval *dest,
|
||||
OSVR_IN_PTR const OSVR_TimeValue *src)
|
||||
OSVR_FUNC_NONNULL((1, 2));
|
||||
|
||||
/** @brief Converts from a TimeValue struct to your system's struct timeval.
|
||||
@param dest An OSVR_TimeValue destination pointer.
|
||||
@param src Pointer to a struct timeval you'd like to convert from.
|
||||
|
||||
The result is normalized.
|
||||
|
||||
If either parameter is NULL, the function will return without doing
|
||||
anything.
|
||||
*/
|
||||
OSVR_UTIL_EXPORT void
|
||||
osvrStructTimevalToTimeValue(OSVR_OUT OSVR_TimeValue *dest,
|
||||
OSVR_IN_PTR const struct timeval *src)
|
||||
OSVR_FUNC_NONNULL((1, 2));
|
||||
#endif
|
||||
|
||||
/** @brief "Normalizes" a time value so that the absolute number of microseconds
|
||||
is less than 1,000,000, and that the sign of both components is the same.
|
||||
|
||||
@param tv Address of a struct TimeValue to normalize in place.
|
||||
|
||||
If the given pointer is NULL, this function returns without doing anything.
|
||||
*/
|
||||
OSVR_UTIL_EXPORT void osvrTimeValueNormalize(OSVR_INOUT_PTR OSVR_TimeValue *tv)
|
||||
OSVR_FUNC_NONNULL((1));
|
||||
|
||||
/** @brief Sums two time values, replacing the first with the result.
|
||||
|
||||
@param tvA Destination and first source.
|
||||
@param tvB second source
|
||||
|
||||
If a given pointer is NULL, this function returns without doing anything.
|
||||
|
||||
Both parameters are expected to be in normalized form.
|
||||
*/
|
||||
OSVR_UTIL_EXPORT void osvrTimeValueSum(OSVR_INOUT_PTR OSVR_TimeValue *tvA,
|
||||
OSVR_IN_PTR const OSVR_TimeValue *tvB)
|
||||
OSVR_FUNC_NONNULL((1, 2));
|
||||
|
||||
/** @brief Computes the difference between two time values, replacing the first
|
||||
with the result.
|
||||
|
||||
Effectively, `*tvA = *tvA - *tvB`
|
||||
|
||||
@param tvA Destination and first source.
|
||||
@param tvB second source
|
||||
|
||||
If a given pointer is NULL, this function returns without doing anything.
|
||||
|
||||
Both parameters are expected to be in normalized form.
|
||||
*/
|
||||
OSVR_UTIL_EXPORT void
|
||||
osvrTimeValueDifference(OSVR_INOUT_PTR OSVR_TimeValue *tvA,
|
||||
OSVR_IN_PTR const OSVR_TimeValue *tvB)
|
||||
OSVR_FUNC_NONNULL((1, 2));
|
||||
|
||||
/** @brief Compares two time values (assumed to be normalized), returning
|
||||
the same values as strcmp
|
||||
|
||||
@return <0 if A is earlier than B, 0 if they are the same, and >0 if A
|
||||
is later than B.
|
||||
*/
|
||||
OSVR_UTIL_EXPORT int osvrTimeValueCmp(OSVR_IN_PTR const OSVR_TimeValue *tvA,
|
||||
OSVR_IN_PTR const OSVR_TimeValue *tvB)
|
||||
OSVR_FUNC_NONNULL((1, 2));
|
||||
|
||||
OSVR_EXTERN_C_END
|
||||
|
||||
/** @brief Compute the difference between the two time values, returning the
|
||||
duration as a double-precision floating-point number of seconds.
|
||||
|
||||
Effectively, `ret = *tvA - *tvB`
|
||||
|
||||
@param tvA first source.
|
||||
@param tvB second source
|
||||
@return Duration of timespan in seconds (floating-point)
|
||||
*/
|
||||
OSVR_INLINE double
|
||||
osvrTimeValueDurationSeconds(OSVR_IN_PTR const OSVR_TimeValue *tvA,
|
||||
OSVR_IN_PTR const OSVR_TimeValue *tvB) {
|
||||
OSVR_TimeValue A = *tvA;
|
||||
osvrTimeValueDifference(&A, tvB);
|
||||
double dt = A.seconds + A.microseconds / 1000000.0;
|
||||
return dt;
|
||||
}
|
||||
|
||||
/** @brief True if A is later than B */
|
||||
OSVR_INLINE OSVR_CBool
|
||||
osvrTimeValueGreater(OSVR_IN_PTR const OSVR_TimeValue *tvA,
|
||||
OSVR_IN_PTR const OSVR_TimeValue *tvB) {
|
||||
if (!tvA || !tvB) {
|
||||
return OSVR_FALSE;
|
||||
}
|
||||
return ((tvA->seconds > tvB->seconds) ||
|
||||
(tvA->seconds == tvB->seconds &&
|
||||
tvA->microseconds > tvB->microseconds))
|
||||
? OSVR_TRUE
|
||||
: OSVR_FALSE;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include <cmath>
|
||||
#include <cassert>
|
||||
|
||||
/// Returns true if the time value is normalized. Typically used in assertions.
|
||||
inline bool osvrTimeValueIsNormalized(const OSVR_TimeValue &tv) {
|
||||
#ifdef __APPLE__
|
||||
// apparently standard library used on mac only has floating-point abs?
|
||||
return std::abs(double(tv.microseconds)) < 1000000 &&
|
||||
#else
|
||||
return std::abs(tv.microseconds) < 1000000 &&
|
||||
#endif
|
||||
((tv.seconds > 0) == (tv.microseconds > 0));
|
||||
}
|
||||
|
||||
/// True if A is later than B
|
||||
inline bool osvrTimeValueGreater(const OSVR_TimeValue &tvA,
|
||||
const OSVR_TimeValue &tvB) {
|
||||
assert(osvrTimeValueIsNormalized(tvA) &&
|
||||
"First timevalue argument to comparison was not normalized!");
|
||||
assert(osvrTimeValueIsNormalized(tvB) &&
|
||||
"Second timevalue argument to comparison was not normalized!");
|
||||
return (tvA.seconds > tvB.seconds) ||
|
||||
(tvA.seconds == tvB.seconds && tvA.microseconds > tvB.microseconds);
|
||||
}
|
||||
|
||||
/// Operator > overload for time values
|
||||
inline bool operator>(const OSVR_TimeValue &tvA, const OSVR_TimeValue &tvB) {
|
||||
return osvrTimeValueGreater(tvA, tvB);
|
||||
}
|
||||
|
||||
/// Operator < overload for time values
|
||||
inline bool operator<(const OSVR_TimeValue &tvA, const OSVR_TimeValue &tvB) {
|
||||
// Change the order of arguments before forwarding.
|
||||
return osvrTimeValueGreater(tvB, tvA);
|
||||
}
|
||||
|
||||
/// Operator == overload for time values
|
||||
inline bool operator==(const OSVR_TimeValue &tvA, const OSVR_TimeValue &tvB) {
|
||||
assert(
|
||||
osvrTimeValueIsNormalized(tvA) &&
|
||||
"First timevalue argument to equality comparison was not normalized!");
|
||||
assert(
|
||||
osvrTimeValueIsNormalized(tvB) &&
|
||||
"Second timevalue argument to equality comparison was not normalized!");
|
||||
return (tvA.seconds == tvB.seconds) &&
|
||||
(tvA.microseconds == tvB.microseconds);
|
||||
}
|
||||
/// Operator == overload for time values
|
||||
inline bool operator!=(const OSVR_TimeValue &tvA, const OSVR_TimeValue &tvB) {
|
||||
assert(osvrTimeValueIsNormalized(tvA) && "First timevalue argument to "
|
||||
"inequality comparison was not "
|
||||
"normalized!");
|
||||
assert(osvrTimeValueIsNormalized(tvB) && "Second timevalue argument to "
|
||||
"inequality comparison was not "
|
||||
"normalized!");
|
||||
return (tvA.seconds != tvB.seconds) ||
|
||||
(tvA.microseconds != tvB.microseconds);
|
||||
}
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
#endif
|
||||
@@ -1,86 +0,0 @@
|
||||
/** @file
|
||||
@brief Header
|
||||
|
||||
Must be c-safe!
|
||||
|
||||
@date 2014
|
||||
|
||||
@author
|
||||
Sensics, Inc.
|
||||
<http://sensics.com/osvr>
|
||||
*/
|
||||
|
||||
/*
|
||||
// Copyright 2014 Sensics, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef INCLUDED_Vec2C_h_GUID_F9715DE4_2649_4182_0F4C_D62121235D5F
|
||||
#define INCLUDED_Vec2C_h_GUID_F9715DE4_2649_4182_0F4C_D62121235D5F
|
||||
|
||||
/* Internal Includes */
|
||||
#include <osvr/Util/APIBaseC.h>
|
||||
|
||||
/* Library/third-party includes */
|
||||
/* none */
|
||||
|
||||
/* Standard includes */
|
||||
/* none */
|
||||
|
||||
OSVR_EXTERN_C_BEGIN
|
||||
|
||||
/** @addtogroup UtilMath
|
||||
@{
|
||||
*/
|
||||
/** @brief A structure defining a 2D vector, which represents position
|
||||
*/
|
||||
typedef struct OSVR_Vec2 {
|
||||
/** @brief Internal array data. */
|
||||
double data[2];
|
||||
} OSVR_Vec2;
|
||||
|
||||
#define OSVR_VEC_MEMBER(COMPONENT, INDEX) \
|
||||
/** @brief Accessor for Vec2 component COMPONENT */ \
|
||||
OSVR_INLINE double osvrVec2Get##COMPONENT(OSVR_Vec2 const *v) { \
|
||||
return v->data[INDEX]; \
|
||||
} \
|
||||
/** @brief Setter for Vec2 component COMPONENT */ \
|
||||
OSVR_INLINE void osvrVec2Set##COMPONENT(OSVR_Vec2 *v, double val) { \
|
||||
v->data[INDEX] = val; \
|
||||
}
|
||||
|
||||
OSVR_VEC_MEMBER(X, 0)
|
||||
OSVR_VEC_MEMBER(Y, 1)
|
||||
|
||||
#undef OSVR_VEC_MEMBER
|
||||
|
||||
/** @brief Set a Vec2 to the zero vector */
|
||||
OSVR_INLINE void osvrVec2Zero(OSVR_Vec2 *v) {
|
||||
osvrVec2SetX(v, 0);
|
||||
osvrVec2SetY(v, 0);
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
||||
OSVR_EXTERN_C_END
|
||||
|
||||
#ifdef __cplusplus
|
||||
template <typename StreamType>
|
||||
inline StreamType &operator<<(StreamType &os, OSVR_Vec2 const &vec) {
|
||||
os << "(" << vec.data[0] << ", " << vec.data[1] << ")";
|
||||
return os;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // INCLUDED_Vec2C_h_GUID_F9715DE4_2649_4182_0F4C_D62121235D5F
|
||||
@@ -1,89 +0,0 @@
|
||||
/** @file
|
||||
@brief Header
|
||||
|
||||
Must be c-safe!
|
||||
|
||||
@date 2014
|
||||
|
||||
@author
|
||||
Sensics, Inc.
|
||||
<http://sensics.com/osvr>
|
||||
*/
|
||||
|
||||
/*
|
||||
// Copyright 2014 Sensics, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef INCLUDED_Vec3C_h_GUID_BF4E98ED_74CF_4785_DB61_109A00BA74DE
|
||||
#define INCLUDED_Vec3C_h_GUID_BF4E98ED_74CF_4785_DB61_109A00BA74DE
|
||||
|
||||
/* Internal Includes */
|
||||
#include <osvr/Util/APIBaseC.h>
|
||||
|
||||
/* Library/third-party includes */
|
||||
/* none */
|
||||
|
||||
/* Standard includes */
|
||||
/* none */
|
||||
|
||||
OSVR_EXTERN_C_BEGIN
|
||||
|
||||
/** @addtogroup UtilMath
|
||||
@{
|
||||
*/
|
||||
/** @brief A structure defining a 3D vector, often a position/translation.
|
||||
*/
|
||||
typedef struct OSVR_Vec3 {
|
||||
/** @brief Internal array data. */
|
||||
double data[3];
|
||||
} OSVR_Vec3;
|
||||
|
||||
#define OSVR_VEC_MEMBER(COMPONENT, INDEX) \
|
||||
/** @brief Accessor for Vec3 component COMPONENT */ \
|
||||
OSVR_INLINE double osvrVec3Get##COMPONENT(OSVR_Vec3 const *v) { \
|
||||
return v->data[INDEX]; \
|
||||
} \
|
||||
/** @brief Setter for Vec3 component COMPONENT */ \
|
||||
OSVR_INLINE void osvrVec3Set##COMPONENT(OSVR_Vec3 *v, double val) { \
|
||||
v->data[INDEX] = val; \
|
||||
}
|
||||
|
||||
OSVR_VEC_MEMBER(X, 0)
|
||||
OSVR_VEC_MEMBER(Y, 1)
|
||||
OSVR_VEC_MEMBER(Z, 2)
|
||||
|
||||
#undef OSVR_VEC_MEMBER
|
||||
|
||||
/** @brief Set a Vec3 to the zero vector */
|
||||
OSVR_INLINE void osvrVec3Zero(OSVR_Vec3 *v) {
|
||||
osvrVec3SetX(v, 0);
|
||||
osvrVec3SetY(v, 0);
|
||||
osvrVec3SetZ(v, 0);
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
||||
OSVR_EXTERN_C_END
|
||||
|
||||
#ifdef __cplusplus
|
||||
template <typename StreamType>
|
||||
inline StreamType &operator<<(StreamType &os, OSVR_Vec3 const &vec) {
|
||||
os << "(" << vec.data[0] << ", " << vec.data[1] << ", " << vec.data[2]
|
||||
<< ")";
|
||||
return os;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,676 +0,0 @@
|
||||
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
||||
/* 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/. */
|
||||
|
||||
/* This file contains just the needed struct definitions for
|
||||
* interacting with the Oculus VR C API, without needing to #include
|
||||
* OVR_CAPI.h directly. Note that it uses the same type names as the
|
||||
* CAPI, and cannot be #included at the same time as OVR_CAPI.h. It
|
||||
* does not include the entire C API, just want's needed.
|
||||
*/
|
||||
|
||||
#ifdef OVR_CAPI_h
|
||||
#ifdef _MSC_VER
|
||||
#pragma message("ovr_capi_dyanmic.h: OVR_CAPI.h included before ovr_capi_dynamic.h, skipping this")
|
||||
#else
|
||||
#warning OVR_CAPI.h included before ovr_capi_dynamic.h, skipping this
|
||||
#endif
|
||||
#define mozilla_ovr_capi_dynamic_h_
|
||||
|
||||
#else
|
||||
|
||||
#ifndef mozilla_ovr_capi_dynamic_h_
|
||||
#define mozilla_ovr_capi_dynamic_h_
|
||||
|
||||
#define OVR_CAPI_LIMITED_MOZILLA 1
|
||||
|
||||
#ifdef HAVE_64BIT_BUILD
|
||||
#define OVR_PTR_SIZE 8
|
||||
#define OVR_ON64(x) x
|
||||
#else
|
||||
#define OVR_PTR_SIZE 4
|
||||
#define OVR_ON64(x) /**/
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32)
|
||||
#define OVR_PFN __cdecl
|
||||
#else
|
||||
#define OVR_PFN
|
||||
#endif
|
||||
|
||||
#if !defined(OVR_ALIGNAS)
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#define OVR_ALIGNAS(n) __attribute__((aligned(n)))
|
||||
#elif defined(_MSC_VER) || defined(__INTEL_COMPILER)
|
||||
#define OVR_ALIGNAS(n) __declspec(align(n))
|
||||
#elif defined(__CC_ARM)
|
||||
#define OVR_ALIGNAS(n) __align(n)
|
||||
#else
|
||||
#error Need to define OVR_ALIGNAS
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if !defined(OVR_UNUSED_STRUCT_PAD)
|
||||
#define OVR_UNUSED_STRUCT_PAD(padName, size) char padName[size];
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef int32_t ovrResult;
|
||||
|
||||
typedef enum {
|
||||
ovrSuccess = 0,
|
||||
ovrSuccess_NotVisible = 1000,
|
||||
ovrSuccess_HMDFirmwareMismatch = 4100,
|
||||
ovrSuccess_TrackerFirmwareMismatch = 4101,
|
||||
ovrSuccess_ControllerFirmwareMismatch = 4104,
|
||||
} ovrSuccessType;
|
||||
|
||||
typedef char ovrBool;
|
||||
typedef struct OVR_ALIGNAS(4) { int x, y; } ovrVector2i;
|
||||
typedef struct OVR_ALIGNAS(4) { int w, h; } ovrSizei;
|
||||
typedef struct OVR_ALIGNAS(4) { ovrVector2i Pos; ovrSizei Size; } ovrRecti;
|
||||
typedef struct OVR_ALIGNAS(4) { float x, y, z, w; } ovrQuatf;
|
||||
typedef struct OVR_ALIGNAS(4) { float x, y; } ovrVector2f;
|
||||
typedef struct OVR_ALIGNAS(4) { float x, y, z; } ovrVector3f;
|
||||
typedef struct OVR_ALIGNAS(4) { float M[4][4]; } ovrMatrix4f;
|
||||
|
||||
typedef struct OVR_ALIGNAS(4) {
|
||||
ovrQuatf Orientation;
|
||||
ovrVector3f Position;
|
||||
} ovrPosef;
|
||||
|
||||
typedef struct OVR_ALIGNAS(8) {
|
||||
ovrPosef ThePose;
|
||||
ovrVector3f AngularVelocity;
|
||||
ovrVector3f LinearVelocity;
|
||||
ovrVector3f AngularAcceleration;
|
||||
ovrVector3f LinearAcceleration;
|
||||
OVR_UNUSED_STRUCT_PAD(pad0, 4)
|
||||
double TimeInSeconds;
|
||||
} ovrPoseStatef;
|
||||
|
||||
typedef struct {
|
||||
float UpTan;
|
||||
float DownTan;
|
||||
float LeftTan;
|
||||
float RightTan;
|
||||
} ovrFovPort;
|
||||
|
||||
typedef enum {
|
||||
ovrHmd_None = 0,
|
||||
ovrHmd_DK1 = 3,
|
||||
ovrHmd_DKHD = 4,
|
||||
ovrHmd_DK2 = 6,
|
||||
ovrHmd_CB = 8,
|
||||
ovrHmd_Other = 9,
|
||||
ovrHmd_E3_2015 = 10,
|
||||
ovrHmd_ES06 = 11,
|
||||
ovrHmd_ES09 = 12,
|
||||
ovrHmd_ES11 = 13,
|
||||
ovrHmd_CV1 = 14,
|
||||
ovrHmd_EnumSize = 0x7fffffff
|
||||
} ovrHmdType;
|
||||
|
||||
typedef enum {
|
||||
ovrHmdCap_DebugDevice = 0x0010,
|
||||
ovrHmdCap_EnumSize = 0x7fffffff
|
||||
} ovrHmdCaps;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
ovrTrackingCap_Orientation = 0x0010,
|
||||
ovrTrackingCap_MagYawCorrection = 0x0020,
|
||||
ovrTrackingCap_Position = 0x0040,
|
||||
ovrTrackingCap_EnumSize = 0x7fffffff
|
||||
} ovrTrackingCaps;
|
||||
|
||||
typedef enum {
|
||||
ovrEye_Left = 0,
|
||||
ovrEye_Right = 1,
|
||||
ovrEye_Count = 2,
|
||||
ovrEye_EnumSize = 0x7fffffff
|
||||
} ovrEyeType;
|
||||
|
||||
typedef enum {
|
||||
ovrTrackingOrigin_EyeLevel = 0,
|
||||
ovrTrackingOrigin_FloorLevel = 1,
|
||||
ovrTrackingOrigin_Count = 2, ///< \internal Count of enumerated elements.
|
||||
ovrTrackingOrigin_EnumSize = 0x7fffffff ///< \internal Force type int32_t.
|
||||
} ovrTrackingOrigin;
|
||||
|
||||
typedef struct OVR_ALIGNAS(OVR_PTR_SIZE) {
|
||||
char Reserved[8];
|
||||
} ovrGraphicsLuid;
|
||||
|
||||
typedef struct OVR_ALIGNAS(OVR_PTR_SIZE) {
|
||||
ovrHmdType Type;
|
||||
OVR_ON64(OVR_UNUSED_STRUCT_PAD(pad0, 4))
|
||||
char ProductName[64];
|
||||
char Manufacturer[64];
|
||||
short VendorId;
|
||||
short ProductId;
|
||||
char SerialNumber[24];
|
||||
short FirmwareMajor;
|
||||
short FirmwareMinor;
|
||||
unsigned int AvailableHmdCaps;
|
||||
unsigned int DefaultHmdCaps;
|
||||
unsigned int AvailableTrackingCaps;
|
||||
unsigned int DefaultTrackingCaps;
|
||||
ovrFovPort DefaultEyeFov[ovrEye_Count];
|
||||
ovrFovPort MaxEyeFov[ovrEye_Count];
|
||||
ovrSizei Resolution;
|
||||
float DisplayRefreshRate;
|
||||
OVR_ON64(OVR_UNUSED_STRUCT_PAD(pad1, 4))
|
||||
} ovrHmdDesc;
|
||||
|
||||
typedef struct ovrHmdStruct* ovrSession;
|
||||
|
||||
typedef enum {
|
||||
ovrStatus_OrientationTracked = 0x0001,
|
||||
ovrStatus_PositionTracked = 0x0002,
|
||||
ovrStatus_EnumSize = 0x7fffffff
|
||||
} ovrStatusBits;
|
||||
|
||||
typedef struct OVR_ALIGNAS(OVR_PTR_SIZE) {
|
||||
float FrustumHFovInRadians;
|
||||
float FrustumVFovInRadians;
|
||||
float FrustumNearZInMeters;
|
||||
float FrustumFarZInMeters;
|
||||
} ovrTrackerDesc;
|
||||
|
||||
typedef enum {
|
||||
ovrTracker_Connected = 0x0020,
|
||||
ovrTracker_PoseTracked = 0x0004
|
||||
} ovrTrackerFlags;
|
||||
|
||||
typedef struct OVR_ALIGNAS(8) {
|
||||
unsigned int TrackerFlags;
|
||||
ovrPosef Pose;
|
||||
ovrPosef LeveledPose;
|
||||
OVR_UNUSED_STRUCT_PAD(pad0, 4)
|
||||
} ovrTrackerPose;
|
||||
|
||||
typedef struct OVR_ALIGNAS(8) {
|
||||
ovrPoseStatef HeadPose;
|
||||
unsigned int StatusFlags;
|
||||
ovrPoseStatef HandPoses[2];
|
||||
unsigned int HandStatusFlags[2];
|
||||
ovrPosef CalibratedOrigin;
|
||||
} ovrTrackingState;
|
||||
|
||||
typedef struct OVR_ALIGNAS(4) {
|
||||
ovrEyeType Eye;
|
||||
ovrFovPort Fov;
|
||||
ovrRecti DistortedViewport;
|
||||
ovrVector2f PixelsPerTanAngleAtCenter;
|
||||
ovrVector3f HmdToEyeOffset;
|
||||
} ovrEyeRenderDesc;
|
||||
|
||||
typedef struct OVR_ALIGNAS(4) {
|
||||
float Projection22;
|
||||
float Projection23;
|
||||
float Projection32;
|
||||
} ovrTimewarpProjectionDesc;
|
||||
|
||||
typedef struct OVR_ALIGNAS(4) {
|
||||
ovrVector3f HmdToEyeViewOffset[ovrEye_Count];
|
||||
float HmdSpaceToWorldScaleInMeters;
|
||||
} ovrViewScaleDesc;
|
||||
|
||||
typedef enum {
|
||||
ovrTexture_2D,
|
||||
ovrTexture_2D_External,
|
||||
ovrTexture_Cube,
|
||||
ovrTexture_Count,
|
||||
ovrTexture_EnumSize = 0x7fffffff
|
||||
} ovrTextureType;
|
||||
|
||||
typedef enum {
|
||||
ovrTextureBind_None,
|
||||
ovrTextureBind_DX_RenderTarget = 0x0001,
|
||||
ovrTextureBind_DX_UnorderedAccess = 0x0002,
|
||||
ovrTextureBind_DX_DepthStencil = 0x0004,
|
||||
ovrTextureBind_EnumSize = 0x7fffffff
|
||||
} ovrTextureBindFlags;
|
||||
|
||||
typedef enum {
|
||||
OVR_FORMAT_UNKNOWN,
|
||||
OVR_FORMAT_B5G6R5_UNORM,
|
||||
OVR_FORMAT_B5G5R5A1_UNORM,
|
||||
OVR_FORMAT_B4G4R4A4_UNORM,
|
||||
OVR_FORMAT_R8G8B8A8_UNORM,
|
||||
OVR_FORMAT_R8G8B8A8_UNORM_SRGB,
|
||||
OVR_FORMAT_B8G8R8A8_UNORM,
|
||||
OVR_FORMAT_B8G8R8A8_UNORM_SRGB,
|
||||
OVR_FORMAT_B8G8R8X8_UNORM,
|
||||
OVR_FORMAT_B8G8R8X8_UNORM_SRGB,
|
||||
OVR_FORMAT_R16G16B16A16_FLOAT,
|
||||
OVR_FORMAT_D16_UNORM,
|
||||
OVR_FORMAT_D24_UNORM_S8_UINT,
|
||||
OVR_FORMAT_D32_FLOAT,
|
||||
OVR_FORMAT_D32_FLOAT_S8X24_UINT,
|
||||
OVR_FORMAT_ENUMSIZE = 0x7fffffff
|
||||
} ovrTextureFormat;
|
||||
|
||||
typedef enum {
|
||||
ovrTextureMisc_None,
|
||||
ovrTextureMisc_DX_Typeless = 0x0001,
|
||||
ovrTextureMisc_AllowGenerateMips = 0x0002,
|
||||
ovrTextureMisc_EnumSize = 0x7fffffff
|
||||
} ovrTextureFlags;
|
||||
|
||||
typedef struct {
|
||||
ovrTextureType Type;
|
||||
ovrTextureFormat Format;
|
||||
int ArraySize;
|
||||
int Width;
|
||||
int Height;
|
||||
int MipLevels;
|
||||
int SampleCount;
|
||||
ovrBool StaticImage;
|
||||
unsigned int MiscFlags;
|
||||
unsigned int BindFlags;
|
||||
} ovrTextureSwapChainDesc;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
ovrTextureFormat Format;
|
||||
int Width;
|
||||
int Height;
|
||||
unsigned int MiscFlags;
|
||||
} ovrMirrorTextureDesc;
|
||||
|
||||
typedef void* ovrTextureSwapChain;
|
||||
typedef struct ovrMirrorTextureData* ovrMirrorTexture;
|
||||
|
||||
|
||||
|
||||
typedef enum {
|
||||
ovrButton_A = 0x00000001,
|
||||
ovrButton_B = 0x00000002,
|
||||
ovrButton_RThumb = 0x00000004,
|
||||
ovrButton_RShoulder = 0x00000008,
|
||||
ovrButton_RMask = ovrButton_A | ovrButton_B | ovrButton_RThumb | ovrButton_RShoulder,
|
||||
ovrButton_X = 0x00000100,
|
||||
ovrButton_Y = 0x00000200,
|
||||
ovrButton_LThumb = 0x00000400,
|
||||
ovrButton_LShoulder = 0x00000800,
|
||||
ovrButton_LMask = ovrButton_X | ovrButton_Y | ovrButton_LThumb | ovrButton_LShoulder,
|
||||
ovrButton_Up = 0x00010000,
|
||||
ovrButton_Down = 0x00020000,
|
||||
ovrButton_Left = 0x00040000,
|
||||
ovrButton_Right = 0x00080000,
|
||||
ovrButton_Enter = 0x00100000,
|
||||
ovrButton_Back = 0x00200000,
|
||||
ovrButton_VolUp = 0x00400000,
|
||||
ovrButton_VolDown = 0x00800000,
|
||||
ovrButton_Home = 0x01000000,
|
||||
ovrButton_Private = ovrButton_VolUp | ovrButton_VolDown | ovrButton_Home,
|
||||
ovrButton_EnumSize = 0x7fffffff
|
||||
} ovrButton;
|
||||
|
||||
typedef enum {
|
||||
ovrTouch_A = ovrButton_A,
|
||||
ovrTouch_B = ovrButton_B,
|
||||
ovrTouch_RThumb = ovrButton_RThumb,
|
||||
ovrTouch_RIndexTrigger = 0x00000010,
|
||||
ovrTouch_RButtonMask = ovrTouch_A | ovrTouch_B | ovrTouch_RThumb | ovrTouch_RIndexTrigger,
|
||||
ovrTouch_X = ovrButton_X,
|
||||
ovrTouch_Y = ovrButton_Y,
|
||||
ovrTouch_LThumb = ovrButton_LThumb,
|
||||
ovrTouch_LIndexTrigger = 0x00001000,
|
||||
ovrTouch_LButtonMask = ovrTouch_X | ovrTouch_Y | ovrTouch_LThumb | ovrTouch_LIndexTrigger,
|
||||
ovrTouch_RIndexPointing = 0x00000020,
|
||||
ovrTouch_RThumbUp = 0x00000040,
|
||||
ovrTouch_RPoseMask = ovrTouch_RIndexPointing | ovrTouch_RThumbUp,
|
||||
ovrTouch_LIndexPointing = 0x00002000,
|
||||
ovrTouch_LThumbUp = 0x00004000,
|
||||
ovrTouch_LPoseMask = ovrTouch_LIndexPointing | ovrTouch_LThumbUp,
|
||||
ovrTouch_EnumSize = 0x7fffffff
|
||||
} ovrTouch;
|
||||
|
||||
typedef enum {
|
||||
ovrControllerType_None = 0x00,
|
||||
ovrControllerType_LTouch = 0x01,
|
||||
ovrControllerType_RTouch = 0x02,
|
||||
ovrControllerType_Touch = 0x03,
|
||||
ovrControllerType_Remote = 0x04,
|
||||
ovrControllerType_XBox = 0x10,
|
||||
ovrControllerType_Active = 0xff,
|
||||
ovrControllerType_EnumSize = 0x7fffffff
|
||||
} ovrControllerType;
|
||||
|
||||
typedef enum {
|
||||
ovrHand_Left = 0,
|
||||
ovrHand_Right = 1,
|
||||
ovrHand_Count = 2,
|
||||
ovrHand_EnumSize = 0x7fffffff
|
||||
} ovrHandType;
|
||||
|
||||
typedef struct {
|
||||
double TimeInSeconds;
|
||||
unsigned int Buttons;
|
||||
unsigned int Touches;
|
||||
float IndexTrigger[ovrHand_Count];
|
||||
float HandTrigger[ovrHand_Count];
|
||||
ovrVector2f Thumbstick[ovrHand_Count];
|
||||
ovrControllerType ControllerType;
|
||||
} ovrInputState;
|
||||
|
||||
typedef enum {
|
||||
ovrInit_Debug = 0x00000001,
|
||||
ovrInit_RequestVersion = 0x00000004,
|
||||
ovrinit_WritableBits = 0x00ffffff,
|
||||
ovrInit_EnumSize = 0x7fffffff
|
||||
} ovrInitFlags;
|
||||
|
||||
typedef enum {
|
||||
ovrLogLevel_Debug = 0,
|
||||
ovrLogLevel_Info = 1,
|
||||
ovrLogLevel_Error = 2,
|
||||
ovrLogLevel_EnumSize = 0x7fffffff
|
||||
} ovrLogLevel;
|
||||
|
||||
typedef void (OVR_PFN* ovrLogCallback)(uintptr_t userData, int level, const char* message);
|
||||
|
||||
typedef struct OVR_ALIGNAS(8) {
|
||||
uint32_t Flags;
|
||||
uint32_t RequestedMinorVersion;
|
||||
ovrLogCallback LogCallback;
|
||||
uintptr_t UserData;
|
||||
uint32_t ConnectionTimeoutMS;
|
||||
OVR_ON64(OVR_UNUSED_STRUCT_PAD(pad0, 4))
|
||||
} ovrInitParams;
|
||||
|
||||
typedef ovrResult(OVR_PFN* pfn_ovr_Initialize)(const ovrInitParams* params);
|
||||
typedef void (OVR_PFN* pfn_ovr_Shutdown)();
|
||||
|
||||
typedef struct {
|
||||
ovrResult Result;
|
||||
char ErrorString[512];
|
||||
} ovrErrorInfo;
|
||||
|
||||
typedef void (OVR_PFN* pfn_ovr_GetLastErrorInfo)(ovrErrorInfo* errorInfo);
|
||||
typedef const char* (OVR_PFN* pfn_ovr_GetVersionString)();
|
||||
typedef int (OVR_PFN* pfn_ovr_TraceMessage)(int level, const char* message);
|
||||
typedef ovrHmdDesc (OVR_PFN* pfn_ovr_GetHmdDesc)(ovrSession session);
|
||||
typedef unsigned int (OVR_PFN* pfn_ovr_GetTrackerCount)(ovrSession session);
|
||||
typedef ovrTrackerDesc* (OVR_PFN* pfn_ovr_GetTrackerDesc)(ovrSession session, unsigned int trackerDescIndex);
|
||||
typedef ovrResult (OVR_PFN* pfn_ovr_Create)(ovrSession* pSession, ovrGraphicsLuid* pLuid);
|
||||
typedef void (OVR_PFN* pfn_ovr_Destroy)(ovrSession session);
|
||||
|
||||
typedef struct {
|
||||
ovrBool IsVisible;
|
||||
ovrBool HmdPresent;
|
||||
ovrBool HmdMounted;
|
||||
ovrBool DisplayLost;
|
||||
ovrBool ShouldQuit;
|
||||
ovrBool ShouldRecenter;
|
||||
} ovrSessionStatus;
|
||||
|
||||
typedef ovrResult (OVR_PFN* pfn_ovr_GetSessionStatus)(ovrSession session, ovrSessionStatus* sessionStatus);
|
||||
|
||||
typedef ovrResult (OVR_PFN* pfn_ovr_SetTrackingOriginType)(ovrSession session, ovrTrackingOrigin origin);
|
||||
typedef ovrTrackingOrigin (OVR_PFN* pfn_ovr_GetTrackingOriginType)(ovrSession session);
|
||||
typedef ovrResult (OVR_PFN* pfn_ovr_RecenterTrackingOrigin)(ovrSession session);
|
||||
typedef void (OVR_PFN* pfn_ovr_ClearShouldRecenterFlag)(ovrSession session);
|
||||
typedef ovrTrackingState (OVR_PFN* pfn_ovr_GetTrackingState)(ovrSession session, double absTime, ovrBool latencyMarker);
|
||||
typedef ovrTrackerPose (OVR_PFN* pfn_ovr_GetTrackerPose)(ovrSession session, unsigned int trackerPoseIndex);
|
||||
typedef ovrResult (OVR_PFN* pfn_ovr_GetInputState)(ovrSession session, ovrControllerType controllerType, ovrInputState* inputState);
|
||||
typedef unsigned int (OVR_PFN* pfn_ovr_GetConnectedControllerTypes)(ovrSession session);
|
||||
typedef ovrResult (OVR_PFN* pfn_ovr_SetControllerVibration)(ovrSession session, ovrControllerType controllerType, float frequency, float amplitude);
|
||||
|
||||
enum {
|
||||
ovrMaxLayerCount = 16
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
ovrLayerType_Disabled = 0,
|
||||
ovrLayerType_EyeFov = 1,
|
||||
ovrLayerType_Quad = 3,
|
||||
ovrLayerType_EyeMatrix = 5,
|
||||
ovrLayerType_EnumSize = 0x7fffffff
|
||||
} ovrLayerType;
|
||||
|
||||
typedef enum {
|
||||
ovrLayerFlag_HighQuality = 0x01,
|
||||
ovrLayerFlag_TextureOriginAtBottomLeft = 0x02,
|
||||
ovrLayerFlag_HeadLocked = 0x04
|
||||
} ovrLayerFlags;
|
||||
|
||||
typedef struct OVR_ALIGNAS(OVR_PTR_SIZE) {
|
||||
ovrLayerType Type;
|
||||
unsigned Flags;
|
||||
} ovrLayerHeader;
|
||||
|
||||
typedef struct OVR_ALIGNAS(OVR_PTR_SIZE) {
|
||||
ovrLayerHeader Header;
|
||||
ovrTextureSwapChain ColorTexture[ovrEye_Count];
|
||||
ovrRecti Viewport[ovrEye_Count];
|
||||
ovrFovPort Fov[ovrEye_Count];
|
||||
ovrPosef RenderPose[ovrEye_Count];
|
||||
double SensorSampleTime;
|
||||
} ovrLayerEyeFov;
|
||||
|
||||
typedef struct OVR_ALIGNAS(OVR_PTR_SIZE) {
|
||||
ovrLayerHeader Header;
|
||||
ovrTextureSwapChain ColorTexture[ovrEye_Count];
|
||||
ovrRecti Viewport[ovrEye_Count];
|
||||
ovrPosef RenderPose[ovrEye_Count];
|
||||
ovrMatrix4f Matrix[ovrEye_Count];
|
||||
double SensorSampleTime;
|
||||
} ovrLayerEyeMatrix;
|
||||
|
||||
typedef struct OVR_ALIGNAS(OVR_PTR_SIZE) {
|
||||
ovrLayerHeader Header;
|
||||
ovrTextureSwapChain ColorTexture;
|
||||
ovrRecti Viewport;
|
||||
ovrPosef QuadPoseCenter;
|
||||
ovrVector2f QuadSize;
|
||||
} ovrLayerQuad;
|
||||
|
||||
typedef union {
|
||||
ovrLayerHeader Header;
|
||||
ovrLayerEyeFov EyeFov;
|
||||
ovrLayerQuad Quad;
|
||||
} ovrLayer_Union;
|
||||
|
||||
|
||||
typedef ovrResult (OVR_PFN* pfn_ovr_GetTextureSwapChainLength)(ovrSession session, ovrTextureSwapChain chain, int* out_Length);
|
||||
typedef ovrResult (OVR_PFN* pfn_ovr_GetTextureSwapChainCurrentIndex)(ovrSession session, ovrTextureSwapChain chain, int* out_Index);
|
||||
typedef ovrResult (OVR_PFN* pfn_ovr_GetTextureSwapChainDesc)(ovrSession session, ovrTextureSwapChain chain, ovrTextureSwapChainDesc* out_Desc);
|
||||
typedef ovrResult (OVR_PFN* pfn_ovr_CommitTextureSwapChain)(ovrSession session, ovrTextureSwapChain chain);
|
||||
typedef void (OVR_PFN* pfn_ovr_DestroyTextureSwapChain)(ovrSession session, ovrTextureSwapChain chain);
|
||||
typedef void (OVR_PFN* pfn_ovr_DestroyMirrorTexture)(ovrSession session, ovrMirrorTexture mirrorTexture);
|
||||
typedef ovrSizei(OVR_PFN* pfn_ovr_GetFovTextureSize)(ovrSession session, ovrEyeType eye, ovrFovPort fov, float pixelsPerDisplayPixel);
|
||||
typedef ovrEyeRenderDesc(OVR_PFN* pfn_ovr_GetRenderDesc)(ovrSession session, ovrEyeType eyeType, ovrFovPort fov);
|
||||
typedef ovrResult(OVR_PFN* pfn_ovr_SubmitFrame)(ovrSession session, unsigned int frameIndex,
|
||||
const ovrViewScaleDesc* viewScaleDesc,
|
||||
ovrLayerHeader const * const * layerPtrList, unsigned int layerCount);
|
||||
typedef double (OVR_PFN* pfn_ovr_GetPredictedDisplayTime)(ovrSession session, long long frameIndex);
|
||||
typedef double (OVR_PFN* pfn_ovr_GetTimeInSeconds)();
|
||||
|
||||
|
||||
typedef enum {
|
||||
ovrPerfHud_Off = 0,
|
||||
ovrPerfHud_PerfSummary = 1,
|
||||
ovrPerfHud_LatencyTiming = 2,
|
||||
ovrPerfHud_AppRenderTiming = 3,
|
||||
ovrPerfHud_CompRenderTiming = 4,
|
||||
ovrPerfHud_VersionInfo = 5,
|
||||
ovrPerfHud_Count = 6,
|
||||
ovrPerfHud_EnumSize = 0x7fffffff
|
||||
} ovrPerfHudMode;
|
||||
|
||||
typedef enum {
|
||||
ovrLayerHud_Off = 0,
|
||||
ovrLayerHud_Info = 1,
|
||||
ovrLayerHud_EnumSize = 0x7fffffff
|
||||
} ovrLayerHudMode;
|
||||
|
||||
typedef enum {
|
||||
ovrDebugHudStereo_Off = 0,
|
||||
ovrDebugHudStereo_Quad = 1,
|
||||
ovrDebugHudStereo_QuadWithCrosshair = 2,
|
||||
ovrDebugHudStereo_CrosshairAtInfinity = 3,
|
||||
ovrDebugHudStereo_Count,
|
||||
ovrDebugHudStereo_EnumSize = 0x7fffffff
|
||||
} ovrDebugHudStereoMode;
|
||||
|
||||
typedef ovrBool(OVR_PFN* pfn_ovr_GetBool)(ovrSession session, const char* propertyName, ovrBool defaultVal);
|
||||
typedef ovrBool(OVR_PFN* pfn_ovr_SetBool)(ovrSession session, const char* propertyName, ovrBool value);
|
||||
typedef int (OVR_PFN* pfn_ovr_GetInt)(ovrSession session, const char* propertyName, int defaultVal);
|
||||
typedef ovrBool (OVR_PFN* pfn_ovr_SetInt)(ovrSession session, const char* propertyName, int value);
|
||||
typedef float (OVR_PFN* pfn_ovr_GetFloat)(ovrSession session, const char* propertyName, float defaultVal);
|
||||
typedef ovrBool (OVR_PFN* pfn_ovr_SetFloat)(ovrSession session, const char* propertyName, float value);
|
||||
typedef unsigned int (OVR_PFN* pfn_ovr_GetFloatArray)(ovrSession session, const char* propertyName,
|
||||
float values[], unsigned int valuesCapacity);
|
||||
typedef ovrBool (OVR_PFN* pfn_ovr_SetFloatArray)(ovrSession session, const char* propertyName,
|
||||
const float values[], unsigned int valuesSize);
|
||||
typedef const char* (OVR_PFN* pfn_ovr_GetString)(ovrSession session, const char* propertyName,
|
||||
const char* defaultVal);
|
||||
typedef ovrBool (OVR_PFN* pfn_ovr_SetString)(ovrSession session, const char* propertyName,
|
||||
const char* value);
|
||||
|
||||
|
||||
|
||||
typedef enum {
|
||||
ovrError_MemoryAllocationFailure = -1000,
|
||||
ovrError_SocketCreationFailure = -1001,
|
||||
ovrError_InvalidSession = -1002,
|
||||
ovrError_Timeout = -1003,
|
||||
ovrError_NotInitialized = -1004,
|
||||
ovrError_InvalidParameter = -1005,
|
||||
ovrError_ServiceError = -1006,
|
||||
ovrError_NoHmd = -1007,
|
||||
ovrError_Unsupported = -1009,
|
||||
ovrError_DeviceUnavailable = -1010,
|
||||
ovrError_InvalidHeadsetOrientation = -1011,
|
||||
ovrError_ClientSkippedDestroy = -1012,
|
||||
ovrError_ClientSkippedShutdown = -1013,
|
||||
ovrError_AudioReservedBegin = -2000,
|
||||
ovrError_AudioDeviceNotFound = -2001,
|
||||
ovrError_AudioComError = -2002,
|
||||
ovrError_AudioReservedEnd = -2999,
|
||||
ovrError_Initialize = -3000,
|
||||
ovrError_LibLoad = -3001,
|
||||
ovrError_LibVersion = -3002,
|
||||
ovrError_ServiceConnection = -3003,
|
||||
ovrError_ServiceVersion = -3004,
|
||||
ovrError_IncompatibleOS = -3005,
|
||||
ovrError_DisplayInit = -3006,
|
||||
ovrError_ServerStart = -3007,
|
||||
ovrError_Reinitialization = -3008,
|
||||
ovrError_MismatchedAdapters = -3009,
|
||||
ovrError_LeakingResources = -3010,
|
||||
ovrError_ClientVersion = -3011,
|
||||
ovrError_OutOfDateOS = -3012,
|
||||
ovrError_OutOfDateGfxDriver = -3013,
|
||||
ovrError_IncompatibleGPU = -3014,
|
||||
ovrError_NoValidVRDisplaySystem = -3015,
|
||||
ovrError_Obsolete = -3016,
|
||||
ovrError_DisabledOrDefaultAdapter = -3017,
|
||||
ovrError_HybridGraphicsNotSupported = -3018,
|
||||
ovrError_DisplayManagerInit = -3019,
|
||||
ovrError_TrackerDriverInit = -3020,
|
||||
ovrError_InvalidBundleAdjustment = -4000,
|
||||
ovrError_USBBandwidth = -4001,
|
||||
ovrError_USBEnumeratedSpeed = -4002,
|
||||
ovrError_ImageSensorCommError = -4003,
|
||||
ovrError_GeneralTrackerFailure = -4004,
|
||||
ovrError_ExcessiveFrameTruncation = -4005,
|
||||
ovrError_ExcessiveFrameSkipping = -4006,
|
||||
ovrError_SyncDisconnected = -4007,
|
||||
ovrError_TrackerMemoryReadFailure = -4008,
|
||||
ovrError_TrackerMemoryWriteFailure = -4009,
|
||||
ovrError_TrackerFrameTimeout = -4010,
|
||||
ovrError_TrackerTruncatedFrame = -4011,
|
||||
ovrError_TrackerDriverFailure = -4012,
|
||||
ovrError_TrackerNRFFailure = -4013,
|
||||
ovrError_HardwareGone = -4014,
|
||||
ovrError_NordicEnabledNoSync = -4015,
|
||||
ovrError_NordicSyncNoFrames = -4016,
|
||||
ovrError_CatastrophicFailure = -4017,
|
||||
ovrError_HMDFirmwareMismatch = -4100,
|
||||
ovrError_TrackerFirmwareMismatch = -4101,
|
||||
ovrError_BootloaderDeviceDetected = -4102,
|
||||
ovrError_TrackerCalibrationError = -4103,
|
||||
ovrError_ControllerFirmwareMismatch = -4104,
|
||||
ovrError_IMUTooManyLostSamples = -4200,
|
||||
ovrError_IMURateError = -4201,
|
||||
ovrError_FeatureReportFailure = -4202,
|
||||
ovrError_Incomplete = -5000,
|
||||
ovrError_Abandoned = -5001,
|
||||
ovrError_DisplayLost = -6000,
|
||||
ovrError_TextureSwapChainFull = -6001,
|
||||
ovrError_TextureSwapChainInvalid = -6002,
|
||||
ovrError_RuntimeException = -7000,
|
||||
ovrError_MetricsUnknownApp = -90000,
|
||||
ovrError_MetricsDuplicateApp = -90001,
|
||||
ovrError_MetricsNoEvents = -90002,
|
||||
ovrError_MetricsRuntime = -90003,
|
||||
ovrError_MetricsFile = -90004,
|
||||
ovrError_MetricsNoClientInfo = -90005,
|
||||
ovrError_MetricsNoAppMetaData = -90006,
|
||||
ovrError_MetricsNoApp = -90007,
|
||||
ovrError_MetricsOafFailure = -90008,
|
||||
ovrError_MetricsSessionAlreadyActive = -90009,
|
||||
ovrError_MetricsSessionNotActive = -90010,
|
||||
} ovrErrorType;
|
||||
|
||||
|
||||
#ifdef XP_WIN
|
||||
|
||||
struct IUnknown;
|
||||
|
||||
typedef ovrResult (OVR_PFN* pfn_ovr_CreateTextureSwapChainDX)(ovrSession session,
|
||||
IUnknown* d3dPtr,
|
||||
const ovrTextureSwapChainDesc* desc,
|
||||
ovrTextureSwapChain* out_TextureSwapChain);
|
||||
|
||||
typedef ovrResult (OVR_PFN* pfn_ovr_GetTextureSwapChainBufferDX)(ovrSession session,
|
||||
ovrTextureSwapChain chain,
|
||||
int index,
|
||||
IID iid,
|
||||
void** out_Buffer);
|
||||
|
||||
typedef ovrResult (OVR_PFN* pfn_ovr_CreateMirrorTextureDX)(ovrSession session,
|
||||
IUnknown* d3dPtr,
|
||||
const ovrMirrorTextureDesc* desc,
|
||||
ovrMirrorTexture* out_MirrorTexture);
|
||||
|
||||
typedef ovrResult (OVR_PFN* pfn_ovr_GetMirrorTextureBufferDX)(ovrSession session,
|
||||
ovrMirrorTexture mirrorTexture,
|
||||
IID iid,
|
||||
void** out_Buffer);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
typedef ovrResult (OVR_PFN* pfn_ovr_CreateTextureSwapChainGL)(ovrSession session,
|
||||
const ovrTextureSwapChainDesc* desc,
|
||||
ovrTextureSwapChain* out_TextureSwapChain);
|
||||
|
||||
typedef ovrResult (OVR_PFN* pfn_ovr_GetTextureSwapChainBufferGL)(ovrSession session,
|
||||
ovrTextureSwapChain chain,
|
||||
int index,
|
||||
unsigned int* out_TexId);
|
||||
|
||||
typedef ovrResult (OVR_PFN* pfn_ovr_CreateMirrorTextureGL)(ovrSession session,
|
||||
const ovrMirrorTextureDesc* desc,
|
||||
ovrMirrorTexture* out_MirrorTexture);
|
||||
|
||||
typedef ovrResult (OVR_PFN* pfn_ovr_GetMirrorTextureBufferGL)(ovrSession session,
|
||||
ovrMirrorTexture mirrorTexture,
|
||||
unsigned int* out_TexId);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* mozilla_ovr_capi_dynamic_h_ */
|
||||
#endif /* OVR_CAPI_h */
|
||||
@@ -4906,30 +4906,6 @@ pref("dom.browserElement.maxScreenshotDelayMS", 2000);
|
||||
// Whether we should show the placeholder when the element is focused but empty.
|
||||
pref("dom.placeholder.show_on_focus", true);
|
||||
|
||||
// VR is disabled by default in release and enabled for nightly and aurora
|
||||
#ifdef RELEASE_OR_BETA
|
||||
pref("dom.vr.enabled", false);
|
||||
#else
|
||||
pref("dom.vr.enabled", true);
|
||||
#endif
|
||||
pref("dom.vr.oculus.enabled", true);
|
||||
// OSVR device
|
||||
pref("dom.vr.osvr.enabled", false);
|
||||
// OpenVR device
|
||||
pref("dom.vr.openvr.enabled", false);
|
||||
// Pose prediction reduces latency effects by returning future predicted HMD
|
||||
// poses to callers of the WebVR API. This currently only has an effect for
|
||||
// Oculus Rift on SDK 0.8 or greater. It is disabled by default for now due to
|
||||
// frame uniformity issues with e10s.
|
||||
pref("dom.vr.poseprediction.enabled", false);
|
||||
// path to openvr DLL
|
||||
pref("gfx.vr.openvr-runtime", "");
|
||||
// path to OSVR DLLs
|
||||
pref("gfx.vr.osvr.utilLibPath", "");
|
||||
pref("gfx.vr.osvr.commonLibPath", "");
|
||||
pref("gfx.vr.osvr.clientLibPath", "");
|
||||
pref("gfx.vr.osvr.clientKitLibPath", "");
|
||||
|
||||
// MMS UA Profile settings
|
||||
pref("wap.UAProf.url", "");
|
||||
pref("wap.UAProf.tagname", "x-wap-profile");
|
||||
|
||||
@@ -73,7 +73,6 @@
|
||||
#endif
|
||||
#include "gfxConfig.h"
|
||||
#include "mozilla/layers/CompositorSession.h"
|
||||
#include "VRManagerChild.h"
|
||||
|
||||
#ifdef DEBUG
|
||||
#include "nsIObserver.h"
|
||||
@@ -366,7 +365,6 @@ nsBaseWidget::OnRenderingDeviceReset()
|
||||
// Update the texture factory identifier.
|
||||
clm->UpdateTextureFactoryIdentifier(identifier);
|
||||
ImageBridgeChild::IdentifyCompositorTextureHost(identifier);
|
||||
gfx::VRManagerChild::IdentifyTextureHost(identifier);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -1377,7 +1375,6 @@ void nsBaseWidget::CreateCompositor(int aWidth, int aHeight)
|
||||
// compositors used with ImageBridge and VR (and more generally web content).
|
||||
if (WidgetTypeSupportsAcceleration()) {
|
||||
ImageBridgeChild::IdentifyCompositorTextureHost(textureFactoryIdentifier);
|
||||
gfx::VRManagerChild::IdentifyTextureHost(textureFactoryIdentifier);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user