Title: [273957] trunk
Revision
273957
Author
[email protected]
Date
2021-03-05 02:50:10 -0800 (Fri, 05 Mar 2021)

Log Message

Implement WebXRBoundedReferenceSpace bounds geometry
https://bugs.webkit.org/show_bug.cgi?id=222737

Patch by Imanol Fernandez <[email protected]> on 2021-03-05
Reviewed by Sergio Villar Senin.

LayoutTests/imported/w3c:

Update WebXRBoundedReferenceSpace test expectations.

* web-platform-tests/webxr/xrBoundedReferenceSpace_updates.https-expected.txt: Added.

Source/WebCore:

Having bounds geometry in WebXRBoundedReferenceSpace enables WebXR room-scale applications. XR systems may have limited
real world spatial ranges in which users can freely move around while remaining tracked. WebXR Applications can query
these boundaries and alter application behavior or content placement to ensure the user can complete the experience while
remaining within the boundary.

Tested by WebXR WPT tests.

* Modules/webxr/WebXRBoundedReferenceSpace.cpp:
(WebCore::WebXRBoundedReferenceSpace::boundsGeometry): Call updateIfNeeded
(WebCore::WebXRBoundedReferenceSpace::getOffsetReferenceSpace): Use Exception instead of null RefPtr<>
(WebCore::WebXRBoundedReferenceSpace::updateIfNeeded): Updates boundsGeometry vector when data changed.
(WebCore::WebXRBoundedReferenceSpace::quantize): Utility method to avoid fingerprinting.
* Modules/webxr/WebXRBoundedReferenceSpace.h:

* Modules/webxr/WebXRBoundedReferenceSpace.idl: Add CustomToJSObject

* Modules/webxr/WebXRReferenceSpace.cpp:
(WebCore::WebXRReferenceSpace::getOffsetReferenceSpace): Use Exception instead of null RefPtr<>
* Modules/webxr/WebXRReferenceSpace.h:
* Modules/webxr/WebXRReferenceSpace.idl: Add CustomToJSObject
* Modules/webxr/WebXRSpace.idl: Add CustomToJSObject

* Sources.txt: Add CustomToJSObject implementations
* bindings/js/JSWebXRReferenceSpaceCustom.cpp: Added.
(WebCore::toJSNewlyCreated):
(WebCore::toJS):
* bindings/js/JSWebXRSpaceCustom.cpp: Added.
(WebCore::toJSNewlyCreated):
(WebCore::toJS):

* platform/xr/PlatformXR.h: Add StageParameters to FrameData.

* platform/xr/openxr/PlatformXROpenXR.cpp: Implement boundsGeometry using OpenXR.
(PlatformXR::OpenXRDevice::initializeReferenceSpace):
(PlatformXR::OpenXRDevice::requestFrame):
(PlatformXR::OpenXRDevice::collectEnabledFeatures):
(PlatformXR::OpenXRDevice::pollEvents):
(PlatformXR::OpenXRDevice::resetSession):
(PlatformXR::OpenXRDevice::updateStageParameters):
* platform/xr/openxr/PlatformXROpenXR.h:

* testing/WebFakeXRDevice.cpp: Implement boundsGeometry for tests.
(WebCore::SimulatedXRDevice::setNativeBoundsGeometry):
(WebCore::SimulatedXRDevice::frameTimerFired):
(WebCore::WebFakeXRDevice::setBoundsGeometry):
* testing/WebFakeXRDevice.h:

LayoutTests:

Update WebXRBoundedReferenceSpace test expectations.

* platform/wpe/TestExpectations:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (273956 => 273957)


--- trunk/LayoutTests/ChangeLog	2021-03-05 10:18:29 UTC (rev 273956)
+++ trunk/LayoutTests/ChangeLog	2021-03-05 10:50:10 UTC (rev 273957)
@@ -1,3 +1,14 @@
+2021-03-05  Imanol Fernandez  <[email protected]>
+
+        Implement WebXRBoundedReferenceSpace bounds geometry
+        https://bugs.webkit.org/show_bug.cgi?id=222737
+
+        Reviewed by Sergio Villar Senin.
+
+        Update WebXRBoundedReferenceSpace test expectations.
+
+        * platform/wpe/TestExpectations:
+
 2021-03-05  Said Abou-Hallawa  <[email protected]>
 
         [GPU Process] RemoteImageBuffer recording GraphicsContext should report its backend RenderingMode

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (273956 => 273957)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2021-03-05 10:18:29 UTC (rev 273956)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2021-03-05 10:50:10 UTC (rev 273957)
@@ -1,3 +1,14 @@
+2021-03-05  Imanol Fernandez  <[email protected]>
+
+        Implement WebXRBoundedReferenceSpace bounds geometry
+        https://bugs.webkit.org/show_bug.cgi?id=222737
+
+        Reviewed by Sergio Villar Senin.
+
+        Update WebXRBoundedReferenceSpace test expectations.
+
+        * web-platform-tests/webxr/xrBoundedReferenceSpace_updates.https-expected.txt: Added.
+
 2021-03-04  Antoine Quint  <[email protected]>
 
         initial value for border-image-outset should be 0

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/webxr/xrBoundedReferenceSpace_updates.https-expected.txt (0 => 273957)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/webxr/xrBoundedReferenceSpace_updates.https-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/webxr/xrBoundedReferenceSpace_updates.https-expected.txt	2021-03-05 10:50:10 UTC (rev 273957)
@@ -0,0 +1,3 @@
+
+PASS 'XRBoundedReferenceSpace updates properly when the changes are applied
+

