Changeset 263503 in webkit


Ignore:
Timestamp:
Jun 25, 2020 3:49:42 AM (4 years ago)
Author:
svillar@igalia.com
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.
Location:
trunk/Source/WebCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r263500 r263503  
     12020-06-23  Sergio Villar Senin  <svillar@igalia.com>
     2
     3        [WebXR] Check device orientation support when requesting a reference space
     4        https://bugs.webkit.org/show_bug.cgi?id=213519
     5
     6        Reviewed by Carlos Garcia Campos.
     7
     8        When requesting a local reference space the specs mandate us to check whether or not the device
     9        supports orientation tracking. This was not implemented in the OpenXR backend, so we were unconditionally
     10        returning true.
     11
     12        The OpenXR devices now properly check whether or not orientation tracking is initialized. We took the chance
     13        to refactor a bit the OpenXR backend moving all the device initialization code to the OpenXRDevice class.
     14
     15        The current tests already check this functionality.
     16
     17        * Modules/webxr/WebXRSession.cpp:
     18        (WebCore::WebXRSession::referenceSpaceIsSupported const): Call supportsOrientationTracking() on device.
     19        * platform/xr/PlatformXR.h:
     20        (PlatformXR::Device::supportsOrientationTracking const): Added.
     21        * platform/xr/openxr/PlatformXROpenXR.cpp:
     22        (PlatformXR::Instance::enumerateImmersiveXRDevices): Just create the OpenXR device, it will automatically
     23        initialize itself.
     24        (PlatformXR::OpenXRDevice::OpenXRDevice): Get XrSystem and XrInstance as parametters.
     25        (PlatformXR::OpenXRDevice::collectSupportedSessionModes): Moved from Instance::Impl.
     26        (PlatformXR::Instance::Impl::collectSupportedSessionModes): Deleted.
     27        * platform/xr/openxr/PlatformXROpenXR.h:
     28        * testing/WebFakeXRDevice.h: Mark the SimulatedXRDevice as supporting orientation tracking.
     29
    1302020-06-24  James Savage  <james.savage@apple.com>
    231
  • trunk/Source/WebCore/Modules/webxr/WebXRSession.cpp

    r263256 r263503  
    109109
    110110        // 4. If type is local or local-floor, and the XR device supports reporting orientation data, return true.
    111         // TODO: add API to PlatformXR::Device
    112         return true;
    113     }
    114 
     111        if (m_device->supportsOrientationTracking())
     112            return true;
     113    }
    115114
    116115    // 5. If type is bounded-floor and session is an immersive session, return the result of whether bounded
  • trunk/Source/WebCore/platform/xr/PlatformXR.h

    r263447 r263503  
    5454    ListOfEnabledFeatures enabledFeatures(SessionMode mode) const { return m_enabledFeaturesMap.get(mode); }
    5555
     56    bool supportsOrientationTracking() const { return m_supportsOrientationTracking; }
     57
    5658protected:
    5759    Device() = default;
     
    6264    using EnabledFeaturesPerModeMap = WTF::HashMap<SessionMode, ListOfEnabledFeatures, WTF::IntHash<SessionMode>, WTF::StrongEnumHashTraits<SessionMode>>;
    6365    EnabledFeaturesPerModeMap m_enabledFeaturesMap;
     66
     67    bool m_supportsOrientationTracking { false };
    6468};
    6569
  • trunk/Source/WebCore/platform/xr/openxr/PlatformXROpenXR.cpp

    r263447 r263503  
    169169#if USE_OPENXR
    170170
    171 Optional<Vector<SessionMode>> Instance::Impl::collectSupportedSessionModes(OpenXRDevice& device)
    172 {
    173     uint32_t viewConfigurationCount;
    174     auto result = xrEnumerateViewConfigurations(m_instance, device.xrSystemId(), 0, &viewConfigurationCount, nullptr);
    175     if (result != XR_SUCCESS) {
    176         LOG(XR, "xrEnumerateViewConfigurations(): error %s\n", resultToString(result, m_instance).utf8().data());
    177         return WTF::nullopt;
    178     }
    179 
    180     XrViewConfigurationType viewConfigurations[viewConfigurationCount];
    181     result = xrEnumerateViewConfigurations(m_instance, device.xrSystemId(), viewConfigurationCount, &viewConfigurationCount, viewConfigurations);
    182     if (result != XR_SUCCESS) {
    183         LOG(XR, "xrEnumerateViewConfigurations(): error %s\n", resultToString(result, m_instance).utf8().data());
    184         return WTF::nullopt;
    185     }
    186 
    187     Vector<SessionMode> supportedModes;
    188     for (uint32_t i = 0; i < viewConfigurationCount; ++i) {
    189         auto viewConfigurationProperties = createStructure<XrViewConfigurationProperties, XR_TYPE_VIEW_CONFIGURATION_PROPERTIES>();
    190         result = xrGetViewConfigurationProperties(m_instance, device.xrSystemId(), viewConfigurations[i], &viewConfigurationProperties);
    191         if (result != XR_SUCCESS) {
    192             LOG(XR, "xrGetViewConfigurationProperties(): error %s\n", resultToString(result, m_instance).utf8().data());
    193             return WTF::nullopt;
    194         }
    195         switch (viewConfigurationProperties.viewConfigurationType) {
    196             case XR_VIEW_CONFIGURATION_TYPE_PRIMARY_MONO:
    197                 supportedModes.append(SessionMode::ImmersiveAr);
    198                 break;
    199             case XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO:
    200                 supportedModes.append(SessionMode::ImmersiveVr);
    201                 break;
    202             default:
    203                 break;
    204         };
    205     }
    206     return supportedModes;
    207 }
    208 
    209171#endif // USE_OPENXR
    210172
     
    238200    XrSystemId systemId;
    239201    XrResult result = xrGetSystem(m_impl->xrInstance(), &systemGetInfo, &systemId);
    240     if (result != XR_SUCCESS) {
    241         LOG(XR, "xrGetSystem(): error %s\n", resultToString(result, m_impl->xrInstance()).utf8().data());
    242         return;
    243     }
    244 
    245     auto device = makeUnique<OpenXRDevice>();
    246     device->setXrSystemId(systemId);
    247     auto sessionModes = m_impl->collectSupportedSessionModes(*device);
    248     if (sessionModes) {
    249         for (auto& mode : sessionModes.value()) {
    250             // TODO: fill in features
    251             device->setEnabledFeatures(mode, { });
     202    RETURN_IF_FAILED(result, "xrGetSystem", m_impl->xrInstance());
     203
     204    m_immersiveXRDevices.append(makeUnique<OpenXRDevice>(systemId, m_impl->xrInstance()));
     205#endif // USE_OPENXR
     206}
     207
     208OpenXRDevice::OpenXRDevice(XrSystemId id, XrInstance instance)
     209    : m_systemId(id)
     210    , m_instance(instance)
     211{
     212    auto systemProperties = createStructure<XrSystemProperties, XR_TYPE_SYSTEM_PROPERTIES>();
     213    XrResult result = xrGetSystemProperties(instance, m_systemId, &systemProperties);
     214    if (result == XR_SUCCESS)
     215        m_supportsOrientationTracking = systemProperties.trackingProperties.orientationTracking == XR_TRUE;
     216    else
     217        LOG(XR, "xrGetSystemProperties(): error %s\n", resultToString(result, m_impl->xrInstance()).utf8().data());
     218
     219    collectSupportedSessionModes();
     220}
     221
     222void OpenXRDevice::collectSupportedSessionModes()
     223{
     224    uint32_t viewConfigurationCount;
     225    auto result = xrEnumerateViewConfigurations(m_instance, m_systemId, 0, &viewConfigurationCount, nullptr);
     226    RETURN_IF_FAILED(result, "xrEnumerateViewConfigurations", m_instance);
     227
     228    XrViewConfigurationType viewConfigurations[viewConfigurationCount];
     229    result = xrEnumerateViewConfigurations(m_instance, m_systemId, viewConfigurationCount, &viewConfigurationCount, viewConfigurations);
     230    RETURN_IF_FAILED(result, "xrEnumerateViewConfigurations", m_instance);
     231
     232    for (uint32_t i = 0; i < viewConfigurationCount; ++i) {
     233        auto viewConfigurationProperties = createStructure<XrViewConfigurationProperties, XR_TYPE_VIEW_CONFIGURATION_PROPERTIES>();
     234        result = xrGetViewConfigurationProperties(m_instance, m_systemId, viewConfigurations[i], &viewConfigurationProperties);
     235        if (result != XR_SUCCESS) {
     236            LOG(XR, "xrGetViewConfigurationProperties(): error %s\n", resultToString(result, m_instance).utf8().data());
     237            continue;
    252238        }
    253     }
    254 
    255     m_immersiveXRDevices.append(WTFMove(device));
    256 #endif // USE_OPENXR
     239        switch (viewConfigurationProperties.viewConfigurationType) {
     240        case XR_VIEW_CONFIGURATION_TYPE_PRIMARY_MONO:
     241            setEnabledFeatures(SessionMode::ImmersiveAr, { });
     242            break;
     243        case XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO:
     244            setEnabledFeatures(SessionMode::ImmersiveVr, { });
     245            break;
     246        default:
     247            break;
     248        };
     249    }
    257250}
    258251
  • trunk/Source/WebCore/platform/xr/openxr/PlatformXROpenXR.h

    r262838 r263503  
    4242class OpenXRDevice final : public Device {
    4343public:
    44     void setXrSystemId(XrSystemId id) { m_systemId = id; }
     44    OpenXRDevice(XrSystemId, XrInstance);
    4545    XrSystemId xrSystemId() const { return m_systemId; }
    4646private:
     47    void collectSupportedSessionModes();
     48
    4749    XrSystemId m_systemId;
     50    XrInstance m_instance;
    4851};
    4952
  • trunk/Source/WebCore/testing/WebFakeXRDevice.h

    r262188 r263503  
    6464    WTF_MAKE_FAST_ALLOCATED;
    6565public:
     66    SimulatedXRDevice() { m_supportsOrientationTracking = true; }
    6667    void setNativeBoundsGeometry(Vector<FakeXRBoundsPoint> geometry) { m_nativeBoundsGeometry = geometry; }
    6768    void setViewerOrigin(RefPtr<WebXRRigidTransform>&& origin) { m_viewerOrigin = WTFMove(origin); }
Note: See TracChangeset for help on using the changeset viewer.