Changeset 271288 in webkit


Ignore:
Timestamp:
Jan 8, 2021 1:59:25 AM (3 years ago)
Author:
svillar@igalia.com
Message:

[WebXR] Initial implemention of device initialization/shutdown with OpenXR
https://bugs.webkit.org/show_bug.cgi?id=216925

Reviewed by Darin Adler.

Added a very basic initialization and shutdown processes of XR devices using OpenXR. So far we're just creating and destroying
the XR session. Follow up patches will add the required machinery to get frame data from OpenXR.

  • Modules/webxr/WebXRSession.cpp:

(WebCore::WebXRSession::WebXRSession): Call initializeTrackingAndRendering().
(WebCore::WebXRSession::~WebXRSession): Call shutdownTrackingAndRendering().
(WebCore::WebXRSession::shutdown): Ditto.

  • Modules/webxr/WebXRSystem.h:
  • platform/xr/PlatformXR.h: New virtual methods to initialize/shutdown devices.
  • platform/xr/openxr/PlatformXROpenXR.cpp:

(PlatformXR::OpenXRDevice::OpenXRDevice): Initialize m_session.
(PlatformXR::OpenXRDevice::~OpenXRDevice): Call shutdownTrackingAndRendering().
(PlatformXR::toXrViewConfigurationType): New method. Translates from SessionMode to XrViewConfigurationType.
(PlatformXR::OpenXRDevice::initializeTrackingAndRendering): New method. Creates a session with a given mode.
(PlatformXR::OpenXRDevice::resetSession): Destroys session.
(PlatformXR::OpenXRDevice::shutdownTrackingAndRendering):

  • platform/xr/openxr/PlatformXROpenXR.h:
  • testing/WebFakeXRDevice.h: Added empty implementations for the new virtual methods.