Modified: trunk/LayoutTests/platform/wpe/TestExpectations (273956 => 273957)


--- trunk/LayoutTests/platform/wpe/TestExpectations	2021-03-05 10:18:29 UTC (rev 273956)
+++ trunk/LayoutTests/platform/wpe/TestExpectations	2021-03-05 10:50:10 UTC (rev 273957)
@@ -606,6 +606,7 @@
 
 # WebXR
 webkit.org/b/212897 imported/w3c/web-platform-tests/webxr/idlharness.https.window.html [ Failure ]
+imported/w3c/web-platform-tests/webxr/xrBoundedReferenceSpace_updates.https.html [ Pass ]
 webkit.org/b/209859 imported/w3c/web-platform-tests/webxr/webGLCanvasContext_create_xrcompatible.https.html [ Pass ]
 webkit.org/b/209859 imported/w3c/web-platform-tests/webxr/webGLCanvasContext_makecompatible_contextlost.https.html [ Pass ]
 webkit.org/b/209859 imported/w3c/web-platform-tests/webxr/webGLCanvasContext_makecompatible_reentrant.https.html [ Pass ]

Modified: trunk/Source/WebCore/ChangeLog (273956 => 273957)


--- trunk/Source/WebCore/ChangeLog	2021-03-05 10:18:29 UTC (rev 273956)
+++ trunk/Source/WebCore/ChangeLog	2021-03-05 10:50:10 UTC (rev 273957)
@@ -1,3 +1,57 @@
+2021-03-05  Imanol Fernandez  <[email protected]>
+
+        Implement WebXRBoundedReferenceSpace bounds geometry
+        https://bugs.webkit.org/show_bug.cgi?id=222737
+
+        Reviewed by Sergio Villar Senin.
+
+        Having bounds geometry in WebXRBoundedReferenceSpace enables WebXR room-scale applications. XR systems may have limited
+        real world spatial ranges in which users can freely move around while remaining tracked. WebXR Applications can query
+        these boundaries and alter application behavior or content placement to ensure the user can complete the experience while
+        remaining within the boundary.
+
+        Tested by WebXR WPT tests.
+
+        * Modules/webxr/WebXRBoundedReferenceSpace.cpp:
+        (WebCore::WebXRBoundedReferenceSpace::boundsGeometry): Call updateIfNeeded
+        (WebCore::WebXRBoundedReferenceSpace::getOffsetReferenceSpace): Use Exception instead of null RefPtr<>
+        (WebCore::WebXRBoundedReferenceSpace::updateIfNeeded): Updates boundsGeometry vector when data changed.
+        (WebCore::WebXRBoundedReferenceSpace::quantize): Utility method to avoid fingerprinting.
+        * Modules/webxr/WebXRBoundedReferenceSpace.h:
+
+        * Modules/webxr/WebXRBoundedReferenceSpace.idl: Add CustomToJSObject
+
+        * Modules/webxr/WebXRReferenceSpace.cpp:
+        (WebCore::WebXRReferenceSpace::getOffsetReferenceSpace): Use Exception instead of null RefPtr<>
+        * Modules/webxr/WebXRReferenceSpace.h:
+        * Modules/webxr/WebXRReferenceSpace.idl: Add CustomToJSObject
+        * Modules/webxr/WebXRSpace.idl: Add CustomToJSObject
+
+        * Sources.txt: Add CustomToJSObject implementations
+        * bindings/js/JSWebXRReferenceSpaceCustom.cpp: Added.
+        (WebCore::toJSNewlyCreated):
+        (WebCore::toJS):
+        * bindings/js/JSWebXRSpaceCustom.cpp: Added.
+        (WebCore::toJSNewlyCreated):
+        (WebCore::toJS):
+
+        * platform/xr/PlatformXR.h: Add StageParameters to FrameData.
+
+        * platform/xr/openxr/PlatformXROpenXR.cpp: Implement boundsGeometry using OpenXR.
+        (PlatformXR::OpenXRDevice::initializeReferenceSpace):
+        (PlatformXR::OpenXRDevice::requestFrame):
+        (PlatformXR::OpenXRDevice::collectEnabledFeatures):
+        (PlatformXR::OpenXRDevice::pollEvents):
+        (PlatformXR::OpenXRDevice::resetSession):
+        (PlatformXR::OpenXRDevice::updateStageParameters):
+        * platform/xr/openxr/PlatformXROpenXR.h:
+
+        * testing/WebFakeXRDevice.cpp: Implement boundsGeometry for tests.
+        (WebCore::SimulatedXRDevice::setNativeBoundsGeometry):
+        (WebCore::SimulatedXRDevice::frameTimerFired):
+        (WebCore::WebFakeXRDevice::setBoundsGeometry):
+        * testing/WebFakeXRDevice.h:
+
 2021-03-05  Said Abou-Hallawa  <[email protected]>
 
         [GPU Process] RemoteImageBuffer recording GraphicsContext should report its backend RenderingMode

