Title: [263503] trunk/Source/WebCore
Revision
263503
Author
[email protected]
Date
2020-06-25 03:49:42 -0700 (Thu, 25 Jun 2020)

Log Message

[WebXR] Check device orientation support when requesting a reference space
https://bugs.webkit.org/show_bug.cgi?id=213519

Reviewed by Carlos Garcia Campos.

When requesting a local reference space the specs mandate us to check whether or not the device
supports orientation tracking. This was not implemented in the OpenXR backend, so we were unconditionally
returning true.

The OpenXR devices now properly check whether or not orientation tracking is initialized. We took the chance
to refactor a bit the OpenXR backend moving all the device initialization code to the OpenXRDevice class.

The current tests already check this functionality.

* Modules/webxr/WebXRSession.cpp:
(WebCore::WebXRSession::referenceSpaceIsSupported const): Call supportsOrientationTracking() on device.
* platform/xr/PlatformXR.h:
(PlatformXR::Device::supportsOrientationTracking const): Added.
* platform/xr/openxr/PlatformXROpenXR.cpp:
(PlatformXR::Instance::enumerateImmersiveXRDevices): Just create the OpenXR device, it will automatically
initialize itself.
(PlatformXR::OpenXRDevice::OpenXRDevice): Get XrSystem and XrInstance as parametters.
(PlatformXR::OpenXRDevice::collectSupportedSessionModes): Moved from Instance::Impl.
(PlatformXR::Instance::Impl::collectSupportedSessionModes): Deleted.
* platform/xr/openxr/PlatformXROpenXR.h:
* testing/WebFakeXRDevice.h: Mark the SimulatedXRDevice as supporting orientation tracking.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (263502 => 263503)


--- trunk/Source/WebCore/ChangeLog	2020-06-25 10:16:43 UTC (rev 263502)
+++ trunk/Source/WebCore/ChangeLog	2020-06-25 10:49:42 UTC (rev 263503)
@@ -1,3 +1,32 @@
+2020-06-23  Sergio Villar Senin  <[email protected]>
+
+        [WebXR] Check device orientation support when requesting a reference space
+        https://bugs.webkit.org/show_bug.cgi?id=213519
+
+        Reviewed by Carlos Garcia Campos.
+
+        When requesting a local reference space the specs mandate us to check whether or not the device
+        supports orientation tracking. This was not implemented in the OpenXR backend, so we were unconditionally
+        returning true.
+
+        The OpenXR devices now properly check whether or not orientation tracking is initialized. We took the chance
+        to refactor a bit the OpenXR backend moving all the device initialization code to the OpenXRDevice class.
+
+        The current tests already check this functionality.
+
+        * Modules/webxr/WebXRSession.cpp:
+        (WebCore::WebXRSession::referenceSpaceIsSupported const): Call supportsOrientationTracking() on device.
+        * platform/xr/PlatformXR.h:
+        (PlatformXR::Device::supportsOrientationTracking const): Added.
+        * platform/xr/openxr/PlatformXROpenXR.cpp:
+        (PlatformXR::Instance::enumerateImmersiveXRDevices): Just create the OpenXR device, it will automatically
+        initialize itself.
+        (PlatformXR::OpenXRDevice::OpenXRDevice): Get XrSystem and XrInstance as parametters.
+        (PlatformXR::OpenXRDevice::collectSupportedSessionModes): Moved from Instance::Impl.
+        (PlatformXR::Instance::Impl::collectSupportedSessionModes): Deleted.
+        * platform/xr/openxr/PlatformXROpenXR.h:
+        * testing/WebFakeXRDevice.h: Mark the SimulatedXRDevice as supporting orientation tracking.
+
 2020-06-24  James Savage  <[email protected]>
 
         Upstream iPadOS 13.0 multi-window support

Modified: trunk/Source/WebCore/Modules/webxr/WebXRSession.cpp (263502 => 263503)


--- trunk/Source/WebCore/Modules/webxr/WebXRSession.cpp	2020-06-25 10:16:43 UTC (rev 263502)
+++ trunk/Source/WebCore/Modules/webxr/WebXRSession.cpp	2020-06-25 10:49:42 UTC (rev 263503)
@@ -108,11 +108,10 @@
             return true;
 
         // 4. If type is local or local-floor, and the XR device supports reporting orientation data, return true.
-        // TODO: add API to PlatformXR::Device
-        return true;
+        if (m_device->supportsOrientationTracking())
+            return true;
     }
 
-
     // 5. If type is bounded-floor and session is an immersive session, return the result of whether bounded
     //    reference spaces are supported by the XR device.
     // https://immersive-web.github.io/webxr/#bounded-reference-spaces-are-supported

