mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-08 02:14:43 +00:00
Bug 1250244 - Part 4: Remove Cardboard VR Support,r=gw280
- The Cardboard VR support has hardcoded values and uses low-performance orientation APIs and rendering paths. - There is little benefit to this Cardboard VR implementation over using polyfills. - A future implementation would be based on Google VR support in Android N and/or Samsung Gear VR Oculus Mobile APIs. MozReview-Commit-ID: 7e9Th8ZTmj8
This commit is contained in:
parent
d7f19a6795
commit
20e3431c17
@ -1070,9 +1070,6 @@ pref("dom.webnotifications.serviceworker.enabled", true);
|
||||
// Retain at most 10 processes' layers buffers
|
||||
pref("layers.compositor-lru-size", 10);
|
||||
|
||||
// Enable Cardboard VR on mobile, assuming VR at all is enabled
|
||||
pref("dom.vr.cardboard.enabled", true);
|
||||
|
||||
// In B2G by deafult any AudioChannelAgent is muted when created.
|
||||
pref("dom.audiochannel.mutedByDefault", true);
|
||||
|
||||
|
@ -309,7 +309,6 @@ private:
|
||||
DECL_GFX_PREF(Live, "dom.meta-viewport.enabled", MetaViewportEnabled, bool, false);
|
||||
DECL_GFX_PREF(Once, "dom.vr.enabled", VREnabled, bool, false);
|
||||
DECL_GFX_PREF(Once, "dom.vr.oculus.enabled", VROculusEnabled, bool, true);
|
||||
DECL_GFX_PREF(Once, "dom.vr.cardboard.enabled", VRCardboardEnabled, bool, false);
|
||||
DECL_GFX_PREF(Once, "dom.vr.osvr.enabled", VROSVREnabled, bool, false);
|
||||
DECL_GFX_PREF(Live, "dom.vr.poseprediction.enabled", VRPosePredictionEnabled, bool, false);
|
||||
DECL_GFX_PREF(Live, "dom.w3c_pointer_events.enabled", PointerEventsEnabled, bool, false);
|
||||
|
@ -1,206 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include <math.h>
|
||||
#include "VRDeviceProxyOrientationFallBack.h"
|
||||
#include "mozilla/dom/ScreenOrientation.h" // for ScreenOrientationInternal
|
||||
#include "mozilla/Hal.h"
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::gfx;
|
||||
|
||||
// 1/sqrt(2) (aka sqrt(2)/2)
|
||||
#ifndef M_SQRT1_2
|
||||
# define M_SQRT1_2 0.70710678118654752440
|
||||
#endif
|
||||
|
||||
#ifdef ANDROID
|
||||
#include <android/log.h>
|
||||
#define LOG(args...) __android_log_print(ANDROID_LOG_INFO, "GeckoVR" , ## args)
|
||||
#else
|
||||
#define LOG(...) do { } while(0)
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
// some utility functions
|
||||
|
||||
// This remaps axes in the given matrix to a new configuration based on the
|
||||
// screen orientation. Similar to what Android SensorManager.remapCoordinateSystem
|
||||
// does, except only for a fixed number of transforms that we need.
|
||||
Matrix4x4
|
||||
RemapMatrixForOrientation(dom::ScreenOrientationInternal screenConfig, const Matrix4x4& aMatrix)
|
||||
{
|
||||
Matrix4x4 out;
|
||||
const float *in = &aMatrix._11;
|
||||
float *o = &out._11;
|
||||
|
||||
if (screenConfig == dom::eScreenOrientation_LandscapePrimary) {
|
||||
// remap X,Y -> Y,-X
|
||||
o[0] = -in[1]; o[1] = in[0]; o[2] = in[2];
|
||||
o[4] = -in[5]; o[5] = in[4]; o[6] = in[6];
|
||||
o[8] = -in[9]; o[9] = in[8]; o[10] = in[10];
|
||||
} else if (screenConfig == dom::eScreenOrientation_LandscapeSecondary) {
|
||||
// remap X,Y -> -Y,X
|
||||
o[0] = in[1]; o[1] = -in[0]; o[2] = in[2];
|
||||
o[4] = in[5]; o[5] = -in[4]; o[6] = in[6];
|
||||
o[8] = in[9]; o[9] = -in[8]; o[10] = in[10];
|
||||
} else if (screenConfig == dom::eScreenOrientation_PortraitPrimary) {
|
||||
out = aMatrix;
|
||||
} else if (screenConfig == dom::eScreenOrientation_PortraitSecondary) {
|
||||
// remap X,Y -> X,-Z
|
||||
o[0] = in[0]; o[1] = in[2]; o[2] = -in[1];
|
||||
o[4] = in[4]; o[5] = in[6]; o[6] = -in[5];
|
||||
o[8] = in[8]; o[9] = in[10]; o[10] = -in[9];
|
||||
} else {
|
||||
MOZ_ASSERT(0, "gfxVRCardboard::RemapMatrixForOrientation invalid screenConfig");
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace mozilla {
|
||||
namespace gfx {
|
||||
|
||||
VRDeviceProxyOrientationFallBack::VRDeviceProxyOrientationFallBack(const VRDeviceUpdate& aDeviceUpdate)
|
||||
: VRDeviceProxy(aDeviceUpdate)
|
||||
, mOrient(dom::eScreenOrientation_PortraitPrimary)
|
||||
, mTracking(false)
|
||||
{
|
||||
MOZ_COUNT_CTOR_INHERITED(VRDeviceProxyOrientationFallBack, VRDeviceProxy);
|
||||
}
|
||||
|
||||
VRDeviceProxyOrientationFallBack::~VRDeviceProxyOrientationFallBack()
|
||||
{
|
||||
StopSensorTracking();
|
||||
MOZ_COUNT_DTOR_INHERITED(VRDeviceProxyOrientationFallBack, VRDeviceProxy);
|
||||
}
|
||||
|
||||
void
|
||||
VRDeviceProxyOrientationFallBack::StartSensorTracking()
|
||||
{
|
||||
if (!mTracking) {
|
||||
// it's never been started before; initialize observers and
|
||||
// initial state.
|
||||
|
||||
hal::ScreenConfiguration sconfig;
|
||||
hal::GetCurrentScreenConfiguration(&sconfig);
|
||||
this->Notify(sconfig);
|
||||
|
||||
hal::RegisterSensorObserver(hal::SENSOR_GAME_ROTATION_VECTOR, this);
|
||||
hal::RegisterScreenConfigurationObserver(this);
|
||||
|
||||
mSensorState.Clear();
|
||||
|
||||
mTracking = true;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
VRDeviceProxyOrientationFallBack::StopSensorTracking()
|
||||
{
|
||||
if (mTracking) {
|
||||
hal::UnregisterScreenConfigurationObserver(this);
|
||||
hal::UnregisterSensorObserver(hal::SENSOR_GAME_ROTATION_VECTOR, this);
|
||||
mTracking = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Android sends us events that have a 90-degree rotation about
|
||||
// the x axis compared to what we want (phone flat vs. phone held in front of the eyes).
|
||||
// Correct for this by applying a transform to undo this rotation.
|
||||
void
|
||||
VRDeviceProxyOrientationFallBack::Notify(const hal::ScreenConfiguration& config)
|
||||
{
|
||||
mOrient = config.orientation();
|
||||
|
||||
if (mOrient == dom::eScreenOrientation_LandscapePrimary) {
|
||||
mScreenTransform = Quaternion(-0.5f, 0.5f, 0.5f, 0.5f);
|
||||
} else if (mOrient == dom::eScreenOrientation_LandscapeSecondary) {
|
||||
mScreenTransform = Quaternion(-0.5f, -0.5f, -0.5f, 0.5f);
|
||||
} else if (mOrient == dom::eScreenOrientation_PortraitPrimary) {
|
||||
mScreenTransform = Quaternion((float) -M_SQRT1_2, 0.f, 0.f, (float) M_SQRT1_2);
|
||||
} else if (mOrient == dom::eScreenOrientation_PortraitSecondary) {
|
||||
// Currently, PortraitSecondary event doesn't be triggered.
|
||||
mScreenTransform = Quaternion((float) M_SQRT1_2, 0.f, 0.f, (float) M_SQRT1_2);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
VRDeviceProxyOrientationFallBack::Notify(const hal::SensorData& data)
|
||||
{
|
||||
if (data.sensor() != hal::SENSOR_GAME_ROTATION_VECTOR)
|
||||
return;
|
||||
|
||||
const nsTArray<float>& sensorValues = data.values();
|
||||
|
||||
// This is super chatty
|
||||
//LOG("HMDInfoCardboard::Notify %f %f %f %f\n", sensorValues[0], sensorValues[1], sensorValues[2], sensorValues[3]);
|
||||
|
||||
mSavedLastSensor.Set(sensorValues[0], sensorValues[1], sensorValues[2], sensorValues[3]);
|
||||
mSavedLastSensorTime = data.timestamp();
|
||||
mNeedsSensorCompute = true;
|
||||
}
|
||||
|
||||
void
|
||||
VRDeviceProxyOrientationFallBack::ZeroSensor()
|
||||
{
|
||||
mSensorZeroInverse = mSavedLastSensor;
|
||||
mSensorZeroInverse.Invert();
|
||||
}
|
||||
|
||||
void
|
||||
VRDeviceProxyOrientationFallBack::ComputeStateFromLastSensor()
|
||||
{
|
||||
if (!mNeedsSensorCompute)
|
||||
return;
|
||||
|
||||
// apply the zero orientation
|
||||
Quaternion q = mSensorZeroInverse * mSavedLastSensor;
|
||||
|
||||
// make a matrix from the quat
|
||||
Matrix4x4 qm;
|
||||
qm.SetRotationFromQuaternion(q);
|
||||
|
||||
// remap the coordinate space, based on the orientation
|
||||
Matrix4x4 qmRemapped = RemapMatrixForOrientation(mOrient, qm);
|
||||
|
||||
// turn it back into a quat
|
||||
q.SetFromRotationMatrix(qmRemapped);
|
||||
|
||||
// apply adjustment based on what's been done to the screen and the original zero
|
||||
// position of the base coordinate space
|
||||
q = mScreenTransform * q;
|
||||
|
||||
mSensorState.flags |= VRStateValidFlags::State_Orientation;
|
||||
mSensorState.orientation[0] = q.x;
|
||||
mSensorState.orientation[1] = q.y;
|
||||
mSensorState.orientation[2] = q.z;
|
||||
mSensorState.orientation[3] = q.w;
|
||||
|
||||
mSensorState.timestamp = mSavedLastSensorTime / 1000000.0;
|
||||
|
||||
mNeedsSensorCompute = false;
|
||||
}
|
||||
|
||||
VRHMDSensorState
|
||||
VRDeviceProxyOrientationFallBack::GetSensorState()
|
||||
{
|
||||
StartSensorTracking();
|
||||
ComputeStateFromLastSensor();
|
||||
return mSensorState;
|
||||
}
|
||||
|
||||
VRHMDSensorState
|
||||
VRDeviceProxyOrientationFallBack::GetImmediateSensorState()
|
||||
{
|
||||
// XXX TODO - Should return actual immediate sensor state
|
||||
return GetSensorState();
|
||||
}
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace mozilla
|
||||
|
@ -1,55 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef GFX_VR_PROXY_ORIENTATION_FALLBACK_H
|
||||
#define GFX_VR_PROXY_ORIENTATION_FALLBACK_H
|
||||
|
||||
#include "VRDeviceProxy.h"
|
||||
|
||||
#include "mozilla/HalSensor.h"
|
||||
#include "mozilla/HalScreenConfiguration.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace gfx {
|
||||
|
||||
class VRDeviceProxyOrientationFallBack : public VRDeviceProxy
|
||||
, public hal::ISensorObserver
|
||||
, public hal::ScreenConfigurationObserver
|
||||
{
|
||||
public:
|
||||
|
||||
explicit VRDeviceProxyOrientationFallBack(const VRDeviceUpdate& aDeviceUpdate);
|
||||
|
||||
virtual void ZeroSensor() override;
|
||||
virtual VRHMDSensorState GetSensorState() override;
|
||||
virtual VRHMDSensorState GetImmediateSensorState() override;
|
||||
|
||||
// ISensorObserver interface
|
||||
void Notify(const hal::SensorData& SensorData) override;
|
||||
// ScreenConfigurationObserver interface
|
||||
void Notify(const hal::ScreenConfiguration& ScreenConfiguration) override;
|
||||
|
||||
|
||||
protected:
|
||||
virtual ~VRDeviceProxyOrientationFallBack();
|
||||
|
||||
void StartSensorTracking();
|
||||
void StopSensorTracking();
|
||||
void ComputeStateFromLastSensor();
|
||||
|
||||
uint32_t mOrient;
|
||||
Quaternion mScreenTransform;
|
||||
Quaternion mSensorZeroInverse;
|
||||
Quaternion mSavedLastSensor;
|
||||
double mSavedLastSensorTime;
|
||||
bool mNeedsSensorCompute; // if we need to compute the state from mSavedLastSensor
|
||||
|
||||
bool mTracking;
|
||||
};
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace mozilla
|
||||
|
||||
#endif /* GFX_VR_PROXY_ORIENTATION_FALLBACK_H */
|
@ -19,8 +19,6 @@
|
||||
#if defined(XP_WIN) || defined(XP_MACOSX) || defined(XP_LINUX)
|
||||
#include "gfxVROSVR.h"
|
||||
#endif
|
||||
#include "gfxVRCardboard.h"
|
||||
|
||||
|
||||
namespace mozilla {
|
||||
namespace gfx {
|
||||
@ -61,11 +59,6 @@ VRManager::VRManager()
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
mgr = VRHMDManagerCardboard::Create();
|
||||
if (mgr) {
|
||||
mManagers.AppendElement(mgr);
|
||||
}
|
||||
}
|
||||
|
||||
VRManager::~VRManager()
|
||||
@ -189,10 +182,8 @@ VRManager::DispatchVRDeviceSensorUpdate()
|
||||
|
||||
for (auto iter = mVRDevices.Iter(); !iter.Done(); iter.Next()) {
|
||||
gfx::VRHMDInfo* device = iter.UserData();
|
||||
if (!device->GetDeviceInfo().GetUseMainThreadOrientation()) {
|
||||
update.AppendElement(VRSensorUpdate(device->GetDeviceInfo().GetDeviceID(),
|
||||
device->GetSensorState()));
|
||||
}
|
||||
update.AppendElement(VRSensorUpdate(device->GetDeviceInfo().GetDeviceID(),
|
||||
device->GetSensorState()));
|
||||
}
|
||||
if (update.Length() > 0) {
|
||||
for (auto iter = mVRManagerParents.Iter(); !iter.Done(); iter.Next()) {
|
||||
|
@ -18,7 +18,6 @@
|
||||
#if defined(XP_WIN) || defined(XP_MACOSX) || defined(XP_LINUX)
|
||||
#include "gfxVROSVR.h"
|
||||
#endif
|
||||
#include "gfxVRCardboard.h"
|
||||
|
||||
#include "mozilla/unused.h"
|
||||
#include "mozilla/layers/Compositor.h"
|
||||
@ -33,12 +32,11 @@ using namespace mozilla::gfx;
|
||||
|
||||
Atomic<uint32_t> VRHMDManager::sDeviceBase(0);
|
||||
|
||||
VRHMDInfo::VRHMDInfo(VRHMDType aType, bool aUseMainThreadOrientation)
|
||||
VRHMDInfo::VRHMDInfo(VRHMDType aType)
|
||||
{
|
||||
MOZ_COUNT_CTOR(VRHMDInfo);
|
||||
mDeviceInfo.mType = aType;
|
||||
mDeviceInfo.mDeviceID = VRHMDManager::AllocateDeviceID();
|
||||
mDeviceInfo.mUseMainThreadOrientation = aUseMainThreadOrientation;
|
||||
}
|
||||
|
||||
VRHMDInfo::~VRHMDInfo()
|
||||
|
@ -27,7 +27,6 @@ namespace gfx {
|
||||
|
||||
enum class VRHMDType : uint16_t {
|
||||
Oculus,
|
||||
Cardboard,
|
||||
OSVR,
|
||||
NumHMDTypes
|
||||
};
|
||||
@ -102,7 +101,6 @@ struct VRDeviceInfo
|
||||
const Point3D& GetEyeTranslation(uint32_t whichEye) const { return mEyeTranslation[whichEye]; }
|
||||
const Matrix4x4& GetEyeProjectionMatrix(uint32_t whichEye) const { return mEyeProjectionMatrix[whichEye]; }
|
||||
const VRFieldOfView& GetEyeFOV(uint32_t whichEye) const { return mEyeFOV[whichEye]; }
|
||||
bool GetUseMainThreadOrientation() const { return mUseMainThreadOrientation; }
|
||||
|
||||
enum Eye {
|
||||
Eye_Left,
|
||||
@ -127,7 +125,6 @@ struct VRDeviceInfo
|
||||
IntRect mScreenRect;
|
||||
|
||||
bool mIsFakeScreen;
|
||||
bool mUseMainThreadOrientation;
|
||||
|
||||
|
||||
|
||||
@ -139,7 +136,6 @@ struct VRDeviceInfo
|
||||
mEyeResolution == other.mEyeResolution &&
|
||||
mScreenRect == other.mScreenRect &&
|
||||
mIsFakeScreen == other.mIsFakeScreen &&
|
||||
mUseMainThreadOrientation == other.mUseMainThreadOrientation &&
|
||||
mMaximumEyeFOV[0] == other.mMaximumEyeFOV[0] &&
|
||||
mMaximumEyeFOV[1] == other.mMaximumEyeFOV[1] &&
|
||||
mRecommendedEyeFOV[0] == other.mRecommendedEyeFOV[0] &&
|
||||
@ -281,7 +277,7 @@ public:
|
||||
|
||||
const VRDistortionMesh& GetDistortionMesh(uint32_t whichEye) const { return mDistortionMesh[whichEye]; }
|
||||
protected:
|
||||
explicit VRHMDInfo(VRHMDType aType, bool aUseMainThreadOrientation);
|
||||
explicit VRHMDInfo(VRHMDType aType);
|
||||
virtual ~VRHMDInfo();
|
||||
|
||||
VRHMDConfiguration mConfiguration;
|
||||
|
@ -1,248 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "prlink.h"
|
||||
#include "prmem.h"
|
||||
#include "prenv.h"
|
||||
#include "gfxPrefs.h"
|
||||
#include "nsString.h"
|
||||
#include "mozilla/Preferences.h"
|
||||
#include "mozilla/Hal.h"
|
||||
|
||||
#include "gfxVRCardboard.h"
|
||||
|
||||
#include "nsServiceManagerUtils.h"
|
||||
#include "nsIScreenManager.h"
|
||||
|
||||
using namespace mozilla::dom;
|
||||
using namespace mozilla::gfx;
|
||||
using namespace mozilla::gfx::impl;
|
||||
|
||||
HMDInfoCardboard::HMDInfoCardboard()
|
||||
: VRHMDInfo(VRHMDType::Cardboard, true)
|
||||
{
|
||||
MOZ_ASSERT(sizeof(HMDInfoCardboard::DistortionVertex) == sizeof(VRDistortionVertex),
|
||||
"HMDInfoCardboard::DistortionVertex must match the size of VRDistortionVertex");
|
||||
|
||||
MOZ_COUNT_CTOR_INHERITED(HMDInfoCardboard, VRHMDInfo);
|
||||
|
||||
mDeviceInfo.mDeviceName.AssignLiteral("Phone Sensor (Cardboard) HMD");
|
||||
|
||||
mDeviceInfo.mSupportedSensorBits = VRStateValidFlags::State_Orientation;
|
||||
|
||||
mDeviceInfo.mRecommendedEyeFOV[VRDeviceInfo::Eye_Left] = gfx::VRFieldOfView(45.0, 45.0, 45.0, 45.0);
|
||||
mDeviceInfo.mRecommendedEyeFOV[VRDeviceInfo::Eye_Right] = gfx::VRFieldOfView(45.0, 45.0, 45.0, 45.0);
|
||||
|
||||
mDeviceInfo.mMaximumEyeFOV[VRDeviceInfo::Eye_Left] = gfx::VRFieldOfView(45.0, 45.0, 45.0, 45.0);
|
||||
mDeviceInfo.mMaximumEyeFOV[VRDeviceInfo::Eye_Right] = gfx::VRFieldOfView(45.0, 45.0, 45.0, 45.0);
|
||||
|
||||
SetFOV(mDeviceInfo.mRecommendedEyeFOV[VRDeviceInfo::Eye_Left], mDeviceInfo.mRecommendedEyeFOV[VRDeviceInfo::Eye_Right], 0.01, 10000.0);
|
||||
|
||||
mDeviceInfo.mScreenRect.x = 0;
|
||||
mDeviceInfo.mScreenRect.y = 0;
|
||||
mDeviceInfo.mScreenRect.width = 1920;
|
||||
mDeviceInfo.mScreenRect.height = 1080;
|
||||
mDeviceInfo.mIsFakeScreen = true;
|
||||
}
|
||||
|
||||
|
||||
VRHMDSensorState
|
||||
HMDInfoCardboard::GetSensorState()
|
||||
{
|
||||
// Actual sensor state is calculated on the main thread,
|
||||
// within VRDeviceProxyOrientationFallBack
|
||||
VRHMDSensorState result;
|
||||
result.Clear();
|
||||
return result;
|
||||
}
|
||||
|
||||
VRHMDSensorState
|
||||
HMDInfoCardboard::GetImmediateSensorState()
|
||||
{
|
||||
return GetSensorState();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
HMDInfoCardboard::ZeroSensor()
|
||||
{
|
||||
MOZ_ASSERT(0, "HMDInfoCardboard::ZeroSensor not implemented. "
|
||||
"Should use VRDeviceProxyOrientationFallBack on main thread");
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
HMDInfoCardboard::NotifyVsync(const TimeStamp& aVsyncTimestamp)
|
||||
{
|
||||
// Nothing to do here for Cardboard VR
|
||||
}
|
||||
|
||||
bool
|
||||
HMDInfoCardboard::KeepSensorTracking()
|
||||
{
|
||||
// Nothing to do here for Cardboard VR
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
HMDInfoCardboard::SetFOV(const gfx::VRFieldOfView& aFOVLeft,
|
||||
const gfx::VRFieldOfView& aFOVRight,
|
||||
double zNear, double zFar)
|
||||
{
|
||||
const float standardIPD = 0.064f;
|
||||
|
||||
for (uint32_t eye = 0; eye < VRDeviceInfo::NumEyes; eye++) {
|
||||
mDeviceInfo.mEyeFOV[eye] = eye == VRDeviceInfo::Eye_Left ? aFOVLeft : aFOVRight;
|
||||
mDeviceInfo.mEyeTranslation[eye] = Point3D(standardIPD * (eye == VRDeviceInfo::Eye_Left ? -1.0 : 1.0), 0.0, 0.0);
|
||||
mDeviceInfo.mEyeProjectionMatrix[eye] = mDeviceInfo.mEyeFOV[eye].ConstructProjectionMatrix(zNear, zFar, true);
|
||||
|
||||
mDistortionMesh[eye].mVertices.SetLength(4);
|
||||
mDistortionMesh[eye].mIndices.SetLength(6);
|
||||
|
||||
HMDInfoCardboard::DistortionVertex *destv = reinterpret_cast<HMDInfoCardboard::DistortionVertex*>(mDistortionMesh[eye].mVertices.Elements());
|
||||
float xoffs = eye == VRDeviceInfo::Eye_Left ? 0.0f : 1.0f;
|
||||
float txoffs = eye == VRDeviceInfo::Eye_Left ? 0.0f : 0.5f;
|
||||
destv[0].pos[0] = -1.0 + xoffs;
|
||||
destv[0].pos[1] = -1.0;
|
||||
destv[0].texR[0] = destv[0].texG[0] = destv[0].texB[0] = 0.0 + txoffs;
|
||||
destv[0].texR[1] = destv[0].texG[1] = destv[0].texB[1] = 1.0;
|
||||
destv[0].padding[0] = 1.0; // vignette factor
|
||||
|
||||
destv[1].pos[0] = 0.0 + xoffs;
|
||||
destv[1].pos[1] = -1.0;
|
||||
destv[1].texR[0] = destv[1].texG[0] = destv[1].texB[0] = 0.5 + txoffs;
|
||||
destv[1].texR[1] = destv[1].texG[1] = destv[1].texB[1] = 1.0;
|
||||
destv[1].padding[0] = 1.0; // vignette factor
|
||||
|
||||
destv[2].pos[0] = 0.0 + xoffs;
|
||||
destv[2].pos[1] = 1.0;
|
||||
destv[2].texR[0] = destv[2].texG[0] = destv[2].texB[0] = 0.5 + txoffs;
|
||||
destv[2].texR[1] = destv[2].texG[1] = destv[2].texB[1] = 0.0;
|
||||
destv[2].padding[0] = 1.0; // vignette factor
|
||||
|
||||
destv[3].pos[0] = -1.0 + xoffs;
|
||||
destv[3].pos[1] = 1.0;
|
||||
destv[3].texR[0] = destv[3].texG[0] = destv[3].texB[0] = 0.0 + txoffs;
|
||||
destv[3].texR[1] = destv[3].texG[1] = destv[3].texB[1] = 0.0;
|
||||
destv[3].padding[0] = 1.0; // vignette factor
|
||||
|
||||
uint16_t *iv = mDistortionMesh[eye].mIndices.Elements();
|
||||
iv[0] = 0; iv[1] = 1; iv[2] = 2;
|
||||
iv[3] = 2; iv[4] = 3; iv[5] = 0;
|
||||
}
|
||||
|
||||
// XXX find out the default screen size and use that
|
||||
mDeviceInfo.mEyeResolution.width = 1920 / 2;
|
||||
mDeviceInfo.mEyeResolution.height = 1080;
|
||||
|
||||
if (PR_GetEnv("FAKE_CARDBOARD_SCREEN")) {
|
||||
// for testing, make the eye resolution 2x of the screen
|
||||
mDeviceInfo.mEyeResolution.width *= 2;
|
||||
mDeviceInfo.mEyeResolution.height *= 2;
|
||||
}
|
||||
|
||||
mConfiguration.hmdType = mDeviceInfo.mType;
|
||||
mConfiguration.value = 0;
|
||||
mConfiguration.fov[0] = aFOVLeft;
|
||||
mConfiguration.fov[1] = aFOVRight;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
HMDInfoCardboard::FillDistortionConstants(uint32_t whichEye,
|
||||
const IntSize& textureSize, const IntRect& eyeViewport,
|
||||
const Size& destViewport, const Rect& destRect,
|
||||
VRDistortionConstants& values)
|
||||
{
|
||||
// these modify the texture coordinates; texcoord * zw + xy
|
||||
values.eyeToSourceScaleAndOffset[0] = 0.0;
|
||||
values.eyeToSourceScaleAndOffset[1] = 0.0;
|
||||
if (PR_GetEnv("FAKE_CARDBOARD_SCREEN")) {
|
||||
values.eyeToSourceScaleAndOffset[2] = 2.0;
|
||||
values.eyeToSourceScaleAndOffset[3] = 2.0;
|
||||
} else {
|
||||
values.eyeToSourceScaleAndOffset[2] = 1.0;
|
||||
values.eyeToSourceScaleAndOffset[3] = 1.0;
|
||||
}
|
||||
|
||||
// Our mesh positions are in the [-1..1] clip space; we give appropriate offset
|
||||
// and scaling for the right viewport. (In the 0..2 space for sanity)
|
||||
|
||||
// this is the destRect in clip space
|
||||
float x0 = destRect.x / destViewport.width * 2.0 - 1.0;
|
||||
float x1 = (destRect.x + destRect.width) / destViewport.width * 2.0 - 1.0;
|
||||
|
||||
float y0 = destRect.y / destViewport.height * 2.0 - 1.0;
|
||||
float y1 = (destRect.y + destRect.height) / destViewport.height * 2.0 - 1.0;
|
||||
|
||||
// offset
|
||||
values.destinationScaleAndOffset[0] = (x0+x1) / 2.0;
|
||||
values.destinationScaleAndOffset[1] = (y0+y1) / 2.0;
|
||||
// scale
|
||||
values.destinationScaleAndOffset[2] = destRect.width / destViewport.width;
|
||||
values.destinationScaleAndOffset[3] = destRect.height / destViewport.height;
|
||||
}
|
||||
|
||||
void
|
||||
HMDInfoCardboard::Destroy()
|
||||
{
|
||||
}
|
||||
|
||||
/*static*/ already_AddRefed<VRHMDManagerCardboard>
|
||||
VRHMDManagerCardboard::Create()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
if (!gfxPrefs::VREnabled() || !gfxPrefs::VRCardboardEnabled())
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
RefPtr<VRHMDManagerCardboard> manager = new VRHMDManagerCardboard();
|
||||
return manager.forget();
|
||||
}
|
||||
|
||||
bool
|
||||
VRHMDManagerCardboard::Init()
|
||||
{
|
||||
if (mCardboardInitialized) {
|
||||
return true;
|
||||
}
|
||||
|
||||
RefPtr<HMDInfoCardboard> hmd = new HMDInfoCardboard();
|
||||
mCardboardHMDs.AppendElement(hmd);
|
||||
|
||||
mCardboardInitialized = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
VRHMDManagerCardboard::Destroy()
|
||||
{
|
||||
if (!mCardboardInitialized)
|
||||
return;
|
||||
|
||||
for (size_t i = 0; i < mCardboardHMDs.Length(); ++i) {
|
||||
mCardboardHMDs[i]->Destroy();
|
||||
}
|
||||
|
||||
mCardboardHMDs.Clear();
|
||||
mCardboardInitialized = false;
|
||||
}
|
||||
|
||||
void
|
||||
VRHMDManagerCardboard::GetHMDs(nsTArray<RefPtr<VRHMDInfo>>& aHMDResult)
|
||||
{
|
||||
if (!mCardboardInitialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < mCardboardHMDs.Length(); ++i) {
|
||||
aHMDResult.AppendElement(mCardboardHMDs[i]);
|
||||
}
|
||||
}
|
@ -1,78 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef GFX_VR_CARDBOARD_H
|
||||
#define GFX_VR_CARDBOARD_H
|
||||
|
||||
#include "mozilla/gfx/2D.h"
|
||||
#include "mozilla/gfx/Quaternion.h"
|
||||
#include "mozilla/EnumeratedArray.h"
|
||||
|
||||
#include "gfxVR.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace gfx {
|
||||
namespace impl {
|
||||
|
||||
class HMDInfoCardboard :
|
||||
public VRHMDInfo
|
||||
{
|
||||
public:
|
||||
explicit HMDInfoCardboard();
|
||||
|
||||
bool SetFOV(const VRFieldOfView& aFOVLeft, const VRFieldOfView& aFOVRight,
|
||||
double zNear, double zFar) override;
|
||||
|
||||
virtual VRHMDSensorState GetSensorState() override;
|
||||
virtual VRHMDSensorState GetImmediateSensorState() override;
|
||||
void ZeroSensor() override;
|
||||
bool KeepSensorTracking() override;
|
||||
void NotifyVsync(const TimeStamp& aVsyncTimestamp) override;
|
||||
|
||||
void FillDistortionConstants(uint32_t whichEye,
|
||||
const IntSize& textureSize, const IntRect& eyeViewport,
|
||||
const Size& destViewport, const Rect& destRect,
|
||||
VRDistortionConstants& values) override;
|
||||
|
||||
void Destroy();
|
||||
|
||||
protected:
|
||||
virtual ~HMDInfoCardboard() {
|
||||
MOZ_COUNT_DTOR_INHERITED(HMDInfoCardboard, VRHMDInfo);
|
||||
Destroy();
|
||||
}
|
||||
|
||||
// must match the size of VRDistortionVertex
|
||||
struct DistortionVertex {
|
||||
float pos[2];
|
||||
float texR[2];
|
||||
float texG[2];
|
||||
float texB[2];
|
||||
float padding[4];
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
} // namespace impl
|
||||
|
||||
class VRHMDManagerCardboard : public VRHMDManager
|
||||
{
|
||||
public:
|
||||
static already_AddRefed<VRHMDManagerCardboard> Create();
|
||||
virtual bool Init() override;
|
||||
virtual void Destroy() override;
|
||||
virtual void GetHMDs(nsTArray<RefPtr<VRHMDInfo> >& aHMDResult) override;
|
||||
protected:
|
||||
VRHMDManagerCardboard()
|
||||
: mCardboardInitialized(false)
|
||||
{ }
|
||||
nsTArray<RefPtr<impl::HMDInfoCardboard>> mCardboardHMDs;
|
||||
bool mCardboardInitialized;
|
||||
};
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace mozilla
|
||||
|
||||
#endif /* GFX_VR_CARDBOARD_H */
|
@ -203,7 +203,7 @@ SetFromTanRadians(double left, double right, double bottom, double top)
|
||||
HMDInfoOSVR::HMDInfoOSVR(OSVR_ClientContext* context,
|
||||
OSVR_ClientInterface* iface,
|
||||
OSVR_DisplayConfig* display)
|
||||
: VRHMDInfo(VRHMDType::OSVR, false)
|
||||
: VRHMDInfo(VRHMDType::OSVR)
|
||||
, m_ctx(context)
|
||||
, m_iface(iface)
|
||||
, m_display(display)
|
||||
@ -619,4 +619,4 @@ VRHMDManagerOSVR::GetHMDs(nsTArray<RefPtr<VRHMDInfo>>& aHMDResult)
|
||||
if (mHMDInfo) {
|
||||
aHMDResult.AppendElement(mHMDInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -293,7 +293,7 @@ FromFovPort(const ovrFovPort& aFOV)
|
||||
} // namespace
|
||||
|
||||
HMDInfoOculus::HMDInfoOculus(ovrSession aSession)
|
||||
: VRHMDInfo(VRHMDType::Oculus, false)
|
||||
: VRHMDInfo(VRHMDType::Oculus)
|
||||
, mSession(aSession)
|
||||
, mInputFrameID(0)
|
||||
{
|
||||
|
@ -8,7 +8,6 @@
|
||||
#include "VRManagerChild.h"
|
||||
#include "VRManagerParent.h"
|
||||
#include "VRDeviceProxy.h"
|
||||
#include "VRDeviceProxyOrientationFallBack.h"
|
||||
#include "mozilla/StaticPtr.h"
|
||||
#include "mozilla/layers/CompositorThread.h" // for CompositorThread
|
||||
#include "mozilla/dom/Navigator.h"
|
||||
@ -138,11 +137,7 @@ VRManagerChild::RecvUpdateDeviceInfo(nsTArray<VRDeviceUpdate>&& aDeviceUpdates)
|
||||
}
|
||||
}
|
||||
if (isNewDevice) {
|
||||
if (deviceUpdate.mDeviceInfo.GetUseMainThreadOrientation()) {
|
||||
devices.AppendElement(new VRDeviceProxyOrientationFallBack(deviceUpdate));
|
||||
} else {
|
||||
devices.AppendElement(new VRDeviceProxy(deviceUpdate));
|
||||
}
|
||||
devices.AppendElement(new VRDeviceProxy(deviceUpdate));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -82,7 +82,6 @@ struct ParamTraits<mozilla::gfx::VRDeviceInfo>
|
||||
WriteParam(aMsg, aParam.mEyeResolution);
|
||||
WriteParam(aMsg, aParam.mScreenRect);
|
||||
WriteParam(aMsg, aParam.mIsFakeScreen);
|
||||
WriteParam(aMsg, aParam.mUseMainThreadOrientation);
|
||||
for (int i = 0; i < mozilla::gfx::VRDeviceInfo::NumEyes; i++) {
|
||||
WriteParam(aMsg, aParam.mMaximumEyeFOV[i]);
|
||||
WriteParam(aMsg, aParam.mRecommendedEyeFOV[i]);
|
||||
@ -100,9 +99,7 @@ struct ParamTraits<mozilla::gfx::VRDeviceInfo>
|
||||
!ReadParam(aMsg, aIter, &(aResult->mSupportedSensorBits)) ||
|
||||
!ReadParam(aMsg, aIter, &(aResult->mEyeResolution)) ||
|
||||
!ReadParam(aMsg, aIter, &(aResult->mScreenRect)) ||
|
||||
!ReadParam(aMsg, aIter, &(aResult->mIsFakeScreen)) ||
|
||||
!ReadParam(aMsg, aIter, &(aResult->mUseMainThreadOrientation))
|
||||
) {
|
||||
!ReadParam(aMsg, aIter, &(aResult->mIsFakeScreen))) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < mozilla::gfx::VRDeviceInfo::NumEyes; i++) {
|
||||
|
@ -19,13 +19,11 @@ LOCAL_INCLUDES += [
|
||||
|
||||
UNIFIED_SOURCES += [
|
||||
'gfxVR.cpp',
|
||||
'gfxVRCardboard.cpp',
|
||||
'gfxVROculus.cpp',
|
||||
'gfxVROSVR.cpp',
|
||||
'ipc/VRManagerChild.cpp',
|
||||
'ipc/VRManagerParent.cpp',
|
||||
'VRDeviceProxy.cpp',
|
||||
'VRDeviceProxyOrientationFallBack.cpp',
|
||||
'VRManager.cpp',
|
||||
]
|
||||
|
||||
|
@ -878,9 +878,6 @@ pref("consoleservice.logcat", false);
|
||||
pref("consoleservice.logcat", true);
|
||||
#endif
|
||||
|
||||
// Enable Cardboard VR on mobile, assuming VR at all is enabled
|
||||
pref("dom.vr.cardboard.enabled", true);
|
||||
|
||||
#ifndef RELEASE_BUILD
|
||||
// Enable VR on mobile, making it enable by default.
|
||||
pref("dom.vr.enabled", true);
|
||||
|
@ -4923,8 +4923,6 @@ pref("dom.vr.enabled", false);
|
||||
pref("dom.vr.enabled", true);
|
||||
#endif
|
||||
pref("dom.vr.oculus.enabled", true);
|
||||
// Cardboard VR device is disabled by default
|
||||
pref("dom.vr.cardboard.enabled", false);
|
||||
// OSVR device
|
||||
pref("dom.vr.osvr.enabled", false);
|
||||
// Pose prediction reduces latency effects by returning future predicted HMD
|
||||
|
Loading…
Reference in New Issue
Block a user