Modified: trunk/Source/WebCore/Modules/webxr/WebXRBoundedReferenceSpace.cpp (273956 => 273957)


--- trunk/Source/WebCore/Modules/webxr/WebXRBoundedReferenceSpace.cpp	2021-03-05 10:18:29 UTC (rev 273956)
+++ trunk/Source/WebCore/Modules/webxr/WebXRBoundedReferenceSpace.cpp	2021-03-05 10:50:10 UTC (rev 273957)
@@ -36,6 +36,12 @@
 
 namespace WebCore {
 
+// https://immersive-web.github.io/webxr/#xrboundedreferencespace-native-bounds-geometry
+// It is suggested that points of the native bounds geometry be quantized to the nearest 5cm.
+static constexpr float BoundsPrecisionInMeters = 0.05; 
+// A valid polygon has at least 3 vertices.
+static constexpr int MinimumBoundsVertices = 3; 
+
 WTF_MAKE_ISO_ALLOCATED_IMPL(WebXRBoundedReferenceSpace);
 
 Ref<WebXRBoundedReferenceSpace> WebXRBoundedReferenceSpace::create(Document& document, Ref<WebXRSession>&& session, XRReferenceSpaceType type)
@@ -43,13 +49,11 @@
     return adoptRef(*new WebXRBoundedReferenceSpace(document, WTFMove(session), WebXRRigidTransform::create(), type));
 }
 
-
 Ref<WebXRBoundedReferenceSpace> WebXRBoundedReferenceSpace::create(Document& document, Ref<WebXRSession>&& session, Ref<WebXRRigidTransform>&& offset, XRReferenceSpaceType type)
 {
     return adoptRef(*new WebXRBoundedReferenceSpace(document, WTFMove(session), WTFMove(offset), type));
 }
 
-
 WebXRBoundedReferenceSpace::WebXRBoundedReferenceSpace(Document& document, Ref<WebXRSession>&& session, Ref<WebXRRigidTransform>&& offset, XRReferenceSpaceType type)
     : WebXRReferenceSpace(document, WTFMove(session), WTFMove(offset), type)
 {
@@ -64,26 +68,54 @@
     return floorOriginTransform();
 }
 
-const Vector<Ref<DOMPointReadOnly>>& WebXRBoundedReferenceSpace::boundsGeometry() const
+const Vector<Ref<DOMPointReadOnly>>& WebXRBoundedReferenceSpace::boundsGeometry()
 {
-    // FIXME: get data from device
+    updateIfNeeded();
     return m_boundsGeometry;
 }
 
-RefPtr<WebXRReferenceSpace> WebXRBoundedReferenceSpace::getOffsetReferenceSpace(const WebXRRigidTransform& offsetTransform)
+ExceptionOr<Ref<WebXRReferenceSpace>> WebXRBoundedReferenceSpace::getOffsetReferenceSpace(const WebXRRigidTransform& offsetTransform)
 {
     auto* document = downcast<Document>(scriptExecutionContext());
     if (!document)
-        return nullptr;
+        return Exception { InvalidStateError };
 
     // https://immersive-web.github.io/webxr/#dom-xrreferencespace-getoffsetreferencespace
     // Set offsetSpace’s origin offset to the result of multiplying base’s origin offset by originOffset in the relevant realm of base.
     auto offset = WebXRRigidTransform::create(originOffset().rawTransform() * offsetTransform.rawTransform());
 
-    // FIXME: set offsetSpace’s boundsGeometry to base’s boundsGeometry, with each point multiplied by the inverse of originOffset.
-    return create(*document, m_session.copyRef(), WTFMove(offset), m_type);
+    return { create(*document, m_session.copyRef(), WTFMove(offset), m_type) };
 }
 
