Title: [228867] trunk/Source/WebCore
Revision
228867
Author
[email protected]
Date
2018-02-21 02:47:14 -0800 (Wed, 21 Feb 2018)

Log Message

[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:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (228866 => 228867)


--- trunk/Source/WebCore/ChangeLog	2018-02-21 09:34:35 UTC (rev 228866)
+++ trunk/Source/WebCore/ChangeLog	2018-02-21 10:47:14 UTC (rev 228867)
@@ -1,3 +1,32 @@
+2018-02-20  Sergio Villar Senin  <[email protected]>
+
+        [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  <[email protected]>
 
         [GStreamer] Create a Wayland GL display instead of EGL

Modified: trunk/Source/WebCore/Modules/webvr/VRDisplay.cpp (228866 => 228867)


--- trunk/Source/WebCore/Modules/webvr/VRDisplay.cpp	2018-02-21 09:34:35 UTC (rev 228866)
+++ trunk/Source/WebCore/Modules/webvr/VRDisplay.cpp	2018-02-21 10:47:14 UTC (rev 228867)
@@ -31,6 +31,7 @@
 #include "VRLayerInit.h"
 #include "VRPlatformDisplay.h"
 #include "VRPose.h"
+#include "VRStageParameters.h"
 
 namespace WebCore {
 
@@ -72,9 +73,10 @@
     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

Modified: trunk/Source/WebCore/Modules/webvr/VRDisplay.h (228866 => 228867)


--- trunk/Source/WebCore/Modules/webvr/VRDisplay.h	2018-02-21 09:34:35 UTC (rev 228866)
+++ trunk/Source/WebCore/Modules/webvr/VRDisplay.h	2018-02-21 10:47:14 UTC (rev 228867)
@@ -55,7 +55,7 @@
     bool isPresenting() const;
 
     const VRDisplayCapabilities& capabilities() const;
-    VRStageParameters* stageParameters() const;
+    RefPtr<VRStageParameters> stageParameters() const;
 
     const VREyeParameters& getEyeParameters(VREye) const;
 
@@ -104,6 +104,7 @@
     // (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;
 };

Modified: trunk/Source/WebCore/Modules/webvr/VRStageParameters.cpp (228866 => 228867)


--- trunk/Source/WebCore/Modules/webvr/VRStageParameters.cpp	2018-02-21 09:34:35 UTC (rev 228866)
+++ trunk/Source/WebCore/Modules/webvr/VRStageParameters.cpp	2018-02-21 10:47:14 UTC (rev 228867)
@@ -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

Modified: trunk/Source/WebCore/Modules/webvr/VRStageParameters.h (228866 => 228867)


--- trunk/Source/WebCore/Modules/webvr/VRStageParameters.h	2018-02-21 09:34:35 UTC (rev 228866)
+++ trunk/Source/WebCore/Modules/webvr/VRStageParameters.h	2018-02-21 10:47:14 UTC (rev 228867)
@@ -24,25 +24,33 @@
  */
 #pragma once
 
+#include "TransformationMatrix.h"
+
 #include <_javascript_Core/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

Modified: trunk/Source/WebCore/platform/vr/VRPlatformDisplay.h (228866 => 228867)


--- trunk/Source/WebCore/platform/vr/VRPlatformDisplay.h	2018-02-21 09:34:35 UTC (rev 228866)
+++ trunk/Source/WebCore/platform/vr/VRPlatformDisplay.h	2018-02-21 10:47:14 UTC (rev 228867)
@@ -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 @@
         unsigned width;
         unsigned height;
     } renderSize;
+
+    std::optional<FloatSize> playAreaBounds;
+    std::optional<TransformationMatrix> sittingToStandingTransform;
 };
 
 class VRPlatformDisplay {

Modified: trunk/Source/WebCore/platform/vr/openvr/VRPlatformDisplayOpenVR.cpp (228866 => 228867)


--- trunk/Source/WebCore/platform/vr/openvr/VRPlatformDisplayOpenVR.cpp	2018-02-21 09:34:35 UTC (rev 228866)
+++ trunk/Source/WebCore/platform/vr/openvr/VRPlatformDisplayOpenVR.cpp	2018-02-21 10:47:14 UTC (rev 228867)
@@ -53,6 +53,7 @@
         VRDisplayCapabilityFlags::Present;
 
     updateEyeParameters();
+    updateStageParameters();
 }
 
 VRPlatformDisplayInfo::FieldOfView VRPlatformDisplayOpenVR::computeFieldOfView(vr::Hmd_Eye eye)
@@ -78,6 +79,25 @@
     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)

Modified: trunk/Source/WebCore/platform/vr/openvr/VRPlatformDisplayOpenVR.h (228866 => 228867)


--- trunk/Source/WebCore/platform/vr/openvr/VRPlatformDisplayOpenVR.h	2018-02-21 09:34:35 UTC (rev 228866)
+++ trunk/Source/WebCore/platform/vr/openvr/VRPlatformDisplayOpenVR.h	2018-02-21 10:47:14 UTC (rev 228867)
@@ -38,6 +38,7 @@
 private:
     VRPlatformDisplayInfo::FieldOfView computeFieldOfView(vr::Hmd_Eye);
     void updateEyeParameters();
+    void updateStageParameters();
 
     vr::IVRSystem* m_system;
     vr::IVRChaperone* m_chaperone;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to