Changeset 264215 in webkit


Ignore:
Timestamp:
Jul 10, 2020 4:08:12 AM (4 years ago)
Author:
svillar@igalia.com
Message:

[WebXR] Retrieve WebGL framebuffer resolution from XR devices
https://bugs.webkit.org/show_bug.cgi?id=213886

Reviewed by Carlos Garcia Campos.

The recommended WebGL framebuffer resolution should be retrieved from the actual XR device being used.
Implemented the OpenXR machinery to retrieve it from the XR system. We are also moving the methods that
call the platform code to the XRSession as specs define, instead of having them inside the XRWebGLLayer.

Finally this patch is also removing a unused definition in OpenXR plaform code and properly initializing
a OpenXR struct. The missing initialization was the source of errors when querying api layer properties.
The patch is also properly setting the SessionMode::Inline when XR_VIEW_CONFIGURATION_TYPE_PRIMARY_MONO
is found. It used to set SessionMode::ImmersiveAr instead, but that's wrong, we should only care about
ImmersiveAr session mode once the WebXR AR module is implemented.

  • Modules/webxr/WebXRRenderState.cpp:

(WebCore::WebXRRenderState::outputCanvas const): Return render state's canvas.

  • Modules/webxr/WebXRRenderState.h: Added a m_outputCanvas member with its getter.
  • Modules/webxr/WebXRSession.cpp:

(WebCore::WebXRSession::nativeWebGLFramebufferResolution const): Moved from WebXRWebGLLayer and reimplemented.
(WebCore::WebXRSession::recommendedWebGLFramebufferResolution const): Ditto.

  • Modules/webxr/WebXRSession.h:
  • Modules/webxr/WebXRWebGLLayer.cpp:

(WebCore::WebXRWebGLLayer::WebXRWebGLLayer):
(WebCore::WebXRWebGLLayer::getNativeFramebufferScaleFactor): Call the session to get native and recommended
resolutions.
(WebCore::WebXRWebGLLayer::computeNativeWebGLFramebufferResolution): Deleted.
(WebCore::WebXRWebGLLayer::computeRecommendedWebGLFramebufferResolution): Ditto.

  • platform/xr/PlatformXR.h:

(PlatformXR::Device::recommendedResolution): New virtual method with default implementation.

  • platform/xr/openxr/PlatformXROpenXR.cpp:

(PlatformXR::Instance::Impl::enumerateApiLayerProperties const): Added initialization of the XrApiLayerProperties
objects. The call to xrEnumerateApiLayerProperties succeeds now.
(PlatformXR::OpenXRDevice::OpenXRDevice): Call enumerateConfigurationViews().
(PlatformXR::OpenXRDevice::collectSupportedSessionModes): Fill in the m_viewConfigurationProperties map.
(PlatformXR::OpenXRDevice::enumerateConfigurationViews): New method that retrieves the XR device views for each
supported configuration.
(PlatformXR::OpenXRDevice::recommendedResolution): Return the recommended resolution for a given SessionMode.

  • platform/xr/openxr/PlatformXROpenXR.h: Added some new methods and attributes.