+// https://immersive-web.github.io/webxr/#dom-xrboundedreferencespace-boundsgeometry
+void WebXRBoundedReferenceSpace::updateIfNeeded()
+{
+    auto& frameData = m_session->frameData();
+    if (frameData.stageParameters.id == m_lastUpdateId)
+        return;
+    m_lastUpdateId = frameData.stageParameters.id;
+
+    m_boundsGeometry.clear();
+
+    if (frameData.stageParameters.bounds.size() >= MinimumBoundsVertices) {
+        // Each point has to multiplied by the inverse of originOffset.
+        auto transform = originOffset().rawTransform().inverse().valueOr(TransformationMatrix());
+        for (auto& point : frameData.stageParameters.bounds) {
+            auto mappedPoint = transform.mapPoint(point);
+            // The y value of each point MUST be 0.
+            m_boundsGeometry.append(DOMPointReadOnly::create(quantize(mappedPoint.x()), 0.0, quantize(mappedPoint.y()), 1.0));
+        }
+    }
+}
+
+// https://immersive-web.github.io/webxr/#quantization
+float WebXRBoundedReferenceSpace::quantize(float value)
+{
+    // Each point in the native bounds geometry MUST also be quantized sufficiently to prevent fingerprinting.
+    // For user’s safety, quantized points values MUST NOT fall outside the bounds reported by the platform.
+    return std::floor(value / BoundsPrecisionInMeters) * BoundsPrecisionInMeters;
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(WEBXR)

Modified: trunk/Source/WebCore/Modules/webxr/WebXRBoundedReferenceSpace.h (273956 => 273957)


--- trunk/Source/WebCore/Modules/webxr/WebXRBoundedReferenceSpace.h	2021-03-05 10:18:29 UTC (rev 273956)
+++ trunk/Source/WebCore/Modules/webxr/WebXRBoundedReferenceSpace.h	2021-03-05 10:50:10 UTC (rev 273957)
@@ -45,8 +45,8 @@
     virtual ~WebXRBoundedReferenceSpace();
 
     TransformationMatrix nativeOrigin() const final;
-    const Vector<Ref<DOMPointReadOnly>>& boundsGeometry() const;
-    RefPtr<WebXRReferenceSpace> getOffsetReferenceSpace(const WebXRRigidTransform&) final;
+    const Vector<Ref<DOMPointReadOnly>>& boundsGeometry();
+    ExceptionOr<Ref<WebXRReferenceSpace>> getOffsetReferenceSpace(const WebXRRigidTransform&) final;
 
 private:
     WebXRBoundedReferenceSpace(Document&, Ref<WebXRSession>&&, Ref<WebXRRigidTransform>&&, XRReferenceSpaceType);
@@ -53,11 +53,18 @@
 
     bool isBoundedReferenceSpace() const final { return true; }
 
+    void updateIfNeeded();
+    float quantize(float);
+
     Vector<Ref<DOMPointReadOnly>> m_boundsGeometry;
+    int m_lastUpdateId { -1 };
 };
 
 } // namespace WebCore
 
-SPECIALIZE_TYPE_TRAITS_WEBXRSPACE(WebXRBoundedReferenceSpace, isBoundedReferenceSpace())
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::WebXRBoundedReferenceSpace)
+    static bool isType(const WebCore::WebXRReferenceSpace& element) { return element.isBoundedReferenceSpace(); }
+    static bool isType(const WebCore::WebXRSpace& element) { return is<WebCore::WebXRReferenceSpace>(element) && isType(downcast<WebCore::WebXRReferenceSpace>(element)); }
+SPECIALIZE_TYPE_TRAITS_END()
 
 #endif // ENABLE(WEBXR)

Modified: trunk/Source/WebCore/Modules/webxr/WebXRBoundedReferenceSpace.idl (273956 => 273957)


--- trunk/Source/WebCore/Modules/webxr/WebXRBoundedReferenceSpace.idl	2021-03-05 10:18:29 UTC (rev 273956)
+++ trunk/Source/WebCore/Modules/webxr/WebXRBoundedReferenceSpace.idl	2021-03-05 10:50:10 UTC (rev 273957)
@@ -27,6 +27,8 @@
     EnabledAtRuntime=WebXR,
     Conditional=WEBXR,
     SecureContext,
+    CustomToJSObject,
+    JSGenerateToNativeObject,
     Exposed=Window,
     InterfaceName=XRBoundedReferenceSpace
 ] interface WebXRBoundedReferenceSpace : WebXRReferenceSpace {

Modified: trunk/Source/WebCore/Modules/webxr/WebXRReferenceSpace.cpp (273956 => 273957)


--- trunk/Source/WebCore/Modules/webxr/WebXRReferenceSpace.cpp	2021-03-05 10:18:29 UTC (rev 273956)
+++ trunk/Source/WebCore/Modules/webxr/WebXRReferenceSpace.cpp	2021-03-05 10:50:10 UTC (rev 273957)
@@ -95,11 +95,11 @@
     return identity;
 }
 
