Title: [264215] trunk/Source/WebCore
Revision
264215
Author
[email protected]
Date
2020-07-10 04:08:12 -0700 (Fri, 10 Jul 2020)

Log 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.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (264214 => 264215)


--- trunk/Source/WebCore/ChangeLog	2020-07-10 10:48:32 UTC (rev 264214)
+++ trunk/Source/WebCore/ChangeLog	2020-07-10 11:08:12 UTC (rev 264215)
@@ -1,3 +1,45 @@
+2020-07-02  Sergio Villar Senin  <[email protected]>
+
+        [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.
+
 2020-07-10  Zalan Bujtas  <[email protected]>
 
         [LFC][MarginCollapsing] Margins do not collapse through when the box has clearance.

Modified: trunk/Source/WebCore/Modules/webxr/WebXRRenderState.cpp (264214 => 264215)


--- trunk/Source/WebCore/Modules/webxr/WebXRRenderState.cpp	2020-07-10 10:48:32 UTC (rev 264214)
+++ trunk/Source/WebCore/Modules/webxr/WebXRRenderState.cpp	2020-07-10 11:08:12 UTC (rev 264215)
@@ -28,6 +28,7 @@
 
 #if ENABLE(WEBXR)
 
+#include "HTMLCanvasElement.h"
 #include "WebXRWebGLLayer.h"
 #include "XRRenderStateInit.h"
 #include <wtf/IsoMallocInlines.h>
@@ -75,6 +76,11 @@
     return m_baseLayer;
 }
 
+HTMLCanvasElement* WebXRRenderState::outputCanvas() const
+{
+    return m_outputCanvas.get();
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(WEBXR)

Modified: trunk/Source/WebCore/Modules/webxr/WebXRRenderState.h (264214 => 264215)


--- trunk/Source/WebCore/Modules/webxr/WebXRRenderState.h	2020-07-10 10:48:32 UTC (rev 264214)
+++ trunk/Source/WebCore/Modules/webxr/WebXRRenderState.h	2020-07-10 11:08:12 UTC (rev 264215)
@@ -33,9 +33,11 @@
 #include <wtf/Ref.h>
 #include <wtf/RefCounted.h>
 #include <wtf/RefPtr.h>
+#include <wtf/WeakPtr.h>
 
 namespace WebCore {
 
+class HTMLCanvasElement;
 class WebXRWebGLLayer;
 struct XRRenderStateInit;
 
@@ -49,6 +51,7 @@
     double depthFar() const;
     Optional<double> inlineVerticalFieldOfView() const;
     RefPtr<WebXRWebGLLayer> baseLayer() const;
+    HTMLCanvasElement* outputCanvas() const;
 
 private:
     explicit WebXRRenderState(Optional<double>&& fieldOfView);
@@ -61,6 +64,7 @@
     } m_depth;
     Optional<double> m_inlineVerticalFieldOfView; // in radians
     RefPtr<WebXRWebGLLayer> m_baseLayer;
+    WeakPtr<HTMLCanvasElement> m_outputCanvas;
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/Modules/webxr/WebXRSession.cpp (264214 => 264215)


--- trunk/Source/WebCore/Modules/webxr/WebXRSession.cpp	2020-07-10 10:48:32 UTC (rev 264214)
+++ trunk/Source/WebCore/Modules/webxr/WebXRSession.cpp	2020-07-10 11:08:12 UTC (rev 264215)
@@ -238,6 +238,24 @@
         m_runningCallbacks[position]->cancel();
 }
 
+// https://immersive-web.github.io/webxr/#native-webgl-framebuffer-resolution
+IntSize WebXRSession::nativeWebGLFramebufferResolution() const
+{
+    if (m_mode == XRSessionMode::Inline) {
+        // FIXME: replace the conditional by ASSERTs once we properly initialize the outputCanvas.
+        return m_activeRenderState && m_activeRenderState->outputCanvas() ? m_activeRenderState->outputCanvas()->size() : IntSize(1, 1);
+    }
+
+    return recommendedWebGLFramebufferResolution();
+}
+
+// https://immersive-web.github.io/webxr/#recommended-webgl-framebuffer-resolution
+IntSize WebXRSession::recommendedWebGLFramebufferResolution() const
+{
+    ASSERT(m_device);
+    return m_device->recommendedResolution(m_mode);
+}
+
 // https://immersive-web.github.io/webxr/#shut-down-the-session
 void WebXRSession::shutdown()
 {

Modified: trunk/Source/WebCore/Modules/webxr/WebXRSession.h (264214 => 264215)


--- trunk/Source/WebCore/Modules/webxr/WebXRSession.h	2020-07-10 10:48:32 UTC (rev 264214)
+++ trunk/Source/WebCore/Modules/webxr/WebXRSession.h	2020-07-10 11:08:12 UTC (rev 264215)
@@ -76,11 +76,13 @@
     unsigned requestAnimationFrame(Ref<XRFrameRequestCallback>&&);
     void cancelAnimationFrame(unsigned callbackId);
 
+    IntSize nativeWebGLFramebufferResolution() const;
+    IntSize recommendedWebGLFramebufferResolution() const;
+
     // EventTarget.
     ScriptExecutionContext* scriptExecutionContext() const final { return ActiveDOMObject::scriptExecutionContext(); }
 
     void end(EndPromise&&);
-
     bool ended() const { return m_ended; }
 
     XRSessionMode mode() const { return m_mode; }

Modified: trunk/Source/WebCore/Modules/webxr/WebXRWebGLLayer.cpp (264214 => 264215)


--- trunk/Source/WebCore/Modules/webxr/WebXRWebGLLayer.cpp	2020-07-10 10:48:32 UTC (rev 264214)
+++ trunk/Source/WebCore/Modules/webxr/WebXRWebGLLayer.cpp	2020-07-10 11:08:12 UTC (rev 264215)
@@ -91,19 +91,6 @@
     );
 }
 