Location:
trunk/Source/WebCore
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r264214 r264215  
     12020-07-02  Sergio Villar Senin  <svillar@igalia.com>
     2
     3        [WebXR] Retrieve WebGL framebuffer resolution from XR devices
     4        https://bugs.webkit.org/show_bug.cgi?id=213886
     5
     6        Reviewed by Carlos Garcia Campos.
     7
     8        The recommended WebGL framebuffer resolution should be retrieved from the actual XR device being used.
     9        Implemented the OpenXR machinery to retrieve it from the XR system. We are also moving the methods that
     10        call the platform code to the XRSession as specs define, instead of having them inside the XRWebGLLayer.
     11
     12        Finally this patch is also removing a unused definition in OpenXR plaform code and properly initializing
     13        a OpenXR struct. The missing initialization was the source of errors when querying api layer properties.
     14        The patch is also properly setting the SessionMode::Inline when XR_VIEW_CONFIGURATION_TYPE_PRIMARY_MONO
     15        is found. It used to set SessionMode::ImmersiveAr instead, but that's wrong, we should only care about
     16        ImmersiveAr session mode once the WebXR AR module is implemented.
     17
     18        * Modules/webxr/WebXRRenderState.cpp:
     19        (WebCore::WebXRRenderState::outputCanvas const): Return render state's canvas.
     20        * Modules/webxr/WebXRRenderState.h: Added a m_outputCanvas member with its getter.
     21        * Modules/webxr/WebXRSession.cpp:
     22        (WebCore::WebXRSession::nativeWebGLFramebufferResolution const): Moved from WebXRWebGLLayer and reimplemented.
     23        (WebCore::WebXRSession::recommendedWebGLFramebufferResolution const): Ditto.
     24        * Modules/webxr/WebXRSession.h:
     25        * Modules/webxr/WebXRWebGLLayer.cpp:
     26        (WebCore::WebXRWebGLLayer::WebXRWebGLLayer):
     27        (WebCore::WebXRWebGLLayer::getNativeFramebufferScaleFactor): Call the session to get native and recommended
     28        resolutions.
     29        (WebCore::WebXRWebGLLayer::computeNativeWebGLFramebufferResolution): Deleted.
     30        (WebCore::WebXRWebGLLayer::computeRecommendedWebGLFramebufferResolution): Ditto.
     31        * platform/xr/PlatformXR.h:
     32        (PlatformXR::Device::recommendedResolution): New virtual method with default implementation.
     33        * platform/xr/openxr/PlatformXROpenXR.cpp:
     34        (PlatformXR::Instance::Impl::enumerateApiLayerProperties const): Added initialization of the XrApiLayerProperties
     35        objects. The call to xrEnumerateApiLayerProperties succeeds now.
     36        (PlatformXR::OpenXRDevice::OpenXRDevice): Call enumerateConfigurationViews().
     37        (PlatformXR::OpenXRDevice::collectSupportedSessionModes): Fill in the m_viewConfigurationProperties map.
     38        (PlatformXR::OpenXRDevice::enumerateConfigurationViews): New method that retrieves the XR device views for each
     39        supported configuration.
     40        (PlatformXR::OpenXRDevice::recommendedResolution): Return the recommended resolution for a given SessionMode.
     41        * platform/xr/openxr/PlatformXROpenXR.h: Added some new methods and attributes.
     42
    1432020-07-10  Zalan Bujtas  <zalan@apple.com>
    244
  • trunk/Source/WebCore/Modules/webxr/WebXRRenderState.cpp

    r261863 r264215  
    2929#if ENABLE(WEBXR)
    3030
     31#include "HTMLCanvasElement.h"
    3132#include "WebXRWebGLLayer.h"
    3233#include "XRRenderStateInit.h"
     
    7677}
    7778
     79HTMLCanvasElement* WebXRRenderState::outputCanvas() const
     80{
     81    return m_outputCanvas.get();
     82}
     83
    7884} // namespace WebCore
    7985
  • trunk/Source/WebCore/Modules/webxr/WebXRRenderState.h

    r261863 r264215  
    3434#include <wtf/RefCounted.h>
    3535#include <wtf/RefPtr.h>
     36#include <wtf/WeakPtr.h>
    3637
    3738namespace WebCore {
    3839
     40class HTMLCanvasElement;
    3941class WebXRWebGLLayer;
    4042struct XRRenderStateInit;
     
    5052    Optional<double> inlineVerticalFieldOfView() const;
    5153    RefPtr<WebXRWebGLLayer> baseLayer() const;
     54    HTMLCanvasElement* outputCanvas() const;
    5255
    5356private:
     
    6265    Optional<double> m_inlineVerticalFieldOfView; // in radians
    6366    RefPtr<WebXRWebGLLayer> m_baseLayer;
     67    WeakPtr<HTMLCanvasElement> m_outputCanvas;
    6468};
    6569
  • trunk/Source/WebCore/Modules/webxr/WebXRSession.cpp

    r263503 r264215  
    239239}
    240240
     241// https://immersive-web.github.io/webxr/#native-webgl-framebuffer-resolution
     242IntSize WebXRSession::nativeWebGLFramebufferResolution() const
     243{
     244    if (m_mode == XRSessionMode::Inline) {
     245        // FIXME: replace the conditional by ASSERTs once we properly initialize the outputCanvas.
     246        return m_activeRenderState && m_activeRenderState->outputCanvas() ? m_activeRenderState->outputCanvas()->size() : IntSize(1, 1);
     247    }
     248
     249    return recommendedWebGLFramebufferResolution();
     250}
     251
     252// https://immersive-web.github.io/webxr/#recommended-webgl-framebuffer-resolution
     253IntSize WebXRSession::recommendedWebGLFramebufferResolution() const
     254{
     255    ASSERT(m_device);
     256    return m_device->recommendedResolution(m_mode);
     257}
     258
    241259// https://immersive-web.github.io/webxr/#shut-down-the-session
    242260void WebXRSession::shutdown()
  • trunk/Source/WebCore/Modules/webxr/WebXRSession.h

    r263403 r264215  
    7777    void cancelAnimationFrame(unsigned callbackId);
    7878
     79    IntSize nativeWebGLFramebufferResolution() const;
     80    IntSize recommendedWebGLFramebufferResolution() const;
     81
    7982    // EventTarget.
    8083    ScriptExecutionContext* scriptExecutionContext() const final { return ActiveDOMObject::scriptExecutionContext(); }
    8184
    8285    void end(EndPromise&&);
    83 
    8486    bool ended() const { return m_ended; }
    8587
  • trunk/Source/WebCore/Modules/webxr/WebXRWebGLLayer.cpp

    r263403 r264215  
    9292}
    9393
    94 // https://immersive-web.github.io/webxr/#native-webgl-framebuffer-resolution
    95 IntSize WebXRWebGLLayer::computeNativeWebGLFramebufferResolution()
    96 {
    97     // FIXME: implement this
    98     return { 1, 1 };
    99 }
    100 
    101 // https://immersive-web.github.io/webxr/#recommended-webgl-framebuffer-resolution
    102 IntSize WebXRWebGLLayer::computeRecommendedWebGLFramebufferResolution()
    103 {
    104     return computeNativeWebGLFramebufferResolution();
    105 }
    106 
    10794WebXRWebGLLayer::WebXRWebGLLayer(Ref<WebXRSession>&& session, WebXRRenderingContext&& context, const XRWebGLLayerInit& init)
    10895    : WebXRLayer(session->scriptExecutionContext())
     
    128115
    129116        //  2. Let framebufferSize be the recommended WebGL framebuffer resolution multiplied by layerInit's framebufferScaleFactor.
    130         IntSize recommendedSize = computeRecommendedWebGLFramebufferResolution();
     117        IntSize recommendedSize = m_session->recommendedWebGLFramebufferResolution();
    131118        m_framebuffer.width = recommendedSize.width() * init.framebufferScaleFactor;
    132119        m_framebuffer.height = recommendedSize.height() * init.framebufferScaleFactor;
     
    205192        return 0.0;
    206193
    207     IntSize nativeSize = computeNativeWebGLFramebufferResolution();
    208     IntSize recommendedSize = computeRecommendedWebGLFramebufferResolution();
     194    IntSize nativeSize = session.nativeWebGLFramebufferResolution();
     195    IntSize recommendedSize = session.recommendedWebGLFramebufferResolution();
    209196
    210197    RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(!recommendedSize.isZero());
  • trunk/Source/WebCore/platform/xr/PlatformXR.h

    r263503 r264215  
    1919#pragma once
    2020
     21#include "IntSize.h"
    2122#include <memory>
    2223#include <wtf/HashMap.h>
     
    5455    ListOfEnabledFeatures enabledFeatures(SessionMode mode) const { return m_enabledFeaturesMap.get(mode); }
    5556
     57    virtual WebCore::IntSize recommendedResolution(SessionMode) { return { 1, 1 }; }
     58
    5659    bool supportsOrientationTracking() const { return m_supportsOrientationTracking; }
    5760
  • trunk/Source/WebCore/platform/xr/openxr/PlatformXROpenXR.cpp

    r263516 r264215  
    7171
    7272#if USE_OPENXR
    73     Optional<Vector<SessionMode>> collectSupportedSessionModes(OpenXRDevice&);
    7473    XrInstance xrInstance() const { return m_instance; }
    7574#endif
     
    9695    }
    9796
    98     Vector<XrApiLayerProperties> properties(propertyCountOutput);
    99     result = xrEnumerateApiLayerProperties(propertyCountOutput, nullptr, properties.data());
     97    Vector<XrApiLayerProperties> properties(propertyCountOutput,
     98        [] {
     99            XrApiLayerProperties object;
     100            std::memset(&object, 0, sizeof(XrApiLayerProperties));
     101            object.type = XR_TYPE_API_LAYER_PROPERTIES;
     102            return object;
     103        }());
     104    result = xrEnumerateApiLayerProperties(propertyCountOutput, &propertyCountOutput, properties.data());
     105
    100106    RETURN_IF_FAILED(result, "xrEnumerateApiLayerProperties()", m_instance);
    101107    LOG(XR, "xrEnumerateApiLayerProperties(): %zu properties\n", properties.size());
     
    214220
    215221    collectSupportedSessionModes();
     222    enumerateConfigurationViews();
    216223}
    217224
     
    233240            continue;
    234241        }
    235         switch (viewConfigurationProperties.viewConfigurationType) {
     242        auto configType = viewConfigurationProperties.viewConfigurationType;
     243        switch (configType) {
    236244        case XR_VIEW_CONFIGURATION_TYPE_PRIMARY_MONO:
    237             setEnabledFeatures(SessionMode::ImmersiveAr, { });
     245            setEnabledFeatures(SessionMode::Inline, { });
    238246            break;
    239247        case XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO:
     
    241249            break;
    242250        default:
    243             break;
     251            continue;
    244252        };
    245     }
    246 }
     253        m_viewConfigurationProperties.add(configType, WTFMove(viewConfigurationProperties));
     254    }
     255}
     256
     257void OpenXRDevice::enumerateConfigurationViews()
     258{
     259    for (auto& config : m_viewConfigurationProperties.values()) {
     260        uint32_t viewCount;
     261        auto configType = config.viewConfigurationType;
     262        auto result = xrEnumerateViewConfigurationViews(m_instance, m_systemId, configType, 0, &viewCount, nullptr);
     263        if (result != XR_SUCCESS) {
     264            LOG(XR, "%s %s: %s\n", __func__, "xrEnumerateViewConfigurationViews", resultToString(result, m_instance).utf8().data());
     265            continue;
     266        }
     267
     268        Vector<XrViewConfigurationView> configViews(viewCount,
     269            [] {
     270                XrViewConfigurationView object;
     271                std::memset(&object, 0, sizeof(XrViewConfigurationView));
     272                object.type = XR_TYPE_VIEW_CONFIGURATION_VIEW;
     273                return object;
     274            }());
     275        result = xrEnumerateViewConfigurationViews(m_instance, m_systemId, configType, viewCount, &viewCount, configViews.data());
     276        if (result != XR_SUCCESS)
     277            continue;
     278        m_configurationViews.add(configType, WTFMove(configViews));
     279    }
     280}
     281
     282WebCore::IntSize OpenXRDevice::recommendedResolution(SessionMode mode)
     283{
     284    auto configType = mode == SessionMode::Inline ? XR_VIEW_CONFIGURATION_TYPE_PRIMARY_MONO : XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO;
     285    auto viewsIterator = m_configurationViews.find(configType);
     286    if (viewsIterator != m_configurationViews.end())
     287        return { static_cast<int>(viewsIterator->value[0].recommendedImageRectWidth), static_cast<int>(viewsIterator->value[0].recommendedImageRectHeight) };
     288    return Device::recommendedResolution(mode);
     289}
     290
     291
    247292#endif // USE_OPENXR
    248293
  • trunk/Source/WebCore/platform/xr/openxr/PlatformXROpenXR.h

    r263503 r264215  
    2323#include "PlatformXR.h"
    2424
     25#include <wtf/HashMap.h>
     26
    2527#if USE_OPENXR
    2628#include <openxr/openxr.h>
     
    4648private:
    4749    void collectSupportedSessionModes();
     50    void enumerateConfigurationViews();
     51
     52    WebCore::IntSize recommendedResolution(SessionMode) final;
     53
     54    using ViewConfigurationPropertiesMap = HashMap<XrViewConfigurationType, XrViewConfigurationProperties, IntHash<XrViewConfigurationType>, WTF::StrongEnumHashTraits<XrViewConfigurationType>>;
     55    ViewConfigurationPropertiesMap m_viewConfigurationProperties;
     56    using ViewConfigurationViewsMap = HashMap<XrViewConfigurationType, Vector<XrViewConfigurationView>, IntHash<XrViewConfigurationType>, WTF::StrongEnumHashTraits<XrViewConfigurationType>>;
     57    ViewConfigurationViewsMap m_configurationViews;
    4858
    4959    XrSystemId m_systemId;
Note: See TracChangeset for help on using the changeset viewer.