Diff
Modified: trunk/Source/WebCore/ChangeLog (228818 => 228819)
--- trunk/Source/WebCore/ChangeLog 2018-02-20 14:16:00 UTC (rev 228818)
+++ trunk/Source/WebCore/ChangeLog 2018-02-20 15:52:01 UTC (rev 228819)
@@ -1,3 +1,51 @@
+2018-02-20 Sergio Villar Senin <[email protected]>
+
+ [WebVR][OpenVR] Retrieve eye parameters and field of view
+ https://bugs.webkit.org/show_bug.cgi?id=182962
+
+ Reviewed by Žan Doberšek.
+
+ Get the required data from OpenVR to fill in the VREyeParameters and
+ the VRFieldOfView objects.
+
+ * Modules/webvr/VRDisplay.cpp: Create some attributes in the
+ body of the constructor instead in the member initialization list to
+ avoid calling getDisplayInfo() multiple times.
+ (WebCore::VRDisplay::VRDisplay):
+ (WebCore::VRDisplay::capabilities const):
+ (WebCore::VRDisplay::getEyeParameters const):
+ * Modules/webvr/VRDisplay.h:
+ * Modules/webvr/VREyeParameters.cpp:
+ (WebCore::VREyeParameters::VREyeParameters): Added new attributes to
+ the constructor.
+ (WebCore::VREyeParameters::offset const): Return a Ref instead of
+ a raw pointer.
+ (WebCore::VREyeParameters::renderWidth const):
+ (WebCore::VREyeParameters::renderHeight const):
+ * Modules/webvr/VREyeParameters.h:
+ (WebCore::VREyeParameters::create):
+ * Modules/webvr/VRFieldOfView.cpp: Removed. All the impletementation
+ fits perfectly in the header file.
+ * Modules/webvr/VRFieldOfView.h:
+ (WebCore::VRFieldOfView::create):
+ (WebCore::VRFieldOfView::upDegrees const):
+ (WebCore::VRFieldOfView::rightDegrees const):
+ (WebCore::VRFieldOfView::downDegrees const):
+ (WebCore::VRFieldOfView::leftDegrees const):
+ (WebCore::VRFieldOfView::VRFieldOfView):
+ * Sources.txt:
+ * platform/vr/VRPlatformDisplay.h: Added some more data to the
+ VRPlatformDisplayInfo struct.
+ * platform/vr/openvr/VRPlatformDisplayOpenVR.cpp:
+ (WebCore::VRPlatformDisplayOpenVR::VRPlatformDisplayOpenVR):
+ (WebCore::VRPlatformDisplayOpenVR::computeFieldOfView): Computes the
+ up/down/left/right FOV angles in degrees from the raw project
+ values returned by OpenVR.
+ (WebCore::VRPlatformDisplayOpenVR::updateEyeParameters): Fills in
+ the eye parameter info.
+ (WebCore::VRPlatformDisplayOpenVR::~VRPlatformDisplayOpenVR):
+ * platform/vr/openvr/VRPlatformDisplayOpenVR.h:
+
2018-02-20 Philippe Normand <[email protected]>
[GStreamer][MiniBrowser] Honor GStreamer command line parameters in MiniBrowser
Modified: trunk/Source/WebCore/Modules/webvr/VRDisplay.cpp (228818 => 228819)
--- trunk/Source/WebCore/Modules/webvr/VRDisplay.cpp 2018-02-20 14:16:00 UTC (rev 228818)
+++ trunk/Source/WebCore/Modules/webvr/VRDisplay.cpp 2018-02-20 15:52:01 UTC (rev 228819)
@@ -43,11 +43,13 @@
VRDisplay::VRDisplay(ScriptExecutionContext& context, WeakPtr<VRPlatformDisplay>&& platformDisplay)
: ActiveDOMObject(&context)
- , m_capabilities(VRDisplayCapabilities::create(platformDisplay->getDisplayInfo().capabilityFlags))
- , m_eyeParameters(VREyeParameters::create())
, m_display(WTFMove(platformDisplay))
- , m_displayName(platformDisplay->getDisplayInfo().displayName)
{
+ auto displayInfo = m_display->getDisplayInfo();
+ m_capabilities = VRDisplayCapabilities::create(displayInfo.capabilityFlags);
+ m_leftEyeParameters = VREyeParameters::create(displayInfo.eyeTranslation[VRPlatformDisplayInfo::EyeLeft], displayInfo.eyeFieldOfView[VRPlatformDisplayInfo::EyeLeft], displayInfo.renderSize);
+ m_rightEyeParameters = VREyeParameters::create(displayInfo.eyeTranslation[VRPlatformDisplayInfo::EyeRight], displayInfo.eyeFieldOfView[VRPlatformDisplayInfo::EyeRight], displayInfo.renderSize);
+ m_displayName = displayInfo.displayName;
}
VRDisplay::~VRDisplay() = default;
@@ -67,7 +69,7 @@
const VRDisplayCapabilities& VRDisplay::capabilities() const
{
- return m_capabilities;
+ return *m_capabilities;
}
VRStageParameters* VRDisplay::stageParameters() const
@@ -75,9 +77,9 @@
return nullptr;
}
-const VREyeParameters& VRDisplay::getEyeParameters(VREye) const
+const VREyeParameters& VRDisplay::getEyeParameters(VREye eye) const
{
- return m_eyeParameters;
+ return eye == VREye::Left ? *m_leftEyeParameters : *m_rightEyeParameters;
}
unsigned VRDisplay::displayId() const
Modified: trunk/Source/WebCore/Modules/webvr/VRDisplay.h (228818 => 228819)
--- trunk/Source/WebCore/Modules/webvr/VRDisplay.h 2018-02-20 14:16:00 UTC (rev 228818)
+++ trunk/Source/WebCore/Modules/webvr/VRDisplay.h 2018-02-20 15:52:01 UTC (rev 228819)
@@ -97,12 +97,15 @@
bool canSuspendForDocumentSuspension() const override;
void stop() override;
- Ref<VRDisplayCapabilities> m_capabilities;
- Ref<VREyeParameters> m_eyeParameters;
-
WeakPtr<VRPlatformDisplay> m_display;
- const String m_displayName;
+ RefPtr<VRDisplayCapabilities> m_capabilities;
+ // We could likely store just one of the two following ones as the values should be identical
+ // (except the sign of the eye to head transform offset).
+ RefPtr<VREyeParameters> m_leftEyeParameters;
+ RefPtr<VREyeParameters> m_rightEyeParameters;
+
+ String m_displayName;
};
} // namespace WebCore
Modified: trunk/Source/WebCore/Modules/webvr/VREyeParameters.cpp (228818 => 228819)
--- trunk/Source/WebCore/Modules/webvr/VREyeParameters.cpp 2018-02-20 14:16:00 UTC (rev 228818)
+++ trunk/Source/WebCore/Modules/webvr/VREyeParameters.cpp 2018-02-20 15:52:01 UTC (rev 228819)
@@ -29,16 +29,22 @@
namespace WebCore {
-VREyeParameters::VREyeParameters()
- : m_fieldOfView(VRFieldOfView::create())
+VREyeParameters::VREyeParameters(const FloatPoint3D& offset, const VRPlatformDisplayInfo::FieldOfView& fieldOfView, const RenderSize& renderSize)
+ : m_fieldOfView(VRFieldOfView::create(fieldOfView))
+ , m_offset(offset)
+ , m_renderSize(renderSize)
{
}
-VREyeParameters::~VREyeParameters() = default;
-
-Float32Array* VREyeParameters::offset() const
+Ref<Float32Array> VREyeParameters::offset() const
{
- return nullptr;
+ auto offset = Float32Array::create(3);
+ RELEASE_ASSERT(offset);
+ float* offsetData = offset->data();
+ offsetData[0] = m_offset.x();
+ offsetData[1] = m_offset.y();
+ offsetData[2] = m_offset.z();
+ return offset.releaseNonNull();
}
const VRFieldOfView& VREyeParameters::fieldOfView() const
@@ -48,12 +54,12 @@
unsigned VREyeParameters::renderWidth() const
{
- return 0;
+ return m_renderSize.width;
}
unsigned VREyeParameters::renderHeight() const
{
- return 0;
+ return m_renderSize.height;
}
} // namespace WebCore
Modified: trunk/Source/WebCore/Modules/webvr/VREyeParameters.h (228818 => 228819)
--- trunk/Source/WebCore/Modules/webvr/VREyeParameters.h 2018-02-20 14:16:00 UTC (rev 228818)
+++ trunk/Source/WebCore/Modules/webvr/VREyeParameters.h 2018-02-20 15:52:01 UTC (rev 228819)
@@ -24,22 +24,25 @@
*/
#pragma once
+#include "FloatPoint3D.h"
+#include "VRFieldOfView.h"
+#include "VRPlatformDisplay.h"
+
#include <_javascript_Core/Float32Array.h>
#include <wtf/RefCounted.h>
namespace WebCore {
-class VRFieldOfView;
-
class VREyeParameters : public RefCounted<VREyeParameters> {
public:
- static Ref<VREyeParameters> create()
+ using RenderSize = VRPlatformDisplayInfo::RenderSize;
+
+ static Ref<VREyeParameters> create(const FloatPoint3D& offset, const VRPlatformDisplayInfo::FieldOfView& fieldOfView, const RenderSize& renderSize)
{
- return adoptRef(*new VREyeParameters);
+ return adoptRef(*new VREyeParameters(offset, fieldOfView, renderSize));
}
- ~VREyeParameters();
- Float32Array* offset() const;
+ Ref<Float32Array> offset() const;
const VRFieldOfView& fieldOfView() const;
@@ -47,9 +50,11 @@
unsigned renderHeight() const;
private:
- VREyeParameters();
+ VREyeParameters(const FloatPoint3D& offset, const VRPlatformDisplayInfo::FieldOfView&, const RenderSize&);
Ref<VRFieldOfView> m_fieldOfView;
+ FloatPoint3D m_offset;
+ RenderSize m_renderSize;
};
} // namespace WebCore
Deleted: trunk/Source/WebCore/Modules/webvr/VRFieldOfView.cpp (228818 => 228819)
--- trunk/Source/WebCore/Modules/webvr/VRFieldOfView.cpp 2018-02-20 14:16:00 UTC (rev 228818)
+++ trunk/Source/WebCore/Modules/webvr/VRFieldOfView.cpp 2018-02-20 15:52:01 UTC (rev 228819)
@@ -1,52 +0,0 @@
-/*
- * Copyright (C) 2017 Igalia S.L. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-#include "config.h"
-#include "VRFieldOfView.h"
-
-namespace WebCore {
-
-VRFieldOfView::VRFieldOfView() = default;
-
-double VRFieldOfView::upDegrees() const
-{
- return 0;
-}
-
-double VRFieldOfView::rightDegrees() const
-{
- return 0;
-}
-
-double VRFieldOfView::downDegrees() const
-{
- return 0;
-}
-
-double VRFieldOfView::leftDegrees() const
-{
- return 0;
-}
-
-} // namespace WebCore
Modified: trunk/Source/WebCore/Modules/webvr/VRFieldOfView.h (228818 => 228819)
--- trunk/Source/WebCore/Modules/webvr/VRFieldOfView.h 2018-02-20 14:16:00 UTC (rev 228818)
+++ trunk/Source/WebCore/Modules/webvr/VRFieldOfView.h 2018-02-20 15:52:01 UTC (rev 228819)
@@ -24,6 +24,8 @@
*/
#pragma once
+#include "VRPlatformDisplay.h"
+
#include <wtf/Ref.h>
#include <wtf/RefCounted.h>
@@ -31,18 +33,29 @@
class VRFieldOfView : public RefCounted<VRFieldOfView> {
public:
- static Ref<VRFieldOfView> create()
+ static Ref<VRFieldOfView> create(VRPlatformDisplayInfo::FieldOfView fieldOfView)
{
- return adoptRef(*new VRFieldOfView);
+ return adoptRef(*new VRFieldOfView(fieldOfView));
}
- double upDegrees() const;
- double rightDegrees() const;
- double downDegrees() const;
- double leftDegrees() const;
+ double upDegrees() const { return m_upDegrees; };
+ double rightDegrees() const { return m_rightDegrees; };
+ double downDegrees() const { return m_downDegrees; };
+ double leftDegrees() const { return m_leftDegrees; };
private:
- VRFieldOfView();
+ VRFieldOfView(VRPlatformDisplayInfo::FieldOfView fieldOfView)
+ : m_upDegrees(fieldOfView.upDegrees)
+ , m_rightDegrees(fieldOfView.rightDegrees)
+ , m_downDegrees(fieldOfView.downDegrees)
+ , m_leftDegrees(fieldOfView.leftDegrees)
+ {
+ }
+
+ double m_upDegrees;
+ double m_rightDegrees;
+ double m_downDegrees;
+ double m_leftDegrees;
};
} // namespace WebCore
Modified: trunk/Source/WebCore/Sources.txt (228818 => 228819)
--- trunk/Source/WebCore/Sources.txt 2018-02-20 14:16:00 UTC (rev 228818)
+++ trunk/Source/WebCore/Sources.txt 2018-02-20 15:52:01 UTC (rev 228819)
@@ -293,7 +293,6 @@
Modules/webvr/VRDisplayCapabilities.cpp
Modules/webvr/VRDisplayEvent.cpp
Modules/webvr/VREyeParameters.cpp
-Modules/webvr/VRFieldOfView.cpp
Modules/webvr/VRFrameData.cpp
Modules/webvr/VRPose.cpp
Modules/webvr/VRStageParameters.cpp
Modified: trunk/Source/WebCore/platform/vr/VRPlatformDisplay.h (228818 => 228819)
--- trunk/Source/WebCore/platform/vr/VRPlatformDisplay.h 2018-02-20 14:16:00 UTC (rev 228818)
+++ trunk/Source/WebCore/platform/vr/VRPlatformDisplay.h 2018-02-20 15:52:01 UTC (rev 228819)
@@ -20,6 +20,8 @@
#pragma once
+#include "FloatPoint3D.h"
+
#include <wtf/WeakPtr.h>
#include <wtf/text/WTFString.h>
@@ -44,6 +46,21 @@
bool isConnected;
bool isMounted;
unsigned capabilityFlags;
+
+ enum Eye { EyeLeft = 0, EyeRight, NumEyes };
+ FloatPoint3D eyeTranslation[Eye::NumEyes];
+
+ struct FieldOfView {
+ double upDegrees;
+ double downDegrees;
+ double leftDegrees;
+ double rightDegrees;
+ } eyeFieldOfView[Eye::NumEyes];
+
+ struct RenderSize {
+ unsigned width;
+ unsigned height;
+ } renderSize;
};
class VRPlatformDisplay {
Modified: trunk/Source/WebCore/platform/vr/openvr/VRPlatformDisplayOpenVR.cpp (228818 => 228819)
--- trunk/Source/WebCore/platform/vr/openvr/VRPlatformDisplayOpenVR.cpp 2018-02-20 14:16:00 UTC (rev 228818)
+++ trunk/Source/WebCore/platform/vr/openvr/VRPlatformDisplayOpenVR.cpp 2018-02-20 15:52:01 UTC (rev 228819)
@@ -51,8 +51,33 @@
VRDisplayCapabilityFlags::Orientation |
VRDisplayCapabilityFlags::ExternalDisplay |
VRDisplayCapabilityFlags::Present;
+
+ updateEyeParameters();
}
+VRPlatformDisplayInfo::FieldOfView VRPlatformDisplayOpenVR::computeFieldOfView(vr::Hmd_Eye eye)
+{
+ float left, right, top, bottom;
+ // OpenVR returns the tangents of the half-angles from the center view axis.
+ m_system->GetProjectionRaw(static_cast<vr::Hmd_Eye>(eye), &left, &right, &top, &bottom);
+ return { -rad2deg(atanf(top)), rad2deg(atanf(bottom)), -rad2deg(atanf(left)), rad2deg(atanf(right)) };
+}
+
+void VRPlatformDisplayOpenVR::updateEyeParameters()
+{
+ for (unsigned eye = 0; eye < VRPlatformDisplayInfo::NumEyes; ++eye) {
+ m_displayInfo.eyeFieldOfView[eye] = computeFieldOfView(static_cast<vr::Hmd_Eye>(eye));
+
+ vr::HmdMatrix34_t eyeToHead = m_system->GetEyeToHeadTransform(static_cast<vr::Hmd_Eye>(eye));
+ m_displayInfo.eyeTranslation[eye].set(eyeToHead.m[0][3], eyeToHead.m[1][3], eyeToHead.m[2][3]);
+ }
+
+ uint32_t width;
+ uint32_t height;
+ m_system->GetRecommendedRenderTargetSize(&width, &height);
+ m_displayInfo.renderSize = { width, height };
+}
+
}; // namespace WebCore
#endif // USE(OPENVR)
Modified: trunk/Source/WebCore/platform/vr/openvr/VRPlatformDisplayOpenVR.h (228818 => 228819)
--- trunk/Source/WebCore/platform/vr/openvr/VRPlatformDisplayOpenVR.h 2018-02-20 14:16:00 UTC (rev 228818)
+++ trunk/Source/WebCore/platform/vr/openvr/VRPlatformDisplayOpenVR.h 2018-02-20 15:52:01 UTC (rev 228819)
@@ -32,9 +32,13 @@
public:
explicit VRPlatformDisplayOpenVR(vr::IVRSystem*, vr::IVRChaperone*, vr::IVRCompositor*);
+ ~VRPlatformDisplayOpenVR() = default;
VRPlatformDisplayInfo getDisplayInfo() override { return m_displayInfo; }
private:
+ VRPlatformDisplayInfo::FieldOfView computeFieldOfView(vr::Hmd_Eye);
+ void updateEyeParameters();
+
vr::IVRSystem* m_system;
vr::IVRChaperone* m_chaperone;
vr::IVRCompositor* m_compositor;