-// https://immersive-web.github.io/webxr/#native-webgl-framebuffer-resolution
-IntSize WebXRWebGLLayer::computeNativeWebGLFramebufferResolution()
-{
-    // FIXME: implement this
-    return { 1, 1 };
-}
-
-// https://immersive-web.github.io/webxr/#recommended-webgl-framebuffer-resolution
-IntSize WebXRWebGLLayer::computeRecommendedWebGLFramebufferResolution()
-{
-    return computeNativeWebGLFramebufferResolution();
-}
-
 WebXRWebGLLayer::WebXRWebGLLayer(Ref<WebXRSession>&& session, WebXRRenderingContext&& context, const XRWebGLLayerInit& init)
     : WebXRLayer(session->scriptExecutionContext())
     , m_session(WTFMove(session))
@@ -127,7 +114,7 @@
         m_antialias = init.antialias;
 
         //  2. Let framebufferSize be the recommended WebGL framebuffer resolution multiplied by layerInit's framebufferScaleFactor.
-        IntSize recommendedSize = computeRecommendedWebGLFramebufferResolution();
+        IntSize recommendedSize = m_session->recommendedWebGLFramebufferResolution();
         m_framebuffer.width = recommendedSize.width() * init.framebufferScaleFactor;
         m_framebuffer.height = recommendedSize.height() * init.framebufferScaleFactor;
 
@@ -204,8 +191,8 @@
     if (session.ended())
         return 0.0;
 
-    IntSize nativeSize = computeNativeWebGLFramebufferResolution();
-    IntSize recommendedSize = computeRecommendedWebGLFramebufferResolution();
+    IntSize nativeSize = session.nativeWebGLFramebufferResolution();
+    IntSize recommendedSize = session.recommendedWebGLFramebufferResolution();
 
     RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(!recommendedSize.isZero());
     return (nativeSize / recommendedSize).width();

Modified: trunk/Source/WebCore/platform/xr/PlatformXR.h (264214 => 264215)


--- trunk/Source/WebCore/platform/xr/PlatformXR.h	2020-07-10 10:48:32 UTC (rev 264214)
+++ trunk/Source/WebCore/platform/xr/PlatformXR.h	2020-07-10 11:08:12 UTC (rev 264215)
@@ -18,6 +18,7 @@
  */
 #pragma once
 
+#include "IntSize.h"
 #include <memory>
 #include <wtf/HashMap.h>
 #include <wtf/UniqueRef.h>
@@ -53,6 +54,8 @@
     void setEnabledFeatures(SessionMode mode, const ListOfEnabledFeatures& features) { m_enabledFeaturesMap.set(mode, features); }
     ListOfEnabledFeatures enabledFeatures(SessionMode mode) const { return m_enabledFeaturesMap.get(mode); }
 
+    virtual WebCore::IntSize recommendedResolution(SessionMode) { return { 1, 1 }; }
+
     bool supportsOrientationTracking() const { return m_supportsOrientationTracking; }
 
 protected:

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


--- trunk/Source/WebCore/platform/xr/openxr/PlatformXROpenXR.cpp	2020-07-10 10:48:32 UTC (rev 264214)
+++ trunk/Source/WebCore/platform/xr/openxr/PlatformXROpenXR.cpp	2020-07-10 11:08:12 UTC (rev 264215)
@@ -70,7 +70,6 @@
     ~Impl();
 
 #if USE_OPENXR
-    Optional<Vector<SessionMode>> collectSupportedSessionModes(OpenXRDevice&);
     XrInstance xrInstance() const { return m_instance; }
 #endif
 
@@ -95,8 +94,15 @@
         return;
     }
 