-RefPtr<WebXRReferenceSpace> WebXRReferenceSpace::getOffsetReferenceSpace(const WebXRRigidTransform& offsetTransform)
+ExceptionOr<Ref<WebXRReferenceSpace>> WebXRReferenceSpace::getOffsetReferenceSpace(const WebXRRigidTransform& offsetTransform)
 {
     auto* document = downcast<Document>(scriptExecutionContext());
     if (!document)
-        return nullptr;
+        return Exception { InvalidStateError };
 
     // https://immersive-web.github.io/webxr/#dom-xrreferencespace-getoffsetreferencespace
     // Set offsetSpace’s origin offset to the result of multiplying base’s origin offset by originOffset in the relevant realm of base.

Modified: trunk/Source/WebCore/Modules/webxr/WebXRReferenceSpace.h (273956 => 273957)


--- trunk/Source/WebCore/Modules/webxr/WebXRReferenceSpace.h	2021-03-05 10:18:29 UTC (rev 273956)
+++ trunk/Source/WebCore/Modules/webxr/WebXRReferenceSpace.h	2021-03-05 10:50:10 UTC (rev 273957)
@@ -50,7 +50,7 @@
 
     WebXRSession& session() const final { return m_session.get(); }
     TransformationMatrix nativeOrigin() const override;
-    virtual RefPtr<WebXRReferenceSpace> getOffsetReferenceSpace(const WebXRRigidTransform&);
+    virtual ExceptionOr<Ref<WebXRReferenceSpace>> getOffsetReferenceSpace(const WebXRRigidTransform&);
     XRReferenceSpaceType type() const { return m_type; }
 
 protected:

Modified: trunk/Source/WebCore/Modules/webxr/WebXRReferenceSpace.idl (273956 => 273957)


--- trunk/Source/WebCore/Modules/webxr/WebXRReferenceSpace.idl	2021-03-05 10:18:29 UTC (rev 273956)
+++ trunk/Source/WebCore/Modules/webxr/WebXRReferenceSpace.idl	2021-03-05 10:50:10 UTC (rev 273957)
@@ -28,12 +28,12 @@
     Conditional=WEBXR,
     SecureContext,
     Exposed=Window,
-    JSGenerateToJSObject,
+    CustomToJSObject,
     JSGenerateToNativeObject,
     SkipVTableValidation,
     InterfaceName=XRReferenceSpace
 ] interface WebXRReferenceSpace : WebXRSpace {
-    [NewObject] WebXRReferenceSpace getOffsetReferenceSpace(WebXRRigidTransform originOffset);
+    [NewObject, MayThrowException] WebXRReferenceSpace getOffsetReferenceSpace(WebXRRigidTransform originOffset);
 
     attribute EventHandler onreset;
 };

Modified: trunk/Source/WebCore/Modules/webxr/WebXRSpace.idl (273956 => 273957)


