Bug 1700051: part 35) Reduce accessibility of `mSoftText.mDOMMapping` to `private...
[gecko.git] / dom / vr / XRSpace.cpp
blob172111c809e1b0709c8707ddc2992ed09e6efb8f
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "mozilla/dom/XRSpace.h"
8 #include "mozilla/dom/XRRigidTransform.h"
9 #include "VRDisplayClient.h"
11 namespace mozilla {
12 namespace dom {
14 NS_IMPL_CYCLE_COLLECTION_CLASS(XRSpace)
16 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(XRSpace, DOMEventTargetHelper)
17 NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSession)
18 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
20 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(XRSpace, DOMEventTargetHelper)
21 NS_IMPL_CYCLE_COLLECTION_UNLINK(mSession)
22 // Don't need NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER because
23 // DOMEventTargetHelper does it for us.
24 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
26 NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED_0(XRSpace, DOMEventTargetHelper)
28 XRSpace::XRSpace(nsIGlobalObject* aParent, XRSession* aSession,
29 XRNativeOrigin* aNativeOrigin)
30 : DOMEventTargetHelper(aParent),
31 mSession(aSession),
32 mNativeOrigin(aNativeOrigin),
33 mOriginOffsetPosition(0.0f, 0.0f, 0.0f),
34 mOriginOffsetOrientation(0.0f, 0.0f, 0.0f, 1.0f) {}
36 JSObject* XRSpace::WrapObject(JSContext* aCx,
37 JS::Handle<JSObject*> aGivenProto) {
38 return XRSpace_Binding::Wrap(aCx, this, aGivenProto);
41 XRSession* XRSpace::GetSession() const { return mSession; }
43 gfx::QuaternionDouble XRSpace::GetEffectiveOriginOrientation() const {
44 gfx::QuaternionDouble orientation =
45 mNativeOrigin->GetOrientation() * mOriginOffsetOrientation;
46 return orientation;
49 gfx::PointDouble3D XRSpace::GetEffectiveOriginPosition() const {
50 gfx::PointDouble3D position;
51 position = mNativeOrigin->GetPosition();
52 position = mOriginOffsetOrientation.RotatePoint(position);
53 position += mOriginOffsetPosition;
54 return position;
57 gfx::Matrix4x4Double XRSpace::GetEffectiveOriginTransform() const {
58 gfx::Matrix4x4Double transform;
59 transform.SetRotationFromQuaternion(GetEffectiveOriginOrientation());
60 transform.PostTranslate(GetEffectiveOriginPosition());
61 return transform;
64 bool XRSpace::IsPositionEmulated() const {
65 gfx::VRDisplayClient* display = mSession->GetDisplayClient();
66 if (!display) {
67 // When there are no sensors, the position is considered emulated.
68 return true;
70 const gfx::VRDisplayInfo& displayInfo = display->GetDisplayInfo();
71 if (displayInfo.GetCapabilities() &
72 gfx::VRDisplayCapabilityFlags::Cap_PositionEmulated) {
73 // Cap_PositionEmulated indicates that the position is always emulated.
74 return true;
76 const gfx::VRHMDSensorState& sensorState = display->GetSensorState();
77 // When positional tracking is lost, the position is considered emulated.
78 return ((sensorState.flags & gfx::VRDisplayCapabilityFlags::Cap_Position) ==
79 gfx::VRDisplayCapabilityFlags::Cap_None);
82 } // namespace dom
83 } // namespace mozilla