2018-12-17 23:46:40 +03:00
|
|
|
/* -*- 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 <fstream>
|
|
|
|
#include "mozilla/JSONWriter.h"
|
2018-12-21 03:52:24 +03:00
|
|
|
#include "mozilla/ClearOnShutdown.h"
|
2018-12-17 23:46:40 +03:00
|
|
|
#include "nsString.h"
|
|
|
|
|
2018-10-26 00:33:25 +03:00
|
|
|
#include "OpenVRSession.h"
|
2019-07-26 04:10:23 +03:00
|
|
|
#include "mozilla/StaticPrefs_dom.h"
|
2018-10-26 00:33:25 +03:00
|
|
|
|
|
|
|
#if defined(XP_WIN)
|
|
|
|
# include <d3d11.h>
|
|
|
|
# include "mozilla/gfx/DeviceManagerDx.h"
|
|
|
|
#elif defined(XP_MACOSX)
|
|
|
|
# include "mozilla/gfx/MacIOSurface.h"
|
|
|
|
#endif
|
|
|
|
|
2019-04-22 23:41:38 +03:00
|
|
|
#if !defined(XP_WIN)
|
|
|
|
# include <sys/stat.h> // for umask()
|
|
|
|
#endif
|
|
|
|
|
2018-10-26 00:33:25 +03:00
|
|
|
#include "mozilla/dom/GamepadEventTypes.h"
|
|
|
|
#include "mozilla/dom/GamepadBinding.h"
|
2019-06-26 21:26:16 +03:00
|
|
|
#include "binding/OpenVRCosmosBinding.h"
|
2018-12-17 23:46:40 +03:00
|
|
|
#include "binding/OpenVRKnucklesBinding.h"
|
|
|
|
#include "binding/OpenVRViveBinding.h"
|
2018-12-21 03:52:24 +03:00
|
|
|
#if defined(XP_WIN) // Windows Mixed Reality is only available in Windows.
|
2018-12-17 23:46:40 +03:00
|
|
|
# include "binding/OpenVRWMRBinding.h"
|
2018-12-21 03:52:24 +03:00
|
|
|
#endif
|
2018-12-17 23:46:40 +03:00
|
|
|
|
2018-12-29 01:09:44 +03:00
|
|
|
#include "VRParent.h"
|
|
|
|
#include "VRProcessChild.h"
|
2018-10-26 00:33:25 +03:00
|
|
|
#include "VRThread.h"
|
|
|
|
|
|
|
|
#if !defined(M_PI)
|
|
|
|
# define M_PI 3.14159265358979323846264338327950288
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define BTN_MASK_FROM_ID(_id) ::vr::ButtonMaskFromId(vr::EVRButtonId::_id)
|
|
|
|
|
|
|
|
// Haptic feedback is updated every 5ms, as this is
|
|
|
|
// the minimum period between new haptic pulse requests.
|
|
|
|
// Effectively, this results in a pulse width modulation
|
|
|
|
// with an interval of 5ms. Through experimentation, the
|
|
|
|
// maximum duty cycle was found to be about 3.9ms
|
|
|
|
const uint32_t kVRHapticUpdateInterval = 5;
|
|
|
|
|
|
|
|
using namespace mozilla::gfx;
|
|
|
|
|
2020-01-18 16:48:34 +03:00
|
|
|
namespace mozilla::gfx {
|
2018-10-26 00:33:25 +03:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2018-12-17 23:46:40 +03:00
|
|
|
// This is for controller action file writer.
|
2018-12-21 03:52:24 +03:00
|
|
|
struct StringWriteFunc : public JSONWriteFunc {
|
2019-04-22 23:41:38 +03:00
|
|
|
nsACString& mBuffer; // This struct must not outlive this buffer
|
2018-12-17 23:46:40 +03:00
|
|
|
|
2019-04-22 23:41:38 +03:00
|
|
|
explicit StringWriteFunc(nsACString& buffer) : mBuffer(buffer) {}
|
2018-12-21 03:52:24 +03:00
|
|
|
|
2019-04-22 23:41:38 +03:00
|
|
|
void Write(const char* aStr) override { mBuffer.Append(aStr); }
|
2018-12-17 23:46:40 +03:00
|
|
|
};
|
|
|
|
|
2018-12-21 03:52:24 +03:00
|
|
|
class ControllerManifestFile {
|
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(ControllerManifestFile)
|
2018-12-17 23:46:40 +03:00
|
|
|
|
2018-12-21 03:52:24 +03:00
|
|
|
public:
|
|
|
|
static already_AddRefed<ControllerManifestFile> CreateManifest() {
|
|
|
|
RefPtr<ControllerManifestFile> manifest = new ControllerManifestFile();
|
|
|
|
return manifest.forget();
|
2018-12-17 23:46:40 +03:00
|
|
|
}
|
|
|
|
|
2018-12-21 03:52:24 +03:00
|
|
|
bool IsExisting() {
|
2019-04-22 23:41:38 +03:00
|
|
|
if (mFileName.IsEmpty() ||
|
|
|
|
!std::ifstream(mFileName.BeginReading()).good()) {
|
2018-12-21 03:52:24 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2018-12-17 23:46:40 +03:00
|
|
|
|
2018-12-21 03:52:24 +03:00
|
|
|
void SetFileName(const char* aName) { mFileName = aName; }
|
2018-12-17 23:46:40 +03:00
|
|
|
|
2018-12-21 03:52:24 +03:00
|
|
|
const char* GetFileName() const { return mFileName.BeginReading(); }
|
2018-12-17 23:46:40 +03:00
|
|
|
|
2018-12-21 03:52:24 +03:00
|
|
|
private:
|
2018-12-17 23:46:40 +03:00
|
|
|
ControllerManifestFile() = default;
|
|
|
|
|
2018-12-21 03:52:24 +03:00
|
|
|
~ControllerManifestFile() {
|
|
|
|
if (!mFileName.IsEmpty() && remove(mFileName.BeginReading()) != 0) {
|
2018-12-17 23:46:40 +03:00
|
|
|
MOZ_ASSERT(false, "Delete controller manifest file failed.");
|
|
|
|
}
|
|
|
|
mFileName = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCString mFileName;
|
|
|
|
};
|
|
|
|
|
|
|
|
// We wanna keep these temporary files existing
|
|
|
|
// until Firefox is closed instead of following OpenVRSession's lifetime.
|
2019-06-26 21:26:16 +03:00
|
|
|
StaticRefPtr<ControllerManifestFile> sCosmosBindingFile;
|
2018-12-21 03:52:24 +03:00
|
|
|
StaticRefPtr<ControllerManifestFile> sKnucklesBindingFile;
|
|
|
|
StaticRefPtr<ControllerManifestFile> sViveBindingFile;
|
|
|
|
#if defined(XP_WIN)
|
|
|
|
StaticRefPtr<ControllerManifestFile> sWMRBindingFile;
|
|
|
|
#endif
|
|
|
|
StaticRefPtr<ControllerManifestFile> sControllerActionFile;
|
2018-12-17 23:46:40 +03:00
|
|
|
|
2018-12-21 03:52:24 +03:00
|
|
|
dom::GamepadHand GetControllerHandFromControllerRole(OpenVRHand aRole) {
|
|
|
|
dom::GamepadHand hand;
|
|
|
|
switch (aRole) {
|
|
|
|
case OpenVRHand::None:
|
|
|
|
hand = dom::GamepadHand::_empty;
|
|
|
|
break;
|
|
|
|
case OpenVRHand::Left:
|
|
|
|
hand = dom::GamepadHand::Left;
|
|
|
|
break;
|
|
|
|
case OpenVRHand::Right:
|
|
|
|
hand = dom::GamepadHand::Right;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
hand = dom::GamepadHand::_empty;
|
|
|
|
MOZ_ASSERT(false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return hand;
|
2018-12-17 23:46:40 +03:00
|
|
|
}
|
|
|
|
|
2018-12-29 01:09:44 +03:00
|
|
|
bool FileIsExisting(const nsCString& aPath) {
|
2019-04-22 23:41:38 +03:00
|
|
|
if (aPath.IsEmpty() || !std::ifstream(aPath.BeginReading()).good()) {
|
2018-12-29 01:09:44 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-10-26 00:33:25 +03:00
|
|
|
}; // anonymous namespace
|
|
|
|
|
2019-04-22 23:41:38 +03:00
|
|
|
#if defined(XP_WIN)
|
|
|
|
bool GenerateTempFileName(nsCString& aPath) {
|
|
|
|
TCHAR tempPathBuffer[MAX_PATH];
|
|
|
|
TCHAR tempFileName[MAX_PATH];
|
|
|
|
|
|
|
|
// Gets the temp path env string (no guarantee it's a valid path).
|
|
|
|
DWORD dwRetVal = GetTempPath(MAX_PATH, tempPathBuffer);
|
|
|
|
if (dwRetVal > MAX_PATH || (dwRetVal == 0)) {
|
|
|
|
NS_WARNING("OpenVR - Creating temp path failed.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Generates a temporary file name.
|
|
|
|
UINT uRetVal = GetTempFileName(tempPathBuffer, // directory for tmp files
|
|
|
|
TEXT("mozvr"), // temp file name prefix
|
|
|
|
0, // create unique name
|
|
|
|
tempFileName); // buffer for name
|
|
|
|
if (uRetVal == 0) {
|
|
|
|
NS_WARNING("OpenVR - Creating temp file failed.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
aPath.Assign(NS_ConvertUTF16toUTF8(tempFileName));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
bool GenerateTempFileName(nsCString& aPath) {
|
|
|
|
const char tmp[] = "/tmp/mozvrXXXXXX";
|
|
|
|
char fileName[PATH_MAX];
|
|
|
|
|
|
|
|
strcpy(fileName, tmp);
|
|
|
|
const mode_t prevMask = umask(S_IXUSR | S_IRWXO | S_IRWXG);
|
|
|
|
const int fd = mkstemp(fileName);
|
|
|
|
umask(prevMask);
|
|
|
|
if (fd == -1) {
|
|
|
|
NS_WARNING(nsPrintfCString("OpenVR - Creating temp file failed: %s",
|
|
|
|
strerror(errno))
|
|
|
|
.get());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
aPath.Assign(fileName);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif // defined(XP_WIN)
|
|
|
|
|
2018-10-26 00:33:25 +03:00
|
|
|
OpenVRSession::OpenVRSession()
|
2018-12-21 03:52:24 +03:00
|
|
|
: VRSession(),
|
|
|
|
mVRSystem(nullptr),
|
|
|
|
mVRChaperone(nullptr),
|
|
|
|
mVRCompositor(nullptr),
|
|
|
|
mHapticPulseRemaining{},
|
|
|
|
mHapticPulseIntensity{},
|
|
|
|
mIsWindowsMR(false),
|
|
|
|
mControllerHapticStateMutex(
|
|
|
|
"OpenVRSession::mControllerHapticStateMutex") {
|
2018-12-17 23:46:40 +03:00
|
|
|
std::fill_n(mControllerDeviceIndex, kVRControllerMaxCount, OpenVRHand::None);
|
|
|
|
}
|
|
|
|
|
2018-12-21 03:52:24 +03:00
|
|
|
OpenVRSession::~OpenVRSession() {
|
2018-12-17 23:46:40 +03:00
|
|
|
mActionsetFirefox = ::vr::k_ulInvalidActionSetHandle;
|
|
|
|
Shutdown();
|
|
|
|
}
|
|
|
|
|
2019-11-22 04:13:28 +03:00
|
|
|
bool OpenVRSession::Initialize(mozilla::gfx::VRSystemState& aSystemState,
|
|
|
|
bool aDetectRuntimesOnly) {
|
2019-07-22 05:10:14 +03:00
|
|
|
if (!StaticPrefs::dom_vr_enabled() ||
|
|
|
|
!StaticPrefs::dom_vr_openvr_enabled_AtStartup()) {
|
2018-10-26 00:33:25 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (mVRSystem != nullptr) {
|
|
|
|
// Already initialized
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (!::vr::VR_IsRuntimeInstalled()) {
|
|
|
|
return false;
|
|
|
|
}
|
2019-11-22 04:13:28 +03:00
|
|
|
if (aDetectRuntimesOnly) {
|
|
|
|
aSystemState.displayState.capabilityFlags |=
|
|
|
|
VRDisplayCapabilityFlags::Cap_ImmersiveVR;
|
|
|
|
return false;
|
|
|
|
}
|
2018-10-26 00:33:25 +03:00
|
|
|
if (!::vr::VR_IsHmdPresent()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
::vr::HmdError err;
|
|
|
|
|
|
|
|
::vr::VR_Init(&err, ::vr::EVRApplicationType::VRApplication_Scene);
|
|
|
|
if (err) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
mVRSystem = (::vr::IVRSystem*)::vr::VR_GetGenericInterface(
|
2018-12-21 03:52:24 +03:00
|
|
|
::vr::IVRSystem_Version, &err);
|
2018-10-26 00:33:25 +03:00
|
|
|
if (err || !mVRSystem) {
|
|
|
|
Shutdown();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
mVRChaperone = (::vr::IVRChaperone*)::vr::VR_GetGenericInterface(
|
2018-12-21 03:52:24 +03:00
|
|
|
::vr::IVRChaperone_Version, &err);
|
2018-10-26 00:33:25 +03:00
|
|
|
if (err || !mVRChaperone) {
|
|
|
|
Shutdown();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
mVRCompositor = (::vr::IVRCompositor*)::vr::VR_GetGenericInterface(
|
2018-12-21 03:52:24 +03:00
|
|
|
::vr::IVRCompositor_Version, &err);
|
2018-10-26 00:33:25 +03:00
|
|
|
if (err || !mVRCompositor) {
|
|
|
|
Shutdown();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(XP_WIN)
|
|
|
|
if (!CreateD3DObjects()) {
|
|
|
|
Shutdown();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Configure coordinate system
|
|
|
|
mVRCompositor->SetTrackingSpace(::vr::TrackingUniverseSeated);
|
|
|
|
|
|
|
|
if (!InitState(aSystemState)) {
|
|
|
|
Shutdown();
|
|
|
|
return false;
|
|
|
|
}
|
2020-02-28 03:40:54 +03:00
|
|
|
if (!SetupContollerActions()) {
|
2019-04-22 23:41:38 +03:00
|
|
|
return false;
|
2018-12-17 23:46:40 +03:00
|
|
|
}
|
|
|
|
|
2018-10-26 00:33:25 +03:00
|
|
|
// Succeeded
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-04-22 23:41:38 +03:00
|
|
|
bool OpenVRSession::SetupContollerActions() {
|
2019-07-09 01:24:00 +03:00
|
|
|
if (!vr::VRInput()) {
|
|
|
|
NS_WARNING("OpenVR - vr::VRInput() is null.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-12-17 23:46:40 +03:00
|
|
|
// Check if this device binding file has been created.
|
|
|
|
// If it didn't exist yet, create a new temp file.
|
2018-12-29 01:09:44 +03:00
|
|
|
nsCString controllerAction;
|
|
|
|
nsCString viveManifest;
|
|
|
|
nsCString WMRManifest;
|
|
|
|
nsCString knucklesManifest;
|
2019-06-26 21:26:16 +03:00
|
|
|
nsCString cosmosManifest;
|
2018-12-29 01:09:44 +03:00
|
|
|
|
2019-04-22 23:41:38 +03:00
|
|
|
// Getting / Generating manifest file paths.
|
2019-07-22 05:10:14 +03:00
|
|
|
if (StaticPrefs::dom_vr_process_enabled_AtStartup()) {
|
2018-12-29 01:09:44 +03:00
|
|
|
VRParent* vrParent = VRProcessChild::GetVRParent();
|
|
|
|
nsCString output;
|
|
|
|
|
|
|
|
if (vrParent->GetOpenVRControllerActionPath(&output)) {
|
|
|
|
controllerAction = output;
|
2018-12-17 23:46:40 +03:00
|
|
|
}
|
2018-12-29 01:09:44 +03:00
|
|
|
|
|
|
|
if (vrParent->GetOpenVRControllerManifestPath(OpenVRControllerType::Vive,
|
|
|
|
&output)) {
|
|
|
|
viveManifest = output;
|
2018-12-17 23:46:40 +03:00
|
|
|
}
|
2019-04-22 23:41:38 +03:00
|
|
|
if (!viveManifest.Length() || !FileIsExisting(viveManifest)) {
|
|
|
|
if (!GenerateTempFileName(viveManifest)) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-12-29 01:09:44 +03:00
|
|
|
OpenVRViveBinding viveBinding;
|
|
|
|
std::ofstream viveBindingFile(viveManifest.BeginReading());
|
|
|
|
if (viveBindingFile.is_open()) {
|
|
|
|
viveBindingFile << viveBinding.binding;
|
|
|
|
viveBindingFile.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-21 03:52:24 +03:00
|
|
|
#if defined(XP_WIN)
|
2018-12-29 01:09:44 +03:00
|
|
|
if (vrParent->GetOpenVRControllerManifestPath(OpenVRControllerType::WMR,
|
|
|
|
&output)) {
|
|
|
|
WMRManifest = output;
|
|
|
|
}
|
2019-04-22 23:41:38 +03:00
|
|
|
if (!WMRManifest.Length() || !FileIsExisting(WMRManifest)) {
|
|
|
|
if (!GenerateTempFileName(WMRManifest)) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-12-29 01:09:44 +03:00
|
|
|
OpenVRWMRBinding WMRBinding;
|
|
|
|
std::ofstream WMRBindingFile(WMRManifest.BeginReading());
|
|
|
|
if (WMRBindingFile.is_open()) {
|
|
|
|
WMRBindingFile << WMRBinding.binding;
|
|
|
|
WMRBindingFile.close();
|
|
|
|
}
|
2018-12-17 23:46:40 +03:00
|
|
|
}
|
2018-12-21 03:52:24 +03:00
|
|
|
#endif
|
2018-12-29 01:09:44 +03:00
|
|
|
if (vrParent->GetOpenVRControllerManifestPath(
|
|
|
|
OpenVRControllerType::Knuckles, &output)) {
|
|
|
|
knucklesManifest = output;
|
|
|
|
}
|
2019-04-22 23:41:38 +03:00
|
|
|
if (!knucklesManifest.Length() || !FileIsExisting(knucklesManifest)) {
|
|
|
|
if (!GenerateTempFileName(knucklesManifest)) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-12-29 01:09:44 +03:00
|
|
|
OpenVRKnucklesBinding knucklesBinding;
|
|
|
|
std::ofstream knucklesBindingFile(knucklesManifest.BeginReading());
|
|
|
|
if (knucklesBindingFile.is_open()) {
|
|
|
|
knucklesBindingFile << knucklesBinding.binding;
|
|
|
|
knucklesBindingFile.close();
|
|
|
|
}
|
|
|
|
}
|
2019-07-16 10:33:44 +03:00
|
|
|
if (vrParent->GetOpenVRControllerManifestPath(OpenVRControllerType::Cosmos,
|
|
|
|
&output)) {
|
2019-06-26 21:26:16 +03:00
|
|
|
cosmosManifest = output;
|
|
|
|
}
|
|
|
|
if (!cosmosManifest.Length() || !FileIsExisting(cosmosManifest)) {
|
|
|
|
if (!GenerateTempFileName(cosmosManifest)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
OpenVRCosmosBinding cosmosBinding;
|
|
|
|
std::ofstream cosmosBindingFile(cosmosManifest.BeginReading());
|
|
|
|
if (cosmosBindingFile.is_open()) {
|
|
|
|
cosmosBindingFile << cosmosBinding.binding;
|
|
|
|
cosmosBindingFile.close();
|
|
|
|
}
|
|
|
|
}
|
2018-12-29 01:09:44 +03:00
|
|
|
} else {
|
2019-04-22 23:41:38 +03:00
|
|
|
// Without using VR process
|
2018-12-29 01:09:44 +03:00
|
|
|
if (!sControllerActionFile) {
|
|
|
|
sControllerActionFile = ControllerManifestFile::CreateManifest();
|
|
|
|
NS_DispatchToMainThread(NS_NewRunnableFunction(
|
|
|
|
"ClearOnShutdown ControllerManifestFile",
|
|
|
|
[]() { ClearOnShutdown(&sControllerActionFile); }));
|
|
|
|
}
|
|
|
|
controllerAction = sControllerActionFile->GetFileName();
|
|
|
|
|
|
|
|
if (!sViveBindingFile) {
|
|
|
|
sViveBindingFile = ControllerManifestFile::CreateManifest();
|
|
|
|
NS_DispatchToMainThread(
|
|
|
|
NS_NewRunnableFunction("ClearOnShutdown ControllerManifestFile",
|
|
|
|
[]() { ClearOnShutdown(&sViveBindingFile); }));
|
|
|
|
}
|
|
|
|
if (!sViveBindingFile->IsExisting()) {
|
2019-04-22 23:41:38 +03:00
|
|
|
nsCString viveBindingPath;
|
|
|
|
if (!GenerateTempFileName(viveBindingPath)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
sViveBindingFile->SetFileName(viveBindingPath.BeginReading());
|
2018-12-29 01:09:44 +03:00
|
|
|
OpenVRViveBinding viveBinding;
|
|
|
|
std::ofstream viveBindingFile(sViveBindingFile->GetFileName());
|
|
|
|
if (viveBindingFile.is_open()) {
|
|
|
|
viveBindingFile << viveBinding.binding;
|
|
|
|
viveBindingFile.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
viveManifest = sViveBindingFile->GetFileName();
|
|
|
|
|
|
|
|
if (!sKnucklesBindingFile) {
|
|
|
|
sKnucklesBindingFile = ControllerManifestFile::CreateManifest();
|
|
|
|
NS_DispatchToMainThread(NS_NewRunnableFunction(
|
|
|
|
"ClearOnShutdown ControllerManifestFile",
|
|
|
|
[]() { ClearOnShutdown(&sKnucklesBindingFile); }));
|
|
|
|
}
|
|
|
|
if (!sKnucklesBindingFile->IsExisting()) {
|
2019-04-22 23:41:38 +03:00
|
|
|
nsCString knucklesBindingPath;
|
|
|
|
if (!GenerateTempFileName(knucklesBindingPath)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
sKnucklesBindingFile->SetFileName(knucklesBindingPath.BeginReading());
|
2018-12-29 01:09:44 +03:00
|
|
|
OpenVRKnucklesBinding knucklesBinding;
|
|
|
|
std::ofstream knucklesBindingFile(sKnucklesBindingFile->GetFileName());
|
|
|
|
if (knucklesBindingFile.is_open()) {
|
|
|
|
knucklesBindingFile << knucklesBinding.binding;
|
|
|
|
knucklesBindingFile.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
knucklesManifest = sKnucklesBindingFile->GetFileName();
|
|
|
|
|
2019-06-26 21:26:16 +03:00
|
|
|
if (!sCosmosBindingFile) {
|
|
|
|
sCosmosBindingFile = ControllerManifestFile::CreateManifest();
|
|
|
|
NS_DispatchToMainThread(NS_NewRunnableFunction(
|
|
|
|
"ClearOnShutdown ControllerManifestFile",
|
|
|
|
[]() { ClearOnShutdown(&sCosmosBindingFile); }));
|
|
|
|
}
|
|
|
|
if (!sCosmosBindingFile->IsExisting()) {
|
|
|
|
nsCString cosmosBindingPath;
|
|
|
|
if (!GenerateTempFileName(cosmosBindingPath)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
sCosmosBindingFile->SetFileName(cosmosBindingPath.BeginReading());
|
|
|
|
OpenVRCosmosBinding cosmosBinding;
|
|
|
|
std::ofstream cosmosBindingFile(sCosmosBindingFile->GetFileName());
|
|
|
|
if (cosmosBindingFile.is_open()) {
|
|
|
|
cosmosBindingFile << cosmosBinding.binding;
|
|
|
|
cosmosBindingFile.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cosmosManifest = sCosmosBindingFile->GetFileName();
|
2018-12-29 01:09:44 +03:00
|
|
|
#if defined(XP_WIN)
|
|
|
|
if (!sWMRBindingFile) {
|
|
|
|
sWMRBindingFile = ControllerManifestFile::CreateManifest();
|
|
|
|
NS_DispatchToMainThread(
|
|
|
|
NS_NewRunnableFunction("ClearOnShutdown ControllerManifestFile",
|
|
|
|
[]() { ClearOnShutdown(&sWMRBindingFile); }));
|
|
|
|
}
|
|
|
|
if (!sWMRBindingFile->IsExisting()) {
|
2019-04-22 23:41:38 +03:00
|
|
|
nsCString WMRBindingPath;
|
|
|
|
if (!GenerateTempFileName(WMRBindingPath)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
sWMRBindingFile->SetFileName(WMRBindingPath.BeginReading());
|
2018-12-29 01:09:44 +03:00
|
|
|
OpenVRWMRBinding WMRBinding;
|
|
|
|
std::ofstream WMRBindingFile(sWMRBindingFile->GetFileName());
|
|
|
|
if (WMRBindingFile.is_open()) {
|
|
|
|
WMRBindingFile << WMRBinding.binding;
|
|
|
|
WMRBindingFile.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
WMRManifest = sWMRBindingFile->GetFileName();
|
|
|
|
#endif
|
|
|
|
}
|
2019-04-22 23:41:38 +03:00
|
|
|
// End of Getting / Generating manifest file paths.
|
2018-12-29 01:09:44 +03:00
|
|
|
|
2019-04-22 23:41:38 +03:00
|
|
|
// Setup controller actions.
|
2018-12-21 03:52:24 +03:00
|
|
|
ControllerInfo leftContollerInfo;
|
|
|
|
leftContollerInfo.mActionPose =
|
|
|
|
ControllerAction("/actions/firefox/in/LHand_pose", "pose");
|
|
|
|
leftContollerInfo.mActionHaptic =
|
|
|
|
ControllerAction("/actions/firefox/out/LHand_haptic", "vibration");
|
|
|
|
leftContollerInfo.mActionTrackpad_Analog =
|
|
|
|
ControllerAction("/actions/firefox/in/LHand_trackpad_analog", "vector2");
|
|
|
|
leftContollerInfo.mActionTrackpad_Pressed =
|
|
|
|
ControllerAction("/actions/firefox/in/LHand_trackpad_pressed", "boolean");
|
|
|
|
leftContollerInfo.mActionTrackpad_Touched =
|
|
|
|
ControllerAction("/actions/firefox/in/LHand_trackpad_touched", "boolean");
|
|
|
|
leftContollerInfo.mActionTrigger_Value =
|
|
|
|
ControllerAction("/actions/firefox/in/LHand_trigger_value", "vector1");
|
|
|
|
leftContollerInfo.mActionGrip_Pressed =
|
|
|
|
ControllerAction("/actions/firefox/in/LHand_grip_pressed", "boolean");
|
|
|
|
leftContollerInfo.mActionGrip_Touched =
|
|
|
|
ControllerAction("/actions/firefox/in/LHand_grip_touched", "boolean");
|
|
|
|
leftContollerInfo.mActionMenu_Pressed =
|
|
|
|
ControllerAction("/actions/firefox/in/LHand_menu_pressed", "boolean");
|
|
|
|
leftContollerInfo.mActionMenu_Touched =
|
|
|
|
ControllerAction("/actions/firefox/in/LHand_menu_touched", "boolean");
|
|
|
|
leftContollerInfo.mActionSystem_Pressed =
|
|
|
|
ControllerAction("/actions/firefox/in/LHand_system_pressed", "boolean");
|
|
|
|
leftContollerInfo.mActionSystem_Touched =
|
|
|
|
ControllerAction("/actions/firefox/in/LHand_system_touched", "boolean");
|
|
|
|
leftContollerInfo.mActionA_Pressed =
|
|
|
|
ControllerAction("/actions/firefox/in/LHand_A_pressed", "boolean");
|
|
|
|
leftContollerInfo.mActionA_Touched =
|
|
|
|
ControllerAction("/actions/firefox/in/LHand_A_touched", "boolean");
|
|
|
|
leftContollerInfo.mActionB_Pressed =
|
|
|
|
ControllerAction("/actions/firefox/in/LHand_B_pressed", "boolean");
|
|
|
|
leftContollerInfo.mActionB_Touched =
|
|
|
|
ControllerAction("/actions/firefox/in/LHand_B_touched", "boolean");
|
|
|
|
leftContollerInfo.mActionThumbstick_Analog = ControllerAction(
|
|
|
|
"/actions/firefox/in/LHand_thumbstick_analog", "vector2");
|
|
|
|
leftContollerInfo.mActionThumbstick_Pressed = ControllerAction(
|
|
|
|
"/actions/firefox/in/LHand_thumbstick_pressed", "boolean");
|
|
|
|
leftContollerInfo.mActionThumbstick_Touched = ControllerAction(
|
|
|
|
"/actions/firefox/in/LHand_thumbstick_touched", "boolean");
|
|
|
|
leftContollerInfo.mActionFingerIndex_Value = ControllerAction(
|
|
|
|
"/actions/firefox/in/LHand_finger_index_value", "vector1");
|
|
|
|
leftContollerInfo.mActionFingerMiddle_Value = ControllerAction(
|
|
|
|
"/actions/firefox/in/LHand_finger_middle_value", "vector1");
|
|
|
|
leftContollerInfo.mActionFingerRing_Value = ControllerAction(
|
|
|
|
"/actions/firefox/in/LHand_finger_ring_value", "vector1");
|
|
|
|
leftContollerInfo.mActionFingerPinky_Value = ControllerAction(
|
|
|
|
"/actions/firefox/in/LHand_finger_pinky_value", "vector1");
|
2019-06-26 21:26:16 +03:00
|
|
|
leftContollerInfo.mActionBumper_Pressed =
|
|
|
|
ControllerAction("/actions/firefox/in/LHand_bumper_pressed", "boolean");
|
2018-12-21 03:52:24 +03:00
|
|
|
|
|
|
|
ControllerInfo rightContollerInfo;
|
|
|
|
rightContollerInfo.mActionPose =
|
|
|
|
ControllerAction("/actions/firefox/in/RHand_pose", "pose");
|
|
|
|
rightContollerInfo.mActionHaptic =
|
|
|
|
ControllerAction("/actions/firefox/out/RHand_haptic", "vibration");
|
|
|
|
rightContollerInfo.mActionTrackpad_Analog =
|
|
|
|
ControllerAction("/actions/firefox/in/RHand_trackpad_analog", "vector2");
|
|
|
|
rightContollerInfo.mActionTrackpad_Pressed =
|
|
|
|
ControllerAction("/actions/firefox/in/RHand_trackpad_pressed", "boolean");
|
|
|
|
rightContollerInfo.mActionTrackpad_Touched =
|
|
|
|
ControllerAction("/actions/firefox/in/RHand_trackpad_touched", "boolean");
|
|
|
|
rightContollerInfo.mActionTrigger_Value =
|
|
|
|
ControllerAction("/actions/firefox/in/RHand_trigger_value", "vector1");
|
|
|
|
rightContollerInfo.mActionGrip_Pressed =
|
|
|
|
ControllerAction("/actions/firefox/in/RHand_grip_pressed", "boolean");
|
|
|
|
rightContollerInfo.mActionGrip_Touched =
|
|
|
|
ControllerAction("/actions/firefox/in/RHand_grip_touched", "boolean");
|
|
|
|
rightContollerInfo.mActionMenu_Pressed =
|
|
|
|
ControllerAction("/actions/firefox/in/RHand_menu_pressed", "boolean");
|
|
|
|
rightContollerInfo.mActionMenu_Touched =
|
|
|
|
ControllerAction("/actions/firefox/in/RHand_menu_touched", "boolean");
|
|
|
|
rightContollerInfo.mActionSystem_Pressed =
|
|
|
|
ControllerAction("/actions/firefox/in/RHand_system_pressed", "boolean");
|
|
|
|
rightContollerInfo.mActionSystem_Touched =
|
|
|
|
ControllerAction("/actions/firefox/in/RHand_system_touched", "boolean");
|
|
|
|
rightContollerInfo.mActionA_Pressed =
|
|
|
|
ControllerAction("/actions/firefox/in/RHand_A_pressed", "boolean");
|
|
|
|
rightContollerInfo.mActionA_Touched =
|
|
|
|
ControllerAction("/actions/firefox/in/RHand_A_touched", "boolean");
|
|
|
|
rightContollerInfo.mActionB_Pressed =
|
|
|
|
ControllerAction("/actions/firefox/in/RHand_B_pressed", "boolean");
|
|
|
|
rightContollerInfo.mActionB_Touched =
|
|
|
|
ControllerAction("/actions/firefox/in/RHand_B_touched", "boolean");
|
|
|
|
rightContollerInfo.mActionThumbstick_Analog = ControllerAction(
|
|
|
|
"/actions/firefox/in/RHand_thumbstick_analog", "vector2");
|
|
|
|
rightContollerInfo.mActionThumbstick_Pressed = ControllerAction(
|
|
|
|
"/actions/firefox/in/RHand_thumbstick_pressed", "boolean");
|
|
|
|
rightContollerInfo.mActionThumbstick_Touched = ControllerAction(
|
|
|
|
"/actions/firefox/in/RHand_thumbstick_touched", "boolean");
|
|
|
|
rightContollerInfo.mActionFingerIndex_Value = ControllerAction(
|
|
|
|
"/actions/firefox/in/RHand_finger_index_value", "vector1");
|
|
|
|
rightContollerInfo.mActionFingerMiddle_Value = ControllerAction(
|
|
|
|
"/actions/firefox/in/RHand_finger_middle_value", "vector1");
|
|
|
|
rightContollerInfo.mActionFingerRing_Value = ControllerAction(
|
|
|
|
"/actions/firefox/in/RHand_finger_ring_value", "vector1");
|
|
|
|
rightContollerInfo.mActionFingerPinky_Value = ControllerAction(
|
|
|
|
"/actions/firefox/in/RHand_finger_pinky_value", "vector1");
|
2019-06-26 21:26:16 +03:00
|
|
|
rightContollerInfo.mActionBumper_Pressed =
|
|
|
|
ControllerAction("/actions/firefox/in/RHand_bumper_pressed", "boolean");
|
2018-12-21 03:52:24 +03:00
|
|
|
|
|
|
|
mControllerHand[OpenVRHand::Left] = leftContollerInfo;
|
|
|
|
mControllerHand[OpenVRHand::Right] = rightContollerInfo;
|
2018-12-17 23:46:40 +03:00
|
|
|
|
2019-04-22 23:41:38 +03:00
|
|
|
if (!controllerAction.Length() || !FileIsExisting(controllerAction)) {
|
|
|
|
if (!GenerateTempFileName(controllerAction)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
nsCString actionData;
|
2019-04-18 02:08:27 +03:00
|
|
|
JSONWriter actionWriter(MakeUnique<StringWriteFunc>(actionData));
|
|
|
|
actionWriter.Start();
|
|
|
|
|
|
|
|
actionWriter.StringProperty("version",
|
|
|
|
"0.1.0"); // TODO: adding a version check.
|
|
|
|
// "default_bindings": []
|
|
|
|
actionWriter.StartArrayProperty("default_bindings");
|
2018-12-17 23:46:40 +03:00
|
|
|
actionWriter.StartObjectElement();
|
2019-04-18 02:08:27 +03:00
|
|
|
actionWriter.StringProperty("controller_type", "vive_controller");
|
|
|
|
actionWriter.StringProperty("binding_url", viveManifest.BeginReading());
|
2018-12-17 23:46:40 +03:00
|
|
|
actionWriter.EndObject();
|
|
|
|
actionWriter.StartObjectElement();
|
2019-04-18 02:08:27 +03:00
|
|
|
actionWriter.StringProperty("controller_type", "knuckles");
|
|
|
|
actionWriter.StringProperty("binding_url", knucklesManifest.BeginReading());
|
2018-12-17 23:46:40 +03:00
|
|
|
actionWriter.EndObject();
|
2019-06-26 21:26:16 +03:00
|
|
|
actionWriter.StartObjectElement();
|
|
|
|
actionWriter.StringProperty("controller_type", "vive_cosmos_controller");
|
|
|
|
actionWriter.StringProperty("binding_url", cosmosManifest.BeginReading());
|
|
|
|
actionWriter.EndObject();
|
2019-04-18 02:08:27 +03:00
|
|
|
#if defined(XP_WIN)
|
2018-12-17 23:46:40 +03:00
|
|
|
actionWriter.StartObjectElement();
|
2019-04-18 02:08:27 +03:00
|
|
|
actionWriter.StringProperty("controller_type", "holographic_controller");
|
|
|
|
actionWriter.StringProperty("binding_url", WMRManifest.BeginReading());
|
2018-12-17 23:46:40 +03:00
|
|
|
actionWriter.EndObject();
|
2019-04-18 02:08:27 +03:00
|
|
|
#endif
|
|
|
|
actionWriter.EndArray(); // End "default_bindings": []
|
|
|
|
|
|
|
|
// "actions": [] Action paths must take the form: "/actions/<action
|
|
|
|
// set>/in|out/<action>"
|
|
|
|
actionWriter.StartArrayProperty("actions");
|
|
|
|
|
|
|
|
for (auto& controller : mControllerHand) {
|
|
|
|
actionWriter.StartObjectElement();
|
|
|
|
actionWriter.StringProperty("name",
|
|
|
|
controller.mActionPose.name.BeginReading());
|
|
|
|
actionWriter.StringProperty("type",
|
|
|
|
controller.mActionPose.type.BeginReading());
|
|
|
|
actionWriter.EndObject();
|
|
|
|
|
|
|
|
actionWriter.StartObjectElement();
|
|
|
|
actionWriter.StringProperty(
|
|
|
|
"name", controller.mActionTrackpad_Analog.name.BeginReading());
|
|
|
|
actionWriter.StringProperty(
|
|
|
|
"type", controller.mActionTrackpad_Analog.type.BeginReading());
|
|
|
|
actionWriter.EndObject();
|
|
|
|
|
|
|
|
actionWriter.StartObjectElement();
|
|
|
|
actionWriter.StringProperty(
|
|
|
|
"name", controller.mActionTrackpad_Pressed.name.BeginReading());
|
|
|
|
actionWriter.StringProperty(
|
|
|
|
"type", controller.mActionTrackpad_Pressed.type.BeginReading());
|
|
|
|
actionWriter.EndObject();
|
|
|
|
|
|
|
|
actionWriter.StartObjectElement();
|
|
|
|
actionWriter.StringProperty(
|
|
|
|
"name", controller.mActionTrackpad_Touched.name.BeginReading());
|
|
|
|
actionWriter.StringProperty(
|
|
|
|
"type", controller.mActionTrackpad_Touched.type.BeginReading());
|
|
|
|
actionWriter.EndObject();
|
|
|
|
|
|
|
|
actionWriter.StartObjectElement();
|
|
|
|
actionWriter.StringProperty(
|
|
|
|
"name", controller.mActionTrigger_Value.name.BeginReading());
|
|
|
|
actionWriter.StringProperty(
|
|
|
|
"type", controller.mActionTrigger_Value.type.BeginReading());
|
|
|
|
actionWriter.EndObject();
|
|
|
|
|
|
|
|
actionWriter.StartObjectElement();
|
|
|
|
actionWriter.StringProperty(
|
|
|
|
"name", controller.mActionGrip_Pressed.name.BeginReading());
|
|
|
|
actionWriter.StringProperty(
|
|
|
|
"type", controller.mActionGrip_Pressed.type.BeginReading());
|
|
|
|
actionWriter.EndObject();
|
|
|
|
|
|
|
|
actionWriter.StartObjectElement();
|
|
|
|
actionWriter.StringProperty(
|
|
|
|
"name", controller.mActionGrip_Touched.name.BeginReading());
|
|
|
|
actionWriter.StringProperty(
|
|
|
|
"type", controller.mActionGrip_Touched.type.BeginReading());
|
|
|
|
actionWriter.EndObject();
|
|
|
|
|
|
|
|
actionWriter.StartObjectElement();
|
|
|
|
actionWriter.StringProperty(
|
|
|
|
"name", controller.mActionMenu_Pressed.name.BeginReading());
|
|
|
|
actionWriter.StringProperty(
|
|
|
|
"type", controller.mActionMenu_Pressed.type.BeginReading());
|
|
|
|
actionWriter.EndObject();
|
|
|
|
|
|
|
|
actionWriter.StartObjectElement();
|
|
|
|
actionWriter.StringProperty(
|
|
|
|
"name", controller.mActionMenu_Touched.name.BeginReading());
|
|
|
|
actionWriter.StringProperty(
|
|
|
|
"type", controller.mActionMenu_Touched.type.BeginReading());
|
|
|
|
actionWriter.EndObject();
|
|
|
|
|
|
|
|
actionWriter.StartObjectElement();
|
|
|
|
actionWriter.StringProperty(
|
|
|
|
"name", controller.mActionSystem_Pressed.name.BeginReading());
|
|
|
|
actionWriter.StringProperty(
|
|
|
|
"type", controller.mActionSystem_Pressed.type.BeginReading());
|
|
|
|
actionWriter.EndObject();
|
|
|
|
|
|
|
|
actionWriter.StartObjectElement();
|
|
|
|
actionWriter.StringProperty(
|
|
|
|
"name", controller.mActionSystem_Touched.name.BeginReading());
|
|
|
|
actionWriter.StringProperty(
|
|
|
|
"type", controller.mActionSystem_Touched.type.BeginReading());
|
|
|
|
actionWriter.EndObject();
|
|
|
|
|
|
|
|
actionWriter.StartObjectElement();
|
|
|
|
actionWriter.StringProperty(
|
|
|
|
"name", controller.mActionA_Pressed.name.BeginReading());
|
|
|
|
actionWriter.StringProperty(
|
|
|
|
"type", controller.mActionA_Pressed.type.BeginReading());
|
|
|
|
actionWriter.EndObject();
|
|
|
|
|
|
|
|
actionWriter.StartObjectElement();
|
|
|
|
actionWriter.StringProperty(
|
|
|
|
"name", controller.mActionA_Touched.name.BeginReading());
|
|
|
|
actionWriter.StringProperty(
|
|
|
|
"type", controller.mActionA_Touched.type.BeginReading());
|
|
|
|
actionWriter.EndObject();
|
|
|
|
|
|
|
|
actionWriter.StartObjectElement();
|
|
|
|
actionWriter.StringProperty(
|
|
|
|
"name", controller.mActionB_Pressed.name.BeginReading());
|
|
|
|
actionWriter.StringProperty(
|
|
|
|
"type", controller.mActionB_Pressed.type.BeginReading());
|
|
|
|
actionWriter.EndObject();
|
|
|
|
|
|
|
|
actionWriter.StartObjectElement();
|
|
|
|
actionWriter.StringProperty(
|
|
|
|
"name", controller.mActionB_Touched.name.BeginReading());
|
|
|
|
actionWriter.StringProperty(
|
|
|
|
"type", controller.mActionB_Touched.type.BeginReading());
|
|
|
|
actionWriter.EndObject();
|
|
|
|
|
|
|
|
actionWriter.StartObjectElement();
|
|
|
|
actionWriter.StringProperty(
|
|
|
|
"name", controller.mActionThumbstick_Analog.name.BeginReading());
|
|
|
|
actionWriter.StringProperty(
|
|
|
|
"type", controller.mActionThumbstick_Analog.type.BeginReading());
|
|
|
|
actionWriter.EndObject();
|
|
|
|
|
|
|
|
actionWriter.StartObjectElement();
|
|
|
|
actionWriter.StringProperty(
|
|
|
|
"name", controller.mActionThumbstick_Pressed.name.BeginReading());
|
|
|
|
actionWriter.StringProperty(
|
|
|
|
"type", controller.mActionThumbstick_Pressed.type.BeginReading());
|
|
|
|
actionWriter.EndObject();
|
|
|
|
|
|
|
|
actionWriter.StartObjectElement();
|
|
|
|
actionWriter.StringProperty(
|
|
|
|
"name", controller.mActionThumbstick_Touched.name.BeginReading());
|
|
|
|
actionWriter.StringProperty(
|
|
|
|
"type", controller.mActionThumbstick_Touched.type.BeginReading());
|
|
|
|
actionWriter.EndObject();
|
|
|
|
|
|
|
|
actionWriter.StartObjectElement();
|
|
|
|
actionWriter.StringProperty(
|
|
|
|
"name", controller.mActionFingerIndex_Value.name.BeginReading());
|
|
|
|
actionWriter.StringProperty(
|
|
|
|
"type", controller.mActionFingerIndex_Value.type.BeginReading());
|
|
|
|
actionWriter.EndObject();
|
|
|
|
|
|
|
|
actionWriter.StartObjectElement();
|
|
|
|
actionWriter.StringProperty(
|
|
|
|
"name", controller.mActionFingerMiddle_Value.name.BeginReading());
|
|
|
|
actionWriter.StringProperty(
|
|
|
|
"type", controller.mActionFingerMiddle_Value.type.BeginReading());
|
|
|
|
actionWriter.EndObject();
|
|
|
|
|
|
|
|
actionWriter.StartObjectElement();
|
|
|
|
actionWriter.StringProperty(
|
|
|
|
"name", controller.mActionFingerRing_Value.name.BeginReading());
|
|
|
|
actionWriter.StringProperty(
|
|
|
|
"type", controller.mActionFingerRing_Value.type.BeginReading());
|
|
|
|
actionWriter.EndObject();
|
|
|
|
|
|
|
|
actionWriter.StartObjectElement();
|
|
|
|
actionWriter.StringProperty(
|
|
|
|
"name", controller.mActionFingerPinky_Value.name.BeginReading());
|
|
|
|
actionWriter.StringProperty(
|
|
|
|
"type", controller.mActionFingerPinky_Value.type.BeginReading());
|
|
|
|
actionWriter.EndObject();
|
|
|
|
|
2019-06-26 21:26:16 +03:00
|
|
|
actionWriter.StartObjectElement();
|
|
|
|
actionWriter.StringProperty(
|
|
|
|
"name", controller.mActionBumper_Pressed.name.BeginReading());
|
|
|
|
actionWriter.StringProperty(
|
|
|
|
"type", controller.mActionBumper_Pressed.type.BeginReading());
|
|
|
|
actionWriter.EndObject();
|
|
|
|
|
2019-04-18 02:08:27 +03:00
|
|
|
actionWriter.StartObjectElement();
|
|
|
|
actionWriter.StringProperty("name",
|
|
|
|
controller.mActionHaptic.name.BeginReading());
|
|
|
|
actionWriter.StringProperty("type",
|
|
|
|
controller.mActionHaptic.type.BeginReading());
|
|
|
|
actionWriter.EndObject();
|
|
|
|
}
|
|
|
|
actionWriter.EndArray(); // End "actions": []
|
|
|
|
actionWriter.End();
|
|
|
|
|
|
|
|
std::ofstream actionfile(controllerAction.BeginReading());
|
2019-04-22 23:41:38 +03:00
|
|
|
nsCString actionResult(actionData.get());
|
2019-04-18 02:08:27 +03:00
|
|
|
if (actionfile.is_open()) {
|
|
|
|
actionfile << actionResult.get();
|
|
|
|
actionfile.close();
|
|
|
|
}
|
2018-12-17 23:46:40 +03:00
|
|
|
}
|
|
|
|
|
2019-07-16 10:33:44 +03:00
|
|
|
vr::EVRInputError err =
|
|
|
|
vr::VRInput()->SetActionManifestPath(controllerAction.BeginReading());
|
2019-07-09 01:24:00 +03:00
|
|
|
if (err != vr::VRInputError_None) {
|
|
|
|
NS_WARNING("OpenVR - SetActionManifestPath failed.");
|
|
|
|
return false;
|
|
|
|
}
|
2019-04-22 23:41:38 +03:00
|
|
|
// End of setup controller actions.
|
2018-12-29 01:09:44 +03:00
|
|
|
|
|
|
|
// Notify the parent process these manifest files are already been recorded.
|
2019-07-22 05:10:14 +03:00
|
|
|
if (StaticPrefs::dom_vr_process_enabled_AtStartup()) {
|
2018-12-29 01:09:44 +03:00
|
|
|
NS_DispatchToMainThread(NS_NewRunnableFunction(
|
|
|
|
"SendOpenVRControllerActionPathToParent",
|
2019-06-26 21:26:16 +03:00
|
|
|
[controllerAction, viveManifest, WMRManifest, knucklesManifest,
|
|
|
|
cosmosManifest]() {
|
2018-12-29 01:09:44 +03:00
|
|
|
VRParent* vrParent = VRProcessChild::GetVRParent();
|
|
|
|
Unused << vrParent->SendOpenVRControllerActionPathToParent(
|
|
|
|
controllerAction);
|
|
|
|
Unused << vrParent->SendOpenVRControllerManifestPathToParent(
|
|
|
|
OpenVRControllerType::Vive, viveManifest);
|
|
|
|
Unused << vrParent->SendOpenVRControllerManifestPathToParent(
|
|
|
|
OpenVRControllerType::WMR, WMRManifest);
|
|
|
|
Unused << vrParent->SendOpenVRControllerManifestPathToParent(
|
|
|
|
OpenVRControllerType::Knuckles, knucklesManifest);
|
2019-06-26 21:26:16 +03:00
|
|
|
Unused << vrParent->SendOpenVRControllerManifestPathToParent(
|
|
|
|
OpenVRControllerType::Cosmos, cosmosManifest);
|
2018-12-29 01:09:44 +03:00
|
|
|
}));
|
2019-04-22 23:41:38 +03:00
|
|
|
} else {
|
|
|
|
sControllerActionFile->SetFileName(controllerAction.BeginReading());
|
2018-12-29 01:09:44 +03:00
|
|
|
}
|
2019-04-22 23:41:38 +03:00
|
|
|
|
|
|
|
return true;
|
2018-12-17 23:46:40 +03:00
|
|
|
}
|
|
|
|
|
2018-10-26 00:33:25 +03:00
|
|
|
#if defined(XP_WIN)
|
|
|
|
bool OpenVRSession::CreateD3DObjects() {
|
|
|
|
RefPtr<ID3D11Device> device = gfx::DeviceManagerDx::Get()->GetVRDevice();
|
|
|
|
if (!device) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!CreateD3DContext(device)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void OpenVRSession::Shutdown() {
|
|
|
|
StopHapticTimer();
|
|
|
|
StopHapticThread();
|
2019-10-03 10:53:52 +03:00
|
|
|
if (mVRSystem || mVRCompositor || mVRChaperone) {
|
2018-10-26 00:33:25 +03:00
|
|
|
::vr::VR_Shutdown();
|
|
|
|
mVRCompositor = nullptr;
|
|
|
|
mVRChaperone = nullptr;
|
|
|
|
mVRSystem = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OpenVRSession::InitState(VRSystemState& aSystemState) {
|
|
|
|
VRDisplayState& state = aSystemState.displayState;
|
2019-01-10 00:57:36 +03:00
|
|
|
strncpy(state.displayName, "OpenVR HMD", kVRDisplayNameMaxLen);
|
|
|
|
state.eightCC = GFX_VR_EIGHTCC('O', 'p', 'e', 'n', 'V', 'R', ' ', ' ');
|
|
|
|
state.isConnected =
|
2018-12-21 03:52:24 +03:00
|
|
|
mVRSystem->IsTrackedDeviceConnected(::vr::k_unTrackedDeviceIndex_Hmd);
|
2019-01-10 00:57:36 +03:00
|
|
|
state.isMounted = false;
|
|
|
|
state.capabilityFlags = (VRDisplayCapabilityFlags)(
|
2018-12-21 03:52:24 +03:00
|
|
|
(int)VRDisplayCapabilityFlags::Cap_None |
|
|
|
|
(int)VRDisplayCapabilityFlags::Cap_Orientation |
|
|
|
|
(int)VRDisplayCapabilityFlags::Cap_Position |
|
|
|
|
(int)VRDisplayCapabilityFlags::Cap_External |
|
|
|
|
(int)VRDisplayCapabilityFlags::Cap_Present |
|
2019-07-31 14:46:48 +03:00
|
|
|
(int)VRDisplayCapabilityFlags::Cap_StageParameters |
|
|
|
|
(int)VRDisplayCapabilityFlags::Cap_ImmersiveVR);
|
|
|
|
state.blendMode = VRDisplayBlendMode::Opaque;
|
2019-01-10 00:57:36 +03:00
|
|
|
state.reportsDroppedFrames = true;
|
2018-10-26 00:33:25 +03:00
|
|
|
|
|
|
|
::vr::ETrackedPropertyError err;
|
|
|
|
bool bHasProximitySensor = mVRSystem->GetBoolTrackedDeviceProperty(
|
2018-12-21 03:52:24 +03:00
|
|
|
::vr::k_unTrackedDeviceIndex_Hmd, ::vr::Prop_ContainsProximitySensor_Bool,
|
|
|
|
&err);
|
2018-10-26 00:33:25 +03:00
|
|
|
if (err == ::vr::TrackedProp_Success && bHasProximitySensor) {
|
2019-01-10 00:57:36 +03:00
|
|
|
state.capabilityFlags = (VRDisplayCapabilityFlags)(
|
|
|
|
(int)state.capabilityFlags |
|
2018-12-21 03:52:24 +03:00
|
|
|
(int)VRDisplayCapabilityFlags::Cap_MountDetection);
|
2018-10-26 00:33:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t w, h;
|
|
|
|
mVRSystem->GetRecommendedRenderTargetSize(&w, &h);
|
2019-01-10 00:57:36 +03:00
|
|
|
state.eyeResolution.width = w;
|
|
|
|
state.eyeResolution.height = h;
|
2018-10-26 00:33:25 +03:00
|
|
|
|
|
|
|
// default to an identity quaternion
|
|
|
|
aSystemState.sensorState.pose.orientation[3] = 1.0f;
|
|
|
|
|
|
|
|
UpdateStageParameters(state);
|
|
|
|
UpdateEyeParameters(aSystemState);
|
|
|
|
|
|
|
|
VRHMDSensorState& sensorState = aSystemState.sensorState;
|
2018-12-21 03:52:24 +03:00
|
|
|
sensorState.flags = (VRDisplayCapabilityFlags)(
|
|
|
|
(int)VRDisplayCapabilityFlags::Cap_Orientation |
|
|
|
|
(int)VRDisplayCapabilityFlags::Cap_Position);
|
|
|
|
sensorState.pose.orientation[3] = 1.0f; // Default to an identity quaternion
|
2018-10-26 00:33:25 +03:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OpenVRSession::UpdateStageParameters(VRDisplayState& aState) {
|
|
|
|
float sizeX = 0.0f;
|
|
|
|
float sizeZ = 0.0f;
|
|
|
|
if (mVRChaperone->GetPlayAreaSize(&sizeX, &sizeZ)) {
|
|
|
|
::vr::HmdMatrix34_t t =
|
2018-12-21 03:52:24 +03:00
|
|
|
mVRSystem->GetSeatedZeroPoseToStandingAbsoluteTrackingPose();
|
2019-01-10 00:57:36 +03:00
|
|
|
aState.stageSize.width = sizeX;
|
|
|
|
aState.stageSize.height = sizeZ;
|
|
|
|
|
|
|
|
aState.sittingToStandingTransform[0] = t.m[0][0];
|
|
|
|
aState.sittingToStandingTransform[1] = t.m[1][0];
|
|
|
|
aState.sittingToStandingTransform[2] = t.m[2][0];
|
|
|
|
aState.sittingToStandingTransform[3] = 0.0f;
|
|
|
|
|
|
|
|
aState.sittingToStandingTransform[4] = t.m[0][1];
|
|
|
|
aState.sittingToStandingTransform[5] = t.m[1][1];
|
|
|
|
aState.sittingToStandingTransform[6] = t.m[2][1];
|
|
|
|
aState.sittingToStandingTransform[7] = 0.0f;
|
|
|
|
|
|
|
|
aState.sittingToStandingTransform[8] = t.m[0][2];
|
|
|
|
aState.sittingToStandingTransform[9] = t.m[1][2];
|
|
|
|
aState.sittingToStandingTransform[10] = t.m[2][2];
|
|
|
|
aState.sittingToStandingTransform[11] = 0.0f;
|
|
|
|
|
|
|
|
aState.sittingToStandingTransform[12] = t.m[0][3];
|
|
|
|
aState.sittingToStandingTransform[13] = t.m[1][3];
|
|
|
|
aState.sittingToStandingTransform[14] = t.m[2][3];
|
|
|
|
aState.sittingToStandingTransform[15] = 1.0f;
|
2018-10-26 00:33:25 +03:00
|
|
|
} else {
|
|
|
|
// If we fail, fall back to reasonable defaults.
|
|
|
|
// 1m x 1m space, 0.75m high in seated position
|
2019-01-10 00:57:36 +03:00
|
|
|
aState.stageSize.width = 1.0f;
|
|
|
|
aState.stageSize.height = 1.0f;
|
|
|
|
|
|
|
|
aState.sittingToStandingTransform[0] = 1.0f;
|
|
|
|
aState.sittingToStandingTransform[1] = 0.0f;
|
|
|
|
aState.sittingToStandingTransform[2] = 0.0f;
|
|
|
|
aState.sittingToStandingTransform[3] = 0.0f;
|
|
|
|
|
|
|
|
aState.sittingToStandingTransform[4] = 0.0f;
|
|
|
|
aState.sittingToStandingTransform[5] = 1.0f;
|
|
|
|
aState.sittingToStandingTransform[6] = 0.0f;
|
|
|
|
aState.sittingToStandingTransform[7] = 0.0f;
|
|
|
|
|
|
|
|
aState.sittingToStandingTransform[8] = 0.0f;
|
|
|
|
aState.sittingToStandingTransform[9] = 0.0f;
|
|
|
|
aState.sittingToStandingTransform[10] = 1.0f;
|
|
|
|
aState.sittingToStandingTransform[11] = 0.0f;
|
|
|
|
|
|
|
|
aState.sittingToStandingTransform[12] = 0.0f;
|
|
|
|
aState.sittingToStandingTransform[13] = 0.75f;
|
|
|
|
aState.sittingToStandingTransform[14] = 0.0f;
|
|
|
|
aState.sittingToStandingTransform[15] = 1.0f;
|
2018-10-26 00:33:25 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OpenVRSession::UpdateEyeParameters(VRSystemState& aState) {
|
|
|
|
// This must be called every frame in order to
|
|
|
|
// account for continuous adjustments to ipd.
|
|
|
|
gfx::Matrix4x4 headToEyeTransforms[2];
|
|
|
|
|
|
|
|
for (uint32_t eye = 0; eye < 2; ++eye) {
|
|
|
|
::vr::HmdMatrix34_t eyeToHead =
|
2018-12-21 03:52:24 +03:00
|
|
|
mVRSystem->GetEyeToHeadTransform(static_cast<::vr::Hmd_Eye>(eye));
|
2019-01-10 00:57:36 +03:00
|
|
|
aState.displayState.eyeTranslation[eye].x = eyeToHead.m[0][3];
|
|
|
|
aState.displayState.eyeTranslation[eye].y = eyeToHead.m[1][3];
|
|
|
|
aState.displayState.eyeTranslation[eye].z = eyeToHead.m[2][3];
|
2018-10-26 00:33:25 +03:00
|
|
|
|
|
|
|
float left, right, up, down;
|
|
|
|
mVRSystem->GetProjectionRaw(static_cast<::vr::Hmd_Eye>(eye), &left, &right,
|
|
|
|
&up, &down);
|
2019-01-10 00:57:36 +03:00
|
|
|
aState.displayState.eyeFOV[eye].upDegrees = atan(-up) * 180.0 / M_PI;
|
|
|
|
aState.displayState.eyeFOV[eye].rightDegrees = atan(right) * 180.0 / M_PI;
|
|
|
|
aState.displayState.eyeFOV[eye].downDegrees = atan(down) * 180.0 / M_PI;
|
|
|
|
aState.displayState.eyeFOV[eye].leftDegrees = atan(-left) * 180.0 / M_PI;
|
2018-10-26 00:33:25 +03:00
|
|
|
|
|
|
|
Matrix4x4 pose;
|
|
|
|
// NOTE! eyeToHead.m is a 3x4 matrix, not 4x4. But
|
|
|
|
// because of its arrangement, we can copy the 12 elements in and
|
|
|
|
// then transpose them to the right place.
|
|
|
|
memcpy(&pose._11, &eyeToHead.m, sizeof(eyeToHead.m));
|
|
|
|
pose.Transpose();
|
|
|
|
pose.Invert();
|
|
|
|
headToEyeTransforms[eye] = pose;
|
|
|
|
}
|
|
|
|
aState.sensorState.CalcViewMatrices(headToEyeTransforms);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OpenVRSession::UpdateHeadsetPose(VRSystemState& aState) {
|
|
|
|
const uint32_t posesSize = ::vr::k_unTrackedDeviceIndex_Hmd + 1;
|
|
|
|
::vr::TrackedDevicePose_t poses[posesSize];
|
|
|
|
// Note: We *must* call WaitGetPoses in order for any rendering to happen at
|
|
|
|
// all.
|
|
|
|
mVRCompositor->WaitGetPoses(poses, posesSize, nullptr, 0);
|
|
|
|
|
|
|
|
::vr::Compositor_FrameTiming timing;
|
|
|
|
timing.m_nSize = sizeof(::vr::Compositor_FrameTiming);
|
|
|
|
if (mVRCompositor->GetFrameTiming(&timing)) {
|
|
|
|
aState.sensorState.timestamp = timing.m_flSystemTimeInSeconds;
|
|
|
|
} else {
|
|
|
|
// This should not happen, but log it just in case
|
|
|
|
fprintf(stderr, "OpenVR - IVRCompositor::GetFrameTiming failed");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (poses[::vr::k_unTrackedDeviceIndex_Hmd].bDeviceIsConnected &&
|
|
|
|
poses[::vr::k_unTrackedDeviceIndex_Hmd].bPoseIsValid &&
|
|
|
|
poses[::vr::k_unTrackedDeviceIndex_Hmd].eTrackingResult ==
|
2018-12-21 03:52:24 +03:00
|
|
|
::vr::TrackingResult_Running_OK) {
|
2018-10-26 00:33:25 +03:00
|
|
|
const ::vr::TrackedDevicePose_t& pose =
|
2018-12-21 03:52:24 +03:00
|
|
|
poses[::vr::k_unTrackedDeviceIndex_Hmd];
|
2018-10-26 00:33:25 +03:00
|
|
|
|
|
|
|
gfx::Matrix4x4 m;
|
|
|
|
// NOTE! mDeviceToAbsoluteTracking is a 3x4 matrix, not 4x4. But
|
|
|
|
// because of its arrangement, we can copy the 12 elements in and
|
|
|
|
// then transpose them to the right place. We do this so we can
|
|
|
|
// pull out a Quaternion.
|
|
|
|
memcpy(&m._11, &pose.mDeviceToAbsoluteTracking,
|
|
|
|
sizeof(pose.mDeviceToAbsoluteTracking));
|
|
|
|
m.Transpose();
|
|
|
|
|
|
|
|
gfx::Quaternion rot;
|
|
|
|
rot.SetFromRotationMatrix(m);
|
|
|
|
rot.Invert();
|
|
|
|
|
|
|
|
aState.sensorState.flags = (VRDisplayCapabilityFlags)(
|
2018-12-21 03:52:24 +03:00
|
|
|
(int)aState.sensorState.flags |
|
|
|
|
(int)VRDisplayCapabilityFlags::Cap_Orientation);
|
2018-10-26 00:33:25 +03:00
|
|
|
aState.sensorState.pose.orientation[0] = rot.x;
|
|
|
|
aState.sensorState.pose.orientation[1] = rot.y;
|
|
|
|
aState.sensorState.pose.orientation[2] = rot.z;
|
|
|
|
aState.sensorState.pose.orientation[3] = rot.w;
|
|
|
|
aState.sensorState.pose.angularVelocity[0] = pose.vAngularVelocity.v[0];
|
|
|
|
aState.sensorState.pose.angularVelocity[1] = pose.vAngularVelocity.v[1];
|
|
|
|
aState.sensorState.pose.angularVelocity[2] = pose.vAngularVelocity.v[2];
|
|
|
|
|
|
|
|
aState.sensorState.flags =
|
2018-12-21 03:52:24 +03:00
|
|
|
(VRDisplayCapabilityFlags)((int)aState.sensorState.flags |
|
|
|
|
(int)VRDisplayCapabilityFlags::Cap_Position);
|
2018-10-26 00:33:25 +03:00
|
|
|
aState.sensorState.pose.position[0] = m._41;
|
|
|
|
aState.sensorState.pose.position[1] = m._42;
|
|
|
|
aState.sensorState.pose.position[2] = m._43;
|
|
|
|
aState.sensorState.pose.linearVelocity[0] = pose.vVelocity.v[0];
|
|
|
|
aState.sensorState.pose.linearVelocity[1] = pose.vVelocity.v[1];
|
|
|
|
aState.sensorState.pose.linearVelocity[2] = pose.vVelocity.v[2];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OpenVRSession::EnumerateControllers(VRSystemState& aState) {
|
|
|
|
MOZ_ASSERT(mVRSystem);
|
|
|
|
|
|
|
|
MutexAutoLock lock(mControllerHapticStateMutex);
|
|
|
|
|
|
|
|
bool controllerPresent[kVRControllerMaxCount] = {false};
|
2018-12-17 23:46:40 +03:00
|
|
|
uint32_t stateIndex = 0;
|
|
|
|
mActionsetFirefox = vr::k_ulInvalidActionSetHandle;
|
|
|
|
|
2018-12-21 03:52:24 +03:00
|
|
|
if (vr::VRInput()->GetActionSetHandle(
|
|
|
|
"/actions/firefox", &mActionsetFirefox) != vr::VRInputError_None) {
|
2018-12-17 23:46:40 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-12-21 03:52:24 +03:00
|
|
|
for (int8_t handIndex = 0; handIndex < OpenVRHand::Total; ++handIndex) {
|
2018-12-17 23:46:40 +03:00
|
|
|
if (handIndex == OpenVRHand::Left) {
|
2018-12-21 03:52:24 +03:00
|
|
|
if (vr::VRInput()->GetInputSourceHandle(
|
|
|
|
"/user/hand/left", &mControllerHand[OpenVRHand::Left].mSource) !=
|
|
|
|
vr::VRInputError_None) {
|
2018-12-17 23:46:40 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else if (handIndex == OpenVRHand::Right) {
|
2018-12-21 03:52:24 +03:00
|
|
|
if (vr::VRInput()->GetInputSourceHandle(
|
|
|
|
"/user/hand/right",
|
|
|
|
&mControllerHand[OpenVRHand::Right].mSource) !=
|
|
|
|
vr::VRInputError_None) {
|
2018-12-17 23:46:40 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
MOZ_ASSERT(false, "Unknown OpenVR hand type.");
|
|
|
|
}
|
|
|
|
|
|
|
|
vr::InputOriginInfo_t originInfo;
|
2018-12-21 03:52:24 +03:00
|
|
|
if (vr::VRInput()->GetOriginTrackedDeviceInfo(
|
|
|
|
mControllerHand[handIndex].mSource, &originInfo,
|
|
|
|
sizeof(originInfo)) == vr::VRInputError_None &&
|
|
|
|
originInfo.trackedDeviceIndex != vr::k_unTrackedDeviceIndexInvalid &&
|
|
|
|
mVRSystem->IsTrackedDeviceConnected(originInfo.trackedDeviceIndex)) {
|
|
|
|
const ::vr::ETrackedDeviceClass deviceType =
|
|
|
|
mVRSystem->GetTrackedDeviceClass(originInfo.trackedDeviceIndex);
|
|
|
|
if (deviceType != ::vr::TrackedDeviceClass_Controller &&
|
|
|
|
deviceType != ::vr::TrackedDeviceClass_GenericTracker) {
|
2018-12-17 23:46:40 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mControllerDeviceIndex[stateIndex] != handIndex) {
|
|
|
|
VRControllerState& controllerState = aState.controllerState[stateIndex];
|
|
|
|
|
2018-12-21 03:52:24 +03:00
|
|
|
vr::VRInput()->GetActionHandle(
|
|
|
|
mControllerHand[handIndex].mActionPose.name.BeginReading(),
|
|
|
|
&mControllerHand[handIndex].mActionPose.handle);
|
|
|
|
vr::VRInput()->GetActionHandle(
|
|
|
|
mControllerHand[handIndex].mActionHaptic.name.BeginReading(),
|
|
|
|
&mControllerHand[handIndex].mActionHaptic.handle);
|
|
|
|
vr::VRInput()->GetActionHandle(
|
|
|
|
mControllerHand[handIndex]
|
|
|
|
.mActionTrackpad_Analog.name.BeginReading(),
|
|
|
|
&mControllerHand[handIndex].mActionTrackpad_Analog.handle);
|
|
|
|
vr::VRInput()->GetActionHandle(
|
|
|
|
mControllerHand[handIndex]
|
|
|
|
.mActionTrackpad_Pressed.name.BeginReading(),
|
|
|
|
&mControllerHand[handIndex].mActionTrackpad_Pressed.handle);
|
|
|
|
vr::VRInput()->GetActionHandle(
|
|
|
|
mControllerHand[handIndex]
|
|
|
|
.mActionTrackpad_Touched.name.BeginReading(),
|
|
|
|
&mControllerHand[handIndex].mActionTrackpad_Touched.handle);
|
|
|
|
vr::VRInput()->GetActionHandle(
|
|
|
|
mControllerHand[handIndex].mActionTrigger_Value.name.BeginReading(),
|
|
|
|
&mControllerHand[handIndex].mActionTrigger_Value.handle);
|
|
|
|
vr::VRInput()->GetActionHandle(
|
|
|
|
mControllerHand[handIndex].mActionGrip_Pressed.name.BeginReading(),
|
|
|
|
&mControllerHand[handIndex].mActionGrip_Pressed.handle);
|
|
|
|
vr::VRInput()->GetActionHandle(
|
|
|
|
mControllerHand[handIndex].mActionGrip_Touched.name.BeginReading(),
|
|
|
|
&mControllerHand[handIndex].mActionGrip_Touched.handle);
|
|
|
|
vr::VRInput()->GetActionHandle(
|
|
|
|
mControllerHand[handIndex].mActionMenu_Pressed.name.BeginReading(),
|
|
|
|
&mControllerHand[handIndex].mActionMenu_Pressed.handle);
|
|
|
|
vr::VRInput()->GetActionHandle(
|
|
|
|
mControllerHand[handIndex].mActionMenu_Touched.name.BeginReading(),
|
|
|
|
&mControllerHand[handIndex].mActionMenu_Touched.handle);
|
|
|
|
vr::VRInput()->GetActionHandle(
|
|
|
|
mControllerHand[handIndex]
|
|
|
|
.mActionSystem_Pressed.name.BeginReading(),
|
|
|
|
&mControllerHand[handIndex].mActionSystem_Pressed.handle);
|
|
|
|
vr::VRInput()->GetActionHandle(
|
|
|
|
mControllerHand[handIndex]
|
|
|
|
.mActionSystem_Touched.name.BeginReading(),
|
|
|
|
&mControllerHand[handIndex].mActionSystem_Touched.handle);
|
|
|
|
vr::VRInput()->GetActionHandle(
|
|
|
|
mControllerHand[handIndex].mActionA_Pressed.name.BeginReading(),
|
|
|
|
&mControllerHand[handIndex].mActionA_Pressed.handle);
|
|
|
|
vr::VRInput()->GetActionHandle(
|
|
|
|
mControllerHand[handIndex].mActionA_Touched.name.BeginReading(),
|
|
|
|
&mControllerHand[handIndex].mActionA_Touched.handle);
|
|
|
|
vr::VRInput()->GetActionHandle(
|
|
|
|
mControllerHand[handIndex].mActionB_Pressed.name.BeginReading(),
|
|
|
|
&mControllerHand[handIndex].mActionB_Pressed.handle);
|
|
|
|
vr::VRInput()->GetActionHandle(
|
|
|
|
mControllerHand[handIndex].mActionB_Touched.name.BeginReading(),
|
|
|
|
&mControllerHand[handIndex].mActionB_Touched.handle);
|
|
|
|
vr::VRInput()->GetActionHandle(
|
|
|
|
mControllerHand[handIndex]
|
|
|
|
.mActionThumbstick_Analog.name.BeginReading(),
|
|
|
|
&mControllerHand[handIndex].mActionThumbstick_Analog.handle);
|
|
|
|
vr::VRInput()->GetActionHandle(
|
|
|
|
mControllerHand[handIndex]
|
|
|
|
.mActionThumbstick_Pressed.name.BeginReading(),
|
|
|
|
&mControllerHand[handIndex].mActionThumbstick_Pressed.handle);
|
|
|
|
vr::VRInput()->GetActionHandle(
|
|
|
|
mControllerHand[handIndex]
|
|
|
|
.mActionThumbstick_Touched.name.BeginReading(),
|
|
|
|
&mControllerHand[handIndex].mActionThumbstick_Touched.handle);
|
|
|
|
vr::VRInput()->GetActionHandle(
|
|
|
|
mControllerHand[handIndex]
|
|
|
|
.mActionFingerIndex_Value.name.BeginReading(),
|
|
|
|
&mControllerHand[handIndex].mActionFingerIndex_Value.handle);
|
|
|
|
vr::VRInput()->GetActionHandle(
|
|
|
|
mControllerHand[handIndex]
|
|
|
|
.mActionFingerMiddle_Value.name.BeginReading(),
|
|
|
|
&mControllerHand[handIndex].mActionFingerMiddle_Value.handle);
|
|
|
|
vr::VRInput()->GetActionHandle(
|
|
|
|
mControllerHand[handIndex]
|
|
|
|
.mActionFingerRing_Value.name.BeginReading(),
|
|
|
|
&mControllerHand[handIndex].mActionFingerRing_Value.handle);
|
|
|
|
vr::VRInput()->GetActionHandle(
|
|
|
|
mControllerHand[handIndex]
|
|
|
|
.mActionFingerPinky_Value.name.BeginReading(),
|
|
|
|
&mControllerHand[handIndex].mActionFingerPinky_Value.handle);
|
2019-07-16 10:33:44 +03:00
|
|
|
vr::VRInput()->GetActionHandle(
|
|
|
|
mControllerHand[handIndex]
|
|
|
|
.mActionBumper_Pressed.name.BeginReading(),
|
2019-06-26 21:26:16 +03:00
|
|
|
&mControllerHand[handIndex].mActionBumper_Pressed.handle);
|
2018-12-17 23:46:40 +03:00
|
|
|
|
|
|
|
nsCString deviceId;
|
2018-12-21 03:52:24 +03:00
|
|
|
GetControllerDeviceId(deviceType, originInfo.trackedDeviceIndex,
|
|
|
|
deviceId);
|
|
|
|
strncpy(controllerState.controllerName, deviceId.BeginReading(),
|
|
|
|
kVRControllerNameMaxLen);
|
2018-12-17 23:46:40 +03:00
|
|
|
controllerState.numHaptics = kNumOpenVRHaptics;
|
|
|
|
}
|
|
|
|
controllerPresent[stateIndex] = true;
|
|
|
|
mControllerDeviceIndex[stateIndex] = static_cast<OpenVRHand>(handIndex);
|
|
|
|
++stateIndex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clear out entries for disconnected controllers
|
2018-12-21 03:52:24 +03:00
|
|
|
for (uint32_t stateIndex = 0; stateIndex < kVRControllerMaxCount;
|
|
|
|
stateIndex++) {
|
|
|
|
if (!controllerPresent[stateIndex] &&
|
|
|
|
mControllerDeviceIndex[stateIndex] != OpenVRHand::None) {
|
2018-12-17 23:46:40 +03:00
|
|
|
mControllerDeviceIndex[stateIndex] = OpenVRHand::None;
|
|
|
|
memset(&aState.controllerState[stateIndex], 0, sizeof(VRControllerState));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-26 00:33:25 +03:00
|
|
|
void OpenVRSession::UpdateControllerButtons(VRSystemState& aState) {
|
|
|
|
MOZ_ASSERT(mVRSystem);
|
|
|
|
|
|
|
|
// Compared to Edge, we have a wrong implementation for the vertical axis
|
|
|
|
// value. In order to not affect the current VR content, we add a workaround
|
|
|
|
// for yAxis.
|
|
|
|
const float yAxisInvert = (mIsWindowsMR) ? -1.0f : 1.0f;
|
2019-06-25 09:32:29 +03:00
|
|
|
const float triggerThreshold =
|
|
|
|
StaticPrefs::dom_vr_controller_trigger_threshold();
|
2018-10-26 00:33:25 +03:00
|
|
|
|
2018-12-21 03:52:24 +03:00
|
|
|
for (uint32_t stateIndex = 0; stateIndex < kVRControllerMaxCount;
|
|
|
|
++stateIndex) {
|
2019-12-18 01:21:53 +03:00
|
|
|
const OpenVRHand role = mControllerDeviceIndex[stateIndex];
|
|
|
|
if (role == OpenVRHand::None) {
|
2018-12-17 23:46:40 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
VRControllerState& controllerState = aState.controllerState[stateIndex];
|
2019-12-18 01:21:53 +03:00
|
|
|
controllerState.hand = GetControllerHandFromControllerRole(role);
|
2018-12-17 23:46:40 +03:00
|
|
|
|
|
|
|
uint32_t axisIdx = 0;
|
|
|
|
uint32_t buttonIdx = 0;
|
|
|
|
// Axis 0 1: Trackpad
|
|
|
|
// Button 0: Trackpad
|
|
|
|
vr::InputAnalogActionData_t analogData;
|
2019-12-18 01:21:53 +03:00
|
|
|
if (mControllerHand[role].mActionTrackpad_Analog.handle &&
|
2018-12-21 03:52:24 +03:00
|
|
|
vr::VRInput()->GetAnalogActionData(
|
2019-12-18 01:21:53 +03:00
|
|
|
mControllerHand[role].mActionTrackpad_Analog.handle, &analogData,
|
|
|
|
sizeof(analogData),
|
2018-12-21 03:52:24 +03:00
|
|
|
vr::k_ulInvalidInputValueHandle) == vr::VRInputError_None &&
|
|
|
|
analogData.bActive) {
|
2018-12-17 23:46:40 +03:00
|
|
|
controllerState.axisValue[axisIdx] = analogData.x;
|
|
|
|
++axisIdx;
|
|
|
|
controllerState.axisValue[axisIdx] = analogData.y * yAxisInvert;
|
|
|
|
++axisIdx;
|
|
|
|
}
|
|
|
|
vr::InputDigitalActionData_t actionData;
|
|
|
|
bool bPressed = false;
|
|
|
|
bool bTouched = false;
|
|
|
|
uint64_t mask = 0;
|
2019-12-18 01:21:53 +03:00
|
|
|
if (mControllerHand[role].mActionTrackpad_Pressed.handle &&
|
2018-12-21 03:52:24 +03:00
|
|
|
vr::VRInput()->GetDigitalActionData(
|
2019-12-18 01:21:53 +03:00
|
|
|
mControllerHand[role].mActionTrackpad_Pressed.handle, &actionData,
|
|
|
|
sizeof(actionData),
|
2018-12-21 03:52:24 +03:00
|
|
|
vr::k_ulInvalidInputValueHandle) == vr::VRInputError_None &&
|
2018-12-17 23:46:40 +03:00
|
|
|
actionData.bActive) {
|
|
|
|
bPressed = actionData.bState;
|
|
|
|
mask = (1ULL << buttonIdx);
|
|
|
|
controllerState.triggerValue[buttonIdx] = bPressed ? 1.0 : 0.0f;
|
|
|
|
if (bPressed) {
|
|
|
|
controllerState.buttonPressed |= mask;
|
|
|
|
} else {
|
|
|
|
controllerState.buttonPressed &= ~mask;
|
|
|
|
}
|
2019-12-18 01:21:53 +03:00
|
|
|
if (mControllerHand[role].mActionTrackpad_Touched.handle &&
|
2018-12-21 03:52:24 +03:00
|
|
|
vr::VRInput()->GetDigitalActionData(
|
2019-12-18 01:21:53 +03:00
|
|
|
mControllerHand[role].mActionTrackpad_Touched.handle, &actionData,
|
|
|
|
sizeof(actionData),
|
2018-12-21 03:52:24 +03:00
|
|
|
vr::k_ulInvalidInputValueHandle) == vr::VRInputError_None) {
|
2018-12-17 23:46:40 +03:00
|
|
|
bTouched = actionData.bActive && actionData.bState;
|
|
|
|
mask = (1ULL << buttonIdx);
|
|
|
|
if (bTouched) {
|
|
|
|
controllerState.buttonTouched |= mask;
|
|
|
|
} else {
|
|
|
|
controllerState.buttonTouched &= ~mask;
|
|
|
|
}
|
|
|
|
}
|
2018-12-21 03:52:24 +03:00
|
|
|
++buttonIdx;
|
2018-12-17 23:46:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Button 1: Trigger
|
2019-12-18 01:21:53 +03:00
|
|
|
if (mControllerHand[role].mActionTrigger_Value.handle &&
|
2018-12-21 03:52:24 +03:00
|
|
|
vr::VRInput()->GetAnalogActionData(
|
2019-12-18 01:21:53 +03:00
|
|
|
mControllerHand[role].mActionTrigger_Value.handle, &analogData,
|
|
|
|
sizeof(analogData),
|
2018-12-21 03:52:24 +03:00
|
|
|
vr::k_ulInvalidInputValueHandle) == vr::VRInputError_None &&
|
|
|
|
analogData.bActive) {
|
2018-12-17 23:46:40 +03:00
|
|
|
UpdateTrigger(controllerState, buttonIdx, analogData.x, triggerThreshold);
|
|
|
|
++buttonIdx;
|
|
|
|
}
|
2018-12-21 03:52:24 +03:00
|
|
|
|
2018-12-17 23:46:40 +03:00
|
|
|
// Button 2: Grip
|
2019-12-18 01:21:53 +03:00
|
|
|
if (mControllerHand[role].mActionGrip_Pressed.handle &&
|
2018-12-21 03:52:24 +03:00
|
|
|
vr::VRInput()->GetDigitalActionData(
|
2019-12-18 01:21:53 +03:00
|
|
|
mControllerHand[role].mActionGrip_Pressed.handle, &actionData,
|
2018-12-21 03:52:24 +03:00
|
|
|
sizeof(actionData),
|
|
|
|
vr::k_ulInvalidInputValueHandle) == vr::VRInputError_None &&
|
|
|
|
actionData.bActive) {
|
2018-12-17 23:46:40 +03:00
|
|
|
bPressed = actionData.bState;
|
|
|
|
mask = (1ULL << buttonIdx);
|
|
|
|
controllerState.triggerValue[buttonIdx] = bPressed ? 1.0 : 0.0f;
|
|
|
|
if (bPressed) {
|
|
|
|
controllerState.buttonPressed |= mask;
|
|
|
|
} else {
|
|
|
|
controllerState.buttonPressed &= ~mask;
|
|
|
|
}
|
2019-12-18 01:21:53 +03:00
|
|
|
if (mControllerHand[role].mActionGrip_Touched.handle &&
|
2018-12-21 03:52:24 +03:00
|
|
|
vr::VRInput()->GetDigitalActionData(
|
2019-12-18 01:21:53 +03:00
|
|
|
mControllerHand[role].mActionGrip_Touched.handle, &actionData,
|
|
|
|
sizeof(actionData),
|
2018-12-21 03:52:24 +03:00
|
|
|
vr::k_ulInvalidInputValueHandle) == vr::VRInputError_None) {
|
2018-12-17 23:46:40 +03:00
|
|
|
bTouched = actionData.bActive && actionData.bState;
|
|
|
|
mask = (1ULL << buttonIdx);
|
|
|
|
if (bTouched) {
|
|
|
|
controllerState.buttonTouched |= mask;
|
|
|
|
} else {
|
|
|
|
controllerState.buttonTouched &= ~mask;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
++buttonIdx;
|
|
|
|
}
|
2018-12-21 03:52:24 +03:00
|
|
|
|
2018-12-17 23:46:40 +03:00
|
|
|
// Button 3: Menu
|
2019-12-18 01:21:53 +03:00
|
|
|
if (mControllerHand[role].mActionMenu_Pressed.handle &&
|
2018-12-21 03:52:24 +03:00
|
|
|
vr::VRInput()->GetDigitalActionData(
|
2019-12-18 01:21:53 +03:00
|
|
|
mControllerHand[role].mActionMenu_Pressed.handle, &actionData,
|
2018-12-21 03:52:24 +03:00
|
|
|
sizeof(actionData),
|
|
|
|
vr::k_ulInvalidInputValueHandle) == vr::VRInputError_None &&
|
|
|
|
actionData.bActive) {
|
2018-12-17 23:46:40 +03:00
|
|
|
bPressed = actionData.bState;
|
|
|
|
mask = (1ULL << buttonIdx);
|
|
|
|
controllerState.triggerValue[buttonIdx] = bPressed ? 1.0 : 0.0f;
|
|
|
|
if (bPressed) {
|
|
|
|
controllerState.buttonPressed |= mask;
|
|
|
|
} else {
|
|
|
|
controllerState.buttonPressed &= ~mask;
|
|
|
|
}
|
2019-12-18 01:21:53 +03:00
|
|
|
if (mControllerHand[role].mActionMenu_Touched.handle &&
|
2018-12-21 03:52:24 +03:00
|
|
|
vr::VRInput()->GetDigitalActionData(
|
2019-12-18 01:21:53 +03:00
|
|
|
mControllerHand[role].mActionMenu_Touched.handle, &actionData,
|
|
|
|
sizeof(actionData),
|
2018-12-21 03:52:24 +03:00
|
|
|
vr::k_ulInvalidInputValueHandle) == vr::VRInputError_None) {
|
|
|
|
bTouched = actionData.bActive && actionData.bState;
|
|
|
|
mask = (1ULL << buttonIdx);
|
|
|
|
if (bTouched) {
|
|
|
|
controllerState.buttonTouched |= mask;
|
|
|
|
} else {
|
|
|
|
controllerState.buttonTouched &= ~mask;
|
|
|
|
}
|
2018-12-17 23:46:40 +03:00
|
|
|
}
|
|
|
|
++buttonIdx;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Button 3: System
|
2019-12-18 01:21:53 +03:00
|
|
|
if (mControllerHand[role].mActionSystem_Pressed.handle &&
|
2018-12-21 03:52:24 +03:00
|
|
|
vr::VRInput()->GetDigitalActionData(
|
2019-12-18 01:21:53 +03:00
|
|
|
mControllerHand[role].mActionSystem_Pressed.handle, &actionData,
|
|
|
|
sizeof(actionData),
|
2018-12-21 03:52:24 +03:00
|
|
|
vr::k_ulInvalidInputValueHandle) == vr::VRInputError_None &&
|
|
|
|
actionData.bActive) {
|
2018-12-17 23:46:40 +03:00
|
|
|
bPressed = actionData.bState;
|
|
|
|
mask = (1ULL << buttonIdx);
|
|
|
|
controllerState.triggerValue[buttonIdx] = bPressed ? 1.0 : 0.0f;
|
|
|
|
if (bPressed) {
|
|
|
|
controllerState.buttonPressed |= mask;
|
|
|
|
} else {
|
|
|
|
controllerState.buttonPressed &= ~mask;
|
|
|
|
}
|
2019-12-18 01:21:53 +03:00
|
|
|
if (mControllerHand[role].mActionSystem_Touched.handle &&
|
2018-12-21 03:52:24 +03:00
|
|
|
vr::VRInput()->GetDigitalActionData(
|
2019-12-18 01:21:53 +03:00
|
|
|
mControllerHand[role].mActionSystem_Touched.handle, &actionData,
|
|
|
|
sizeof(actionData),
|
2018-12-21 03:52:24 +03:00
|
|
|
vr::k_ulInvalidInputValueHandle) == vr::VRInputError_None) {
|
|
|
|
bTouched = actionData.bActive && actionData.bState;
|
|
|
|
mask = (1ULL << buttonIdx);
|
|
|
|
if (bTouched) {
|
|
|
|
controllerState.buttonTouched |= mask;
|
|
|
|
} else {
|
|
|
|
controllerState.buttonTouched &= ~mask;
|
|
|
|
}
|
2018-12-17 23:46:40 +03:00
|
|
|
}
|
|
|
|
++buttonIdx;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Button 4: A
|
2019-12-18 01:21:53 +03:00
|
|
|
if (mControllerHand[role].mActionA_Pressed.handle &&
|
2018-12-21 03:52:24 +03:00
|
|
|
vr::VRInput()->GetDigitalActionData(
|
2019-12-18 01:21:53 +03:00
|
|
|
mControllerHand[role].mActionA_Pressed.handle, &actionData,
|
2018-12-21 03:52:24 +03:00
|
|
|
sizeof(actionData),
|
|
|
|
vr::k_ulInvalidInputValueHandle) == vr::VRInputError_None &&
|
|
|
|
actionData.bActive) {
|
2018-12-17 23:46:40 +03:00
|
|
|
bPressed = actionData.bState;
|
|
|
|
mask = (1ULL << buttonIdx);
|
|
|
|
controllerState.triggerValue[buttonIdx] = bPressed ? 1.0 : 0.0f;
|
|
|
|
if (bPressed) {
|
|
|
|
controllerState.buttonPressed |= mask;
|
|
|
|
} else {
|
|
|
|
controllerState.buttonPressed &= ~mask;
|
|
|
|
}
|
2019-12-18 01:21:53 +03:00
|
|
|
if (mControllerHand[role].mActionA_Touched.handle &&
|
2018-12-21 03:52:24 +03:00
|
|
|
vr::VRInput()->GetDigitalActionData(
|
2019-12-18 01:21:53 +03:00
|
|
|
mControllerHand[role].mActionA_Touched.handle, &actionData,
|
2018-12-21 03:52:24 +03:00
|
|
|
sizeof(actionData),
|
|
|
|
vr::k_ulInvalidInputValueHandle) == vr::VRInputError_None) {
|
2018-12-17 23:46:40 +03:00
|
|
|
bTouched = actionData.bActive && actionData.bState;
|
|
|
|
mask = (1ULL << buttonIdx);
|
|
|
|
if (bTouched) {
|
|
|
|
controllerState.buttonTouched |= mask;
|
|
|
|
} else {
|
|
|
|
controllerState.buttonTouched &= ~mask;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
++buttonIdx;
|
|
|
|
}
|
2019-06-26 21:26:16 +03:00
|
|
|
|
2018-12-17 23:46:40 +03:00
|
|
|
// Button 5: B
|
2019-12-18 01:21:53 +03:00
|
|
|
if (mControllerHand[role].mActionB_Pressed.handle &&
|
2018-12-21 03:52:24 +03:00
|
|
|
vr::VRInput()->GetDigitalActionData(
|
2019-12-18 01:21:53 +03:00
|
|
|
mControllerHand[role].mActionB_Pressed.handle, &actionData,
|
2018-12-21 03:52:24 +03:00
|
|
|
sizeof(actionData),
|
|
|
|
vr::k_ulInvalidInputValueHandle) == vr::VRInputError_None &&
|
|
|
|
actionData.bActive) {
|
2018-12-17 23:46:40 +03:00
|
|
|
bPressed = actionData.bState;
|
|
|
|
mask = (1ULL << buttonIdx);
|
|
|
|
controllerState.triggerValue[buttonIdx] = bPressed ? 1.0 : 0.0f;
|
|
|
|
if (bPressed) {
|
|
|
|
controllerState.buttonPressed |= mask;
|
|
|
|
} else {
|
|
|
|
controllerState.buttonPressed &= ~mask;
|
|
|
|
}
|
2019-12-18 01:21:53 +03:00
|
|
|
if (mControllerHand[role].mActionB_Touched.handle &&
|
2018-12-21 03:52:24 +03:00
|
|
|
vr::VRInput()->GetDigitalActionData(
|
2019-12-18 01:21:53 +03:00
|
|
|
mControllerHand[role].mActionB_Touched.handle, &actionData,
|
2018-12-21 03:52:24 +03:00
|
|
|
sizeof(actionData),
|
|
|
|
vr::k_ulInvalidInputValueHandle) == vr::VRInputError_None) {
|
2018-12-17 23:46:40 +03:00
|
|
|
bTouched = actionData.bActive && actionData.bState;
|
|
|
|
mask = (1ULL << buttonIdx);
|
|
|
|
if (bTouched) {
|
|
|
|
controllerState.buttonTouched |= mask;
|
|
|
|
} else {
|
|
|
|
controllerState.buttonTouched &= ~mask;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
++buttonIdx;
|
|
|
|
}
|
2019-06-26 21:26:16 +03:00
|
|
|
|
2018-12-17 23:46:40 +03:00
|
|
|
// Axis 2 3: Thumbstick
|
|
|
|
// Button 6: Thumbstick
|
2019-12-18 01:21:53 +03:00
|
|
|
if (mControllerHand[role].mActionThumbstick_Analog.handle &&
|
2018-12-21 03:52:24 +03:00
|
|
|
vr::VRInput()->GetAnalogActionData(
|
2019-12-18 01:21:53 +03:00
|
|
|
mControllerHand[role].mActionThumbstick_Analog.handle, &analogData,
|
|
|
|
sizeof(analogData),
|
2018-12-21 03:52:24 +03:00
|
|
|
vr::k_ulInvalidInputValueHandle) == vr::VRInputError_None &&
|
|
|
|
analogData.bActive) {
|
2018-12-17 23:46:40 +03:00
|
|
|
controllerState.axisValue[axisIdx] = analogData.x;
|
|
|
|
++axisIdx;
|
|
|
|
controllerState.axisValue[axisIdx] = analogData.y * yAxisInvert;
|
|
|
|
++axisIdx;
|
|
|
|
}
|
2019-12-18 01:21:53 +03:00
|
|
|
if (mControllerHand[role].mActionThumbstick_Pressed.handle &&
|
2018-12-21 03:52:24 +03:00
|
|
|
vr::VRInput()->GetDigitalActionData(
|
2019-12-18 01:21:53 +03:00
|
|
|
mControllerHand[role].mActionThumbstick_Pressed.handle, &actionData,
|
|
|
|
sizeof(actionData),
|
2018-12-21 03:52:24 +03:00
|
|
|
vr::k_ulInvalidInputValueHandle) == vr::VRInputError_None &&
|
|
|
|
actionData.bActive) {
|
2018-12-17 23:46:40 +03:00
|
|
|
bPressed = actionData.bState;
|
2019-06-26 21:26:16 +03:00
|
|
|
mask = (1ULL << buttonIdx);
|
2018-12-17 23:46:40 +03:00
|
|
|
controllerState.triggerValue[buttonIdx] = bPressed ? 1.0 : 0.0f;
|
|
|
|
if (bPressed) {
|
|
|
|
controllerState.buttonPressed |= mask;
|
|
|
|
} else {
|
|
|
|
controllerState.buttonPressed &= ~mask;
|
|
|
|
}
|
2019-12-18 01:21:53 +03:00
|
|
|
if (mControllerHand[role].mActionThumbstick_Touched.handle &&
|
2018-12-21 03:52:24 +03:00
|
|
|
vr::VRInput()->GetDigitalActionData(
|
2019-12-18 01:21:53 +03:00
|
|
|
mControllerHand[role].mActionThumbstick_Touched.handle,
|
2018-12-21 03:52:24 +03:00
|
|
|
&actionData, sizeof(actionData),
|
|
|
|
vr::k_ulInvalidInputValueHandle) == vr::VRInputError_None) {
|
2018-12-17 23:46:40 +03:00
|
|
|
bTouched = actionData.bActive && actionData.bState;
|
|
|
|
mask = (1ULL << buttonIdx);
|
|
|
|
if (bTouched) {
|
|
|
|
controllerState.buttonTouched |= mask;
|
|
|
|
} else {
|
|
|
|
controllerState.buttonTouched &= ~mask;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
++buttonIdx;
|
|
|
|
}
|
2019-06-26 21:26:16 +03:00
|
|
|
|
|
|
|
// Button 7: Bumper (Cosmos only)
|
2019-12-18 01:21:53 +03:00
|
|
|
if (mControllerHand[role].mActionBumper_Pressed.handle &&
|
2019-06-26 21:26:16 +03:00
|
|
|
vr::VRInput()->GetDigitalActionData(
|
2019-12-18 01:21:53 +03:00
|
|
|
mControllerHand[role].mActionBumper_Pressed.handle, &actionData,
|
|
|
|
sizeof(actionData),
|
2019-06-26 21:26:16 +03:00
|
|
|
vr::k_ulInvalidInputValueHandle) == vr::VRInputError_None &&
|
|
|
|
actionData.bActive) {
|
|
|
|
bPressed = actionData.bState;
|
|
|
|
mask = (1ULL << buttonIdx);
|
|
|
|
controllerState.triggerValue[buttonIdx] = bPressed ? 1.0 : 0.0f;
|
|
|
|
if (bPressed) {
|
|
|
|
controllerState.buttonPressed |= mask;
|
|
|
|
} else {
|
|
|
|
controllerState.buttonPressed &= ~mask;
|
|
|
|
}
|
|
|
|
++buttonIdx;
|
|
|
|
}
|
|
|
|
|
2018-12-17 23:46:40 +03:00
|
|
|
// Button 7: Finger index
|
2019-12-18 01:21:53 +03:00
|
|
|
if (mControllerHand[role].mActionFingerIndex_Value.handle &&
|
2018-12-21 03:52:24 +03:00
|
|
|
vr::VRInput()->GetAnalogActionData(
|
2019-12-18 01:21:53 +03:00
|
|
|
mControllerHand[role].mActionFingerIndex_Value.handle, &analogData,
|
|
|
|
sizeof(analogData),
|
2018-12-21 03:52:24 +03:00
|
|
|
vr::k_ulInvalidInputValueHandle) == vr::VRInputError_None &&
|
|
|
|
analogData.bActive) {
|
|
|
|
UpdateTrigger(controllerState, buttonIdx, analogData.x, triggerThreshold);
|
2018-12-17 23:46:40 +03:00
|
|
|
++buttonIdx;
|
|
|
|
}
|
2019-06-26 21:26:16 +03:00
|
|
|
|
2018-12-17 23:46:40 +03:00
|
|
|
// Button 8: Finger middle
|
2019-12-18 01:21:53 +03:00
|
|
|
if (mControllerHand[role].mActionFingerMiddle_Value.handle &&
|
2018-12-21 03:52:24 +03:00
|
|
|
vr::VRInput()->GetAnalogActionData(
|
2019-12-18 01:21:53 +03:00
|
|
|
mControllerHand[role].mActionFingerMiddle_Value.handle, &analogData,
|
|
|
|
sizeof(analogData),
|
2018-12-21 03:52:24 +03:00
|
|
|
vr::k_ulInvalidInputValueHandle) == vr::VRInputError_None &&
|
|
|
|
analogData.bActive) {
|
|
|
|
UpdateTrigger(controllerState, buttonIdx, analogData.x, triggerThreshold);
|
2018-12-17 23:46:40 +03:00
|
|
|
++buttonIdx;
|
|
|
|
}
|
2019-06-26 21:26:16 +03:00
|
|
|
|
2018-12-17 23:46:40 +03:00
|
|
|
// Button 9: Finger ring
|
2019-12-18 01:21:53 +03:00
|
|
|
if (mControllerHand[role].mActionFingerRing_Value.handle &&
|
2018-12-21 03:52:24 +03:00
|
|
|
vr::VRInput()->GetAnalogActionData(
|
2019-12-18 01:21:53 +03:00
|
|
|
mControllerHand[role].mActionFingerRing_Value.handle, &analogData,
|
|
|
|
sizeof(analogData),
|
2018-12-21 03:52:24 +03:00
|
|
|
vr::k_ulInvalidInputValueHandle) == vr::VRInputError_None &&
|
|
|
|
analogData.bActive) {
|
|
|
|
UpdateTrigger(controllerState, buttonIdx, analogData.x, triggerThreshold);
|
2018-12-17 23:46:40 +03:00
|
|
|
++buttonIdx;
|
|
|
|
}
|
2019-06-26 21:26:16 +03:00
|
|
|
|
2018-12-17 23:46:40 +03:00
|
|
|
// Button 10: Finger pinky
|
2019-12-18 01:21:53 +03:00
|
|
|
if (mControllerHand[role].mActionFingerPinky_Value.handle &&
|
2018-12-21 03:52:24 +03:00
|
|
|
vr::VRInput()->GetAnalogActionData(
|
2019-12-18 01:21:53 +03:00
|
|
|
mControllerHand[role].mActionFingerPinky_Value.handle, &analogData,
|
|
|
|
sizeof(analogData),
|
2018-12-21 03:52:24 +03:00
|
|
|
vr::k_ulInvalidInputValueHandle) == vr::VRInputError_None &&
|
|
|
|
analogData.bActive) {
|
|
|
|
UpdateTrigger(controllerState, buttonIdx, analogData.x, triggerThreshold);
|
2018-12-17 23:46:40 +03:00
|
|
|
++buttonIdx;
|
|
|
|
}
|
|
|
|
|
2018-12-21 03:52:24 +03:00
|
|
|
controllerState.numButtons = buttonIdx;
|
|
|
|
controllerState.numAxes = axisIdx;
|
2018-12-17 23:46:40 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-26 00:33:25 +03:00
|
|
|
void OpenVRSession::UpdateControllerPoses(VRSystemState& aState) {
|
|
|
|
MOZ_ASSERT(mVRSystem);
|
|
|
|
|
2019-12-18 01:21:53 +03:00
|
|
|
for (uint32_t stateIndex = 0; stateIndex < kVRControllerMaxCount;
|
|
|
|
++stateIndex) {
|
|
|
|
const OpenVRHand role = mControllerDeviceIndex[stateIndex];
|
|
|
|
if (role == OpenVRHand::None) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
VRControllerState& controllerState = aState.controllerState[stateIndex];
|
2018-12-17 23:46:40 +03:00
|
|
|
vr::InputPoseActionData_t poseData;
|
2018-12-21 03:52:24 +03:00
|
|
|
if (vr::VRInput()->GetPoseActionData(
|
2019-12-18 01:21:53 +03:00
|
|
|
mControllerHand[role].mActionPose.handle,
|
2018-12-21 03:52:24 +03:00
|
|
|
vr::TrackingUniverseSeated, 0, &poseData, sizeof(poseData),
|
|
|
|
vr::k_ulInvalidInputValueHandle) != vr::VRInputError_None ||
|
2018-12-17 23:46:40 +03:00
|
|
|
!poseData.bActive || !poseData.pose.bPoseIsValid) {
|
|
|
|
controllerState.isOrientationValid = false;
|
|
|
|
controllerState.isPositionValid = false;
|
|
|
|
} else {
|
|
|
|
const ::vr::TrackedDevicePose_t& pose = poseData.pose;
|
|
|
|
if (pose.bDeviceIsConnected) {
|
|
|
|
controllerState.flags = (dom::GamepadCapabilityFlags::Cap_Orientation |
|
|
|
|
dom::GamepadCapabilityFlags::Cap_Position);
|
|
|
|
} else {
|
|
|
|
controllerState.flags = dom::GamepadCapabilityFlags::Cap_None;
|
|
|
|
}
|
|
|
|
if (pose.bPoseIsValid &&
|
|
|
|
pose.eTrackingResult == ::vr::TrackingResult_Running_OK) {
|
|
|
|
gfx::Matrix4x4 m;
|
|
|
|
|
|
|
|
// NOTE! mDeviceToAbsoluteTracking is a 3x4 matrix, not 4x4. But
|
|
|
|
// because of its arrangement, we can copy the 12 elements in and
|
|
|
|
// then transpose them to the right place. We do this so we can
|
|
|
|
// pull out a Quaternion.
|
|
|
|
memcpy(&m.components, &pose.mDeviceToAbsoluteTracking,
|
|
|
|
sizeof(pose.mDeviceToAbsoluteTracking));
|
|
|
|
m.Transpose();
|
|
|
|
|
|
|
|
gfx::Quaternion rot;
|
|
|
|
rot.SetFromRotationMatrix(m);
|
|
|
|
rot.Invert();
|
|
|
|
|
|
|
|
controllerState.pose.orientation[0] = rot.x;
|
|
|
|
controllerState.pose.orientation[1] = rot.y;
|
|
|
|
controllerState.pose.orientation[2] = rot.z;
|
|
|
|
controllerState.pose.orientation[3] = rot.w;
|
|
|
|
controllerState.pose.angularVelocity[0] = pose.vAngularVelocity.v[0];
|
|
|
|
controllerState.pose.angularVelocity[1] = pose.vAngularVelocity.v[1];
|
|
|
|
controllerState.pose.angularVelocity[2] = pose.vAngularVelocity.v[2];
|
|
|
|
controllerState.pose.angularAcceleration[0] = 0.0f;
|
|
|
|
controllerState.pose.angularAcceleration[1] = 0.0f;
|
|
|
|
controllerState.pose.angularAcceleration[2] = 0.0f;
|
|
|
|
controllerState.isOrientationValid = true;
|
|
|
|
|
|
|
|
controllerState.pose.position[0] = m._41;
|
|
|
|
controllerState.pose.position[1] = m._42;
|
|
|
|
controllerState.pose.position[2] = m._43;
|
|
|
|
controllerState.pose.linearVelocity[0] = pose.vVelocity.v[0];
|
|
|
|
controllerState.pose.linearVelocity[1] = pose.vVelocity.v[1];
|
|
|
|
controllerState.pose.linearVelocity[2] = pose.vVelocity.v[2];
|
|
|
|
controllerState.pose.linearAcceleration[0] = 0.0f;
|
|
|
|
controllerState.pose.linearAcceleration[1] = 0.0f;
|
|
|
|
controllerState.pose.linearAcceleration[2] = 0.0f;
|
|
|
|
controllerState.isPositionValid = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-26 00:33:25 +03:00
|
|
|
void OpenVRSession::GetControllerDeviceId(
|
|
|
|
::vr::ETrackedDeviceClass aDeviceType,
|
|
|
|
::vr::TrackedDeviceIndex_t aDeviceIndex, nsCString& aId) {
|
|
|
|
switch (aDeviceType) {
|
|
|
|
case ::vr::TrackedDeviceClass_Controller: {
|
|
|
|
::vr::ETrackedPropertyError err;
|
|
|
|
uint32_t requiredBufferLen;
|
|
|
|
bool isFound = false;
|
|
|
|
char charBuf[128];
|
|
|
|
requiredBufferLen = mVRSystem->GetStringTrackedDeviceProperty(
|
2018-12-21 03:52:24 +03:00
|
|
|
aDeviceIndex, ::vr::Prop_RenderModelName_String, charBuf, 128, &err);
|
2018-10-26 00:33:25 +03:00
|
|
|
if (requiredBufferLen > 128) {
|
|
|
|
MOZ_CRASH("Larger than the buffer size.");
|
|
|
|
}
|
|
|
|
MOZ_ASSERT(requiredBufferLen && err == ::vr::TrackedProp_Success);
|
|
|
|
nsCString deviceId(charBuf);
|
|
|
|
if (deviceId.Find("knuckles") != kNotFound) {
|
|
|
|
aId.AssignLiteral("OpenVR Knuckles");
|
|
|
|
isFound = true;
|
2019-06-26 21:26:16 +03:00
|
|
|
} else if (deviceId.Find("vive_cosmos_controller") != kNotFound) {
|
|
|
|
aId.AssignLiteral("OpenVR Cosmos");
|
|
|
|
isFound = true;
|
2018-10-26 00:33:25 +03:00
|
|
|
}
|
|
|
|
requiredBufferLen = mVRSystem->GetStringTrackedDeviceProperty(
|
2018-12-21 03:52:24 +03:00
|
|
|
aDeviceIndex, ::vr::Prop_SerialNumber_String, charBuf, 128, &err);
|
2018-10-26 00:33:25 +03:00
|
|
|
if (requiredBufferLen > 128) {
|
|
|
|
MOZ_CRASH("Larger than the buffer size.");
|
|
|
|
}
|
|
|
|
MOZ_ASSERT(requiredBufferLen && err == ::vr::TrackedProp_Success);
|
|
|
|
deviceId.Assign(charBuf);
|
|
|
|
if (deviceId.Find("MRSOURCE") != kNotFound) {
|
|
|
|
aId.AssignLiteral("Spatial Controller (Spatial Interaction Source) ");
|
|
|
|
mIsWindowsMR = true;
|
|
|
|
isFound = true;
|
|
|
|
}
|
|
|
|
if (!isFound) {
|
|
|
|
aId.AssignLiteral("OpenVR Gamepad");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ::vr::TrackedDeviceClass_GenericTracker: {
|
|
|
|
aId.AssignLiteral("OpenVR Tracker");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
MOZ_ASSERT(false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OpenVRSession::StartFrame(mozilla::gfx::VRSystemState& aSystemState) {
|
|
|
|
UpdateHeadsetPose(aSystemState);
|
|
|
|
UpdateEyeParameters(aSystemState);
|
2020-02-28 03:40:54 +03:00
|
|
|
EnumerateControllers(aSystemState);
|
2018-12-17 23:46:40 +03:00
|
|
|
|
2020-02-28 03:40:54 +03:00
|
|
|
vr::VRActiveActionSet_t actionSet = {0};
|
|
|
|
actionSet.ulActionSet = mActionsetFirefox;
|
|
|
|
vr::VRInput()->UpdateActionState(&actionSet, sizeof(actionSet), 1);
|
|
|
|
UpdateControllerButtons(aSystemState);
|
|
|
|
UpdateControllerPoses(aSystemState);
|
2018-10-26 00:33:25 +03:00
|
|
|
UpdateTelemetry(aSystemState);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OpenVRSession::ProcessEvents(mozilla::gfx::VRSystemState& aSystemState) {
|
|
|
|
bool isHmdPresent = ::vr::VR_IsHmdPresent();
|
|
|
|
if (!isHmdPresent) {
|
|
|
|
mShouldQuit = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
::vr::VREvent_t event;
|
|
|
|
while (mVRSystem && mVRSystem->PollNextEvent(&event, sizeof(event))) {
|
|
|
|
switch (event.eventType) {
|
|
|
|
case ::vr::VREvent_TrackedDeviceUserInteractionStarted:
|
|
|
|
if (event.trackedDeviceIndex == ::vr::k_unTrackedDeviceIndex_Hmd) {
|
2019-01-10 00:57:36 +03:00
|
|
|
aSystemState.displayState.isMounted = true;
|
2018-10-26 00:33:25 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ::vr::VREvent_TrackedDeviceUserInteractionEnded:
|
|
|
|
if (event.trackedDeviceIndex == ::vr::k_unTrackedDeviceIndex_Hmd) {
|
2019-01-10 00:57:36 +03:00
|
|
|
aSystemState.displayState.isMounted = false;
|
2018-10-26 00:33:25 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ::vr::EVREventType::VREvent_TrackedDeviceActivated:
|
|
|
|
if (event.trackedDeviceIndex == ::vr::k_unTrackedDeviceIndex_Hmd) {
|
2019-01-10 00:57:36 +03:00
|
|
|
aSystemState.displayState.isConnected = true;
|
2018-10-26 00:33:25 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ::vr::EVREventType::VREvent_TrackedDeviceDeactivated:
|
|
|
|
if (event.trackedDeviceIndex == ::vr::k_unTrackedDeviceIndex_Hmd) {
|
2019-01-10 00:57:36 +03:00
|
|
|
aSystemState.displayState.isConnected = false;
|
2018-10-26 00:33:25 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ::vr::EVREventType::VREvent_DriverRequestedQuit:
|
|
|
|
case ::vr::EVREventType::VREvent_Quit:
|
2018-12-29 01:38:14 +03:00
|
|
|
// When SteamVR runtime haven't been launched before viewing VR,
|
|
|
|
// SteamVR will send a VREvent_ProcessQuit event. It will tell the parent
|
|
|
|
// process to shutdown the VR process, and we need to avoid it.
|
|
|
|
// case ::vr::EVREventType::VREvent_ProcessQuit:
|
2018-10-26 00:33:25 +03:00
|
|
|
case ::vr::EVREventType::VREvent_QuitAcknowledged:
|
|
|
|
case ::vr::EVREventType::VREvent_QuitAborted_UserPrompt:
|
|
|
|
mShouldQuit = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// ignore
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(XP_WIN)
|
2018-12-21 03:52:24 +03:00
|
|
|
bool OpenVRSession::SubmitFrame(
|
|
|
|
const mozilla::gfx::VRLayer_Stereo_Immersive& aLayer,
|
|
|
|
ID3D11Texture2D* aTexture) {
|
|
|
|
return SubmitFrame((void*)aTexture, ::vr::ETextureType::TextureType_DirectX,
|
2019-01-10 00:57:36 +03:00
|
|
|
aLayer.leftEyeRect, aLayer.rightEyeRect);
|
2018-10-26 00:33:25 +03:00
|
|
|
}
|
|
|
|
#elif defined(XP_MACOSX)
|
2018-12-21 03:52:24 +03:00
|
|
|
bool OpenVRSession::SubmitFrame(
|
|
|
|
const mozilla::gfx::VRLayer_Stereo_Immersive& aLayer,
|
|
|
|
const VRLayerTextureHandle& aTexture) {
|
|
|
|
return SubmitFrame(aTexture, ::vr::ETextureType::TextureType_IOSurface,
|
2019-01-10 00:57:36 +03:00
|
|
|
aLayer.leftEyeRect, aLayer.rightEyeRect);
|
2018-10-26 00:33:25 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
bool OpenVRSession::SubmitFrame(const VRLayerTextureHandle& aTextureHandle,
|
|
|
|
::vr::ETextureType aTextureType,
|
|
|
|
const VRLayerEyeRect& aLeftEyeRect,
|
|
|
|
const VRLayerEyeRect& aRightEyeRect) {
|
|
|
|
::vr::Texture_t tex;
|
|
|
|
#if defined(XP_MACOSX)
|
|
|
|
// We get aTextureHandle from get_SurfaceDescriptorMacIOSurface() at
|
|
|
|
// VRDisplayExternal. scaleFactor and opaque are skipped because they always
|
|
|
|
// are 1.0 and false.
|
|
|
|
RefPtr<MacIOSurface> surf = MacIOSurface::LookupSurface(aTextureHandle);
|
|
|
|
if (!surf) {
|
|
|
|
NS_WARNING("OpenVRSession::SubmitFrame failed to get a MacIOSurface");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-08-14 17:53:45 +03:00
|
|
|
CFTypeRefPtr<IOSurfaceRef> ioSurface = surf->GetIOSurfaceRef();
|
|
|
|
tex.handle = (void*)ioSurface.get();
|
2018-10-26 00:33:25 +03:00
|
|
|
#else
|
|
|
|
tex.handle = aTextureHandle;
|
|
|
|
#endif
|
|
|
|
tex.eType = aTextureType;
|
|
|
|
tex.eColorSpace = ::vr::EColorSpace::ColorSpace_Auto;
|
|
|
|
|
|
|
|
::vr::VRTextureBounds_t bounds;
|
|
|
|
bounds.uMin = aLeftEyeRect.x;
|
|
|
|
bounds.vMin = 1.0 - aLeftEyeRect.y;
|
|
|
|
bounds.uMax = aLeftEyeRect.x + aLeftEyeRect.width;
|
|
|
|
bounds.vMax = 1.0 - (aLeftEyeRect.y + aLeftEyeRect.height);
|
|
|
|
|
|
|
|
::vr::EVRCompositorError err;
|
|
|
|
err = mVRCompositor->Submit(::vr::EVREye::Eye_Left, &tex, &bounds);
|
|
|
|
if (err != ::vr::EVRCompositorError::VRCompositorError_None) {
|
|
|
|
printf_stderr("OpenVR Compositor Submit() failed.\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
bounds.uMin = aRightEyeRect.x;
|
|
|
|
bounds.vMin = 1.0 - aRightEyeRect.y;
|
|
|
|
bounds.uMax = aRightEyeRect.x + aRightEyeRect.width;
|
|
|
|
bounds.vMax = 1.0 - (aRightEyeRect.y + aRightEyeRect.height);
|
|
|
|
|
|
|
|
err = mVRCompositor->Submit(::vr::EVREye::Eye_Right, &tex, &bounds);
|
|
|
|
if (err != ::vr::EVRCompositorError::VRCompositorError_None) {
|
|
|
|
printf_stderr("OpenVR Compositor Submit() failed.\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
mVRCompositor->PostPresentHandoff();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OpenVRSession::StopPresentation() {
|
|
|
|
mVRCompositor->ClearLastSubmittedFrame();
|
|
|
|
|
|
|
|
::vr::Compositor_CumulativeStats stats;
|
|
|
|
mVRCompositor->GetCumulativeStats(&stats,
|
|
|
|
sizeof(::vr::Compositor_CumulativeStats));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OpenVRSession::StartPresentation() { return true; }
|
|
|
|
|
2018-12-21 03:52:24 +03:00
|
|
|
void OpenVRSession::VibrateHaptic(uint32_t aControllerIdx,
|
|
|
|
uint32_t aHapticIndex, float aIntensity,
|
|
|
|
float aDuration) {
|
2018-10-26 00:33:25 +03:00
|
|
|
MutexAutoLock lock(mControllerHapticStateMutex);
|
2019-09-18 03:13:12 +03:00
|
|
|
|
|
|
|
// Initilize the haptic thread when the first time to do vibration.
|
|
|
|
if (!mHapticThread) {
|
|
|
|
NS_DispatchToMainThread(NS_NewRunnableFunction(
|
|
|
|
"OpenVRSession::StartHapticThread", [this]() { StartHapticThread(); }));
|
|
|
|
}
|
2018-10-26 00:33:25 +03:00
|
|
|
if (aHapticIndex >= kNumOpenVRHaptics ||
|
|
|
|
aControllerIdx >= kVRControllerMaxCount) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-12-18 01:21:53 +03:00
|
|
|
const OpenVRHand role = mControllerDeviceIndex[aControllerIdx];
|
|
|
|
if (role == OpenVRHand::None) {
|
2018-10-26 00:33:25 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
mHapticPulseRemaining[aControllerIdx][aHapticIndex] = aDuration;
|
|
|
|
mHapticPulseIntensity[aControllerIdx][aHapticIndex] = aIntensity;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OpenVRSession::StartHapticThread() {
|
2018-11-03 00:54:12 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2018-10-26 00:33:25 +03:00
|
|
|
if (!mHapticThread) {
|
|
|
|
mHapticThread = new VRThread(NS_LITERAL_CSTRING("VR_OpenVR_Haptics"));
|
|
|
|
}
|
|
|
|
mHapticThread->Start();
|
2018-11-03 00:54:12 +03:00
|
|
|
StartHapticTimer();
|
2018-10-26 00:33:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void OpenVRSession::StopHapticThread() {
|
|
|
|
if (mHapticThread) {
|
2018-11-03 00:54:12 +03:00
|
|
|
NS_DispatchToMainThread(NS_NewRunnableFunction(
|
|
|
|
"mHapticThread::Shutdown",
|
|
|
|
[thread = mHapticThread]() { thread->Shutdown(); }));
|
2018-10-26 00:33:25 +03:00
|
|
|
mHapticThread = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OpenVRSession::StartHapticTimer() {
|
|
|
|
if (!mHapticTimer && mHapticThread) {
|
|
|
|
mLastHapticUpdate = TimeStamp();
|
|
|
|
mHapticTimer = NS_NewTimer();
|
|
|
|
mHapticTimer->SetTarget(mHapticThread->GetThread()->EventTarget());
|
|
|
|
mHapticTimer->InitWithNamedFuncCallback(
|
|
|
|
HapticTimerCallback, this, kVRHapticUpdateInterval,
|
|
|
|
nsITimer::TYPE_REPEATING_PRECISE_CAN_SKIP,
|
|
|
|
"OpenVRSession::HapticTimerCallback");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OpenVRSession::StopHapticTimer() {
|
|
|
|
if (mHapticTimer) {
|
|
|
|
mHapticTimer->Cancel();
|
|
|
|
mHapticTimer = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:07:19 +03:00
|
|
|
/*static*/
|
|
|
|
void OpenVRSession::HapticTimerCallback(nsITimer* aTimer, void* aClosure) {
|
2018-10-26 00:33:25 +03:00
|
|
|
/**
|
|
|
|
* It is safe to use the pointer passed in aClosure to reference the
|
|
|
|
* OpenVRSession object as the timer is canceled in OpenVRSession::Shutdown,
|
|
|
|
* which is called by the OpenVRSession destructor, guaranteeing
|
|
|
|
* that this function runs if and only if the VRManager object is valid.
|
|
|
|
*/
|
|
|
|
OpenVRSession* self = static_cast<OpenVRSession*>(aClosure);
|
2020-02-28 03:40:54 +03:00
|
|
|
MOZ_ASSERT(self);
|
|
|
|
self->UpdateHaptics();
|
2018-10-26 00:33:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void OpenVRSession::UpdateHaptics() {
|
|
|
|
MOZ_ASSERT(mHapticThread->GetThread() == NS_GetCurrentThread());
|
|
|
|
MOZ_ASSERT(mVRSystem);
|
|
|
|
|
|
|
|
MutexAutoLock lock(mControllerHapticStateMutex);
|
|
|
|
|
|
|
|
TimeStamp now = TimeStamp::Now();
|
|
|
|
if (mLastHapticUpdate.IsNull()) {
|
|
|
|
mLastHapticUpdate = now;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
float deltaTime = (float)(now - mLastHapticUpdate).ToSeconds();
|
|
|
|
mLastHapticUpdate = now;
|
|
|
|
|
2019-12-18 01:21:53 +03:00
|
|
|
for (uint32_t stateIndex = 0; stateIndex < kVRControllerMaxCount;
|
|
|
|
++stateIndex) {
|
|
|
|
const OpenVRHand role = mControllerDeviceIndex[stateIndex];
|
|
|
|
if (role == OpenVRHand::None) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
for (uint32_t hapticIdx = 0; hapticIdx < kNumOpenVRHaptics; hapticIdx++) {
|
|
|
|
float intensity = mHapticPulseIntensity[stateIndex][hapticIdx];
|
|
|
|
float duration = mHapticPulseRemaining[stateIndex][hapticIdx];
|
2018-12-17 23:46:40 +03:00
|
|
|
if (duration <= 0.0f || intensity <= 0.0f) {
|
|
|
|
continue;
|
|
|
|
}
|
2018-12-21 03:52:24 +03:00
|
|
|
vr::VRInput()->TriggerHapticVibrationAction(
|
2019-12-18 01:21:53 +03:00
|
|
|
mControllerHand[role].mActionHaptic.handle, 0.0f, deltaTime, 4.0f,
|
|
|
|
intensity > 1.0f ? 1.0f : intensity, vr::k_ulInvalidInputValueHandle);
|
2018-12-17 23:46:40 +03:00
|
|
|
|
|
|
|
duration -= deltaTime;
|
|
|
|
if (duration < 0.0f) {
|
|
|
|
duration = 0.0f;
|
|
|
|
}
|
2019-12-18 01:21:53 +03:00
|
|
|
mHapticPulseRemaining[stateIndex][hapticIdx] = duration;
|
2018-12-17 23:46:40 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-26 00:33:25 +03:00
|
|
|
void OpenVRSession::StopVibrateHaptic(uint32_t aControllerIdx) {
|
|
|
|
MutexAutoLock lock(mControllerHapticStateMutex);
|
|
|
|
if (aControllerIdx >= kVRControllerMaxCount) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (int iHaptic = 0; iHaptic < kNumOpenVRHaptics; iHaptic++) {
|
|
|
|
mHapticPulseRemaining[aControllerIdx][iHaptic] = 0.0f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OpenVRSession::StopAllHaptics() {
|
|
|
|
MutexAutoLock lock(mControllerHapticStateMutex);
|
|
|
|
for (auto& controller : mHapticPulseRemaining) {
|
|
|
|
for (auto& haptic : controller) {
|
|
|
|
haptic = 0.0f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OpenVRSession::UpdateTelemetry(VRSystemState& aSystemState) {
|
|
|
|
::vr::Compositor_CumulativeStats stats;
|
|
|
|
mVRCompositor->GetCumulativeStats(&stats,
|
|
|
|
sizeof(::vr::Compositor_CumulativeStats));
|
2019-01-10 00:57:36 +03:00
|
|
|
aSystemState.displayState.droppedFrameCount = stats.m_nNumReprojectedFrames;
|
2018-10-26 00:33:25 +03:00
|
|
|
}
|
|
|
|
|
2020-01-18 16:48:34 +03:00
|
|
|
} // namespace mozilla::gfx
|