summaryrefslogtreecommitdiffstats
path: root/dom/vr/XRSpace.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /dom/vr/XRSpace.cpp
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/vr/XRSpace.cpp')
-rw-r--r--dom/vr/XRSpace.cpp81
1 files changed, 81 insertions, 0 deletions
diff --git a/dom/vr/XRSpace.cpp b/dom/vr/XRSpace.cpp
new file mode 100644
index 0000000000..1f6449e870
--- /dev/null
+++ b/dom/vr/XRSpace.cpp
@@ -0,0 +1,81 @@
+/* -*- 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 "mozilla/dom/XRSpace.h"
+#include "mozilla/dom/XRRigidTransform.h"
+#include "VRDisplayClient.h"
+
+namespace mozilla::dom {
+
+NS_IMPL_CYCLE_COLLECTION_CLASS(XRSpace)
+
+NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(XRSpace, DOMEventTargetHelper)
+ NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSession)
+NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
+
+NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(XRSpace, DOMEventTargetHelper)
+ NS_IMPL_CYCLE_COLLECTION_UNLINK(mSession)
+ // Don't need NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER because
+ // DOMEventTargetHelper does it for us.
+NS_IMPL_CYCLE_COLLECTION_UNLINK_END
+
+NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED_0(XRSpace, DOMEventTargetHelper)
+
+XRSpace::XRSpace(nsIGlobalObject* aParent, XRSession* aSession,
+ XRNativeOrigin* aNativeOrigin)
+ : DOMEventTargetHelper(aParent),
+ mSession(aSession),
+ mNativeOrigin(aNativeOrigin),
+ mOriginOffsetPosition(0.0f, 0.0f, 0.0f),
+ mOriginOffsetOrientation(0.0f, 0.0f, 0.0f, 1.0f) {}
+
+JSObject* XRSpace::WrapObject(JSContext* aCx,
+ JS::Handle<JSObject*> aGivenProto) {
+ return XRSpace_Binding::Wrap(aCx, this, aGivenProto);
+}
+
+XRSession* XRSpace::GetSession() const { return mSession; }
+
+gfx::QuaternionDouble XRSpace::GetEffectiveOriginOrientation() const {
+ gfx::QuaternionDouble orientation =
+ mNativeOrigin->GetOrientation() * mOriginOffsetOrientation;
+ return orientation;
+}
+
+gfx::PointDouble3D XRSpace::GetEffectiveOriginPosition() const {
+ gfx::PointDouble3D position;
+ position = mNativeOrigin->GetPosition();
+ position = mOriginOffsetOrientation.RotatePoint(position);
+ position += mOriginOffsetPosition;
+ return position;
+}
+
+gfx::Matrix4x4Double XRSpace::GetEffectiveOriginTransform() const {
+ gfx::Matrix4x4Double transform;
+ transform.SetRotationFromQuaternion(GetEffectiveOriginOrientation());
+ transform.PostTranslate(GetEffectiveOriginPosition());
+ return transform;
+}
+
+bool XRSpace::IsPositionEmulated() const {
+ gfx::VRDisplayClient* display = mSession->GetDisplayClient();
+ if (!display) {
+ // When there are no sensors, the position is considered emulated.
+ return true;
+ }
+ const gfx::VRDisplayInfo& displayInfo = display->GetDisplayInfo();
+ if (displayInfo.GetCapabilities() &
+ gfx::VRDisplayCapabilityFlags::Cap_PositionEmulated) {
+ // Cap_PositionEmulated indicates that the position is always emulated.
+ return true;
+ }
+ const gfx::VRHMDSensorState& sensorState = display->GetSensorState();
+ // When positional tracking is lost, the position is considered emulated.
+ return ((sensorState.flags & gfx::VRDisplayCapabilityFlags::Cap_Position) ==
+ gfx::VRDisplayCapabilityFlags::Cap_None);
+}
+
+} // namespace mozilla::dom