-    Vector<XrApiLayerProperties> properties(propertyCountOutput);
-    result = xrEnumerateApiLayerProperties(propertyCountOutput, nullptr, properties.data());
+    Vector<XrApiLayerProperties> properties(propertyCountOutput,
+        [] {
+            XrApiLayerProperties object;
+            std::memset(&object, 0, sizeof(XrApiLayerProperties));
+            object.type = XR_TYPE_API_LAYER_PROPERTIES;
+            return object;
+        }());
+    result = xrEnumerateApiLayerProperties(propertyCountOutput, &propertyCountOutput, properties.data());
+
     RETURN_IF_FAILED(result, "xrEnumerateApiLayerProperties()", m_instance);
     LOG(XR, "xrEnumerateApiLayerProperties(): %zu properties\n", properties.size());
 }
@@ -213,6 +219,7 @@
         LOG(XR, "xrGetSystemProperties(): error %s\n", resultToString(result, m_instance).utf8().data());
 
     collectSupportedSessionModes();
+    enumerateConfigurationViews();
 }
 
 void OpenXRDevice::collectSupportedSessionModes()
@@ -232,18 +239,56 @@
             LOG(XR, "xrGetViewConfigurationProperties(): error %s\n", resultToString(result, m_instance).utf8().data());
             continue;
         }
-        switch (viewConfigurationProperties.viewConfigurationType) {
+        auto configType = viewConfigurationProperties.viewConfigurationType;
+        switch (configType) {
         case XR_VIEW_CONFIGURATION_TYPE_PRIMARY_MONO:
-            setEnabledFeatures(SessionMode::ImmersiveAr, { });
+            setEnabledFeatures(SessionMode::Inline, { });
             break;
         case XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO:
             setEnabledFeatures(SessionMode::ImmersiveVr, { });
             break;
         default:
-            break;
+            continue;
         };
+        m_viewConfigurationProperties.add(configType, WTFMove(viewConfigurationProperties));
     }
 }
+
+void OpenXRDevice::enumerateConfigurationViews()
+{
+    for (auto& config : m_viewConfigurationProperties.values()) {
+        uint32_t viewCount;
+        auto configType = config.viewConfigurationType;
+        auto result = xrEnumerateViewConfigurationViews(m_instance, m_systemId, configType, 0, &viewCount, nullptr);
+        if (result != XR_SUCCESS) {
+            LOG(XR, "%s %s: %s\n", __func__, "xrEnumerateViewConfigurationViews", resultToString(result, m_instance).utf8().data());
+            continue;
+        }
+
+        Vector<XrViewConfigurationView> configViews(viewCount,
+            [] {
+                XrViewConfigurationView object;
+                std::memset(&object, 0, sizeof(XrViewConfigurationView));
+                object.type = XR_TYPE_VIEW_CONFIGURATION_VIEW;
+                return object;
+            }());
+        result = xrEnumerateViewConfigurationViews(m_instance, m_systemId, configType, viewCount, &viewCount, configViews.data());
+        if (result != XR_SUCCESS)
+            continue;
+        m_configurationViews.add(configType, WTFMove(configViews));
+    }
+}
+
+WebCore::IntSize OpenXRDevice::recommendedResolution(SessionMode mode)
+{
+    auto configType = mode == SessionMode::Inline ? XR_VIEW_CONFIGURATION_TYPE_PRIMARY_MONO : XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO;
+    auto viewsIterator = m_configurationViews.find(configType);
+    if (viewsIterator != m_configurationViews.end())
+        return { static_cast<int>(viewsIterator->value[0].recommendedImageRectWidth), static_cast<int>(viewsIterator->value[0].recommendedImageRectHeight) };
+    return Device::recommendedResolution(mode);
+}
+
+
 #endif // USE_OPENXR
 
 } // namespace PlatformXR

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


--- trunk/Source/WebCore/platform/xr/openxr/PlatformXROpenXR.h	2020-07-10 10:48:32 UTC (rev 264214)
+++ trunk/Source/WebCore/platform/xr/openxr/PlatformXROpenXR.h	2020-07-10 11:08:12 UTC (rev 264215)
@@ -22,6 +22,8 @@
 #if ENABLE(WEBXR)
 #include "PlatformXR.h"
 
+#include <wtf/HashMap.h>
+
 #if USE_OPENXR
 #include <openxr/openxr.h>
 
@@ -45,7 +47,15 @@
     XrSystemId xrSystemId() const { return m_systemId; }
 private:
     void collectSupportedSessionModes();
+    void enumerateConfigurationViews();
 
+    WebCore::IntSize recommendedResolution(SessionMode) final;
+
+    using ViewConfigurationPropertiesMap = HashMap<XrViewConfigurationType, XrViewConfigurationProperties, IntHash<XrViewConfigurationType>, WTF::StrongEnumHashTraits<XrViewConfigurationType>>;
+    ViewConfigurationPropertiesMap m_viewConfigurationProperties;
+    using ViewConfigurationViewsMap = HashMap<XrViewConfigurationType, Vector<XrViewConfigurationView>, IntHash<XrViewConfigurationType>, WTF::StrongEnumHashTraits<XrViewConfigurationType>>;
+    ViewConfigurationViewsMap m_configurationViews;
+
     XrSystemId m_systemId;
     XrInstance m_instance;
 };
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to