--- trunk/Source/WebCore/Modules/webxr/WebXRSpace.idl	2021-03-05 10:18:29 UTC (rev 273956)
+++ trunk/Source/WebCore/Modules/webxr/WebXRSpace.idl	2021-03-05 10:50:10 UTC (rev 273957)
@@ -26,6 +26,7 @@
 [
     EnabledAtRuntime=WebXR,
     Conditional=WEBXR,
+    CustomToJSObject,
     SecureContext,
     Exposed=Window,
     InterfaceName=XRSpace

Modified: trunk/Source/WebCore/Sources.txt (273956 => 273957)


--- trunk/Source/WebCore/Sources.txt	2021-03-05 10:18:29 UTC (rev 273956)
+++ trunk/Source/WebCore/Sources.txt	2021-03-05 10:50:10 UTC (rev 273957)
@@ -619,6 +619,8 @@
 bindings/js/JSWebAnimationCustom.cpp
 bindings/js/JSWebGL2RenderingContextCustom.cpp
 bindings/js/JSWebGLRenderingContextCustom.cpp
+bindings/js/JSWebXRReferenceSpaceCustom.cpp
+bindings/js/JSWebXRSpaceCustom.cpp
 bindings/js/JSWindowProxy.cpp
 bindings/js/JSWorkerGlobalScopeBase.cpp
 bindings/js/JSWorkerGlobalScopeCustom.cpp

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (273956 => 273957)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2021-03-05 10:18:29 UTC (rev 273956)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2021-03-05 10:50:10 UTC (rev 273957)
@@ -6351,6 +6351,8 @@
 		11CB2786203BA570004A1DC9 /* RenderTreeBuilderFullScreen.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = RenderTreeBuilderFullScreen.cpp; sourceTree = "<group>"; };
 		11CB2787203BA570004A1DC9 /* RenderTreeBuilderFullScreen.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RenderTreeBuilderFullScreen.h; sourceTree = "<group>"; };
 		11D19C2E23159BAE008F24D3 /* TableFormattingContextGeometry.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = TableFormattingContextGeometry.cpp; sourceTree = "<group>"; };
+		11E6CF1B25F140E30013D3D5 /* JSWebXRReferenceSpaceCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSWebXRReferenceSpaceCustom.cpp; sourceTree = "<group>"; };
+		11E6CF1D25F140E40013D3D5 /* JSWebXRSpaceCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSWebXRSpaceCustom.cpp; sourceTree = "<group>"; };
 		11FF02D520BA3C810083F25B /* Verification.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = Verification.cpp; sourceTree = "<group>"; };
 		12F75A9A86EA03DAF24B7971 /* ISOProtectionSystemSpecificHeaderBox.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ISOProtectionSystemSpecificHeaderBox.h; sourceTree = "<group>"; };
 		1400D7A717136EA70077CE05 /* ScriptWrappableInlines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScriptWrappableInlines.h; sourceTree = "<group>"; };
@@ -22879,6 +22881,8 @@
 				715DA5D3201BB902002EF2B0 /* JSWebAnimationCustom.cpp */,
 				D3F3D3591A69A3B00059FC2B /* JSWebGL2RenderingContextCustom.cpp */,
 				49EED14C1051971A00099FAB /* JSWebGLRenderingContextCustom.cpp */,
+				11E6CF1B25F140E30013D3D5 /* JSWebXRReferenceSpaceCustom.cpp */,
+				11E6CF1D25F140E40013D3D5 /* JSWebXRSpaceCustom.cpp */,
 				E18258AB0EF3CD7000933242 /* JSWorkerGlobalScopeCustom.cpp */,
 				46F91BC91FCDD0FE001599C3 /* JSWorkerNavigatorCustom.cpp */,
 				83A4A9F81CE7FD7E00709B00 /* JSXMLDocumentCustom.cpp */,

Added: trunk/Source/WebCore/bindings/js/JSWebXRReferenceSpaceCustom.cpp (0 => 273957)


--- trunk/Source/WebCore/bindings/js/JSWebXRReferenceSpaceCustom.cpp	                        (rev 0)
+++ trunk/Source/WebCore/bindings/js/JSWebXRReferenceSpaceCustom.cpp	2021-03-05 10:50:10 UTC (rev 273957)
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2021 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. ``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
+ * 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"
+
+#if ENABLE(WEBXR)
+#include "JSWebXRReferenceSpace.h"
+
+#include "JSWebXRBoundedReferenceSpace.h"
+#include "WebXRBoundedReferenceSpace.h"
+
+namespace WebCore {
+using namespace JSC;
+
+JSValue toJSNewlyCreated(JSGlobalObject*, JSDOMGlobalObject* globalObject, Ref<WebXRReferenceSpace>&& space)
+{
+    if (space->isBoundedReferenceSpace())
+        return createWrapper<WebXRBoundedReferenceSpace>(globalObject, WTFMove(space));
+    return createWrapper<WebXRReferenceSpace>(globalObject, WTFMove(space));
+}
+
+JSValue toJS(JSGlobalObject* lexicalGlobalObject, JSDOMGlobalObject* globalObject, WebXRReferenceSpace& space)
+{
+    return wrap(lexicalGlobalObject, globalObject, space);
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(WEBXR)

Added: trunk/Source/WebCore/bindings/js/JSWebXRSpaceCustom.cpp (0 => 273957)


--- trunk/Source/WebCore/bindings/js/JSWebXRSpaceCustom.cpp	                        (rev 0)
+++ trunk/Source/WebCore/bindings/js/JSWebXRSpaceCustom.cpp	2021-03-05 10:50:10 UTC (rev 273957)
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2021 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. ``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
+ * 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"
+
+#if ENABLE(WEBXR)
+#include "JSWebXRSpace.h"
+
+#include "WebXRReferenceSpace.h"
+
+namespace WebCore {
+using namespace JSC;
+
+JSValue toJSNewlyCreated(JSGlobalObject* lexicalGlobalObject, JSDOMGlobalObject* globalObject, Ref<WebXRSpace>&& space)
+{
+    if (is<WebXRReferenceSpace>(space))
+        return toJSNewlyCreated(lexicalGlobalObject, globalObject, static_reference_cast<WebXRReferenceSpace>(WTFMove(space)));
+    return createWrapper<WebXRSpace>(globalObject, WTFMove(space));
+}
+
+JSValue toJS(JSGlobalObject* lexicalGlobalObject, JSDOMGlobalObject* globalObject, WebXRSpace& space)
+{
+    return wrap(lexicalGlobalObject, globalObject, space);
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(WEBXR)

Modified: trunk/Source/WebCore/platform/xr/PlatformXR.h (273956 => 273957)


--- trunk/Source/WebCore/platform/xr/PlatformXR.h	2021-03-05 10:18:29 UTC (rev 273956)
+++ trunk/Source/WebCore/platform/xr/PlatformXR.h	2021-03-05 10:50:10 UTC (rev 273957)
@@ -114,6 +114,11 @@
             Projection projection = { nullptr };
         };
 
+        struct StageParameters {
+            int id { 0 };
+            Vector<WebCore::FloatPoint> bounds;
+        };
+
         bool isTrackingValid { false };
         bool isPositionValid { false };
         bool isPositionEmulated { false };
@@ -120,6 +125,7 @@
         long predictedDisplayTime { 0 };
         Pose origin;
         Optional<Pose> floorTransform;
+        StageParameters stageParameters;
         Vector<View> views;
     };
 

Modified: trunk/Source/WebCore/platform/xr/openxr/PlatformXROpenXR.cpp (273956 => 273957)


--- trunk/Source/WebCore/platform/xr/openxr/PlatformXROpenXR.cpp	2021-03-05 10:18:29 UTC (rev 273956)
+++ trunk/Source/WebCore/platform/xr/openxr/PlatformXROpenXR.cpp	2021-03-05 10:50:10 UTC (rev 273957)
@@ -143,6 +143,8 @@
 {
     if ((spaceType == ReferenceSpaceType::LocalFloor || spaceType == ReferenceSpaceType::BoundedFloor) && m_stageSpace == XR_NULL_HANDLE)
         m_stageSpace = createReferenceSpace(XR_REFERENCE_SPACE_TYPE_STAGE);
+    if (spaceType == ReferenceSpaceType::BoundedFloor)
+        updateStageParameters();
 }
 
 void OpenXRDevice::requestFrame(RequestFrameCallback&& callback)
@@ -169,8 +171,8 @@
 
         Device::FrameData frameData;
         frameData.predictedDisplayTime = frameState.predictedDisplayTime;
+        frameData.stageParameters = m_stageParameters;
 
-
         ASSERT(m_configurationViews.contains(m_currentViewConfigurationType));
         const auto& configurationView = m_configurationViews.get(m_currentViewConfigurationType);
 
@@ -256,8 +258,9 @@
     // The spec uses a estimated height if we don't provide a floor transform in frameData.
     features.append(ReferenceSpaceType::LocalFloor);
 
-    // FIXME: Enable BoundedFloor when we implement xrGetReferenceSpaceBoundsRect and the related bits in the DOM.
-    // enabledFeatures.append(ReferenceSpaceType::BoundedFloor);
+    // Mark BoundedFloor as supported regardless if XR_REFERENCE_SPACE_TYPE_STAGE is available.
+    // The spec allows reporting an empty array if xrGetReferenceSpaceBoundsRect fails.
+    features.append(ReferenceSpaceType::BoundedFloor);
 
     if (m_extensions.isExtensionSupported(XR_MSFT_UNBOUNDED_REFERENCE_SPACE_EXTENSION_NAME))
         features.append(ReferenceSpaceType::Unbounded);
@@ -354,7 +357,7 @@
     while (xrPollEvent(m_instance, &runtimeEvent) == XR_SUCCESS) {
         switch (runtimeEvent.type) {
         case XR_TYPE_EVENT_DATA_SESSION_STATE_CHANGED: {
-            auto* event = (XrEventDataSessionStateChanged*)&runtimeEvent;
+            auto* event = reinterpret_cast<XrEventDataSessionStateChanged*>(&runtimeEvent);
             m_sessionState = event->state;
             handleSessionStateChange();
             break;
@@ -361,7 +364,12 @@
         }
         case XR_TYPE_EVENT_DATA_EVENTS_LOST:
         case XR_TYPE_EVENT_DATA_INSTANCE_LOSS_PENDING:
-        case XR_TYPE_EVENT_DATA_REFERENCE_SPACE_CHANGE_PENDING:
+        case XR_TYPE_EVENT_DATA_REFERENCE_SPACE_CHANGE_PENDING: {
+            auto* event = reinterpret_cast<XrEventDataReferenceSpaceChangePending*>(&runtimeEvent);
+            if (event->referenceSpaceType == XR_REFERENCE_SPACE_TYPE_STAGE)
+                updateStageParameters();
+            break;
+        }
         case XR_TYPE_EVENT_DATA_INTERACTION_PROFILE_CHANGED:
         case XR_TYPE_EVENT_DATA_MAIN_SESSION_VISIBILITY_CHANGED_EXTX:
         case XR_TYPE_EVENT_DATA_VISIBILITY_MASK_CHANGED_KHR:
@@ -413,6 +421,10 @@
         m_session = XR_NULL_HANDLE;
     }
     m_sessionState = XR_SESSION_STATE_UNKNOWN;
+    m_localSpace = XR_NULL_HANDLE;
+    m_viewSpace  = XR_NULL_HANDLE;
+    m_stageSpace = XR_NULL_HANDLE;
+    m_stageParameters = { };
 
     // deallocate graphic resources
     m_egl.reset();
@@ -430,7 +442,6 @@
     }
 }
 
-
 void OpenXRDevice::waitUntilStopping()
 {
     ASSERT(&RunLoop::current() == &m_queue.runLoop());
@@ -442,6 +453,32 @@
     });
 }
 
