summaryrefslogtreecommitdiffstats
path: root/gfx/vr/gfxVR.cpp
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /gfx/vr/gfxVR.cpp
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'gfx/vr/gfxVR.cpp')
-rw-r--r--gfx/vr/gfxVR.cpp127
1 files changed, 127 insertions, 0 deletions
diff --git a/gfx/vr/gfxVR.cpp b/gfx/vr/gfxVR.cpp
new file mode 100644
index 000000000..c0babb4f8
--- /dev/null
+++ b/gfx/vr/gfxVR.cpp
@@ -0,0 +1,127 @@
+/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include <math.h>
+
+#include "gfxVR.h"
+#ifdef MOZ_GAMEPAD
+#include "mozilla/dom/GamepadEventTypes.h"
+#include "mozilla/dom/GamepadBinding.h"
+#endif
+
+#ifndef M_PI
+# define M_PI 3.14159265358979323846
+#endif
+
+using namespace mozilla;
+using namespace mozilla::gfx;
+
+Atomic<uint32_t> VRDisplayManager::sDisplayBase(0);
+Atomic<uint32_t> VRControllerManager::sControllerBase(0);
+
+/* static */ uint32_t
+VRDisplayManager::AllocateDisplayID()
+{
+ return ++sDisplayBase;
+}
+
+Matrix4x4
+VRFieldOfView::ConstructProjectionMatrix(float zNear, float zFar,
+ bool rightHanded) const
+{
+ float upTan = tan(upDegrees * M_PI / 180.0);
+ float downTan = tan(downDegrees * M_PI / 180.0);
+ float leftTan = tan(leftDegrees * M_PI / 180.0);
+ float rightTan = tan(rightDegrees * M_PI / 180.0);
+
+ float handednessScale = rightHanded ? -1.0 : 1.0;
+
+ float pxscale = 2.0f / (leftTan + rightTan);
+ float pxoffset = (leftTan - rightTan) * pxscale * 0.5;
+ float pyscale = 2.0f / (upTan + downTan);
+ float pyoffset = (upTan - downTan) * pyscale * 0.5;
+
+ Matrix4x4 mobj;
+ float *m = &mobj._11;
+
+ m[0*4+0] = pxscale;
+ m[2*4+0] = pxoffset * handednessScale;
+
+ m[1*4+1] = pyscale;
+ m[2*4+1] = -pyoffset * handednessScale;
+
+ m[2*4+2] = zFar / (zNear - zFar) * -handednessScale;
+ m[3*4+2] = (zFar * zNear) / (zNear - zFar);
+
+ m[2*4+3] = handednessScale;
+ m[3*4+3] = 0.0f;
+
+ return mobj;
+}
+
+/* static */ uint32_t
+VRControllerManager::AllocateControllerID()
+{
+ return ++sControllerBase;
+}
+
+void
+VRControllerManager::AddGamepad(const char* aID, uint32_t aMapping,
+ uint32_t aNumButtons, uint32_t aNumAxes)
+{
+ dom::GamepadAdded a(NS_ConvertUTF8toUTF16(nsDependentCString(aID)), mControllerCount,
+ aMapping, dom::GamepadServiceType::VR, aNumButtons,
+ aNumAxes);
+
+ VRManager* vm = VRManager::Get();
+ MOZ_ASSERT(vm);
+ vm->NotifyGamepadChange<dom::GamepadAdded>(a);
+}
+
+void
+VRControllerManager::RemoveGamepad(uint32_t aIndex)
+{
+ dom::GamepadRemoved a(aIndex, dom::GamepadServiceType::VR);
+
+ VRManager* vm = VRManager::Get();
+ MOZ_ASSERT(vm);
+ vm->NotifyGamepadChange<dom::GamepadRemoved>(a);
+}
+
+void
+VRControllerManager::NewButtonEvent(uint32_t aIndex, uint32_t aButton,
+ bool aPressed)
+{
+ dom::GamepadButtonInformation a(aIndex, dom::GamepadServiceType::VR,
+ aButton, aPressed, aPressed ? 1.0L : 0.0L);
+
+ VRManager* vm = VRManager::Get();
+ MOZ_ASSERT(vm);
+ vm->NotifyGamepadChange<dom::GamepadButtonInformation>(a);
+}
+
+void
+VRControllerManager::NewAxisMove(uint32_t aIndex, uint32_t aAxis,
+ double aValue)
+{
+ dom::GamepadAxisInformation a(aIndex, dom::GamepadServiceType::VR,
+ aAxis, aValue);
+
+ VRManager* vm = VRManager::Get();
+ MOZ_ASSERT(vm);
+ vm->NotifyGamepadChange<dom::GamepadAxisInformation>(a);
+}
+
+void
+VRControllerManager::NewPoseState(uint32_t aIndex,
+ const dom::GamepadPoseState& aPose)
+{
+ dom::GamepadPoseInformation a(aIndex, dom::GamepadServiceType::VR,
+ aPose);
+
+ VRManager* vm = VRManager::Get();
+ MOZ_ASSERT(vm);
+ vm->NotifyGamepadChange<dom::GamepadPoseInformation>(a);
+}