Modified: trunk/Source/WebCore/platform/xr/PlatformXR.h (263502 => 263503)


--- trunk/Source/WebCore/platform/xr/PlatformXR.h	2020-06-25 10:16:43 UTC (rev 263502)
+++ trunk/Source/WebCore/platform/xr/PlatformXR.h	2020-06-25 10:49:42 UTC (rev 263503)
@@ -53,6 +53,8 @@
     void setEnabledFeatures(SessionMode mode, const ListOfEnabledFeatures& features) { m_enabledFeaturesMap.set(mode, features); }
     ListOfEnabledFeatures enabledFeatures(SessionMode mode) const { return m_enabledFeaturesMap.get(mode); }
 
+    bool supportsOrientationTracking() const { return m_supportsOrientationTracking; }
+
 protected:
     Device() = default;
 
@@ -61,6 +63,8 @@
     // which is a list of feature descriptors which MUST be initially an empty list.
     using EnabledFeaturesPerModeMap = WTF::HashMap<SessionMode, ListOfEnabledFeatures, WTF::IntHash<SessionMode>, WTF::StrongEnumHashTraits<SessionMode>>;
     EnabledFeaturesPerModeMap m_enabledFeaturesMap;
+
+    bool m_supportsOrientationTracking { false };
 };
 
 class Instance {

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


--- trunk/Source/WebCore/platform/xr/openxr/PlatformXROpenXR.cpp	2020-06-25 10:16:43 UTC (rev 263502)
+++ trunk/Source/WebCore/platform/xr/openxr/PlatformXROpenXR.cpp	2020-06-25 10:49:42 UTC (rev 263503)
@@ -168,44 +168,6 @@
 
 #if USE_OPENXR
 
-Optional<Vector<SessionMode>> Instance::Impl::collectSupportedSessionModes(OpenXRDevice& device)
-{
-    uint32_t viewConfigurationCount;
-    auto result = xrEnumerateViewConfigurations(m_instance, device.xrSystemId(), 0, &viewConfigurationCount, nullptr);
-    if (result != XR_SUCCESS) {
-        LOG(XR, "xrEnumerateViewConfigurations(): error %s\n", resultToString(result, m_instance).utf8().data());
-        return WTF::nullopt;
-    }
-
-    XrViewConfigurationType viewConfigurations[viewConfigurationCount];
-    result = xrEnumerateViewConfigurations(m_instance, device.xrSystemId(), viewConfigurationCount, &viewConfigurationCount, viewConfigurations);
-    if (result != XR_SUCCESS) {
-        LOG(XR, "xrEnumerateViewConfigurations(): error %s\n", resultToString(result, m_instance).utf8().data());
-        return WTF::nullopt;
-    }
-
-    Vector<SessionMode> supportedModes;
-    for (uint32_t i = 0; i < viewConfigurationCount; ++i) {
-        auto viewConfigurationProperties = createStructure<XrViewConfigurationProperties, XR_TYPE_VIEW_CONFIGURATION_PROPERTIES>();
-        result = xrGetViewConfigurationProperties(m_instance, device.xrSystemId(), viewConfigurations[i], &viewConfigurationProperties);
-        if (result != XR_SUCCESS) {
-            LOG(XR, "xrGetViewConfigurationProperties(): error %s\n", resultToString(result, m_instance).utf8().data());
-            return WTF::nullopt;
-        }
-        switch (viewConfigurationProperties.viewConfigurationType) {
-            case XR_VIEW_CONFIGURATION_TYPE_PRIMARY_MONO:
-                supportedModes.append(SessionMode::ImmersiveAr);
-                break;
-            case XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO:
-                supportedModes.append(SessionMode::ImmersiveVr);
-                break;
-            default:
-                break;
-        };
-    }
-    return supportedModes;
-}
-
 #endif // USE_OPENXR
 
 Instance& Instance::singleton()
@@ -237,23 +199,54 @@
 
     XrSystemId systemId;
     XrResult result = xrGetSystem(m_impl->xrInstance(), &systemGetInfo, &systemId);
-    if (result != XR_SUCCESS) {
-        LOG(XR, "xrGetSystem(): error %s\n", resultToString(result, m_impl->xrInstance()).utf8().data());
-        return;
-    }
+    RETURN_IF_FAILED(result, "xrGetSystem", m_impl->xrInstance());
 
-    auto device = makeUnique<OpenXRDevice>();
-    device->setXrSystemId(systemId);
-    auto sessionModes = m_impl->collectSupportedSessionModes(*device);
-    if (sessionModes) {
-        for (auto& mode : sessionModes.value()) {
-            // TODO: fill in features
-            device->setEnabledFeatures(mode, { });
+    m_immersiveXRDevices.append(makeUnique<OpenXRDevice>(systemId, m_impl->xrInstance()));
+#endif // USE_OPENXR
+}
+
+OpenXRDevice::OpenXRDevice(XrSystemId id, XrInstance instance)
+    : m_systemId(id)
+    , m_instance(instance)
+{
+    auto systemProperties = createStructure<XrSystemProperties, XR_TYPE_SYSTEM_PROPERTIES>();
+    XrResult result = xrGetSystemProperties(instance, m_systemId, &systemProperties);
+    if (result == XR_SUCCESS)
+        m_supportsOrientationTracking = systemProperties.trackingProperties.orientationTracking == XR_TRUE;
+    else
+        LOG(XR, "xrGetSystemProperties(): error %s\n", resultToString(result, m_impl->xrInstance()).utf8().data());
+
+    collectSupportedSessionModes();
+}
+
+void OpenXRDevice::collectSupportedSessionModes()
+{
+    uint32_t viewConfigurationCount;
+    auto result = xrEnumerateViewConfigurations(m_instance, m_systemId, 0, &viewConfigurationCount, nullptr);
+    RETURN_IF_FAILED(result, "xrEnumerateViewConfigurations", m_instance);
+
+    XrViewConfigurationType viewConfigurations[viewConfigurationCount];
+    result = xrEnumerateViewConfigurations(m_instance, m_systemId, viewConfigurationCount, &viewConfigurationCount, viewConfigurations);
+    RETURN_IF_FAILED(result, "xrEnumerateViewConfigurations", m_instance);
+
+    for (uint32_t i = 0; i < viewConfigurationCount; ++i) {
+        auto viewConfigurationProperties = createStructure<XrViewConfigurationProperties, XR_TYPE_VIEW_CONFIGURATION_PROPERTIES>();
+        result = xrGetViewConfigurationProperties(m_instance, m_systemId, viewConfigurations[i], &viewConfigurationProperties);
+        if (result != XR_SUCCESS) {
+            LOG(XR, "xrGetViewConfigurationProperties(): error %s\n", resultToString(result, m_instance).utf8().data());
+            continue;
         }
+        switch (viewConfigurationProperties.viewConfigurationType) {
+        case XR_VIEW_CONFIGURATION_TYPE_PRIMARY_MONO:
+            setEnabledFeatures(SessionMode::ImmersiveAr, { });
+            break;
+        case XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO:
+            setEnabledFeatures(SessionMode::ImmersiveVr, { });
+            break;
+        default:
+            break;
+        };
     }
-
-    m_immersiveXRDevices.append(WTFMove(device));
-#endif // USE_OPENXR
 }
 
 } // namespace PlatformXR

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


--- trunk/Source/WebCore/platform/xr/openxr/PlatformXROpenXR.h	2020-06-25 10:16:43 UTC (rev 263502)
+++ trunk/Source/WebCore/platform/xr/openxr/PlatformXROpenXR.h	2020-06-25 10:49:42 UTC (rev 263503)
@@ -41,10 +41,13 @@
 // the XRSystem is basically the entry point for the WebXR API available via the Navigator object.
 class OpenXRDevice final : public Device {
 public:
-    void setXrSystemId(XrSystemId id) { m_systemId = id; }
+    OpenXRDevice(XrSystemId, XrInstance);
     XrSystemId xrSystemId() const { return m_systemId; }
 private:
+    void collectSupportedSessionModes();
+
     XrSystemId m_systemId;
+    XrInstance m_instance;
 };
 
 } // namespace PlatformXR

Modified: trunk/Source/WebCore/testing/WebFakeXRDevice.h (263502 => 263503)


--- trunk/Source/WebCore/testing/WebFakeXRDevice.h	2020-06-25 10:16:43 UTC (rev 263502)
+++ trunk/Source/WebCore/testing/WebFakeXRDevice.h	2020-06-25 10:49:42 UTC (rev 263503)
@@ -63,6 +63,7 @@
 class SimulatedXRDevice final : public PlatformXR::Device {
     WTF_MAKE_FAST_ALLOCATED;
 public:
+    SimulatedXRDevice() { m_supportsOrientationTracking = true; }
     void setNativeBoundsGeometry(Vector<FakeXRBoundsPoint> geometry) { m_nativeBoundsGeometry = geometry; }
     void setViewerOrigin(RefPtr<WebXRRigidTransform>&& origin) { m_viewerOrigin = WTFMove(origin); }
     void setFloorOrigin(RefPtr<WebXRRigidTransform>&& origin) { m_floorOrigin = WTFMove(origin); }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to