+void OpenXRDevice::updateStageParameters()
+{
+    ASSERT(&RunLoop::current() == &m_queue.runLoop());
+    if (m_stageSpace == XR_NULL_HANDLE)
+        return; // Stage space not requested.
+
+    m_stageParameters.id++;
+
+    XrExtent2Df bounds;
+    if (XR_SUCCEEDED(xrGetReferenceSpaceBoundsRect(m_session, XR_REFERENCE_SPACE_TYPE_STAGE, &bounds))) {
+        // https://immersive-web.github.io/webxr/#xrboundedreferencespace-native-bounds-geometry
+        // Points MUST be given in a clockwise order as viewed from above, looking towards the negative end of the Y axis.
+        m_stageParameters.bounds = Vector<WebCore::FloatPoint> {
+            { bounds.width * 0.5f, -bounds.height * 0.5f },
+            { bounds.width * 0.5f, bounds.height * 0.5f },
+            { -bounds.width * 0.5f, bounds.height * 0.5f },
+            { -bounds.width * 0.5f, -bounds.height * 0.5f }
+        };
+    } else {
+        // https://immersive-web.github.io/webxr/#dom-xrboundedreferencespace-boundsgeometry
+        // If the native bounds geometry is temporarily unavailable, which may occur for several reasons such as during XR device initialization,
+        // extended periods of tracking loss, or movement between pre-configured spaces, the boundsGeometry MUST report an empty array.
+        m_stageParameters.bounds.clear();
+    }
+}
+
 } // namespace PlatformXR
 
 #endif // ENABLE(WEBXR) && USE(OPENXR)

