Skip to content
Permalink
Browse files
[WebVR][OpenVR] Retrieve stage parameters
https://bugs.webkit.org/show_bug.cgi?id=182976

Reviewed by Žan Doberšek.

Use OpenVR to retrieve stage parameters, i.e., play area size and
the transformation from sitting to standing position. It includes
the same fallback used by Firefox to provide sensible values in case
we cannot get the required information from the VR SDK (it's quite
common not to have defined a play area).

* Modules/webvr/VRDisplay.cpp:
(WebCore::VRDisplay::stageParameters const):
* Modules/webvr/VRDisplay.h:
* Modules/webvr/VRStageParameters.cpp:
(WebCore::VRStageParameters::VRStageParameters):
(WebCore::VRStageParameters::sittingToStandingTransform const):
(WebCore::VRStageParameters::sizeX const):
(WebCore::VRStageParameters::sizeZ const):
* Modules/webvr/VRStageParameters.h:
(WebCore::VRStageParameters::create):
* platform/vr/VRPlatformDisplay.h:
* platform/vr/openvr/VRPlatformDisplayOpenVR.cpp:
(WebCore::VRPlatformDisplayOpenVR::VRPlatformDisplayOpenVR):
(WebCore::VRPlatformDisplayOpenVR::updateStageParameters):
* platform/vr/openvr/VRPlatformDisplayOpenVR.h:

Canonical link: https://commits.webkit.org/198745@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@228867 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
svillar committed Feb 21, 2018
1 parent 3c8c8ee commit 54e0ff3485c5eab9233d2bfc54a63b7bffcdd83a
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 13 deletions.
@@ -1,3 +1,32 @@
2018-02-20 Sergio Villar Senin <svillar@igalia.com>

[WebVR][OpenVR] Retrieve stage parameters
https://bugs.webkit.org/show_bug.cgi?id=182976

Reviewed by Žan Doberšek.

Use OpenVR to retrieve stage parameters, i.e., play area size and
the transformation from sitting to standing position. It includes
the same fallback used by Firefox to provide sensible values in case
we cannot get the required information from the VR SDK (it's quite
common not to have defined a play area).

* Modules/webvr/VRDisplay.cpp:
(WebCore::VRDisplay::stageParameters const):
* Modules/webvr/VRDisplay.h:
* Modules/webvr/VRStageParameters.cpp:
(WebCore::VRStageParameters::VRStageParameters):
(WebCore::VRStageParameters::sittingToStandingTransform const):
(WebCore::VRStageParameters::sizeX const):
(WebCore::VRStageParameters::sizeZ const):
* Modules/webvr/VRStageParameters.h:
(WebCore::VRStageParameters::create):
* platform/vr/VRPlatformDisplay.h:
* platform/vr/openvr/VRPlatformDisplayOpenVR.cpp:
(WebCore::VRPlatformDisplayOpenVR::VRPlatformDisplayOpenVR):
(WebCore::VRPlatformDisplayOpenVR::updateStageParameters):
* platform/vr/openvr/VRPlatformDisplayOpenVR.h:

2018-02-21 Philippe Normand <pnormand@igalia.com>

[GStreamer] Create a Wayland GL display instead of EGL
@@ -31,6 +31,7 @@
#include "VRLayerInit.h"
#include "VRPlatformDisplay.h"
#include "VRPose.h"
#include "VRStageParameters.h"

namespace WebCore {

@@ -72,9 +73,10 @@ const VRDisplayCapabilities& VRDisplay::capabilities() const
return *m_capabilities;
}

VRStageParameters* VRDisplay::stageParameters() const
RefPtr<VRStageParameters> VRDisplay::stageParameters() const
{
return nullptr;
auto displayInfo = m_display->getDisplayInfo();
return VRStageParameters::create(displayInfo.sittingToStandingTransform, displayInfo.playAreaBounds);
}

const VREyeParameters& VRDisplay::getEyeParameters(VREye eye) const
@@ -55,7 +55,7 @@ class VRDisplay : public RefCounted<VRDisplay>, public EventTargetWithInlineData
bool isPresenting() const;

const VRDisplayCapabilities& capabilities() const;
VRStageParameters* stageParameters() const;
RefPtr<VRStageParameters> stageParameters() const;

const VREyeParameters& getEyeParameters(VREye) const;

@@ -104,6 +104,7 @@ class VRDisplay : public RefCounted<VRDisplay>, public EventTargetWithInlineData
// (except the sign of the eye to head transform offset).
RefPtr<VREyeParameters> m_leftEyeParameters;
RefPtr<VREyeParameters> m_rightEyeParameters;
RefPtr<VRStageParameters> m_stageParameters;

String m_displayName;
};
@@ -27,21 +27,27 @@