Location:
trunk/Source/WebCore
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r271284 r271288  
     12020-09-24  Sergio Villar Senin  <svillar@igalia.com>
     2
     3        [WebXR] Initial implemention of device initialization/shutdown with OpenXR
     4        https://bugs.webkit.org/show_bug.cgi?id=216925
     5
     6        Reviewed by Darin Adler.
     7
     8        Added a very basic initialization and shutdown processes of XR devices using OpenXR. So far we're just creating and destroying
     9        the XR session. Follow up patches will add the required machinery to get frame data from OpenXR.
     10
     11        * Modules/webxr/WebXRSession.cpp:
     12        (WebCore::WebXRSession::WebXRSession): Call initializeTrackingAndRendering().
     13        (WebCore::WebXRSession::~WebXRSession): Call shutdownTrackingAndRendering().
     14        (WebCore::WebXRSession::shutdown): Ditto.
     15        * Modules/webxr/WebXRSystem.h:
     16        * platform/xr/PlatformXR.h: New virtual methods to initialize/shutdown devices.
     17        * platform/xr/openxr/PlatformXROpenXR.cpp:
     18        (PlatformXR::OpenXRDevice::OpenXRDevice): Initialize m_session.
     19        (PlatformXR::OpenXRDevice::~OpenXRDevice): Call shutdownTrackingAndRendering().
     20        (PlatformXR::toXrViewConfigurationType): New method. Translates from SessionMode to XrViewConfigurationType.
     21        (PlatformXR::OpenXRDevice::initializeTrackingAndRendering): New method. Creates a session with a given mode.
     22        (PlatformXR::OpenXRDevice::resetSession): Destroys session.
     23        (PlatformXR::OpenXRDevice::shutdownTrackingAndRendering):
     24        * platform/xr/openxr/PlatformXROpenXR.h:
     25        * testing/WebFakeXRDevice.h: Added empty implementations for the new virtual methods.
     26
    1272021-01-07  Zalan Bujtas  <zalan@apple.com>
    228
  • trunk/Source/WebCore/Modules/webxr/WebXRSession.cpp

    r266782 r271288  
    5858    , m_animationTimer(*this, &WebXRSession::animationTimerFired)
    5959{
    60     // FIXME: If no other features of the user agent have done so already, perform the necessary platform-specific steps to
    61     // initialize the device's tracking and rendering capabilities, including showing any necessary instructions to the user.
     60    m_device->initializeTrackingAndRendering(mode);
     61
    6262    suspendIfNeeded();
    6363}
    6464
    65 WebXRSession::~WebXRSession() = default;
     65WebXRSession::~WebXRSession()
     66{
     67    if (!m_ended && m_device)
     68        m_device->shutDownTrackingAndRendering();
     69}
    6670
    6771XREnvironmentBlendMode WebXRSession::environmentBlendMode() const
     
    330334    //  6.2. Deallocating any graphics resources acquired by session for presentation to the XR device.
    331335    //  6.3. Putting the XR device in a state such that a different source may be able to initiate a session with the same device if session is an immersive session.
     336    if (m_device)
     337        m_device->shutDownTrackingAndRendering();
     338
    332339    // 7. Queue a task that fires an XRSessionEvent named end on session.
    333340    auto event = XRSessionEvent::create(eventNames().endEvent, { makeRefPtr(*this) });
     
    343350    // 1. Let promise be a new Promise.
    344351    // 2. Shut down the target XRSession object.
    345     shutdown();
     352    if (!m_ended)
     353        shutdown();
    346354
    347355    // 3. Queue a task to perform the following steps:
  • trunk/Source/WebCore/Modules/webxr/WebXRSystem.h

    r270067 r271288  
    108108    public:
    109109        DummyInlineDevice();
     110
     111    private:
     112        void initializeTrackingAndRendering(PlatformXR::SessionMode) final { }
     113        void shutDownTrackingAndRendering() final { }
    110114    };
    111115    DummyInlineDevice m_defaultInlineDevice;
  • trunk/Source/WebCore/platform/xr/PlatformXR.h

    r269032 r271288  
    6060    bool supportsOrientationTracking() const { return m_supportsOrientationTracking; }
    6161
     62    virtual void initializeTrackingAndRendering(SessionMode) = 0;
     63    virtual void shutDownTrackingAndRendering() = 0;
     64
    6265protected:
    6366    Device() = default;
  • trunk/Source/WebCore/platform/xr/openxr/PlatformXROpenXR.cpp

    r270067 r271288  
    2525#include "Logging.h"
    2626#include <openxr/openxr_platform.h>
     27#include <wtf/NeverDestroyed.h>
    2728#include <wtf/Optional.h>
    2829#include <wtf/Scope.h>
    2930#include <wtf/text/StringConcatenateNumbers.h>
    3031#include <wtf/text/WTFString.h>
    31 #include <wtf/NeverDestroyed.h>
    3232
    3333using namespace WebCore;
     
    5454}
    5555
    56 #define RETURN_IF_FAILED(result, call, instance, ...)                                               \
    57     if (XR_FAILED(result)) {                                                                        \
    58         LOG(XR, "%s %s: %s\n", __func__, call, resultToString(result, instance).utf8().data());     \
    59         return __VA_ARGS__;                                                                         \
    60     }                                                                                               \
     56#define RETURN_IF_FAILED(result, call, instance, ...)                                           \
     57    if (XR_FAILED(result)) {                                                                    \
     58        LOG(XR, "%s %s: %s\n", __func__, call, resultToString(result, instance).utf8().data()); \
     59        return __VA_ARGS__;                                                                     \
     60    }
    6161
    6262struct Instance::Impl {
    63     WTF_MAKE_FAST_ALLOCATED;
    64 public:
     63    WTF_MAKE_STRUCT_FAST_ALLOCATED;
     64
    6565    Impl();
    6666    ~Impl();
     
    259259        callOnMainThread(WTFMove(callback));
    260260    });
     261}
     262
     263OpenXRDevice::~OpenXRDevice()
     264{
     265    shutDownTrackingAndRendering();
    261266}
    262267
     
    378383}
    379384
     385XrViewConfigurationType toXrViewConfigurationType(SessionMode mode)
     386{
     387    switch (mode) {
     388    case SessionMode::ImmersiveVr:
     389        return XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO;
     390    case SessionMode::Inline:
     391    case SessionMode::ImmersiveAr:
     392        return XR_VIEW_CONFIGURATION_TYPE_PRIMARY_MONO;
     393    };
     394    ASSERT_NOT_REACHED();
     395    return XR_VIEW_CONFIGURATION_TYPE_PRIMARY_MONO;
     396}
     397
     398void OpenXRDevice::initializeTrackingAndRendering(SessionMode mode)
     399{
     400    m_queue.dispatch([this, mode]() {
     401        ASSERT(m_instance != XR_NULL_HANDLE);
     402        ASSERT(m_session == XR_NULL_HANDLE);
     403
     404        m_currentViewConfigurationType = toXrViewConfigurationType(mode);
     405        ASSERT(m_configurationViews.contains(m_currentViewConfigurationType));
     406
     407        // Create the session.
     408        auto sessionCreateInfo = createStructure<XrSessionCreateInfo, XR_TYPE_SESSION_CREATE_INFO>();
     409        sessionCreateInfo.systemId = m_systemId;
     410        auto result = xrCreateSession(m_instance, &sessionCreateInfo, &m_session);
     411        RETURN_IF_FAILED(result, "xrEnumerateInstanceExtensionProperties", m_instance);
     412    });
     413}
     414
     415void OpenXRDevice::resetSession()
     416{
     417    m_queue.dispatch([this]() {
     418        if (m_session == XR_NULL_HANDLE)
     419            return;
     420        xrDestroySession(m_session);
     421        m_session = XR_NULL_HANDLE;
     422    });
     423}
     424
     425void OpenXRDevice::shutDownTrackingAndRendering()
     426{
     427    resetSession();
     428}
     429
    380430} // namespace PlatformXR
    381431
  • trunk/Source/WebCore/platform/xr/openxr/PlatformXROpenXR.h

    r270067 r271288  
    4545public:
    4646    OpenXRDevice(XrSystemId, XrInstance, WorkQueue&, CompletionHandler<void()>&&);
     47    ~OpenXRDevice();
    4748    XrSystemId xrSystemId() const { return m_systemId; }
    4849
     
    5556    WebCore::IntSize recommendedResolution(SessionMode) final;
    5657
     58    void initializeTrackingAndRendering(SessionMode) final;
     59    void shutDownTrackingAndRendering() final;
     60
     61    void resetSession();
     62
    5763    using ViewConfigurationPropertiesMap = HashMap<XrViewConfigurationType, XrViewConfigurationProperties, IntHash<XrViewConfigurationType>, WTF::StrongEnumHashTraits<XrViewConfigurationType>>;
    5864    ViewConfigurationPropertiesMap m_viewConfigurationProperties;
     
    6268    XrSystemId m_systemId;
    6369    XrInstance m_instance;
    64     XrSession m_session;
     70    XrSession m_session { XR_NULL_HANDLE };
    6571
    6672    WorkQueue& m_queue;
     73
     74    XrViewConfigurationType m_currentViewConfigurationType;
    6775};
    6876
  • trunk/Source/WebCore/testing/WebFakeXRDevice.h

    r264568 r271288  
    7171    Vector<Ref<FakeXRView>>& views() { return m_views; }
    7272private:
     73    void initializeTrackingAndRendering(PlatformXR::SessionMode) final { }
     74    void shutDownTrackingAndRendering() final { }
    7375    Optional<Vector<FakeXRBoundsPoint>> m_nativeBoundsGeometry;
    7476    RefPtr<WebXRRigidTransform> m_viewerOrigin;
Note: See TracChangeset for help on using the changeset viewer.