Modified: trunk/Source/WebCore/platform/xr/openxr/PlatformXROpenXR.h (273956 => 273957)


--- trunk/Source/WebCore/platform/xr/openxr/PlatformXROpenXR.h	2021-03-05 10:18:29 UTC (rev 273956)
+++ trunk/Source/WebCore/platform/xr/openxr/PlatformXROpenXR.h	2021-03-05 10:50:10 UTC (rev 273957)
@@ -69,6 +69,7 @@
     void resetSession();
     void handleSessionStateChange();
     void waitUntilStopping();
+    void updateStageParameters();
 
     XrInstance m_instance;
     XrSystemId m_systemId;
@@ -87,6 +88,7 @@
     XrSpace m_localSpace { XR_NULL_HANDLE };
     XrSpace m_viewSpace { XR_NULL_HANDLE };
     XrSpace m_stageSpace { XR_NULL_HANDLE };
+    Device::FrameData::StageParameters m_stageParameters;
 };
 
 } // namespace PlatformXR

Modified: trunk/Source/WebCore/testing/WebFakeXRDevice.cpp (273956 => 273957)


--- trunk/Source/WebCore/testing/WebFakeXRDevice.cpp	2021-03-05 10:18:29 UTC (rev 273956)
+++ trunk/Source/WebCore/testing/WebFakeXRDevice.cpp	2021-03-05 10:50:10 UTC (rev 273957)
@@ -59,6 +59,14 @@
     stopTimer();
 }
 
+void SimulatedXRDevice::setNativeBoundsGeometry(const Vector<FakeXRBoundsPoint>& geometry)
+{
+    m_stageParameters.id++;
+    m_stageParameters.bounds.clear();
+    for (auto& point : geometry)
+        m_stageParameters.bounds.append({ static_cast<float>(point.x), static_cast<float>(point.z) });
+}
+
 void SimulatedXRDevice::simulateShutdownCompleted()
 {
     if (m_trackingAndRenderingClient)
@@ -100,6 +108,8 @@
     if (m_floorOrigin)
         data.floorTransform = { *m_floorOrigin };
 
+    data.stageParameters = m_stageParameters;
+
     for (auto& fakeView : m_views) {
         FrameData::View view;
         view.offset = fakeView->offset();
@@ -182,9 +192,12 @@
 {
 }
 
-void WebFakeXRDevice::setBoundsGeometry(Vector<FakeXRBoundsPoint>&&)
+void WebFakeXRDevice::setBoundsGeometry(Vector<FakeXRBoundsPoint>&& bounds)
 {
-}
+    m_device.scheduleOnNextFrame([this, bounds = WTFMove(bounds)]() {
+        m_device.setNativeBoundsGeometry(bounds);
+    });
+} 
 
 void WebFakeXRDevice::setFloorOrigin(FakeXRRigidTransformInit origin)
 {

Modified: trunk/Source/WebCore/testing/WebFakeXRDevice.h (273956 => 273957)


--- trunk/Source/WebCore/testing/WebFakeXRDevice.h	2021-03-05 10:18:29 UTC (rev 273956)
+++ trunk/Source/WebCore/testing/WebFakeXRDevice.h	2021-03-05 10:50:10 UTC (rev 273957)
@@ -71,7 +71,7 @@
     SimulatedXRDevice();
     ~SimulatedXRDevice();
     void setViews(Vector<Ref<FakeXRView>>&& views) { m_views = WTFMove(views); }
-    void setNativeBoundsGeometry(const Vector<FakeXRBoundsPoint>& geometry) { m_nativeBoundsGeometry = geometry; }
+    void setNativeBoundsGeometry(const Vector<FakeXRBoundsPoint>&);
     void setViewerOrigin(Optional<FrameData::Pose>&& origin) { m_viewerOrigin = WTFMove(origin); }
     void setFloorOrigin(Optional<FrameData::Pose>&& origin) { m_floorOrigin = WTFMove(origin); }
     void setEmulatedPosition(bool emulated) { m_emulatedPosition = emulated; }
@@ -100,6 +100,7 @@
     Timer m_frameTimer;
     RequestFrameCallback m_FrameCallback;
     Vector<Function<void()>> m_pendingUpdates;
+    FrameData::StageParameters m_stageParameters;
 };
 
 class WebFakeXRDevice final : public RefCounted<WebFakeXRDevice> {
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to