namespace WebCore {

VRStageParameters::VRStageParameters() = default;
VRStageParameters::VRStageParameters(const TransformationMatrix& sittingToStandingTransform, const FloatSize& playAreaBounds)
: m_playAreaBounds(playAreaBounds)
, m_sittingToStandingTransform(sittingToStandingTransform)
{
}

Float32Array* VRStageParameters::sittingToStandingTransform() const
Ref<Float32Array> VRStageParameters::sittingToStandingTransform() const
{
return nullptr;
TransformationMatrix::FloatMatrix4 columnMajorMatrix;
m_sittingToStandingTransform.toColumnMajorFloatArray(columnMajorMatrix);
return Float32Array::create(columnMajorMatrix, 16).releaseNonNull();
}

float VRStageParameters::sizeX() const
{
return 0;
return m_playAreaBounds.width();
}

float VRStageParameters::sizeZ() const
{
return 0;
return m_playAreaBounds.height();
}

} // namespace WebCore
@@ -24,25 +24,33 @@
*/
#pragma once

#include "TransformationMatrix.h"

#include <JavaScriptCore/Float32Array.h>
#include <wtf/RefCounted.h>
#include <wtf/RefPtr.h>

namespace WebCore {

class VRStageParameters : public RefCounted<VRStageParameters> {
public:
static Ref<VRStageParameters> create()
static RefPtr<VRStageParameters> create(const std::optional<TransformationMatrix>& sittingToStandingTransform, const std::optional<FloatSize>& playAreaBounds)
{
return adoptRef(*new VRStageParameters);
if (!sittingToStandingTransform || !playAreaBounds)
return nullptr;

return adoptRef(*new VRStageParameters(sittingToStandingTransform.value(), playAreaBounds.value()));
}

Float32Array* sittingToStandingTransform() const;
Ref<Float32Array> sittingToStandingTransform() const;

float sizeX() const;
float sizeZ() const;

private:
VRStageParameters();
VRStageParameters(const TransformationMatrix& sittingToStandingTransform, const FloatSize& playAreaBounds);

FloatSize m_playAreaBounds;
TransformationMatrix m_sittingToStandingTransform;
};

} // namespace WebCore
@@ -21,6 +21,7 @@
#pragma once

#include "FloatPoint3D.h"
#include "TransformationMatrix.h"

#include <wtf/WeakPtr.h>
#include <wtf/text/WTFString.h>
@@ -61,6 +62,9 @@ struct VRPlatformDisplayInfo {
unsigned width;
unsigned height;
} renderSize;

std::optional<FloatSize> playAreaBounds;
std::optional<TransformationMatrix> sittingToStandingTransform;
};

class VRPlatformDisplay {
@@ -53,6 +53,7 @@ VRPlatformDisplayOpenVR::VRPlatformDisplayOpenVR(vr::IVRSystem* system, vr::IVRC
VRDisplayCapabilityFlags::Present;

updateEyeParameters();
updateStageParameters();
}

VRPlatformDisplayInfo::FieldOfView VRPlatformDisplayOpenVR::computeFieldOfView(vr::Hmd_Eye eye)
@@ -78,6 +79,25 @@ void VRPlatformDisplayOpenVR::updateEyeParameters()
m_displayInfo.renderSize = { width, height };
}

void VRPlatformDisplayOpenVR::updateStageParameters()
{
float playAreaWidth = 1;
float playAreaDepth = 1;
if (!m_chaperone->GetPlayAreaSize(&playAreaWidth, &playAreaDepth)) {
// Fallback to sensible values, 1mx1m play area and 0.75m high seated position. We do as
// Firefox does.
m_displayInfo.sittingToStandingTransform = TransformationMatrix();
m_displayInfo.sittingToStandingTransform->setM42(0.75);
} else {
vr::HmdMatrix34_t transformMatrix = m_system->GetSeatedZeroPoseToStandingAbsoluteTrackingPose();
m_displayInfo.sittingToStandingTransform = TransformationMatrix(transformMatrix.m[0][0], transformMatrix.m[1][0], transformMatrix.m[2][0], 0,
transformMatrix.m[0][1], transformMatrix.m[1][1], transformMatrix.m[2][1], 0,
transformMatrix.m[0][2], transformMatrix.m[1][2], transformMatrix.m[2][2], 0,
transformMatrix.m[0][3], transformMatrix.m[1][3], transformMatrix.m[2][3], 1);
}
m_displayInfo.playAreaBounds = FloatSize(playAreaWidth, playAreaDepth);
}

}; // namespace WebCore

#endif // USE(OPENVR)
@@ -38,6 +38,7 @@ class VRPlatformDisplayOpenVR : public VRPlatformDisplay {
private:
VRPlatformDisplayInfo::FieldOfView computeFieldOfView(vr::Hmd_Eye);
void updateEyeParameters();
void updateStageParameters();

vr::IVRSystem* m_system;
vr::IVRChaperone* m_chaperone;

0 comments on commit 54e0ff3

Please sign in to comment.