--- a/dom/base/Element.cpp
+++ b/dom/base/Element.cpp
@@ -138,17 +138,17 @@
#include "nsITextControlElement.h"
#include "nsITextControlFrame.h"
#include "nsISupportsImpl.h"
#include "mozilla/dom/CSSPseudoElement.h"
#include "mozilla/dom/DocumentFragment.h"
#include "mozilla/dom/KeyframeEffectBinding.h"
#include "mozilla/dom/WindowBinding.h"
#include "mozilla/dom/ElementBinding.h"
-#include "mozilla/dom/VRDevice.h"
+#include "mozilla/dom/VRDisplay.h"
#include "mozilla/IntegerPrintfMacros.h"
#include "mozilla/Preferences.h"
#include "nsComputedDOMStyle.h"
using namespace mozilla;
using namespace mozilla::dom;
nsIAtom*
--- a/dom/base/Navigator.cpp
+++ b/dom/base/Navigator.cpp
@@ -46,17 +46,17 @@
#include "mozilla/dom/MobileMessageManager.h"
#include "mozilla/dom/Permissions.h"
#include "mozilla/dom/Presentation.h"
#include "mozilla/dom/ServiceWorkerContainer.h"
#include "mozilla/dom/TCPSocket.h"
#include "mozilla/dom/Telephony.h"
#include "mozilla/dom/Voicemail.h"
#include "mozilla/dom/TVManager.h"
-#include "mozilla/dom/VRDevice.h"
+#include "mozilla/dom/VRDisplay.h"
#include "mozilla/dom/workers/RuntimeService.h"
#include "mozilla/Hal.h"
#include "nsISiteSpecificUserAgent.h"
#include "mozilla/ClearOnShutdown.h"
#include "mozilla/StaticPtr.h"
#include "Connection.h"
#include "mozilla/dom/Event.h" // for nsIDOMEvent::InternalDOMEvent()
#include "nsGlobalWindow.h"
@@ -262,17 +262,17 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(
#ifdef MOZ_EME
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMediaKeySystemAccessManager)
#endif
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDeviceStorageAreaListener)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPresentation)
#ifdef MOZ_GAMEPAD
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mGamepadServiceTest)
#endif
- NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mVRGetDevicesPromises)
+ NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mVRGetDisplaysPromises)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION_TRACE_WRAPPERCACHE(Navigator)
void
Navigator::Invalidate()
{
@@ -407,17 +407,17 @@ Navigator::Invalidate()
#ifdef MOZ_GAMEPAD
if (mGamepadServiceTest) {
mGamepadServiceTest->Shutdown();
mGamepadServiceTest = nullptr;
}
#endif
- mVRGetDevicesPromises.Clear();
+ mVRGetDisplaysPromises.Clear();
}
//*****************************************************************************
// Navigator::nsIDOMNavigator
//*****************************************************************************
NS_IMETHODIMP
Navigator::GetUserAgent(nsAString& aUserAgent)
@@ -2032,58 +2032,58 @@ Navigator::RequestGamepadServiceTest()
if (!mGamepadServiceTest) {
mGamepadServiceTest = GamepadServiceTest::CreateTestService(mWindow);
}
return mGamepadServiceTest;
}
#endif
already_AddRefed<Promise>
-Navigator::GetVRDevices(ErrorResult& aRv)
+Navigator::GetVRDisplays(ErrorResult& aRv)
{
if (!mWindow || !mWindow->GetDocShell()) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
nsCOMPtr<nsIGlobalObject> go = do_QueryInterface(mWindow);
RefPtr<Promise> p = Promise::Create(go, aRv);
if (aRv.Failed()) {
return nullptr;
}
- // We pass ourself to RefreshVRDevices, so NotifyVRDevicesUpdated will
- // be called asynchronously, resolving the promises in mVRGetDevicesPromises.
- if (!VRDevice::RefreshVRDevices(this)) {
+ // We pass ourself to RefreshVRDisplays, so NotifyVRDisplaysUpdated will
+ // be called asynchronously, resolving the promises in mVRGetDisplaysPromises.
+ if (!VRDisplay::RefreshVRDisplays(this)) {
p->MaybeReject(NS_ERROR_FAILURE);
return p.forget();
}
- mVRGetDevicesPromises.AppendElement(p);
+ mVRGetDisplaysPromises.AppendElement(p);
return p.forget();
}
void
-Navigator::NotifyVRDevicesUpdated()
+Navigator::NotifyVRDisplaysUpdated()
{
// Synchronize the VR devices and resolve the promises in
- // mVRGetDevicesPromises
+ // mVRGetDisplaysPromises
nsGlobalWindow* win = nsGlobalWindow::Cast(mWindow);
- nsTArray<RefPtr<VRDevice>> vrDevs;
- if (win->UpdateVRDevices(vrDevs)) {
- for (auto p: mVRGetDevicesPromises) {
- p->MaybeResolve(vrDevs);
+ nsTArray<RefPtr<VRDisplay>> vrDisplays;
+ if (win->UpdateVRDisplays(vrDisplays)) {
+ for (auto p : mVRGetDisplaysPromises) {
+ p->MaybeResolve(vrDisplays);
}
} else {
- for (auto p: mVRGetDevicesPromises) {
+ for (auto p : mVRGetDisplaysPromises) {
p->MaybeReject(NS_ERROR_FAILURE);
}
}
- mVRGetDevicesPromises.Clear();
+ mVRGetDisplaysPromises.Clear();
}
//*****************************************************************************
// Navigator::nsIMozNavigatorNetwork
//*****************************************************************************
NS_IMETHODIMP
Navigator::GetProperties(nsINetworkProperties** aProperties)
--- a/dom/base/Navigator.h
+++ b/dom/base/Navigator.h
@@ -255,18 +255,18 @@ public:
#endif
#ifdef MOZ_B2G_RIL
MobileConnectionArray* GetMozMobileConnections(ErrorResult& aRv);
#endif // MOZ_B2G_RIL
#ifdef MOZ_GAMEPAD
void GetGamepads(nsTArray<RefPtr<Gamepad> >& aGamepads, ErrorResult& aRv);
GamepadServiceTest* RequestGamepadServiceTest();
#endif // MOZ_GAMEPAD
- already_AddRefed<Promise> GetVRDevices(ErrorResult& aRv);
- void NotifyVRDevicesUpdated();
+ already_AddRefed<Promise> GetVRDisplays(ErrorResult& aRv);
+ void NotifyVRDisplaysUpdated();
#ifdef MOZ_B2G_FM
FMRadio* GetMozFMRadio(ErrorResult& aRv);
#endif
#ifdef MOZ_B2G_BT
bluetooth::BluetoothManager* GetMozBluetooth(ErrorResult& aRv);
#endif // MOZ_B2G_BT
#ifdef MOZ_TIME_MANAGER
time::TimeManager* GetMozTime(ErrorResult& aRv);
@@ -389,16 +389,16 @@ private:
RefPtr<time::TimeManager> mTimeManager;
RefPtr<ServiceWorkerContainer> mServiceWorkerContainer;
nsCOMPtr<nsPIDOMWindowInner> mWindow;
RefPtr<DeviceStorageAreaListener> mDeviceStorageAreaListener;
RefPtr<Presentation> mPresentation;
#ifdef MOZ_GAMEPAD
RefPtr<GamepadServiceTest> mGamepadServiceTest;
#endif
- nsTArray<RefPtr<Promise> > mVRGetDevicesPromises;
+ nsTArray<RefPtr<Promise> > mVRGetDisplaysPromises;
nsTArray<uint32_t> mRequestedVibrationPattern;
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_Navigator_h
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -254,17 +254,17 @@
#include "nsISpeculativeConnect.h"
#include "mozilla/MediaManager.h"
#ifdef MOZ_WEBRTC
#include "IPeerConnection.h"
#endif // MOZ_WEBRTC
-#include "VRDeviceProxy.h"
+#include "VRDisplayProxy.h"
using namespace mozilla;
using namespace mozilla::dom;
typedef nsTArray<Link*> LinkArray;
static LazyLogModule gDocumentLeakPRLog("DocumentLeak");
static LazyLogModule gCspPRLog("CSP");
--- a/dom/base/nsGlobalWindow.cpp
+++ b/dom/base/nsGlobalWindow.cpp
@@ -187,17 +187,17 @@
#include "mozilla/dom/MessageChannel.h"
#include "mozilla/dom/Promise.h"
#ifdef MOZ_GAMEPAD
#include "mozilla/dom/Gamepad.h"
#include "mozilla/dom/GamepadManager.h"
#endif
-#include "mozilla/dom/VRDevice.h"
+#include "mozilla/dom/VRDisplay.h"
#include "nsRefreshDriver.h"
#include "Layers.h"
#include "mozilla/AddonPathService.h"
#include "mozilla/BasePrincipal.h"
#include "mozilla/Services.h"
#include "mozilla/Telemetry.h"
@@ -1886,17 +1886,17 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPendingStorageEvents)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mIdleObservers)
#ifdef MOZ_GAMEPAD
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mGamepads)
#endif
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mCacheStorage)
- NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mVRDevices)
+ NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mVRDisplays)
// Traverse stuff from nsPIDOMWindow
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mChromeEventHandler)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mParentTarget)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mFrameElement)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mFocusedNode)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMenubar)
@@ -1962,17 +1962,17 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(ns
NS_IMPL_CYCLE_COLLECTION_UNLINK(mPendingStorageEvents)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mIdleObservers)
#ifdef MOZ_GAMEPAD
NS_IMPL_CYCLE_COLLECTION_UNLINK(mGamepads)
#endif
NS_IMPL_CYCLE_COLLECTION_UNLINK(mCacheStorage)
- NS_IMPL_CYCLE_COLLECTION_UNLINK(mVRDevices)
+ NS_IMPL_CYCLE_COLLECTION_UNLINK(mVRDisplays)
// Unlink stuff from nsPIDOMWindow
NS_IMPL_CYCLE_COLLECTION_UNLINK(mChromeEventHandler)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mParentTarget)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mFrameElement)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mFocusedNode)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mMenubar)
@@ -13444,22 +13444,22 @@ nsGlobalWindow::SyncGamepadState()
for (auto iter = mGamepads.Iter(); !iter.Done(); iter.Next()) {
gamepadManager->SyncGamepadState(iter.Key(), iter.UserData());
}
}
}
#endif // MOZ_GAMEPAD
bool
-nsGlobalWindow::UpdateVRDevices(nsTArray<RefPtr<mozilla::dom::VRDevice>>& aDevices)
-{
- FORWARD_TO_INNER(UpdateVRDevices, (aDevices), false);
-
- VRDevice::UpdateVRDevices(mVRDevices, ToSupports(this));
- aDevices = mVRDevices;
+nsGlobalWindow::UpdateVRDisplays(nsTArray<RefPtr<mozilla::dom::VRDisplay>>& aDevices)
+{
+ FORWARD_TO_INNER(UpdateVRDisplays, (aDevices), false);
+
+ VRDisplay::UpdateVRDisplays(mVRDisplays, ToSupports(this));
+ aDevices = mVRDisplays;
return true;
}
// nsGlobalChromeWindow implementation
NS_IMPL_CYCLE_COLLECTION_CLASS(nsGlobalChromeWindow)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsGlobalChromeWindow,
--- a/dom/base/nsGlobalWindow.h
+++ b/dom/base/nsGlobalWindow.h
@@ -117,17 +117,17 @@ class Navigator;
class OwningExternalOrWindowProxy;
class Promise;
class PostMessageEvent;
struct RequestInit;
class RequestOrUSVString;
class Selection;
class SpeechSynthesis;
class U2F;
-class VRDevice;
+class VRDisplay;
class WakeLock;
#if defined(MOZ_WIDGET_ANDROID) || defined(MOZ_WIDGET_GONK)
class WindowOrientationObserver;
#endif
namespace cache {
class CacheStorage;
} // namespace cache
class IDBFactory;
@@ -796,18 +796,18 @@ public:
void SyncGamepadState();
#endif
// Inner windows only.
// Enable/disable updates for gamepad input.
void EnableGamepadUpdates();
void DisableGamepadUpdates();
- // Update the VR devices for this window
- bool UpdateVRDevices(nsTArray<RefPtr<mozilla::dom::VRDevice>>& aDevices);
+ // Update the VR displays for this window
+ bool UpdateVRDisplays(nsTArray<RefPtr<mozilla::dom::VRDisplay>>& aDisplays);
#define EVENT(name_, id_, type_, struct_) \
mozilla::dom::EventHandlerNonNull* GetOn##name_() \
{ \
mozilla::EventListenerManager* elm = GetExistingListenerManager(); \
return elm ? elm->GetEventHandler(nsGkAtoms::on##name_, EmptyString()) \
: nullptr; \
} \
@@ -1903,18 +1903,18 @@ protected:
#ifdef MOZ_WEBSPEECH
// mSpeechSynthesis is only used on inner windows.
RefPtr<mozilla::dom::SpeechSynthesis> mSpeechSynthesis;
#endif
// This is the CC generation the last time we called CanSkip.
uint32_t mCanSkipCCGeneration;
- // The VRDevies for this window
- nsTArray<RefPtr<mozilla::dom::VRDevice>> mVRDevices;
+ // The VR Displays for this window
+ nsTArray<RefPtr<mozilla::dom::VRDisplay>> mVRDisplays;
friend class nsDOMScriptableHelper;
friend class nsDOMWindowUtils;
friend class mozilla::dom::PostMessageEvent;
friend class DesktopNotification;
static WindowByIdTable* sWindowsById;
static bool sWarnedAboutWindowInternal;
--- a/dom/bindings/Bindings.conf
+++ b/dom/bindings/Bindings.conf
@@ -1228,17 +1228,17 @@ DOMInterfaces = {
'TreeWalker': {
'wrapperCache': False,
},
'UndoManager': {
'implicitJSContext' : [ 'undo', 'redo', 'transact' ],
},
-'VRDevice': {
+'VRDisplay': {
'concrete': False
},
'VTTCue': {
'nativeType': 'mozilla::dom::TextTrackCue'
},
'VTTRegion': {
--- a/dom/tests/mochitest/general/test_interfaces.html
+++ b/dom/tests/mochitest/general/test_interfaces.html
@@ -514,17 +514,17 @@ var interfaceNamesInGlobalScope =
"HashChangeEvent",
// IMPORTANT: Do not change this list without review from a DOM peer!
"Headers",
// IMPORTANT: Do not change this list without review from a DOM peer!
"History",
// IMPORTANT: Do not change this list without review from a DOM peer!
{name: "HDMIInputPort", b2g: true, permission: ["inputport"]},
// IMPORTANT: Do not change this list without review from a DOM peer!
- {name: "HMDVRDevice", release: false},
+ {name: "HMDVRDisplay", release: false},
// IMPORTANT: Do not change this list without review from a DOM peer!
"HTMLAllCollection",
// IMPORTANT: Do not change this list without review from a DOM peer!
"HTMLAnchorElement",
// IMPORTANT: Do not change this list without review from a DOM peer!
"HTMLAppletElement",
// IMPORTANT: Do not change this list without review from a DOM peer!
"HTMLAreaElement",
@@ -940,17 +940,17 @@ var interfaceNamesInGlobalScope =
{name: "PointerEvent", nightly: true, desktop: true, disabled: true},
// IMPORTANT: Do not change this list without review from a DOM peer!
"PopStateEvent",
// IMPORTANT: Do not change this list without review from a DOM peer!
"PopupBlockedEvent",
// IMPORTANT: Do not change this list without review from a DOM peer!
{name: "PopupBoxObject", xbl: true},
// IMPORTANT: Do not change this list without review from a DOM peer!
- {name: "PositionSensorVRDevice", release: false},
+ {name: "PositionSensorVRDisplay", release: false},
// IMPORTANT: Do not change this list without review from a DOM peer!
{name: "PresentationDeviceInfoManager",
disabled: true,
permission: ["presentation-device-manage"]},
// IMPORTANT: Do not change this list without review from a DOM peer!
{name: "Presentation", disabled: true, permission: ["presentation"]},
// IMPORTANT: Do not change this list without review from a DOM peer!
{name: "PresentationAvailability", disabled: true, permission: ["presentation"]},
@@ -1387,17 +1387,17 @@ var interfaceNamesInGlobalScope =
"UserProximityEvent",
// IMPORTANT: Do not change this list without review from a DOM peer!
"ValidityState",
// IMPORTANT: Do not change this list without review from a DOM peer!
"VideoPlaybackQuality",
// IMPORTANT: Do not change this list without review from a DOM peer!
"VideoStreamTrack",
// IMPORTANT: Do not change this list without review from a DOM peer!
- {name: "VRDevice", release: false},
+ {name: "VRDisplay", release: false},
// IMPORTANT: Do not change this list without review from a DOM peer!
{name: "VRPositionState", release: false},
// IMPORTANT: Do not change this list without review from a DOM peer!
{name: "VREyeParameters", release: false},
// IMPORTANT: Do not change this list without review from a DOM peer!
{name: "VRFieldOfView", release: false},
// IMPORTANT: Do not change this list without review from a DOM peer!
{name: "VRFieldOfViewReadOnly", release: false},
deleted file mode 100644
--- a/dom/vr/VRDevice.cpp
+++ /dev/null
@@ -1,367 +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/VRDeviceBinding.h"
-#include "mozilla/dom/ElementBinding.h"
-#include "mozilla/dom/VRDevice.h"
-#include "Navigator.h"
-#include "gfxVR.h"
-#include "VRDeviceProxy.h"
-#include "VRManagerChild.h"
-#include "nsIFrame.h"
-
-using namespace mozilla::gfx;
-
-namespace mozilla {
-namespace dom {
-
-/*static*/ bool
-VRDevice::RefreshVRDevices(dom::Navigator* aNavigator)
-{
- gfx::VRManagerChild* vm = gfx::VRManagerChild::Get();
- return vm && vm->RefreshVRDevicesWithCallback(aNavigator);
-}
-
-/*static*/ void
-VRDevice::UpdateVRDevices(nsTArray<RefPtr<VRDevice>>& aDevices, nsISupports* aParent)
-{
- nsTArray<RefPtr<VRDevice>> devices;
-
- gfx::VRManagerChild* vm = gfx::VRManagerChild::Get();
- nsTArray<RefPtr<gfx::VRDeviceProxy>> proxyDevices;
- if (vm && vm->GetVRDevices(proxyDevices)) {
- for (size_t i = 0; i < proxyDevices.Length(); i++) {
- RefPtr<gfx::VRDeviceProxy> proxyDevice = proxyDevices[i];
- bool isNewDevice = true;
- for (size_t j = 0; j < aDevices.Length(); j++) {
- if (aDevices[j]->GetHMD()->GetDeviceInfo() == proxyDevice->GetDeviceInfo()) {
- devices.AppendElement(aDevices[j]);
- isNewDevice = false;
- }
- }
-
- if (isNewDevice) {
- gfx::VRStateValidFlags sensorBits = proxyDevice->GetDeviceInfo().GetSupportedSensorStateBits();
- devices.AppendElement(new HMDInfoVRDevice(aParent, proxyDevice));
- if (sensorBits & (gfx::VRStateValidFlags::State_Position |
- gfx::VRStateValidFlags::State_Orientation))
- {
- devices.AppendElement(new HMDPositionVRDevice(aParent, proxyDevice));
- }
- }
- }
- }
-
- aDevices = devices;
-}
-
-NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(VRFieldOfViewReadOnly, mParent)
-NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(VRFieldOfViewReadOnly, AddRef)
-NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(VRFieldOfViewReadOnly, Release)
-
-JSObject*
-VRFieldOfViewReadOnly::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
-{
- return VRFieldOfViewReadOnlyBinding::Wrap(aCx, this, aGivenProto);
-}
-
-already_AddRefed<VRFieldOfView>
-VRFieldOfView::Constructor(const GlobalObject& aGlobal, const VRFieldOfViewInit& aParams,
- ErrorResult& aRV)
-{
- RefPtr<VRFieldOfView> fov =
- new VRFieldOfView(aGlobal.GetAsSupports(),
- aParams.mUpDegrees, aParams.mRightDegrees,
- aParams.mDownDegrees, aParams.mLeftDegrees);
- return fov.forget();
-}
-
-already_AddRefed<VRFieldOfView>
-VRFieldOfView::Constructor(const GlobalObject& aGlobal,
- double aUpDegrees, double aRightDegrees,
- double aDownDegrees, double aLeftDegrees,
- ErrorResult& aRV)
-{
- RefPtr<VRFieldOfView> fov =
- new VRFieldOfView(aGlobal.GetAsSupports(),
- aUpDegrees, aRightDegrees, aDownDegrees,
- aLeftDegrees);
- return fov.forget();
-}
-
-JSObject*
-VRFieldOfView::WrapObject(JSContext* aCx,
- JS::Handle<JSObject*> aGivenProto)
-{
- return VRFieldOfViewBinding::Wrap(aCx, this, aGivenProto);
-}
-
-NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(VREyeParameters, mParent, mMinFOV, mMaxFOV, mRecFOV, mCurFOV, mEyeTranslation, mRenderRect)
-NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(VREyeParameters, AddRef)
-NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(VREyeParameters, Release)
-
-VREyeParameters::VREyeParameters(nsISupports* aParent,
- const gfx::VRFieldOfView& aMinFOV,
- const gfx::VRFieldOfView& aMaxFOV,
- const gfx::VRFieldOfView& aRecFOV,
- const gfx::Point3D& aEyeTranslation,
- const gfx::VRFieldOfView& aCurFOV,
- const gfx::IntRect& aRenderRect)
- : mParent(aParent)
-{
- mMinFOV = new VRFieldOfView(aParent, aMinFOV);
- mMaxFOV = new VRFieldOfView(aParent, aMaxFOV);
- mRecFOV = new VRFieldOfView(aParent, aRecFOV);
- mCurFOV = new VRFieldOfView(aParent, aCurFOV);
-
- mEyeTranslation = new DOMPoint(aParent, aEyeTranslation.x, aEyeTranslation.y, aEyeTranslation.z, 0.0);
- mRenderRect = new DOMRect(aParent, aRenderRect.x, aRenderRect.y, aRenderRect.width, aRenderRect.height);
-}
-
-VRFieldOfView*
-VREyeParameters::MinimumFieldOfView()
-{
- return mMinFOV;
-}
-
-VRFieldOfView*
-VREyeParameters::MaximumFieldOfView()
-{
- return mMaxFOV;
-}
-
-VRFieldOfView*
-VREyeParameters::RecommendedFieldOfView()
-{
- return mRecFOV;
-}
-
-VRFieldOfView*
-VREyeParameters::CurrentFieldOfView()
-{
- return mCurFOV;
-}
-
-DOMPoint*
-VREyeParameters::EyeTranslation()
-{
- return mEyeTranslation;
-}
-
-DOMRect*
-VREyeParameters::RenderRect()
-{
- return mRenderRect;
-}
-
-JSObject*
-VREyeParameters::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
-{
- return VREyeParametersBinding::Wrap(aCx, this, aGivenProto);
-}
-
-NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(VRPositionState, mParent)
-NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(VRPositionState, AddRef)
-NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(VRPositionState, Release)
-
-VRPositionState::VRPositionState(nsISupports* aParent, const gfx::VRHMDSensorState& aState)
- : mParent(aParent)
- , mVRState(aState)
-{
- mTimeStamp = aState.timestamp;
-
- if (aState.flags & gfx::VRStateValidFlags::State_Position) {
- mPosition = new DOMPoint(mParent, aState.position[0], aState.position[1], aState.position[2], 0.0);
- }
-
- if (aState.flags & gfx::VRStateValidFlags::State_Orientation) {
- mOrientation = new DOMPoint(mParent, aState.orientation[0], aState.orientation[1], aState.orientation[2], aState.orientation[3]);
- }
-}
-
-DOMPoint*
-VRPositionState::GetLinearVelocity()
-{
- if (!mLinearVelocity) {
- mLinearVelocity = new DOMPoint(mParent, mVRState.linearVelocity[0], mVRState.linearVelocity[1], mVRState.linearVelocity[2], 0.0);
- }
- return mLinearVelocity;
-}
-
-DOMPoint*
-VRPositionState::GetLinearAcceleration()
-{
- if (!mLinearAcceleration) {
- mLinearAcceleration = new DOMPoint(mParent, mVRState.linearAcceleration[0], mVRState.linearAcceleration[1], mVRState.linearAcceleration[2], 0.0);
- }
- return mLinearAcceleration;
-}
-
-DOMPoint*
-VRPositionState::GetAngularVelocity()
-{
- if (!mAngularVelocity) {
- mAngularVelocity = new DOMPoint(mParent, mVRState.angularVelocity[0], mVRState.angularVelocity[1], mVRState.angularVelocity[2], 0.0);
- }
- return mAngularVelocity;
-}
-
-DOMPoint*
-VRPositionState::GetAngularAcceleration()
-{
- if (!mAngularAcceleration) {
- mAngularAcceleration = new DOMPoint(mParent, mVRState.angularAcceleration[0], mVRState.angularAcceleration[1], mVRState.angularAcceleration[2], 0.0);
- }
- return mAngularAcceleration;
-}
-
-JSObject*
-VRPositionState::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
-{
- return VRPositionStateBinding::Wrap(aCx, this, aGivenProto);
-}
-
-NS_IMPL_CYCLE_COLLECTING_ADDREF(VRDevice)
-NS_IMPL_CYCLE_COLLECTING_RELEASE(VRDevice)
-
-NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(VRDevice)
- NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
- NS_INTERFACE_MAP_ENTRY(nsISupports)
-NS_INTERFACE_MAP_END
-
-NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(VRDevice, mParent)
-
-/* virtual */ JSObject*
-HMDVRDevice::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
-{
- return HMDVRDeviceBinding::Wrap(aCx, this, aGivenProto);
-}
-
-/* virtual */ JSObject*
-PositionSensorVRDevice::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
-{
- return PositionSensorVRDeviceBinding::Wrap(aCx, this, aGivenProto);
-}
-
-HMDInfoVRDevice::HMDInfoVRDevice(nsISupports* aParent, gfx::VRDeviceProxy* aHMD)
- : HMDVRDevice(aParent, aHMD)
-{
- MOZ_COUNT_CTOR_INHERITED(HMDInfoVRDevice, HMDVRDevice);
- uint64_t hmdid = aHMD->GetDeviceInfo().GetDeviceID() << 8;
- uint64_t devid = hmdid | 0x00; // we generate a devid with low byte 0 for the HMD, 1 for the position sensor
-
- mHWID.Truncate();
- mHWID.AppendPrintf("0x%llx", hmdid);
-
- mDeviceId.Truncate();
- mDeviceId.AppendPrintf("0x%llx", devid);
-
- mDeviceName.Truncate();
- mDeviceName.Append(NS_ConvertASCIItoUTF16(aHMD->GetDeviceInfo().GetDeviceName()));
- mDeviceName.AppendLiteral(" (HMD)");
-
- mValid = true;
-}
-
-HMDInfoVRDevice::~HMDInfoVRDevice()
-{
- MOZ_COUNT_DTOR_INHERITED(HMDInfoVRDevice, HMDVRDevice);
-}
-
-/* If a field of view that is set to all 0's is passed in,
- * the recommended field of view for that eye is used.
- */
-void
-HMDInfoVRDevice::SetFieldOfView(const VRFieldOfViewInit& aLeftFOV,
- const VRFieldOfViewInit& aRightFOV,
- double zNear, double zFar)
-{
- gfx::VRFieldOfView left = gfx::VRFieldOfView(aLeftFOV.mUpDegrees, aLeftFOV.mRightDegrees,
- aLeftFOV.mDownDegrees, aLeftFOV.mLeftDegrees);
- gfx::VRFieldOfView right = gfx::VRFieldOfView(aRightFOV.mUpDegrees, aRightFOV.mRightDegrees,
- aRightFOV.mDownDegrees, aRightFOV.mLeftDegrees);
-
- if (left.IsZero()) {
- left = mHMD->GetDeviceInfo().GetRecommendedEyeFOV(VRDeviceInfo::Eye_Left);
- }
-
- if (right.IsZero()) {
- right = mHMD->GetDeviceInfo().GetRecommendedEyeFOV(VRDeviceInfo::Eye_Right);
- }
-
- mHMD->SetFOV(left, right, zNear, zFar);
-}
-
-already_AddRefed<VREyeParameters> HMDInfoVRDevice::GetEyeParameters(VREye aEye)
-{
- gfx::IntSize sz(mHMD->GetDeviceInfo().SuggestedEyeResolution());
- gfx::VRDeviceInfo::Eye eye = aEye == VREye::Left ? gfx::VRDeviceInfo::Eye_Left : gfx::VRDeviceInfo::Eye_Right;
- RefPtr<VREyeParameters> params =
- new VREyeParameters(mParent,
- gfx::VRFieldOfView(15, 15, 15, 15), // XXX min?
- mHMD->GetDeviceInfo().GetMaximumEyeFOV(eye),
- mHMD->GetDeviceInfo().GetRecommendedEyeFOV(eye),
- mHMD->GetDeviceInfo().GetEyeTranslation(eye),
- mHMD->GetDeviceInfo().GetEyeFOV(eye),
- gfx::IntRect((aEye == VREye::Left) ? 0 : sz.width, 0, sz.width, sz.height));
- return params.forget();
-}
-
-HMDPositionVRDevice::HMDPositionVRDevice(nsISupports* aParent, gfx::VRDeviceProxy* aHMD)
- : PositionSensorVRDevice(aParent, aHMD)
-{
- MOZ_COUNT_CTOR_INHERITED(HMDPositionVRDevice, PositionSensorVRDevice);
-
- uint64_t hmdid = aHMD->GetDeviceInfo().GetDeviceID() << 8;
- uint64_t devid = hmdid | 0x01; // we generate a devid with low byte 0 for the HMD, 1 for the position sensor
-
- mHWID.Truncate();
- mHWID.AppendPrintf("0x%llx", hmdid);
-
- mDeviceId.Truncate();
- mDeviceId.AppendPrintf("0x%llx", devid);
-
- mDeviceName.Truncate();
- mDeviceName.Append(NS_ConvertASCIItoUTF16(aHMD->GetDeviceInfo().GetDeviceName()));
- mDeviceName.AppendLiteral(" (Sensor)");
-
- mValid = true;
-}
-
-HMDPositionVRDevice::~HMDPositionVRDevice()
-{
- MOZ_COUNT_DTOR_INHERITED(HMDPositionVRDevice, PositionSensorVRDevice);
-}
-
-already_AddRefed<VRPositionState>
-HMDPositionVRDevice::GetState()
-{
- gfx::VRHMDSensorState state = mHMD->GetSensorState();
- RefPtr<VRPositionState> obj = new VRPositionState(mParent, state);
-
- return obj.forget();
-}
-
-already_AddRefed<VRPositionState>
-HMDPositionVRDevice::GetImmediateState()
-{
- gfx::VRHMDSensorState state = mHMD->GetImmediateSensorState();
- RefPtr<VRPositionState> obj = new VRPositionState(mParent, state);
-
- return obj.forget();
-}
-
-void
-HMDPositionVRDevice::ResetSensor()
-{
- mHMD->ZeroSensor();
-}
-
-} // namespace dom
-} // namespace mozilla
deleted file mode 100644
--- a/dom/vr/VRDevice.h
+++ /dev/null
@@ -1,317 +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_VRDevice_h_
-#define mozilla_dom_VRDevice_h_
-
-#include <stdint.h>
-
-#include "mozilla/ErrorResult.h"
-#include "mozilla/dom/TypedArray.h"
-#include "mozilla/dom/VRDeviceBinding.h"
-#include "mozilla/dom/DOMPoint.h"
-#include "mozilla/dom/DOMRect.h"
-
-#include "nsCOMPtr.h"
-#include "nsString.h"
-#include "nsTArray.h"
-#include "nsWrapperCache.h"
-
-#include "gfxVR.h"
-#include "VRDeviceProxy.h"
-
-namespace mozilla {
-namespace dom {
-class Navigator;
-
-class VRFieldOfViewReadOnly : public nsWrapperCache
-{
-public:
- VRFieldOfViewReadOnly(nsISupports* aParent,
- double aUpDegrees, double aRightDegrees,
- double aDownDegrees, double aLeftDegrees)
- : mParent(aParent)
- , mUpDegrees(aUpDegrees)
- , mRightDegrees(aRightDegrees)
- , mDownDegrees(aDownDegrees)
- , mLeftDegrees(aLeftDegrees)
- {
- }
-
- NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(VRFieldOfViewReadOnly)
- NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(VRFieldOfViewReadOnly)
-
- 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 ~VRFieldOfViewReadOnly() {}
-
- nsCOMPtr<nsISupports> mParent;
-
- double mUpDegrees;
- double mRightDegrees;
- double mDownDegrees;
- double mLeftDegrees;
-};
-
-class VRFieldOfView final : public VRFieldOfViewReadOnly
-{
-public:
- VRFieldOfView(nsISupports* aParent, const gfx::VRFieldOfView& aSrc)
- : VRFieldOfViewReadOnly(aParent,
- aSrc.upDegrees, aSrc.rightDegrees,
- aSrc.downDegrees, aSrc.leftDegrees)
- {}
-
- explicit VRFieldOfView(nsISupports* aParent,
- double aUpDegrees = 0.0, double aRightDegrees = 0.0,
- double aDownDegrees = 0.0, double aLeftDegrees = 0.0)
- : VRFieldOfViewReadOnly(aParent,
- aUpDegrees, aRightDegrees, aDownDegrees, aLeftDegrees)
- {}
-
- static already_AddRefed<VRFieldOfView>
- Constructor(const GlobalObject& aGlobal, const VRFieldOfViewInit& aParams,
- ErrorResult& aRv);
-
- static already_AddRefed<VRFieldOfView>
- Constructor(const GlobalObject& aGlobal,
- double aUpDegrees, double aRightDegrees,
- double aDownDegrees, double aLeftDegrees,
- ErrorResult& aRv);
-
- virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
-
- void SetUpDegrees(double aVal) { mUpDegrees = aVal; }
- void SetRightDegrees(double aVal) { mRightDegrees = aVal; }
- void SetDownDegrees(double aVal) { mDownDegrees = aVal; }
- void SetLeftDegrees(double aVal) { mLeftDegrees = aVal; }
-};
-
-class VRPositionState final : public nsWrapperCache
-{
- ~VRPositionState() {}
-public:
- VRPositionState(nsISupports* aParent, const gfx::VRHMDSensorState& aState);
-
- NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(VRPositionState)
- NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(VRPositionState)
-
- double TimeStamp() const { return mTimeStamp; }
-
- bool HasPosition() const { return mPosition != nullptr; }
- DOMPoint* GetPosition() const { return mPosition; }
-
- bool HasOrientation() const { return mOrientation != nullptr; }
- DOMPoint* GetOrientation() const { return mOrientation; }
-
- // these are created lazily
- DOMPoint* GetLinearVelocity();
- DOMPoint* GetLinearAcceleration();
- DOMPoint* GetAngularVelocity();
- DOMPoint* GetAngularAcceleration();
-
- nsISupports* GetParentObject() const { return mParent; }
- virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
-
-protected:
- nsCOMPtr<nsISupports> mParent;
-
- double mTimeStamp;
- gfx::VRHMDSensorState mVRState;
-
- RefPtr<DOMPoint> mPosition;
- RefPtr<DOMPoint> mLinearVelocity;
- RefPtr<DOMPoint> mLinearAcceleration;
-
- RefPtr<DOMPoint> mOrientation;
- RefPtr<DOMPoint> mAngularVelocity;
- RefPtr<DOMPoint> mAngularAcceleration;
-};
-
-class VREyeParameters final : public nsWrapperCache
-{
-public:
- VREyeParameters(nsISupports* aParent,
- const gfx::VRFieldOfView& aMinFOV,
- const gfx::VRFieldOfView& aMaxFOV,
- const gfx::VRFieldOfView& aRecFOV,
- const gfx::Point3D& aEyeTranslation,
- const gfx::VRFieldOfView& aCurFOV,
- const gfx::IntRect& aRenderRect);
-
- NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(VREyeParameters)
- NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(VREyeParameters)
-
- VRFieldOfView* MinimumFieldOfView();
- VRFieldOfView* MaximumFieldOfView();
- VRFieldOfView* RecommendedFieldOfView();
- DOMPoint* EyeTranslation();
-
- VRFieldOfView* CurrentFieldOfView();
- DOMRect* RenderRect();
-
- nsISupports* GetParentObject() const { return mParent; }
- virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
-protected:
- ~VREyeParameters() {}
-
- nsCOMPtr<nsISupports> mParent;
-
- RefPtr<VRFieldOfView> mMinFOV;
- RefPtr<VRFieldOfView> mMaxFOV;
- RefPtr<VRFieldOfView> mRecFOV;
- RefPtr<DOMPoint> mEyeTranslation;
- RefPtr<VRFieldOfView> mCurFOV;
- RefPtr<DOMRect> mRenderRect;
-};
-
-class VRDevice : public nsISupports,
- public nsWrapperCache
-{
-public:
-
- NS_DECL_CYCLE_COLLECTING_ISUPPORTS
- NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(VRDevice)
-
- void GetHardwareUnitId(nsAString& aHWID) const { aHWID = mHWID; }
- void GetDeviceId(nsAString& aDeviceId) const { aDeviceId = mDeviceId; }
- void GetDeviceName(nsAString& aDeviceName) const { aDeviceName = mDeviceName; }
-
- bool IsValid() { return mValid; }
-
- nsISupports* GetParentObject() const
- {
- return mParent;
- }
-
- enum VRDeviceType {
- HMD,
- PositionSensor
- };
-
- VRDeviceType GetType() const { return mType; }
-
- static bool RefreshVRDevices(dom::Navigator* aNavigator);
- static void UpdateVRDevices(nsTArray<RefPtr<VRDevice> >& aDevices,
- nsISupports* aParent);
-
- gfx::VRDeviceProxy *GetHMD() {
- return mHMD;
- }
-
-protected:
- VRDevice(nsISupports* aParent,
- gfx::VRDeviceProxy* aHMD,
- VRDeviceType aType)
- : mParent(aParent)
- , mHMD(aHMD)
- , mType(aType)
- , mValid(false)
- {
- MOZ_COUNT_CTOR(VRDevice);
- mHWID.AssignLiteral("uknown");
- mDeviceId.AssignLiteral("unknown");
- mDeviceName.AssignLiteral("unknown");
- }
-
- virtual ~VRDevice()
- {
- MOZ_COUNT_DTOR(VRDevice);
- }
-
- nsCOMPtr<nsISupports> mParent;
- RefPtr<gfx::VRDeviceProxy> mHMD;
- nsString mHWID;
- nsString mDeviceId;
- nsString mDeviceName;
-
- VRDeviceType mType;
-
- bool mValid;
-};
-
-class HMDVRDevice : public VRDevice
-{
-public:
- virtual already_AddRefed<VREyeParameters> GetEyeParameters(VREye aEye) = 0;
-
- virtual void SetFieldOfView(const VRFieldOfViewInit& aLeftFOV,
- const VRFieldOfViewInit& aRightFOV,
- double zNear, double zFar) = 0;
-
- virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
-
-protected:
- HMDVRDevice(nsISupports* aParent, gfx::VRDeviceProxy* aHMD)
- : VRDevice(aParent, aHMD, VRDevice::HMD)
- {
- MOZ_COUNT_CTOR_INHERITED(HMDVRDevice, VRDevice);
- }
-
- virtual ~HMDVRDevice()
- {
- MOZ_COUNT_DTOR_INHERITED(HMDVRDevice, VRDevice);
- }
-};
-
-class HMDInfoVRDevice : public HMDVRDevice
-{
-public:
- HMDInfoVRDevice(nsISupports* aParent, gfx::VRDeviceProxy* aHMD);
- virtual ~HMDInfoVRDevice();
-
- /* If a field of view that is set to all 0's is passed in,
- * the recommended field of view for that eye is used.
- */
- virtual void SetFieldOfView(const VRFieldOfViewInit& aLeftFOV,
- const VRFieldOfViewInit& aRightFOV,
- double zNear, double zFar) override;
- virtual already_AddRefed<VREyeParameters> GetEyeParameters(VREye aEye) override;
-};
-
-class PositionSensorVRDevice : public VRDevice
-{
-public:
- virtual already_AddRefed<VRPositionState> GetState() = 0;
- virtual already_AddRefed<VRPositionState> GetImmediateState() = 0;
- virtual void ResetSensor() = 0;
- virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
-
-protected:
- explicit PositionSensorVRDevice(nsISupports* aParent, gfx::VRDeviceProxy* aHMD)
- : VRDevice(aParent, aHMD, VRDevice::PositionSensor)
- {
- MOZ_COUNT_CTOR_INHERITED(PositionSensorVRDevice, VRDevice);
- }
-
- virtual ~PositionSensorVRDevice()
- {
- MOZ_COUNT_DTOR_INHERITED(PositionSensorVRDevice, VRDevice);
- }
-};
-
-class HMDPositionVRDevice : public PositionSensorVRDevice
-{
-public:
- HMDPositionVRDevice(nsISupports* aParent, gfx::VRDeviceProxy* aHMD);
- ~HMDPositionVRDevice();
-
- virtual already_AddRefed<VRPositionState> GetState() override;
- virtual already_AddRefed<VRPositionState> GetImmediateState() override;
- virtual void ResetSensor() override;
-};
-
-} // namespace dom
-} // namespace mozilla
-
-#endif
new file mode 100644
--- /dev/null
+++ b/dom/vr/VRDisplay.cpp
@@ -0,0 +1,367 @@
+/* -*- 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/VRDisplayBinding.h"
+#include "mozilla/dom/ElementBinding.h"
+#include "mozilla/dom/VRDisplay.h"
+#include "Navigator.h"
+#include "gfxVR.h"
+#include "VRDisplayProxy.h"
+#include "VRManagerChild.h"
+#include "nsIFrame.h"
+
+using namespace mozilla::gfx;
+
+namespace mozilla {
+namespace dom {
+
+/*static*/ bool
+VRDisplay::RefreshVRDisplays(dom::Navigator* aNavigator)
+{
+ gfx::VRManagerChild* vm = gfx::VRManagerChild::Get();
+ return vm && vm->RefreshVRDisplaysWithCallback(aNavigator);
+}
+
+/*static*/ void
+VRDisplay::UpdateVRDisplays(nsTArray<RefPtr<VRDisplay>>& aDevices, nsISupports* aParent)
+{
+ nsTArray<RefPtr<VRDisplay>> devices;
+
+ gfx::VRManagerChild* vm = gfx::VRManagerChild::Get();
+ nsTArray<RefPtr<gfx::VRDisplayProxy>> proxyDevices;
+ if (vm && vm->GetVRDisplays(proxyDevices)) {
+ for (size_t i = 0; i < proxyDevices.Length(); i++) {
+ RefPtr<gfx::VRDisplayProxy> proxyDevice = proxyDevices[i];
+ bool isNewDevice = true;
+ for (size_t j = 0; j < aDevices.Length(); j++) {
+ if (aDevices[j]->GetHMD()->GetDeviceInfo() == proxyDevice->GetDeviceInfo()) {
+ devices.AppendElement(aDevices[j]);
+ isNewDevice = false;
+ }
+ }
+
+ if (isNewDevice) {
+ gfx::VRStateValidFlags sensorBits = proxyDevice->GetDeviceInfo().GetSupportedSensorStateBits();
+ devices.AppendElement(new HMDInfoVRDisplay(aParent, proxyDevice));
+ if (sensorBits & (gfx::VRStateValidFlags::State_Position |
+ gfx::VRStateValidFlags::State_Orientation))
+ {
+ devices.AppendElement(new HMDPositionVRDisplay(aParent, proxyDevice));
+ }
+ }
+ }
+ }
+
+ aDevices = devices;
+}
+
+NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(VRFieldOfViewReadOnly, mParent)
+NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(VRFieldOfViewReadOnly, AddRef)
+NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(VRFieldOfViewReadOnly, Release)
+
+JSObject*
+VRFieldOfViewReadOnly::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
+{
+ return VRFieldOfViewReadOnlyBinding::Wrap(aCx, this, aGivenProto);
+}
+
+already_AddRefed<VRFieldOfView>
+VRFieldOfView::Constructor(const GlobalObject& aGlobal, const VRFieldOfViewInit& aParams,
+ ErrorResult& aRV)
+{
+ RefPtr<VRFieldOfView> fov =
+ new VRFieldOfView(aGlobal.GetAsSupports(),
+ aParams.mUpDegrees, aParams.mRightDegrees,
+ aParams.mDownDegrees, aParams.mLeftDegrees);
+ return fov.forget();
+}
+
+already_AddRefed<VRFieldOfView>
+VRFieldOfView::Constructor(const GlobalObject& aGlobal,
+ double aUpDegrees, double aRightDegrees,
+ double aDownDegrees, double aLeftDegrees,
+ ErrorResult& aRV)
+{
+ RefPtr<VRFieldOfView> fov =
+ new VRFieldOfView(aGlobal.GetAsSupports(),
+ aUpDegrees, aRightDegrees, aDownDegrees,
+ aLeftDegrees);
+ return fov.forget();
+}
+
+JSObject*
+VRFieldOfView::WrapObject(JSContext* aCx,
+ JS::Handle<JSObject*> aGivenProto)
+{
+ return VRFieldOfViewBinding::Wrap(aCx, this, aGivenProto);
+}
+
+NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(VREyeParameters, mParent, mMinFOV, mMaxFOV, mRecFOV, mCurFOV, mEyeTranslation, mRenderRect)
+NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(VREyeParameters, AddRef)
+NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(VREyeParameters, Release)
+
+VREyeParameters::VREyeParameters(nsISupports* aParent,
+ const gfx::VRFieldOfView& aMinFOV,
+ const gfx::VRFieldOfView& aMaxFOV,
+ const gfx::VRFieldOfView& aRecFOV,
+ const gfx::Point3D& aEyeTranslation,
+ const gfx::VRFieldOfView& aCurFOV,
+ const gfx::IntRect& aRenderRect)
+ : mParent(aParent)
+{
+ mMinFOV = new VRFieldOfView(aParent, aMinFOV);
+ mMaxFOV = new VRFieldOfView(aParent, aMaxFOV);
+ mRecFOV = new VRFieldOfView(aParent, aRecFOV);
+ mCurFOV = new VRFieldOfView(aParent, aCurFOV);
+
+ mEyeTranslation = new DOMPoint(aParent, aEyeTranslation.x, aEyeTranslation.y, aEyeTranslation.z, 0.0);
+ mRenderRect = new DOMRect(aParent, aRenderRect.x, aRenderRect.y, aRenderRect.width, aRenderRect.height);
+}
+
+VRFieldOfView*
+VREyeParameters::MinimumFieldOfView()
+{
+ return mMinFOV;
+}
+
+VRFieldOfView*
+VREyeParameters::MaximumFieldOfView()
+{
+ return mMaxFOV;
+}
+
+VRFieldOfView*
+VREyeParameters::RecommendedFieldOfView()
+{
+ return mRecFOV;
+}
+
+VRFieldOfView*
+VREyeParameters::CurrentFieldOfView()
+{
+ return mCurFOV;
+}
+
+DOMPoint*
+VREyeParameters::EyeTranslation()
+{
+ return mEyeTranslation;
+}
+
+DOMRect*
+VREyeParameters::RenderRect()
+{
+ return mRenderRect;
+}
+
+JSObject*
+VREyeParameters::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
+{
+ return VREyeParametersBinding::Wrap(aCx, this, aGivenProto);
+}
+
+NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(VRPositionState, mParent)
+NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(VRPositionState, AddRef)
+NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(VRPositionState, Release)
+
+VRPositionState::VRPositionState(nsISupports* aParent, const gfx::VRHMDSensorState& aState)
+ : mParent(aParent)
+ , mVRState(aState)
+{
+ mTimeStamp = aState.timestamp;
+
+ if (aState.flags & gfx::VRStateValidFlags::State_Position) {
+ mPosition = new DOMPoint(mParent, aState.position[0], aState.position[1], aState.position[2], 0.0);
+ }
+
+ if (aState.flags & gfx::VRStateValidFlags::State_Orientation) {
+ mOrientation = new DOMPoint(mParent, aState.orientation[0], aState.orientation[1], aState.orientation[2], aState.orientation[3]);
+ }
+}
+
+DOMPoint*
+VRPositionState::GetLinearVelocity()
+{
+ if (!mLinearVelocity) {
+ mLinearVelocity = new DOMPoint(mParent, mVRState.linearVelocity[0], mVRState.linearVelocity[1], mVRState.linearVelocity[2], 0.0);
+ }
+ return mLinearVelocity;
+}
+
+DOMPoint*
+VRPositionState::GetLinearAcceleration()
+{
+ if (!mLinearAcceleration) {
+ mLinearAcceleration = new DOMPoint(mParent, mVRState.linearAcceleration[0], mVRState.linearAcceleration[1], mVRState.linearAcceleration[2], 0.0);
+ }
+ return mLinearAcceleration;
+}
+
+DOMPoint*
+VRPositionState::GetAngularVelocity()
+{
+ if (!mAngularVelocity) {
+ mAngularVelocity = new DOMPoint(mParent, mVRState.angularVelocity[0], mVRState.angularVelocity[1], mVRState.angularVelocity[2], 0.0);
+ }
+ return mAngularVelocity;
+}
+
+DOMPoint*
+VRPositionState::GetAngularAcceleration()
+{
+ if (!mAngularAcceleration) {
+ mAngularAcceleration = new DOMPoint(mParent, mVRState.angularAcceleration[0], mVRState.angularAcceleration[1], mVRState.angularAcceleration[2], 0.0);
+ }
+ return mAngularAcceleration;
+}
+
+JSObject*
+VRPositionState::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
+{
+ return VRPositionStateBinding::Wrap(aCx, this, aGivenProto);
+}
+
+NS_IMPL_CYCLE_COLLECTING_ADDREF(VRDisplay)
+NS_IMPL_CYCLE_COLLECTING_RELEASE(VRDisplay)
+
+NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(VRDisplay)
+ NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
+ NS_INTERFACE_MAP_ENTRY(nsISupports)
+NS_INTERFACE_MAP_END
+
+NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(VRDisplay, mParent)
+
+/* virtual */ JSObject*
+HMDVRDisplay::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
+{
+ return HMDVRDisplayBinding::Wrap(aCx, this, aGivenProto);
+}
+
+/* virtual */ JSObject*
+PositionSensorVRDisplay::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
+{
+ return PositionSensorVRDisplayBinding::Wrap(aCx, this, aGivenProto);
+}
+
+HMDInfoVRDisplay::HMDInfoVRDisplay(nsISupports* aParent, gfx::VRDisplayProxy* aHMD)
+ : HMDVRDisplay(aParent, aHMD)
+{
+ MOZ_COUNT_CTOR_INHERITED(HMDInfoVRDisplay, HMDVRDisplay);
+ uint64_t hmdid = aHMD->GetDeviceInfo().GetDeviceID() << 8;
+ uint64_t devid = hmdid | 0x00; // we generate a devid with low byte 0 for the HMD, 1 for the position sensor
+
+ mHWID.Truncate();
+ mHWID.AppendPrintf("0x%llx", hmdid);
+
+ mDeviceId.Truncate();
+ mDeviceId.AppendPrintf("0x%llx", devid);
+
+ mDeviceName.Truncate();
+ mDeviceName.Append(NS_ConvertASCIItoUTF16(aHMD->GetDeviceInfo().GetDeviceName()));
+ mDeviceName.AppendLiteral(" (HMD)");
+
+ mValid = true;
+}
+
+HMDInfoVRDisplay::~HMDInfoVRDisplay()
+{
+ MOZ_COUNT_DTOR_INHERITED(HMDInfoVRDisplay, HMDVRDisplay);
+}
+
+/* If a field of view that is set to all 0's is passed in,
+ * the recommended field of view for that eye is used.
+ */
+void
+HMDInfoVRDisplay::SetFieldOfView(const VRFieldOfViewInit& aLeftFOV,
+ const VRFieldOfViewInit& aRightFOV,
+ double zNear, double zFar)
+{
+ gfx::VRFieldOfView left = gfx::VRFieldOfView(aLeftFOV.mUpDegrees, aLeftFOV.mRightDegrees,
+ aLeftFOV.mDownDegrees, aLeftFOV.mLeftDegrees);
+ gfx::VRFieldOfView right = gfx::VRFieldOfView(aRightFOV.mUpDegrees, aRightFOV.mRightDegrees,
+ aRightFOV.mDownDegrees, aRightFOV.mLeftDegrees);
+
+ if (left.IsZero()) {
+ left = mHMD->GetDeviceInfo().GetRecommendedEyeFOV(VRDisplayInfo::Eye_Left);
+ }
+
+ if (right.IsZero()) {
+ right = mHMD->GetDeviceInfo().GetRecommendedEyeFOV(VRDisplayInfo::Eye_Right);
+ }
+
+ mHMD->SetFOV(left, right, zNear, zFar);
+}
+
+already_AddRefed<VREyeParameters> HMDInfoVRDisplay::GetEyeParameters(VREye aEye)
+{
+ gfx::IntSize sz(mHMD->GetDeviceInfo().SuggestedEyeResolution());
+ gfx::VRDisplayInfo::Eye eye = aEye == VREye::Left ? gfx::VRDisplayInfo::Eye_Left : gfx::VRDisplayInfo::Eye_Right;
+ RefPtr<VREyeParameters> params =
+ new VREyeParameters(mParent,
+ gfx::VRFieldOfView(15, 15, 15, 15), // XXX min?
+ mHMD->GetDeviceInfo().GetMaximumEyeFOV(eye),
+ mHMD->GetDeviceInfo().GetRecommendedEyeFOV(eye),
+ mHMD->GetDeviceInfo().GetEyeTranslation(eye),
+ mHMD->GetDeviceInfo().GetEyeFOV(eye),
+ gfx::IntRect((aEye == VREye::Left) ? 0 : sz.width, 0, sz.width, sz.height));
+ return params.forget();
+}
+
+HMDPositionVRDisplay::HMDPositionVRDisplay(nsISupports* aParent, gfx::VRDisplayProxy* aHMD)
+ : PositionSensorVRDisplay(aParent, aHMD)
+{
+ MOZ_COUNT_CTOR_INHERITED(HMDPositionVRDisplay, PositionSensorVRDisplay);
+
+ uint64_t hmdid = aHMD->GetDeviceInfo().GetDeviceID() << 8;
+ uint64_t devid = hmdid | 0x01; // we generate a devid with low byte 0 for the HMD, 1 for the position sensor
+
+ mHWID.Truncate();
+ mHWID.AppendPrintf("0x%llx", hmdid);
+
+ mDeviceId.Truncate();
+ mDeviceId.AppendPrintf("0x%llx", devid);
+
+ mDeviceName.Truncate();
+ mDeviceName.Append(NS_ConvertASCIItoUTF16(aHMD->GetDeviceInfo().GetDeviceName()));
+ mDeviceName.AppendLiteral(" (Sensor)");
+
+ mValid = true;
+}
+
+HMDPositionVRDisplay::~HMDPositionVRDisplay()
+{
+ MOZ_COUNT_DTOR_INHERITED(HMDPositionVRDisplay, PositionSensorVRDisplay);
+}
+
+already_AddRefed<VRPositionState>
+HMDPositionVRDisplay::GetState()
+{
+ gfx::VRHMDSensorState state = mHMD->GetSensorState();
+ RefPtr<VRPositionState> obj = new VRPositionState(mParent, state);
+
+ return obj.forget();
+}
+
+already_AddRefed<VRPositionState>
+HMDPositionVRDisplay::GetImmediateState()
+{
+ gfx::VRHMDSensorState state = mHMD->GetImmediateSensorState();
+ RefPtr<VRPositionState> obj = new VRPositionState(mParent, state);
+
+ return obj.forget();
+}
+
+void
+HMDPositionVRDisplay::ResetSensor()
+{
+ mHMD->ZeroSensor();
+}
+
+} // namespace dom
+} // namespace mozilla
new file mode 100644
--- /dev/null
+++ b/dom/vr/VRDisplay.h
@@ -0,0 +1,317 @@
+/* -*- 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/dom/DOMPoint.h"
+#include "mozilla/dom/DOMRect.h"
+
+#include "nsCOMPtr.h"
+#include "nsString.h"
+#include "nsTArray.h"
+#include "nsWrapperCache.h"
+
+#include "gfxVR.h"
+#include "VRDisplayProxy.h"
+
+namespace mozilla {
+namespace dom {
+class Navigator;
+
+class VRFieldOfViewReadOnly : public nsWrapperCache
+{
+public:
+ VRFieldOfViewReadOnly(nsISupports* aParent,
+ double aUpDegrees, double aRightDegrees,
+ double aDownDegrees, double aLeftDegrees)
+ : mParent(aParent)
+ , mUpDegrees(aUpDegrees)
+ , mRightDegrees(aRightDegrees)
+ , mDownDegrees(aDownDegrees)
+ , mLeftDegrees(aLeftDegrees)
+ {
+ }
+
+ NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(VRFieldOfViewReadOnly)
+ NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(VRFieldOfViewReadOnly)
+
+ 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 ~VRFieldOfViewReadOnly() {}
+
+ nsCOMPtr<nsISupports> mParent;
+
+ double mUpDegrees;
+ double mRightDegrees;
+ double mDownDegrees;
+ double mLeftDegrees;
+};
+
+class VRFieldOfView final : public VRFieldOfViewReadOnly
+{
+public:
+ VRFieldOfView(nsISupports* aParent, const gfx::VRFieldOfView& aSrc)
+ : VRFieldOfViewReadOnly(aParent,
+ aSrc.upDegrees, aSrc.rightDegrees,
+ aSrc.downDegrees, aSrc.leftDegrees)
+ {}
+
+ explicit VRFieldOfView(nsISupports* aParent,
+ double aUpDegrees = 0.0, double aRightDegrees = 0.0,
+ double aDownDegrees = 0.0, double aLeftDegrees = 0.0)
+ : VRFieldOfViewReadOnly(aParent,
+ aUpDegrees, aRightDegrees, aDownDegrees, aLeftDegrees)
+ {}
+
+ static already_AddRefed<VRFieldOfView>
+ Constructor(const GlobalObject& aGlobal, const VRFieldOfViewInit& aParams,
+ ErrorResult& aRv);
+
+ static already_AddRefed<VRFieldOfView>
+ Constructor(const GlobalObject& aGlobal,
+ double aUpDegrees, double aRightDegrees,
+ double aDownDegrees, double aLeftDegrees,
+ ErrorResult& aRv);
+
+ virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
+
+ void SetUpDegrees(double aVal) { mUpDegrees = aVal; }
+ void SetRightDegrees(double aVal) { mRightDegrees = aVal; }
+ void SetDownDegrees(double aVal) { mDownDegrees = aVal; }
+ void SetLeftDegrees(double aVal) { mLeftDegrees = aVal; }
+};
+
+class VRPositionState final : public nsWrapperCache
+{
+ ~VRPositionState() {}
+public:
+ VRPositionState(nsISupports* aParent, const gfx::VRHMDSensorState& aState);
+
+ NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(VRPositionState)
+ NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(VRPositionState)
+
+ double TimeStamp() const { return mTimeStamp; }
+
+ bool HasPosition() const { return mPosition != nullptr; }
+ DOMPoint* GetPosition() const { return mPosition; }
+
+ bool HasOrientation() const { return mOrientation != nullptr; }
+ DOMPoint* GetOrientation() const { return mOrientation; }
+
+ // these are created lazily
+ DOMPoint* GetLinearVelocity();
+ DOMPoint* GetLinearAcceleration();
+ DOMPoint* GetAngularVelocity();
+ DOMPoint* GetAngularAcceleration();
+
+ nsISupports* GetParentObject() const { return mParent; }
+ virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
+
+protected:
+ nsCOMPtr<nsISupports> mParent;
+
+ double mTimeStamp;
+ gfx::VRHMDSensorState mVRState;
+
+ RefPtr<DOMPoint> mPosition;
+ RefPtr<DOMPoint> mLinearVelocity;
+ RefPtr<DOMPoint> mLinearAcceleration;
+
+ RefPtr<DOMPoint> mOrientation;
+ RefPtr<DOMPoint> mAngularVelocity;
+ RefPtr<DOMPoint> mAngularAcceleration;
+};
+
+class VREyeParameters final : public nsWrapperCache
+{
+public:
+ VREyeParameters(nsISupports* aParent,
+ const gfx::VRFieldOfView& aMinFOV,
+ const gfx::VRFieldOfView& aMaxFOV,
+ const gfx::VRFieldOfView& aRecFOV,
+ const gfx::Point3D& aEyeTranslation,
+ const gfx::VRFieldOfView& aCurFOV,
+ const gfx::IntRect& aRenderRect);
+
+ NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(VREyeParameters)
+ NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(VREyeParameters)
+
+ VRFieldOfView* MinimumFieldOfView();
+ VRFieldOfView* MaximumFieldOfView();
+ VRFieldOfView* RecommendedFieldOfView();
+ DOMPoint* EyeTranslation();
+
+ VRFieldOfView* CurrentFieldOfView();
+ DOMRect* RenderRect();
+
+ nsISupports* GetParentObject() const { return mParent; }
+ virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
+protected:
+ ~VREyeParameters() {}
+
+ nsCOMPtr<nsISupports> mParent;
+
+ RefPtr<VRFieldOfView> mMinFOV;
+ RefPtr<VRFieldOfView> mMaxFOV;
+ RefPtr<VRFieldOfView> mRecFOV;
+ RefPtr<DOMPoint> mEyeTranslation;
+ RefPtr<VRFieldOfView> mCurFOV;
+ RefPtr<DOMRect> mRenderRect;
+};
+
+class VRDisplay : public nsISupports,
+ public nsWrapperCache
+{
+public:
+
+ NS_DECL_CYCLE_COLLECTING_ISUPPORTS
+ NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(VRDisplay)
+
+ void GetHardwareUnitId(nsAString& aHWID) const { aHWID = mHWID; }
+ void GetDeviceId(nsAString& aDeviceId) const { aDeviceId = mDeviceId; }
+ void GetDeviceName(nsAString& aDeviceName) const { aDeviceName = mDeviceName; }
+
+ bool IsValid() { return mValid; }
+
+ nsISupports* GetParentObject() const
+ {
+ return mParent;
+ }
+
+ enum VRDisplayType {
+ HMD,
+ PositionSensor
+ };
+
+ VRDisplayType GetType() const { return mType; }
+
+ static bool RefreshVRDisplays(dom::Navigator* aNavigator);
+ static void UpdateVRDisplays(nsTArray<RefPtr<VRDisplay> >& aDevices,
+ nsISupports* aParent);
+
+ gfx::VRDisplayProxy *GetHMD() {
+ return mHMD;
+ }
+
+protected:
+ VRDisplay(nsISupports* aParent,
+ gfx::VRDisplayProxy* aHMD,
+ VRDisplayType aType)
+ : mParent(aParent)
+ , mHMD(aHMD)
+ , mType(aType)
+ , mValid(false)
+ {
+ MOZ_COUNT_CTOR(VRDisplay);
+ mHWID.AssignLiteral("uknown");
+ mDeviceId.AssignLiteral("unknown");
+ mDeviceName.AssignLiteral("unknown");
+ }
+
+ virtual ~VRDisplay()
+ {
+ MOZ_COUNT_DTOR(VRDisplay);
+ }
+
+ nsCOMPtr<nsISupports> mParent;
+ RefPtr<gfx::VRDisplayProxy> mHMD;
+ nsString mHWID;
+ nsString mDeviceId;
+ nsString mDeviceName;
+
+ VRDisplayType mType;
+
+ bool mValid;
+};
+
+class HMDVRDisplay : public VRDisplay
+{
+public:
+ virtual already_AddRefed<VREyeParameters> GetEyeParameters(VREye aEye) = 0;
+
+ virtual void SetFieldOfView(const VRFieldOfViewInit& aLeftFOV,
+ const VRFieldOfViewInit& aRightFOV,
+ double zNear, double zFar) = 0;
+
+ virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
+
+protected:
+ HMDVRDisplay(nsISupports* aParent, gfx::VRDisplayProxy* aHMD)
+ : VRDisplay(aParent, aHMD, VRDisplay::HMD)
+ {
+ MOZ_COUNT_CTOR_INHERITED(HMDVRDisplay, VRDisplay);
+ }
+
+ virtual ~HMDVRDisplay()
+ {
+ MOZ_COUNT_DTOR_INHERITED(HMDVRDisplay, VRDisplay);
+ }
+};
+
+class HMDInfoVRDisplay : public HMDVRDisplay
+{
+public:
+ HMDInfoVRDisplay(nsISupports* aParent, gfx::VRDisplayProxy* aHMD);
+ virtual ~HMDInfoVRDisplay();
+
+ /* If a field of view that is set to all 0's is passed in,
+ * the recommended field of view for that eye is used.
+ */
+ virtual void SetFieldOfView(const VRFieldOfViewInit& aLeftFOV,
+ const VRFieldOfViewInit& aRightFOV,
+ double zNear, double zFar) override;
+ virtual already_AddRefed<VREyeParameters> GetEyeParameters(VREye aEye) override;
+};
+
+class PositionSensorVRDisplay : public VRDisplay
+{
+public:
+ virtual already_AddRefed<VRPositionState> GetState() = 0;
+ virtual already_AddRefed<VRPositionState> GetImmediateState() = 0;
+ virtual void ResetSensor() = 0;
+ virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
+
+protected:
+ explicit PositionSensorVRDisplay(nsISupports* aParent, gfx::VRDisplayProxy* aHMD)
+ : VRDisplay(aParent, aHMD, VRDisplay::PositionSensor)
+ {
+ MOZ_COUNT_CTOR_INHERITED(PositionSensorVRDisplay, VRDisplay);
+ }
+
+ virtual ~PositionSensorVRDisplay()
+ {
+ MOZ_COUNT_DTOR_INHERITED(PositionSensorVRDisplay, VRDisplay);
+ }
+};
+
+class HMDPositionVRDisplay : public PositionSensorVRDisplay
+{
+public:
+ HMDPositionVRDisplay(nsISupports* aParent, gfx::VRDisplayProxy* aHMD);
+ ~HMDPositionVRDisplay();
+
+ virtual already_AddRefed<VRPositionState> GetState() override;
+ virtual already_AddRefed<VRPositionState> GetImmediateState() override;
+ virtual void ResetSensor() override;
+};
+
+} // namespace dom
+} // namespace mozilla
+
+#endif
--- a/dom/vr/moz.build
+++ b/dom/vr/moz.build
@@ -1,20 +1,20 @@
# -*- 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 += [
- 'VRDevice.h',
+ 'VRDisplay.h',
]
UNIFIED_SOURCES = [
- 'VRDevice.cpp',
+ 'VRDisplay.cpp',
]
include('/ipc/chromium/chromium-config.mozbuild')
FINAL_LIBRARY = 'xul'
LOCAL_INCLUDES += [
'/dom/base'
]
--- a/dom/webidl/Navigator.webidl
+++ b/dom/webidl/Navigator.webidl
@@ -336,17 +336,17 @@ partial interface Navigator {
partial interface Navigator {
[Pref="dom.gamepad.test.enabled"]
GamepadServiceTest requestGamepadServiceTest();
};
#endif // MOZ_GAMEPAD
partial interface Navigator {
[Throws, Pref="dom.vr.enabled"]
- Promise<sequence<VRDevice>> getVRDevices();
+ Promise<sequence<VRDisplay>> getVRDisplays();
};
#ifdef MOZ_B2G_BT
partial interface Navigator {
[Throws, ChromeOnly, UnsafeInPrerendering]
readonly attribute BluetoothManager mozBluetooth;
};
#endif // MOZ_B2G_BT
deleted file mode 100644
--- a/dom/webidl/VRDevice.webidl
+++ /dev/null
@@ -1,130 +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/VRDevice.h"]
-interface VRFieldOfViewReadOnly {
- readonly attribute double upDegrees;
- readonly attribute double rightDegrees;
- readonly attribute double downDegrees;
- readonly attribute double leftDegrees;
-};
-
-[Pref="dom.vr.enabled",
- HeaderFile="mozilla/dom/VRDevice.h",
- Constructor(optional VRFieldOfViewInit fov),
- Constructor(double upDegrees, double rightDegrees, double downDegrees, double leftDegrees)]
-interface VRFieldOfView : VRFieldOfViewReadOnly {
- inherit attribute double upDegrees;
- inherit attribute double rightDegrees;
- inherit attribute double downDegrees;
- inherit attribute double leftDegrees;
-};
-
-dictionary VRFieldOfViewInit {
- double upDegrees = 0.0;
- double rightDegrees = 0.0;
- double downDegrees = 0.0;
- double leftDegrees = 0.0;
-};
-
-[Pref="dom.vr.enabled",
- HeaderFile="mozilla/dom/VRDevice.h"]
-interface VRPositionState {
- readonly attribute double timeStamp;
-
- readonly attribute boolean hasPosition;
- readonly attribute DOMPoint? position;
- readonly attribute DOMPoint? linearVelocity;
- readonly attribute DOMPoint? linearAcceleration;
-
- readonly attribute boolean hasOrientation;
- // XXX should be DOMQuaternion as soon as we add that
- readonly attribute DOMPoint? orientation;
- readonly attribute DOMPoint? angularVelocity;
- readonly attribute DOMPoint? angularAcceleration;
-};
-
-[Pref="dom.vr.enabled",
- HeaderFile="mozilla/dom/VRDevice.h"]
-interface VREyeParameters {
- /* These values are expected to be static per-device/per-user */
- [Constant, Cached] readonly attribute VRFieldOfView minimumFieldOfView;
- [Constant, Cached] readonly attribute VRFieldOfView maximumFieldOfView;
- [Constant, Cached] readonly attribute VRFieldOfView recommendedFieldOfView;
- [Constant, Cached] readonly attribute DOMPoint eyeTranslation;
-
- /* These values will vary after a FOV has been set */
- [Constant, Cached] readonly attribute VRFieldOfView currentFieldOfView;
- [Constant, Cached] readonly attribute DOMRect renderRect;
-};
-
-[Pref="dom.vr.enabled"]
-interface VRDevice {
- /**
- * An identifier for the distinct hardware unit that this
- * VR Device is a part of. All VRDevice/Sensors that come
- * from the same hardware will have the same hardwareId
- */
- [Constant] readonly attribute DOMString hardwareUnitId;
-
- /**
- * An identifier for this distinct sensor/device on a physical
- * hardware device. This shouldn't change across browser
- * restrats, allowing configuration data to be saved based on it.
- */
- [Constant] readonly attribute DOMString deviceId;
-
- /**
- * a device name, a user-readable name identifying it
- */
- [Constant] readonly attribute DOMString deviceName;
-};
-
-[Pref="dom.vr.enabled",
- HeaderFile="mozilla/dom/VRDevice.h"]
-interface HMDVRDevice : VRDevice {
- // Return the current VREyeParameters for the given eye
- VREyeParameters getEyeParameters(VREye whichEye);
-
- // Set a field of view. If either of the fields of view is null,
- // or if their values are all zeros, then the recommended field of view
- // for that eye will be used.
- void setFieldOfView(optional VRFieldOfViewInit leftFOV,
- optional VRFieldOfViewInit rightFOV,
- optional double zNear = 0.01,
- optional double zFar = 10000.0);
-};
-
-[Pref="dom.vr.enabled" ,
- HeaderFile="mozilla/dom/VRDevice.h"]
-interface PositionSensorVRDevice : VRDevice {
- /*
- * Return a VRPositionState dictionary containing the state of this position sensor
- * for the current frame if within a requestAnimationFrame callback, or for the
- * previous frame if not.
- *
- * The VRPositionState will contain the position, orientation, and velocity
- * and acceleration of each of these properties. Use "hasPosition" and "hasOrientation"
- * to check if the associated members are valid; if these are false, those members
- * will be null.
- */
- [NewObject] VRPositionState getState();
-
- /*
- * Return the current instantaneous sensor state.
- */
- [NewObject] VRPositionState getImmediateState();
-
- /* Reset this sensor, treating its current position and orientation
- * as the "origin/zero" values.
- */
- void resetSensor();
-};
new file mode 100644
--- /dev/null
+++ b/dom/webidl/VRDisplay.webidl
@@ -0,0 +1,130 @@
+/* -*- 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 VRFieldOfViewReadOnly {
+ readonly attribute double upDegrees;
+ readonly attribute double rightDegrees;
+ readonly attribute double downDegrees;
+ readonly attribute double leftDegrees;
+};
+
+[Pref="dom.vr.enabled",
+ HeaderFile="mozilla/dom/VRDisplay.h",
+ Constructor(optional VRFieldOfViewInit fov),
+ Constructor(double upDegrees, double rightDegrees, double downDegrees, double leftDegrees)]
+interface VRFieldOfView : VRFieldOfViewReadOnly {
+ inherit attribute double upDegrees;
+ inherit attribute double rightDegrees;
+ inherit attribute double downDegrees;
+ inherit attribute double leftDegrees;
+};
+
+dictionary VRFieldOfViewInit {
+ double upDegrees = 0.0;
+ double rightDegrees = 0.0;
+ double downDegrees = 0.0;
+ double leftDegrees = 0.0;
+};
+
+[Pref="dom.vr.enabled",
+ HeaderFile="mozilla/dom/VRDisplay.h"]
+interface VRPositionState {
+ readonly attribute double timeStamp;
+
+ readonly attribute boolean hasPosition;
+ readonly attribute DOMPoint? position;
+ readonly attribute DOMPoint? linearVelocity;
+ readonly attribute DOMPoint? linearAcceleration;
+
+ readonly attribute boolean hasOrientation;
+ // XXX should be DOMQuaternion as soon as we add that
+ readonly attribute DOMPoint? orientation;
+ readonly attribute DOMPoint? angularVelocity;
+ readonly attribute DOMPoint? angularAcceleration;
+};
+
+[Pref="dom.vr.enabled",
+ HeaderFile="mozilla/dom/VRDisplay.h"]
+interface VREyeParameters {
+ /* These values are expected to be static per-device/per-user */
+ [Constant, Cached] readonly attribute VRFieldOfView minimumFieldOfView;
+ [Constant, Cached] readonly attribute VRFieldOfView maximumFieldOfView;
+ [Constant, Cached] readonly attribute VRFieldOfView recommendedFieldOfView;
+ [Constant, Cached] readonly attribute DOMPoint eyeTranslation;
+
+ /* These values will vary after a FOV has been set */
+ [Constant, Cached] readonly attribute VRFieldOfView currentFieldOfView;
+ [Constant, Cached] readonly attribute DOMRect renderRect;
+};
+
+[Pref="dom.vr.enabled"]
+interface VRDisplay {
+ /**
+ * An identifier for the distinct hardware unit that this
+ * VR Device is a part of. All VRDisplay/Sensors that come
+ * from the same hardware will have the same hardwareId
+ */
+ [Constant] readonly attribute DOMString hardwareUnitId;
+
+ /**
+ * An identifier for this distinct sensor/device on a physical
+ * hardware device. This shouldn't change across browser
+ * restrats, allowing configuration data to be saved based on it.
+ */
+ [Constant] readonly attribute DOMString deviceId;
+
+ /**
+ * a device name, a user-readable name identifying it
+ */
+ [Constant] readonly attribute DOMString deviceName;
+};
+
+[Pref="dom.vr.enabled",
+ HeaderFile="mozilla/dom/VRDisplay.h"]
+interface HMDVRDisplay : VRDisplay {
+ // Return the current VREyeParameters for the given eye
+ VREyeParameters getEyeParameters(VREye whichEye);
+
+ // Set a field of view. If either of the fields of view is null,
+ // or if their values are all zeros, then the recommended field of view
+ // for that eye will be used.
+ void setFieldOfView(optional VRFieldOfViewInit leftFOV,
+ optional VRFieldOfViewInit rightFOV,
+ optional double zNear = 0.01,
+ optional double zFar = 10000.0);
+};
+
+[Pref="dom.vr.enabled" ,
+ HeaderFile="mozilla/dom/VRDisplay.h"]
+interface PositionSensorVRDisplay : VRDisplay {
+ /*
+ * Return a VRPositionState dictionary containing the state of this position sensor
+ * for the current frame if within a requestAnimationFrame callback, or for the
+ * previous frame if not.
+ *
+ * The VRPositionState will contain the position, orientation, and velocity
+ * and acceleration of each of these properties. Use "hasPosition" and "hasOrientation"
+ * to check if the associated members are valid; if these are false, those members
+ * will be null.
+ */
+ [NewObject] VRPositionState getState();
+
+ /*
+ * Return the current instantaneous sensor state.
+ */
+ [NewObject] VRPositionState getImmediateState();
+
+ /* Reset this sensor, treating its current position and orientation
+ * as the "origin/zero" values.
+ */
+ void resetSensor();
+};
--- a/dom/webidl/moz.build
+++ b/dom/webidl/moz.build
@@ -576,17 +576,17 @@ WEBIDL_FILES = [
'URL.webidl',
'URLSearchParams.webidl',
'USSDSession.webidl',
'ValidityState.webidl',
'VideoPlaybackQuality.webidl',
'VideoStreamTrack.webidl',
'VideoTrack.webidl',
'VideoTrackList.webidl',
- 'VRDevice.webidl',
+ 'VRDisplay.webidl',
'VTTCue.webidl',
'VTTRegion.webidl',
'WaveShaperNode.webidl',
'WebComponents.webidl',
'WebGL2RenderingContext.webidl',
'WebGLRenderingContext.webidl',
'WebKitCSSMatrix.webidl',
'WebSocket.webidl',
deleted file mode 100644
--- a/gfx/vr/VRDeviceProxy.cpp
+++ /dev/null
@@ -1,165 +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 "VRDeviceProxy.h"
-#include "VRManagerChild.h"
-
-using namespace mozilla;
-using namespace mozilla::gfx;
-
-VRDeviceProxy::VRDeviceProxy(const VRDeviceUpdate& aDeviceUpdate)
- : mDeviceInfo(aDeviceUpdate.mDeviceInfo)
- , mSensorState(aDeviceUpdate.mSensorState)
-{
- MOZ_COUNT_CTOR(VRDeviceProxy);
-
- if (mDeviceInfo.mScreenRect.width && mDeviceInfo.mScreenRect.height) {
- if (mDeviceInfo.mIsFakeScreen) {
- mScreen = MakeFakeScreen(mDeviceInfo.mScreenRect);
- } else {
- nsCOMPtr<nsIScreenManager> screenmgr = do_GetService("@mozilla.org/gfx/screenmanager;1");
- if (screenmgr) {
- screenmgr->ScreenForRect(mDeviceInfo.mScreenRect.x, mDeviceInfo.mScreenRect.y,
- mDeviceInfo.mScreenRect.width, mDeviceInfo.mScreenRect.height,
- getter_AddRefs(mScreen));
- }
- }
-#ifdef DEBUG
- printf_stderr("VR DEVICE SCREEN: %d %d %d %d\n",
- mDeviceInfo.mScreenRect.x, mDeviceInfo.mScreenRect.y,
- mDeviceInfo.mScreenRect.width, mDeviceInfo.mScreenRect.height);
-#endif
- }
-}
-
-VRDeviceProxy::~VRDeviceProxy() {
- MOZ_COUNT_DTOR(VRDeviceProxy);
-}
-
-void
-VRDeviceProxy::UpdateDeviceInfo(const VRDeviceUpdate& aDeviceUpdate)
-{
- mDeviceInfo = aDeviceUpdate.mDeviceInfo;
- mSensorState = aDeviceUpdate.mSensorState;
-}
-
-bool
-VRDeviceProxy::SetFOV(const VRFieldOfView& aFOVLeft, const VRFieldOfView& aFOVRight,
- double zNear, double zFar)
-{
- VRManagerChild *vm = VRManagerChild::Get();
- vm->SendSetFOV(mDeviceInfo.mDeviceID, aFOVLeft, aFOVRight, zNear, zFar);
- return true;
-}
-
-void
-VRDeviceProxy::ZeroSensor()
-{
- VRManagerChild *vm = VRManagerChild::Get();
- vm->SendResetSensor(mDeviceInfo.mDeviceID);
-}
-
-VRHMDSensorState
-VRDeviceProxy::GetSensorState()
-{
- VRManagerChild *vm = VRManagerChild::Get();
- Unused << vm->SendKeepSensorTracking(mDeviceInfo.mDeviceID);
- return mSensorState;
-}
-
-VRHMDSensorState
-VRDeviceProxy::GetImmediateSensorState()
-{
- // XXX TODO - Need to perform IPC call to get the current sensor
- // state rather than the predictive state used for the frame rendering.
- return GetSensorState();
-}
-
-void
-VRDeviceProxy::UpdateSensorState(const VRHMDSensorState& aSensorState)
-{
- mSensorState = aSensorState;
-}
-
-// Dummy nsIScreen implementation, for when we just need to specify a size
-class FakeScreen : public nsIScreen
-{
-public:
- explicit FakeScreen(const IntRect& aScreenRect)
- : mScreenRect(aScreenRect)
- { }
-
- NS_DECL_ISUPPORTS
-
- NS_IMETHOD GetRect(int32_t *l, int32_t *t, int32_t *w, int32_t *h) override {
- *l = mScreenRect.x;
- *t = mScreenRect.y;
- *w = mScreenRect.width;
- *h = mScreenRect.height;
- return NS_OK;
- }
- NS_IMETHOD GetAvailRect(int32_t *l, int32_t *t, int32_t *w, int32_t *h) override {
- return GetRect(l, t, w, h);
- }
- NS_IMETHOD GetRectDisplayPix(int32_t *l, int32_t *t, int32_t *w, int32_t *h) override {
- return GetRect(l, t, w, h);
- }
- NS_IMETHOD GetAvailRectDisplayPix(int32_t *l, int32_t *t, int32_t *w, int32_t *h) override {
- return GetAvailRect(l, t, w, h);
- }
-
- NS_IMETHOD GetId(uint32_t* aId) override { *aId = (uint32_t)-1; return NS_OK; }
- NS_IMETHOD GetPixelDepth(int32_t* aPixelDepth) override { *aPixelDepth = 24; return NS_OK; }
- NS_IMETHOD GetColorDepth(int32_t* aColorDepth) override { *aColorDepth = 24; return NS_OK; }
-
- NS_IMETHOD LockMinimumBrightness(uint32_t aBrightness) override { return NS_ERROR_NOT_AVAILABLE; }
- NS_IMETHOD UnlockMinimumBrightness(uint32_t aBrightness) override { return NS_ERROR_NOT_AVAILABLE; }
- NS_IMETHOD GetRotation(uint32_t* aRotation) override {
- *aRotation = nsIScreen::ROTATION_0_DEG;
- return NS_OK;
- }
- NS_IMETHOD SetRotation(uint32_t aRotation) override { return NS_ERROR_NOT_AVAILABLE; }
- NS_IMETHOD GetContentsScaleFactor(double* aContentsScaleFactor) override {
- *aContentsScaleFactor = 1.0;
- return NS_OK;
- }
- NS_IMETHOD GetDefaultCSSScaleFactor(double* aScaleFactor) override {
- *aScaleFactor = 1.0;
- return NS_OK;
- }
-
-protected:
- virtual ~FakeScreen() {}
-
- IntRect mScreenRect;
-};
-
-NS_IMPL_ISUPPORTS(FakeScreen, nsIScreen)
-
-
-/* static */ already_AddRefed<nsIScreen>
-VRDeviceProxy::MakeFakeScreen(const IntRect& aScreenRect)
-{
- nsCOMPtr<nsIScreen> screen = new FakeScreen(aScreenRect);
- return screen.forget();
-}
-
deleted file mode 100644
--- a/gfx/vr/VRDeviceProxy.h
+++ /dev/null
@@ -1,58 +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_PROXY_H
-#define GFX_VR_PROXY_H
-
-#include "nsIScreen.h"
-#include "nsCOMPtr.h"
-#include "mozilla/RefPtr.h"
-
-#include "gfxVR.h"
-
-namespace mozilla {
-namespace gfx {
-
-class VRManagerChild;
-
-class VRDeviceProxy
-{
-public:
- NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VRDeviceProxy)
-
- explicit VRDeviceProxy(const VRDeviceUpdate& aDeviceUpdate);
-
- void UpdateDeviceInfo(const VRDeviceUpdate& aDeviceUpdate);
- void UpdateSensorState(const VRHMDSensorState& aSensorState);
-
- const VRDeviceInfo& GetDeviceInfo() const { return mDeviceInfo; }
- virtual VRHMDSensorState GetSensorState();
- virtual VRHMDSensorState GetImmediateSensorState();
-
- bool SetFOV(const VRFieldOfView& aFOVLeft, const VRFieldOfView& aFOVRight,
- double zNear, double zFar);
-
- virtual void ZeroSensor();
-
-
- // The nsIScreen that represents this device
- nsIScreen* GetScreen() { return mScreen; }
-
-protected:
- virtual ~VRDeviceProxy();
-
- VRDeviceInfo mDeviceInfo;
- VRHMDSensorState mSensorState;
-
- nsCOMPtr<nsIScreen> mScreen;
-
- static already_AddRefed<nsIScreen> MakeFakeScreen(const IntRect& aScreenRect);
-
-};
-
-} // namespace gfx
-} // namespace mozilla
-
-#endif /* GFX_VR_PROXY_H */
new file mode 100644
--- /dev/null
+++ b/gfx/vr/VRDisplayProxy.cpp
@@ -0,0 +1,165 @@
+/* -*- 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 "VRDisplayProxy.h"
+#include "VRManagerChild.h"
+
+using namespace mozilla;
+using namespace mozilla::gfx;
+
+VRDisplayProxy::VRDisplayProxy(const VRDisplayUpdate& aDeviceUpdate)
+ : mDeviceInfo(aDeviceUpdate.mDeviceInfo)
+ , mSensorState(aDeviceUpdate.mSensorState)
+{
+ MOZ_COUNT_CTOR(VRDisplayProxy);
+
+ if (mDeviceInfo.mScreenRect.width && mDeviceInfo.mScreenRect.height) {
+ if (mDeviceInfo.mIsFakeScreen) {
+ mScreen = MakeFakeScreen(mDeviceInfo.mScreenRect);
+ } else {
+ nsCOMPtr<nsIScreenManager> screenmgr = do_GetService("@mozilla.org/gfx/screenmanager;1");
+ if (screenmgr) {
+ screenmgr->ScreenForRect(mDeviceInfo.mScreenRect.x, mDeviceInfo.mScreenRect.y,
+ mDeviceInfo.mScreenRect.width, mDeviceInfo.mScreenRect.height,
+ getter_AddRefs(mScreen));
+ }
+ }
+#ifdef DEBUG
+ printf_stderr("VR DEVICE SCREEN: %d %d %d %d\n",
+ mDeviceInfo.mScreenRect.x, mDeviceInfo.mScreenRect.y,
+ mDeviceInfo.mScreenRect.width, mDeviceInfo.mScreenRect.height);
+#endif
+ }
+}
+
+VRDisplayProxy::~VRDisplayProxy() {
+ MOZ_COUNT_DTOR(VRDisplayProxy);
+}
+
+void
+VRDisplayProxy::UpdateDeviceInfo(const VRDisplayUpdate& aDeviceUpdate)
+{
+ mDeviceInfo = aDeviceUpdate.mDeviceInfo;
+ mSensorState = aDeviceUpdate.mSensorState;
+}
+
+bool
+VRDisplayProxy::SetFOV(const VRFieldOfView& aFOVLeft, const VRFieldOfView& aFOVRight,
+ double zNear, double zFar)
+{
+ VRManagerChild *vm = VRManagerChild::Get();
+ vm->SendSetFOV(mDeviceInfo.mDeviceID, aFOVLeft, aFOVRight, zNear, zFar);
+ return true;
+}
+
+void
+VRDisplayProxy::ZeroSensor()
+{
+ VRManagerChild *vm = VRManagerChild::Get();
+ vm->SendResetSensor(mDeviceInfo.mDeviceID);
+}
+
+VRHMDSensorState
+VRDisplayProxy::GetSensorState()
+{
+ VRManagerChild *vm = VRManagerChild::Get();
+ Unused << vm->SendKeepSensorTracking(mDeviceInfo.mDeviceID);
+ return mSensorState;
+}
+
+VRHMDSensorState
+VRDisplayProxy::GetImmediateSensorState()
+{
+ // XXX TODO - Need to perform IPC call to get the current sensor
+ // state rather than the predictive state used for the frame rendering.
+ return GetSensorState();
+}
+
+void
+VRDisplayProxy::UpdateSensorState(const VRHMDSensorState& aSensorState)
+{
+ mSensorState = aSensorState;
+}
+
+// Dummy nsIScreen implementation, for when we just need to specify a size
+class FakeScreen : public nsIScreen
+{
+public:
+ explicit FakeScreen(const IntRect& aScreenRect)
+ : mScreenRect(aScreenRect)
+ { }
+
+ NS_DECL_ISUPPORTS
+
+ NS_IMETHOD GetRect(int32_t *l, int32_t *t, int32_t *w, int32_t *h) override {
+ *l = mScreenRect.x;
+ *t = mScreenRect.y;
+ *w = mScreenRect.width;
+ *h = mScreenRect.height;
+ return NS_OK;
+ }
+ NS_IMETHOD GetAvailRect(int32_t *l, int32_t *t, int32_t *w, int32_t *h) override {
+ return GetRect(l, t, w, h);
+ }
+ NS_IMETHOD GetRectDisplayPix(int32_t *l, int32_t *t, int32_t *w, int32_t *h) override {
+ return GetRect(l, t, w, h);
+ }
+ NS_IMETHOD GetAvailRectDisplayPix(int32_t *l, int32_t *t, int32_t *w, int32_t *h) override {
+ return GetAvailRect(l, t, w, h);
+ }
+
+ NS_IMETHOD GetId(uint32_t* aId) override { *aId = (uint32_t)-1; return NS_OK; }
+ NS_IMETHOD GetPixelDepth(int32_t* aPixelDepth) override { *aPixelDepth = 24; return NS_OK; }
+ NS_IMETHOD GetColorDepth(int32_t* aColorDepth) override { *aColorDepth = 24; return NS_OK; }
+
+ NS_IMETHOD LockMinimumBrightness(uint32_t aBrightness) override { return NS_ERROR_NOT_AVAILABLE; }
+ NS_IMETHOD UnlockMinimumBrightness(uint32_t aBrightness) override { return NS_ERROR_NOT_AVAILABLE; }
+ NS_IMETHOD GetRotation(uint32_t* aRotation) override {
+ *aRotation = nsIScreen::ROTATION_0_DEG;
+ return NS_OK;
+ }
+ NS_IMETHOD SetRotation(uint32_t aRotation) override { return NS_ERROR_NOT_AVAILABLE; }
+ NS_IMETHOD GetContentsScaleFactor(double* aContentsScaleFactor) override {
+ *aContentsScaleFactor = 1.0;
+ return NS_OK;
+ }
+ NS_IMETHOD GetDefaultCSSScaleFactor(double* aScaleFactor) override {
+ *aScaleFactor = 1.0;
+ return NS_OK;
+ }
+
+protected:
+ virtual ~FakeScreen() {}
+
+ IntRect mScreenRect;
+};
+
+NS_IMPL_ISUPPORTS(FakeScreen, nsIScreen)
+
+
+/* static */ already_AddRefed<nsIScreen>
+VRDisplayProxy::MakeFakeScreen(const IntRect& aScreenRect)
+{
+ nsCOMPtr<nsIScreen> screen = new FakeScreen(aScreenRect);
+ return screen.forget();
+}
+
new file mode 100644
--- /dev/null
+++ b/gfx/vr/VRDisplayProxy.h
@@ -0,0 +1,58 @@
+/* -*- 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_PROXY_H
+#define GFX_VR_PROXY_H
+
+#include "nsIScreen.h"
+#include "nsCOMPtr.h"
+#include "mozilla/RefPtr.h"
+
+#include "gfxVR.h"
+
+namespace mozilla {
+namespace gfx {
+
+class VRManagerChild;
+
+class VRDisplayProxy
+{
+public:
+ NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VRDisplayProxy)
+
+ explicit VRDisplayProxy(const VRDisplayUpdate& aDeviceUpdate);
+
+ void UpdateDeviceInfo(const VRDisplayUpdate& aDeviceUpdate);
+ void UpdateSensorState(const VRHMDSensorState& aSensorState);
+
+ const VRDisplayInfo& GetDeviceInfo() const { return mDeviceInfo; }
+ virtual VRHMDSensorState GetSensorState();
+ virtual VRHMDSensorState GetImmediateSensorState();
+
+ bool SetFOV(const VRFieldOfView& aFOVLeft, const VRFieldOfView& aFOVRight,
+ double zNear, double zFar);
+
+ virtual void ZeroSensor();
+
+
+ // The nsIScreen that represents this device
+ nsIScreen* GetScreen() { return mScreen; }
+
+protected:
+ virtual ~VRDisplayProxy();
+
+ VRDisplayInfo mDeviceInfo;
+ VRHMDSensorState mSensorState;
+
+ nsCOMPtr<nsIScreen> mScreen;
+
+ static already_AddRefed<nsIScreen> MakeFakeScreen(const IntRect& aScreenRect);
+
+};
+
+} // namespace gfx
+} // namespace mozilla
+
+#endif /* GFX_VR_PROXY_H */
--- a/gfx/vr/VRManager.cpp
+++ b/gfx/vr/VRManager.cpp
@@ -3,17 +3,17 @@
* 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 "mozilla/ClearOnShutdown.h"
-#include "mozilla/dom/VRDevice.h"
+#include "mozilla/dom/VRDisplay.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)
@@ -66,17 +66,17 @@ VRManager::~VRManager()
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(!mInitialized);
MOZ_COUNT_DTOR(VRManager);
}
void
VRManager::Destroy()
{
- mVRDevices.Clear();
+ mVRDisplays.Clear();
for (uint32_t i = 0; i < mManagers.Length(); ++i) {
mManagers[i]->Destroy();
}
mInitialized = false;
}
void
VRManager::Init()
@@ -111,96 +111,96 @@ VRManager::RemoveVRManagerParent(VRManag
if (mVRManagerParents.IsEmpty()) {
Destroy();
}
}
void
VRManager::NotifyVsync(const TimeStamp& aVsyncTimestamp)
{
- for (auto iter = mVRDevices.Iter(); !iter.Done(); iter.Next()) {
+ for (auto iter = mVRDisplays.Iter(); !iter.Done(); iter.Next()) {
gfx::VRHMDInfo* device = iter.UserData();
device->NotifyVsync(aVsyncTimestamp);
}
- DispatchVRDeviceSensorUpdate();
+ DispatchVRDisplaySensorUpdate();
}
void
-VRManager::RefreshVRDevices()
+VRManager::RefreshVRDisplays()
{
nsTArray<RefPtr<gfx::VRHMDInfo> > devices;
for (uint32_t i = 0; i < mManagers.Length(); ++i) {
mManagers[i]->GetHMDs(devices);
}
bool deviceInfoChanged = false;
- if (devices.Length() != mVRDevices.Count()) {
+ if (devices.Length() != mVRDisplays.Count()) {
deviceInfoChanged = true;
}
for (const auto& device: devices) {
RefPtr<VRHMDInfo> oldDevice = GetDevice(device->GetDeviceInfo().GetDeviceID());
if (oldDevice == nullptr) {
deviceInfoChanged = true;
break;
}
if (oldDevice->GetDeviceInfo() != device->GetDeviceInfo()) {
deviceInfoChanged = true;
break;
}
}
if (deviceInfoChanged) {
- mVRDevices.Clear();
+ mVRDisplays.Clear();
for (const auto& device: devices) {
- mVRDevices.Put(device->GetDeviceInfo().GetDeviceID(), device);
+ mVRDisplays.Put(device->GetDeviceInfo().GetDeviceID(), device);
}
}
- DispatchVRDeviceInfoUpdate();
+ DispatchVRDisplayInfoUpdate();
}
void
-VRManager::DispatchVRDeviceInfoUpdate()
+VRManager::DispatchVRDisplayInfoUpdate()
{
- nsTArray<VRDeviceUpdate> update;
- for (auto iter = mVRDevices.Iter(); !iter.Done(); iter.Next()) {
+ nsTArray<VRDisplayUpdate> update;
+ for (auto iter = mVRDisplays.Iter(); !iter.Done(); iter.Next()) {
gfx::VRHMDInfo* device = iter.UserData();
- update.AppendElement(VRDeviceUpdate(device->GetDeviceInfo(),
+ update.AppendElement(VRDisplayUpdate(device->GetDeviceInfo(),
device->GetSensorState()));
}
for (auto iter = mVRManagerParents.Iter(); !iter.Done(); iter.Next()) {
Unused << iter.Get()->GetKey()->SendUpdateDeviceInfo(update);
}
}
void
-VRManager::DispatchVRDeviceSensorUpdate()
+VRManager::DispatchVRDisplaySensorUpdate()
{
nsTArray<VRSensorUpdate> update;
- for (auto iter = mVRDevices.Iter(); !iter.Done(); iter.Next()) {
+ for (auto iter = mVRDisplays.Iter(); !iter.Done(); iter.Next()) {
gfx::VRHMDInfo* device = iter.UserData();
update.AppendElement(VRSensorUpdate(device->GetDeviceInfo().GetDeviceID(),
device->GetSensorState()));
}
if (update.Length() > 0) {
for (auto iter = mVRManagerParents.Iter(); !iter.Done(); iter.Next()) {
Unused << iter.Get()->GetKey()->SendUpdateDeviceSensors(update);
}
}
}
RefPtr<gfx::VRHMDInfo>
VRManager::GetDevice(const uint32_t& aDeviceID)
{
RefPtr<gfx::VRHMDInfo> device;
- if (mVRDevices.Get(aDeviceID, getter_AddRefs(device))) {
+ if (mVRDisplays.Get(aDeviceID, getter_AddRefs(device))) {
return device;
}
return nullptr;
}
} // namespace gfx
} // namespace mozilla
--- a/gfx/vr/VRManager.h
+++ b/gfx/vr/VRManager.h
@@ -25,39 +25,39 @@ class VRManager
public:
static void ManagerInit();
static VRManager* Get();
void AddVRManagerParent(VRManagerParent* aVRManagerParent);
void RemoveVRManagerParent(VRManagerParent* aVRManagerParent);
void NotifyVsync(const TimeStamp& aVsyncTimestamp);
- void RefreshVRDevices();
+ void RefreshVRDisplays();
RefPtr<gfx::VRHMDInfo> GetDevice(const uint32_t& aDeviceID);
protected:
VRManager();
~VRManager();
private:
void Init();
void Destroy();
- void DispatchVRDeviceInfoUpdate();
- void DispatchVRDeviceSensorUpdate();
+ void DispatchVRDisplayInfoUpdate();
+ void DispatchVRDisplaySensorUpdate();
typedef nsTHashtable<nsRefPtrHashKey<VRManagerParent>> VRManagerParentSet;
VRManagerParentSet mVRManagerParents;
typedef nsTArray<RefPtr<VRHMDManager>> VRHMDManagerArray;
VRHMDManagerArray mManagers;
typedef nsRefPtrHashtable<nsUint32HashKey, gfx::VRHMDInfo> VRHMDInfoHashMap;
- VRHMDInfoHashMap mVRDevices;
+ VRHMDInfoHashMap mVRDisplays;
Atomic<bool> mInitialized;
};
} // namespace gfx
} // namespace mozilla
--- a/gfx/vr/gfxVR.h
+++ b/gfx/vr/gfxVR.h
@@ -83,17 +83,17 @@ struct VRDistortionMesh {
// 12 floats per vertex. Position, tex coordinates
// for each channel, and 4 generic attributes
struct VRDistortionConstants {
float eyeToSourceScaleAndOffset[4];
float destinationScaleAndOffset[4];
};
-struct VRDeviceInfo
+struct VRDisplayInfo
{
VRHMDType GetType() const { return mType; }
uint32_t GetDeviceID() const { return mDeviceID; }
const nsCString& GetDeviceName() const { return mDeviceName; }
VRStateValidFlags GetSupportedSensorStateBits() const { return mSupportedSensorBits; }
const VRFieldOfView& GetRecommendedEyeFOV(uint32_t whichEye) const { return mRecommendedEyeFOV[whichEye]; }
const VRFieldOfView& GetMaximumEyeFOV(uint32_t whichEye) const { return mMaximumEyeFOV[whichEye]; }
@@ -107,33 +107,33 @@ struct VRDeviceInfo
Eye_Right,
NumEyes
};
uint32_t mDeviceID;
VRHMDType mType;
nsCString mDeviceName;
VRStateValidFlags mSupportedSensorBits;
- VRFieldOfView mMaximumEyeFOV[VRDeviceInfo::NumEyes];
- VRFieldOfView mRecommendedEyeFOV[VRDeviceInfo::NumEyes];
- VRFieldOfView mEyeFOV[VRDeviceInfo::NumEyes];
- Point3D mEyeTranslation[VRDeviceInfo::NumEyes];
- Matrix4x4 mEyeProjectionMatrix[VRDeviceInfo::NumEyes];
+ VRFieldOfView mMaximumEyeFOV[VRDisplayInfo::NumEyes];
+ VRFieldOfView mRecommendedEyeFOV[VRDisplayInfo::NumEyes];
+ VRFieldOfView mEyeFOV[VRDisplayInfo::NumEyes];
+ Point3D mEyeTranslation[VRDisplayInfo::NumEyes];
+ Matrix4x4 mEyeProjectionMatrix[VRDisplayInfo::NumEyes];
/* Suggested resolution for rendering a single eye.
* Assumption is that left/right rendering will be 2x of this size.
* XXX fix this for vertical displays
*/
IntSize mEyeResolution;
IntRect mScreenRect;
bool mIsFakeScreen;
- bool operator==(const VRDeviceInfo& other) const {
+ bool operator==(const VRDisplayInfo& other) const {
return mType == other.mType &&
mDeviceID == other.mDeviceID &&
mDeviceName == other.mDeviceName &&
mSupportedSensorBits == other.mSupportedSensorBits &&
mEyeResolution == other.mEyeResolution &&
mScreenRect == other.mScreenRect &&
mIsFakeScreen == other.mIsFakeScreen &&
mMaximumEyeFOV[0] == other.mMaximumEyeFOV[0] &&
@@ -143,17 +143,17 @@ struct VRDeviceInfo
mEyeFOV[0] == other.mEyeFOV[0] &&
mEyeFOV[1] == other.mEyeFOV[1] &&
mEyeTranslation[0] == other.mEyeTranslation[0] &&
mEyeTranslation[1] == other.mEyeTranslation[1] &&
mEyeProjectionMatrix[0] == other.mEyeProjectionMatrix[0] &&
mEyeProjectionMatrix[1] == other.mEyeProjectionMatrix[1];
}
- bool operator!=(const VRDeviceInfo& other) const {
+ bool operator!=(const VRDisplayInfo& other) const {
return !(*this == other);
}
};
struct VRHMDSensorState {
double timestamp;
@@ -176,24 +176,24 @@ struct VRSensorUpdate {
VRSensorUpdate(uint32_t aDeviceID, const VRHMDSensorState& aSensorState)
: mDeviceID(aDeviceID)
, mSensorState(aSensorState) { };
uint32_t mDeviceID;
VRHMDSensorState mSensorState;
};
-struct VRDeviceUpdate {
- VRDeviceUpdate() { }; // Required for ipdl binding
- VRDeviceUpdate(const VRDeviceInfo& aDeviceInfo,
+struct VRDisplayUpdate {
+ VRDisplayUpdate() { }; // Required for ipdl binding
+ VRDisplayUpdate(const VRDisplayInfo& aDeviceInfo,
const VRHMDSensorState& aSensorState)
: mDeviceInfo(aDeviceInfo)
, mSensorState(aSensorState) { };
- VRDeviceInfo mDeviceInfo;
+ VRDisplayInfo mDeviceInfo;
VRHMDSensorState mSensorState;
};
/* A pure data struct that can be used to see if
* the configuration of one HMDInfo matches another; for rendering purposes,
* really asking "can the rendering details of this one be used for the other"
*/
struct VRHMDConfiguration {
@@ -246,17 +246,17 @@ protected:
};
class VRHMDInfo {
public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VRHMDInfo)
const VRHMDConfiguration& GetConfiguration() const { return mConfiguration; }
- const VRDeviceInfo& GetDeviceInfo() const { return mDeviceInfo; }
+ const VRDisplayInfo& GetDeviceInfo() const { return mDeviceInfo; }
/* set the FOV for this HMD unit; this triggers a computation of all the remaining bits. Returns false if it fails */
virtual bool SetFOV(const VRFieldOfView& aFOVLeft, const VRFieldOfView& aFOVRight,
double zNear, double zFar) = 0;
virtual bool KeepSensorTracking() = 0;
virtual void NotifyVsync(const TimeStamp& aVsyncTimestamp) = 0;
virtual VRHMDSensorState GetSensorState() = 0;
@@ -276,18 +276,18 @@ public:
VRDistortionConstants& values) = 0;
const VRDistortionMesh& GetDistortionMesh(uint32_t whichEye) const { return mDistortionMesh[whichEye]; }
protected:
explicit VRHMDInfo(VRHMDType aType);
virtual ~VRHMDInfo();
VRHMDConfiguration mConfiguration;
- VRDeviceInfo mDeviceInfo;
- VRDistortionMesh mDistortionMesh[VRDeviceInfo::NumEyes];
+ VRDisplayInfo mDeviceInfo;
+ VRDistortionMesh mDistortionMesh[VRDisplayInfo::NumEyes];
};
class VRHMDManager {
public:
static uint32_t AllocateDeviceID();
protected:
static Atomic<uint32_t> sDeviceBase;
--- a/gfx/vr/gfxVROSVR.cpp
+++ b/gfx/vr/gfxVROSVR.cpp
@@ -231,18 +231,18 @@ HMDInfoOSVR::HMDInfoOSVR(OSVR_ClientCont
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);
- SetFOV(mDeviceInfo.mRecommendedEyeFOV[VRDeviceInfo::Eye_Left],
- mDeviceInfo.mRecommendedEyeFOV[VRDeviceInfo::Eye_Right], 0.01,
+ SetFOV(mDeviceInfo.mRecommendedEyeFOV[VRDisplayInfo::Eye_Left],
+ mDeviceInfo.mRecommendedEyeFOV[VRDisplayInfo::Eye_Right], 0.01,
10000.0);
}
void
HMDInfoOSVR::Destroy()
{
// destroy non-owning pointers
m_ctx = nullptr;
@@ -279,18 +279,18 @@ HMDInfoOSVR::SetFOV(const gfx::VRFieldOf
mDeviceInfo.mEyeTranslation[eye].z = eyePose.translation.data[2];
mDeviceInfo.mEyeProjectionMatrix[eye] =
mDeviceInfo.mEyeFOV[eye].ConstructProjectionMatrix(zNear, zFar, true);
}
mConfiguration.hmdType = mDeviceInfo.mType;
mConfiguration.value = 0;
- mConfiguration.fov[VRDeviceInfo::Eye_Left] = aFOVLeft;
- mConfiguration.fov[VRDeviceInfo::Eye_Right] = aFOVRight;
+ mConfiguration.fov[VRDisplayInfo::Eye_Left] = aFOVLeft;
+ mConfiguration.fov[VRDisplayInfo::Eye_Right] = aFOVRight;
return true;
}
void
HMDInfoOSVR::FillDistortionConstants(
uint32_t whichEye, const IntSize& textureSize, const IntRect& eyeViewport,
const Size& destViewport, const Rect& destRect, VRDistortionConstants& values)
--- a/gfx/vr/gfxVROculus.cpp
+++ b/gfx/vr/gfxVROculus.cpp
@@ -309,31 +309,31 @@ HMDInfoOculus::HMDInfoOculus(ovrSession
mDeviceInfo.mSupportedSensorBits = VRStateValidFlags::State_None;
if (mDesc.AvailableTrackingCaps & ovrTrackingCap_Orientation) {
mDeviceInfo.mSupportedSensorBits |= VRStateValidFlags::State_Orientation;
}
if (mDesc.AvailableTrackingCaps & ovrTrackingCap_Position) {
mDeviceInfo.mSupportedSensorBits |= VRStateValidFlags::State_Position;
}
- mDeviceInfo.mRecommendedEyeFOV[VRDeviceInfo::Eye_Left] = FromFovPort(mDesc.DefaultEyeFov[ovrEye_Left]);
- mDeviceInfo.mRecommendedEyeFOV[VRDeviceInfo::Eye_Right] = FromFovPort(mDesc.DefaultEyeFov[ovrEye_Right]);
+ mDeviceInfo.mRecommendedEyeFOV[VRDisplayInfo::Eye_Left] = FromFovPort(mDesc.DefaultEyeFov[ovrEye_Left]);
+ mDeviceInfo.mRecommendedEyeFOV[VRDisplayInfo::Eye_Right] = FromFovPort(mDesc.DefaultEyeFov[ovrEye_Right]);
- mDeviceInfo.mMaximumEyeFOV[VRDeviceInfo::Eye_Left] = FromFovPort(mDesc.MaxEyeFov[ovrEye_Left]);
- mDeviceInfo.mMaximumEyeFOV[VRDeviceInfo::Eye_Right] = FromFovPort(mDesc.MaxEyeFov[ovrEye_Right]);
+ mDeviceInfo.mMaximumEyeFOV[VRDisplayInfo::Eye_Left] = FromFovPort(mDesc.MaxEyeFov[ovrEye_Left]);
+ mDeviceInfo.mMaximumEyeFOV[VRDisplayInfo::Eye_Right] = FromFovPort(mDesc.MaxEyeFov[ovrEye_Right]);
uint32_t w = mDesc.Resolution.w;
uint32_t h = mDesc.Resolution.h;
mDeviceInfo.mScreenRect.x = 0;
mDeviceInfo.mScreenRect.y = 0;
mDeviceInfo.mScreenRect.width = std::max(w, h);
mDeviceInfo.mScreenRect.height = std::min(w, h);
mDeviceInfo.mIsFakeScreen = true;
- SetFOV(mDeviceInfo.mRecommendedEyeFOV[VRDeviceInfo::Eye_Left], mDeviceInfo.mRecommendedEyeFOV[VRDeviceInfo::Eye_Right], 0.01, 10000.0);
+ SetFOV(mDeviceInfo.mRecommendedEyeFOV[VRDisplayInfo::Eye_Left], mDeviceInfo.mRecommendedEyeFOV[VRDisplayInfo::Eye_Right], 0.01, 10000.0);
for (int i = 0; i < kMaxLatencyFrames; i++) {
mLastSensorState[i].Clear();
}
}
void
HMDInfoOculus::Destroy()
@@ -347,34 +347,34 @@ HMDInfoOculus::Destroy()
bool
HMDInfoOculus::SetFOV(const gfx::VRFieldOfView& aFOVLeft, const gfx::VRFieldOfView& aFOVRight,
double zNear, double zFar)
{
float pixelsPerDisplayPixel = 1.0;
ovrSizei texSize[2];
// get eye parameters and create the mesh
- for (uint32_t eye = 0; eye < VRDeviceInfo::NumEyes; eye++) {
+ for (uint32_t eye = 0; eye < VRDisplayInfo::NumEyes; eye++) {
mDeviceInfo.mEyeFOV[eye] = eye == 0 ? aFOVLeft : aFOVRight;
mFOVPort[eye] = ToFovPort(mDeviceInfo.mEyeFOV[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.
mDeviceInfo.mEyeTranslation[eye] = Point3D(renderDesc.HmdToEyeOffset.x, renderDesc.HmdToEyeOffset.y, renderDesc.HmdToEyeOffset.z);
// note that we are using a right-handed coordinate system here, to match CSS
mDeviceInfo.mEyeProjectionMatrix[eye] = mDeviceInfo.mEyeFOV[eye].ConstructProjectionMatrix(zNear, zFar, true);
texSize[eye] = ovr_GetFovTextureSize(mSession, (ovrEyeType)eye, mFOVPort[eye], pixelsPerDisplayPixel);
}
// take the max of both for eye resolution
- mDeviceInfo.mEyeResolution.width = std::max(texSize[VRDeviceInfo::Eye_Left].w, texSize[VRDeviceInfo::Eye_Right].w);
- mDeviceInfo.mEyeResolution.height = std::max(texSize[VRDeviceInfo::Eye_Left].h, texSize[VRDeviceInfo::Eye_Right].h);
+ mDeviceInfo.mEyeResolution.width = std::max(texSize[VRDisplayInfo::Eye_Left].w, texSize[VRDisplayInfo::Eye_Right].w);
+ mDeviceInfo.mEyeResolution.height = std::max(texSize[VRDisplayInfo::Eye_Left].h, texSize[VRDisplayInfo::Eye_Right].h);
mConfiguration.hmdType = mDeviceInfo.mType;
mConfiguration.value = 0;
mConfiguration.fov[0] = aFOVLeft;
mConfiguration.fov[1] = aFOVRight;
return true;
}
--- a/gfx/vr/ipc/PVRManager.ipdl
+++ b/gfx/vr/ipc/PVRManager.ipdl
@@ -3,17 +3,17 @@
*/
/* 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 "VRMessageUtils.h";
using struct mozilla::gfx::VRFieldOfView from "gfxVR.h";
-using struct mozilla::gfx::VRDeviceUpdate from "gfxVR.h";
+using struct mozilla::gfx::VRDisplayUpdate from "gfxVR.h";
using struct mozilla::gfx::VRSensorUpdate from "gfxVR.h";
namespace mozilla {
namespace gfx {
/**
* The PVRManager protocol is used to enable communication of VR device
* enumeration and sensor state between the compositor thread and
@@ -43,17 +43,17 @@ parent:
VRFieldOfView aFOVRight, double zNear, double zFar);
child:
// Notify children of updated VR device enumeration and details. This will
// be sent to all children when the parent receives RefreshDevices, even
// if no changes have been detected. This ensures that Promises exposed
// through DOM calls are always resolved.
- async UpdateDeviceInfo(VRDeviceUpdate[] aDeviceUpdates);
+ async UpdateDeviceInfo(VRDisplayUpdate[] aDeviceUpdates);
// Notify children of updated VR device sensor states. This will be
// sent once per frame for at least one second after the parent receives
// KeepSensorTracking.
async UpdateDeviceSensors(VRSensorUpdate[] aDeviceSensorUpdates);
async __delete__();
--- a/gfx/vr/ipc/VRManagerChild.cpp
+++ b/gfx/vr/ipc/VRManagerChild.cpp
@@ -2,17 +2,17 @@
* 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 "VRDeviceProxy.h"
+#include "VRDisplayProxy.h"
#include "mozilla/StaticPtr.h"
#include "mozilla/layers/CompositorThread.h" // for CompositorThread
#include "mozilla/dom/Navigator.h"
namespace mozilla {
namespace gfx {
static StaticRefPtr<VRManagerChild> sVRManagerChildSingleton;
@@ -116,41 +116,41 @@ VRManagerChild::Destroy()
// The DeferredDestroyVRManager task takes ownership of
// the VRManagerChild and will release it when it runs.
MessageLoop::current()->PostTask(
NewRunnableFunction(DeferredDestroy, selfRef));
}
bool
-VRManagerChild::RecvUpdateDeviceInfo(nsTArray<VRDeviceUpdate>&& aDeviceUpdates)
+VRManagerChild::RecvUpdateDeviceInfo(nsTArray<VRDisplayUpdate>&& aDeviceUpdates)
{
// mDevices could be a hashed container for more scalability, but not worth
// it now as we expect < 10 entries.
- nsTArray<RefPtr<VRDeviceProxy> > devices;
+ nsTArray<RefPtr<VRDisplayProxy> > devices;
for (auto& deviceUpdate: aDeviceUpdates) {
bool isNewDevice = true;
for (auto& device: mDevices) {
if (device->GetDeviceInfo().GetDeviceID() == deviceUpdate.mDeviceInfo.GetDeviceID()) {
device->UpdateDeviceInfo(deviceUpdate);
devices.AppendElement(device);
isNewDevice = false;
break;
}
}
if (isNewDevice) {
- devices.AppendElement(new VRDeviceProxy(deviceUpdate));
+ devices.AppendElement(new VRDisplayProxy(deviceUpdate));
}
}
mDevices = devices;
for (auto& nav: mNavigatorCallbacks) {
- nav->NotifyVRDevicesUpdated();
+ nav->NotifyVRDisplaysUpdated();
}
mNavigatorCallbacks.Clear();
return true;
}
bool
VRManagerChild::RecvUpdateDeviceSensors(nsTArray<VRSensorUpdate>&& aDeviceSensorUpdates)
@@ -166,24 +166,24 @@ VRManagerChild::RecvUpdateDeviceSensors(
}
}
}
return true;
}
bool
-VRManagerChild::GetVRDevices(nsTArray<RefPtr<VRDeviceProxy> >& aDevices)
+VRManagerChild::GetVRDisplays(nsTArray<RefPtr<VRDisplayProxy> >& aDevices)
{
aDevices = mDevices;
return true;
}
bool
-VRManagerChild::RefreshVRDevicesWithCallback(dom::Navigator* aNavigator)
+VRManagerChild::RefreshVRDisplaysWithCallback(dom::Navigator* aNavigator)
{
bool success = SendRefreshDevices();
if (success) {
mNavigatorCallbacks.AppendElement(aNavigator);
}
return success;
}
--- a/gfx/vr/ipc/VRManagerChild.h
+++ b/gfx/vr/ipc/VRManagerChild.h
@@ -9,54 +9,54 @@
#define MOZILLA_GFX_VR_VRMANAGERCHILD_H
#include "mozilla/gfx/PVRManagerChild.h"
#include "ThreadSafeRefcountingWithMainThreadDestruction.h"
namespace mozilla {
namespace dom {
class Navigator;
-class VRDevice;
+class VRDisplay;
} // namespace dom
namespace gfx {
-class VRDeviceProxy;
+class VRDisplayProxy;
class VRManagerChild : public PVRManagerChild
{
public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING_WITH_MAIN_THREAD_DESTRUCTION(VRManagerChild)
int GetInputFrameID();
- bool GetVRDevices(nsTArray<RefPtr<VRDeviceProxy> >& aDevices);
- bool RefreshVRDevicesWithCallback(dom::Navigator* aNavigator);
+ bool GetVRDisplays(nsTArray<RefPtr<VRDisplayProxy> >& aDevices);
+ bool RefreshVRDisplaysWithCallback(dom::Navigator* aNavigator);
static void InitSameProcess();
static void InitWithGPUProcess(Endpoint<PVRManagerChild>&& aEndpoint);
static bool InitForContent(Endpoint<PVRManagerChild>&& aEndpoint);
static void ShutDown();
static bool IsCreated();
static VRManagerChild* Get();
protected:
explicit VRManagerChild();
~VRManagerChild();
void Destroy();
static void DeferredDestroy(RefPtr<VRManagerChild> aVRManagerChild);
- virtual bool RecvUpdateDeviceInfo(nsTArray<VRDeviceUpdate>&& aDeviceUpdates) override;
+ virtual bool RecvUpdateDeviceInfo(nsTArray<VRDisplayUpdate>&& aDeviceUpdates) override;
virtual bool RecvUpdateDeviceSensors(nsTArray<VRSensorUpdate>&& aDeviceSensorUpdates) override;
friend class layers::CompositorBridgeChild;
private:
- nsTArray<RefPtr<VRDeviceProxy> > mDevices;
+ nsTArray<RefPtr<VRDisplayProxy> > mDevices;
nsTArray<dom::Navigator*> mNavigatorCallbacks;
int32_t mInputFrameID;
};
} // namespace mozilla
} // namespace gfx
--- a/gfx/vr/ipc/VRManagerParent.cpp
+++ b/gfx/vr/ipc/VRManagerParent.cpp
@@ -128,17 +128,17 @@ VRManagerParent::OnChannelConnected(int3
{
mCompositorThreadHolder = layers::CompositorThreadHolder::GetSingleton();
}
bool
VRManagerParent::RecvRefreshDevices()
{
VRManager* vm = VRManager::Get();
- vm->RefreshVRDevices();
+ vm->RefreshVRDisplays();
return true;
}
bool
VRManagerParent::RecvResetSensor(const uint32_t& aDeviceID)
{
VRManager* vm = VRManager::Get();
--- a/gfx/vr/ipc/VRMessageUtils.h
+++ b/gfx/vr/ipc/VRMessageUtils.h
@@ -22,19 +22,19 @@ struct ParamTraits<mozilla::gfx::VRHMDTy
mozilla::gfx::VRHMDType(mozilla::gfx::VRHMDType::NumHMDTypes)> {};
template<>
struct ParamTraits<mozilla::gfx::VRStateValidFlags> :
public BitFlagsEnumSerializer<mozilla::gfx::VRStateValidFlags,
mozilla::gfx::VRStateValidFlags::State_All> {};
template <>
-struct ParamTraits<mozilla::gfx::VRDeviceUpdate>
+struct ParamTraits<mozilla::gfx::VRDisplayUpdate>
{
- typedef mozilla::gfx::VRDeviceUpdate paramType;
+ typedef mozilla::gfx::VRDisplayUpdate paramType;
static void Write(Message* aMsg, const paramType& aParam)
{
WriteParam(aMsg, aParam.mDeviceInfo);
WriteParam(aMsg, aParam.mSensorState);
}
static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
@@ -64,30 +64,30 @@ struct ParamTraits<mozilla::gfx::VRSenso
!ReadParam(aMsg, aIter, &(aResult->mSensorState))) {
return false;
}
return true;
}
};
template <>
-struct ParamTraits<mozilla::gfx::VRDeviceInfo>
+struct ParamTraits<mozilla::gfx::VRDisplayInfo>
{
- typedef mozilla::gfx::VRDeviceInfo paramType;
+ typedef mozilla::gfx::VRDisplayInfo paramType;
static void Write(Message* aMsg, const paramType& aParam)
{
WriteParam(aMsg, aParam.mType);
WriteParam(aMsg, aParam.mDeviceID);
WriteParam(aMsg, aParam.mDeviceName);
WriteParam(aMsg, aParam.mSupportedSensorBits);
WriteParam(aMsg, aParam.mEyeResolution);
WriteParam(aMsg, aParam.mScreenRect);
WriteParam(aMsg, aParam.mIsFakeScreen);
- for (int i = 0; i < mozilla::gfx::VRDeviceInfo::NumEyes; i++) {
+ for (int i = 0; i < mozilla::gfx::VRDisplayInfo::NumEyes; i++) {
WriteParam(aMsg, aParam.mMaximumEyeFOV[i]);
WriteParam(aMsg, aParam.mRecommendedEyeFOV[i]);
WriteParam(aMsg, aParam.mEyeFOV[i]);
WriteParam(aMsg, aParam.mEyeTranslation[i]);
WriteParam(aMsg, aParam.mEyeProjectionMatrix[i]);
}
}
@@ -97,17 +97,17 @@ struct ParamTraits<mozilla::gfx::VRDevic
!ReadParam(aMsg, aIter, &(aResult->mDeviceID)) ||
!ReadParam(aMsg, aIter, &(aResult->mDeviceName)) ||
!ReadParam(aMsg, aIter, &(aResult->mSupportedSensorBits)) ||
!ReadParam(aMsg, aIter, &(aResult->mEyeResolution)) ||
!ReadParam(aMsg, aIter, &(aResult->mScreenRect)) ||
!ReadParam(aMsg, aIter, &(aResult->mIsFakeScreen))) {
return false;
}
- for (int i = 0; i < mozilla::gfx::VRDeviceInfo::NumEyes; i++) {
+ for (int i = 0; i < mozilla::gfx::VRDisplayInfo::NumEyes; i++) {
if (!ReadParam(aMsg, aIter, &(aResult->mMaximumEyeFOV[i])) ||
!ReadParam(aMsg, aIter, &(aResult->mRecommendedEyeFOV[i])) ||
!ReadParam(aMsg, aIter, &(aResult->mEyeFOV[i])) ||
!ReadParam(aMsg, aIter, &(aResult->mEyeTranslation[i])) ||
!ReadParam(aMsg, aIter, &(aResult->mEyeProjectionMatrix[i]))) {
return false;
}
}
--- a/gfx/vr/moz.build
+++ b/gfx/vr/moz.build
@@ -4,31 +4,31 @@
# 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/VRManagerChild.h',
'ipc/VRManagerParent.h',
'ipc/VRMessageUtils.h',
- 'VRDeviceProxy.h',
+ 'VRDisplayProxy.h',
'VRManager.h',
]
LOCAL_INCLUDES += [
'/gfx/thebes',
]
UNIFIED_SOURCES += [
'gfxVR.cpp',
'gfxVROculus.cpp',
'gfxVROSVR.cpp',
'ipc/VRManagerChild.cpp',
'ipc/VRManagerParent.cpp',
- 'VRDeviceProxy.cpp',
+ 'VRDisplayProxy.cpp',
'VRManager.cpp',
]
IPDL_SOURCES = [
'ipc/PVRManager.ipdl',
]
# For building with the real SDK instead of our local hack
--- a/layout/base/nsDisplayList.cpp
+++ b/layout/base/nsDisplayList.cpp
@@ -14,17 +14,17 @@
#include <stdint.h>
#include <algorithm>
#include "gfxUtils.h"
#include "mozilla/dom/TabChild.h"
#include "mozilla/dom/KeyframeEffect.h"
#include "mozilla/gfx/2D.h"
-#include "VRDeviceProxy.h"
+#include "VRDisplayProxy.h"
#include "mozilla/layers/PLayerTransaction.h"
#include "nsCSSRendering.h"
#include "nsRenderingContext.h"
#include "nsISelectionController.h"
#include "nsIPresShell.h"
#include "nsRegion.h"
#include "nsStyleStructInlines.h"
#include "nsStyleTransformMatrix.h"